Пример #1
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new RokGallery_Config();
     }
     return self::$instance;
 }
Пример #2
0
 /**
  * @param RokGallery_Model_File $record
  * @return string
  */
 protected function _getMiniAdminThumbUrl(RokGallery_Model_File $record)
 {
     $this->_getMiniAdminThumbPath($record);
     $slice =& $record->getAdminThumbSlice();
     $root = RokGallery_Config::getOption(RokGallery_Config::OPTION_THUMBNAIL_BASE_URL);
     if (null == $slice) {
         return $root . RokGallery_Config::getOption(RokGallery_Config::OPTION_MISSING_IMAGE_PATH, '/mini_missing_image.png');
     }
     $path = $root . $slice->getRelativeThumbPath('/', 'mini-admin-thumb');
     return $path;
 }
Пример #3
0
 /**
  * Delete the file and all associated rows (done by foreign keys) and files
  * $params object should be a json like
  * <code>
  * {
  *  'id': 'xxxx-x-x-x-x-x-x'
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function file($params)
 {
     $result = new RokCommon_Ajax_Result();
     $tx = RokGallery_Doctrine::getConnection()->transaction;
     $tx->setIsolation('READ UNCOMMITTED');
     try {
         if (count($_FILES) == 0) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NO_FILES_SENT'));
         }
         $job = RokGallery_Job::get($params->id);
         if ($job === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_JOB', $params->id));
         }
         if ($job->getStateName() != RokGallery_Job::STATE_PREPPING) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_IN_PREPPING_STATUS'));
         }
         if ($job->getType() != RokGallery_Job::TYPE_IMPORT) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_AN_IMPORT_JOB'));
         }
         $job_properties = $job->getProperties();
         if (empty($job_properties)) {
             $job_properties = array();
         }
         $basepath = RokGallery_Config::getOption(RokGallery_Config::OPTION_JOB_QUEUE_PATH) . DS . $job->getId();
         if (!file_exists($basepath)) {
             @mkdir($basepath);
             RokGallery_Queue_DirectoryCreate::add($basepath);
         }
         if (!(file_exists($basepath) && is_dir($basepath) && is_writable($basepath))) {
             throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_CREATE_OR_WRITE_TO_TEMP_DIR', $basepath));
         }
         $tx->beginTransaction();
         foreach ($_FILES as $uploaded_file) {
             if ($uploaded_file['error'] == UPLOAD_ERR_OK) {
                 $file = new RokGallery_Job_Property_ImportFile();
                 $file->setFilename($uploaded_file['name']);
                 $file->setPath($basepath . DS . $file->getId());
                 move_uploaded_file($uploaded_file['tmp_name'], $file->getPath());
                 $job_properties[] = $file;
             }
         }
         $job->setProperties($job_properties);
         $job->save();
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
     return $result;
 }
Пример #4
0
 /**
  */
 public function process()
 {
     try {
         /** @var $properties RokGallery_Job_Property_ImportFile[] */
         $properties = $this->_job->getProperties();
         $total_files = count($properties['files']);
         foreach ($properties['files'] as $key => &$file) {
             // keep bumping the time as log as a file doesnt take 30 seconds or more
             /** @var RokGallery_Job_Property_ImportFile $file  */
             if (!$this->_checkState($properties, rc__('ROKGALLERY_CREATE_UPDATE'))) {
                 return;
             }
             if ($file->isCompleted()) {
                 continue;
             }
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $gallery = RokGallery_Model_GalleryTable::getSingle($properties['galleryId']);
             if ($gallery === false) {
                 throw new RokGallery_Job_Exception(rc__('ROKGALLERY_NOT_A_VALID_GALLERY'));
             }
             $full_file = RokGallery_Model_FileTable::getSingle($file->getId());
             if ($full_file === false) {
                 $file->setStatus(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
                 $file->setError(true);
                 RokGallery_Doctrine::getConnection()->commit();
                 continue;
             }
             if ($gallery && $full_file) {
                 $full_file->updateSlicesForGallery($gallery);
             }
             $file->setCompleted();
             $percent = (int) (($key + 1) / $total_files * 100);
             $this->_job->setProperties($properties);
             $this->_job->save(rc__('ROKGALLERY_UPDATED_GALLERY_SLICE_FOR_FILE_N', $full_file->title), $percent);
             RokGallery_Doctrine::getConnection()->commit();
         }
         $this->_job->Complete(rc__('ROKGALLERY_GALLERY_UPDATE_COMPLETE'));
         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) {
             sleep(5);
             $this->_job->Delete();
         }
         return;
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         $this->_job->Error($e->getMessage());
         return;
     }
 }
