Exemplo n.º 1
0
$layout = $params->get('layout', 'default');
$color = $params->get('layout-sidenews-textcolor', 'FFFFFF');
if ($color) {
    $color = " color:#{$color};";
}
$playMode = $params->get('layout-sidenews-play_mode', 'caption');
$bgcolor = $params->get('layout-sidenews-bgcolor', '008800');
if ($bgcolor) {
    $bgcolor = " background-color:#{$bgcolor};";
}
$trans = intval($params->get('layout-sidenews-transparent', 80));
$thumbnailMode = $params->get('thumbnail_mode', 'crop');
$aspect = $params->get('thumbnail_mode-resize-use_ratio', '1');
$crop = $thumbnailMode == 'crop' ? true : false;
$lists = array();
$jaimage = JAImage::getInstance();
// load js and css files.
if (!defined('_MODE_JASIDERNEWS_ASSETS_')) {
    define('_MODE_JASIDERNEWS_ASSETS_', 1);
    JHTML::stylesheet('modules/' . $module->module . '/assets/' . 'style.css');
    if (is_file(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'css' . DS . $module->module . ".css")) {
        JHTML::stylesheet('templates/' . $mainframe->getTemplate() . '/css/' . $module->module . ".css");
    }
}
if ($layout == 'default' || $layout == -1) {
    $layout = 'default.php';
}
$helper = new modJASildeNewsHelper();
$list = $helper->getList($params);
if ($layout == 'sidenews' || $layout == "sidenews.php") {
    $layout = $layout . '_' . $sidemode;
Exemplo n.º 2
0
 /**
  *
  * Get list articles
  * @param object $params
  * @return array
  */
 public function getAticles($params)
 {
     // Get the dbo
     $db = JFactory::getDbo();
     // Get an instance of the generic articles model
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
         } else {
             $model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
         }
     }
     // Set application parameters in model
     $appParams = JFactory::getApplication()->getParams();
     $model->setState('params', $appParams);
     $model->setState('list.select', 'a.fulltext, a.id, a.title, a.alias, a.introtext, a.state, a.images, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured, a.ordering, c.alias AS category_alias, ' . ' LENGTH(a.fulltext) AS readmore');
     // Set the filters based on the module params
     $model->setState('list.start', 0);
     $model->setState('list.limit', (int) trim($params->get('count', 5)));
     if ((int) trim($params->get('count', 5)) == 0) {
         $model->setState('filter.published', 10);
     } else {
         $model->setState('filter.published', 1);
     }
     // Access filter
     $access = !JComponentHelper::getParams('com_content')->get('show_noauth');
     $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
     $model->setState('filter.access', $access);
     // Category filter
     if ($params->get('category')) {
         $model->setState('filter.category_id', $params->get('category'));
     }
     $featured = $params->get('show_featured', 1);
     if (!$featured) {
         $model->setState('filter.featured', 'hide');
     } elseif ($featured == 2) {
         $model->setState('filter.featured', 'only');
     }
     // Set ordering
     $ordering = $params->get('type', 'latest');
     if ($ordering == 'latest') {
         // Set ordering
         $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'mc_dsc' => 'CASE WHEN (a.modified = ' . $db->quote($db->getNullDate()) . ') THEN a.created ELSE a.modified END', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up');
         $ordering = JArrayHelper::getValue($order_map, $params->get('ordering', 'm_dsc'), 'a.publish_up');
     } else {
         $ordering = 'a.hits';
     }
     $dir = 'DESC';
     if ($ordering !== 'latest' && $params->get('timerange')) {
         $model->setState('filter.date_filtering', 'relative');
         $model->setState('filter.relative_date', $params->get('timerange'));
     }
     $model->setState('list.ordering', $ordering);
     $model->setState('list.direction', $dir);
     $items = $model->getItems();
     if ($items) {
         $i = 0;
         $showHits = $params->get('show_hits', 0);
         $showHits = $showHits == "1" ? true : false;
         $showimg = $params->get('show_image', 1);
         $w = (int) $params->get('width', 80);
         $h = (int) $params->get('height', 96);
         $showdate = $params->get('show_date', 1);
         $thumbnailMode = $params->get('thumbnail_mode', 'crop');
         $aspect = $params->get('use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $lists = array();
         $jaimage = JAImage::getInstance();
         foreach ($items as &$item) {
             $item->slug = $item->id . ':' . $item->alias;
             $item->catslug = $item->catid . ':' . $item->category_alias;
             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 {
                 $item->link = JRoute::_('index.php?option=com_user&view=login');
             }
             $item->introtext = JHtml::_('content.prepare', $item->introtext);
             $item->text = htmlspecialchars($item->title);
             if ($showdate) {
                 $item->date = $item->modified == null || $item->modified == "" || $item->modified == "0000-00-00 00:00:00" ? $item->created : $item->modified;
             }
             $item->image = '';
             if ($showimg) {
                 $imageSource = $jaimage->parseImage($item);
                 if ($imageSource) {
                     if ($thumbnailMode != 'none') {
                         $imageURL = $jaimage->resize($imageSource, $w, $h, $crop, $aspect);
                         if ($imageURL) {
                             if ($imageURL == $imageSource) {
                                 $width = $w ? "width=\"{$w}\"" : "";
                                 $height = $h ? "height=\"{$h}\"" : "";
                                 $item->image = "<img src=\"{$imageURL}\" alt=\"{$item->text}\" title=\"{$item->text}\" {$width} {$height} />";
                             } else {
                                 $item->image = "<img src=\"{$imageURL}\" alt=\"{$item->text}\" title=\"{$item->text}\" />";
                             }
                         } else {
                             $item->image = '';
                         }
                     } else {
                         $width = $w ? "width=\"{$w}\"" : "";
                         $height = $h ? "height=\"{$h}\"" : "";
                         $item->image = "<img src=\"{$imageSource}\" alt=\"{$item->text}\" title=\"{$item->text}\" {$width} {$height} />";
                     }
                 }
             }
             $item->creater = isset($item->author) ? $item->author : $item->created_by_alias;
             if ($showHits) {
                 $item->hits = isset($item->hits) ? $item->hits : 0;
             } else {
                 $item->hits = null;
             }
         }
     }
     return $items;
 }
