Пример #1
0
 public function addTemplate($fileName, $roleIds = null, $default = false)
 {
     $canvasWidth = self::CANVAS_WIDTH;
     $canvasHeight = $this->config['cover_height'];
     $coverImage = new UTIL_Image($fileName);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $template = new UHEADER_BOL_Template();
     $extension = UTIL_File::getExtension($fileName);
     $template->file = uniqid('template-') . '.' . $extension;
     $template->default = $default;
     $template->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveTemplate($template);
     if ($roleIds !== null) {
         $this->service->saveRoleIdsForTemplateId($template->id, $roleIds);
     }
     $templatePath = $this->service->getTemplatePath($template);
     OW::getStorage()->copyFile($fileName, $templatePath);
 }
Пример #2
0
 public function copyBigAvatar($userId)
 {
     $avatarService = BOL_AvatarService::getInstance();
     $avatar = $avatarService->findByUserId($userId);
     if (!$avatar) {
         return false;
     }
     // remove old
     $this->removeBigAvatar($userId);
     $origAvatarPath = $avatarService->getAvatarPath($userId, 3);
     $tmpPath = $this->getAvatarPluginFilesPath($userId, $avatar->hash);
     if (!is_writable(dirname($tmpPath))) {
         return false;
     }
     $storage = OW::getStorage();
     $storage->copyFileToLocalFS($origAvatarPath, $tmpPath);
     $image = new UTIL_Image($tmpPath);
     $width = $image->getWidth();
     if ($width < self::BIG_AVATAR_WIDTH) {
         @unlink($tmpPath);
         return false;
     }
     // store new
     $newAvatar = new SKADATE_BOL_Avatar();
     $newAvatar->userId = $userId;
     $newAvatar->avatarId = $avatar->id;
     $newAvatar->hash = $avatar->hash;
     SKADATE_BOL_AvatarDao::getInstance()->save($newAvatar);
     $bigAvatarPath = $this->getAvatarPath($userId, $avatar->hash);
     $image->resizeImage(self::BIG_AVATAR_WIDTH, self::BIG_AVATAR_HEIGHT, true)->saveImage($tmpPath);
     $storage->copyFile($tmpPath, $bigAvatarPath);
     @unlink($tmpPath);
     return true;
 }
Пример #3
0
 public function uploadImage($uploadedFileName)
 {
     $image = new UTIL_Image($uploadedFileName);
     $imagePath = $this->getDefaultImagePath();
     $width = $image->getWidth();
     $height = $image->getHeight();
     $side = $width >= $height ? $height : $width;
     $side = $side > 200 ? 200 : $side;
     $image->resizeImage($side, $side, true)->saveImage($imagePath);
 }
