Ejemplo n.º 1
0
/*------------------------------------------------------------------------
# mod_featcats - Featured Categories
# ------------------------------------------------------------------------
# author    Jesús Vargas Garita
# Copyright (C) 2010 www.joomlahill.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.joomlahill.com
# Technical Support:  Forum - http://www.joomlahill.com/forum
-------------------------------------------------------------------------*/
defined('_JEXEC') or die;
if ($params->get('hide1', 0) && (JRequest::getCmd('option') == 'com_content' && JRequest::getCmd('view') == 'article')) {
    return;
} else {
    require_once dirname(__FILE__) . '/helper.php';
    $cats = modFeatcatsHelper::getList($params);
    if (!empty($cats)) {
        $moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
        $item_heading = $params->get('item_heading');
        $cat_heading = $params->get('cat_heading');
        $link_cats = $params->get('link_cats', 1);
        $show_image = $params->get('show_image', 0);
        $show_more = $params->get('show_more');
        $link_target = $params->get('link_target');
        $pag = $params->get('pag_show', 0);
        $css = $params->get('add_css', 'featcats.css');
        if (!$params->get('mid')) {
            $mid = $module->id;
        } else {
            $mid = $params->get('mid');
        }
Ejemplo n.º 2
0
 public static function getThumbnail($img, &$params, $item_id, $alt)
 {
     $width = $params->get('thumb_width', 90);
     $height = $params->get('thumb_height', 90);
     $proportion = $params->get('thumb_proportions', 'bestfit');
     $img_type = $params->get('thumb_type', '');
     $bgcolor = hexdec($params->get('thumb_bg', '#FFFFFF'));
     $def_image = $params->get('def_image', '');
     $item_img = $img ? $img : $def_image;
     $img_name = pathinfo($item_img, PATHINFO_FILENAME);
     $img_ext = pathinfo($item_img, PATHINFO_EXTENSION);
     $img_path = JPATH_BASE . '/' . $item_img;
     $img_base = JURI::base(false);
     if (modFeatcatsHelper::is_absolute($item_img)) {
         $img_path = $item_img;
     }
     $size = @getimagesize($img_path);
     $errors = array();
     if (!$size) {
         $errors[] = 'There was a problem loading image ' . $img_name . '.' . $img_ext . ' in mod_featcats';
     } else {
         $sub_folder = $img ? '0' . substr($item_id, -1) : 'default';
         if ($img_type) {
             $img_ext = $img_type;
         }
         $origw = $size[0];
         $origh = $size[1];
         if ($origw < $width && $origh < $height) {
             $width = $origw;
             $height = $origh;
         }
         $prefix = substr($proportion, 0, 1) . "_" . $width . "_" . $height . "_" . ($proportion == 'fill' ? $bgcolor . "_" : "") . ($img ? $item_id . "_" : "");
         $thumb_file = $prefix . str_replace(array(JPATH_ROOT, ':', '/', '\\', '?', '&', '%20', ' '), '_', urlencode($img_name) . '.' . $img_ext);
         //$thumb_path = __DIR__ . '/thumbs/' . $sub_folder . '/' . $thumb_file;
         $thumb_path = dirname(__FILE__) . '/thumbs/' . $sub_folder . '/' . $thumb_file;
         $attribs = array();
         if (file_exists($thumb_path)) {
             $size = @getimagesize($thumb_path);
             if ($size) {
                 $attribs['width'] = $size[0];
                 $attribs['height'] = $size[1];
             }
         } else {
             modFeatcatsHelper::calculateSize($origw, $origh, $width, $height, $proportion, $newwidth, $newheight, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
             switch (strtolower($size['mime'])) {
                 case 'image/png':
                     $imagecreatefrom = "imagecreatefrompng";
                     break;
                 case 'image/gif':
                     $imagecreatefrom = "imagecreatefromgif";
                     break;
                 case 'image/jpeg':
                     $imagecreatefrom = "imagecreatefromjpeg";
                     break;
                 default:
                     $errors[] = "Unsupported image type {$img_name}.{$img_ext} " . $size['mime'];
             }
             if (!function_exists($imagecreatefrom)) {
                 $errors[] = "Failed to process {$img_name}.{$img_ext} in mod_featcats. Function {$imagecreatefrom} doesn't exist.";
             }
             $src_img = $imagecreatefrom($img_path);
             if (!$src_img) {
                 $errors[] = "There was a problem to process image {$img_name}.{$img_ext} " . $size['mime'] . 'in mod_featcats';
             }
             $dst_img = ImageCreateTrueColor($width, $height);
             // $bgcolor = imagecolorallocatealpha($image, 200, 200, 200, 127);
             imagefill($dst_img, 0, 0, $bgcolor);
             if ($proportion == 'transparent') {
                 imagecolortransparent($dst_img, $bgcolor);
             }
             imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $newwidth, $newheight, $src_w, $src_h);
             switch (strtolower($img_ext)) {
                 case 'png':
                     $imagefunction = "imagepng";
                     break;
                 case 'gif':
                     $imagefunction = "imagegif";
                     break;
                 default:
                     $imagefunction = "imagejpeg";
             }
             if ($imagefunction == 'imagejpeg') {
                 $result = @$imagefunction($dst_img, $thumb_path, 80);
             } else {
                 $result = @$imagefunction($dst_img, $thumb_path);
             }
             imagedestroy($src_img);
             if (!$result) {
                 if (!isset($disablepermissionwarning)) {
                     $errors[] = 'Could not create image:<br />' . $thumb_path . ' in mod_featcats.<br /> Check if the folder exists and if you have write permissions:<br /> ' . dirname(__FILE__) . '/thumbs/' . $sub_folder;
                 }
                 $disablepermissionwarning = true;
             } else {
                 imagedestroy($dst_img);
             }
         }
     }
     if (count($errors)) {
         JError::raiseWarning(404, implode("\n", $errors));
         return false;
     }
     $image = $img_base . "modules/mod_featcats/thumbs/{$sub_folder}/" . urlencode(basename($thumb_path));
     return JHTML::_('image', $image, $alt, $attribs);
 }