Exemplo n.º 3
0
 /**
  *
  * Resize image in content
  * @param object $row
  * @param string $align
  * @param int $autoresize
  * @param int $maxchars
  * @param int $showimage
  * @param int $width
  * @param int $height
  * @param int $hiddenClasses
  * @return string new image
  */
 function replaceImage($row, $width = 0, $height = 0)
 {
     $regex = '#<\\s*img [^\\>]*src\\s*=\\s*(["\'])(.*?)\\1#im';
     if (!isset($row->introtext)) {
         $row->introtext = "";
     }
     if (!isset($row->text)) {
         $row->text = "";
     }
     //check to see if there is an  intro image or fulltext image  first
     $images = "";
     if (isset($row->images)) {
         $images = json_decode($row->images);
     }
     if ((isset($images->image_fulltext) and !empty($images->image_fulltext)) || (isset($images->image_intro) and !empty($images->image_intro))) {
         $image = (isset($images->image_intro) and !empty($images->image_intro)) ? $images->image_intro : ((isset($images->image_fulltext) and !empty($images->image_fulltext)) ? $images->image_fulltext : "");
     } else {
         preg_match($regex, $row->introtext, $matches);
         if (!count($matches)) {
             preg_match($regex, $row->fulltext, $matches);
         }
         $images = count($matches) ? $matches : array();
         $image = '';
         if (count($images)) {
             $image = trim($images[2]);
         }
     }
     if ($image) {
         $width = $this->_params->get('width', '100');
         $height = $this->_params->get('height', '100');
         $thumbnailMode = $this->_params->get('thumbnail_mode', 'crop');
         $class = 'jaimage';
         if ($width > 0 && $height > 0) {
             $aspect = $this->get('use_ratio', '1');
             $crop = $thumbnailMode == 'crop' ? true : false;
             $jaimage = JAImage::getInstance();
             if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
                 $imageURL = $jaimage->resize($image, $width, $height, $crop, $aspect);
                 $image = $imageURL ? "<img class=\"{$class}\" src=\"" . $imageURL . "\" alt=\"{$row->title}\"  />" : "";
             } else {
                 $width = $width ? "width=\"{$width}\"" : "";
                 $height = $height ? "height=\"{$height}\"" : "";
                 $image = "<img class=\"{$class}\" src=\"" . JURI::root() . $image . "\" alt=\"{$row->title}\" {$width} {$height} />";
             }
         } else {
             $image = "<img class=\"{$class}\" src=\"" . JURI::root() . $image . "\" alt=\"{$row->title}\" />";
         }
     } else {
         $class = 'jaimage';
         $image = '<img class="' . $class . ' blank" src="' . JURI::root() . 'modules/mod_jacontentpopup/assets/img/blank.gif" />';
     }
     // clean up globals
     return $image;
 }