Пример #4
0
 public function addFromPhotos($query)
 {
     $photoId = $query['photoId'];
     $groupId = $query['groupId'];
     if (!GHEADER_CLASS_CreditsBridge::getInstance()->credits->isAvaliable(GHEADER_CLASS_Credits::ACTION_ADD)) {
         $error = GHEADER_CLASS_CreditsBridge::getInstance()->credits->getErrorMessage(GHEADER_CLASS_Credits::ACTION_ADD);
         throw new InvalidArgumentException($error);
     }
     $sourcePath = GHEADER_CLASS_PhotoBridge::getInstance()->pullPhoto($photoId);
     if ($sourcePath === null) {
         throw new InvalidArgumentException("The requested photo wasn't find");
     }
     $canvasWidth = $query['width'];
     $canvasHeight = OW::getConfig()->getValue('gheader', 'cover_height');
     $coverImage = new UTIL_Image($sourcePath);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $this->validateImage($coverImage, $canvasWidth, $canvasHeight);
     $cover = $this->service->findCoverByGroupId($groupId, GHEADER_BOL_Cover::STATUS_TMP);
     if ($cover === null) {
         $cover = new GHEADER_BOL_Cover();
     }
     $extension = UTIL_File::getExtension($sourcePath);
     $cover->file = uniqid('cover-' . $groupId . '-') . '.' . $extension;
     $cover->groupId = $groupId;
     $cover->status = GHEADER_BOL_Cover::STATUS_TMP;
     $cover->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $cover->setSettings(array('photoId' => $photoId, 'dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveCover($cover);
     $coverPath = $this->service->getCoverPath($cover);
     OW::getStorage()->copyFile($sourcePath, $coverPath);
     @unlink($sourcePath);
     $coverUrl = $this->service->getCoverUrl($cover);
     return array('src' => $coverUrl, 'data' => $cover->getSettings());
 }
 public function moveTemporaryPhoto($tmpId, $albumId, $desc, $tag = NULL, $angle = 0, $uploadKey = null, $status = null)
 {
     $tmp = $this->photoTemporaryDao->findById($tmpId);
     $album = PHOTO_BOL_PhotoAlbumService::getInstance()->findAlbumById($albumId);
     if (!$tmp || !$album) {
         return FALSE;
     }
     $previewTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 1);
     $mainTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 2);
     $originalTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 3);
     $smallTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 4);
     $fullscreenTmp = $this->photoTemporaryDao->getTemporaryPhotoPath($tmp->id, 5);
     $privacy = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => $album->userId, 'action' => 'photo_view_album'));
     $photoService = PHOTO_BOL_PhotoService::getInstance();
     $photo = new PHOTO_BOL_Photo();
     $photo->description = htmlspecialchars(trim($desc));
     $photo->albumId = $albumId;
     $photo->addDatetime = time();
     $photo->status = empty($status) ? "approved" : $status;
     $photo->hasFullsize = (int) $tmp->hasFullsize;
     $photo->privacy = !empty($privacy) ? $privacy : 'everybody';
     $photo->hash = uniqid();
     $photo->uploadKey = empty($uploadKey) ? $photoService->getPhotoUploadKey($albumId) : $uploadKey;
     PHOTO_BOL_PhotoDao::getInstance()->save($photo);
     try {
         $storage = OW::getStorage();
         $dimension = array();
         if ((int) $angle !== 0) {
             $tmpImage = $tmp->hasFullsize ? (bool) OW::getConfig()->getValue('photo', 'store_fullsize') ? $originalTmp : $fullscreenTmp : $mainTmp;
             $smallImg = new UTIL_Image($tmpImage);
             $smallImg->resizeImage(PHOTO_BOL_PhotoService::DIM_SMALL_WIDTH, PHOTO_BOL_PhotoService::DIM_SMALL_HEIGHT, TRUE)->rotate($angle)->saveImage($smallTmp);
             $storage->copyFile($smallTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_SMALL));
             $dimension[PHOTO_BOL_PhotoService::TYPE_SMALL] = array($smallImg->getWidth(), $smallImg->getHeight());
             $smallImg->destroy();
             $previewImage = new UTIL_Image($tmpImage);
             $previewImage->resizeImage(PHOTO_BOL_PhotoService::DIM_PREVIEW_WIDTH, PHOTO_BOL_PhotoService::DIM_PREVIEW_HEIGHT)->rotate($angle)->saveImage($previewTmp);
             $storage->copyFile($previewTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_PREVIEW));
             $dimension[PHOTO_BOL_PhotoService::TYPE_PREVIEW] = array($previewImage->getWidth(), $previewImage->getHeight());
             $previewImage->destroy();
             $main = new UTIL_Image($tmpImage);
             $main->resizeImage(PHOTO_BOL_PhotoService::DIM_MAIN_WIDTH, PHOTO_BOL_PhotoService::DIM_MAIN_HEIGHT)->rotate($angle)->saveImage($mainTmp);
             $storage->copyFile($mainTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_MAIN));
             $dimension[PHOTO_BOL_PhotoService::TYPE_MAIN] = array($main->getWidth(), $main->getHeight());
             $main->destroy();
             $originalImage = new UTIL_Image($tmpImage);
             $originalImage->resizeImage(PHOTO_BOL_PhotoService::DIM_ORIGINAL_WIDTH, PHOTO_BOL_PhotoService::DIM_ORIGINAL_HEIGHT)->rotate($angle)->saveImage($originalTmp);
             $storage->copyFile($originalTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_ORIGINAL));
             $dimension[PHOTO_BOL_PhotoService::TYPE_ORIGINAL] = array($originalImage->getWidth(), $originalImage->getHeight());
             $originalImage->destroy();
             if ($tmp->hasFullsize && (bool) OW::getConfig()->getValue('photo', 'store_fullsize')) {
                 $fullscreen = new UTIL_Image($tmpImage);
                 $fullscreen->resizeImage(PHOTO_BOL_PhotoService::DIM_FULLSCREEN_WIDTH, PHOTO_BOL_PhotoService::DIM_FULLSCREEN_HEIGHT)->rotate($angle)->saveImage($fullscreenTmp);
                 $storage->copyFile($fullscreenTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_FULLSCREEN));
                 $dimension[PHOTO_BOL_PhotoService::TYPE_FULLSCREEN] = array($fullscreen->getWidth(), $fullscreen->getHeight());
                 $fullscreen->destroy();
             }
         } else {
             $storage->copyFile($smallTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_SMALL));
             list($width, $height) = getimagesize($smallTmp);
             $dimension[PHOTO_BOL_PhotoService::TYPE_SMALL] = array($width, $height);
             $storage->copyFile($previewTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_PREVIEW));
             list($width, $height) = getimagesize($previewTmp);
             $dimension[PHOTO_BOL_PhotoService::TYPE_PREVIEW] = array($width, $height);
             $storage->copyFile($mainTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_MAIN));
             list($width, $height) = getimagesize($mainTmp);
             $dimension[PHOTO_BOL_PhotoService::TYPE_MAIN] = array($width, $height);
             $storage->copyFile($originalTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_ORIGINAL));
             list($width, $height) = getimagesize($originalTmp);
             $dimension[PHOTO_BOL_PhotoService::TYPE_ORIGINAL] = array($width, $height);
             if ($tmp->hasFullsize && (bool) OW::getConfig()->getValue('photo', 'store_fullsize')) {
                 $storage->copyFile($fullscreenTmp, $photoService->getPhotoPath($photo->id, $photo->hash, PHOTO_BOL_PhotoService::TYPE_FULLSCREEN));
                 list($width, $height) = getimagesize($fullscreenTmp);
                 $dimension[PHOTO_BOL_PhotoService::TYPE_FULLSCREEN] = array($width, $height);
             }
         }
         $photo->setDimension(json_encode($dimension));
         PHOTO_BOL_PhotoDao::getInstance()->save($photo);
         if (mb_strlen($desc)) {
             BOL_TagService::getInstance()->updateEntityTags($photo->id, 'photo', $photoService->descToHashtag($desc));
         }
         if (mb_strlen($tag)) {
             BOL_TagService::getInstance()->updateEntityTags($photo->id, 'photo', explode(',', $tag));
         }
         OW::getEventManager()->trigger(new OW_Event('photo.onMoveTemporaryPhoto', array('tmpId' => $tmpId, 'albumId' => $albumId, 'photoId' => $photo->id)));
     } catch (Exception $e) {
         $photo = NULL;
     }
     return $photo;
 }
