uawdijnntqw1x1x1
IP : 216.73.216.231
Hostname : 213-108-241-110.cprapid.com
Kernel : Linux 213-108-241-110.cprapid.com 5.14.0-570.25.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 9 04:57:09 EDT 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
digilove
/
public_html
/
media
/
..
/
media
/
..
/
41423
/
core.tar
/
/
helper.php000064400000016417152325744560006562 0ustar00<?php /** * @package Sj Basic News * @version 2.5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL * @copyright (c) 2012 YouTech Company. All Rights Reserved. * @author YouTech Company http://www.smartaddons.com * */ defined('_JEXEC') or die; $com_path = JPATH_SITE.'/components/com_content/'; require_once $com_path.'router.php'; require_once $com_path.'helpers/route.php'; if(!class_exists('JModelLegacy')){ class JModelLegacy extends JModel{ } } JModelLegacy::addIncludePath($com_path . '/models', 'ContentModel'); //JLoader::register('ImageHelper', __DIR__.'/helper_base.php'); include_once dirname(__FILE__).'/helper_base.php'; /** * Helper for mod_sj_slideshow * * @package Joomla.Site * @subpackage mod_sj_slideshow */ class SjBasicNewsHelper extends BaseHelper { public static function getList(&$params) { $db = JFactory::getDbo(); // Get an instance of the generic articles model $articles = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); // Set application parameters in model $articles->setState( 'list.select', 'a.id, a.title, a.alias, a.introtext, a.fulltext, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . // use created if modified is 0 'CASE WHEN a.modified = ' . $db->q($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, uam.name as modified_by_name,' . // use created if publish_up is 0 'CASE WHEN a.publish_up = ' . $db->q($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END as publish_up,' . 'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' . 'a.hits, a.xreference, a.featured' ); $app = JFactory::getApplication(); $appParams = $app->getParams(); $articles->setState('params', $appParams); // Set the filters based on the module params $articles->setState('list.start', 0); $articles->setState('list.limit', (int) $params->get('count', 0)); $articles->setState('filter.published', 1); // Access filter $access = !JComponentHelper::getParams('com_content')->get('show_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $articles->setState('filter.access', $access); // Category filter $catids = $params->get('catid'); if ($catids != null) { if ($params->get('show_child_category_articles', 0) && (int) $params->get('levels', 0) > 0) { // Get an instance of the generic categories model $categories = JModelLegacy::getInstance('Categories', 'ContentModel', array('ignore_request' => true)); $categories->setState('params', $appParams); $levels = $params->get('levels', 1) ? $params->get('levels', 1) : 9999; $categories->setState('filter.get_children', $levels); $categories->setState('filter.published', 1); $categories->setState('filter.access', $access); $additional_catids = array(); foreach($catids as $catid) { $categories->setState('filter.parentId', $catid); $recursive = true; $items = $categories->getItems($recursive); if ($items) { foreach($items as $category) { $condition = (($category->level - $categories->getParent()->level) <= $levels); if ($condition) { $additional_catids[] = $category->id; } } } } $catids = array_unique(array_merge($catids, $additional_catids)); } $articles->setState('filter.category_id', $catids); // Ordering $articles->setState('list.ordering', $params->get('article_ordering', 'a.ordering')); $articles->setState('list.direction', $params->get('article_ordering_direction', 'ASC')); // // New Parameters $articles->setState('filter.featured', $params->get('show_front', 'show')); // Filter by language $articles->setState('filter.language', $app->getLanguageFilter()); $items = $articles->getItems(); // Find current Article ID if on an article page $option = $app->input->get('option'); $view = $app->input->get('view'); if ($option === 'com_content' && $view === 'article') { $active_article_id = $app->input->getInt('id'); } else { $active_article_id = 0; } // Prepare data for display using display options foreach ($items as &$item) { $item->slug = $item->id.':'.$item->alias; $item->catslug = $item->catid ? $item->catid .':'.$item->category_alias : $item->catid; $item->catlink = JRoute::_( ContentHelperRoute::getCategoryRoute($item->catslug) ); if ($access || in_array($item->access, $authorised)) { // We know that user has the privilege to view the article $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); } else { $app = JFactory::getApplication(); $menu = $app->getMenu(); $menuitems = $menu->getItems('link', 'index.php?option=com_users&view=login'); if (isset($menuitems[0])) { $Itemid = $menuitems[0]->id; } elseif ($app->input->getInt('Itemid') > 0) { // Use Itemid from requesting page only if there is no existing menu $Itemid = $app->input->getInt('Itemid'); } $item->link = JRoute::_('index.php?option=com_users&view=login&Itemid='.$Itemid); } self::getAImages($item, $params); $item->introtext = self::_cleanText($item->introtext); } return $items; } } public static function groupBy($list, $fieldName, $article_grouping_direction, $fieldNameToKeep = null) { $grouped = array(); if (!is_array($list)) { if ($list == '') { return $grouped; } $list = array($list); } foreach($list as $key => $item) { if (!isset($grouped[$item->$fieldName])) { $grouped[$item->$fieldName] = array(); } if (is_null($fieldNameToKeep)) { $grouped[$item->$fieldName][$key] = $item; } else { $grouped[$item->$fieldName][$key] = $item->$fieldNameToKeep; } unset($list[$key]); } $article_grouping_direction($grouped); return $grouped; } public static function groupByDate($list, $type = 'year', $article_grouping_direction, $month_year_format = 'F Y') { $grouped = array(); if (!is_array($list)) { if ($list == '') { return $grouped; } $list = array($list); } foreach($list as $key => $item) { switch($type) { case 'month_year': $month_year = JString::substr($item->created, 0, 7); if (!isset($grouped[$month_year])) { $grouped[$month_year] = array(); } $grouped[$month_year][$key] = $item; break; case 'year': default: $year = JString::substr($item->created, 0, 4); if (!isset($grouped[$year])) { $grouped[$year] = array(); } $grouped[$year][$key] = $item; break; } unset($list[$key]); } $article_grouping_direction($grouped); if ($type === 'month_year') { foreach($grouped as $group => $items) { $date = new JDate($group); $formatted_group = $date->format($month_year_format); $grouped[$formatted_group] = $items; unset($grouped[$group]); } } return $grouped; } } helper_base.php000064400000043612152325744560007551 0ustar00<?php /** * @package BaseHelper * @subpackage SmartAddons.Helper * @version 2.5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL * @copyright (c) 2012 YouTech Company. All Rights Reserved. * @author YouTech Company http://www.smartaddons.com * */ defined('_JEXEC') or die; JLoader::register('ImageHelper', dirname(__FILE__).'/helper_image.php'); if (!class_exists('BaseHelper')){ /** * BaseHelper for com_content only. */ abstract class BaseHelper{ /** * Cache all image path or url * @var array */ protected static $image_cache = array(); /** * strips all tag, except a, em, strong * @param string $text * @return string */ public static function _cleanText($text){ $text = str_replace('<p>', ' ', $text); $text = str_replace('</p>', ' ', $text); $text = strip_tags($text, '<a><em><strong>'); $text = trim($text); return $text; } /** * Parse and build target attribute for links. * @param string $value (_self, _blank, _windowopen, _modal) * _blank Opens the linked document in a new window or tab * _self Opens the linked document in the same frame as it was clicked (this is default) * _parent Opens the linked document in the parent frame * _top Opens the linked document in the full body of the window * _windowopen Opens the linked document in a Window * _modal Opens the linked document in a Modal Window */ public static function parseTarget($type='_self'){ $target = ''; switch($type){ default: case '_self': break; case '_blank': case '_parent': case '_top': $target = 'target="'.$type.'"'; break; case '_windowopen': $target = "onclick=\"window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,false');return false;\""; break; case '_modal': // user process break; } return $target; } /** * Truncate string by $length * @param string $string * @param int $length * @param string $etc * @return string */ public static function truncate($string, $length, $etc='...'){ return defined('MB_OVERLOAD_STRING') ? self::_mb_truncate($string, $length, $etc) : self::_truncate($string, $length, $etc); } /** * Truncate string if it's size over $length * @param string $string * @param int $length * @param string $etc * @return string */ private static function _truncate($string, $length, $etc='...'){ if ($length>0 && $length<strlen($string)){ $buffer = ''; $buffer_length = 0; $parts = preg_split('/(<[^>]*>)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); $self_closing_tag = split(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); $open = array(); foreach($parts as $i => $s){ if( false===strpos($s, '<') ){ $s_length = strlen($s); if ($buffer_length + $s_length < $length){ $buffer .= $s; $buffer_length += $s_length; } else if ($buffer_length + $s_length == $length) { if ( !empty($etc) ){ $buffer .= ($s[$s_length - 1]==' ') ? $etc : " $etc"; } break; } else { $words = preg_split('/([^\s]*)/', $s, - 1, PREG_SPLIT_DELIM_CAPTURE); $space_end = false; foreach ($words as $w){ if ($w_length = strlen($w)){ if ($buffer_length + $w_length < $length){ $buffer .= $w; $buffer_length += $w_length; $space_end = (trim($w) == ''); } else { if ( !empty($etc) ){ $more = $space_end ? $etc : " $etc"; $buffer .= $more; $buffer_length += strlen($more); } break; } } } break; } } else { preg_match('/^<([\/]?\s?)([a-zA-Z0-9]+)\s?[^>]*>$/', $s, $m); //$tagclose = isset($m[1]) && trim($m[1])=='/'; if (empty($m[1]) && isset($m[2]) && !in_array($m[2], $self_closing_tag)){ array_push($open, $m[2]); } else if (trim($m[1])=='/') { $tag = array_pop($open); if ($tag != $m[2]){ // uncomment to to check invalid html string. // die('invalid close tag: '. $s); } } $buffer .= $s; } } // close tag openned. while(count($open)>0){ $tag = array_pop($open); $buffer .= "</$tag>"; } return $buffer; } return $string; } /** * Truncate mutibyte string if it's size over $length * @param string $string * @param int $length * @param string $etc * @return string */ private static function _mb_truncate($string, $length, $etc='...'){ $encoding = mb_detect_encoding($string); if ($length>0 && $length<mb_strlen($string, $encoding)){ $buffer = ''; $buffer_length = 0; $parts = preg_split('/(<[^>]*>)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); $self_closing_tag = explode(',', 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'); $open = array(); foreach($parts as $i => $s){ if (false === mb_strpos($s, '<')){ $s_length = mb_strlen($s, $encoding); if ($buffer_length + $s_length < $length){ $buffer .= $s; $buffer_length += $s_length; } else if ($buffer_length + $s_length == $length) { if ( !empty($etc) ){ $buffer .= ($s[$s_length - 1]==' ') ? $etc : " $etc"; } break; } else { $words = preg_split('/([^\s]*)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE); $space_end = false; foreach ($words as $w){ if ($w_length = mb_strlen($w, $encoding)){ if ($buffer_length + $w_length < $length){ $buffer .= $w; $buffer_length += $w_length; $space_end = (trim($w) == ''); } else { if ( !empty($etc) ){ $more = $space_end ? $etc : " $etc"; $buffer .= $more; $buffer_length += mb_strlen($more); } break; } } } break; } } else { preg_match('/^<([\/]?\s?)([a-zA-Z0-9]+)\s?[^>]*>$/', $s, $m); //$tagclose = isset($m[1]) && trim($m[1])=='/'; if (empty($m[1]) && isset($m[2]) && !in_array($m[2], $self_closing_tag)){ array_push($open, $m[2]); } else if (trim($m[1])=='/') { $tag = array_pop($open); if ($tag != $m[2]){ // uncomment to to check invalid html string. // die('invalid close tag: '. $s); } } $buffer .= $s; } } // close tag openned. while(count($open)>0){ $tag = array_pop($open); $buffer .= "</$tag>"; } return $buffer; } return $string; } /** * First image in list of images for Article * @param object $item is an Article of Content * @param unknown_type $params * @return Ambigous <NULL, unknown> */ public static function getAImage($item, $params, $prefix='imgcfg'){ $images = self::getAImages($item, $params, $prefix); return is_array($images) && count($images) ? $images[0] : null; } /** * * @param unknown_type $item * @param unknown_type $params */ public static function getAImages($item, $params, $prefix='imgcfg'){ $hash = md5( serialize(array($params, 'article')) ); if ( !isset(self::$image_cache[$hash][$item->id]) ){ $defaults = array( 'external' => 1, 'image_intro' => 1, 'inline_introtext' => 1, 'image_fulltext' => 1, 'inline_fulltext' => 1 ); $images_path = array(); $priority = preg_split('/[\s|,|;]/', $params->get($prefix.'_order', 'external, imagE_intro,inline_introtext,image_fulltext,inline_fulltext'), -1, PREG_SPLIT_NO_EMPTY); if ( count($priority) > 0 ){ $priority = array_map('strtolower', $priority); $mark = array(); for($i=0; $i<count($priority); $i++){ $type = $priority[$i]; if ( array_key_exists($type, $defaults) ) unset($defaults[ $type ]); if ( $params->get($prefix.'_from_'.$type, 1) ) $mark[ $type ] = 1; } } foreach($defaults as $type => $val){ if ( $params->get($prefix.'_from_'.$type, 1) ) $mark[ $type ] = 1; } if ( count($mark) > 0 ){ // prepare data. $images_data = null; if (array_key_exists('image_intro', $mark) || array_key_exists('image_fulltext', $mark)){ $images_data = json_decode($item->images, true); } foreach($mark as $type => $true){ switch ($type){ case 'image_intro': case 'image_fulltext': if ( isset($images_data) && isset($images_data[$type]) && !empty($images_data[$type])){ $image = array( 'src' => $images_data[$type] ); if (array_key_exists($type.'_alt', $images_data)){ $image['alt'] = $images_data[$type.'_alt']; } if (array_key_exists($type.'_caption', $images_data)){ /* $image['class'] = 'caption'; */ $image['title'] = $images_data[$type.'_caption']; } array_push($images_path, $image); } break; case 'inline_introtext': $text = $item->introtext; case 'inline_fulltext': if ($type == 'inline_fulltext'){ $text = $item->fulltext; } $inline_images = self::getInlineImages($text); for ($i=0; $i<count($inline_images); $i++){ array_push($images_path, $inline_images[$i]); } break; case 'external': $exf = $params->get($prefix.'_external_url', 'images/article/{id}/'); preg_match_all('/{([a-zA-Z0-9_]+)}/', $exf, $m); if ( count($m)==2 && count($m[0])>0 ){ $compat = 1; foreach ($m[1] as $property){ !property_exists($item, $property) && ($compat=0); } if ($compat){ $replace = array(); foreach ($m[1] as $property){ $replace[] = is_null($item->$property) ? '' : $item->$property; } $exf = str_replace($m[0], $replace, $exf); } } $files = self::getExternalImages($exf); for ($i=0; $i<count($files); $i++){ array_push($images_path, array('src'=>$files[$i])); } break; default: break; } } } if ( count($images_path) == 0 && $params->get($prefix.'_placeholder', 1)==1){ $images_path[] = array('src'=> $params->get($prefix.'_placeholder_path', 'modules/mod_sj_basic_news/assets/images/nophoto.png'), 'class'=>'placeholder'); } self::$image_cache[$hash][$item->id] = $images_path; } return self::$image_cache[$hash][$item->id]; } public static function getCImage($item, $params, $prefix='imgcfg'){ $images = &self::getCImages($item, $params, $prefix); return is_array($images) && count($images) ? $images[0] : null; } public static function getCImages($item, $params, $prefix='imgcfg'){ $hash = md5( serialize(array($params, 'category')) ); if ( !isset(self::$image_cache[$hash][$item->id]) ){ $defaults = array( 'external' => 1, 'params' => 1, 'description' => 1 ); $images_path = array(); $priority = preg_split('/[\s|,|;]/', $params->get($prefix.'_order', 'external, params, description'), -1, PREG_SPLIT_NO_EMPTY); if ( count($priority) > 0 ){ $priority = array_map('strtolower', $priority); $mark = array(); for($i=0; $i<count($priority); $i++){ $type = $priority[$i]; if ( array_key_exists($type, $defaults) ) unset($defaults[ $type ]); if ( $params->get($prefix.'_from_'.$type, 1) ) $mark[ $type ] = 1; } } foreach($defaults as $type => $val){ if ( $params->get($prefix.'_from_'.$type, 1) ) $mark[ $type ] = 1; } if ( count($mark) > 0 ){ $cparams = null; if (array_key_exists('params', $mark)){ $cparams = new JRegistry; $cparams->loadString($item->params); } foreach($mark as $type => $true){ switch ($type){ case 'params': if ( $cparams instanceof JRegistry && $cparams->get('image') ){ $image = array( 'src' => $cparams->get('image') ); array_push($images_path, $image); } break; case 'description': $inline_images = self::getInlineImages($item->description); for ($i=0; $i<count($inline_images); $i++){ array_push($images_path, $inline_images[$i]); } break; case 'external': $exf = $params->get($prefix.'_external_url', 'images/category/{id}/'); preg_match_all('/{([a-zA-Z0-9_]+)}/', $exf, $m); if ( count($m)==2 && count($m[0])>0 ){ $compat = 1; foreach ($m[1] as $property){ !property_exists($item, $property) && ($compat=0); } if ($compat){ $replace = array(); foreach ($m[1] as $property){ $replace[] = is_null($item->$property) ? '' : $item->$property; } $exf = str_replace($m[0], $replace, $exf); } } $files = self::getExternalImages($exf); for ($i=0; $i<count($files); $i++){ array_push($images_path, array('src'=>$files[$i])); } break; default: break; } } } if ( count($images_path) == 0 && $params->get($prefix.'_placeholder', 1)==1){ $images_path[] = array('src'=> $params->get($prefix.'_placeholder_path', null), 'class'=>'placeholder'); } self::$image_cache[$hash][$item->id] = $images_path; } return self::$image_cache[$hash][$item->id]; } /** * Get all image url|path in $text. * @param string $text * @return string */ public static function getInlineImages($text){ $images = array(); $searchTags = array( 'img' => '/<img[^>]+>/i', 'input' => '/<input[^>]+type\s?=\s?"image"[^>]+>/i' ); foreach ($searchTags as $tag => $regex){ preg_match_all($regex, $text, $m); if ( is_array($m) && isset($m[0]) && count($m[0])){ foreach ($m[0] as $htmltag){ $tmp = JUtility::parseAttributes($htmltag); if ( isset($tmp['src']) ){ if ($tag == 'input'){ array_push( $images, array('src' => $tmp['src']) ); } else { array_push( $images, $tmp ); } } } } } return $images; } /** * * @param string $path * @return multitype:multitype:unknown |Ambigous <multitype:, boolean, multitype:unknown multitype:unknown > */ public static function getExternalImages($path){ jimport('joomla.filesystem.folder'); $files = array(); // check if $path is url $path = trim($path); $isHttp = stripos($path, 'http') === 0; if ($isHttp){ if ( !JUri::isInternal($path) ){ // is external, test if is valid if ( version_compare(JVERSION, '3.0.0', '>=') ){ // is Joomla 3 $http = JHttpFactory::getHttp(); $head = $http->head($path); if ($head->code == 200 || $head->code == 302 || $head->code == 304){ // is valid url if (preg_match('/image/', $head->headers['Content-Type'])){ // is true image $files[] = $path; } } } else { // for Joomla 3 older $files[] = $path; } if (!count($files)){ var_dump('Url is not valid'); } return $files; } else { $uri = JUri::getInstance($path); $uri_path = (string)$uri->getPath(); $uri_base = (string)JURI::base(true); if (stripos($uri_path, $uri_base)===0 && ($baselen = strlen($uri_base))){ $uri_path = substr($uri_path, $baselen); } $path = JPATH_BASE.$uri_path; } } if ( ($realpath = realpath($path))===false ){ //var_dump('File or Folder is not exists!'); return $files; } if ( is_file($realpath) ){ $files[] = $realpath; } else if ( is_dir($realpath) ){ $files = JFolder::files($path, '.jpg|.png|.gif', false, true); } return $files; } /** * Get an image helper object * @param string $image - path or url of image * @param array $options * @return ImageHelper */ public static function getImageHelper($image, $options=array()){ return ImageHelper::init($image, $options); } /** * Resize and return image tag (<img .../>) * @param string $image - path or url of image * @param array $options * @return string */ public static function imageTag($image, $options=array()){ return ImageHelper::init($image, $options)->tag(); } /** * Resize and return image src * @param string $image - path or url of image * @param array $options * @return string */ public static function imageSrc($image, $options=array()){ return ImageHelper::init($image, $options)->src(); } protected static $js = array(); public static function jQuery($extension, $include_jquery = true, $noConflict = true, $debug = null){ if (version_compare(JVERSION, '3.0.0', '>=')){ // 3.0.0 or upper JHtml::_('jquery.framework', $noConflict, $debug); } else { if ( !empty(self::$js[__METHOD__]) || !$include_jquery) return; // If no debugging value is set, use the configuration setting if ($debug === null) { $config = JFactory::getConfig(); $debug = (boolean) $config->get('debug'); } if (!empty($extension) && substr($extension, -1)!='/'){ $extension .= '/'; } JHtml::script($extension.'jquery'.($debug?'.min':'').'.js', false, true, false, false, $debug); if ($noConflict){ JHtml::script($extension.'jquery-noconflict.js', false, true, false, false, false); } self::$js[__METHOD__] = true; } } } } helper_image.php000064400000051503152325744560007717 0ustar00<?php /** * @package HelperImages * @version 2.5.0 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL * @copyright (c) 2012 YouTech Company. All Rights Reserved. * @author YouTech Company http://www.smartaddons.com */ defined('_JEXEC') or die; class ImageHelper{ protected static $instances = array(); protected static $defaults = array( 'type' => null, 'width' => null, 'height' => null, 'quality' => 90, 'function' => null, 'function_mode' => null, 'transparency' => true, 'background' => array('r'=>255, 'g'=>255, 'b'=>255) ); public static $cache = null; public static $cache_url = null; public static $supports = array( IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG ); public static $functions = array( 'resize', 'crop', 'rotate', 'flip_horizontal', 'flip_vertical' ); public static $modes = array( 'center', 'fill', 'fit', 'stretch' ); protected $image = null; protected $in = null; protected $out = null; protected $errors = array(); protected $options = null; protected $_process = 1; protected $debug = false; /** * * @param mixed $image * @param array $options * @return ImageHelper */ public static function init($image, $options = array()){ $cacheid = count(self::$instances); if (!isset(self::$instances[$cacheid])){ self::$instances[$cacheid] = new ImageHelper($image, $options); } return self::$instances[$cacheid]; } /** * ImageHelper constructor * @param unknown_type $image * @param unknown_type $options */ public function __construct($image = null, $options = array()){ !is_null($image) && $this->image = $image; // defaults foreach (ImageHelper::$defaults as $name => $value){ $this->options[$name] = array_key_exists($name, $options) ? $options[$name] : $value; } $this->in = array( 'type'=>null, 'src' =>null ); $this->out = array(); $this->initCache($options); $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::__construct'); } public static function setDefault($params = null){ self::$defaults = array( 'type' => null, 'width' => null, 'height' => null, 'quality' => 90, 'function' => null, 'function_mode' => null, 'transparency' => true, 'background' => array('r'=>255, 'g'=>255, 'b'=>255) ); if ($params instanceof JRegistry){ $opts = array(); // output type ? $imgcfg_type = $params->get('imgcfg_type', 0); if (in_array($imgcfg_type, array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF))){ $opts['type'] = $imgcfg_type; } // function ? $imgcfg_fn = $params->get('imgcfg_function', 'none_resize'); $imgcfg_fn = explode('_', $imgcfg_fn); if ( in_array($imgcfg_fn[0], self::$functions) ){ $opts['function'] = $imgcfg_fn[0]; if ($imgcfg_fn[0] == 'resize'){ if ( isset($imgcfg_fn[1]) && in_array($imgcfg_fn[1], self::$modes) ){ $opts['function_mode'] = $imgcfg_fn[1]; } else { $opts['function_mode'] = self::$modes[2]; } } } // background $imgcfg_background = $params->get('imgcfg_background', null); if (!is_null($imgcfg_background)){ $opts['background'] = $imgcfg_background; } // quality $imgcfg_quality = $params->get('imgcfg_quality', null); if ( $imgcfg_quality != null && intval($imgcfg_quality) > 0 && intval($imgcfg_quality) < 100 ){ $opts['quality'] = intval($imgcfg_quality); } // transparency $imgcfg_transparency = $params->get('imgcfg_transparency', 1); if ( $imgcfg_transparency != null){ $opts['transparency'] = $imgcfg_transparency ? true : false; } // dimension ? $imgcfg_w = $params->get('imgcfg_width', 0); $imgcfg_h = $params->get('imgcfg_height', 0); if ( intval($imgcfg_w) > 0 ){ $opts['width'] = $imgcfg_w; } if ( intval($imgcfg_h) > 0 ){ $opts['height'] = $imgcfg_h; } self::$cache = $params->get('imgcfg_cache'); self::$cache_url = $params->get('imgcfg_cache_url'); // $this->initCache($cache_params); } self::$defaults = array_merge(self::$defaults, $opts); } public static function testDefault(){ echo 'ImageHelper::$defaults'.'<br>'; var_dump(self::$defaults); } /** * convert absolute path in joomla to url (not 4 script file) * @param string $jpath must contain JPATH_BASE * @return string */ public function jpath2url($jpath){ $realpath = realpath($jpath); if (!empty($realpath) && defined('JPATH_BASE')){ $jpathbase = realpath(JPATH_BASE); if (stripos($realpath, $jpathbase)===0){ $subpath = str_replace($jpathbase, '', $realpath); if (!empty($subpath) && DIRECTORY_SEPARATOR==$subpath[0]){ $subpath = substr($subpath, 1); } return JPath::clean($subpath, '/'); } } return $jpath; } public function initCache($options = array()){ $private_cache = array_key_exists('cache', $options) ? $options['cache'] : null; $private_cache_url = array_key_exists('cache_url', $options) ? $options['cache_url'] : null; if (empty($private_cache)){ if (is_null(ImageHelper::$cache) && defined('JPATH_CACHE')){ ImageHelper::$cache = JPATH_CACHE.'/resized'; if (!file_exists(ImageHelper::$cache)){ if (!@mkdir(ImageHelper::$cache, 0755, true)){ ImageHelper::$cache = null; } } } if (is_null(ImageHelper::$cache)){ ImageHelper::$cache = dirname(__FILE__).'/resized'; } if (!file_exists(ImageHelper::$cache)){ if (!@mkdir(ImageHelper::$cache, 0755, true)){ ImageHelper::$cache = null; } } if (is_null(ImageHelper::$cache)){ $this->errors[] = 'Can not create cache folder!'; } else { $private_cache = ImageHelper::$cache; } } if (empty($private_cache_url)){ if (empty($private_cache)){ // noop } else { $private_cache_url = $this->jpath2url($private_cache); } } $this->out['cache'] = $private_cache; $this->out['cache_url'] = $private_cache_url; } /** * Get image type for input url or path of file. * @return mixed */ protected function getInputType(){ if ( !isset($this->in['type']) ){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getInputType'); if (is_string($this->image)){ $path = $this->image; } else { $path = @$this->image['src']; } if (is_string($path)){ $ps = JString::parse_url($path); if ( array_key_exists('path', $ps) && !empty($ps['path']) ){ $isHttp = isset($ps['scheme']) && in_array($ps['scheme'], array('http', 'https')); if (!$isHttp || JURI::isInternal($path)){ $path = $ps['path']; } else { // is extenal url. $this->in['type'] = 'url'; $this->in['src'] = $path; return $this->in['type']; } } } else if (!$path){ $this->errors[] = 'Image path must be string or stored in array_argument[src]!'; } //var_dump('Path: ', $path); if ( !file_exists($path) ){ $this->errors[] = 'Image path is not exists!'; } else { //var_dump('EXISTS'); $this->in['src'] = realpath($path); $infor = array(); if ( !function_exists('exif_imagetype') ){ $intype = exif_imagetype($path); } else { $infor = getimagesize($path); $intype= @$infor[2]; } switch ($intype){ case IMAGETYPE_PNG: $this->in['type'] = IMAGETYPE_PNG; break; case IMAGETYPE_GIF: $this->in['type'] = IMAGETYPE_GIF; break; case IMAGETYPE_JPEG: $this->in['type'] = IMAGETYPE_JPEG; break; default: } } } return $this->in['type']; } protected function getInputResource(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getInputResource'); //var_dump('getInputResource: '.$this->in['src']); if ( !isset($this->in['image']) ){ $intype = $this->getInputType(); switch ($intype){ case IMAGETYPE_PNG: $this->in['image'] = imagecreatefrompng($this->in['src']); break; case IMAGETYPE_GIF: $this->in['image'] = imagecreatefromgif($this->in['src']); break; case IMAGETYPE_JPEG: $this->in['image'] = imagecreatefromjpeg($this->in['src']); break; default: $this->in['image'] = null; return false; } } return is_resource($this->in['image']) ? $this->in['image'] : null; } protected function validOptions(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::validOptions'); // TODO: validate input $type = $this->getInputType(); $input_type_ok = ($type=='url') || in_array($type, ImageHelper::$supports); if ( !$input_type_ok ){ $this->errors[] = 'Input type is not supported!'; $this->_process = 0; } else if ($type=='url'){ $this->_process = 0; } // required options $output_type_ok = !is_null($this->options['type']) && in_array($this->options['type'], ImageHelper::$supports); if ( !$output_type_ok ){ if ( $input_type_ok ){ $this->options['type'] = $type; } } if ( !($this->options['width']>0 || $this->options['height']>0) ){ $this->errors[] = 'Output width or height must be greater than zero (>0)!'; $this->_process = 0; } if ( in_array($this->options['function'], ImageHelper::$functions) ){ if ($this->options['function'] == 'resize' && !in_array($this->options['function_mode'], ImageHelper::$modes)){ $this->errors[] = 'Resize mode is not valid! should be in ['.implode(', ', ImageHelper::$modes).']'; $this->_process = 0; } } else { $this->errors[] = 'Output function is not valid! should be in ['.implode(', ', ImageHelper::$functions).']'; $this->_process = 0; } // auto parse options if ( !isset($this->options['quality']) || !is_numeric($this->options['quality']) || $this->options['quality']==0 ){ $this->options['quality'] = 90; } else { if ($this->options['quality'] < 10){ $this->options['quality'] = 10; } if ($this->options['quality'] > 100){ $this->options['quality'] = 100; } } $c = &$this->options['background']; if ( is_string($this->options['background']) ){ if ( preg_match('/^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$/i', $this->options['background'], $m) ){ $hex = isset($m[1]) ? $m[1] : null; if (strlen($hex)==3){ $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; } if ($hex){ $dec = hexdec($hex); $this->options['background'] = array( 'r' => 0xFF & ($dec >> 0x10), 'g' => 0xFF & ($dec >> 0x8), 'b' => 0xFF & $dec ); } else { $this->options['background'] = null; } } else { $this->options['background'] = null; } } if ( !is_array($this->options['background']) ){ $this->options['background'] = null; } else { $valid = 1; $bg = $this->options['background']; foreach (array('r', 'g', 'b') as $e){ if ( !array_key_exists($e, $bg) || ($bg[$e]<0) || ($bg[$e]>255) ){ $valid = 0; break; } } if (!$valid){ $this->options['background'] = null; } } $this->initCache(); return count($this->errors) == 0; } protected function getOutputFile(){ if ( !array_key_exists('src', $this->out) || is_null($this->out['src']) ){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getOutputFile'); $hash = md5( serialize( array($this->options, $this->in['src'], $this->in['type']) ) ); if (defined('DEBUG') && 0){ $hash = basename($this->in['src'], '.jpg'); $w = isset($this->options['width']) ? $this->options['width'] : 0; $h = isset($this->options['height']) ? $this->options['height'] : 0; $hash .= '-'.$w.'x'.$h; $hash .= '-'.$this->options['function']; $hash .= '-'.$this->options['function_mode']; $hash .= '-'.$this->options['quality']; } switch ($this->options['type']){ case IMAGETYPE_PNG: $ext = '.png'; break; case IMAGETYPE_GIF: $ext = '.gif'; break; case IMAGETYPE_JPEG: $ext = '.jpg'; break; default: $ext = image_type_to_extension($this->options['type'], true); } $this->out['src'] = $this->out['cache'].'/'.$hash.$ext; $this->save2f(); $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getOutputFile::::'.$this->out['src']); } return $this->out['src']; } protected function getOutputUrl(){ if (!isset($this->out['url'])){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getOutputUrl'); if ( $this->validOptions() && in_array($this->options['type'], ImageHelper::$supports) ){ $this->out['url'] = $this->out['cache_url'].'/'.basename( $this->getOutputFile() ); } else { $original = is_string($this->image) ? $this->image : @$this->image['src']; if (!(stripos($original, 'http')===0)){ $original = $this->jpath2url($original); } $this->out['url'] = $original; $this->debug && JFactory::getApplication()->enqueueMessage('Not validOptions:: '.$this->out['url']); } $is_ajax = ! empty ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) && strtolower ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest'; if ($is_ajax && !(stripos($this->out['url'], 'http')===0)){ $this->out['url'] = JUri::root(). $this->out['url']; } } return $this->out['url']; } /** * @return mixed */ public function output(){ if ( $this->validOptions() && $this->getInputResource()){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::output'); $this->process(); if (is_resource($this->out['image'])){ $oImage = &$this->out['image']; switch( $this->options['type'] ){ case IMAGETYPE_JPEG: imagejpeg($oImage, $this->getOutputFile(), $this->options['quality']); break; case IMAGETYPE_GIF: imagegif($oImage, $this->getOutputFile()); break; case IMAGETYPE_PNG: imagepng($oImage, $this->getOutputFile(), 10 - round($this->options['quality']/10.0)); break; } } } } /** *@return string */ public function tag(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::tag'); if (!$this->getOutputUrl()){ return ''; } $tag = array(); if (is_array($this->image)){ foreach ($this->image as $att => $val){ if ($att == 'src'){ $tag[] = 'src="'.$this->getOutputUrl().'"'; } else { $tag[] = $att.'="'.$val.'"'; } } if (!array_key_exists('alt', $this->image)){ $tag[] = 'alt="'.$this->getOutputUrl().'"'; } } else { $tag[] = 'src="'.$this->getOutputUrl().'"'; $tag[] = 'alt="'.$this->getOutputUrl().'"'; } return count($tag) ? '<img '.implode(' ', $tag).'/>' : ''; } /** * @return string */ public function path(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::path'); return $this->__toString(); } public function src(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::src'); return $this->getOutputUrl(); } /** * @return string */ public function error(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::error'); return $this->errors; } /** * Resize input image by size * @param int $w * @param int $h * @return ImageHelper */ public function resize($w = 0, $h = 0){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::resize'); if ($w > 0) $this->options['width'] = $w; if ($h > 0) $this->options['height'] = $h; return $this; } protected function actionPerformed(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::actionPerformed'); $sImage = $this->getInputResource(); if ( !is_resource($sImage) ) return; $sw = imagesx($sImage); $sh = imagesy($sImage); if ( $this->options['function']=='resize' ){ $ow = is_null($this->options['width']) ? 0 : intval($this->options['width']); $oh = is_null($this->options['height']) ? 0 : intval($this->options['height']); if ( $ow==0 && $oh==0 ){ die('thoi khoi resize'); } else if ($ow == 0){ // resize by height. $this->options['function_mode'] = ImageHelper::$modes[3]; $ow = $this->options['width'] = round($oh * $sw/$sh); } else if ($oh == 0){ $this->options['function_mode'] = ImageHelper::$modes[3]; $oh = $this->options['height'] = (int)round($ow * $sh/$sw); // resize by width } else if ( abs($oh-round($ow*$sh/$sw)) <= 1 ){ // resize by ca hai $this->options['function_mode'] = ImageHelper::$modes[3]; $oh = $this->options['height'] = round($ow*$sh/$sw); } $oImage = $this->getCanvas(); // build agrs $sx = $sy = 0; $dx = $dy = 0; $dw = $sw; $dh = $sh; switch($this->options['function_mode']){ case ImageHelper::$modes[0]: if ($ow > $dw) { $dx = ($ow-$dw)/2; } if ($oh > $dh) { $dy = ($oh-$dh)/2; } if ($sw > $ow){ $sx = ($sw-$ow)/2; } if ($sh > $oh){ $sy = ($sh-$oh)/2; } break; case ImageHelper::$modes[1]: $or = 1.0*$sw/$sh; if ($ow < $oh*$or){ $dw = round($oh*$or); $dh = $oh; $dx = ($ow-$dw)/2; $dy = 0; } else { $dw = $ow; $dh = round($ow/$or); $dx = 0; $dy = ($oh-$dh)/2; } break; case ImageHelper::$modes[2]: $or = 1.0*$sw/$sh; if ($ow > $oh*$or){ $dw = round($oh*$or); $dh = $oh; $dx = ($ow-$dw)/2; $dy = 0; } else { $dw = $ow; $dh = round($ow/$or); $dx = 0; $dy = ($oh-$dh)/2; } break; default: case ImageHelper::$modes[3]: $dw = $ow; $dh = $oh; break; } imagecopyresampled( $oImage, $sImage, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh ); $this->out['image'] = $oImage; } return 1; } // public function __destruct(){ // $this->save2f(); // $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::__destruct'); // } protected function save2f(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::save2f'); if ($this->_process && ($of = $this->getOutputFile()) && !file_exists($of)){ $this->actionPerformed(); if ( array_key_exists('image', $this->out) && is_resource($this->out['image'])){ $oImage = &$this->out['image']; switch( $this->options['type'] ){ case IMAGETYPE_JPEG: imagejpeg($oImage, $of, $this->options['quality']); break; case IMAGETYPE_GIF: imagegif($oImage, $of); break; case IMAGETYPE_PNG: imagepng($oImage, $of, 10 - round($this->options['quality']/10.0)); break; } } } } protected function getCanvas(){ if ( !isset($this->out['image']) ){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::getCanvas'); $oImage = imagecreatetruecolor($this->options['width'], $this->options['height']); if ($this->options['transparency'] && in_array($this->options['type'], array(IMAGETYPE_GIF, IMAGETYPE_PNG))){ if (IMAGETYPE_GIF == $this->in['type']){ $trans_index = imagecolortransparent($this->in['image']); if ($trans_index >= 0) { $trans_color = imagecolorsforindex($this->in['image'], $trans_index); $trans_index = imagecolorallocate($oImage, $trans_color['red'], $trans_color['green'], $trans_color['blue']); imagefill($oImage, 0, 0, $trans_index); imagecolortransparent($oImage, $trans_index); } } else if (IMAGETYPE_PNG == $this->in['type']){ $png_alpha = ((ord(file_get_contents($this->in['src'], false, null, 25, 1)) & 6) & 4) == 4; if ($png_alpha){ imagealphablending($oImage, true); $transparent = imagecolorallocatealpha($oImage, 0, 0, 0, 127); imagefilledrectangle($oImage, 0, 0, $this->options['width'], $this->options['height'], $transparent); imagealphablending($oImage, false); imagesavealpha($oImage, true); } } } else if ( !is_null($this->options['background']) && $this->options['function']==ImageHelper::$functions[0] && in_array($this->options['function_mode'], array(ImageHelper::$modes[0], ImageHelper::$modes[2]))){ $bgc = imagecolorallocate( $oImage, $this->options['background']['r'], $this->options['background']['g'], $this->options['background']['b'] ); imagefilledrectangle($oImage, 0, 0, $this->options['width'], $this->options['height'], $bgc); } $this->out['image'] = $oImage; } return $this->out['image']; } public function __toString(){ $this->debug && JFactory::getApplication()->enqueueMessage('ImageHelper::__toString'); $f = $this->getOutputFile(); return is_null($f) ? '' : $f; } }index.html000064400000000054152325744560006555 0ustar00<html><body bgcolor="#FFFFFF"></body></html>
/home/digilove/public_html/media/../media/../41423/core.tar