Exemplo n.º 4
0
 /**
  * render image from image source.
  */
 function renderImage($title, $image, $params, $width = 0, $height = 0, $attrs = '', $returnURL = false)
 {
     global $database, $_MAMBOTS, $current_charset;
     if ($image) {
         $title = strip_tags($title);
         $thumbnailMode = $params->get('source-articles-images-thumbnail_mode', 'crop');
         $aspect = $params->get('source-articles-images-thumbnail_mode-resize-use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $jaimage = JAImage::getInstance();
         if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
             $imageURL = $jaimage->resize($image, $width, $height, $crop, $aspect);
             if ($returnURL) {
                 return JURI::base() . $imageURL;
             }
             if ($imageURL == $image) {
                 $width = $width ? "width=\"{$width}\"" : "";
                 $height = $height ? "height=\"{$height}\"" : "";
                 $image = "<img src=\"" . JURI::base() . "{$imageURL}\"   alt=\"{$title}\" title=\"{$title}\" {$width} {$height} {$attrs} />";
             } else {
                 $image = "<img src=\"" . JURI::base() . "{$imageURL}\"  {$attrs}  alt=\"{$title}\" title=\"{$title}\" />";
             }
         } else {
             if ($returnURL) {
                 return JURI::base() . $image;
             }
             $width = $width ? "width=\"{$width}\"" : "";
             $height = $height ? "height=\"{$height}\"" : "";
             $image = "<img {$attrs} src=\"{$image}\" alt=\"{$title}\" title=\"{$title}\" {$width} {$height} />";
         }
     } else {
         $image = '';
     }
     // clean up globals
     return $image;
 }