Пример #5
0
 /**
  * $params object should be a json like
  * <code>
  * {
  *      "id": 1   // this is the slice ID displayed
  * }
  * @throws Exception|RokCommon_Ajax_Exception
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function remove($params)
 {
     try {
         $result = new RokCommon_Ajax_Result();
         $slice = RokGallery_Model_SliceTable::getSingle($params->id);
         if ($slice === false) {
             throw new RokCommon_Ajax_Exception('No Slice Found');
         }
         if (RokCommon_Session::get(self::CONTEXT_ROOT . $slice->file_id, false)) {
             $slice->decrementLoves();
             RokCommon_Session::clear(self::CONTEXT_ROOT . $slice->file_id);
         }
         $result->setPayload(array('loves' => $slice->File->Loves->count, 'new_action' => 'love', 'text' => rc__(RokGallery_Config::getOption(RokGallery_Config::OPTION_LOVE_TEXT))));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Пример #6
0
 /**
  * Get the basic file info and supporting slices/tags
  * $params object should be a json like
  * <code>
  * {
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function get($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $q = Doctrine_Query::create()->select('j.*')->from('RokGallery_Model_Gallery j')->orderBy('j.name DESC');
         /** @var Doctrine_Collection $galleries  */
         $galleries = $q->execute(array(), Doctrine_Core::HYDRATE_RECORD);
         $outgalleries = array();
         foreach ($galleries as $gallery) {
             /** @var RokGallery_Model_Gallery $gallery  */
             $outgalleries[] = $gallery->toJsonableArray();
         }
         $html = RokCommon_Composite::get('com_rokgallery.galleries')->load('default.php', array('galleries' => $galleries));
         $result->setPayload(array('galleries' => $outgalleries, 'html' => $html, 'delete_slices' => RokGallery_Config::getOption(RokGallery_Config::OPTION_GALLERY_REMOVE_SLICES, 0)));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Пример #7
0
 /**
  */
 public function process()
 {
     try {
         /** @var $properties RokGallery_Job_Property_FileTags[] */
         $properties = $this->_job->getProperties();
         $total_files = count($properties);
         foreach ($properties as $key => &$tagAddition) {
             // keep bumping the time as log as a file doesnt take 30 seconds or more
             if (!$this->_checkState($properties, rc__('ROKGALLERY_CREATE_UPDATE'))) {
                 return;
             }
             if ($tagAddition->isCompleted()) {
                 continue;
             }
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $file = RokGallery_Model_FileTable::getSingle($tagAddition->getFileId());
             if (!$file) {
                 $tagAddition->setStatus(rc__('ROKGALLERY_UNABLE_TO_FIND_FILE'));
                 $tagAddition->setError(true);
                 RokGallery_Doctrine::getConnection()->commit();
                 continue;
             }
             RokGallery_Model_FileTable::addTagsToFile($file, $tagAddition->getTags());
             $tagAddition->setCompleted();
             $percent = (int) (($key + 1) / $total_files * 100);
             $this->_job->setProperties($properties);
             $this->_job->save(rc__('ROKGALLERY_ADDED_TAGS_TO_FILE_N', $file->title), $percent);
             RokGallery_Doctrine::getConnection()->commit();
         }
         $this->_job->Complete(rc__('ROKGALLERY_TAG_ADDITION_COMPLETE'));
         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) {
             sleep(5);
             $this->_job->Delete();
         }
         return;
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         $this->_job->Error($e->getMessage());
         return;
     }
 }
