public function pullPhoto($photoId) { if (!$this->isActive()) { return null; } $photo = PHOTO_BOL_PhotoService::getInstance()->findPhotoById($photoId); if (empty($photo)) { return null; } $source = PHOTO_BOL_PhotoService::getInstance()->getPhotoPath($photoId, $photo->hash); $pluginfilesDir = $this->plugin->getPluginFilesDir(); $dist = $pluginfilesDir . uniqid('tmp_') . '.jpg'; if (!OW::getStorage()->copyFileToLocalFS($source, $dist)) { return null; } return $dist; }
/** * * @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; }
/** * Uninstalls plugin * * @param string $pluginKey */ public function uninstall($pluginKey) { if (empty($pluginKey)) { throw new LogicException("Empty plugin key provided for uninstall"); } $pluginDto = $this->findPluginByKey(trim($pluginKey)); if ($pluginDto === null) { throw new LogicException("Invalid plugin key - `{$pluginKey}` provided for uninstall!"); } $plugin = new OW_Plugin($pluginDto); // trigger event OW::getEventManager()->trigger(new OW_Event(OW_EventManager::ON_BEFORE_PLUGIN_UNINSTALL, array("pluginKey" => $pluginDto->getKey()))); $this->includeScript($plugin->getRootDir() . BOL_PluginService::SCRIPT_DEACTIVATE); $this->includeScript($plugin->getRootDir() . BOL_PluginService::SCRIPT_UNINSTALL); // delete plugin work dirs $dirsToRemove = array($plugin->getPluginFilesDir(), $plugin->getUserFilesDir(), $plugin->getPublicStaticDir()); foreach ($dirsToRemove as $dir) { if (file_exists($dir)) { UTIL_File::removeDir($dir); } } // remove plugin configs OW::getConfig()->deletePluginConfigs($pluginDto->getKey()); // delete language prefix $prefixId = BOL_LanguageService::getInstance()->findPrefixId($pluginDto->getKey()); if (!empty($prefixId)) { BOL_LanguageService::getInstance()->deletePrefix($prefixId, true); } //delete authorization stuff BOL_AuthorizationService::getInstance()->deleteGroup($pluginDto->getKey()); // drop plugin tables $tables = OW::getDbo()->queryForColumnList("SHOW TABLES LIKE '" . str_replace('_', '\\_', OW_DB_PREFIX) . $pluginDto->getKey() . "\\_%'"); if (!empty($tables)) { $query = "DROP TABLE "; foreach ($tables as $table) { $query .= "`" . $table . "`,"; } $query = substr($query, 0, -1); OW::getDbo()->query($query); } //remove entry in DB $this->deletePluginById($pluginDto->getId()); $this->updatePluginListCache(); // trigger event OW::getEventManager()->trigger(new OW_Event(OW_EventManager::ON_AFTER_PLUGIN_UNINSTALL, array("pluginKey" => $pluginDto->getKey()))); }