Пример #6
0
 public function cropTempAvatar($key, $coords, $viewSize)
 {
     $originalPath = $this->getTempAvatarPath($key, 3);
     $bigAvatarPath = $this->getTempAvatarPath($key, 2);
     $avatarPath = $this->getTempAvatarPath($key, 1);
     $image = new UTIL_Image($originalPath);
     $width = $image->getWidth();
     $k = $width / $viewSize;
     $config = OW::getConfig();
     $avatarSize = (int) $config->getValue('base', 'avatar_size');
     $bigAvatarSize = (int) $config->getValue('base', 'avatar_big_size');
     $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k)->resizeImage($bigAvatarSize, $bigAvatarSize, true)->saveImage($bigAvatarPath)->resizeImage($avatarSize, $avatarSize, true)->saveImage($avatarPath);
     return true;
 }
Пример #7
0
 private function addTemplate($file, $roleId = null)
 {
     $canvasWidth = self::CANVAS_WIDTH;
     $canvasHeight = $this->config['cover_height'];
     $this->validateFile($file);
     $pluginfilesDir = OW::getPluginManager()->getPlugin('uheader')->getPluginFilesDir();
     $tmpTplPath = $pluginfilesDir . uniqid('tmp_') . '.jpg';
     if (!move_uploaded_file($file['tmp_name'], $tmpTplPath)) {
         throw new InvalidArgumentException('Moving uploaded file faild');
     }
     $coverImage = new UTIL_Image($tmpTplPath);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $this->validateImage($coverImage, $canvasWidth, $canvasHeight);
     $template = new UHEADER_BOL_Template();
     $extension = UTIL_File::getExtension($file['name']);
     $template->file = uniqid('template-') . '.' . $extension;
     $template->default = false;
     $template->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveTemplate($template);
     if ($roleId !== null) {
         $this->service->saveRoleIdsForTemplateId($template->id, array($roleId));
     }
     $templatePath = $this->service->getTemplatePath($template);
     OW::getStorage()->copyFile($tmpTplPath, $templatePath);
     @unlink($tmpTplPath);
 }
