Exemplo n.º 1
0
 public function executeUpload()
 {
     $upload_max_filesize = str_replace('M', '', ini_get('upload_max_filesize'));
     $res = new \AjaxResponse();
     $upload_dir = PUBLIC_DIR . '/media/editor_upload/';
     Folder::create($upload_dir, 0777);
     $error = array();
     $fileUploader = new Uploader($upload_dir, 'file_upload');
     $fileUploader->setMaximumFileSize($upload_max_filesize);
     $fileUploader->setFilterType('.jpg, .jpeg, .png, .bmp, .gif');
     $fileUploader->setIsEncryptFileName(true);
     if ($fileUploader->upload('file_upload')) {
         $data = $fileUploader->getData();
         $file_path = '/media/editor_upload/' . $data['file_name'];
         $file_url = rtrim($this->document()->getBaseUrl(), '/') . preg_replace('/(\\/+)/', '/', '/../' . $file_path);
         $image = ['file_name' => $data['file_name'], 'url' => $file_url, 'path' => $file_path];
         $res->type = \AjaxResponse::SUCCESS;
         $res->image = $image;
         return $this->renderText($res->toString());
     } else {
         $error['upload'] = $fileUploader->getError();
     }
     $res->type = \AjaxResponse::ERROR;
     $res->error = $error;
     return $this->renderText($res->toString());
 }
Exemplo n.º 2
0
 public function executeUpload()
 {
     $upload_max_filesize = str_replace('M', '', ini_get('upload_max_filesize'));
     $res = new \AjaxResponse();
     $postId = $this->request()->post('post_id');
     $upload_dir = PUBLIC_DIR . '/media/post_img/';
     Folder::create($upload_dir, 0777);
     $error = array();
     $fileUploader = new Uploader($upload_dir, 'file_upload');
     $fileUploader->setMaximumFileSize($upload_max_filesize);
     $fileUploader->setFilterType('.jpg, .jpeg, .png, .bmp, .gif');
     $fileUploader->setIsEncryptFileName(true);
     if ($fileUploader->upload('upload_images')) {
         $data = $fileUploader->getData();
         $filePath = '/media/post_img/' . $data['file_name'];
         $fileUrl = $this->document()->getBaseUrl() . '/../' . $filePath;
         $otherImages = \PostPeer::getPostImg($postId);
         $ordering = sizeof($otherImages);
         foreach ($otherImages as $image) {
             if ($image->getOrdering() > $ordering) {
                 $ordering = $image->getOrdering();
             }
         }
         $ordering++;
         $postImg = new \PostImages();
         $postImg->setPath($filePath);
         $postImg->setPostId($postId);
         $postImg->setOrdering($ordering);
         if (!\PostPeer::getPostMainImg($postId)) {
             $postImg->setIsMain(true);
         }
         if ($postImg->save()) {
             $res->type = \AjaxResponse::SUCCESS;
             $t = $postImg->toArray();
             $t['thumb_url'] = $postImg->getThumbs(96, 96);
             $t['url'] = $postImg->getUrl();
             $res->postImage = $t;
             return $this->renderText($res->toString());
         } else {
             foreach ($postImg->getValidationFailures() as $validationFailure) {
                 $error[$validationFailure->getColumn()] = $validationFailure->getMessage();
             }
         }
     } else {
         $error['upload'] = $fileUploader->getError();
     }
     $res->type = \AjaxResponse::ERROR;
     $res->error = $error;
     return $this->renderText($res->toString());
 }
Exemplo n.º 3
0
 protected function _writeFile($path, $content)
 {
     Folder::create($path);
     if (!($id = session_id())) {
         $id = md5(uniqid() . mt_rand());
     }
     $filename = $this->_file_prefix . date('Y-m-d') . '-' . $id . $this->_file_ext;
     $file = $path . DIRECTORY_SEPARATOR . $filename;
     if (!file_exists($file)) {
         touch($file);
         // Create blank file
         chmod($file, 0777);
     }
     $stream = fopen($file, 'a');
     fwrite($stream, $content);
     fclose($stream);
 }
Exemplo n.º 4
0
 private function _generateBaseModel($table)
 {
     $dir = $this->getDestinationDir() . 'Base/';
     //generate base model
     $class = str_replace(' ', '', ucwords(str_replace('_', ' ', trim(str_replace($this->tbPrefix, '', $table), '_'))));
     $file = $dir . $class . 'Base.php';
     Folder::create($dir);
     /* colums get from yaml files */
     $columns = $this->_getListTableColumn($table);
     $configs = $this->_getListTableConfig($table);
     /* comment for new base Class */
     $classComment = $this->_writeClassComment($class);
     $magicProperties = $magicMethod = '';
     if (!empty($columns)) {
         foreach ($columns as $name => $property) {
             $magicProperties .= $this->_writeClassMagicProperties($name, $property);
             $magicMethod .= $this->_writeClassMagicMethod($class, $name, $property);
         }
     }
     $buffer = sprintf($this->baseModelTemplate(), $classComment, $magicProperties, $magicMethod, $class . 'Base', $this->_writeClassInfo($table, $columns, $configs), $this->_writeTableDefinition($table, $columns));
     $fp = @fopen($file, 'w');
     if ($fp === false) {
         throw new \Flywheel\Exception("Couldn't write model data. Failed to open {$file}");
     }
     fwrite($fp, "<?php " . PHP_EOL . $buffer);
     fclose($fp);
     unset($buffer);
     unset($columns);
     unset($classComment);
     unset($name);
     unset($property);
     unset($classProperties);
     echo ' -- Generate om:' . 'Base/' . $class . 'Base.php' . " succeed!\n";
 }