Exemplo n.º 5
0
 /**
  *
  * Get Articles of K2
  * @param array $catids categories of K2
  * @param object $helper
  * @param object $params
  * @return object
  */
 function getArticles($catids, &$helper, $params)
 {
     jimport('joomla.filesystem.file');
     $limit = (int) $params->get('introitems', $helper->get('introitems')) + (int) $params->get('linkitems', $helper->get('linkitems'));
     if (!$limit) {
         $limit = 4;
     }
     $ordering = $helper->get('ordering', '');
     //get params of K2 component
     $componentParams = JComponentHelper::getParams('com_k2');
     $limitstart = 0;
     $user = JFactory::getUser();
     $aid = $user->get('aid') ? $user->get('aid') : 1;
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     //$now 				= $jnow->toMySQL();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $now = $jnow->toSql();
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $now = $jnow->toMySQL();
         } else {
             $now = $jnow->toMySQL();
         }
     }
     $nullDate = $db->getNullDate();
     $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.name as cattitle, c.params AS categoryparams";
     $query .= "\n FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
     $query .= "\n WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
     $query .= "\n AND i.catid IN ({$catids})";
     $query .= "\n AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
     $query .= "\n AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
     if ($helper->get('featured') == 'hide') {
         $query .= "\n AND i.featured = 0";
     }
     if ($helper->get('featured') == 'only') {
         $query .= "\n AND i.featured = 1";
     }
     if ($helper->get('timerange') > 0) {
         $datenow = JFactory::getDate();
         //$date 		= $datenow->toMySQL();
         if (version_compare(JVERSION, '3.0', 'ge')) {
             $date = $datenow->toSql();
         } else {
             if (version_compare(JVERSION, '2.5', 'ge')) {
                 $date = $datenow->toMySQL();
             } else {
                 $date = $datenow->toMySQL();
             }
         }
         $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $helper->get('timerange') . " DAY) ";
     }
     $sort_order = $helper->get('sort_order', 'DESC');
     switch ($ordering) {
         case 'ordering':
             $ordering = 'ordering ' . $sort_order;
             break;
         case 'rand':
             $ordering = 'RAND()';
             break;
         case 'hits':
             $ordering = 'hits ' . $sort_order;
             break;
         case 'created':
             $ordering = 'created ' . $sort_order;
             break;
         case 'modified':
             $ordering = 'modified ' . $sort_order;
             break;
         case 'title':
             $ordering = 'title ' . $sort_order;
             break;
     }
     if ($ordering == 'RAND()') {
         $query .= "\n ORDER BY " . $ordering;
     } else {
         $query .= "\n ORDER BY i." . $ordering;
     }
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $autoresize = intval(trim($helper->get('autoresize', 0)));
     $width_img = (int) $helper->get('width', 100) < 0 ? 100 : $helper->get('width', 100);
     $height_img = (int) $helper->get('height', 100) < 0 ? 100 : $helper->get('height', 100);
     $img_w = intval(trim($width_img));
     $img_h = intval(trim($height_img));
     //$img_w 				= intval(trim($helper->get('width', 100)));
     //$img_h 				= intval(trim($helper->get('height', 100)));
     $img_align = $helper->get('align', 'left');
     $showimage = $params->get('showimage', $helper->get('showimage', 0));
     $maxchars = intval(trim($helper->get('maxchars', 200)));
     $hiddenClasses = trim($helper->get('hiddenClasses', ''));
     $showdate = $helper->get('showdate', 0);
     $enabletimestamp = $helper->get('timestamp', 0);
     if (count($rows)) {
         foreach ($rows as $j => $row) {
             $row->introtext1 = "";
             $row->cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->categoryid . ':' . urlencode($row->categoryalias))));
             //Clean title
             $row->title = JFilterOutput::ampReplace($row->title);
             //Images
             $image = '';
             if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XL.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XS.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_L.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_S.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_M.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_Generic.jpg';
             }
             if ($image != '') {
                 $thumbnailMode = $helper->get('thumbnail_mode', 'crop');
                 $aspect = $helper->get('use_ratio', '1');
                 $crop = $thumbnailMode == 'crop' ? true : false;
                 $align = $img_align ? "align=\"{$img_align}\"" : "";
                 $jaimage = JAImage::getInstance();
                 if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
                     $imageURL = $jaimage->resize($image, $img_w, $img_h, $crop, $aspect);
                     $imageURL = str_replace(JURI::base(), '', $imageURL);
                     $imageURL = JURI::base() . $imageURL;
                     $row->image = $imageURL ? "<img class=\"{$img_align}\" src=\"" . $imageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
                 } else {
                     $width = $img_w ? "width=\"{$img_w}\"" : "";
                     $height = $img_h ? "height=\"{$img_h}\"" : "";
                     $imageURL = str_replace(JURI::base(), '', $imageURL);
                     $imageURL = JURI::base() . $imageURL;
                     $row->image = "<img class=\"{$img_align}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$img_w} {$img_h} {$align} />";
                 }
                 if ($maxchars && strlen($row->introtext) > $maxchars) {
                     $doc = JDocument::getInstance();
                     if (function_exists('mb_substr')) {
                         $row->introtext1 = SmartTrim::mb_trim($row->introtext, 0, $maxchars, $doc->_charset);
                     } else {
                         $row->introtext1 = SmartTrim::trim($row->introtext, 0, $maxchars);
                     }
                 } elseif ($maxchars == 0) {
                     $row->introtext1 = '';
                 }
                 $helper->replaceImage($row, $img_align, $autoresize, $maxchars, $showimage, $img_w, $img_h, $hiddenClasses);
             } else {
                 $row->image = $helper->replaceImage($row, $img_align, $autoresize, $maxchars, $showimage, $img_w, $img_h, $hiddenClasses);
                 if ($maxchars == 0) {
                     $row->introtext1 = '';
                 }
             }
             // Introtext
             $row->text = $row->introtext;
             //Read more link
             $row->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->id . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->categoryalias))));
             $helper->_params->set('parsedInModule', 1);
             $dispatcher = JDispatcher::getInstance();
             if ($helper->get('JPlugins', 1)) {
                 //Plugins
                 $results = $dispatcher->trigger('onBeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onPrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Init K2 plugin events
             $row->event->K2BeforeDisplay = '';
             $row->event->K2AfterDisplay = '';
             $row->event->K2AfterDisplayTitle = '';
             $row->event->K2BeforeDisplayContent = '';
             $row->event->K2AfterDisplayContent = '';
             $row->event->K2CommentsCounter = '';
             //K2 plugins
             if ($helper->get('K2Plugins', 1)) {
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onK2PrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Clean the plugin tags
             $row->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $row->introtext);
             $row->introtext = '<p>' . $row->introtext . '</p>';
             //Author
             if ($helper->get('showcreator')) {
                 if (!empty($row->created_by_alias)) {
                     $row->author = $row->created_by_alias;
                     $row->authorGender = NULL;
                 } else {
                     $author = JFactory::getUser($row->created_by);
                     $row->author = $author->name;
                     $query = "SELECT `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                     $db->setQuery($query, 0, 1);
                     $row->authorGender = $db->loadResult();
                     //Author Link
                     $row->authorLink = JRoute::_(K2HelperRoute::getUserRoute($row->created_by));
                 }
             }
             $row->created = $row->modified != '' && $row->modified != '0000-00-00 00:00:00' ? $row->modified : $row->created;
             if ($enabletimestamp) {
                 $row->created = $helper->generatTimeStamp($row->created);
             } else {
                 $row->created = JHTML::_('date', $row->created);
             }
             $rows[$j] = $row;
         }
     }
     return $rows;
 }