Пример #8
0
 /**
  * Replaces slide image with a new one 
  * 
  * @param $slideId
  * @param $file
  */
 public function updateSlideImage($slideId, $file)
 {
     if (!$slideId) {
         return false;
     }
     $storage = OW::getStorage();
     $slide = $this->findSlideById($slideId);
     $oldPath = $this->getImageDir($slide->id, $slide->widgetId, $slide->addStamp, $slide->ext);
     $ext = UTIL_File::getExtension($file['name']);
     $newAddStamp = time();
     $tmpPath = $this->getImageTmpDir($slide->id, $slide->widgetId, $newAddStamp, $slide->ext);
     $destPath = $this->getImageDir($slide->id, $slide->widgetId, $newAddStamp, $slide->ext);
     if (move_uploaded_file($file['tmp_name'], $tmpPath)) {
         $image = new UTIL_Image($tmpPath);
         $image->resizeImage(1000, null)->saveImage($tmpPath);
         $slide->width = $image->getWidth();
         $slide->height = $image->getHeight();
         $slide->ext = $ext;
         $slide->addStamp = $newAddStamp;
         $this->slideDao->save($slide);
         $storage->removeFile($oldPath);
         $storage->copyFile($tmpPath, $destPath);
         @unlink($tmpPath);
         return true;
     }
     return false;
 }
Пример #9
0
 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));
 }
Пример #10
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');
 }
Пример #11
0
 /**
  * Crops user avatar using coordinates
  *
  * @param int $userId
  * @param array $coords
  * @param int $viewSize
  * @param int $hash
  */
 public function cropAvatar($userId, $coords, $viewSize, $hash)
 {
     if (!empty($coords)) {
         $origAvatarPath = $this->getAvatarPath($userId, 3);
         // tmp file in pluginfiles
         $tmpPath = $this->getAvatarPluginFilesPath($userId, 3, $hash);
         $storage = OW::getStorage();
         $storage->copyFileToLocalFS($origAvatarPath, $tmpPath);
         $image = new UTIL_Image($tmpPath);
         $width = $image->getWidth();
         $height = $image->getHeight();
         $k = $width / $viewSize;
         $config = OW::getConfig();
         $avatarSize = (int) $config->getValue('base', 'avatar_size');
         $bigAvatarSize = (int) $config->getValue('base', 'avatar_big_size');
         $avatarPath = $this->getAvatarPath($userId, 1, $hash);
         $bigAvatarPath = trim($this->getAvatarPath($userId, 2, $hash));
         // pluginfiles tmp path
         $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $hash);
         $bigAvatarPFPath = trim($this->getAvatarPluginFilesPath($userId, 2, $hash));
         $image->cropImage($coords['x'] * $k, $coords['y'] * $k, $coords['w'] * $k, $coords['h'] * $k)->resizeImage($bigAvatarSize, $bigAvatarSize, true)->saveImage($bigAvatarPFPath)->resizeImage($avatarSize, $avatarSize, true)->saveImage($avatarPFPath);
         $storage->copyFile($bigAvatarPFPath, $bigAvatarPath);
         $storage->copyFile($avatarPFPath, $avatarPath);
         @unlink($tmpPath);
         @unlink($avatarPFPath);
         @unlink($bigAvatarPFPath);
     }
 }
