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; }
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); }
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); }
public function copy_resize_image($tmp_name, $slugimage, $idThumb, $extension, $width = null, $height = null) { if ($extension == null) { $extension = ''; } $storage = OW::getStorage(); $imagesDir = OW::getPluginManager()->getPlugin('spdownload')->getUserFilesDir(); $imageName = $slugimage . '_' . $idThumb . '.' . $extension; $imagePath = $imagesDir . $imageName; $pluginfilesDir = Ow::getPluginManager()->getPlugin('spdownload')->getPluginFilesDir(); $tmpImgPath = $slugimage . '_' . $idThumb . '.' . $extension; $image = new UTIL_Image($tmp_name); $image->resizeImage($width, $height)->saveImage($tmpImgPath); //Copy file into storage folder $storage->copyFile($tmpImgPath, $imagePath); unlink($tmpImgPath); }
/** * 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; }
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; }
protected function saveImages($postFile, GROUPS_BOL_Group $group) { $service = GROUPS_BOL_Service::getInstance(); $smallFile = $service->getGroupImagePath($group, GROUPS_BOL_Service::IMAGE_SIZE_SMALL); $bigFile = $service->getGroupImagePath($group, GROUPS_BOL_Service::IMAGE_SIZE_BIG); $tmpDir = OW::getPluginManager()->getPlugin('groups')->getPluginFilesDir(); $smallTmpFile = $tmpDir . uniqid('small_') . '.jpg'; $bigTmpFile = $tmpDir . uniqid('big_') . '.jpg'; $image = new UTIL_Image($postFile['tmp_name']); $image->resizeImage(GROUPS_BOL_Service::IMAGE_WIDTH_BIG, null)->saveImage($bigTmpFile)->resizeImage(GROUPS_BOL_Service::IMAGE_WIDTH_SMALL, GROUPS_BOL_Service::IMAGE_WIDTH_SMALL, true)->saveImage($smallTmpFile); try { OW::getStorage()->copyFile($smallTmpFile, $smallFile); OW::getStorage()->copyFile($bigTmpFile, $bigFile); } catch (Exception $e) { } unlink($smallTmpFile); unlink($bigTmpFile); }
/** * Makes and saves event standard image and icon. * * @param string $imagePath * @param integer $imageId */ public function saveEventImage($imagePath, $imageId) { $storage = OW::getStorage(); if ($storage->fileExists($this->generateImagePath($imageId))) { $storage->removeFile($this->generateImagePath($imageId)); $storage->removeFile($this->generateImagePath($imageId, false)); } $pluginfilesDir = Ow::getPluginManager()->getPlugin('event')->getPluginFilesDir(); $tmpImgPath = $pluginfilesDir . 'img_' . uniqid() . '.jpg'; $tmpIconPath = $pluginfilesDir . 'icon_' . uniqid() . '.jpg'; $image = new UTIL_Image($imagePath); $image->resizeImage(400, null)->saveImage($tmpImgPath)->resizeImage(100, 100, true)->saveImage($tmpIconPath); unlink($imagePath); $storage->copyFile($tmpIconPath, $this->generateImagePath($imageId)); $storage->copyFile($tmpImgPath, $this->generateImagePath($imageId, false)); unlink($tmpImgPath); unlink($tmpIconPath); }
public function saveImage($goalId, $imagePath, $imageId) { $storage = OW::getStorage(); $goal = $this->goalDao->findById($goalId); if (!$imageId) { $imageId = uniqid(); $goal->image = $imageId; $this->goalDao->save($goal); } elseif ($storage->fileExists($this->generateImagePath($imageId))) { $storage->removeFile($this->generateImagePath($imageId)); $storage->removeFile($this->generateImagePath($imageId, false)); $imageId = uniqid(); $goal->image = $imageId; $this->goalDao->save($goal); } $pluginfilesDir = Ow::getPluginManager()->getPlugin('ocsfundraising')->getPluginFilesDir(); $tmpImgPath = $pluginfilesDir . 'project_image_' . $imageId . '.jpg'; $tmpIconPath = $pluginfilesDir . 'project_icon_' . $imageId . '.jpg'; $image = new UTIL_Image($imagePath); $image->resizeImage(300, null)->saveImage($tmpImgPath)->resizeImage(170, 130, true)->saveImage($tmpIconPath); unlink($imagePath); $storage->copyFile($tmpIconPath, $this->generateImagePath($imageId)); $storage->copyFile($tmpImgPath, $this->generateImagePath($imageId, false)); unlink($tmpImgPath); unlink($tmpIconPath); }
public function processUploadedFile($pluginKey, array $fileInfo, $bundle = null, $validFileExtensions = array(), $maxUploadSize = null, $dimensions = null) { $language = OW::getLanguage(); $error = false; if (!OW::getUser()->isAuthenticated()) { throw new InvalidArgumentException($language->text('base', 'user_is_not_authenticated')); } if (empty($fileInfo) || !is_uploaded_file($fileInfo['tmp_name'])) { throw new InvalidArgumentException($language->text('base', 'upload_file_fail')); } if ($fileInfo['error'] != UPLOAD_ERR_OK) { switch ($fileInfo['error']) { case UPLOAD_ERR_INI_SIZE: $error = $language->text('base', 'upload_file_max_upload_filesize_error'); break; case UPLOAD_ERR_PARTIAL: $error = $language->text('base', 'upload_file_file_partially_uploaded_error'); break; case UPLOAD_ERR_NO_FILE: $error = $language->text('base', 'upload_file_no_file_error'); break; case UPLOAD_ERR_NO_TMP_DIR: $error = $language->text('base', 'upload_file_no_tmp_dir_error'); break; case UPLOAD_ERR_CANT_WRITE: $error = $language->text('base', 'upload_file_cant_write_file_error'); break; case UPLOAD_ERR_EXTENSION: $error = $language->text('base', 'upload_file_invalid_extention_error'); break; default: $error = $language->text('base', 'upload_file_fail'); } throw new InvalidArgumentException($error); } if (empty($validFileExtensions)) { $validFileExtensions = json_decode(OW::getConfig()->getValue('base', 'attch_ext_list'), true); } if ($maxUploadSize === null) { $maxUploadSize = OW::getConfig()->getValue('base', 'attch_file_max_size_mb'); } if (!empty($validFileExtensions) && !in_array(UTIL_File::getExtension($fileInfo['name']), $validFileExtensions)) { throw new InvalidArgumentException($language->text('base', 'upload_file_extension_is_not_allowed')); } // get all bundle upload size $bundleSize = floor($fileInfo['size'] / 1024); if ($bundle !== null) { $list = $this->attachmentDao->findAttahcmentByBundle($pluginKey, $bundle); /* @var $item BOL_Attachment */ foreach ($list as $item) { $bundleSize += $item->getSize(); } } if ($maxUploadSize > 0 && $bundleSize > $maxUploadSize * 1024) { throw new InvalidArgumentException($language->text('base', 'upload_file_max_upload_filesize_error')); } $attachDto = new BOL_Attachment(); $attachDto->setUserId(OW::getUser()->getId()); $attachDto->setAddStamp(time()); $attachDto->setStatus(0); $attachDto->setSize(floor($fileInfo['size'] / 1024)); $attachDto->setOrigFileName(htmlspecialchars($fileInfo['name'])); $attachDto->setFileName(uniqid() . '_' . UTIL_File::sanitizeName($attachDto->getOrigFileName())); $attachDto->setPluginKey($pluginKey); if ($bundle !== null) { $attachDto->setBundle($bundle); } $this->attachmentDao->save($attachDto); $uploadPath = $this->getAttachmentsDir() . $attachDto->getFileName(); $tempPath = $this->getAttachmentsDir() . 'temp_' . $attachDto->getFileName(); if (in_array(UTIL_File::getExtension($fileInfo['name']), array('jpg', 'jpeg', 'gif', 'png'))) { try { $image = new UTIL_Image($fileInfo['tmp_name']); if (empty($dimensions)) { $dimensions = array('width' => 1000, 'height' => 1000); } $image->resizeImage($dimensions['width'], $dimensions['height'])->orientateImage()->saveImage($tempPath); $image->destroy(); @unlink($fileInfo['tmp_name']); } catch (Exception $e) { throw new InvalidArgumentException($language->text('base', 'upload_file_fail')); } } else { move_uploaded_file($fileInfo['tmp_name'], $tempPath); } OW::getStorage()->copyFile($tempPath, $uploadPath); OW::getStorage()->chmod($uploadPath, 0666); unlink($tempPath); return array('uid' => $attachDto->getBundle(), 'dto' => $attachDto, 'path' => $uploadPath, 'url' => $this->getAttachmentsUrl() . $attachDto->getFileName()); }
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"); }
/** * * @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; }
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; }
public function toplinklist($curr = null) { OW::getDocument()->addStyleSheet(OW::getPluginManager()->getPlugin('toplink')->getStaticCssUrl() . 'style.css'); OW::getDocument()->addScript(OW::getPluginManager()->getPlugin('toplink')->getStaticJsUrl() . 'toplink.js'); $currId = @$curr['id']; $topForm = new Form("topForm"); $topForm->setEnctype('multipart/form-data'); $topSubmit = new Submit("topSubmit"); $topForm->addElement($topSubmit); $topName = new TextField("topName"); $topUrl = new TextField("topUrl"); $topIcon = new TextField("topIcon"); $topId = new HiddenField("topId"); $uploadIcon = new FileField('topIconFile'); $uploadIcon->setLabel($this->text('toplink', 'new_icon')); $topOrder = new TextField('toporder'); $topTarget = new CheckboxField('toptarget'); $topPermission = new CheckboxGroup('toppermission'); $topPermission->setColumnCount(1); $topPermission->setLabel($this->text('toplink', 'new_permission')); $availableDesc = TOPLINK_BOL_Service::$visibility; $topPermission->addOptions($availableDesc); $topOrder->setLabel($this->text('toplink', 'new_order')); $topOrder->setRequired(); $topTarget->setLabel($this->text('toplink', 'new_target')); $topName->setLabel($this->text('toplink', 'new_name')); //$topName->setRequired(); $topUrl->setLabel($this->text('toplink', 'new_url')); $topUrl->setRequired(); $topIcon->setLabel($this->text('toplink', 'new_icon')); if (!empty($currId) && !OW::getRequest()->isPost()) { $theTopLink = $this->myService->getTopLinkById($currId); $topName->setValue($theTopLink->itemname); $topId->setValue($currId); $topUrl->setValue($theTopLink->url); $topIcon->setValue($theTopLink->icon); $topTarget->setValue($theTopLink->target); $topOrder->setValue($theTopLink->order); $theTopLinkChild = $this->myService->getTopLinkChildObjectByParentId($currId); $theTopLinkPermission = $this->myService->getTopLinkPermissionById($currId); if (!empty($theTopLinkPermission)) { $i = 1; foreach ($theTopLinkPermission as $topLinkPermission) { $permissionOption[$i] = $topLinkPermission->availablefor; $i++; } $topPermission->setValue($permissionOption); } } $topForm->addElement($topName); $topForm->addElement($topUrl); $topForm->addElement($topIcon); $topForm->addElement($topId); $topForm->addElement($topTarget); $topForm->addElement($topOrder); $topForm->addElement($uploadIcon); $topForm->addElement($topPermission); $this->addForm($topForm); /* --- form submit --- */ $childrenNameList = @$_REQUEST['menuchildname']; $childrenUrlList = @$_REQUEST['menuchildurl']; $childrenIDList = @$_REQUEST['menuchildid']; if (OW::getRequest()->isPost()) { if ($topForm->isValid($_POST)) { $fdata = $topForm->getValues(); $newtoplink = new TOPLINK_BOL_Toplink(); $newtoplink->id = $fdata['topId']; $newtoplink->itemname = $fdata['topName']; $theurl = $fdata['topUrl']; if (!empty($theurl)) { $theurl = preg_match("/^http/", $theurl) ? $theurl : "http://" . $theurl; } else { $theurl = "#"; } $newtoplink->url = $theurl; /* check file exist */ if (!empty($fdata['topIcon']) && preg_match("/^\\//", $fdata['topIcon'])) { $newtoplink->icon = $fdata['topIcon']; $iconFileName = preg_replace("/^\\//", "", $newtoplink->icon); if (!file_exists($this->iconDir . $iconFileName)) { $newtoplink->icon = null; } } /* end */ $newtoplink->target = $fdata['toptarget']; $newtoplink->order = empty($fdata['toporder']) ? 5 : $fdata['toporder']; $loadedExts = get_loaded_extensions(); if (in_array('imagick', $loadedExts)) { $this->iMagicInstalled = true; } if ($_FILES['topIconFile']['error'] == 0) { $ext = explode('.', $_FILES['topIconFile']['name']); $ext = end($ext); if ($this->iMagicInstalled) { $image = new Imagick($_FILES['topIconFile']['tmp_name']); $image->thumbnailImage(16, 0); file_put_contents($this->iconDir . $_FILES['topIconFile']['name'] . '.png', $image); $uploadresult = $_FILES['topIconFile']['name'] . '.png'; } else { try { $image = new UTIL_Image($_FILES['topIconFile']['tmp_name'], 'PNG'); $image->resizeImage(16, 16, false)->saveImage($this->iconDir . $_FILES['topIconFile']['name'] . '.png'); $uploadresult = $_FILES['topIconFile']['name'] . '.png'; } catch (Exception $e) { $uploadresult = null; } } if ($uploadresult) { $newtoplink->icon = "/" . $uploadresult; } /* check file exist AGAIN AFTER UPLOAD */ if ($newtoplink->icon && preg_match("/^\\//", $newtoplink->icon)) { $iconFileName = preg_replace("/^\\//", "", $newtoplink->icon); if (!file_exists($this->iconDir . $iconFileName)) { $newtoplink->icon = null; } } /* end */ } $permission = $fdata['toppermission']; //save link $newid = $this->myService->saveToplink($newtoplink, $permission); $toplinkid = !empty($newtoplink->id) ? $newtoplink->id : $newid; $childIds = $this->myService->getTopLinkChildIdByParentId($toplinkid); if (!empty($childIds)) { if (!empty($childrenIDList)) { foreach ($childIds as $cid) { if (!in_array($cid, $childrenIDList)) { $this->myService->removeToplinkChild($cid); } } } else { foreach ($childIds as $cid) { $this->myService->removeToplinkChild($cid); } } } //process children if any if (!empty($childrenNameList) && !empty($childrenUrlList)) { foreach ($childrenNameList as $childIndex => $childName) { if (!empty($childName) && !empty($childrenUrlList[$childIndex])) { $childDoa = new TOPLINK_BOL_ToplinkChildren(); $childDoa->childof = $toplinkid; $childDoa->name = $childName; if (!empty($childrenUrlList[$childIndex])) { $thecurl = preg_match("/^http/", $childrenUrlList[$childIndex]) ? $childrenUrlList[$childIndex] : "http://" . $childrenUrlList[$childIndex]; } else { $thecurl = "#"; } $childDoa->url = $thecurl; if (!empty($childrenIDList[$childIndex])) { $childDoa->id = $childrenIDList[$childIndex]; } $this->myService->saveTopLinkChild($childDoa); } } } OW::getFeedback()->info($this->text('toplink', 'save_success_message')); $this->redirect(OW::getRouter()->urlForRoute('toplink.admin')); } } $alltoplink = $this->myService->getTopLink(true); $updatelink = array(); if (!empty($alltoplink)) { foreach ($alltoplink as $toplinkId => $toplink) { $toplink->itemname = empty($toplink->itemname) ? $this->text('toplink', 'top_link_no_name') : $toplink->itemname; $permissionx = array(); $theTopLinkPermission = $this->myService->getTopLinkPermissionById($toplink->id); foreach ($theTopLinkPermission as $topLinkPermission) { $permissionx[] = ucwords($availableDesc[$topLinkPermission->availablefor]); } $toplink->permission = !empty($permissionx) ? implode(',', $permissionx) : ''; $toplink->updateurl = OW::getRouter()->urlForRoute('toplink.admin2', array('id' => $toplink->id)); $toplink->removeurl = OW::getRouter()->urlForRoute('toplink.remove', array('id' => $toplink->id)); $alltoplink[$toplinkId] = $toplink; } } if (!empty($theTopLinkChild)) { $this->assign('children', $theTopLinkChild); } $this->assign('alltoplink', $alltoplink); }
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);
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); }
public function image_copy_resize($file_source = "", $file_dest = "", $crop = false, $width = 800, $height = 600) { if ($file_source and $file_dest) { $image = new UTIL_Image($file_source); $mainPhoto = $image->resizeImage($width, $height, $crop)->saveImage($file_dest); return true; } else { return false; } }
public function setUserAvatar($userId, $uploadedFileName) { $avatar = $this->findByUserId($userId); if (!$avatar) { $avatar = new BOL_Avatar(); $avatar->userId = $userId; } else { $oldHash = $avatar->hash; } $avatar->hash = time(); // destination path $avatarPath = $this->getAvatarPath($userId, 1, $avatar->hash); $avatarBigPath = $this->getAvatarPath($userId, 2, $avatar->hash); $avatarOriginalPath = $this->getAvatarPath($userId, 3, $avatar->hash); // pluginfiles tmp path $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $avatar->hash); $avatarPFBigPath = $this->getAvatarPluginFilesPath($userId, 2, $avatar->hash); $avatarPFOriginalPath = $this->getAvatarPluginFilesPath($userId, 3, $avatar->hash); if (!is_writable(dirname($avatarPFPath))) { return false; } try { $image = new UTIL_Image($uploadedFileName); $config = OW::getConfig(); $configAvatarSize = $config->getValue('base', 'avatar_size'); $configBigAvatarSize = $config->getValue('base', 'avatar_big_size'); $image->copyImage($avatarPFOriginalPath)->resizeImage($configBigAvatarSize, $configBigAvatarSize, true)->saveImage($avatarPFBigPath)->resizeImage($configAvatarSize, $configAvatarSize, true)->saveImage($avatarPFPath); $this->updateAvatar($avatar); // remove old images if (isset($oldHash)) { $oldAvatarPath = $this->getAvatarPath($userId, 1, $oldHash); $oldAvatarBigPath = $this->getAvatarPath($userId, 2, $oldHash); $oldAvatarOriginalPath = $this->getAvatarPath($userId, 3, $oldHash); $this->removeAvatarImage($oldAvatarPath); $this->removeAvatarImage($oldAvatarBigPath); $this->removeAvatarImage($oldAvatarOriginalPath); } $storage = OW::getStorage(); $storage->copyFile($avatarPFOriginalPath, $avatarOriginalPath); $storage->copyFile($avatarPFBigPath, $avatarBigPath); $storage->copyFile($avatarPFPath, $avatarPath); @unlink($avatarPFPath); @unlink($avatarPFBigPath); @unlink($avatarPFOriginalPath); return true; } catch (Exception $e) { return false; } }
/** * Makes and saves event standard image and icon. * * @param string $imagePath * @param integer $imageId */ public function saveEventImage($tmpPath, $imageId) { $event = new OW_Event(self::EVENT_BEFORE_IMAGE_UPDATE, array("tmpPath" => $tmpPath, "eventId" => $imageId), array("tmpPath" => $tmpPath)); OW::getEventManager()->trigger($event); $data = $event->getData(); $imagePath = $data["tmpPath"]; $storage = OW::getStorage(); if ($storage->fileExists($this->generateImagePath($imageId))) { $storage->removeFile($this->generateImagePath($imageId)); $storage->removeFile($this->generateImagePath($imageId, false)); } $pluginfilesDir = Ow::getPluginManager()->getPlugin('event')->getPluginFilesDir(); $tmpImgPath = $pluginfilesDir . 'img_' . uniqid() . '.jpg'; $tmpIconPath = $pluginfilesDir . 'icon_' . uniqid() . '.jpg'; $image = new UTIL_Image($imagePath); $image->resizeImage(400, null)->saveImage($tmpImgPath)->resizeImage(100, 100, true)->saveImage($tmpIconPath); $storage->copyFile($tmpIconPath, $this->generateImagePath($imageId)); $storage->copyFile($tmpImgPath, $this->generateImagePath($imageId, false)); OW::getEventManager()->trigger(new OW_Event(self::EVENT_AFTER_IMAGE_UPDATE, array("tmpPath" => $tmpPath, "eventId" => $imageId))); unlink($imagePath); unlink($tmpImgPath); unlink($tmpIconPath); }
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 addTemporaryPhoto($source, $userId, $order) { if (!file_exists($source) || !$userId) { return false; } $tmpPhoto = new PHOTO_BOL_PhotoTemporary(); $tmpPhoto->userId = $userId; $tmpPhoto->addDatetime = time(); $tmpPhoto->hasFullsize = 0; $tmpPhoto->order = $order; $this->photoTemporaryDao->save($tmpPhoto); $preview = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1); $main = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2); $original = $this->photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 3); $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'); try { $image = new UTIL_Image($source); $mainPhoto = $image->resizeImage($width, $height)->orientateImage()->saveImage($main); if ((bool) $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)->orientateImage()->saveImage($original); $tmpPhoto->hasFullsize = 1; $this->photoTemporaryDao->save($tmpPhoto); } $mainPhoto->resizeImage($previewWidth, $previewHeight, true)->orientateImage()->saveImage($preview); } catch (WideImage_Exception $e) { $this->photoTemporaryDao->deleteById($tmpPhoto->id); return false; } return $tmpPhoto->id; }
public function processPhotoAttachment(array $fileInfo) { $language = OW::getLanguage(); $error = false; if (!OW::getUser()->isAuthenticated() || empty($fileInfo) || !is_uploaded_file($fileInfo['tmp_name'])) { $error = $language->text('base', 'upload_file_fail'); } if ($fileInfo['error'] != UPLOAD_ERR_OK) { switch ($fileInfo['error']) { case UPLOAD_ERR_INI_SIZE: $error = $language->text('base', 'upload_file_max_upload_filesize_error'); break; case UPLOAD_ERR_PARTIAL: $error = $language->text('base', 'upload_file_file_partially_uploaded_error'); break; case UPLOAD_ERR_NO_FILE: $error = $language->text('base', 'upload_file_no_file_error'); break; case UPLOAD_ERR_NO_TMP_DIR: $error = $language->text('base', 'upload_file_no_tmp_dir_error'); break; case UPLOAD_ERR_CANT_WRITE: $error = $language->text('base', 'upload_file_cant_write_file_error'); break; case UPLOAD_ERR_EXTENSION: $error = $language->text('base', 'upload_file_invalid_extention_error'); break; default: $error = $language->text('base', 'upload_file_fail'); } } if (!in_array(UTIL_File::getExtension($_FILES['attachment']['name']), array('jpeg', 'jpg', 'png', 'gif'))) { $error = $language->text('base', 'upload_file_extension_is_not_allowed'); } if ((int) $_FILES['attachment']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) { $error = $language->text('base', 'upload_file_max_upload_filesize_error'); } if ($error !== false) { throw new InvalidArgumentException($error); } $attachDto = new BOL_Attachment(); $attachDto->setUserId(OW::getUser()->getId()); $attachDto->setAddStamp(time()); $attachDto->setStatus(0); $this->attachmentDao->save($attachDto); $fileName = 'attach_' . $attachDto->getId() . '.' . UTIL_File::getExtension($_FILES['attachment']['name']); $attachDto->setFileName($fileName); $this->attachmentDao->save($attachDto); $uploadPath = $this->getAttachmentsDir() . $fileName; $uploadUrl = $this->getAttachmentsUrl() . $fileName; try { $image = new UTIL_Image($fileInfo['tmp_name']); $image->resizeImage(1000, 1000)->orientateImage()->saveImage($uploadPath); } catch (Exception $e) { throw new InvalidArgumentException($language->text('base', 'upload_file_fail')); } chmod($uploadPath, 0666); return array('genId' => $attachDto->getId(), 'url' => $uploadUrl); }
public function setUserAvatar($userId, $uploadedFileName, array $editionalParams = array()) { $avatar = $this->findByUserId($userId); if (!$avatar) { $avatar = new BOL_Avatar(); $avatar->userId = $userId; } else { $oldHash = $avatar->hash; } $avatar->hash = time(); // destination path $avatarPath = $this->getAvatarPath($userId, 1, $avatar->hash); $avatarBigPath = $this->getAvatarPath($userId, 2, $avatar->hash); $avatarOriginalPath = $this->getAvatarPath($userId, 3, $avatar->hash); // pluginfiles tmp path $avatarPFPath = $this->getAvatarPluginFilesPath($userId, 1, $avatar->hash); $avatarPFBigPath = $this->getAvatarPluginFilesPath($userId, 2, $avatar->hash); $avatarPFOriginalPath = $this->getAvatarPluginFilesPath($userId, 3, $avatar->hash); if (!is_writable(dirname($avatarPFPath))) { return false; } try { $image = new UTIL_Image($uploadedFileName); $config = OW::getConfig(); $configAvatarSize = $config->getValue('base', 'avatar_size'); $configBigAvatarSize = $config->getValue('base', 'avatar_big_size'); $image->copyImage($avatarPFOriginalPath)->resizeImage($configBigAvatarSize, $configBigAvatarSize, true)->saveImage($avatarPFBigPath)->resizeImage($configAvatarSize, $configAvatarSize, true)->saveImage($avatarPFPath); $this->updateAvatar($avatar); $params = array('avatarId' => $avatar->id, 'userId' => $userId, 'trackAction' => isset($editionalParams['trackAction']) ? $editionalParams['trackAction'] : true); $event = new OW_Event('base.after_avatar_update', array_merge($editionalParams, $params)); OW::getEventManager()->trigger($event); // remove old images if (isset($oldHash)) { $oldAvatarPath = $this->getAvatarPath($userId, 1, $oldHash); $oldAvatarBigPath = $this->getAvatarPath($userId, 2, $oldHash); $oldAvatarOriginalPath = $this->getAvatarPath($userId, 3, $oldHash); $this->removeAvatarImage($oldAvatarPath); $this->removeAvatarImage($oldAvatarBigPath); $this->removeAvatarImage($oldAvatarOriginalPath); } $storage = OW::getStorage(); $storage->copyFile($avatarPFOriginalPath, $avatarOriginalPath); $storage->copyFile($avatarPFBigPath, $avatarBigPath); $storage->copyFile($avatarPFPath, $avatarPath); @unlink($avatarPFPath); @unlink($avatarPFBigPath); @unlink($avatarPFOriginalPath); return true; } catch (Exception $e) { return false; } }
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)); }
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()); }
/** * 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; }