protected function processImages() { if (!empty($this->items)) { $params = JComponentHelper::getParams('com_phocagallery'); $pagination_thumbnail_creation = $params->get('pagination_thumbnail_creation', 0); $clean_thumbnails = $params->get('clean_thumbnails', 0); //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->items_thumbnail)) { if ($pagination_thumbnail_creation == 1) { $this->items_thumbnail = $this->items; } else { $this->items_thumbnail = $this->get('ItemsThumbnail'); } } // - - - - - - - - - - - - - - - - - - - - // 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 = PhocaGalleryPath::getPath(); $origPath = $path->image_abs; $origPathServer = str_replace(DS, '/', $path->image_abs); //----------------------------------------- //Do all thumbnails no limit no pagination if (!empty($this->items_thumbnail)) { foreach ($this->items_thumbnail as $key => $value) { $fileOriginalThumb = PhocaGalleryFile::getFileOriginal($value->filename); //Let the user know that the file doesn't exists and delete all thumbnails if (JFile::exists($fileOriginalThumb)) { $refreshUrlThumb = 'index.php?option=com_phocagallery&view=phocagalleryimgs'; $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refreshUrlThumb, 1, 1, 1); } } } $this->items_thumbnail = null; // delete data to reduce memory //Only the the site with limitation or pagination... if (!empty($this->items)) { foreach ($this->items as $key => $value) { $fileOriginal = PhocaGalleryFile::getFileOriginal($value->filename); //Let the user know that the file doesn't exists and delete all thumbnails if (!JFile::exists($fileOriginal)) { $this->items[$key]->filename = JText::_('COM_PHOCAGALLERY_IMG_FILE_NOT_EXISTS'); $this->items[$key]->fileoriginalexist = 0; } else { //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&view=phocagalleryimgs'; $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($value->filename, $refresh_url, 1, 1, 1); $this->items[$key]->linkthumbnailpath = $fileThumb['thumb_name_s_no_rel']; $this->items[$key]->fileoriginalexist = 1; } } } //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { PhocaGalleryFileFolder::cleanThumbsFolder(); } } }
public static function getList($small = 0, $medium = 0, $large = 0, $refreshUrl) { static $list; $params = JComponentHelper::getParams('com_phocagallery'); $clean_thumbnails = $params->get('clean_thumbnails', 0); // Only process the list once per request if (is_array($list)) { return $list; } // Get current path from request $current = JRequest::getVar('folder'); // If undefined, set to empty if ($current == 'undefined') { $current = ''; } //Get folder variables from Helper $path = PhocaGalleryPath::getPath(); // Initialize variables if (strlen($current) > 0) { $origPath = JPath::clean($path->image_abs . $current); } else { $origPath = $path->image_abs; } $origPathServer = str_replace(DS, '/', $path->image_abs); $images = array(); $folders = array(); // Get the list of files and folders from the given folder $fileList = JFolder::files($origPath); $folderList = JFolder::folders($origPath, '', false, false, array(0 => 'thumbs')); if (is_array($fileList) && !empty($fileList)) { natcasesort($fileList); } $field = JRequest::getVar('field'); $refreshUrl = $refreshUrl . '&folder=' . $current . '&field=' . $field; // Iterate over the files if they exist //file - abc.img, file_no - folder/abc.img if ($fileList !== false) { foreach ($fileList as $file) { $ext = strtolower(JFile::getExt($file)); // Don't display thumbnails from defined files (don't save them into a database)... $dontCreateThumb = PhocaGalleryFileThumbnail::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 (JFile::exists($origPath . DS . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') { //Create thumbnails small, medium, large $fileNo = $current . "/" . $file; $fileThumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($fileNo, $refreshUrl, $small, $medium, $large); $tmp = new JObject(); $tmp->name = $fileThumb['name']; $tmp->nameno = $fileThumb['name_no']; $tmp->linkthumbnailpath = $fileThumb['thumb_name_m_no_rel']; $tmp->linkthumbnailpathabs = $fileThumb['thumb_name_m_no_abs']; $images[] = $tmp; } } } } //Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { PhocaGalleryFileFolder::cleanThumbsFolder(); } // - - - - - - - - - - - - // Iterate over the folders if they exist if ($folderList !== false) { foreach ($folderList as $folder) { $tmp = new JObject(); $tmp->name = basename($folder); $tmp->path_with_name = str_replace(DS, '/', JPath::clean($origPath . DS . $folder)); $tmp->path_without_name_relative = $path->image_abs . str_replace($origPathServer, '', $tmp->path_with_name); $tmp->path_with_name_relative_no = str_replace($origPathServer, '', $tmp->path_with_name); $folders[] = $tmp; } } $list = array('folders' => $folders, 'Images' => $images); return $list; }
function delete($cid = array()) { $params =& JComponentHelper::getParams('com_phocagallery'); $clean_thumbnails = $params->get('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); $fileObject = $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 ($fileObject 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); $sameFileObject = $this->_db->loadObject(); // same file in other category doesn't exist - we can delete it if (!$sameFileObject) { PhocaGalleryFileThumbnail::deleteFileThumbnail($value->filename, 1, 1, 1); } } // Clean Thumbs Folder if there are thumbnail files but not original file if ($clean_thumbnails == 1) { phocagalleryimport('phocagallery.file.filefolder'); PhocaGalleryFileFolder::cleanThumbsFolder(); } // - - - - - - - - - - - - - - } return true; }