Пример #12
0
 public function addFromPhotos($query)
 {
     $photoId = $query['photoId'];
     $userId = OW::getUser()->getId();
     $this->checkCredits();
     $sourcePath = UHEADER_CLASS_PhotoBridge::getInstance()->pullPhoto($photoId);
     if ($sourcePath === null) {
         throw new InvalidArgumentException("The requested photo wasn't find");
     }
     $coverDefaultHeight = OW::getConfig()->getValue('uheader', 'cover_height');
     $canvasWidth = $query['width'];
     $canvasHeight = $query['height'] < $coverDefaultHeight ? $coverDefaultHeight : $query['height'];
     $coverImage = new UTIL_Image($sourcePath);
     $imageHeight = $coverImage->getHeight();
     $imageWidth = $coverImage->getWidth();
     $css = array('width' => 'auto', 'height' => 'auto');
     $tmp = $canvasWidth * $imageHeight / $imageWidth;
     if ($tmp >= $canvasHeight) {
         $css['width'] = '100%';
     } else {
         $css['height'] = '100%';
     }
     $this->validateImage($coverImage, $canvasWidth, $canvasHeight);
     // Saving the cover
     $cover = $this->service->findCoverByUserId($userId, UHEADER_BOL_Cover::STATUS_TMP);
     if ($cover === null) {
         $cover = new UHEADER_BOL_Cover();
     }
     $extension = UTIL_File::getExtension($sourcePath);
     $cover->file = uniqid('cover-' . $userId . '-') . '.' . $extension;
     $cover->userId = $userId;
     $cover->status = UHEADER_BOL_Cover::STATUS_TMP;
     $cover->timeStamp = time();
     $dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
     $cover->setSettings(array('photoId' => $photoId, 'dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
     $this->service->saveCover($cover);
     $coverPath = $this->service->getCoverPath($cover);
     OW::getStorage()->copyFile($sourcePath, $coverPath);
     @unlink($sourcePath);
     $coverUrl = $this->service->getCoverUrl($cover);
     return array('src' => $coverUrl, 'data' => $cover->getSettings(), 'ratio' => $cover->getRatio(), "mode" => "reposition");
 }
Пример #13
0
 /**
  *
  * @return PHOTO_BOL_Photo
  */
 private function upload($userId, $path, $description, $tagData)
 {
     $pluginfilesDir = $this->plugin->getPluginFilesDir();
     $source = $pluginfilesDir . uniqid('tmp_') . '.jpg';
     if (!@OW::getStorage()->copyFileToLocalFS($path, $source)) {
         return null;
     }
     $photoService = PHOTO_BOL_PhotoService::getInstance();
     $album = $this->getAlbum($userId);
     $privacy = OW::getEventManager()->call('plugin.privacy.get_privacy', array('ownerId' => $userId, 'action' => 'photo_view_album'));
     $photo = new PHOTO_BOL_Photo();
     $photo->description = htmlspecialchars($description);
     $photo->albumId = $album->id;
     $photo->addDatetime = time();
     $photo->status = 'approved';
     $photo->hasFullsize = true;
     $photo->privacy = mb_strlen($privacy) ? $privacy : 'everybody';
     $photoService->addPhoto($photo);
     $config = OW::getConfig();
     $width = $config->getValue('photo', 'main_image_width');
     $height = $config->getValue('photo', 'main_image_height');
     $previewWidth = $config->getValue('photo', 'preview_image_width');
     $previewHeight = $config->getValue('photo', 'preview_image_height');
     $tmpMainPath = $pluginfilesDir . 'main_' . $photo->id . '.jpg';
     $tmpPreviewPath = $pluginfilesDir . 'preview_' . $photo->id . '.jpg';
     $tmpOriginalPath = $pluginfilesDir . 'original_' . $photo->id . '.jpg';
     try {
         $image = new UTIL_Image($source);
         $tagCoords = $this->getTagRealCoords($tagData, $image->getWidth(), $image->getHeight(), $previewWidth, $previewHeight);
         $mainPhoto = $image->resizeImage($width, $height)->saveImage($tmpMainPath);
         //Cropping tag
         if (!empty($tagCoords["crop"])) {
             $mainPhoto->cropImage($tagCoords["crop"]["left"], $tagCoords["crop"]["top"], $tagCoords["crop"]["width"], $tagCoords["crop"]["height"]);
         }
         if (!empty($tagCoords["resize"])) {
             $mainPhoto->resizeImage($tagCoords["resize"]["width"], $tagCoords["resize"]["height"], $tagCoords["resize"]["crop"]);
         }
         $mainPhoto->saveImage($tmpPreviewPath);
         if ($config->getValue('photo', 'store_fullsize') && $mainPhoto->imageResized()) {
             $originalImage = new UTIL_Image($source);
             $res = (int) $config->getValue('photo', 'fullsize_resolution');
             $res = $res ? $res : 1024;
             $originalImage->resizeImage($res, $res)->saveImage($tmpOriginalPath);
             $photo->hasFullsize = true;
         } else {
             $photo->hasFullsize = false;
             $photoService->updatePhoto($photo);
         }
     } catch (WideImage_Exception $e) {
         @unlink($source);
         return null;
     }
     @unlink($source);
     $storage = OW::getStorage();
     $mainPath = $photoService->getPhotoPath($photo->id, $photo->hash);
     $previewPath = $photoService->getPhotoPath($photo->id, $photo->hash, 'preview');
     $originalPath = $photoService->getPhotoPath($photo->id, $photo->hash, 'original');
     $storage->copyFile($tmpMainPath, $mainPath);
     @unlink($tmpMainPath);
     $storage->copyFile($tmpPreviewPath, $previewPath);
     @unlink($tmpPreviewPath);
     if ($photo->hasFullsize) {
         $storage->copyFile($tmpOriginalPath, $originalPath);
         @unlink($tmpOriginalPath);
     }
     return $photo;
 }
Пример #14
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;
 }
Пример #15
0
    OW::getConfig()->addConfig('socialsharing', 'place_photo', '1');
}

