Beispiel #1
0
 function getData()
 {
     //Params
     $params =& JComponentHelper::getParams('com_phocagallery');
     //Standard Thumbs creation or Pagination Thumbs Creation
     if ($params->get('pagination_thumbnail_creation') != '') {
         $pagination_thumbnail_creation = $params->get('pagination_thumbnail_creation');
     } else {
         $pagination_thumbnail_creation = 0;
     }
     //Clean Thumbnails or not
     if ($params->get('clean_thumbnails') != '') {
         $clean_thumbnails = $params->get('clean_thumbnails');
     } else {
         $clean_thumbnails = 0;
     }
     // Lets load the content if it doesn't already exist
     if (empty($this->_data)) {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
     }
     //Server doesn't have CPU power
     //we do thumbnail for all images - there is no pagination...
     //or we do thumbanil for only listed images
     if (empty($this->_data_thumbnail)) {
         if ($pagination_thumbnail_creation == 1) {
             $this->_data_thumbnail = $this->_data;
         } else {
             $query = $this->_buildQueryThumbnail();
             $this->_data_thumbnail = $this->_getList($query);
         }
     }
     //------------------------------------------------------------------------------------------------------
     // Check if the file stored in database is on the server. If not please refer to user
     // Get filename from every object there is stored in database
     //------------------------------------------------------------------------------------------------------
     //file - abc.img, file_no - folder/abc.img
     //Get folder variables from Helper
     $path = PhocaGalleryHelper::getPathSet();
     $orig_path = $path['orig_abs_ds'];
     $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/');
     //-----------------------------------------
     //Do all thumbnails no limit no pagination
     if (!empty($this->_data_thumbnail)) {
         foreach ($this->_data_thumbnail as $key => $value) {
             $file_original_thumb = PhocaGalleryHelper::getFileOriginal($value->filename);
             //Let the user know that the file doesn't exists and delete all thumbnails
             if (!JFile::exists($file_original_thumb)) {
                 //$this->_data[$key]->filename = JText::_( 'File does not exist' );
                 //$this->_data[$key]->fileoriginalexist = 0;
                 //We must not delete the thumbnails if the file doesn't exist - we use cleanThumbsFolder() function
             } else {
                 //Create thumbnails small, medium, large
                 $refresh_url_thumb = 'index.php?option=com_phocagallery&view=phocagallerys';
                 //$refresh_url_thumb = 'index.php?option=com_phocagallery&controller=phocagallerys';
                 $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $value->filename, $refresh_url_thumb, 1, 1, 1);
                 //$this->_data[$key]->linkthumbnailpath 	= $file_thumb['thumb_name_s_no_rel'];
                 //$this->_data[$key]->path_without_name_relative	= $file_thumb['path_without_name_relative'];
                 //$this->_data[$key]->fileoriginalexist = 1;
             }
         }
         //Clean Thumbs Folder if there are thumbnail files but not original file
         //PhocaGalleryHelper::cleanThumbsFolder();
         //------------------------------------------------------------------------------------------------------
     }
     $this->_data_thumbnail = null;
     // delete data to reduce memory
     //Only the the site with limitation or pagination...
     if (!empty($this->_data)) {
         foreach ($this->_data as $key => $value) {
             $file_original = PhocaGalleryHelper::getFileOriginal($value->filename);
             //Let the user know that the file doesn't exists and delete all thumbnails
             if (!JFile::exists($file_original)) {
                 $this->_data[$key]->filename = JText::_('Image Filename does not exist');
                 $this->_data[$key]->fileoriginalexist = 0;
                 //We must not delete the thumbnails if the file doesn't exist - we use cleanThumbsFolder() function
             } else {
                 //Create thumbnails small, medium, large
                 $refresh_url = 'index.php?option=com_phocagallery&view=phocagallerys';
                 //$refresh_url = 'index.php?option=com_phocagallery&controller=phocagallerys';
                 $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $value->filename, $refresh_url, 1, 1, 1);
                 $this->_data[$key]->linkthumbnailpath = $file_thumb['thumb_name_s_no_rel'];
                 //$this->_data[$key]->path_without_name_relative	= $file_thumb['path_without_name_relative'];
                 $this->_data[$key]->fileoriginalexist = 1;
             }
         }
         //Clean Thumbs Folder if there are thumbnail files but not original file
         //PhocaGalleryHelper::cleanThumbsFolder();
         //------------------------------------------------------------------------------------------------------
     }
     //Clean Thumbs Folder if there are thumbnail files but not original file
     if ($clean_thumbnails == 1) {
         PhocaGalleryHelper::cleanThumbsFolder();
     }
     return $this->_data;
 }
