Exemple #1
0
 function _loadData()
 {
     global $mainframe;
     // Lets load the content if it doesn't already exist
     if (empty($this->_data)) {
         // Lets load the content if it doesn't already exist
         if (empty($this->_data)) {
             $query = 'SELECT p.filename as filename' . ' FROM #__phocagallery AS p' . ' WHERE p.id = ' . (int) $this->_id;
             $this->_db->setQuery($query);
             $filename_object = $this->_db->loadObject();
             //Get Folder settings and File resize settings
             $path = PhocaGalleryHelper::getPathSet();
             $file = new JObject();
             //Create thumbnail if it doesn't exists but originalfile must exist
             $orig_path = $path['orig_abs_ds'];
             $refresh_url = 'index.php?option=com_phocagallery&view=phocagalleryd&tmpl=component&cid[]=' . $this->_id;
             //Creata thumbnails if not exist
             PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $filename_object->filename, $refresh_url, 1, 1, 1);
             jimport('joomla.filesystem.file');
             if (!isset($filename_object->filename)) {
                 $file->set('linkthumbnailpath', '');
             } else {
                 $thumbnail_file = PhocaGalleryHelper::getThumbnailName($filename_object->filename, 'large');
                 $file->set('linkthumbnailpath', $thumbnail_file['rel']);
             }
         }
         if (isset($file)) {
             $this->_data = $file;
         } else {
             $this->_data = '';
         }
         return (bool) $this->_data;
     }
     return true;
 }
Exemple #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;
 }
