function display($tpl = null) { $app = JFactory::getApplication(); $document =& JFactory::getDocument(); $this->params = $app->getParams(); $user =& JFactory::getUser(); $var['slideshow'] = JRequest::getVar('phocaslideshow', 0, '', 'int'); $var['download'] = JRequest::getVar('phocadownload', 0, '', 'int'); $uri =& JFactory::getURI(); $this->tmpl['action'] = $uri->toString(); $path = PhocaGalleryPath::getPath(); $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels(); $access = PhocaGalleryAccess::isAccess($user->authorisedLevels(), $neededAccessLevels); // Information from the plugin - window is displayed after plugin action $get = array(); $get['detail'] = JRequest::getVar('detail', '', 'get', 'string'); $get['buttons'] = JRequest::getVar('buttons', '', 'get', 'string'); $get['ratingimg'] = JRequest::getVar('ratingimg', '', 'get', 'string'); $this->tmpl['picasa_correct_width_l'] = (int) $this->params->get('large_image_width', 640); $this->tmpl['picasa_correct_height_l'] = (int) $this->params->get('large_image_height', 480); $this->tmpl['enablecustomcss'] = $this->params->get('enable_custom_css', 0); $this->tmpl['customcss'] = $this->params->get('custom_css', ''); $this->tmpl['enable_multibox'] = $this->params->get('enable_multibox', 0); $this->tmpl['multibox_height'] = (int) $this->params->get('multibox_height', 560); $this->tmpl['multibox_width'] = (int) $this->params->get('multibox_width', 980); $this->tmpl['multibox_map_height'] = (int) $this->params->get('multibox_map_height', 300); $this->tmpl['multibox_map_width'] = (int) $this->params->get('multibox_map_width', 280); $this->tmpl['multibox_height_overflow'] = (int) $this->tmpl['multibox_height'] - 10; //padding $this->tmpl['multibox_left_bgcolor'] = $this->params->get('multibox_left_bgcolor', '#000000'); $this->tmpl['multibox_right_bgcolor'] = $this->params->get('multibox_right_bgcolor', '#ffffff'); $this->tmpl['multibox_comments_width'] = $this->params->get('multibox_comments_width', 300); $this->tmpl['multibox_comments_height'] = $this->params->get('multibox_comments_height', 600); $this->tmpl['multibox_thubms_box_width'] = $this->params->get('multibox_thubms_box_width', 300); $this->tmpl['multibox_thubms_count'] = $this->params->get('multibox_thubms_count', 4); $this->tmpl['large_image_width'] = $this->params->get('large_image_width', 640); $this->tmpl['large_image_height'] = $this->params->get('large_image_height', 640); $this->tmpl['multibox_fixed_cols'] = $this->params->get('multibox_fixed_cols', 1); $this->tmpl['display_multibox'] = $this->params->get('display_multibox', array(1, 2)); // CSS JHtml::stylesheet('components/com_phocagallery/assets/phocagallery.css'); if ($this->tmpl['enablecustomcss'] == 1) { JHtml::stylesheet('components/com_phocagallery/assets/phocagallerycustom.css'); PhocaGalleryRenderFront::displayCustomCSS($this->tmpl['customcss']); } // Plugin information $this->tmpl['detailwindow'] = $this->params->get('detail_window', 0); if (isset($get['detail']) && $get['detail'] != '') { $this->tmpl['detailwindow'] = $get['detail']; } // Plugin information $this->tmpl['detailbuttons'] = $this->params->get('detail_buttons', 1); if (isset($get['buttons']) && $get['buttons'] != '') { $this->tmpl['detailbuttons'] = $get['buttons']; } // Close and Reload links (for different window types) $close = PhocaGalleryRenderFront::renderCloseReloadDetail($this->tmpl['detailwindow']); $this->tmpl['detailwindowclose'] = $close['detailwindowclose']; $this->tmpl['detailwindowreload'] = $close['detailwindowreload']; $this->tmpl['displaydescriptiondetail'] = $this->params->get('display_description_detail', 0); $this->tmpl['displaytitleindescription'] = $this->params->get('display_title_description', 0); $this->tmpl['descriptiondetailheight'] = $this->params->get('description_detail_height', 16); $this->tmpl['fontsizedesc'] = $this->params->get('font_size_desc', 11); $this->tmpl['fontcolordesc'] = $this->params->get('font_color_desc', '#333333'); $this->tmpl['detailwindowbackgroundcolor'] = $this->params->get('detail_window_background_color', '#ffffff'); $this->tmpl['descriptionlightboxfontcolor'] = $this->params->get('description_lightbox_font_color', '#ffffff'); $this->tmpl['descriptionlightboxbgcolor'] = $this->params->get('description_lightbox_bg_color', '#000000'); $this->tmpl['descriptionlightboxfontsize'] = $this->params->get('description_lightbox_font_size', 12); $this->tmpl['displayratingimg'] = $this->params->get('display_rating_img', 0); $this->tmpl['displayicondownload'] = $this->params->get('display_icon_download', 0); $this->tmpl['externalcommentsystem'] = $this->params->get('external_comment_system', 0); $this->tmpl['largewidth'] = $this->params->get('large_image_width', 640); $this->tmpl['largeheight'] = $this->params->get('large_image_height', 480); $this->tmpl['boxlargewidth'] = $this->params->get('front_modal_box_width', 680); $this->tmpl['boxlargeheight'] = $this->params->get('front_modal_box_height', 560); $this->tmpl['slideshow_delay'] = $this->params->get('slideshow_delay', 3000); $this->tmpl['slideshow_pause'] = $this->params->get('slideshow_pause', 2500); $this->tmpl['slideshowrandom'] = $this->params->get('slideshow_random', 0); $this->tmpl['slideshow_description'] = $this->params->get('slideshow_description', 'peekaboo'); $this->tmpl['gallerymetakey'] = $this->params->get('gallery_metakey', ''); $this->tmpl['gallerymetadesc'] = $this->params->get('gallery_metadesc', ''); $this->tmpl['altvalue'] = $this->params->get('alt_value', 1); $this->tmpl['enablecustomcss'] = $this->params->get('enable_custom_css', 0); $this->tmpl['customcss'] = $this->params->get('custom_css', ''); $this->tmpl['display_tags_links'] = $this->params->get('display_tags_links', 0); $this->tmpl['ytb_display'] = $this->params->get('ytb_display', 0); $paramsFb = PhocaGalleryFbSystem::getCommentsParams($this->params->get('fb_comment_user_id', '')); // Facebook $this->tmpl['fb_comment_app_id'] = isset($paramsFb['fb_comment_app_id']) ? $paramsFb['fb_comment_app_id'] : ''; $this->tmpl['fb_comment_width'] = isset($paramsFb['fb_comment_width']) ? $paramsFb['fb_comment_width'] : 550; $this->tmpl['fb_comment_lang'] = isset($paramsFb['fb_comment_lang']) ? $paramsFb['fb_comment_lang'] : 'en_US'; $this->tmpl['fb_comment_count'] = isset($paramsFb['fb_comment_count']) ? $paramsFb['fb_comment_count'] : ''; $oH = ''; if ($this->tmpl['enable_multibox'] == 1) { $this->tmpl['fb_comment_width'] = $this->tmpl['multibox_comments_width']; $oH = 'overflow:hidden;'; } // CSS JHtml::stylesheet('components/com_phocagallery/assets/phocagallery.css'); if ($this->tmpl['enablecustomcss'] == 1) { JHtml::stylesheet('components/com_phocagallery/assets/phocagallerycustom.css'); if ($this->tmpl['customcss'] != '') { $document->addCustomTag("\n <style type=\"text/css\"> \n" . $this->escape(strip_tags($this->tmpl['customcss'])) . "\n </style> \n"); } } //Multibox displaying $this->tmpl['mb_title'] = PhocaGalleryUtils::isEnabledMultiboxFeature(1); $this->tmpl['mb_desc'] = PhocaGalleryUtils::isEnabledMultiboxFeature(2); $this->tmpl['mb_uploaded_by'] = PhocaGalleryUtils::isEnabledMultiboxFeature(3); $this->tmpl['mb_rating'] = PhocaGalleryUtils::isEnabledMultiboxFeature(4); $this->tmpl['mb_maps'] = PhocaGalleryUtils::isEnabledMultiboxFeature(5); $this->tmpl['mb_tags'] = PhocaGalleryUtils::isEnabledMultiboxFeature(6); $this->tmpl['mb_comments'] = PhocaGalleryUtils::isEnabledMultiboxFeature(7); $this->tmpl['mb_thumbs'] = PhocaGalleryUtils::isEnabledMultiboxFeature(8); // No bar in Detail View if ($this->tmpl['detailwindow'] == 7) { } else { $document->addCustomTag("<style type=\"text/css\"> \n" . " html, body, .contentpane, #all, #main {" . $oH . "background:" . $this->tmpl['detailwindowbackgroundcolor'] . ";padding:0px !important;margin:0px !important; width: 100% !important; max-width: 100% !important;} \n" . " center, table {background:" . $this->tmpl['detailwindowbackgroundcolor'] . ";} \n" . " #sbox-window {background-color:#fff;padding:5px} \n" . "body {min-width:100%} \n" . ".rt-container {width:100%} \n" . " </style> \n"); } // Download from the detail view which is not in the popupbox if ($var['download'] == 2) { $this->tmpl['displayicondownload'] = 2; } // Plugin Information if (isset($get['ratingimg']) && $get['ratingimg'] != '') { $this->tmpl['displayratingimg'] = $get['ratingimg']; } // Model $model =& $this->getModel(); $item = $model->getData(); //Multibox Thumbnails $this->tmpl['mb_thumbs_data'] = ''; if ($this->tmpl['mb_thumbs'] == 1) { // if we get item variable, we have rights to load the thumbnails, this is why we checking it if (isset($item->id) && isset($item->catid) && (int) $item->id > 0 && (int) $item->catid > 0) { $this->tmpl['mb_thumbs_data'] = $model->getThumbnails((int) $item->id, (int) $item->catid, (int) $item->ordering); } } // User Avatar $this->tmpl['useravatarimg'] = ''; $this->tmpl['useravatarmiddle'] = ''; $userAvatar = PhocaGalleryUser::getUserAvatar($item->userid); if ($userAvatar) { $pathAvatarAbs = $path->avatar_abs . 'thumbs' . DS . 'phoca_thumb_s_' . $userAvatar->avatar; $pathAvatarRel = $path->avatar_rel . 'thumbs/phoca_thumb_s_' . $userAvatar->avatar; if (JFile::exists($pathAvatarAbs)) { $sIH = $this->params->get('small_image_height', 50); $sIHR = @getImageSize($pathAvatarAbs); if (isset($sIHR[1])) { $sIH = $sIHR[1]; } if ((int) $sIH > 0) { $this->tmpl['useravatarmiddle'] = (int) $sIH / 2 - 10; } $this->tmpl['useravatarimg'] = '<img src="' . JURI::base(true) . '/' . $pathAvatarRel . '?imagesid=' . md5(uniqid(time())) . '" alt="" />'; } } // Access check - don't display the image if you have no access to this image (if user add own url) // USER RIGHT - ACCESS - - - - - - - - - - $rightDisplay = 0; if (!empty($item)) { $rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $item->cataccessuserid, $item->cataccess, $user->authorisedLevels(), $user->get('id', 0), 0); } if ((int) $rightDisplay == 0) { echo $close['html']; //Some problem with cache - Joomla! return this message if there is no reason for do it. //$this->tmpl['pl'] = 'index.php?option=com_users&view=login&return='.base64_encode($uri->toString()); //$app->redirect(JRoute::_($this->tmpl['pl'], false), JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION')); exit; } // - - - - - - - - - - - - - - - - - - - - phocagalleryimport('phocagallery.image.image'); phocagalleryimport('phocagallery.render.renderdetailbutton'); // Javascript Slideshow buttons $detailButton = new PhocaGalleryRenderDetailButton(); if ($this->tmpl['enable_multibox'] == 1) { $detailButton->setType('multibox'); } $item->reloadbutton = $detailButton->getReload($item->catslug, $item->slug); $item->closebutton = $detailButton->getClose($item->catslug, $item->slug); $item->closetext = $detailButton->getCloseText($item->catslug, $item->slug); $item->nextbutton = $detailButton->getNext((int) $item->catid, (int) $item->id, (int) $item->ordering); $item->nextbuttonhref = $detailButton->getNext((int) $item->catid, (int) $item->id, (int) $item->ordering, 1); $item->prevbutton = $detailButton->getPrevious((int) $item->catid, (int) $item->id, (int) $item->ordering); $slideshowData = $detailButton->getJsSlideshow((int) $item->catid, (int) $item->id, (int) $var['slideshow'], $item->catslug, $item->slug); $item->slideshowbutton = $slideshowData['icons']; $item->slideshowfiles = $slideshowData['files']; $item->slideshow = $var['slideshow']; $item->download = $var['download']; // ALT VALUE $altValue = PhocaGalleryRenderFront::getAltValue($this->tmpl['altvalue'], $item->title, $item->description, $item->metadesc); $item->altvalue = $altValue; // Get file thumbnail or No Image $item->filenameno = $item->filename; $item->filename = PhocaGalleryFile::getTitleFromFile($item->filename, 1); $item->filesize = PhocaGalleryFile::getFileSize($item->filenameno); $realImageSize = ''; $extImage = PhocaGalleryImage::isExtImage($item->extid); if ($extImage) { $item->extl = $item->extl; $item->exto = $item->exto; $realImageSize = PhocaGalleryImage::getRealImageSize($item->extl, '', 1); $item->imagesize = PhocaGalleryImage::getImageSize($item->exto, 1, 1); if ($item->extw != '') { $extw = explode(',', $item->extw); $item->extw = $extw[0]; } $correctImageRes = PhocaGalleryPicasa::correctSizeWithRate($item->extw, $item->exth, $this->tmpl['picasa_correct_width_l'], $this->tmpl['picasa_correct_height_l']); $item->linkimage = JHtml::_('image', $item->extl, $item->altvalue, array('width' => $correctImageRes['width'], 'height' => $correctImageRes['height'], 'class' => 'pg-detail-image')); $item->realimagewidth = $correctImageRes['width']; $item->realimageheight = $correctImageRes['height']; } else { $item->linkthumbnailpath = PhocaGalleryImageFront::displayCategoryImageOrNoImage($item->filenameno, 'large'); $item->linkimage = JHtml::_('image', $item->linkthumbnailpath, $item->altvalue, array('class' => 'pg-detail-image')); $realImageSize = PhocaGalleryImage::getRealImageSize($item->filenameno); $item->imagesize = PhocaGalleryImage::getImageSize($item->filenameno, 1); if (isset($realImageSize['w']) && isset($realImageSize['h'])) { $item->realimagewidth = $realImageSize['w']; $item->realimageheight = $realImageSize['h']; } else { $item->realimagewidth = $this->tmpl['largewidth']; $item->realimageheight = $this->tmpl['largeheight']; } } // Add Statistics $model->hit(JRequest::getVar('id', '', '', 'int')); // R A T I N G // Only registered (VOTES + COMMENTS) $this->tmpl['notregisteredimg'] = true; $this->tmpl['usernameimg'] = ''; if ($access > 0) { $this->tmpl['notregisteredimg'] = false; $this->tmpl['usernameimg'] = $user->name; } // VOTES Statistics Img if ((int) $this->tmpl['displayratingimg'] == 1 || $this->tmpl['mb_rating']) { $this->tmpl['votescountimg'] = 0; $this->tmpl['votesaverageimg'] = 0; $this->tmpl['voteswidthimg'] = 0; $votesStatistics = PhocaGalleryRateImage::getVotesStatistics((int) $item->id); if (!empty($votesStatistics->count)) { $this->tmpl['votescountimg'] = $votesStatistics->count; } if (!empty($votesStatistics->average)) { $this->tmpl['votesaverageimg'] = $votesStatistics->average; if ($this->tmpl['votesaverageimg'] > 0) { $this->tmpl['votesaverageimg'] = round((double) $this->tmpl['votesaverageimg'] / 0.5) * 0.5; $this->tmpl['voteswidthimg'] = 22 * $this->tmpl['votesaverageimg']; } else { $this->tmpl['votesaverageimg'] = (int) 0; // not float displaying } } if ((int) $this->tmpl['votescountimg'] > 1) { $this->tmpl['votestextimg'] = 'COM_PHOCAGALLERY_VOTES'; } else { $this->tmpl['votestextimg'] = 'COM_PHOCAGALLERY_VOTE'; } // Already rated? $this->tmpl['alreadyratedimg'] = PhocaGalleryRateImage::checkUserVote((int) $item->id, (int) $user->id); } // Tags $this->tmpl['displaying_tags_output'] = ''; if ($this->tmpl['display_tags_links'] == 1 || $this->tmpl['display_tags_links'] == 3 || $this->tmpl['mb_tags']) { if ($this->tmpl['detailwindow'] == 7) { $this->tmpl['displaying_tags_output'] = PhocaGalleryTag::displayTags($item->id); } else { $this->tmpl['displaying_tags_output'] = PhocaGalleryTag::displayTags($item->id, 1); } } // Back button $this->tmpl['backbutton'] = ''; if ($this->tmpl['detailwindow'] == 7) { phocagalleryimport('phocagallery.image.image'); $formatIcon =& PhocaGalleryImage::getFormatIcon(); $this->tmpl['backbutton'] = '<div><a href="' . JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $item->catslug . '&Itemid=' . JRequest::getVar('Itemid', 0, '', 'int')) . '"' . ' title="' . JText::_('COM_PHOCAGALLERY_BACK_TO_CATEGORY') . '">' . JHtml::_('image', 'components/com_phocagallery/assets/images/icon-up-images.' . $formatIcon, JText::_('COM_PHOCAGALLERY_BACK_TO_CATEGORY')) . '</a></div>'; } // ASIGN $this->assignRef('tmpl', $this->tmpl); $this->assignRef('item', $item); $this->_prepareDocument($item); if ($this->tmpl['enable_multibox'] == 1) { if ($item->download > 0) { if ($this->tmpl['displayicondownload'] == 2) { $backLink = 'index.php?option=com_phocagallery&view=category&id=' . $item->catslug . '&Itemid=' . JRequest::getVar('Itemid', 0, '', 'int'); phocagalleryimport('phocagallery.file.filedownload'); if (isset($item->exto) && $item->exto != '') { PhocaGalleryFileDownload::download($item, $backLink, 1); } else { PhocaGalleryFileDownload::download($item, $backLink); } exit; } else { parent::display('multibox'); //parent::display('download'); } } else { if (isset($item->videocode) && $item->videocode != '' && $item->videocode != '0') { $item->videocode = PhocaGalleryYoutube::displayVideo($item->videocode); } parent::display('multibox'); } } else { if (isset($item->videocode) && $item->videocode != '' && $item->videocode != '0') { $item->videocode = PhocaGalleryYoutube::displayVideo($item->videocode); if ($this->tmpl['detailwindow'] != 7 && $this->tmpl['ytb_display'] == 1) { $document->addCustomTag("<style type=\"text/css\"> \n" . " html, body, .contentpane, div#all, div#main, div#system-message-container {padding: 0px !important;margin: 0px !important;} \n" . " div#sbox-window {background-color:#fff;padding: 0px;margin: 0px;} \n" . " </style> \n"); } parent::display('video'); } else { parent::display('slideshowjs'); if ($item->slideshow == 1) { parent::display('slideshow'); } else { if ($item->download > 0) { if ($this->tmpl['displayicondownload'] == 2) { $backLink = 'index.php?option=com_phocagallery&view=category&id=' . $item->catslug . '&Itemid=' . JRequest::getVar('Itemid', 0, '', 'int'); phocagalleryimport('phocagallery.file.filedownload'); if (isset($item->exto) && $item->exto != '') { PhocaGalleryFileDownload::download($item, $backLink, 1); } else { PhocaGalleryFileDownload::download($item, $backLink); } exit; } else { parent::display('download'); } } else { parent::display($tpl); } } } } }
public static function getImageFromCat($idCat, $idImg = 0) { $db = JFactory::getDBO(); $nextImg = ''; if ($idImg > 0) { $nextImg = ' AND a.id > ' . (int) $idImg; } $query = 'SELECT a.*' . ' FROM #__phocagallery AS a' . ' WHERE a.catid = ' . (int) $idCat . ' AND a.published = 1' . ' AND a.approved = 1' . $nextImg . ' ORDER BY a.id ASC LIMIT 1'; $db->setQuery($query); $item = $db->loadObject(); if (!isset($item->id) || isset($item->id) && $item->id < 1) { $img['end'] = 1; return $img; } if (isset($item->description) && $item->description != '') { $img['caption'] = $item->title . ' - ' . $item->description; } else { $img['caption'] = $item->title; } //TODO TEST EXT IMAGE if (isset($item->extid) && $item->extid != '') { $img['extid'] = $item->extid; } $img['id'] = $item->id; $img['title'] = $item->title; $img['filename'] = PhocaGalleryFile::getTitleFromFile($item->filename, 1); $img['fileorigabs'] = PhocaGalleryFile::getFileOriginal($item->filename); return $img; }
function store($data, $return) { //If this file doesn't exists don't save it if (!PhocaGalleryFile::existsFileOriginal($data['filename'])) { $this->setError('File not exists'); return false; } $data['imgorigsize'] = PhocaGalleryFile::getFileSize($data['filename'], 0); //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'] = PhocaGalleryFile::getTitleFromFile($data['filename']); } if (!isset($data['alias']) || isset($data['alias']) && $data['alias'] == '') { $data['alias'] = PhocaGalleryFile::getTitleFromFile($data['filename']); } //clean alias name (no bad characters) //$data['alias'] = PhocaGalleryText::getAliasName($data['alias']); if (!isset($data['longitude']) || isset($data['longitude']) && $data['longitude'] == '' || (!isset($data['latitude']) || isset($data['latitude']) && $data['latitude'] == '')) { phocagalleryimport('phocagallery.geo.geo'); $coords = PhocaGalleryGeo::getGeoCoords($data['filename']); if (!isset($data['longitude']) || isset($data['longitude']) && $data['longitude'] == '') { $data['longitude'] = $coords['longitude']; } if (!isset($data['latitude']) || isset($data['latitude']) && $data['latitude'] == '') { $data['latitude'] = $coords['latitude']; } if ((!isset($data['zoom']) || isset($data['zoom']) && $data['zoom'] == '') && $data['longitude'] != '' && $data['latitude'] != '') { $data['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom'); } } $row =& $this->getTable('phocagallery', 'Table'); // 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 $returnFrontMessage = PhocaGalleryFileThumbnail::getOrCreateThumbnail($row->filename, $return, 1, 1, 1, 1); if ($returnFrontMessage == 'Success') { return true; } else { return false; } }
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; }
function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $this->params = $app->getParams(); $user = JFactory::getUser(); $uri = JFactory::getURI(); $this->itemId = $app->input->get('Itemid', 0, 'int'); $neededAccessLevels = PhocaGalleryAccess::getNeededAccessLevels(); $access = PhocaGalleryAccess::isAccess($user->getAuthorisedViewLevels(), $neededAccessLevels); // PLUGIN WINDOW - we get information from plugin $get = ''; $get['comment'] = $app->input->get('comment', '', 'string'); $this->tmpl['id'] = $app->input->get('id', 0, 'int'); $this->tmpl['catid'] = $app->input->get('catid', '', 'string'); $this->tmpl['maxcommentchar'] = $this->params->get('max_comment_char', 1000); $this->tmpl['displaycommentimg'] = $this->params->get('display_comment_img', 0); $this->tmpl['detailwindowbackgroundcolor'] = $this->params->get('detail_window_background_color', '#ffffff'); $this->tmpl['commentwidth'] = $this->params->get('comment_width', 500); $this->tmpl['enable_multibox'] = $this->params->get('enable_multibox', 0); $this->tmpl['multibox_comments_width'] = $this->params->get('multibox_comments_width', 300); $this->tmpl['externalcommentsystem'] = $this->params->get('external_comment_system', 0); $this->tmpl['gallerymetakey'] = $this->params->get('gallery_metakey', ''); $this->tmpl['gallerymetadesc'] = $this->params->get('gallery_metadesc', ''); $this->tmpl['altvalue'] = $this->params->get('alt_value', 1); $this->tmpl['largewidth'] = $this->params->get('large_image_width', 640); $this->tmpl['largeheight'] = $this->params->get('large_image_height', 480); $this->tmpl['picasa_correct_width_l'] = (int) $this->params->get('large_image_width', 640); $this->tmpl['picasa_correct_height_l'] = (int) $this->params->get('large_image_height', 480); $paramsFb = PhocaGalleryFbSystem::getCommentsParams($this->params->get('fb_comment_user_id', '')); // Facebook $this->tmpl['fb_comment_app_id'] = isset($paramsFb['fb_comment_app_id']) ? $paramsFb['fb_comment_app_id'] : ''; $this->tmpl['fb_comment_width'] = isset($paramsFb['fb_comment_width']) ? $paramsFb['fb_comment_width'] : 550; $this->tmpl['fb_comment_lang'] = isset($paramsFb['fb_comment_lang']) ? $paramsFb['fb_comment_lang'] : 'en_US'; $this->tmpl['fb_comment_count'] = isset($paramsFb['fb_comment_count']) ? $paramsFb['fb_comment_count'] : ''; $this->tmpl['display_comment_nopup'] = $this->params->get('display_comment_nopup', 0); $this->tmpl['enablecustomcss'] = $this->params->get('enable_custom_css', 0); $this->tmpl['customcss'] = $this->params->get('custom_css', ''); // Multibox if ($this->tmpl['enable_multibox'] == 1) { $this->tmpl['commentwidth'] = (int) $this->tmpl['multibox_comments_width'] - 70; //padding - margin } $get['commentsi'] = $app->input->get('commentsi', '', 'int'); $this->tmpl['enable_multibox_iframe'] = 0; if ($get['commentsi'] == 1) { // Seems we are in iframe $this->tmpl['enable_multibox_iframe'] = 1; } // CSS PhocaGalleryRenderFront::renderAllCSS(); if ($this->tmpl['gallerymetakey'] != '') { $document->setMetaData('keywords', $this->tmpl['gallerymetakey']); } if ($this->tmpl['gallerymetadesc'] != '') { $document->setMetaData('description', $this->tmpl['gallerymetadesc']); } // PARAMS - Open window parameters - modal popup box or standard popup window $detail_window = $this->params->get('detail_window', 0); // Plugin information if (isset($get['comment']) && $get['comment'] != '') { $detail_window = $get['comment']; } // Only registered (VOTES + COMMENTS) $this->tmpl['not_registered'] = true; $this->tmpl['name'] = ''; if ($access) { $this->tmpl['not_registered'] = false; $this->tmpl['name'] = $user->name; } $document->addScript(JURI::base(true) . '/media/com_phocagallery/js/comments.js'); $document->addCustomTag(PhocaGalleryRenderFront::renderCommentJS((int) $this->tmpl['maxcommentchar'])); $this->tmpl['already_commented'] = PhocaGalleryCommentImage::checkUserComment((int) $this->tmpl['id'], (int) $user->id); $commentItem = PhocaGalleryCommentImage::displayComment((int) $this->tmpl['id']); // PARAMS - Display Description in Detail window - set the font color $this->tmpl['detailwindowbackgroundcolor'] = $this->params->get('detail_window_background_color', '#ffffff'); $this->tmpl['detailwindow'] = $this->params->get('detail_window', 0); $description_lightbox_font_color = $this->params->get('description_lightbox_font_color', '#ffffff'); $description_lightbox_bg_color = $this->params->get('description_lightbox_bg_color', '#000000'); $description_lightbox_font_size = $this->params->get('description_lightbox_font_size', 12); // NO SCROLLBAR IN DETAIL WINDOW $document->addCustomTag("<style type=\"text/css\"> \n" . " html,body, .contentpane{background:" . $this->tmpl['detailwindowbackgroundcolor'] . ";text-align:left;} \n" . " center, table {background:" . $this->tmpl['detailwindowbackgroundcolor'] . ";} \n" . " #sbox-window {background-color:#fff;padding:5px} \n" . " </style> \n"); $model = $this->getModel(); $item = $model->getData(); $this->tmpl['imgtitle'] = $item->title; // Back button $this->tmpl['backbutton'] = ''; if ($this->tmpl['detailwindow'] == 7 || $this->tmpl['display_comment_nopup']) { // Display Image // Access check - don't display the image if you have no access to this image (if user add own url) // USER RIGHT - ACCESS - - - - - - - - - - $rightDisplay = 0; if (!empty($item)) { $rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $item->cataccessuserid, $item->cataccess, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0); } if ($rightDisplay == 0) { $this->tmpl['pl'] = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()); $app->redirect(JRoute::_($this->tmpl['pl'], false), JText::_('COM_PHOCAGALLERY_NOT_AUTHORISED_ACTION')); exit; } // - - - - - - - - - - - - - - - - - - - - phocagalleryimport('phocagallery.image.image'); $this->tmpl['backbutton'] = '<div><a href="' . JRoute::_('index.php?option=com_phocagallery&view=category&id=' . $this->tmpl['catid'] . '&Itemid=' . $this->itemId) . '"' . ' title="' . JText::_('COM_PHOCAGALLERY_BACK_TO_CATEGORY') . '">' . JHtml::_('image', 'media/com_phocagallery/images/icon-up-images.png', JText::_('COM_PHOCAGALLERY_BACK_TO_CATEGORY')) . '</a></div>'; // Get file thumbnail or No Image $item->filenameno = $item->filename; $item->filename = PhocaGalleryFile::getTitleFromFile($item->filename, 1); $item->filesize = PhocaGalleryFile::getFileSize($item->filenameno); $altValue = PhocaGalleryRenderFront::getAltValue($this->tmpl['altvalue'], $item->title, $item->description, $item->metadesc); $item->altvalue = $altValue; $realImageSize = ''; $extImage = PhocaGalleryImage::isExtImage($item->extid); if ($extImage) { $item->extl = $item->extl; $item->exto = $item->exto; $realImageSize = PhocaGalleryImage::getRealImageSize($item->extl, '', 1); $item->imagesize = PhocaGalleryImage::getImageSize($item->exto, 1, 1); if ($item->extw != '') { $extw = explode(',', $item->extw); $item->extw = $extw[0]; } $correctImageRes = PhocaGalleryPicasa::correctSizeWithRate($item->extw, $item->exth, $this->tmpl['picasa_correct_width_l'], $this->tmpl['picasa_correct_height_l']); $item->linkimage = JHtml::_('image', $item->extl, $item->altvalue, array('width' => $correctImageRes['width'], 'height' => $correctImageRes['height'])); $item->realimagewidth = $correctImageRes['width']; $item->realimageheight = $correctImageRes['height']; } else { $item->linkthumbnailpath = PhocaGalleryImageFront::displayCategoryImageOrNoImage($item->filenameno, 'large'); $item->linkimage = JHtml::_('image', $item->linkthumbnailpath, $item->altvalue); $realImageSize = PhocaGalleryImage::getRealImageSize($item->filenameno); $item->imagesize = PhocaGalleryImage::getImageSize($item->filenameno, 1); if (isset($realImageSize['w']) && isset($realImageSize['h'])) { $item->realimagewidth = $realImageSize['w']; $item->realimageheight = $realImageSize['h']; } else { $item->realimagewidth = $this->tmpl['largewidth']; $item->realimageheight = $this->tmpl['largeheight']; } } $this->assignRef('item', $item); } // ACTION $this->assignRef('item', $item); $this->tmpl['action'] = $uri->toString(); $this->assignRef('commentitem', $commentItem); $this->_prepareDocument($item); parent::display($tpl); }
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; }
/** * need GD library (first PHP line WIN: dl("php_gd.dll"); UNIX: dl("gd.so"); * www.boutell.com/gd/ * interval.cz/clanky/php-skript-pro-generovani-galerie-obrazku-2/ * cz.php.net/imagecopyresampled * www.linuxsoft.cz/sw_detail.php?id_item=871 * www.webtip.cz/art/wt_tech_php/liquid_ir.html * php.vrana.cz/zmensovani-obrazku.php * diskuse.jakpsatweb.cz/ * * @param string $fileIn Vstupni soubor (mel by existovat) * @param string $fileOut Vystupni soubor, null ho jenom zobrazi (taky kdyz nema pravo se zapsat :) * @param int $width Vysledna sirka (maximalni) * @param int $height Vysledna vyska (maximalni) * @param bool $crop Orez (true, obrazek bude presne tak velky), jinak jenom Resample (udane maximalni rozmery) * @param int $typeOut IMAGETYPE_type vystupniho obrazku * @return bool Chyba kdyz vrati false */ public static function imageMagic($fileIn, $fileOut = null, $width = null, $height = null, $crop = null, $typeOut = null, $watermarkParams = array(), $frontUpload = 0, &$errorMsg) { $params = JComponentHelper::getParams('com_phocagallery'); $jfile_thumbs = $params->get('jfile_thumbs', 1); $jpeg_quality = $params->get('jpeg_quality', 85); $jpeg_quality = PhocaGalleryImage::getJpegQuality($jpeg_quality); $fileWatermark = ''; // While front upload we don't display the process page if ($frontUpload == 0) { $stopText = PhocaGalleryRenderProcess::displayStopThumbnailsCreating('processpage'); echo $stopText; } // Memory - - - - - - - - $memory = 8; $memoryLimitChanged = 0; $memory = (int) ini_get('memory_limit'); if ($memory == 0) { $memory = 8; } // - - - - - - - - - - - if ($fileIn !== '' && JFile::exists($fileIn)) { // array of width, height, IMAGETYPE, "height=x width=x" (string) list($w, $h, $type) = GetImageSize($fileIn); if ($w > 0 && $h > 0) { // we got the info from GetImageSize // size of the image if ($width == null || $width == 0) { // no width added $width = $w; } else { if ($height == null || $height == 0) { // no height, adding the same as width $height = $width; } } if ($height == null || $height == 0) { // no height, no width $height = $h; } // miniaturizing if (!$crop) { // new size - nw, nh (new width/height) $scale = $width / $w < $height / $h ? $width / $w : $height / $h; // smaller rate $src = array(0, 0, $w, $h); $dst = array(0, 0, floor($w * $scale), floor($h * $scale)); } else { // will be cropped $scale = $width / $w > $height / $h ? $width / $w : $height / $h; // greater rate $newW = $width / $scale; // check the size of in file $newH = $height / $scale; // which side is larger (rounding error) if ($w - $newW > $h - $newH) { $src = array(floor(($w - $newW) / 2), 0, floor($newW), $h); } else { $src = array(0, floor(($h - $newH) / 2), $w, floor($newH)); } $dst = array(0, 0, floor($width), floor($height)); } // Watermark - - - - - - - - - - - if (!empty($watermarkParams) && ($watermarkParams['create'] == 1 || $watermarkParams['create'] == 2)) { $thumbnailSmall = false; $thumbnailMedium = false; $thumbnailLarge = false; $thumbnailMedium = preg_match("/phoca_thumb_m_/i", $fileOut); $thumbnailLarge = preg_match("/phoca_thumb_l_/i", $fileOut); $path = PhocaGalleryPath::getPath(); $fileName = PhocaGalleryFile::getTitleFromFile($fileIn, 1); // Which Watermark will be used // If watermark is in current directory use it else use Default $fileWatermarkMedium = str_replace($fileName, 'watermark-medium.png', $fileIn); $fileWatermarkLarge = str_replace($fileName, 'watermark-large.png', $fileIn); clearstatcache(); // Which Watermark will be used if ($thumbnailMedium) { if (JFile::exists($fileWatermarkMedium)) { $fileWatermark = $fileWatermarkMedium; } else { if ($watermarkParams['create'] == 2) { $fileWatermark = $path->image_abs . 'watermark-medium.png'; } else { $fileWatermark = ''; } } } else { if ($thumbnailLarge) { if (JFile::exists($fileWatermarkLarge)) { $fileWatermark = $fileWatermarkLarge; } else { if ($watermarkParams['create'] == 2) { $fileWatermark = $path->image_abs . 'watermark-large.png'; } else { $fileWatermark = ''; } } } else { $fileWatermark = ''; } } if (!JFile::exists($fileWatermark)) { $fileWatermark = ''; } if ($fileWatermark != '') { list($wW, $hW, $typeW) = GetImageSize($fileWatermark); switch ($watermarkParams['x']) { case 'left': $locationX = 0; break; case 'right': $locationX = $dst[2] - $wW; break; case 'center': default: $locationX = $dst[2] / 2 - $wW / 2; break; } switch ($watermarkParams['y']) { case 'top': $locationY = 0; break; case 'bottom': $locationY = $dst[3] - $hW; break; case 'middle': default: $locationY = $dst[3] / 2 - $hW / 2; break; } } } else { $fileWatermark = ''; } } if ($memory < 50) { ini_set('memory_limit', '50M'); $memoryLimitChanged = 1; } // Resampling // in file // Watemark if ($fileWatermark != '') { if (!function_exists('ImageCreateFromPNG')) { $errorMsg = 'ErrorNoPNGFunction'; return false; } $waterImage1 = ImageCreateFromPNG($fileWatermark); } // End Watermark - - - - - - - - - - - - - - - - - - switch ($type) { case IMAGETYPE_JPEG: if (!function_exists('ImageCreateFromJPEG')) { $errorMsg = 'ErrorNoJPGFunction'; return false; } //$image1 = ImageCreateFromJPEG($fileIn); try { $image1 = ImageCreateFromJPEG($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorJPGFunction'; return false; } break; case IMAGETYPE_PNG: if (!function_exists('ImageCreateFromPNG')) { $errorMsg = 'ErrorNoPNGFunction'; return false; } //$image1 = ImageCreateFromPNG($fileIn); try { $image1 = ImageCreateFromPNG($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorPNGFunction'; return false; } break; case IMAGETYPE_GIF: if (!function_exists('ImageCreateFromGIF')) { $errorMsg = 'ErrorNoGIFFunction'; return false; } //$image1 = ImageCreateFromGIF($fileIn); try { $image1 = ImageCreateFromGIF($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorGIFFunction'; return false; } break; case IMAGETYPE_WBMP: if (!function_exists('ImageCreateFromWBMP')) { $errorMsg = 'ErrorNoWBMPFunction'; return false; } //$image1 = ImageCreateFromWBMP($fileIn); try { $image1 = ImageCreateFromWBMP($fileIn); } catch (\Exception $exception) { $errorMsg = 'ErrorWBMPFunction'; return false; } break; default: $errorMsg = 'ErrorNotSupportedImage'; return false; break; } if ($image1) { $image2 = @ImageCreateTruecolor($dst[2], $dst[3]); if (!$image2) { $errorMsg = 'ErrorNoImageCreateTruecolor'; return false; } switch ($type) { case IMAGETYPE_PNG: //imagealphablending($image1, false); @imagealphablending($image2, false); //imagesavealpha($image1, true); @imagesavealpha($image2, true); break; } ImageCopyResampled($image2, $image1, $dst[0], $dst[1], $src[0], $src[1], $dst[2], $dst[3], $src[2], $src[3]); // Watermark - - - - - - if ($fileWatermark != '') { ImageCopy($image2, $waterImage1, $locationX, $locationY, 0, 0, $wW, $hW); } // End Watermark - - - - // Display the Image - not used if ($fileOut == null) { header("Content-type: " . image_type_to_mime_type($typeOut)); } // Create the file if ($typeOut == null) { // no bitmap $typeOut = $type == IMAGETYPE_WBMP ? IMAGETYPE_PNG : $type; } switch ($typeOut) { case IMAGETYPE_JPEG: if (!function_exists('ImageJPEG')) { $errorMsg = 'ErrorNoJPGFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImageJPEG($image2, NULL, $jpeg_quality)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgJPEGToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgJPEGToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImageJPEG($image2, $fileOut, $jpeg_quality)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; case IMAGETYPE_PNG: if (!function_exists('ImagePNG')) { $errorMsg = 'ErrorNoPNGFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImagePNG($image2, NULL)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgPNGToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgPNGToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImagePNG($image2, $fileOut)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; case IMAGETYPE_GIF: if (!function_exists('ImageGIF')) { $errorMsg = 'ErrorNoGIFFunction'; return false; } if ($jfile_thumbs == 1) { ob_start(); if (!@ImageGIF($image2, NULL)) { ob_end_clean(); $errorMsg = 'ErrorWriteFile'; return false; } $imgGIFToWrite = ob_get_contents(); ob_end_clean(); if (!JFile::write($fileOut, $imgGIFToWrite)) { $errorMsg = 'ErrorWriteFile'; return false; } } else { if (!@ImageGIF($image2, $fileOut)) { $errorMsg = 'ErrorWriteFile'; return false; } } break; default: $errorMsg = 'ErrorNotSupportedImage'; return false; break; } // free memory ImageDestroy($image1); ImageDestroy($image2); if (isset($waterImage1)) { ImageDestroy($waterImage1); } if ($memoryLimitChanged == 1) { $memoryString = $memory . 'M'; ini_set('memory_limit', $memoryString); } $errorMsg = ''; // Success return true; } else { $errorMsg = 'Error1'; return false; } if ($memoryLimitChanged == 1) { $memoryString = $memory . 'M'; ini_set('memory_limit', $memoryString); } } $errorMsg = 'Error2'; return false; }
function save($data) { $params =& JComponentHelper::getParams('com_phocagallery'); $clean_thumbnails = $params->get('clean_thumbnails', 0); $fileOriginalNotExist = 0; if ((int) $data['extid'] > 0) { $data['imgorigsize'] = 0; if ($data['title'] == '') { $data['title'] = 'External Image'; } } else { //If this file doesn't exists don't save it if (!PhocaGalleryFile::existsFileOriginal($data['filename'])) { //$this->setError('Original File does not exist'); //return false; $fileOriginalNotExist = 1; $errorMsg = JText::_('COM_PHOCAGALLERY_ORIGINAL_IMAGE_NOT_EXIST'); } $data['imgorigsize'] = PhocaGalleryFile::getFileSize($data['filename'], 0); $data['format'] = PhocaGalleryFile::getFileFormat($data['filename']); //If there is no title and no alias, use filename as title and alias if ($data['title'] == '') { $data['title'] = PhocaGalleryFile::getTitleFromFile($data['filename']); } } if ($data['extlink1link'] != '') { $extlink1 = str_replace('http://', '', $data['extlink1link']); $data['extlink1'] = $extlink1 . '|' . $data['extlink1title'] . '|' . $data['extlink1target'] . '|' . $data['extlink1icon']; } else { $data['extlink1'] = $data['extlink1link'] . '|' . $data['extlink1title'] . '|' . $data['extlink1target'] . '|' . $data['extlink1icon']; } if ($data['extlink2link'] != '') { $extlink2 = str_replace('http://', '', $data['extlink2link']); $data['extlink2'] = $extlink2 . '|' . $data['extlink2title'] . '|' . $data['extlink2target'] . '|' . $data['extlink2icon']; } else { $data['extlink2'] = $data['extlink2link'] . '|' . $data['extlink2title'] . '|' . $data['extlink2target'] . '|' . $data['extlink2icon']; } // Geo if ($data['longitude'] == '' || $data['latitude'] == '') { phocagalleryimport('phocagallery.geo.geo'); $coords = PhocaGalleryGeo::getGeoCoords($data['filename']); if ($data['longitude'] == '') { $data['longitude'] = $coords['longitude']; } if ($data['latitude'] == '') { $data['latitude'] = $coords['latitude']; } if ($data['latitude'] != '' && $data['longitude'] != '' && $data['zoom'] == '') { $data['zoom'] = PhocaGallerySettings::getAdvancedSettings('geozoom'); } } if ($data['alias'] == '') { $data['alias'] = $data['title']; } //clean alias name (no bad characters) //$data['alias'] = PhocaGalleryText::getAliasName($data['alias']); // if new item, order last in appropriate group //if (!$row->id) { // $where = 'catid = ' . (int) $row->catid ; // $row->ordering = $row->getNextOrder( $where ); //} // = = = = = = = = = = // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id'); $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } if (intval($table->date) == 0) { $table->date = JFactory::getDate()->toSql(); } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. /*$result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, $table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; }*/ // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } // Store to ref table if (!isset($data['tags'])) { $data['tags'] = array(); } if ((int) $table->id > 0) { PhocaGalleryTag::storeTags($data['tags'], (int) $table->id); } // Clean the cache. $cache = JFactory::getCache($this->option); $cache->clean(); // Trigger the onContentAfterSave event. //$dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, $table, $isNew)); $pkName = $table->getKeyName(); if (isset($table->{$pkName})) { $this->setState($this->getName() . '.id', $table->{$pkName}); } $this->setState($this->getName() . '.new', $isNew); // = = = = = = $task = JRequest::getVar('task'); if (isset($table->{$pkName})) { $id = $table->{$pkName}; } if ((int) $data['extid'] > 0 || $fileOriginalNotExist == 1) { } else { // - - - - - - - - - - - - - - - - - - //Create thumbnail small, medium, large //file - abc.img, file_no - folder/abc.img //Get folder variables from Helper //Create thumbnails small, medium, large $refresh_url = 'index.php?option=com_phocagallery&task=phocagalleryimg.thumbs'; $task = JRequest::getVar('task'); if (isset($table->{$pkName}) && $task == 'apply') { $id = $table->{$pkName}; $refresh_url = 'index.php?option=com_phocagallery&task=phocagalleryimg.edit&id=' . (int) $id; } if ($task == 'save2new') { // Don't create automatically thumbnails in case, we are going to add new image } else { $file_thumb = PhocaGalleryFileThumbnail::getOrCreateThumbnail($data['filename'], $refresh_url, 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; }