Exemplo n.º 5
0
 /**
  * make file name after upload
  *
  * @return string filename included extension
  */
 protected function _makeFileName()
 {
     if (true == $this->_encryptFileName) {
         return uniqid() . $this->_data['file_extension'];
     }
     if (null != $this->_newName) {
         $name = Folder::cleanFileName($this->_newName);
         $name = str_replace($this->_data['file_extension'], '', $name);
     } else {
         $name = Folder::cleanFileName($this->_data['file_origin_name']);
         $name = str_replace($this->_data['file_extension'], '', $name);
     }
     if (false !== $this->_ansiName) {
         $name = preg_replace('/[^A-Za-z0-9_\\-]/', '', $name);
     }
     if (false !== $this->_removeSpaceName) {
         $name = preg_replace('/\\s+/', '-', $name);
     }
     if (true !== $this->_overwrite && file_exists($this->_dir . $name . $this->_data['file_extension'])) {
         $i = 1;
         do {
             $_t = $name . '(' . $i . ')';
             ++$i;
         } while (file_exists($this->_dir . $_t . $this->_data['file_extension']));
         $name = $_t;
     }
     return $name . $this->_data['file_extension'];
 }
Exemplo n.º 6
0
 private function _generateSchemas($table, $class)
 {
     $dir = $this->getDestinationDir();
     $file = $dir . $class . '.yml';
     Folder::create($dir);
     $structArray = array(array('comment' => $this->_writeComment($class)), array('colums' => $this->_getListTableColumn($table)), array('infos' => $this->_generaInfo($table)));
     $yaml = $this->dumpYaml($structArray);
     $fileSystem = new Symfony\Component\Filesystem\Filesystem();
     $fileSystem->dumpFile($file, $yaml);
     return $class . ".yml";
 }
Exemplo n.º 7
0
 public function _save(\Banner $banner, &$error = array())
 {
     $banner->hydrate($this->request()->post('input', 'ARRAY', array()));
     $file_upload = @$_FILES['file_upload']['tmp_name'];
     if ($banner->isNew() && null == $file_upload) {
         @($error['banner.file'] = t('Banner file is required!'));
     }
     if (!$banner->getTermId()) {
         @($error['banner.term_id'] = t('Banner group is required!'));
     }
     if (empty($error)) {
         //upload file
         if ($file_upload) {
             $upload_dir = PUBLIC_DIR . '/media/banner';
             Folder::create($upload_dir, 0777);
             $fileUploader = new Uploader(PUBLIC_DIR . '/media/banner/', 'file_upload');
             $fileUploader->setMaximumFileSize(ini_get('upload_max_filesize'));
             $fileUploader->setFilterType('.jpg, .jpeg, .png, .bmp, .gif');
             $fileUploader->setIsEncryptFileName(true);
             if ($fileUploader->upload()) {
                 $data = $fileUploader->getData();
                 $banner->setFile('/media/banner/' . $data['file_name']);
             } else {
                 $uploadErr = $fileUploader->getError();
                 $error['banner.file'] = implode('.', $uploadErr);
             }
         }
         if (empty($error) && $banner->save()) {
             return true;
         }
         foreach ($banner->getValidationFailures() as $validationFailure) {
             $error[$validationFailure->getColumn()] = $validationFailure->getMessage();
         }
     }
     return false;
 }
Exemplo n.º 8
0
 public function afterDelete()
 {
     @unlink(\Flywheel\Util\Folder::clean(MEDIA_DIR . $this->getPath()));
     return parent::afterDelete();
 }
Exemplo n.º 9
0
 public function executeRemoveImg()
 {
     $file_name = $this->post('file_name');
     $item_id = $this->post('item_id');
     $res = new \AjaxResponse();
     $res->type = \AjaxResponse::ERROR;
     if (!$item_id || !($item = \Items::retrieveById($item_id))) {
         $res->message = t('Items not found');
         return $this->renderText($res->toString());
     }
     if ($file_name) {
         $file_path = MEDIA_DIR . '/product_img/' . $file_name;
         Folder::clean($file_path);
         $item->removeImage($file_name);
         if ($item->save(false)) {
             @unlink($file_path);
             $res->message = t('OK!');
             $res->type = \AjaxResponse::SUCCESS;
         } else {
             $res->message = t('Something went wrong, could not remove image');
         }
     }
     $item_img = $item->getImages();
     foreach ($item_img as &$img) {
         $img['url'] = rtrim($this->document()->getBaseUrl(), '/') . preg_replace('/(\\/+)/', '/', '/../' . $img['path']);
         $img['thumb_url'] = \Items::getImgThumbFromPath($img['path'], 52);
     }
     $res->images = $item_img;
     return $this->renderText($res->toString());
 }