Exemplo n.º 1
0
    function onContentPrepare($context, &$row, &$params, $page = 0)
    {
        // API
        jimport('joomla.filesystem.file');
        $mainframe =& JFactory::getApplication();
        $document =& JFactory::getDocument();
        // Requests
        $option = JRequest::getCmd('option');
        $view = JRequest::getCmd('view');
        $layout = JRequest::getCmd('layout');
        $page = JRequest::getCmd('page');
        $secid = JRequest::getInt('secid');
        $catid = JRequest::getInt('catid');
        $itemid = JRequest::getInt('Itemid');
        if (!$itemid) {
            $itemid = 999999;
        }
        // Assign paths
        $sitePath = JPATH_SITE;
        $siteUrl = JURI::base(true);
        // Check if plugin is enabled
        if (JPluginHelper::isEnabled('content', $this->plg_name) == false) {
            return;
        }
        // Bail out if the page is not HTML
        if (JRequest::getCmd('format') != 'html' && JRequest::getCmd('format') != '') {
            return;
        }
        // Load the plugin language file the proper way
        JPlugin::loadLanguage('plg_content_' . $this->plg_name, JPATH_ADMINISTRATOR);
        // simple performance check to determine whether plugin should process further
        if (JString::strpos($row->text, $this->plg_tag) === false) {
            return;
        }
        // expression to search for
        $regex = "#{" . $this->plg_tag . "}(.*?){/" . $this->plg_tag . "}#s";
        // find all instances of the plugin and put them in $matches
        preg_match_all($regex, $row->text, $matches);
        // Number of plugins
        $count = count($matches[0]);
        // Plugin only processes if there are any instances of the plugin in the text
        if (!$count) {
            return;
        }
        // Check for basic requirements
        if (!extension_loaded('gd') && !function_exists('gd_info')) {
            JError::raiseNotice('', JText::_('JW_SIG_NGD'));
        }
        if (!is_writable($sitePath . DS . 'cache')) {
            JError::raiseNotice('', JText::_('JW_SIG_CFU'));
        }
        // ----------------------------------- Get plugin parameters -----------------------------------
        $galleries_rootfolder = $this->params->get('galleries_rootfolder', 'images');
        $thb_width = (int) $this->params->get('thb_width', 200);
        $thb_height = (int) $this->params->get('thb_height', 160);
        $smartResize = $this->params->get('smartResize', 1);
        $jpg_quality = (int) $this->params->get('jpg_quality', 80);
        $galleryMessages = $this->params->get('galleryMessages', 1);
        $cache_expire_time = (int) $this->params->get('cache_expire_time', 120) * 60;
        // Cache expiration time in minutes
        // Advanced
        $memoryLimit = (int) $this->params->get('memoryLimit');
        if ($memoryLimit) {
            ini_set("memory_limit", $memoryLimit . "M");
        }
        // Preset
        $thb_template = $this->params->get('thb_template', 'Polaroids');
        $cacheFolder = 'cache/jw_simpleImageGallery';
        // Other assignments
        $transparent = $siteUrl . "/plugins/content/" . $this->plg_name . "/" . $this->plg_name . "/includes/images/transparent.gif";
        // Includes
        require_once dirname(__FILE__) . DS . $this->plg_name . DS . 'includes' . DS . 'helper.php';
        // ----------------------------------- Head tag includes -----------------------------------
        $pluginCSS = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'css/template.css', $thb_template);
        $pluginCSS = $pluginCSS->http;
        $pluginCSSie6 = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'css/template_ie6.css', $thb_template);
        $pluginCSSie6 = $pluginCSSie6->http;
        $pluginCSSie7 = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'css/template_ie7.css', $thb_template);
        $pluginCSSie7 = $pluginCSSie7->http;
        $headIncludes = '
		' . JHTML::_('behavior.framework') . '
		<script type="text/javascript" src="' . $siteUrl . '/plugins/content/' . $this->plg_name . '/' . $this->plg_name . '/includes/jquery/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="' . $siteUrl . '/plugins/content/' . $this->plg_name . '/' . $this->plg_name . '/includes/slimbox-2.04/js/slimbox2.js"></script>
		<link rel="stylesheet" type="text/css" href="' . $siteUrl . '/plugins/content/' . $this->plg_name . '/' . $this->plg_name . '/includes/slimbox-2.04/css/slimbox2.css" />
		<link rel="stylesheet" type="text/css" href="' . $pluginCSS . '" />
		<!--[if lte IE 6]>
		<link rel="stylesheet" type="text/css" href="' . $pluginCSSie6 . '" />
		<![endif]-->
		<!--[if IE 7]>
		<link rel="stylesheet" type="text/css" href="' . $pluginCSSie7 . '" />
		<![endif]-->
		';
        $headIncludes = '';
        // ----------------------------------- Prepare the output -----------------------------------
        // Process plugin tags
        if (preg_match_all($regex, $row->text, $matches, PREG_PATTERN_ORDER) > 0) {
            // start the replace loop
            foreach ($matches[0] as $key => $match) {
                $tagcontent = preg_replace("/{.+?}/", "", $match);
                $tagparams = explode(':', $tagcontent);
                $galleryFolder = $tagparams[0];
                // Gallery specific
                $srcimgfolder = $galleries_rootfolder . '/' . $galleryFolder . '/';
                $galleryID = substr(md5($key . $srcimgfolder), 1, 10);
                // create a unique 8-digit identifier for each gallery
                $gallery = SimpleImageGalleryHelper::renderGallery($srcimgfolder, $cacheFolder, $thb_width, $thb_height, $smartResize, $jpg_quality, $cache_expire_time);
                if (!$gallery) {
                    JError::raiseNotice('', JText::_('JW_SIG_PRG'));
                    return;
                }
                // Fetch the template
                ob_start();
                $templatePath = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'default.php', $thb_template);
                $templatePath = $templatePath->file;
                include $templatePath;
                $getTemplate = $this->plg_copyrights_start . ob_get_contents() . $this->plg_copyrights_end;
                ob_end_clean();
                // Output
                $plg_html = $getTemplate;
                // Do the replace
                $row->text = preg_replace("#{" . $this->plg_tag . "}" . $tagcontent . "{/" . $this->plg_tag . "}#s", $plg_html, $row->text);
            }
            // end foreach
        }
        // end if
        // Append head includes, but not when we're outputing raw content in K2
        if (JRequest::getCmd('format') == '' || JRequest::getCmd('format') == 'html') {
            SimpleImageGalleryHelper::loadHeadIncludes($this->plg_copyrights_start . $headIncludes . $this->plg_copyrights_end);
        }
    }