Exemplo n.º 6
0
 /**
  *
  * Resize image in content
  * @param object $row
  * @param string $align
  * @param int $autoresize
  * @param int $maxchars
  * @param int $showimage
  * @param int $width
  * @param int $height
  * @param int $hiddenClasses
  * @return string new image
  */
 function replaceImage(&$row, $align, $autoresize, $maxchars, $showimage, $width = 0, $height = 0, $hiddenClasses = '')
 {
     $image = '';
     $jaImage = new JAImage();
     $image = $jaImage->parseImage($row);
     $class = $align;
     $align = $align ? "align=\"{$align}\"" : "";
     if ($image && $showimage) {
         $thumbnailMode = $this->get('thumbnail_mode', 'crop');
         $aspect = $this->get('use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $jaimage = JAImage::getInstance();
         if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
             $imageURL = $jaimage->resize($image, $width, $height, $crop, $aspect);
             $image = $imageURL ? "<img class=\"{$class}\" src=\"" . $imageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
         } else {
             $width = $width ? "width=\"{$width}\"" : "";
             $height = $height ? "height=\"{$height}\"" : "";
             $image = "<img class=\"{$class}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$width} {$height} {$align} />";
         }
     } else {
         $image = '';
     }
     $regex1 = "/\\<img[^\\>]*>/";
     $row->introtext = preg_replace($regex1, '', $row->introtext);
     $regex1 = "/<div class=\"mosimage\".*<\\/div>/";
     $row->introtext = preg_replace($regex1, '', $row->introtext);
     $row->introtext = trim($row->introtext);
     $row->introtext1 = $row->introtext;
     if ($maxchars && strlen($row->introtext) > $maxchars) {
         $doc = JDocument::getInstance();
         if (function_exists('mb_substr')) {
             $row->introtext1 = SmartTrim::mb_trim($row->introtext, 0, $maxchars, $doc->_charset);
         } else {
             $row->introtext1 = SmartTrim::trim($row->introtext, 0, $maxchars);
         }
     }
     // clean up globals
     return $image;
 }
Exemplo n.º 7
0
 /**
  *
  * Render image from article
  * @param object $row
  * @param object $params
  * @param int $maxchars
  * @param int $width
  * @param int $height
  * @return string image
  */
 function renderImage(&$row, $params, $maxchars, $width = 0, $height = 0)
 {
     global $database, $_MAMBOTS, $current_charset;
     $image = "";
     $align = ($tmp = $params->get("image_alignment", "left")) != "auto" ? 'align="' . $tmp . '"' : "";
     $source = $params->get('using_mode', 'content');
     $image = $this->parseImage($row, $source);
     if ($image) {
         $thumbnailMode = $params->get('thumbnail_mode', 'crop');
         $aspect = $params->get('thumbnail_mode-resize-use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $jaimage = JAImage::getInstance();
         if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
             $imageURL = $jaimage->resize($image, $width, $height, $crop, $aspect);
             if ($imageURL == $image) {
                 $width = $width ? "width=\"{$width}\"" : "";
                 $height = $height ? "height=\"{$height}\"" : "";
                 $image = "<img src=\"{$imageURL}\" {$align}  alt=\"{$row->title}\" title=\"{$row->title}\" {$width} {$height} />";
             } else {
                 $image = "<img src=\"{$imageURL}\"  {$align}  alt=\"{$row->title}\" title=\"{$row->title}\" />";
             }
         } else {
             $width = $width ? "width=\"{$width}\"" : "";
             $height = $height ? "height=\"{$height}\"" : "";
             $image = "<img src=\"{$image}\" alt=\"{$row->title}\" {$align}  title=\"{$row->title}\" {$width} {$height} />";
         }
     } else {
         $image = '';
     }
     $regex1 = "/\\<img.*\\/\\>/";
     $row->introtext = preg_replace($regex1, '', $row->introtext);
     $row->introtext = trim($row->introtext);
     // clean up globals
     return $image;
 }