Пример #8
0
 /**
  */
 public function process()
 {
     try {
         /** @var RokGallery_Job_Property_ImportFile[] $import_files  */
         $import_files = $this->_job->getProperties();
         $total_files = count($import_files);
         foreach ($import_files as $key => &$import_file) {
             $this->_job->refreshState();
             if (!$this->_checkState($properties, 'Import')) {
                 return;
             }
             if ($import_file->isCompleted()) {
                 continue;
             }
             RokGallery_Doctrine::getConnection()->beginTransaction();
             $file = RokGallery_Model_File::createNew($import_file->getFilename(), $import_file->getPath());
             // If we need to check to make sure it is not a duplicated file
             if (RokGallery_Config::getOption(RokGallery_Config::OPTION_ALLOW_DUPLICATE_FILES, true) == false && RokGallery_Model_FileTable::getMD5($file->md5) !== false && RokGallery_Model_FileTable::getMD5($file->md5)->count() > 0) {
                 throw new RokGallery_Job_Exception(rc__('ROKGALLERY_A_MATCHING_FILE_FOR_N_IN_SYSTEM', $file->filename));
             }
             // Copy file to fine directory
             $basepath = dirname($file->getFullPath());
             if (!file_exists($basepath)) {
                 @mkdir($basepath, 0777, true);
                 RokGallery_Queue_DirectoryCreate::add($basepath);
             }
             if (!(file_exists($basepath) && is_dir($basepath) && is_writable($basepath))) {
                 throw new RokGallery_Job_Exception(rc__('ROKGALLERY_UNABLE_TO_CREATE_OR_WRITE_TO_THE_DIR_N', $basepath));
             }
             // Move the file to its final location
             $endpath = $file->getFullPath();
             rename($import_file->getPath(), $endpath);
             // update the image file info
             $file_image_info = @getimagesize($endpath);
             $file->xsize = $file_image_info[0];
             /// x size
             $file->ysize = $file_image_info[1];
             /// y size
             // Create the initial admin slice
             $this->createInitialAdminSlice($file);
             // Save the file to the db;
             $file->save();
             $import_file->setCompleted();
             $percent = (int) (($key + 1) / $total_files * 100);
             $this->_job->setProperties($import_files);
             $this->_job->save(rc__('ROKGALLERY_IMPORTED_FILE_N', $import_file->getFilename()), $percent);
             RokGallery_Doctrine::getConnection()->commit();
             $file->free(true);
         }
         $this->_job->Complete('Importing Complete');
         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_AUTO_CLEAR_SUCCESSFUL_JOBS, false)) {
             sleep(5);
             $this->_job->Delete();
         }
         return;
     } catch (Exception $e) {
         RokGallery_Doctrine::getConnection()->rollback();
         $this->_job->Error($e->getMessage());
         return;
     }
 }
Пример #9
0
 protected function getThumbUrl(RokGallery_Model_Slice $record, $type)
 {
     $root = RokGallery_Config::getOption(RokGallery_Config::OPTION_THUMBNAIL_BASE_URL);
     $path = $root . $record->getRelativeThumbPath('/', $type);
     return $path;
 }
Пример #10
0
 public static function getImageQuality($type)
 {
     $quality = null;
     switch (strtolower($type)) {
         case 'jpeg':
         case 'jpg':
             $quality = RokGallery_Config::getOption(RokGallery_Config::OPTION_JPEG_QUALITY, 80);
             break;
         case 'png':
             $quality = RokGallery_Config::getOption(RokGallery_Config::OPTION_PNG_COMPRESSION, 0);
             break;
         default:
             $quality = null;
             break;
     }
     return $quality;
 }
Пример #11
0
 /**
  * @return array
  */
 protected function getDefaults()
 {
     return array('thumb_xsize' => RokGallery_Config::getOption(RokGallery_Config::OPTION_DEFAULT_THUMB_XSIZE, RokGallery_Config::DEFAULT_DEFAULT_THUMB_XSIZE), 'thumb_ysize' => RokGallery_Config::getOption(RokGallery_Config::OPTION_DEFAULT_THUMB_YSIZE, RokGallery_Config::DEFAULT_DEFAULT_THUMB_YSIZE), 'thumb_keep_aspect' => (int) RokGallery_Config::getOption(RokGallery_Config::OPTION_DEFAULT_THUMB_KEEP_ASPECT, RokGallery_Config::DEFAULT_DEFAULT_THUMB_KEEP_ASPECT), 'thumb_background' => RokGallery_Config::getOption(RokGallery_Config::OPTION_DEFAULT_THUMB_BACKGROUND, RokGallery_Config::DEFAULT_DEFAULT_THUMB_BACKGROUND));
 }
