Exemple #1
0
 public static function process($plugin, $params)
 {
     $language = OW::getLanguage();
     $uploaddir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir();
     $name = $_FILES['file']['name'];
     if (!UTIL_File::validateImage($name)) {
         OW::getFeedback()->error("Invalid file type. Acceptable file types: JPG/PNG/GIF");
         OW::getApplication()->redirect();
     }
     $tmpname = $_FILES['file']['tmp_name'];
     if ((int) $_FILES['file']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
         OW::getFeedback()->error($language->text('base', 'upload_file_max_upload_filesize_error'));
         OW::getApplication()->redirect();
     }
     $image = new UTIL_Image($tmpname);
     $height = $image->getHeight();
     $width = $image->getWidth();
     $id = BOL_MediaPanelService::getInstance()->add($plugin, 'image', OW::getUser()->getId(), array('name' => $name, 'height' => $height, 'width' => $width));
     $uploadFilePath = $uploaddir . $id . '-' . $name;
     $tmpUploadFilePath = $uploaddir . 'tmp_' . $id . '-' . $name;
     $image->saveImage($tmpUploadFilePath);
     $storage = OW::getStorage();
     $storage->copyFile($tmpUploadFilePath, $uploadFilePath);
     @unlink($tmpUploadFilePath);
     $params['pid'] = $id;
     OW::getApplication()->redirect(OW::getRouter()->urlFor('BASE_CTRL_MediaPanel', 'gallery', $params) . '#bottom');
 }
 public function cropAlbumCover(PHOTO_BOL_PhotoAlbum $album, $coords, $viewSize, $photoId = 0)
 {
     if (!empty($photoId) && ($photo = $this->photoDao->findById($photoId)) !== NULL) {
         $path = $this->photoDao->getPhotoPath($photo->id, $photo->hash, 'main');
     } else {
         $path = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathByAlbumId($album->id);
     }
     $storage = OW::getStorage();
     $tmpPath = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg';
     $storage->copyFileToLocalFS($path, $tmpPath);
     if (($coverDto = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->findByAlbumId($album->id)) === NULL) {
         $coverDto = new PHOTO_BOL_PhotoAlbumCover();
         $coverDto->albumId = $album->id;
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
     }
     $oldCover = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto);
     $oldCoverOrig = PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto);
     $coverDto->hash = uniqid();
     $coverDto->auto = 0;
     try {
         $image = new UTIL_Image($tmpPath);
         if ($image->getWidth() >= $coords['w'] && $coords['w'] > 0 && $image->getHeight() >= $coords['h'] && $coords['h'] > 0) {
             $width = $image->getWidth();
             $k = $width / $viewSize;
             $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k);
         }
         $saveImage = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(time(), TRUE) . '.jpg';
         $image->saveImage($saveImage);
         $image->destroy();
         $storage->copyFile($saveImage, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto));
         $storage->copyFile($tmpPath, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto));
         $storage->removeFile($oldCover);
         $storage->removeFile($oldCoverOrig);
         @unlink($saveImage);
         @unlink($tmpPath);
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
     } catch (Exception $e) {
         return FALSE;
     }
     return array('cover' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverUrlForCoverEntity($coverDto), 'coverOrig' => PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigUrlForCoverEntity($coverDto));
 }
Exemple #3
0
 public function createAlbumCover($albumId, array $photos)
 {
     if (empty($albumId) || count($photos) === 0 || PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->isAlbumCoverExist($albumId)) {
         return FALSE;
     }
     foreach ($photos as $photo) {
         $path = $this->getPhotoPath($photo->id, $photo->hash, 'main');
         $storage = OW::getStorage();
         if (!$storage->fileExists($path)) {
             continue;
         }
         $tmpPathCrop = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg';
         $tmpPathOrig = OW::getPluginManager()->getPlugin('photo')->getPluginFilesDir() . uniqid(uniqid(), TRUE) . '.jpg';
         if (!$storage->copyFileToLocalFS($path, $tmpPathOrig)) {
             continue;
         }
         $info = getimagesize($tmpPathOrig);
         if ($info['0'] < 330 || $info['1'] < 330) {
             @unlink($tmpPathOrig);
             continue;
         }
         $coverDto = new PHOTO_BOL_PhotoAlbumCover();
         $coverDto->albumId = $albumId;
         $coverDto->hash = uniqid();
         PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->save($coverDto);
         $image = new UTIL_Image($tmpPathOrig);
         $left = $image->getWidth() / 2 - 165;
         $top = $image->getHeight() / 2 - 165;
         $image->cropImage($left, $top, 330, 330);
         $image->saveImage($tmpPathCrop);
         $image->destroy();
         $storage->copyFile($tmpPathCrop, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverPathForCoverEntity($coverDto));
         $storage->copyFile($tmpPathOrig, PHOTO_BOL_PhotoAlbumCoverDao::getInstance()->getAlbumCoverOrigPathForCoverEntity($coverDto));
         @unlink($tmpPathCrop);
         @unlink($tmpPathOrig);
         return TRUE;
     }
     return FALSE;
 }