Exemplo n.º 2
0
 function renderGallery($srcimgfolder, $cacheFolder, $thb_width, $thb_height, $smartResize, $jpg_quality, $cache_expire_time)
 {
     // API
     jimport('joomla.filesystem.folder');
     // Path assignment
     $sitePath = JPATH_SITE . '/';
     $siteUrl = JURI::base(true) . '/';
     // Internal parameters
     $prefix = "jwsig_cache_";
     // Set the cache folder
     $cacheFolderPath = $sitePath . DS . str_replace('/', DS, $cacheFolder);
     if (file_exists($cacheFolderPath) && is_dir($cacheFolderPath)) {
         // all OK
     } else {
         mkdir($cacheFolderPath);
     }
     // Check if the source folder exists and read it
     $srcFolder = JFolder::files($sitePath . $srcimgfolder);
     // Proceed if the folder is OK or fail silently
     if (!$srcFolder) {
         return;
     }
     // Loop through the source folder for images
     $fileTypes = array('jpg', 'jpeg', 'gif', 'png');
     // Create an array of file types
     $found = array();
     // Create an array for matching files
     foreach ($srcFolder as $srcImage) {
         $fileInfo = pathinfo($srcImage);
         if (array_key_exists('extension', $fileInfo) && in_array(strtolower($fileInfo['extension']), $fileTypes)) {
             $found[] = $srcImage;
         }
     }
     // Bail out if there are no images found
     if (count($found) == 0) {
         return;
     }
     // Sort the images
     sort($found);
     // Initiate array to hold gallery
     $gallery = array();
     // Loop through the image file list
     foreach ($found as $key => $filename) {
         // Determing thumb image filename
         if (strtolower(substr($filename, -4, 4)) == 'jpeg') {
             $thumbfilename = substr($filename, 0, -4) . 'jpg';
         } elseif (strtolower(substr($filename, -3, 3)) == 'gif' || strtolower(substr($filename, -3, 3)) == 'png' || strtolower(substr($filename, -3, 3)) == 'jpg') {
             $thumbfilename = substr($filename, 0, -3) . 'jpg';
         }
         // Object to hold each image elements
         $gallery[$key] = new JObject();
         // Assign source image and path to a variable
         $original = $sitePath . $srcimgfolder . $filename;
         // Check if thumb image exists already
         $thumbimage = $sitePath . str_replace('/', DS, $cacheFolder) . DS . $prefix . substr(md5($srcimgfolder), 1, 10) . '_' . strtolower($thumbfilename);
         if (file_exists($thumbimage) && is_readable($thumbimage) && filemtime($thumbimage) + $cache_expire_time > time()) {
             // do nothing
         } else {
             // Otherwise create the thumb image
             // begin by getting the details of the original
             list($width, $height, $type) = getimagesize($original);
             // strip the extension off the image filename (case insensitive)
             $imagetypes = array('/\\.gif$/i', '/\\.jpg$/i', '/\\.jpeg$/i', '/\\.png$/i');
             $name = preg_replace($imagetypes, '', basename($original));
             // create an image resource for the original
             switch ($type) {
                 case 1:
                     $source = @imagecreatefromgif($original);
                     /*
                     if(!$source){
                     	$error = JText::_('GIF images cannot be processed by this server. Please use JPEG or PNG images.');
                     }
                     */
                     break;
                 case 2:
                     $source = imagecreatefromjpeg($original);
                     break;
                 case 3:
                     $source = imagecreatefrompng($original);
                     break;
                 default:
                     $source = NULL;
                     //$error = JText::_('Cannot identify file type!');
             }
             // Bail out if the image resource is not OK
             if (!$source) {
                 return;
             }
             // calculate thumbnails
             $thumbnail = SimpleImageGalleryHelper::thumbDimCalc($width, $height, $thb_width, $thb_height, $smartResize);
             $thumb_width = $thumbnail['width'];
             $thumb_height = $thumbnail['height'];
             // create an image resource for the thumbnail
             $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
             // create the resized copy
             imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
             // save the resized copy
             $thumbname = str_replace('/', DS, $cacheFolder) . DS . $prefix . substr(md5($srcimgfolder), 1, 10) . '_' . strtolower($name);
             // convert all thumbs to .jpg
             $success = imagejpeg($thumb, $sitePath . $thumbname . '.jpg', $jpg_quality);
             // Bail out if there is a problem in the GD conversion
             if (!$success) {
                 return;
             }
             // remove the image resources from memory
             imagedestroy($source);
             imagedestroy($thumb);
         }
         // Assemble the image elements
         $gallery[$key]->filename = $filename;
         $gallery[$key]->sourceImageFilePath = $siteUrl . $srcimgfolder . SimpleImageGalleryHelper::replaceWhiteSpace($filename);
         $gallery[$key]->thumbImageFilePath = $siteUrl . $cacheFolder . '/' . $prefix . substr(md5($srcimgfolder), 1, 10) . '_' . strtolower(SimpleImageGalleryHelper::replaceWhiteSpace($thumbfilename));
     }
     // foreach loop
     // OUTPUT
     return $gallery;
 }