Exemplo n.º 8
0
 /**
  *
  * Get Articles of K2
  * @param object $helper
  * @param object $params
  * @return object
  */
 function getArticles(&$helper, $params)
 {
     if (!file_exists(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php')) {
         return;
     }
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php';
     $helper->set('getChildren', $params->get('getChildren', 1));
     $catsid = $params->get('k2catsid');
     $catids = array();
     if (!is_array($catsid)) {
         $catids[] = $catsid;
     } else {
         $catids = $catsid;
     }
     JArrayHelper::toInteger($catids);
     if ($catids) {
         if ($catids && count($catids) > 0) {
             foreach ($catids as $k => $catid) {
                 if (!$catid) {
                     unset($catids[$k]);
                 }
             }
         }
     }
     jimport('joomla.filesystem.file');
     $limit = (int) $helper->get('limit', 10);
     if (!$limit) {
         $limit = 4;
     }
     $limitstart = (int) $helper->get('limitstart', 0);
     $ordering = $helper->get('ordering', '');
     $sort_order = $helper->get('sort_order', 'DESC');
     $componentParams =& JComponentHelper::getParams('com_k2');
     $user = JFactory::getUser();
     $aid = $user->get('aid') ? $user->get('aid') : 1;
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     //$now = $jnow->toMySQL();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $now = $jnow->toSql();
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $now = $jnow->toMySQL();
         } else {
             $now = $jnow->toMySQL();
         }
     }
     $nullDate = $db->getNullDate();
     $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.name as cattitle, c.params AS categoryparams";
     $query .= "\n FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
     $query .= "\n WHERE i.published = 1 AND i.featured=1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
     $query .= "\n AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
     $query .= "\n AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
     switch ($params->get('featured')) {
         case 'hide':
             $query = str_replace("AND i.featured=1", "AND i.featured=0", $query);
             break;
         case 'show':
             $query = str_replace("AND i.featured=1", " ", $query);
             break;
     }
     if ($catids) {
         $catids_new = $catids;
         if ($params->get('getChildren', 1)) {
             foreach ($catids as $k => $catid) {
                 $subcatids = JAK2HelperFP::getK2CategoryChildren($catid, true);
                 if ($subcatids) {
                     $catids_new = array_merge($catids_new, array_diff($subcatids, $catids_new));
                 }
             }
         }
         $catids = implode(',', $catids_new);
         $query .= "\n AND i.catid IN ({$catids})";
     }
     switch ($ordering) {
         case 'ordering':
             $ordering = 'featured_ordering';
             break;
         case 'rorder':
             $ordering = 'featured_ordering DESC';
             break;
         case 'rand':
             $ordering = 'RAND()';
             break;
     }
     if ($ordering == 'RAND()') {
         $query .= "\n ORDER BY " . $ordering . ' ' . $sort_order;
     } else {
         $query .= "\n ORDER BY i." . $ordering . ' ' . $sort_order . ", i.id desc";
     }
     $db->setQuery($query, $limitstart, $limit);
     $rows = $db->loadObjectList();
     $autoresize = intval(trim($helper->get('autoresize', 1)));
     $img_align = trim($helper->get('align', 'left'));
     $hiddenClasses = trim($helper->get('hiddenClasses', ''));
     $bigmaxchar = $helper->get('bigmaxchars', 200);
     $bigimg_w = (int) $helper->get('bigimg_w', 150) < 0 ? 150 : $helper->get('bigimg_w', 150);
     $bigimg_h = (int) $helper->get('bigimg_h', 100) < 0 ? 100 : $helper->get('bigimg_h', 100);
     $bigshowimage = $helper->get('bigshowimage', 1);
     $smallmaxchar = $helper->get('smallmaxchars', 100);
     $smallimg_w = (int) $helper->get('smallimg_w', 80) < 0 ? 80 : $helper->get('smallimg_w', 80);
     $smallimg_h = (int) $helper->get('smallimg_h', 80) < 0 ? 80 : $helper->get('smallimg_h', 80);
     $smallshowimage = $helper->get('smallshowimage', 1);
     if (count($rows)) {
         foreach ($rows as $j => $row) {
             //Clean title
             $row->title = JFilterOutput::ampReplace($row->title);
             $row->bigintrotext = $row->introtext;
             $row->smallintrotext = $row->introtext;
             // Introtext
             $row->text = $row->introtext;
             //Read more link
             $row->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->id . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->categoryalias))));
             $helper->_params->set('parsedInModule', 1);
             $dispatcher =& JDispatcher::getInstance();
             if ($helper->get('JPlugins', 1)) {
                 //Plugins
                 $results = $dispatcher->trigger('onBeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onPrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Init K2 plugin events
             $row->event->K2BeforeDisplay = '';
             $row->event->K2AfterDisplay = '';
             $row->event->K2AfterDisplayTitle = '';
             $row->event->K2BeforeDisplayContent = '';
             $row->event->K2AfterDisplayContent = '';
             $row->event->K2CommentsCounter = '';
             //K2 plugins
             if ($helper->get('K2Plugins', 1)) {
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onK2PrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Clean the plugin tags
             $row->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $row->introtext);
             //Images
             $image = '';
             if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XL.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XS.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_L.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_S.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_M.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_Generic.jpg';
             }
             if ($image != '') {
                 $thumbnailMode = $helper->get('thumbnail_mode', 'crop');
                 $aspect = $helper->get('use_ratio', '1');
                 $crop = $thumbnailMode == 'crop' ? true : false;
                 $align = $img_align ? "align=\"{$img_align}\"" : "";
                 $jaimage = JAImage::getInstance();
                 if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
                     $smallimageURL = $jaimage->resize($image, $smallimg_w, $smallimg_h, $crop, $aspect);
                     $row->smallimage = $smallimageURL ? "<img src=\"" . $smallimageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
                     $bigimageURL = $jaimage->resize($image, $bigimg_w, $bigimg_h, $crop, $aspect);
                     $row->bigimage = $bigimageURL ? "<img src=\"" . $bigimageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
                 } else {
                     $width = $bigimg_w ? "width=\"{$bigimg_w}\"" : "";
                     $height = $bigimg_h ? "height=\"{$bigimg_h}\"" : "";
                     $row->bigimage = "<img class=\"{$img_align}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$width} {$height} {$align} />";
                     $width = $smallimg_w ? "width=\"{$smallimg_w}\"" : "";
                     $height = $smallimg_h ? "height=\"{$smallimg_h}\"" : "";
                     $row->smallimage = "<img class=\"{$img_align}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$width} {$height} {$align} />";
                 }
                 $regex = "/\\<img[^\\>]*>/";
                 $row->introtext = preg_replace($regex, '', $row->introtext);
                 if ($bigmaxchar && strlen($row->introtext) > $bigmaxchar) {
                     $doc = JDocument::getInstance();
                     if (function_exists('mb_substr')) {
                         $row->bigintrotext = SmartTrim::mb_trim($row->introtext, 0, $bigmaxchar, $doc->_charset);
                     } else {
                         $row->bigintrotext = SmartTrim::trim($row->introtext, 0, $bigmaxchar);
                     }
                 } elseif ($bigmaxchar == 0) {
                     $row->bigintrotext = '';
                 }
                 if ($smallmaxchar && strlen($row->introtext) > $smallmaxchar) {
                     $doc = JDocument::getInstance();
                     if (function_exists('mb_substr')) {
                         $row->smallintrotext = SmartTrim::mb_trim($row->introtext, 0, $smallmaxchar, $doc->_charset);
                     } else {
                         $row->smallintrotext = SmartTrim::trim($row->introtext, 0, $smallmaxchar);
                     }
                 } elseif ($smallmaxchar == 0) {
                     $row->smallintrotext = '';
                 }
             } else {
                 $introtext = $row->introtext;
                 $row->bigimage = $helper->replaceImage($row, $img_align, $autoresize, $bigmaxchar, $bigshowimage, $bigimg_w, $bigimg_h, $hiddenClasses);
                 $row->bigintrotext = $row->introtext1;
                 if ($bigmaxchar == 0) {
                     $row->bigintrotext = '';
                 }
                 $row->introtext = $introtext;
                 $row->smallimage = $helper->replaceImage($row, $img_align, $autoresize, $smallmaxchar, $smallshowimage, $smallimg_w, $smallimg_h, $hiddenClasses);
                 $row->smallintrotext = $row->introtext1;
                 if ($smallmaxchar == 0) {
                     $row->smallintrotext = '';
                 }
             }
             $row->introtext = '<p>' . $row->introtext . '</p>';
             $row->bigintrotext = '<p>' . $row->bigintrotext . '</p>';
             $row->smallintrotext = '<p>' . $row->smallintrotext . '</p>';
             //Author
             if ($helper->get('showcreator')) {
                 if (!empty($row->created_by_alias)) {
                     $row->creator = $row->created_by_alias;
                     $row->authorGender = NULL;
                 } else {
                     $author =& JFactory::getUser($row->created_by);
                     $row->creator = $author->name;
                     $query = "SELECT `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                     $db->setQuery($query, 0, 1);
                     $row->authorGender = $db->loadResult();
                     //Author Link
                     $row->authorLink = JRoute::_(K2HelperRoute::getUserRoute($row->created_by));
                 }
             }
             $rows[$j] = $row;
         }
     }
     return $rows;
 }
