Example #1
0
 /**
  * @param RokGallery_Model_File $file
  * @throws RokGallery_Job_Exception
  */
 protected function createInitialAdminSlice(RokGallery_Model_File &$file)
 {
     $default_x = RokGallery_Config::DEFAULT_ADMIN_THUMB_XSIZE;
     $default_y = RokGallery_Config::DEFAULT_ADMIN_THUMB_YSIZE;
     $admin_slice = RokGallery_Model_Slice::createNew($file, 'Admin Thumbnail', 'Admin Thumbnail', false, true);
     $modifications = array();
     // Create the Admin Slice
     $source_aspect_ratio = $file->xsize / $file->ysize;
     $desired_aspect_ratio = $default_x / $default_y;
     if (!($file->xsize < $default_x && $file->ysize < $default_y)) {
         $resize_width = $default_x;
         $resize_height = $default_y;
         $crop_left = 0;
         $crop_top = 0;
         if ($source_aspect_ratio > $desired_aspect_ratio) {
             $resize_height = $default_y;
             $resize_width = (int) round($default_y * $source_aspect_ratio);
             $crop_left = (int) round(($resize_width - $default_x) / 2);
         } elseif ($source_aspect_ratio < $desired_aspect_ratio) {
             $resize_width = $default_x;
             $resize_height = (int) round($default_x / $source_aspect_ratio);
             $crop_top = (int) round(($resize_height - $default_y) / 2);
         }
         $modifications[] = new RokGallery_Manipulation_Action_Resize(array('width' => $resize_width, 'height' => $resize_height));
         $modifications[] = new RokGallery_Manipulation_Action_Crop(array('left' => $crop_left, 'top' => $crop_top, 'width' => $default_x, 'height' => $default_y));
     }
     $admin_slice->manipulations = $modifications;
 }
Example #2
0
 protected function checkThumbExists(RokGallery_Model_Slice $record, $path, $type)
 {
     $ret = false;
     if (!file_exists($path)) {
         switch ($type) {
             case 'admin-thumb':
                 $record->generateAdminThumbnail();
                 $ret = true;
                 break;
             case 'mini-admin-thumb':
                 $record->generateMiniAdminThumbnail();
                 $ret = true;
                 break;
             case 'thumb':
                 $record->generateDefaultThumbnail();
                 $record->save();
                 $ret = true;
                 break;
             default:
                 $ret = false;
         }
     } else {
         if ($record->thumb_xsize == 0 && $record->thumb_ysize == 0) {
             $record->generateDefaultThumbnail();
             $record->save();
         } else {
             $ret = true;
         }
     }
     return $ret;
 }