Exemplo n.º 3
0
 function renderSimpleImageGallery(&$row, &$params, $page = 0)
 {
     // API
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $document = JFactory::getDocument();
     // Assign paths
     $sitePath = JPATH_SITE;
     $siteUrl = JURI::root(true);
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $pluginLivePath = $siteUrl . '/plugins/content/' . $this->plg_name . '/' . $this->plg_name;
     } else {
         $pluginLivePath = $siteUrl . '/plugins/content/' . $this->plg_name;
     }
     // Check if plugin is enabled
     if (JPluginHelper::isEnabled('content', $this->plg_name) == false) {
         return;
     }
     // Bail out if the page format is not what we want
     $allowedFormats = array('', 'html', 'feed', 'json');
     if (!in_array(JRequest::getCmd('format'), $allowedFormats)) {
         return;
     }
     // Simple performance check to determine whether plugin should process further
     if (JString::strpos($row->text, $this->plg_tag) === false) {
         return;
     }
     // expression to search for
     $regex = "#{" . $this->plg_tag . "}(.*?){/" . $this->plg_tag . "}#is";
     // Find all instances of the plugin and put them in $matches
     preg_match_all($regex, $row->text, $matches);
     // Number of plugins
     $count = count($matches[0]);
     // Plugin only processes if there are any instances of the plugin in the text
     if (!$count) {
         return;
     }
     // Load the plugin language file the proper way
     JPlugin::loadLanguage('plg_content_' . $this->plg_name, JPATH_ADMINISTRATOR);
     // Check for basic requirements
     if (!extension_loaded('gd') && !function_exists('gd_info')) {
         JError::raiseNotice('', JText::_('JW_PLG_SIG_NOTICE_01'));
         return;
     }
     if (!is_writable($sitePath . DS . 'cache')) {
         JError::raiseNotice('', JText::_('JW_PLG_SIG_NOTICE_02'));
         return;
     }
     // Check if Simple Image Gallery Pro is present and mute
     if (JPluginHelper::isEnabled('content', 'jw_sigpro') == true) {
         return;
     }
     // Check if Simple Image Gallery Free (old) is present and show a warning
     if (JPluginHelper::isEnabled('content', 'jw_simpleImageGallery') == true) {
         JError::raiseNotice('', JText::_('JW_PLG_SIG_NOTICE_OLD_SIG'));
         return;
     }
     // ----------------------------------- Get plugin parameters -----------------------------------
     // Get plugin info
     $plugin = JPluginHelper::getPlugin('content', $this->plg_name);
     // Control external parameters and set variable for controlling plugin layout within modules
     if (!$params) {
         $params = class_exists('JParameter') ? new JParameter(null) : new JRegistry(null);
     }
     $parsedInModule = $params->get('parsedInModule');
     $pluginParams = class_exists('JParameter') ? new JParameter($plugin->params) : new JRegistry($plugin->params);
     $galleries_rootfolder = $params->get('galleries_rootfolder') ? $params->get('galleries_rootfolder') : $pluginParams->get('galleries_rootfolder', $defaultImagePath);
     $popup_engine = 'jquery_fancybox';
     $jQueryHandling = $pluginParams->get('jQueryHandling', '1.8');
     $thb_template = 'Classic';
     $thb_width = !is_null($params->get('thb_width', null)) ? $params->get('thb_width') : $pluginParams->get('thb_width', 200);
     $thb_height = !is_null($params->get('thb_height', null)) ? $params->get('thb_height') : $pluginParams->get('thb_height', 160);
     $smartResize = 1;
     $jpg_quality = $pluginParams->get('jpg_quality', 80);
     $showcaptions = 0;
     $cache_expire_time = $pluginParams->get('cache_expire_time', 1440) * 60;
     // Cache expiration time in minutes
     // Advanced
     $memoryLimit = (int) $pluginParams->get('memoryLimit');
     if ($memoryLimit) {
         ini_set("memory_limit", $memoryLimit . "M");
     }
     // Cleanups
     // Remove first and last slash if they exist
     if (substr($galleries_rootfolder, 0, 1) == '/') {
         $galleries_rootfolder = substr($galleries_rootfolder, 1);
     }
     if (substr($galleries_rootfolder, -1, 1) == '/') {
         $galleries_rootfolder = substr($galleries_rootfolder, 0, -1);
     }
     // Includes
     require_once dirname(__FILE__) . DS . $this->plg_name . DS . 'includes' . DS . 'helper.php';
     // Other assignments
     $transparent = $pluginLivePath . '/includes/images/transparent.gif';
     // When used with K2 extra fields
     if (!isset($row->title)) {
         $row->title = '';
     }
     // Variable cleanups for K2
     if (JRequest::getCmd('format') == 'raw') {
         $this->plg_copyrights_start = '';
         $this->plg_copyrights_end = '';
     }
     // ----------------------------------- Prepare the output -----------------------------------
     // Process plugin tags
     if (preg_match_all($regex, $row->text, $matches, PREG_PATTERN_ORDER) > 0) {
         // start the replace loop
         foreach ($matches[0] as $key => $match) {
             $tagcontent = preg_replace("/{.+?}/", "", $match);
             if (strpos($tagcontent, ':') !== false) {
                 $tagparams = explode(':', $tagcontent);
                 $galleryFolder = $tagparams[0];
             } else {
                 $galleryFolder = $tagcontent;
             }
             // HTML & CSS assignments
             $srcimgfolder = $galleries_rootfolder . '/' . $galleryFolder;
             $gal_id = substr(md5($key . $srcimgfolder), 1, 10);
             // Render the gallery
             $gallery = SimpleImageGalleryHelper::renderGallery($srcimgfolder, $thb_width, $thb_height, $smartResize, $jpg_quality, $cache_expire_time, $gal_id);
             if (!$gallery) {
                 JError::raiseNotice('', JText::_('JW_PLG_SIG_NOTICE_03') . ' ' . $srcimgfolder);
                 continue;
             }
             // CSS & JS includes: Append head includes, but not when we're outputing raw content (like in K2)
             if (JRequest::getCmd('format') == '' || JRequest::getCmd('format') == 'html') {
                 // Initiate variables
                 $relName = '';
                 $extraClass = '';
                 $extraWrapperClass = '';
                 $legacyHeadIncludes = '';
                 $customLinkAttributes = '';
                 $popupPath = "{$pluginLivePath}/includes/js/{$popup_engine}";
                 $popupRequire = dirname(__FILE__) . DS . $this->plg_name . DS . 'includes' . DS . 'js' . DS . $popup_engine . DS . 'popup.php';
                 if (file_exists($popupRequire) && is_readable($popupRequire)) {
                     require $popupRequire;
                 }
                 if (version_compare(JVERSION, '1.6.0', 'ge')) {
                     JHtml::_('behavior.framework');
                 } else {
                     JHTML::_('behavior.mootools');
                 }
                 if (count($stylesheets)) {
                     foreach ($stylesheets as $stylesheet) {
                         $document->addStyleSheet($popupPath . '/' . $stylesheet);
                     }
                 }
                 if (count($stylesheetDeclarations)) {
                     foreach ($stylesheetDeclarations as $stylesheetDeclaration) {
                         $document->addStyleDeclaration($stylesheetDeclaration);
                     }
                 }
                 if (strpos($popup_engine, 'jquery_') !== false && $jQueryHandling != 0) {
                     if (version_compare(JVERSION, '3.0', 'ge') !== false) {
                         JHtml::_('jquery.framework');
                     } else {
                         if ($jQueryHandling == '1.9') {
                             $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
                         } else {
                             $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/' . $jQueryHandling . '/jquery.min.js');
                         }
                     }
                 }
                 if (count($scripts)) {
                     foreach ($scripts as $script) {
                         if (substr($script, 0, 4) == 'http' || substr($script, 0, 2) == '//') {
                             $document->addScript($script);
                         } else {
                             $document->addScript($popupPath . '/' . $script);
                         }
                     }
                 }
                 if (count($scriptDeclarations)) {
                     foreach ($scriptDeclarations as $scriptDeclaration) {
                         $document->addScriptDeclaration($scriptDeclaration);
                     }
                 }
                 if ($legacyHeadIncludes) {
                     $document->addCustomTag($this->plg_copyrights_start . $legacyHeadIncludes . $this->plg_copyrights_end);
                 }
                 if ($extraClass) {
                     $extraClass = ' ' . $extraClass;
                 }
                 if ($extraWrapperClass) {
                     $extraWrapperClass = ' ' . $extraWrapperClass;
                 }
                 if ($customLinkAttributes) {
                     $customLinkAttributes = ' ' . $customLinkAttributes;
                 }
                 $pluginCSS = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'css/template.css', $thb_template);
                 $pluginCSS = $pluginCSS->http;
                 $document->addStyleSheet($pluginCSS, 'text/css', 'screen');
                 // Print CSS
                 $document->addStyleSheet($pluginLivePath . '/includes/css/print.css', 'text/css', 'print');
                 // Message to show when printing an article/item with a gallery
                 $websiteURL = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off" ? "https://" . $_SERVER['HTTP_HOST'] : "http://" . $_SERVER['HTTP_HOST'];
                 $itemPrintURL = $websiteURL . $_SERVER['REQUEST_URI'];
                 $itemPrintURL = explode("#", $itemPrintURL);
                 $itemPrintURL = $itemPrintURL[0] . '#sigFreeId' . $gal_id;
             } else {
                 $itemPrintURL = false;
             }
             // Fetch the template
             ob_start();
             $templatePath = SimpleImageGalleryHelper::getTemplatePath($this->plg_name, 'default.php', $thb_template);
             $templatePath = $templatePath->file;
             include $templatePath;
             $getTemplate = $this->plg_copyrights_start . ob_get_contents() . $this->plg_copyrights_end;
             ob_end_clean();
             // Output
             $plg_html = $getTemplate;
             // Do the replace
             $row->text = preg_replace("#{" . $this->plg_tag . "}" . $tagcontent . "{/" . $this->plg_tag . "}#s", $plg_html, $row->text);
         }
         // end foreach
         // Global head includes
         if (JRequest::getCmd('format') == '' || JRequest::getCmd('format') == 'html') {
             $document->addScript($pluginLivePath . '/includes/js/behaviour.js');
         }
     }
     // end if
 }