示例#1
0
 /** 
  * Edit image properties
  *
  * @return void
  */
 function editAction()
 {
     $this->view->title = "Edit Image";
     $form = new ImageForm(array('legend' => 'Edit Image'));
     $form->submit->setLabel('Update');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $form_data = $this->_request->getPost();
         if ($form->isValid($form_data)) {
             $images = new Images();
             $id = (int) $form->getValue('id');
             $row = $images->fetchRow('id=' . $id);
             $row->title = $form->getValue('title');
             $row->description = $form->getValue('description');
             $row->album_id = $form->getValue('album_id');
             $row->updated_at = $this->datetime();
             $row->save();
             $this->saveImage($id, 'image', 'raw');
             $this->saveImage($id, 'thumb_file', 'thumb');
             $this->_redirect("/image/view/id/{$id}");
         } else {
             $form->populate($form_data);
         }
     } else {
         $id = (int) $this->_request->getParam('id', 0);
         if ($id > 0) {
             $images = new Images();
             $image = $images->fetchRow('id=' . $id);
             $form->populate($image->toArray());
         }
     }
     $this->_helper->viewRenderer('form');
 }
 public function run()
 {
     if ($image = CUploadedFile::getInstanceByName($this->field)) {
         // Валидация по форме
         $v = new ImageForm();
         $v->image = true;
         $v->image_file = $image;
         if ($v->validate()) {
             $preid = Yii::app()->request->getPost('preid', date('Ymd'));
             $tmp = pathinfo($image->name);
             $filename = EString::strtolower(EFile::sanitize($tmp['filename']) . '_' . uniqid() . '.' . $tmp['extension']);
             $path = Yii::getPathOfAlias($this->folder . '.' . $this->field) . DIRECTORY_SEPARATOR . $preid . DIRECTORY_SEPARATOR;
             $result = Image::addFile($image, $filename, $path, $this->sizes, $preid, null, $this->watermark ? Yii::app()->params['watermark'] : false);
             echo '"' . Image::getFile($result, 'normal') . '"';
         } else {
             echo '{"error":"Файл не проходит валидацию, выберите другой."}';
         }
     } else {
         echo '{"error":"Ошибка загрузки файла."}';
     }
 }
 /** Add a new image
  */
 public function addAction()
 {
     $form = new ImageForm();
     $form->submit->setLabel('Submit a new image.');
     $user = $this->getUserDetails();
     $username = $user['username'];
     if (is_dir(self::PATH . $username)) {
         $form->image->setDestination(self::PATH . $username);
     } else {
         $path = mkdir(self::PATH . $username);
         $form->image->setDestination($path);
     }
     $this->view->form = $form;
     $savePath = self::PATH . $username . '/medium/';
     $thumbPath = self::PATH . 'thumbnails/';
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         $upload = new Zend_File_Transfer_Adapter_Http();
         if ($form->isValid($formData)) {
             $upload = new Zend_File_Transfer_Adapter_Http();
             $upload->addValidator('NotExists', false, array(self::PATH . $username));
             $filesize = $upload->getFileSize();
             if ($upload->isValid()) {
                 $filename = $form->getValue('image');
                 $label = $formData['label'];
                 $secuid = $this->secuid();
                 $insertData = array();
                 $insertData['filename'] = $filename;
                 $insertData['label'] = $label;
                 $insertData['county'] = $form->getValue('county');
                 $insertData['period'] = $form->getValue('period');
                 $insertData['filedate'] = $this->getTimeForForms();
                 $insertData['created'] = $this->getTimeForForms();
                 $insertData['createdBy'] = $this->getIdentityForForms();
                 $insertData['filesize'] = $filesize;
                 $insertData['imagerights'] = $form->getValue('copyrighttext');
                 $insertData['secuid'] = $secuid;
                 //$insertData['mimetype'] = $mimetype;
                 foreach ($insertData as $key => $value) {
                     if (is_null($value) || $value == "") {
                         unset($insertData[$key]);
                     }
                 }
                 $upload->receive();
                 $location = self::PATH . $username . '/' . $filename;
                 $id = $this->_images->insert($insertData);
                 //Update the solr instance
                 $this->_helper->solrUpdater->update('beoimages', $id);
                 $largepath = self::PATH . $username . '/';
                 $mediumpath = self::PATH . $username . '/medium/';
                 $smallpath = self::PATH . $username . '/small/';
                 $displaypath = self::PATH . $username . '/display/';
                 $thumbpath = self::PATH . 'thumbnails/';
                 $name = substr($filename, 0, strrpos($filename, '.'));
                 $ext = '.jpg';
                 //create medium size
                 $phMagick = new phMagick($location, $mediumpath . $name . $ext);
                 $phMagick->resize(500, 0);
                 $phMagick->convert();
                 //Very small size
                 $phMagick = new phMagick($location, $smallpath . $name . $ext);
                 $phMagick->resize(40, 0);
                 $phMagick->convert();
                 //Record display size
                 $phMagick = new phMagick($location, $displaypath . $name . $ext);
                 $phMagick->resize(0, 150);
                 $phMagick->convert();
                 //Thumbnail size
                 $phMagick = new phMagick($location, $thumbpath . $id . $ext);
                 $phMagick->resize(100, 100);
                 $phMagick->convert();
                 $linkData = array();
                 $linkData['find_id'] = $this->_getParam('findID');
                 $linkData['image_id'] = $secuid;
                 $linkData['secuid'] = $this->secuid();
                 $imagelink = new FindsImages();
                 $insertedlink = $imagelink->insert($linkData);
                 $this->_cache->remove('findtoimage' . $this->_getParam('id'));
                 $this->_flashMessenger->addMessage('The image has been resized and added!');
                 $this->_redirect('/database/artefacts/record/id/' . $this->_getParam('id'));
             } else {
                 $this->_flashMessenger->addMessage('There is a problem with your upload. Probably that image exists.');
                 $this->view->errors = $upload->getMessages();
             }
         } else {
             $form->populate($form->getValues());
             $this->_flashMessenger->addMessage('Check your form for errors dude');
         }
     }
 }
<?php

session_start();
require 'include/beContent.inc.php';
require_once 'include/content.inc.php';
require 'include/auth.inc.php';
require_once realpath(dirname(__FILE__)) . '/include/view/template/InitGraphic.php';
$main = new Skin('system');
InitGraphic::getInstance()->createSystemGraphic($main);
$form = new Form('dataEntry', $pageEntity);
$form->addSection('Page Management');
$form->addText('title', 'Titolo', 60, null, 60, true);
//$form->addTextarea('description', 'Description', 10, 50);
$form->addText('subtitle', 'Sottotitolo', 60);
$form->addText('link', 'Script Collegato', 255);
$form->addEditor('body', 'Corpo', 50, 50);
$form->addSelectFromReference($pageEntity, 'father', 'Padre');
//$form->addHierarchicalPosition('section', 'Sezione padre',MANDATORY,$sectionEntity);
$imageForm = new ImageForm('imageEntry', $pageEntity);
$imageForm->addImage('foto', 'Foto');
$form->triggers($imageForm);
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = 'edit';
}
$main->setContent('body', $form->requestAction());
$main->close();