Example #3
0
 /**
  * @param RokGallery_Model_Gallery $gallery
  */
 public function updateSlicesForGallery(RokGallery_Model_Gallery &$gallery)
 {
     try {
         $manipulations = array();
         if ($gallery->keep_aspect) {
             $gallery_aspect_ratio = $gallery->width / $gallery->height;
             $image_aspect_ratio = $this->xsize / $this->ysize;
             $resize_height = $gallery->height;
             $resize_width = $gallery->width;
             if ($image_aspect_ratio < $gallery_aspect_ratio) {
                 $resize_height = $gallery->height;
                 $resize_width = (int) round($gallery->height * $image_aspect_ratio);
             } elseif ($image_aspect_ratio > $gallery_aspect_ratio) {
                 $resize_width = $gallery->width;
                 $resize_height = (int) round($gallery->width / $image_aspect_ratio);
             }
             $manipulations[] = new RokGallery_Manipulation_Action_Resize(array('width' => $resize_width, 'height' => $resize_height));
         } else {
             // Create thumbnail but dont make thumbnail keep the aspect ratio
             $source_aspect_ratio = $this->xsize / $this->ysize;
             $desired_aspect_ratio = $gallery->width / $gallery->height;
             $temp_width = $gallery->width;
             $temp_height = $gallery->height;
             $temp_left = 0;
             $temp_top = 0;
             if ($source_aspect_ratio > $desired_aspect_ratio) {
                 $temp_height = $gallery->height;
                 $temp_width = (int) round($gallery->height * $source_aspect_ratio);
                 $temp_left = (int) round(($temp_width - $gallery->width) / 2);
                 $temp_top = 0;
             } elseif ($source_aspect_ratio < $desired_aspect_ratio) {
                 $temp_width = $gallery->width;
                 $temp_height = (int) round($gallery->width / $source_aspect_ratio);
                 $temp_left = 0;
                 $temp_top = (int) round(($temp_height - $gallery->height) / 2);
             }
             $manipulations[] = new RokGallery_Manipulation_Action_Resize(array('width' => $temp_width, 'height' => $temp_height));
             $manipulations[] = new RokGallery_Manipulation_Action_Crop(array('left' => $temp_left, 'top' => $temp_top, 'width' => $gallery->width, 'height' => $gallery->height));
         }
         $slices = $this->getSlicesForGallery($gallery->id);
         if ($slices === false) {
             $slices = array();
             $slice = RokGallery_Model_Slice::createNew($this, $this->title, $this->description, $gallery->auto_publish);
             $slice->Gallery = $gallery;
             $slices[] = $slice;
         }
         foreach ($slices as &$slice) {
             // skip changing manipulations if force_image_size is set and image size is the same  position could have been modified
             if (!$gallery->keep_aspect && $gallery->force_image_size && $gallery->width == $slice->xsize && $gallery->height == $slice->ysize) {
                 $manipulations = $slice->manipulations;
             }
             if ($slice->Gallery->id == $gallery->id) {
                 $slice->manipulations = $manipulations;
                 $slice->save();
                 if (!file_exists($slice->getFullPath()) || $gallery->thumb_xsize != $slice->thumb_xsize || $gallery->thumb_ysize != $slice->thumb_ysize || $gallery->thumb_keep_aspect != $slice->thumb_keep_aspect || $gallery->thumb_background != $slice->thumb_background) {
                     $slice->thumb_xsize = $gallery->thumb_xsize;
                     $slice->thumb_ysize = $gallery->thumb_ysize;
                     $slice->thumb_keep_aspect = $gallery->thumb_keep_aspect;
                     $slice->thumb_background = $gallery->thumb_background;
                     $slice->generateThumbnail($gallery->thumb_xsize, $gallery->thumb_ysize, $gallery->thumb_keep_aspect, $gallery->thumb_background);
                     $slice->save();
                 }
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #4
0
 protected function &getPresentationImage(RokGallery_Model_Slice $slice, JRegistry $params)
 {
     $image = new stdClass();
     $image->id = $slice->id;
     $image->title = $params->get('detail_use_title_from', 'slice') == 'slice' ? $slice->title : $slice->File->title;
     $image->caption = $params->get('detail_use_caption_from', 'slice') == 'slice' ? $slice->caption : $slice->File->description;
     $image->created_at = date('j M Y', strtotime($slice->File->created_at));
     $image->updated_at = date('j M Y', strtotime($slice->updated_at));
     $image->views = $slice->File->Views->count;
     $image->loves = $slice->File->Loves->count;
     $image->thumburl = $slice->thumburl;
     $image->imageurl = $slice->imageurl;
     $image->xsize = $params->get('detail_use_dimensions_from', 'file') == 'slice' ? $slice->xsize : $slice->File->xsize;
     $image->ysize = $params->get('detail_use_dimensions_from', 'file') == 'slice' ? $slice->xsize : $slice->File->xsize;
     $image->filesize = RokGallery_Helper::decodeSize($params->get('detail_use_filesize_from', 'file') == 'slice' ? $slice->filesize : $slice->File->filesize);
     $image->fullimageurl = $slice->File->imageurl;
     $image->doilove = $slice->doilove;
     switch ($params->get('gallery_use_tags_from', 'slice')) {
         case 'slice':
             $tags =& $slice->Tags;
             break;
         case 'file':
             $tags =& $slice->File->Tags;
             break;
         case 'combined':
             $tags =& $slice->getCombinedTags();
             break;
     }
     $image->tags = array();
     foreach ($tags as $tag) {
         if (!($params->get('gallery_remove_gallery_tags', false) && in_array($tag['tag'], $slice->Gallery->filetags))) {
             $image->tags[] = $tag['tag'];
         }
     }
     return $image;
 }
Example #5
0
 /**
  * Update the slice
  * $params object should be a json like
  * <code>
  * {
  *  'id': 1
  *  'slice':{'title':'new title','description':'new description'}
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function create($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $file = RokGallery_Model_FileTable::getSingle($params->fileId);
         /** @var $slice RokGallery_Model_Slice */
         $slice =& RokGallery_Model_Slice::createNew($file);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_SLICE_N', $params->id));
         }
         foreach ($params->slice as $field => $value) {
             // change the manipulation format if passed
             if ($field == 'manipulations') {
                 $value = RokGallery_Manipulation_Helper::unserializeFromJson($value);
             }
             // Add any tags if they are passed
             if ($field == 'Tags') {
                 if (!empty($value) && is_array($value)) {
                     foreach ($value as $tag) {
                         $slice->addTag($tag);
                     }
                 }
                 continue;
             }
             $slice->{$field} = $value;
         }
         $slice->save();
         $slice->populateFilterInfo();
         $slice->manipulations = RokGallery_Manipulation_Helper::prepSerializedForJson($slice->manipulations);
         $slice->Tags;
         $slice->FileTags;
         $slice->File;
         $result->setPayload(array('slice' => $slice->toJsonableArray()));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Example #6
0
 protected function &getPresentationImage(RokGallery_Model_Slice &$slice, JRegistry &$params, $base_page_url, $sort_by, $sort_direction)
 {
     $image = new stdClass();
     $image->id = $slice->id;
     $image->title = $params->get('gallery_use_title_from', 'slice') == 'slice' ? $slice->title : $slice->File->title;
     $image->caption = $params->get('gallery_use_caption_from', 'slice') == 'slice' ? $slice->caption : $slice->File->description;
     $image->created_at = date('j M Y', strtotime($slice->File->created_at));
     $image->updated_at = date('j M Y', strtotime($slice->updated_at));
     $image->views = $slice->File->Views->count;
     $image->loves = $slice->File->Loves->count;
     $image->thumburl = $slice->thumburl;
     $image->xsize = $slice->xsize;
     $image->ysize = $slice->ysize;
     $image->doilove = $slice->doilove;
     $image->filesize = $slice->filesize;
     $image->imageurl = $slice->imageurl;
     $image->rel = '';
     if (!RokGallery_Link::isJson($slice->link)) {
         $link = new RokGallery_Link(json_encode(new RokGallery_Link_Type_Manual_Info($slice->link)));
     } else {
         $link = new RokGallery_Link($slice->link);
     }
     switch ($params->get('slice_link_to')) {
         case 'rokbox':
             $image->link = $slice->imageurl;
             $image->rel = 'rel="rokbox[' . $image->xsize . ' ' . $image->ysize . '](' . str_replace(' ', '', $slice->Gallery->name) . ')" title="' . $image->title . ' :: ' . $image->caption . '" ';
             break;
         case 'rokbox_full':
             $image->link = $slice->imageurl;
             $image->rel = 'rel="rokbox[' . $image->xsize . ' ' . $image->ysize . '](' . str_replace(' ', '', $slice->Gallery->name) . ')" title="' . $image->title . ' :: ' . $image->caption . '" ';
             break;
         case 'force_details':
             $image->link = JRoute::_(RokCommon_URL::updateParams($base_page_url, array('view' => 'detail', 'id' => $slice->id)));
             break;
         default:
             switch ($link->getType()) {
                 case 'manual':
                     $image->link = $link->getUrl() != '' ? $link->getUrl() : JRoute::_(RokCommon_URL::updateParams($base_page_url, array('view' => 'detail', 'id' => $slice->id)));
                     break;
                 case 'article':
                     $image->link = JRoute::_($link->getUrl());
                     break;
             }
             break;
     }
     switch ($params->get('gallery_use_tags_from', 'slice')) {
         case 'slice':
             $tags =& $slice->Tags;
             break;
         case 'file':
             $tags =& $slice->File->Tags;
             break;
         case 'combined':
             $tags =& $slice->getCombinedTags();
             break;
     }
     $image->tags = array();
     foreach ($tags as $tag) {
         if (!($params->get('gallery_remove_gallery_tags', false) && in_array($tag['tag'], $slice->Gallery->filetags))) {
             $image->tags[] = $tag['tag'];
         }
     }
     return $image;
 }