Пример #1
0
 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;
 }
Пример #2
0
 function getOrCreateThumbnail($fileNo, $refreshUrl, $small = 0, $medium = 0, $large = 0, $frontUpload = 0)
 {
     if ($frontUpload) {
         $returnFrontMessage = '';
     }
     $onlyThumbnailInfo = 0;
     if ($small == 0 && $medium == 0 && $large == 0) {
         $onlyThumbnailInfo = 1;
     }
     $paramsC = JComponentHelper::getParams('com_phocagallery');
     $additional_thumbnails = $paramsC->get('additional_thumbnails', 0);
     $path = PhocaGalleryPath::getPath();
     $origPathServer = str_replace(DS, '/', $path->image_abs);
     $file['name'] = PhocaGalleryFile::getTitleFromFile($fileNo, 1);
     $file['name_no'] = ltrim($fileNo, '/');
     $file['name_original_abs'] = PhocaGalleryFile::getFileOriginal($fileNo);
     $file['name_original_rel'] = PhocaGalleryFile::getFileOriginal($fileNo, 1);
     $file['path_without_file_name_original'] = str_replace($file['name'], '', $file['name_original_abs']);
     $file['path_without_file_name_thumb'] = str_replace($file['name'], '', $file['name_original_abs'] . 'thumbs' . DS);
     //$file['path_without_name']				= str_replace(DS, '/', JPath::clean($origPathServer));
     //$file['path_with_name_relative_no']		= str_replace($origPathServer, '', $file['name_original']);
     /*
     		$file['path_with_name_relative']		= $path['orig_rel_ds'] . str_replace($origPathServer, '', $file['name_original']);
     		$file['path_with_name_relative_no']		= str_replace($origPathServer, '', $file['name_original']);
     		
     		$file['path_without_name']				= str_replace(DS, '/', JPath::clean($origPath.DS));
     		$file['path_without_name_relative']		= $path['orig_rel_ds'] . str_replace($origPathServer, '', $file['path_without_name']);
     		$file['path_without_name_relative_no']	= str_replace($origPathServer, '', $file['path_without_name']);
     		$file['path_without_name_thumbs'] 		= $file['path_without_name'] .'thumbs';
     		$file['path_without_file_name_original'] 			= str_replace($file['name'], '', $file['name_original']);
     		$file['path_without_name_thumbs_no'] 	= str_replace($file['name'], '', $file['name_original'] .'thumbs');*/
     $ext = strtolower(JFile::getExt($file['name']));
     switch ($ext) {
         case 'jpg':
         case 'png':
         case 'gif':
         case 'jpeg':
             //Get File thumbnails name
             $thumbNameS = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'small');
             $file['thumb_name_s_no_abs'] = $thumbNameS->abs;
             $file['thumb_name_s_no_rel'] = $thumbNameS->rel;
             $thumbNameM = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'medium');
             $file['thumb_name_m_no_abs'] = $thumbNameM->abs;
             $file['thumb_name_m_no_rel'] = $thumbNameM->rel;
             $thumbNameL = PhocaGalleryFileThumbnail::getThumbnailName($fileNo, 'large');
             $file['thumb_name_l_no_abs'] = $thumbNameL->abs;
             $file['thumb_name_l_no_rel'] = $thumbNameL->rel;
             // Don't create thumbnails from watermarks...
             $dontCreateThumb = PhocaGalleryFileThumbnail::dontCreateThumb($file['name']);
             if ($dontCreateThumb == 1) {
                 $onlyThumbnailInfo = 1;
                 // WE USE $onlyThumbnailInfo FOR NOT CREATE A THUMBNAIL CLAUSE
             }
             // We want only information from the pictures OR
             if ($onlyThumbnailInfo == 0) {
                 $thumbInfo = $fileNo;
                 //Create thumbnail folder if not exists
                 $errorMsg = 'ErrorCreatingFolder';
                 $creatingFolder = PhocaGalleryFileThumbnail::createThumbnailFolder($file['path_without_file_name_original'], $file['path_without_file_name_thumb'], $errorMsg);
                 switch ($errorMsg) {
                     case 'Success':
                         //case 'ThumbnailExists':
                     //case 'ThumbnailExists':
                     case 'DisabledThumbCreation':
                         //case 'OnlyInformation':
                         break;
                     default:
                         // BACKEND OR FRONTEND
                         if ($frontUpload != 1) {
                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl, $errorMsg, $frontUpload);
                             exit;
                         } else {
                             $returnFrontMessage = $errorMsg;
                         }
                         break;
                 }
                 // Folder must exist
                 if (JFolder::exists($file['path_without_file_name_thumb'])) {
                     $errorMsgS = $errorMsgM = $errorMsgL = '';
                     //Small thumbnail
                     if ($small == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameS->abs, 'small', $frontUpload, $errorMsgS);
                         if ($additional_thumbnails == 2 || $additional_thumbnails == 3) {
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s1_', $thumbNameS->abs), 'small1', $frontUpload, $errorMsgS);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s2_', $thumbNameS->abs), 'small2', $frontUpload, $errorMsgS);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_s_', 'phoca_thumb_s3_', $thumbNameS->abs), 'small3', $frontUpload, $errorMsgS);
                         }
                     } else {
                         $errorMsgS = 'ThumbnailExists';
                         // in case we only need medium or large, because of if clause bellow
                     }
                     //Medium thumbnail
                     if ($medium == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameM->abs, 'medium', $frontUpload, $errorMsgM);
                         if ($additional_thumbnails == 1 || $additional_thumbnails == 3) {
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m1_', $thumbNameM->abs), 'medium1', $frontUpload, $errorMsgM);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m2_', $thumbNameM->abs), 'medium2', $frontUpload, $errorMsgM);
                             PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], str_replace('phoca_thumb_m_', 'phoca_thumb_m3_', $thumbNameM->abs), 'medium3', $frontUpload, $errorMsgM);
                         }
                     } else {
                         $errorMsgM = 'ThumbnailExists';
                         // in case we only need small or large, because of if clause bellow
                     }
                     //Large thumbnail
                     if ($large == 1) {
                         PhocaGalleryFileThumbnail::createFileThumbnail($file['name_original_abs'], $thumbNameL->abs, 'large', $frontUpload, $errorMsgL);
                     } else {
                         $errorMsgL = 'ThumbnailExists';
                         // in case we only need small or medium, because of if clause bellow
                     }
                     // Error messages for all 3 thumbnails (if the message contains error string, we got error
                     // Other strings can be:
                     // - ThumbnailExists  - do not display error message nor success page
                     // - OnlyInformation - do not display error message nor success page
                     // - DisabledThumbCreation - do not display error message nor success page
                     $creatingSError = $creatingMError = $creatingLError = false;
                     $creatingSError = preg_match("/Error/i", $errorMsgS);
                     $creatingMError = preg_match("/Error/i", $errorMsgM);
                     $creatingLError = preg_match("/Error/i", $errorMsgL);
                     // BACKEND OR FRONTEND
                     if ($frontUpload != 1) {
                         // There is an error while creating thumbnail in m or in s or in l
                         if ($creatingSError || $creatingMError || $creatingLError) {
                             // if all or two errors appear, we only display the last error message
                             // because the errors in this case is the same
                             if ($errorMsgS != '') {
                                 $creatingError = $errorMsgS;
                             }
                             if ($errorMsgM != '') {
                                 $creatingError = $errorMsgM;
                             }
                             if ($errorMsgL != '') {
                                 $creatingError = $errorMsgL;
                             }
                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl, $creatingError);
                             exit;
                         } else {
                             if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == '') {
                                 PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                 exit;
                             } else {
                                 if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                     PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                     exit;
                                 } else {
                                     if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == 'ThumbnailExists') {
                                         PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                         exit;
                                     } else {
                                         if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                             PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                             exit;
                                         } else {
                                             if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                                 PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                 exit;
                                             } else {
                                                 if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == '') {
                                                     PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                     exit;
                                                 } else {
                                                     if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                                         PhocaGalleryRenderProcess::getProcessPage($file['name'], $thumbInfo, $refreshUrl);
                                                         exit;
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         // There is an error while creating thumbnail in m or in s or in l
                         if ($creatingSError || $creatingMError || $creatingLError) {
                             // if all or two errors appear, we only display the last error message
                             // because the errors in this case is the same
                             if ($errorMsgS != '') {
                                 $creatingError = $errorMsgS;
                             }
                             if ($errorMsgM != '') {
                                 $creatingError = $errorMsgM;
                             }
                             if ($errorMsgL != '') {
                                 $creatingError = $errorMsgL;
                             }
                             // because the errors in this case is the same
                             $returnFrontMessage = $creatingError;
                         } else {
                             if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == '') {
                                 $returnFrontMessage = 'Success';
                             } else {
                                 if ($errorMsgS == '' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                     $returnFrontMessage = 'Success';
                                 } else {
                                     if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == 'ThumbnailExists') {
                                         $returnFrontMessage = 'Success';
                                     } else {
                                         if ($errorMsgS == '' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                             $returnFrontMessage = 'Success';
                                         } else {
                                             if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == 'ThumbnailExists' && $errorMsgL == '') {
                                                 $returnFrontMessage = 'Success';
                                             } else {
                                                 if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == '') {
                                                     $returnFrontMessage = 'Success';
                                                 } else {
                                                     if ($errorMsgS == 'ThumbnailExists' && $errorMsgM == '' && $errorMsgL == 'ThumbnailExists') {
                                                         $returnFrontMessage = 'Success';
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if ($frontUpload == 1) {
                         return $returnFrontMessage;
                     }
                 }
             }
             break;
     }
     return $file;
 }
Пример #3
0
 protected function _addAllImagesFromFolder(&$existingImages, $category_id, $fullPath, $rel_path, $data = array())
 {
     $count = 0;
     $fileList = JFolder::files($fullPath);
     natcasesort($fileList);
     // Iterate over the files if they exist
     //file - abc.img, file_no - folder/abc.img
     if ($fileList !== false) {
         foreach ($fileList as $filename) {
             $storedfilename = ltrim(str_replace(DS, '/', JPath::clean($rel_path . DS . $filename)), '/');
             $ext = strtolower(JFile::getExt($filename));
             // Don't create thumbnails from defined files (don't save them into a database)...
             $dontCreateThumb = PhocaGalleryFileThumbnail::dontCreateThumb($filename);
             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($fullPath . DS . $filename) && substr($filename, 0, 1) != '.' && strtolower($filename) !== 'index.html' && !$this->_ImageExist($existingImages, $storedfilename, $category_id)) {
                     $row = $this->getTable('phocagallery');
                     $datam = array();
                     $datam['published'] = $data['published'];
                     $datam['catid'] = $category_id;
                     $datam['filename'] = $storedfilename;
                     $datam['approved'] = $data['approved'];
                     $datam['language'] = $data['language'];
                     if ($data['title'] != '') {
                         $datam['title'] = $data['title'];
                     } else {
                         $datam['title'] = PhocaGalleryFile::getTitleFromFile($filename);
                     }
                     if ($data['alias'] != '') {
                         $datam['alias'] = $data['alias'];
                     } else {
                         $datam['alias'] = $datam['title'];
                         //PhocaGalleryText::getAliasName($datam['title']);
                     }
                     $datam['imgorigsize'] = PhocaGalleryFile::getFileSize($datam['filename'], 0);
                     $datam['format'] = PhocaGalleryFile::getFileFormat($datam['filename']);
                     // Geo
                     phocagalleryimport('phocagallery.geo.geo');
                     $coords = PhocaGalleryGeo::getGeoCoords($datam['filename']);
                     $datam['longitude'] = $coords['longitude'];
                     $datam['latitude'] = $coords['latitude'];
                     if ($datam['latitude'] != '' && $datam['longitude'] != '') {
                         $datam['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom');
                     }
                     // Save
                     // Bind the form fields to the Phoca gallery table
                     if (!$row->bind($datam)) {
                         $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;
                     }
                     if ($this->firstImageFolder == '') {
                         $this->setFirstImageFolder($row->filename);
                     }
                     $image = new JObject();
                     $image->filename = $storedfilename;
                     $image->catid = $category_id;
                     $existingImages[] =& $image;
                     $count++;
                 }
             }
         }
     }
     //	$this->setImageCount($count);
     return $count;
 }