/** * * 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; }
/** * * convert array to string * @param array $arr * @param int $len * @return string */ public static function toString($arr, $len) { $i = 0; $stack = new JAStack(); $length = 0; while ($i < count($arr)) { /*$tag = trim ( $arr [$i ++] );*/ $tag = $arr[$i++]; if ($tag == '') { continue; } if (SmartTrim::isCloseTag($tag)) { if ($ltag = $stack->getLast()) { if ('</' . SmartTrim::getTag($ltag) . '>' == $tag) { $stack->pop(); } else { $stack->push($tag); } } } else { if (SmartTrim::isOpenTag($tag)) { $stack->push($tag); } else { if (SmartTrim::isFullTag($tag)) { //echo "[TAG: $tag, $length, $len]\n"; if ($length < $len) { $stack->push($tag); } } else { $length += strlen($tag); $stack->push($tag); } } } } return $stack->toString(); }
?> </h2> <p> <?php if (!$javconfig['plugin']->get('enable_bbcode', 1)) { $item->content = str_replace("\n", '<br/>', $item->content); } $maxchars = $javconfig['systems']->get('maxchars', 100); if ($maxchars == -1) { echo $item->content; } elseif ($maxchars > 0) { if (function_exists('mb_substr')) { $doc = JDocument::getInstance(); echo SmartTrim::mb_trim($item->content, 0, $javconfig['systems']->get('maxchars', 100), $doc->_charset); } else { echo SmartTrim::trim($item->content, 0, $javconfig['systems']->get('maxchars', 100)); } } // echo $item->content; ?> </p> </div> </div> </li> <?php } ?> </ol> <?php } else {
$item = $admin_response[$i]; JFilterOutput::objectHtmlSafe($item); ?> <li style="line-height: 20px;"><a href="index.php?option=com_javoice&view=items&voicetypes=<?php echo $item->voice_types_id; ?> &search=<?php echo $item->item_id; ?> "> <?php if (function_exists('mb_substr')) { $doc = JDocument::getInstance(); echo SmartTrim::mb_trim($item->item_title, 0, 50, $doc->_charset); } else { echo SmartTrim::mb($item->item_title, 0, 50); } ?> </a> <?php } ?> </ol> </div> <?php } else { ?> <div style="min-height: 250px;"> <?php echo JText::_('HAVE_NO_RESULT');
/** * * 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; }
/** * trim string with max specify * * @param string $title * @param integer $max. */ function trimString($title, $maxchars = 60, $includeTags = NULL) { if (!empty($includeTags)) { $title = $this->trimIncludeTags($title, $this->buildStrTags($includeTags)); } if (function_exists('mb_substr')) { $doc = JDocument::getInstance(); return SmartTrim::mb_trim($title, 0, $maxchars, $doc->_charset); } else { return SmartTrim::trim($title, 0, $maxchars); } }
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', ''); $componentParams =& JComponentHelper::getParams('com_flexicontent'); $limitstart = 0; $user =& JFactory::getUser(); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $query = 'SELECT i.*, u.name as creator,cc.description as catdesc, cc.title as cattitle,s.description as secdesc, s.title as sectitle,' . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(":", i.id, i.alias) ELSE i.id END as slug,' . ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as secslug' . ' FROM #__content AS i' . ' INNER JOIN #__categories AS cc ON cc.id = i.catid' . ' INNER JOIN #__sections AS s ON s.id = i.sectionid' . ' LEFT JOIN #__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . ' LEFT JOIN #__groups AS g ON g.id = i.access' . ' LEFT JOIN #__users AS u ON u.id = i.created_by'; $query .= ' WHERE i.state != -1' . ' AND i.state != -2' . ' AND i.sectionid = ' . FLEXI_SECTION . ' AND (i.publish_up = ' . $db->Quote($nullDate) . ' OR i.publish_up <= ' . $db->Quote($now) . ' ) ' . ' AND (i.publish_down = ' . $db->Quote($nullDate) . ' OR i.publish_down >= ' . $db->Quote($now) . ' )' . "\n AND rel.catid in ({$catids})"; $ordering = $helper->get('ordering', 'ordering'); if ($helper->get('showcontentfrontpage') == '0') { $query .= ' AND i.id not in (SELECT content_id FROM #__content_frontpage )'; } else { if ($helper->get('showcontentfrontpage') == '2') { $query .= ' AND i.id in (SELECT content_id FROM #__content_frontpage )'; } } if ($ordering == 'rand') { $query .= "\n ORDER BY RAND()"; } else { $query .= "\n ORDER BY i." . $ordering; } $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $autoresize = intval(trim($helper->get('autoresize', 0))); $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 ($helper->get('JPlugins', 1)) { JPluginHelper::importPlugin('content'); $dispatcher =& JDispatcher::getInstance(); } if (count($rows)) { foreach ($rows as $j => $row) { //Clean title $row->title = JFilterOutput::ampReplace($row->title); $row->image = $helper->replaceImage($row, $img_align, $autoresize, $maxchars, $showimage, $img_w, $img_h, $hiddenClasses); $row->text = $row->introtext; $row->link = urldecode(JRoute::_(FlexicontentHelperRoute::getItemRoute($row->id, $row->catid))); $row->cat_link = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($row->catid)); if ($enabletimestamp) { $row->created = $helper->generatTimeStamp($row->created); } else { $row->created = JHTML::_('date', $row->created); } $helper->_params->set('parsedInModule', 1); 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); } } if ($helper->get('JPlugins', 1)) { $row->event = new stdClass(); $results = $dispatcher->trigger('onPrepareContent', array(&$row, &$helper->_params, $limitstart)); $row->event->afterDisplayTitle = 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)); } // $row->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $row->introtext); $rows[$j] = $row; } } return $rows; }