Exemple #3
0
 function store($data, $return)
 {
     //If this file doesn't exists don't save it
     if (!PhocaGalleryHelper::existsFileOriginal($data['filename'])) {
         $this->setError('File not exists');
         return false;
     }
     //If there is no title and no alias, use filename as title and alias
     if (!isset($data['title']) || isset($data['title']) && $data['title'] == '') {
         $data['title'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']);
     }
     if (!isset($data['alias']) || isset($data['alias']) && $data['alias'] == '') {
         $data['alias'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']);
     }
     //clean alias name (no bad characters)
     $data['alias'] = PhocaGalleryHelper::getAliasName($data['alias']);
     $row =& $this->getTable('phocagallery');
     // Bind the form fields to the Phoca gallery table
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Create the timestamp for the date
     $row->date = gmdate('Y-m-d H:i:s');
     // if new item, order last in appropriate group
     if (!$row->id) {
         $where = 'catid = ' . (int) $row->catid;
         $row->ordering = $row->getNextOrder($where);
     }
     // Make sure the Phoca gallery table is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Store the Phoca gallery table to the database
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     //Create thumbnail small, medium, large
     $path = PhocaGalleryHelper::getPathSet();
     $returnFrontMessage = PhocaGalleryHelper::getOrCreateThumbnail($path['orig_abs_ds'], $row->filename, $return, 1, 1, 1, 1);
     if ($returnFrontMessage == 'Success') {
         return true;
     } else {
         return false;
     }
 }
Exemple #4
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;
 }
Exemple #5
0
 function piclens($cids)
 {
     $db =& JFactory::getDBO();
     $path = PhocaGalleryHelper::getPathSet();
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     // PARAMS
     $piclens_image = $paramsC->get('piclens_image', 1);
     if (JFolder::exists($path['orig_abs_ds'])) {
         foreach ($cids as $kcid => $vcid) {
             $this->setXMLFile();
             if (!$this->_XMLFile) {
                 $this->setError('Could not create XML builder');
                 return false;
             }
             if (!($node = $this->_XMLFile->createElement('rss'))) {
                 $this->setError('Could not create node!');
                 return false;
             }
             $node->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss');
             $node->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
             $node->setAttribute('version', '2.0');
             $this->_XMLFile->setDocumentElement($node);
             if (!($root =& $this->_XMLFile->documentElement)) {
                 $this->setError('Could not obtain root element!');
                 return false;
             }
             $channel =& $this->_XMLFile->createElement('channel');
             $atomIcon =& $this->_XMLFile->createElement('atom:icon');
             $atomIcon->setText('http://www.phoca.cz/images/phoca-piclens.png');
             $channel->appendChild($atomIcon);
             $query = 'SELECT a.id AS id, a.title AS title, a.filename AS filename FROM #__phocagallery AS a' . ' WHERE a.catid = ' . (int) $vcid . ' AND a.published = 1' . ' ORDER BY a.catid, a.ordering';
             $db->setQuery($query);
             $rows = $db->loadObjectList();
             foreach ($rows as $krow => $vrow) {
                 $file = PhocaGalleryHelper::getOrCreateThumbnail('', $vrow->filename, '');
                 $orig_file = str_replace("../", "", $file['path_with_name_relative']);
                 $orig_file = str_replace("//", "/", $orig_file);
                 $thumb_name_l_no_rel = str_replace("../", "", $file['thumb_name_l_no_rel']);
                 $thumb_name_l_no_rel = str_replace("//", "/", $thumb_name_l_no_rel);
                 $juri_base = str_replace("administrator", "", JURI::base(true));
                 $thumb_image_path = $juri_base . $thumb_name_l_no_rel;
                 $orig_file_path = $juri_base . $orig_file;
                 $item =& $this->_XMLFile->createElement('item');
                 $item->appendChild($this->_buildXMLElement('title', $vrow->title));
                 $item->appendChild($this->_buildXMLElement('link', $thumb_image_path));
                 $thumbnail =& $this->_XMLFile->createElement('media:thumbnail');
                 $thumbnail->setAttribute('url', $thumb_image_path);
                 $content =& $this->_XMLFile->createElement('media:content');
                 if ($piclens_image == 1) {
                     $content->setAttribute('url', $thumb_image_path);
                 } else {
                     $content->setAttribute('url', $orig_file_path);
                 }
                 $item->appendChild($thumbnail);
                 $item->appendChild($content);
                 $guid =& $this->_XMLFile->createElement('guid');
                 $guid->setText($vcid . '-phocagallerypiclenscode-' . $vrow->filename);
                 $guid->setAttribute('isPermaLink', "false");
                 $item->appendChild($guid);
                 $channel->appendChild($item);
             }
             $root->appendChild($channel);
             $this->_XMLFile->setXMLDeclaration('<?xml version="1.0" encoding="utf-8" standalone="yes"?>');
             //echo $this->_XMLFile->toNormalizedString( true );exit;
             // saveXML_utf8 doesn't save setXMLDeclaration
             if (!$this->_XMLFile->saveXML($path['orig_abs_ds'] . DS . $vcid . '.rss', true)) {
                 $this->setError('Could not save XML file!');
                 return false;
             }
         }
         return true;
     } else {
         $this->setError('Phoca Gallery image folder not exists');
     }
 }
Exemple #6
0
 function store($data)
 {
     //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;
     }
     //If this file doesn't exists don't save it
     if (!PhocaGalleryHelper::existsFileOriginal($data['filename'])) {
         $this->setError();
         return false;
     }
     //If there is no title and no alias, use filename as title and alias
     if ($data['title'] == '') {
         $data['title'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']);
     }
     if ($data['alias'] == '') {
         $data['alias'] = PhocaGalleryHelper::getTitleFromFilenameWithoutExt($data['filename']);
     }
     //clean alias name (no bad characters)
     $data['alias'] = PhocaGalleryHelper::getAliasName($data['alias']);
     $row =& $this->getTable();
     // Bind the form fields to the Phoca gallery table
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Create the timestamp for the date
     $row->date = gmdate('Y-m-d H:i:s');
     // if new item, order last in appropriate group
     if (!$row->id) {
         $where = 'catid = ' . (int) $row->catid;
         $row->ordering = $row->getNextOrder($where);
     }
     // Make sure the Phoca gallery table is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Store the Phoca gallery table to the database
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     //------------------------------------------------------------------------------------------------------
     //Create thumbnail small, medium, large
     //------------------------------------------------------------------------------------------------------
     //file - abc.img, file_no - folder/abc.img
     //Get folder variables from Helper
     $path = PhocaGalleryHelper::getPathSet();
     $orig_path = $path['orig_abs_ds'];
     //Create thumbnails small, medium, large
     $refresh_url = 'index.php?option=com_phocagallery&controller=phocagallery&task=thumbs';
     $file_thumb = PhocaGalleryHelper::getOrCreateThumbnail($orig_path, $row->filename, $refresh_url, 1, 1, 1);
     //Clean Thumbs Folder if there are thumbnail files but not original file
     if ($clean_thumbnails == 1) {
         PhocaGalleryHelper::cleanThumbsFolder();
     }
     //---------------------------------------------------------------------------------------------------------------
     return true;
 }