/**
  * Returns an instance of class.
  *
  * @return PHOTO_BOL_PhotoTemporaryDao
  */
 public static function getInstance()
 {
     if (self::$classInstance === null) {
         self::$classInstance = new self();
     }
     return self::$classInstance;
 }
示例#2
0
 public function deleteTemporaryPhoto($photoId)
 {
     $photo = $this->photoTemporaryDao->findById($photoId);
     if (!$photo) {
         return false;
     }
     $preview = $this->photoTemporaryDao->getTemporaryPhotoPath($photoId, 1);
     @unlink($preview);
     $main = $this->photoTemporaryDao->getTemporaryPhotoPath($photoId, 2);
     @unlink($main);
     if ($photo->hasFullsize) {
         $original = $this->photoTemporaryDao->getTemporaryPhotoPath($photoId, 3);
         @unlink($original);
     }
     $this->photoTemporaryDao->delete($photo);
     return true;
 }
 public function deleteLimitedPhotos()
 {
     foreach ($this->photoTemporaryDao->findLimitedPhotos(self::TEMPORARY_PHOTO_LIVE_LIMIT) as $id) {
         $this->deleteTemporaryPhoto($id);
     }
 }
示例#4
0
 public function upload(array $params = array())
 {
     if ($this->isAvailableFile($_FILES)) {
         $order = !empty($_POST['order']) ? (int) $_POST['order'] : 0;
         ini_set('memory_limit', '-1');
         if ($id = PHOTO_BOL_PhotoTemporaryService::getInstance()->addTemporaryPhoto($_FILES['file']['tmp_name'], OW::getUser()->getId(), $order)) {
             $fileUrl = PHOTO_BOL_PhotoTemporaryDao::getInstance()->getTemporaryPhotoUrl($id, 2);
             $this->returnResponse(array('status' => self::STATUS_SUCCESS, 'fileUrl' => $fileUrl, 'id' => $id));
         } else {
             $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => OW::getLanguage()->text('photo', 'no_photo_uploaded')));
         }
     } else {
         $msg = $this->getErrorMsg($_FILES);
         $this->returnResponse(array('status' => self::STATUS_ERROR, 'msg' => $msg));
     }
 }
示例#5
0
文件: Service.php 项目: vazahat/dudex
 public static function addTemporaryPhoto($source, $userId, $order)
 {
     $tmpPhoto = new PHOTO_BOL_PhotoTemporary();
     $tmpPhoto->userId = $userId;
     $tmpPhoto->addDatetime = time();
     $tmpPhoto->hasFullsize = 0;
     $tmpPhoto->order = $order;
     $photoTemporaryDao = PHOTO_BOL_PhotoTemporaryDao::getInstance();
     $photoTemporaryDao->save($tmpPhoto);
     $preview = $photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 1);
     $main = $photoTemporaryDao->getTemporaryPhotoPath($tmpPhoto->id, 2);
     $original = $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)->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)->saveImage($original);
             $tmpPhoto->hasFullsize = 1;
             $photoTemporaryDao->save($tmpPhoto);
         }
         $mainPhoto->resizeImage($previewWidth, $previewHeight, true)->saveImage($preview);
     } catch (WideImage_Exception $e) {
         $photoTemporaryDao->deleteById($tmpPhoto->id);
         return false;
     }
     return true;
 }