Exemplo n.º 9
0
 /**
  *
  * Resize image in content
  * @param object $row
  * @param string $align
  * @param int $autoresize
  * @param int $maxchars
  * @param int $showimage
  * @param int $width
  * @param int $height
  * @param int $hiddenClasses
  * @return string new image
  */
 function replaceImage(&$row, $align, $autoresize, $maxchars, $showimage, $width = 0, $height = 0, $hiddenClasses = '')
 {
     $regex = '#<\\s*img [^\\>]*src\\s*=\\s*(["\'])(.*?)\\1#im';
     if (!isset($row->introtext)) {
         $row->introtext = "";
     }
     if (!isset($row->text)) {
         $row->text = "";
     }
     //check to see if there is an  intro image or fulltext image  first
     $images = "";
     if (isset($row->images)) {
         $images = json_decode($row->images);
     }
     if ((isset($images->image_fulltext) and !empty($images->image_fulltext)) || (isset($images->image_intro) and !empty($images->image_intro))) {
         $image = (isset($images->image_intro) and !empty($images->image_intro)) ? $images->image_intro : ((isset($images->image_fulltext) and !empty($images->image_fulltext)) ? $images->image_fulltext : "");
     } else {
         preg_match($regex, $row->introtext, $matches);
         if (!count($matches)) {
             preg_match($regex, $row->fulltext, $matches);
         }
         $images = count($matches) ? $matches : array();
         $image = '';
         if (count($images)) {
             $image = trim($images[2]);
         }
     }
     $class = $align;
     $align = $align ? "align=\"{$align}\"" : "";
     if ($image && $showimage) {
         $thumbnailMode = $this->get('thumbnail_mode', 'crop');
         $aspect = $this->get('use_ratio', '1');
         $crop = $thumbnailMode == 'crop' ? true : false;
         $jaimage = JAImage::getInstance();
         if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
             $imageURL = $jaimage->resize($image, $width, $height, $crop, $aspect);
             $imageURL = str_replace(JURI::base(), '', $imageURL);
             $image = $imageURL ? "<img class=\"{$class}\" src=\"" . $imageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
         } else {
             $width = $width ? "width=\"{$width}\"" : "";
             $height = $height ? "height=\"{$height}\"" : "";
             $image = str_replace(JURI::base(), '', $image);
             $image = JURI::base() . $image;
             $image = "<img class=\"{$class}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$width} {$height} {$align} />";
         }
     } else {
         $image = '';
     }
     $regex1 = "/\\<img[^\\>]*>/";
     $row->introtext = preg_replace($regex1, '', $row->introtext);
     $regex1 = "/<div class=\"mosimage\".*<\\/div>/";
     $row->introtext = preg_replace($regex1, '', $row->introtext);
     $row->introtext = trim($row->introtext);
     $row->introtext1 = $row->introtext;
     if ($maxchars && strlen($row->introtext) > $maxchars) {
         $doc = JDocument::getInstance();
         if (function_exists('mb_substr')) {
             $row->introtext1 = SmartTrim::mb_trim($row->introtext, 0, $maxchars, $doc->_charset);
         } else {
             $row->introtext1 = SmartTrim::trim($row->introtext, 0, $maxchars);
         }
     }
     // clean up globals
     return $image;
 }