Beispiel #2
0
 function getList()
 {
     static $list;
     //Params
     $params =& JComponentHelper::getParams('com_phocagallery');
     //Clean Thumbnails or not
     if ($params->get('clean_thumbnails') != '') {
         $clean_thumbnails = $params->get('clean_thumbnails');
     } else {
         $clean_thumbnails = 0;
     }
     // Only process the list once per request
     if (is_array($list)) {
         return $list;
     }
     // Get current path from request
     $current = $this->getState('folder');
     // If undefined, set to empty
     if ($current == 'undefined') {
         $current = '';
     }
     //Get folder variables from Helper
     $path = PhocaGalleryHelper::getPathSet();
     // Initialize variables
     if (strlen($current) > 0) {
         $orig_path = $path['orig_abs_ds'] . $current;
     } else {
         $orig_path = $path['orig_abs_ds'];
     }
     $orig_path_server = str_replace(DS, '/', $path['orig_abs'] . '/');
     $images = array();
     $folders = array();
     // Get the list of files and folders from the given folder
     $file_list = JFolder::files($orig_path);
     $folder_list = JFolder::folders($orig_path, '', false, false, array(0 => 'thumbs'));
     natcasesort($file_list);
     // Iterate over the files if they exist
     //file - abc.img, file_no - folder/abc.img
     if ($file_list !== false) {
         foreach ($file_list as $file) {
             $ext = strtolower(JFile::getExt($file));
             // Don't display thumbnails from defined files (don't save them into a database)...
             $dontCreateThumb = PhocaGalleryHelper::dontCreateThumb($file);
             if ($dontCreateThumb == 1) {
                 $ext = '';
                 // WE USE $ext FOR NOT CREATE A THUMBNAIL CLAUSE
             }
             if ($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg') {
                 if (is_file($orig_path . DS . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
                     //Create thumbnails small, medium, large
                     $refresh_url = 'index.php?option=com_phocagallery&view=phocagallerym&layout=form&hidemainmenu=1&folder=' . $current;
                     $file_no = $current . "/" . $file;
                     $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($path['orig_abs_ds'], $file_no, $refresh_url, 0, 0, 0);
                     $tmp = new JObject();
                     $tmp->name = $file_thumb['name'];
                     $tmp->path_with_name_relative_no = $file_thumb['path_with_name_relative_no'];
                     $tmp->linkthumbnailpath = $file_thumb['thumb_name_m_no_rel'];
                     $images[] = $tmp;
                 }
             }
         }
     }
     //Clean Thumbs Folder if there are thumbnail files but not original file
     if ($clean_thumbnails == 1) {
         PhocaGalleryHelper::cleanThumbsFolder();
     }
     //---------------------------------------------------------------------------------------------------------------
     // Iterate over the folders if they exist
     if ($folder_list !== false) {
         foreach ($folder_list as $folder) {
             $tmp = new JObject();
             $tmp->name = basename($folder);
             $tmp->path_with_name = str_replace(DS, '/', JPath::clean($orig_path . DS . $folder));
             $tmp->path_without_name_relative = $path['orig_rel_ds'] . str_replace($orig_path_server, '', $tmp->path_with_name);
             $tmp->path_with_name_relative_no = str_replace($orig_path_server, '', $tmp->path_with_name);
             $folders[] = $tmp;
         }
     }
     $list = array('folders' => $folders, 'images' => $images);
     return $list;
 }
Beispiel #3
0
 function delete($cid = array())
 {
     //Params
     $params =& JComponentHelper::getParams('com_phocagallery');
     //Clean Thumbnails or not
     if ($params->get('clean_thumbnails') != '') {
         $clean_thumbnails = $params->get('clean_thumbnails');
     } else {
         $clean_thumbnails = 0;
     }
     $result = false;
     if (count($cid)) {
         JArrayHelper::toInteger($cid);
         $cids = implode(',', $cid);
         //-------------------------------------------------------------------------------------------------------
         // Get all filenames we want to delete from database, we delete all thumbnails from server of this file
         $queryd = 'SELECT filename as filename FROM #__phocagallery WHERE id IN ( ' . $cids . ' )';
         $this->_db->setQuery($queryd);
         $file_object = $this->_db->loadObjectList();
         //-------------------------------------------------------------------------------------------------------
         //Delete it from DB
         $query = 'DELETE FROM #__phocagallery' . ' WHERE id IN ( ' . $cids . ' )';
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         //------------------------------------------------------------------------------------------------------
         # Delete thumbnails - medium and large, small from server
         //All id we want to delete - gel all filenames
         foreach ($file_object as $key => $value) {
             //The file can be stored in other category - don't delete it from server because other category use it
             $querys = "SELECT id as id FROM #__phocagallery WHERE filename='" . $value->filename . "' ";
             $this->_db->setQuery($queryd);
             $same_file_object = $this->_db->loadObject();
             //same file in other category doesn't exist - we can delete it
             if (!$same_file_object) {
                 //Delete all thumbnail files but not original (Only user can delete original file e.g. in media manager)
                 //if (JFile::exists($file_original))		{JFile::delete($file_thumbnail);}
                 PhocaGalleryHelper::deleteFileThumbnail($value->filename, 1, 1, 1);
             }
         }
         //Clean Thumbs Folder if there are thumbnail files but not original file
         if ($clean_thumbnails == 1) {
             PhocaGalleryHelper::cleanThumbsFolder();
         }
         //------------------------------------------------------------------------------------------------------
     }
     return true;
 }