Пример #12
0
    function display($tpl = null)
    {
        JHTML::_('behavior.mootools');
        JHTML::_('behavior.keepalive');
        $option = JRequest::getCmd('option');
        $document =& JFactory::getDocument();
        $session =& JFactory::getSession();
        $model = new RokGallery_Admin_MainPage();
        $current_page = 1;
        $items_per_page = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_PAGE, 6);
        $items_per_row = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_ROW, 3);
        $files = $model->getFiles($current_page, $items_per_page * 2);
        $pager = $model->getPager($current_page, $items_per_page * 2);
        $next_page = $current_page == 1 ? 3 : $current_page + 1;
        $next_page = $current_page == $pager->getLastPage() ? false : $next_page;
        $more_pages = $next_page == false ? "false" : "true";
        $application = JURI::root(true) . '/administrator/components/' . $option . '/assets/application/';
        $images = JURI::root(true) . '/administrator/components/' . $option . '/assets/images/';
        $url = JURI::root(true) . '/administrator/index.php?option=com_rokgallery&task=ajax&format=raw';
        // debug: &XDEBUG_SESSION_START=default
        $document->addScriptDeclaration('var RokGallerySettings = {
			application: "' . $application . '", 
			images: "' . $images . '", 
			next_page: "' . $next_page . '",
            last_page: "' . $pager->getLastPage() . '",
			more_pages: ' . $more_pages . ', 
			items_per_page: "' . $items_per_page . '",
            total_items: ' . $pager->getNumResults() . ',
			url: "' . $url . '", 
			token: "' . JUtility::getToken() . '", 
			session: {
				name: "' . $session->getName() . '", 
				id: "' . $session->getId() . '"
			},
			order: ["order-created_at", "order-desc"]
		};');
        $document->addStyleSheet('components/' . $option . '/assets/styles/master.css');
        if (RokCommon_Browser::getShortName() == 'ie8') {
            $document->addStyleSheet('components/' . $option . '/assets/styles/internet-explorer-8.css');
        }
        $document->addScript('components/' . $option . '/assets/application/Common.js');
        $document->addScript('components/' . $option . '/assets/application/RokGallery.js');
        $document->addScript('components/' . $option . '/assets/application/RokGallery.Filters.js');
        $document->addScript('components/' . $option . '/assets/application/RokGallery.Blocks.js');
        $document->addScript('components/' . $option . '/assets/application/RokGallery.FileSettings.js');
        $document->addScript('components/' . $option . '/assets/application/RokGallery.Edit.js');
        $document->addScript('components/' . $option . '/assets/application/MainPage.js');
        $document->addScript('components/' . $option . '/assets/application/Tags.js');
        $document->addScript('components/' . $option . '/assets/application/Tags.Slice.js');
        $document->addScript('components/' . $option . '/assets/application/Tags.Ajax.js');
        $document->addScript('components/' . $option . '/assets/application/Scrollbar.js');
        $document->addScript('components/' . $option . '/assets/application/Popup.js');
        $document->addScript('components/' . $option . '/assets/application/Progress.js');
        $document->addScript('components/' . $option . '/assets/application/Job.js');
        $document->addScript('components/' . $option . '/assets/application/JobsManager.js');
        $document->addScript('components/' . $option . '/assets/application/MassTags.js');
        $document->addScript('components/' . $option . '/assets/application/GalleriesManager.js');
        $document->addScript('components/' . $option . '/assets/application/Swiff.Uploader.js');
        $document->addScript('components/' . $option . '/assets/application/Uploader.js');
        $document->addScript('components/' . $option . '/assets/application/Rubberband.js');
        $document->addScript('components/' . $option . '/assets/application/Marquee.js');
        $document->addScript('components/' . $option . '/assets/application/Marquee.Crop.js');
        $galleries = RokGallery_Model_GalleryTable::getAll();
        if ($galleries === false) {
            $galleries = array();
        }
        $this->assign('total_items_in_filter', $pager->getNumResults());
        $this->assign('items_to_be_rendered', $pager->getResultsInPage());
        $this->assign('next_page', $next_page);
        $this->assign('items_per_page', $items_per_page);
        $this->assign('items_per_row', $items_per_row);
        $this->assign('currently_shown_items', $pager->getLastIndice());
        $this->assign('totalFilesCount', $pager->getNumResults());
        $this->assignRef('files', $files);
        $this->assignRef('galleries', $galleries);
        parent::display($tpl);
    }