if ( !OW::getConfig()->configExists('socialsharing', 'place_video') )
{
    OW::getConfig()->addConfig('socialsharing', 'place_video', '1');
}

if ( !OW::getConfig()->configExists('socialsharing', 'place_forum') )
{
    OW::getConfig()->addConfig('socialsharing', 'place_forum', '1');
}

if ( !OW::getConfig()->configExists('socialsharing', 'place_links') )
{
    OW::getConfig()->addConfig('socialsharing', 'place_links', '1');
}

if ( !OW::getConfig()->configExists('socialsharing', 'place_virtual gifts') )
{
    OW::getConfig()->addConfig('socialsharing', 'place_virtual gifts', '1');
} */
OW::getPluginManager()->addPluginSettingsRouteName('socialsharing', 'socialsharing.admin');
BOL_LanguageService::getInstance()->importPrefixFromZip(OW_DIR_PLUGIN . 'social_sharing' . DS . 'langs.zip', 'socialsharing');
$image = new UTIL_Image(OW::getPluginManager()->getPlugin('socialsharing')->getRootDir() . 'install' . DS . 'default.jpg');
$imagePath = OW::getPluginManager()->getPlugin('socialsharing')->getUserFilesDir() . 'default.jpg';
$width = $image->getWidth();
$height = $image->getHeight();
$side = $width >= $height ? $height : $width;
$side = $side > 200 ? 200 : $side;
$image->resizeImage($side, $side, true)->saveImage($imagePath);
Пример #16
0
 /**
  * Add file
  * 
  * @param string $plugin
  * @return integer|string
  */
 public static function addFile($plugin)
 {
     $uploaddir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir();
     $name = $_FILES['file']['name'];
     if (!UTIL_File::validateImage($name)) {
         return OW::getLanguage()->text('base', 'invalid_file_type_acceptable_file_types_jpg_png_gif');
     }
     $tmpname = $_FILES['file']['tmp_name'];
     if ((int) $_FILES['file']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
         return OW::getLanguage()->text('base', 'upload_file_max_upload_filesize_error');
     }
     $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));
     OW::getStorage()->copyFile($tmpname, $uploaddir . $id . '-' . $name);
     @unlink($tmpname);
     return $id;
 }