Пример #13
0
 /**
  * Delete the file and all associated rows (done by foreign keys) and files
  * $params object should be a json like
  * <code>
  * {
  *  "page": 3,
  *  "items_per_page":6
  *  "filters": [{ type: "title", operator: "is not", query: "example"},{ type: "title", operator: "is not", query: "example"}]
  *  "get_remaining": true
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function getPage($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $html = '';
         $filters = array();
         foreach ($params->filters as $filter) {
             $filters[] = RokGallery_Filter_Item::createFromJson($filter);
         }
         $model = new RokGallery_Admin_MainPage();
         $order_by = isset($params->order->order_by) ? $params->order->order_by : null;
         $order_direction = isset($params->order->order_direction) ? $params->order->order_direction : null;
         $files = $model->getFiles($params->page, $params->items_per_page, $filters, $order_by, $order_direction);
         $pager = $model->getPager($params->page, $params->items_per_page, $filters, $order_by, $order_direction);
         $model->clearPager();
         $total_items_count = $pager->getResultsInPage();
         $current_page = $params->page;
         $next_page = $current_page == 1 ? 3 : $current_page + 1;
         $next_page = $current_page == $pager->getLastPage() ? false : $next_page;
         $remaining_pages = $next_page ? $pager->getLastPage() - $current_page : 0;
         $items_per_page = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_PAGE, 6);
         $passed_items_per_page = $items_per_page;
         $items_per_page = $current_page == 1 ? $items_per_page * 2 : $items_per_page;
         $items_per_row = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_ROW, 3);
         $that->files =& $files;
         $that->items_per_page = $items_per_page;
         $that->items_per_row = $items_per_row;
         ob_start();
         $that->row_entry_number = 0;
         $that->item_number = 1;
         $that->items_to_be_rendered = $pager->getResultsInPage();
         foreach ($that->files as $that->file) {
             if (!isset($params->composite) || !isset($params->composite->context) || !isset($params->composite->layout)) {
                 echo RokCommon_Composite::get('com_rokgallery.default')->load('default_row.php', array('that' => $that));
             } else {
                 echo RokCommon_Composite::get($params->composite->context)->load($params->composite->layout . '.php', array('that' => $that));
             }
             $that->row_entry_number++;
             $that->item_number++;
         }
         $html .= ob_get_clean();
         if (isset($params->get_remaining) && $params->get_remaining) {
             for ($params->page++; $params->page <= $pager->getLastPage(); $params->page++) {
                 $more_files = $model->getFiles($params->page, $params->items_per_page, $filters, $order_by, $order_direction);
                 $pager = $model->getPager($params->page, $params->items_per_page, $filters, $order_by, $order_direction);
                 $model->clearPager();
                 $total_items_count = $total_items_count + $pager->getResultsInPage();
                 $current_page = $params->page;
                 $next_page = $current_page == 1 ? 3 : $current_page + 1;
                 $next_page = $current_page == $pager->getLastPage() ? false : $next_page;
                 $remaining_pages = $next_page ? $pager->getLastPage() - $current_page : 0;
                 $items_per_page = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_PAGE, 6);
                 $passed_items_per_page = $items_per_page;
                 $items_per_page = $current_page == 1 ? $items_per_page * 2 : $items_per_page;
                 $items_per_row = RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_ITEMS_PER_ROW, 3);
                 $that->files =& $more_files;
                 $that->items_per_page = $items_per_page;
                 $that->items_per_row = $items_per_row;
                 ob_start();
                 $that->row_entry_number = 0;
                 $that->item_number = 1;
                 $that->items_to_be_rendered = $pager->getResultsInPage();
                 foreach ($that->files as $that->file) {
                     if (!isset($params->composite) || !isset($params->composite->context) || !isset($params->composite->layout)) {
                         echo RokCommon_Composite::get('com_rokgallery.default')->load('default_row.php', array('that' => $that));
                     } else {
                         echo RokCommon_Composite::get($params->composite->context)->load($params->composite->layout . '.php', array('that' => $that));
                     }
                     $that->row_entry_number++;
                     $that->item_number++;
                 }
                 $html .= ob_get_clean();
             }
         }
         $result->setPayload(array('next_page' => $next_page, 'last_page' => $pager->getLastPage(), 'items_per_page' => $passed_items_per_page, 'items_returned' => $total_items_count, 'more_pages' => $next_page == false ? false : true, 'remaining_pages' => $remaining_pages, 'total_items_in_filter' => $pager->getNumResults(), 'total_items_shown' => $pager->getLastIndice(), 'total_items' => RokGallery_Model_FileTable::getTotalFileCount(), 'html' => $html));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
Пример #14
0
 public function generateMiniAdminThumbnail()
 {
     $this->generateThumbnail(RokGallery_Config::DEFAULT_MINI_ADMIN_THUMB_XSIZE, RokGallery_Config::DEFAULT_MINI_ADMIN_THUMB_YSIZE, true, RokGallery_Config::getOption(RokGallery_Config::OPTION_ADMIN_THUMB_BACKGROUND), "mini-admin-thumb");
 }
Пример #15
0
 /**
  * Get the basic file info and supporting slices/tags
  * $params object should be a json like
  * <code>
  * {
  *  "id": 1
  *  "gallery": {
  *      "name": "Gallery name",
  *      "width": 100
  *      "height": 100
  *      "thumb_xsize": 50
  *      "thumb_ysize": 50
  *   }
  *  "order": [1, 2, 10, 3, 8]
  * }
  * </code>
  *
  * @param $params
  * @return RokCommon_Ajax_Result
  */
 public function update($params)
 {
     $result = new RokCommon_Ajax_Result();
     /** @var Doctrine_Transaction $tx  */
     $tx = RokGallery_Doctrine::getConnection()->transaction;
     $tx->setIsolation('REPEATABLE READ');
     try {
         $tx->beginTransaction();
         $gallery = RokGallery_Model_GalleryTable::getSingle($params->id);
         if ($gallery === false) {
             throw new RokCommon_Ajax_Exception(rc__('ROKGALLERY_UNABLE_TO_FIND_GALLERY_WITH_ID_N_TO_UPDATE', $params->id));
         }
         $oldfiletags = $gallery->filetags;
         $update_slices = false;
         foreach ($params->gallery as $field => $value) {
             if (isset($gallery->{$field})) {
                 // see if we need to update the slices
                 if ($field == 'width' || $field == 'height' || $field == 'keep_aspect' || $field == 'thumb_xsize' || $field == 'thumb_ysize' || $field == 'thumb_background' || $field == 'thumb_keep_aspect') {
                     $update_slices = true;
                 }
                 if ($value == '') {
                     $value = null;
                 }
                 $gallery->{$field} = $value;
             }
         }
         $gallery->save();
         $result->setPayload(array('gallery' => $gallery->toJsonableArray()));
         // get list of files to process
         $fileids = RokGallery_Model_FileTable::getIdsByTags($gallery->filetags);
         // get list of files to remove
         $original_fileids = RokGallery_Model_FileTable::getIdsByTags($oldfiletags);
         // get the list of file ids to remove or add
         $remove_fileids = array_diff($original_fileids, $fileids);
         $new_fileids = array_diff($fileids, $original_fileids);
         // just return if there are no files to process
         if ((empty($fileids) || $fileids === false) && (empty($remove_fileids) || $remove_fileids === false)) {
             $tx->commit();
             return $result;
         }
         /** @var RokGallery_Job_Property_GalleryFile[] $files  */
         $files = array();
         // Add any new files to the job
         if (!empty($new_fileids)) {
             foreach ($new_fileids as $new_fileid) {
                 $files[] = new RokGallery_Job_Property_GalleryFile($new_fileid);
             }
         }
         // if we need to update all slices populate them
         if ($update_slices) {
             foreach ($fileids as $fileid) {
                 $files[] = new RokGallery_Job_Property_GalleryFile($fileid);
             }
         }
         $remove_slices = array();
         // remove all non linked slices
         foreach ($gallery->Slices as $key => &$slice) {
             /** @var RokGallery_Model_Slice $slice */
             if (in_array($slice->File->id, $remove_fileids)) {
                 $remove_slices[] = $slice->id;
             }
         }
         foreach ($remove_slices as $remove_slice_id) {
             $remove_slice = RokGallery_Model_SliceTable::getSingle($remove_slice_id);
             if (RokGallery_Config::getOption(RokGallery_Config::OPTION_GALLERY_REMOVE_SLICES, false)) {
                 $remove_slice->delete();
             } else {
                 $remove_slice->unlink('Gallery');
                 $remove_slice->save();
             }
         }
         // if there are no files to process just return
         if (empty($files)) {
             $tx->commit();
             return;
         }
         $properties = array("galleryId" => $gallery->id, "files" => $files);
         $job = RokGallery_Job::create(RokGallery_Job::TYPE_UPDATEGALLERY);
         $job->propertires = serialize($properties);
         $job->setProperties($properties);
         $job->save();
         $tx->commit();
         // Disconnect and process job
         $this->sendDisconnectingReturn($result);
         $job->Ready();
         $job->Run('Starting Gallery Update');
         $job->process();
         die;
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
Пример #16
0
 /**
  * @return string
  */
 public function getDirectoryPath()
 {
     return RokGallery_Config::getOption(RokGallery_Config::OPTION_ROOT_PATH) . RokGallery_Helper::getPathFromGUID($this->guid, DS);
 }
Пример #17
0
 /**
  * @param \RokGallery_Model_File $file
  * @param array $tags
  */
 public static function removeTagsFromFile(RokGallery_Model_File &$file, array $tags = array())
 {
     try {
         $query = Doctrine_Query::create()->delete('RokGallery_Model_FileTags ft')->where('ft.file_id = ?', $file->id)->andWhereIn('ft.tag', $tags);
         $query->execute();
         foreach ($tags as $tag) {
             $galleries = RokGallery_Model_GalleryTable::getByTag($tag);
             foreach ($galleries as $gallery) {
                 $slices = $file->getSlicesForGallery($gallery->id);
                 if (is_array($slices)) {
                     foreach ($slices as &$slice) {
                         if (RokGallery_Config::getOption(RokGallery_Config::OPTION_GALLERY_REMOVE_SLICES, false)) {
                             $file->unlink('Slices', array($slice->id));
                             $slice->delete();
                         } else {
                             $slice->gallery_id = null;
                             $slice->save();
                         }
                     }
                 }
             }
         }
         $file->save();
     } catch (Exception $e) {
         throw $e;
     }
 }
Пример #18
0
 function display($tpl = null)
 {
     JHTML::_('behavior.mootools');
     $session_namespace = 'com_rokgallery.site';
     $session =& JFactory::getSession();
     $app =& JFactory::getApplication();
     $params =& $app->getParams();
     $menu =& JSite::getMenu();
     $menuItem =& $menu->getActive();
     //$params = new JParameter($menuItem->params);
     $document =& JFactory::getDocument();
     $id = JRequest::getVar('id');
     $style = JRequest::getWord('style', $params->get('default_style'));
     $layout = JRequest::getVar('layout', $session->get('layout', $this->getLayout(), $session_namespace));
     if ($layout == 'default') {
         $layout = $params->get('detail_layout');
     }
     $gallery_id = $session->get('gallery_id', $params->get('gallery_id'), $session_namespace);
     $sort_by = $session->get('sort_by', $params->get('default_sort_by'), $session_namespace);
     $sort_direction = $session->get('sort_direction', $params->get('default_sort_direction'), $session_namespace);
     $page = JRequest::getVar('page', $session->get('last_page', 1, $session_namespace));
     $items_per_page = $session->get('items_per_page', (int) $params->get($layout . '-items_per_row', 2) * (int) $params->get($layout . '-rows_per_page', 2), $session_namespace);
     /** @var RokGallery_Site_DetailModel $rtmodel  */
     $this->rtmodel = new RokGallery_Site_DetailModel($gallery_id, $id, $page, $items_per_page, $sort_by, $sort_direction);
     $slice = $this->rtmodel->getSingle();
     if ($slice === false) {
         return JError::raiseError(500, 'Gallery Item is not published.');
     }
     if (!RokCommon_Session::get('com_rokgallery.site.views.file_' . $slice->file_id, false)) {
         $slice->incrementView();
         RokCommon_Session::set('com_rokgallery.site.views.file_' . $slice->file_id, true);
     }
     $base_page_url = RokCommon_URL::setParams('index.php', array('option' => 'com_rokgallery', 'view' => 'gallery'));
     $base_ajax_url = RokCommon_URL::setParams('index.php', array('option' => 'com_rokgallery', 'task' => 'ajax', 'format' => 'raw'));
     // Assignments to JS namespaces
     $this->assign('base_ajax_url', $base_ajax_url);
     $next_link = null;
     $prev_link = null;
     if ($this->rtmodel->getNextId() != null) {
         $next_link = JRoute::_(RokCommon_URL::updateParams($base_page_url, array('view' => 'detail', 'id' => $this->rtmodel->getNextId(), 'page' => $this->rtmodel->getNextPage())));
     }
     if ($this->rtmodel->getPrevId() != null) {
         $prev_link = JRoute::_(RokCommon_URL::updateParams($base_page_url, array('view' => 'detail', 'id' => $this->rtmodel->getPrevId(), 'page' => $this->rtmodel->getPrevPage())));
     }
     $pathway =& $app->getPathway();
     $pwc = $pathway->getPathway();
     $pwc[count($pwc) - 1]->link = $pwc[count($pwc) - 1]->link . '&page=' . $page;
     $pathway->setPathway($pwc);
     $pathway->addItem($slice->title);
     $layout = $this->getLayout();
     $context = 'com_rokgallery.detail.' . $layout;
     $style_context = $context . "." . $style;
     $this->assign('gallery_link', JRoute::_($menuItem->link . "&page=" . $this->rtmodel->getCurrentPage()));
     $this->assign('gallery_name', $menuItem->title);
     $this->assign('context', $context);
     $this->assign('style_context', $style_context);
     $this->assign('width', $slice->Gallery->width);
     $this->assign('height', $slice->Gallery->height);
     $this->assign('love_text', rc__(RokGallery_Config::getOption(RokGallery_Config::OPTION_LOVE_TEXT)));
     $this->assign('unlove_text', rc__(RokGallery_Config::getOption(RokGallery_Config::OPTION_UNLOVE_TEXT)));
     $this->assignRef('slice', $slice);
     $image = $this->getPresentationImage($slice, $params);
     $this->assignRef('image', $image);
     $session->set('last_page', $this->rtmodel->getCurrentPage(), $session_namespace);
     $document->setTitle($document->getTitle() . ' - ' . $image->title);
     $this->assign('next_link', $next_link);
     $this->assign('prev_link', $prev_link);
     $this->assign('show_title', $params->get('detail_show_title', false));
     $this->assign('show_caption', $params->get('detail_show_caption', false));
     $this->assign('show_tags', $params->get('detail_show_tags', false));
     $this->assign('show_tags_count', $params->get('detail_show_tags_count', false));
     $this->assign('show_created_at', $params->get('detail_show_created_at', true));
     $this->assign('show_updated_at', $params->get('detail_show_updated_at', true));
     $this->assign('show_loves', $params->get('detail_show_loves', false));
     $this->assign('show_views', $params->get('detail_show_views', false));
     $this->assign('show_filesize', $params->get('detail_show_filesize', true));
     $this->assign('show_dimensions', $params->get('detail_show_dimensions', true));
     $this->assign('show_download_full', $params->get('detail_show_download_full', true));
     $this->assign('show_gallery_info', $params->get('detail_show_download_full', true));
     $this->setLayout('default');
     parent::display($tpl);
 }