function report($tpl = null) { JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $row =& JTable::getInstance('K2Comment', 'Table'); $row->load(JRequest::getInt('commentID')); if (!$row->published) { JError::raiseError(404, JText::_('K2_NOT_FOUND')); } $this->assignRef('row', $row); $user = JFactory::getUser(); $this->assignRef('user', $user); $params =& K2HelperUtilities::getParams('com_k2'); if (!$params->get('comments') || !$params->get('commentsReporting') || $params->get('commentsReporting') == '2' && $user->guest) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } $this->assignRef('params', $params); if ($params->get('recaptcha') && $user->guest) { $document = JFactory::getDocument(); $document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js'); $js = ' function showRecaptcha(){ Recaptcha.create("' . $params->get('recaptcha_public_key') . '", "recaptcha", { theme: "' . $params->get('recaptcha_theme', 'clean') . '" }); } $K2(window).load(function() { showRecaptcha(); }); '; $document->addScriptDeclaration($js); } parent::display($tpl); }
function getAvatar($userID, $email = NULL, $width = 50) { jimport('joomla.filesystem.folder'); jimport('joomla.application.component.model'); $mainframe =& JFactory::getApplication(); $params =& K2HelperUtilities::getParams('com_k2'); if (K2_CB && $userID != 'alias') { $cbUser = CBuser::getInstance((int) $userID); if (is_object($cbUser)) { $avatar = $cbUser->getField('avatar', null, 'csv', 'none', 'profile'); return $avatar; } } /* // JomSocial Avatar integration if(JFolder::exists(JPATH_SITE.DS.'components'.DS.'com_community') && $userID>0){ $userInfo = &CFactory::getUser($userID); return $userInfo->getThumbAvatar(); } */ // Check for placeholder overrides if (JFile::exists(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'images' . DS . 'placeholder' . DS . 'user.png')) { $avatarPath = 'templates/' . $mainframe->getTemplate() . '/images/placeholder/user.png'; } else { $avatarPath = 'components/com_k2/images/placeholder/user.png'; } // Continue with default K2 avatar determination if ($userID == 'alias') { $avatar = JURI::root(true) . '/' . $avatarPath; } else { if ($userID == 0) { if ($params->get('gravatar') && !is_null($email)) { $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath); } else { $avatar = JURI::root(true) . '/' . $avatarPath; } } else { if (is_numeric($userID) && $userID > 0) { JModel::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models'); $model =& JModel::getInstance('Item', 'K2Model'); $profile = $model->getUserProfile($userID); $avatar = is_null($profile) ? '' : $profile->image; if (empty($avatar)) { if ($params->get('gravatar') && !is_null($email)) { $avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath); } else { $avatar = JURI::root(true) . '/' . $avatarPath; } } else { $avatar = JURI::root(true) . '/media/k2/users/' . $avatar; } } } } if (!$params->get('userImageDefault') && $avatar == JURI::root(true) . '/' . $avatarPath) { $avatar = ''; } return $avatar; }
public static function loadjQuery($ui = false, $mediaManager = false) { JLoader::register('K2HelperUtilities', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php'); $application = JFactory::getApplication(); $document = JFactory::getDocument(); $params = K2HelperUtilities::getParams('com_k2'); if ($document->getType() == 'html') { if (K2_JVERSION == '15') { JHtml::_('behavior.mootools'); } else { if (K2_JVERSION == '25') { JHtml::_('behavior.framework'); } else { JHtml::_('behavior.framework'); if ($application->isAdmin() || $application->isSite() && $params->get('jQueryHandling')) { JHtml::_('jquery.framework'); } } } $handling = $application->isAdmin() ? $params->get('backendJQueryHandling', 'remote') : $params->get('jQueryHandling', '1.8remote'); // jQuery if (K2_JVERSION != '30') { if ($handling == 'remote') { $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'); } else { if ($handling == 'local') { $document->addScript(JURI::root(true) . '/media/k2/assets/js/jquery-1.8.3.min.js'); } else { if ($handling && JString::strpos($handling, 'remote') !== false) { if ($handling == '1.9remote') { $handling = '1remote'; } $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/' . str_replace('remote', '', $handling) . '/jquery.min.js'); } else { if ($handling && JString::strpos($handling, 'remote') === false) { $document->addScript(JURI::root(true) . '/media/k2/assets/js/jquery-' . $handling . '.min.js'); } } } } } // jQuery UI if ($application->isAdmin() || $ui) { // No conflict loaded when $ui requested or in the backend. // No need to reload for $mediaManager as the latter is always called with $ui $document->addScript(JURI::root(true) . '/media/k2/assets/js/k2.noconflict.js'); if ($handling == 'local') { $document->addScript(JURI::root(true) . '/media/k2/assets/js/jquery-ui-1.8.24.custom.min.js'); } else { $document->addScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js'); } } if ($mediaManager) { $document->addScript(JURI::root(true) . '/media/k2/assets/js/elfinder.min.js?v=2.6.7'); } } }
public static function getUserRoute($userID) { if (K2_CB) { global $_CB_framework; return $_CB_framework->userProfileUrl((int) $userID); } $key = (int) $userID; if (isset(self::$cache['user'][$key])) { return self::$cache['user'][$key]; } $needles = array('user' => (int) $userID); $user = JFactory::getUser($userID); if (K2_JVERSION != '15' && JFactory::getConfig()->get('unicodeslugs') == 1) { $alias = JApplication::stringURLSafe($user->name); } else { if (JPluginHelper::isEnabled('system', 'unicodeslug') || JPluginHelper::isEnabled('system', 'jw_unicodeSlugsExtended')) { $alias = JFilterOutput::stringURLSafe($user->name); } else { mb_internal_encoding("UTF-8"); mb_regex_encoding("UTF-8"); $alias = trim(mb_strtolower($user->name)); $alias = str_replace('-', ' ', $alias); $alias = mb_ereg_replace('[[:space:]]+', ' ', $alias); $alias = trim(str_replace(' ', '', $alias)); $alias = str_replace('.', '', $alias); $stripthese = ',|~|!|@|%|^|(|)|<|>|:|;|{|}|[|]|&|`|„|‹|’|‘|“|â€�|•|›|«|´|»|°|«|»|…'; $strips = explode('|', $stripthese); foreach ($strips as $strip) { $alias = str_replace($strip, '', $alias); } $params = K2HelperUtilities::getParams('com_k2'); $SEFReplacements = array(); $items = explode(',', $params->get('SEFReplacements', NULL)); foreach ($items as $item) { if (!empty($item)) { @(list($src, $dst) = explode('|', trim($item))); $SEFReplacements[trim($src)] = trim($dst); } } foreach ($SEFReplacements as $key => $value) { $alias = str_replace($key, $value, $alias); } $alias = trim($alias, '-.'); if (trim(str_replace('-', '', $alias)) == '') { $datenow = JFactory::getDate(); $alias = K2_JVERSION == '15' ? $datenow->toFormat("%Y-%m-%d-%H-%M-%S") : $datenow->format("Y-m-d-H-i-s"); } } } $link = 'index.php?option=com_k2&view=itemlist&task=user&id=' . $userID . ':' . $alias; if ($item = K2HelperRoute::_findItem($needles)) { $link .= '&Itemid=' . $item->id; } self::$cache['user'][$key] = $link; return $link; }
function getAuthors(&$params) { $componentParams =& JComponentHelper::getParams('com_k2'); $where = ''; $cid = $params->get('authors_module_category'); if ($cid > 0) { $categories = modK2ToolsHelper::getCategoryChildren($cid); $categories[] = $cid; JArrayHelper::toInteger($categories); $where = " catid IN(" . implode(',', $categories) . ") AND "; } $user =& JFactory::getUser(); $aid = (int) $user->get('aid'); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT created_by FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )"; $db->setQuery($query); $rows = $db->loadObjectList(); $authors = array(); if (count($rows)) { foreach ($rows as $row) { $author = JFactory::getUser($row->created_by); $author->link = JRoute::_(K2HelperRoute::getUserRoute($author->id)); $query = "SELECT id, gender, description, image, url, `group`, plugins FROM #__k2_users WHERE userID=" . (int) $author->id; $db->setQuery($query); $author->profile = $db->loadObject(); if ($params->get('authorAvatar')) { $author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth')); } $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i\n LEFT JOIN #__k2_categories c ON c.id = i.catid\n WHERE i.created_by = " . (int) $author->id . "\n AND i.published = 1\n AND i.access <= {$aid}\n AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n AND i.trash = 0 AND created_by_alias='' AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0 ORDER BY created DESC"; $db->setQuery($query, 0, 1); $author->latest = $db->loadObject(); $author->latest->id = (int) $author->latest->id; $author->latest->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($author->latest->id . ':' . urlencode($author->latest->alias), $author->latest->catid . ':' . urlencode($author->latest->categoryalias)))); $query = "SELECT COUNT(*) FROM #__k2_comments WHERE published=1 AND itemID={$author->latest->id}"; $db->setQuery($query); $author->latest->numOfComments = $db->loadResult(); if ($params->get('authorItemsCounter')) { $query = "SELECT COUNT(*) FROM #__k2_items WHERE {$where} published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND created_by={$row->created_by} AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )"; $db->setQuery($query); $numofitems = $db->loadResult(); $author->items = $numofitems; } $authors[] = $author; } } return $authors; }
public static function getLatestComments($params) { $model = K2Model::getInstance('Comments'); $model->setState('filter.items', true); $model->setState('state', 1); $filter = $params->get('category_id'); if ($filter && isset($filter->enabled) && $filter->enabled) { $model->setState('category', $filter->categories); } $model->setState('limit', (int) $params->get('comments_limit', '5')); $model->setState('sorting', 'id.reverse'); $comments = $model->getRows(); foreach ($comments as $comment) { if ((int) $params->get('comments_word_limit')) { $comment->text = K2HelperUtilities::wordLimit($comment->text, $params->get('comments_word_limit')); } $comment->user->displayName = $params->get('commenterName', 1) == 2 ? $comment->user->username : $comment->user->name; } return $comments; }
" title="<?php if (!empty($item->image_caption)) { echo K2HelperUtilities::cleanHtml($item->image_caption); } else { echo K2HelperUtilities::cleanHtml($item->title); } ?> "> <img src="<?php echo $item->imageGeneric; ?> " alt="<?php if (!empty($item->image_caption)) { echo K2HelperUtilities::cleanHtml($item->image_caption); } else { echo K2HelperUtilities::cleanHtml($item->title); } ?> " style="width:<?php echo $this->params->get('itemImageGeneric'); ?> px; height:auto;" /> </a> </span> <div class="clr"></div> </div> <?php } ?> <div class="clr"></div>
<?php /** * @version $Id: category_item.php 493 2010-06-17 14:58:58Z joomlaworks $ * @package K2 * @author JoomlaWorks http://www.joomlaworks.gr * @copyright Copyright (c) 2006 - 2010 JoomlaWorks, a business unit of Nuevvo Webware Ltd. All rights reserved. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html */ // no direct access defined('_JEXEC') or die('Restricted access'); // Define default image size (do not change) K2HelperUtilities::setDefaultImage($this->item, 'itemlist', $this->item->params); ?> <!-- Start K2 Item Layout --> <div class="catItemView group<?php echo ucfirst($this->item->itemGroup); echo $this->item->featured ? ' catItemIsFeatured' : ''; if ($this->item->params->get('pageclass_sfx')) { echo ' ' . $this->item->params->get('pageclass_sfx'); } ?> "> <!-- Plugins: BeforeDisplay --> <?php echo $this->item->event->BeforeDisplay; ?> <!-- K2 Plugins: K2BeforeDisplay -->
function display($tpl = null) { $mainframe =& JFactory::getApplication(); $user =& JFactory::getUser(); $document =& JFactory::getDocument(); $params =& JComponentHelper::getParams('com_k2'); $limitstart = JRequest::getInt('limitstart', 0); $view = JRequest::getWord('view'); $task = JRequest::getWord('task'); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $this->setLayout('item'); //Add link if (K2HelperPermissions::canAddItem()) { $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component'); } $this->assignRef('addLink', $addLink); //Get item $model =& $this->getModel(); $item = $model->getData(); //Prepare item if ($user->guest) { $cache =& JFactory::getCache('com_k2_extended'); $hits = $item->hits; $item->hits = 0; $item = $cache->call(array('K2ModelItem', 'prepareItem'), $item, $view, $task); $item->hits = $hits; } else { $item = $model->prepareItem($item, $view, $task); } //Plugins $item = $model->execPlugins($item, $view, $task); //Access check if ($this->getLayout() == 'form') { JError::raiseError(403, JText::_("ALERTNOTAUTH")); } if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) { JError::raiseError(403, JText::_("ALERTNOTAUTH")); } //Published check if (!$item->published || $item->trash) { JError::raiseError(404, JText::_("Item not found")); } if ($item->publish_up != $nullDate && $item->publish_up > $now) { JError::raiseError(404, JText::_("Item not found")); } if ($item->publish_down != $nullDate && $item->publish_down < $now) { JError::raiseError(404, JText::_("Item not found")); } if (!$item->category->published || $item->category->trash) { JError::raiseError(404, JText::_("Item not found")); } //Increase hits counter $model->hit($item->id); //Set default image K2HelperUtilities::setDefaultImage($item, $view); //Comments $item->event->K2CommentsCounter = ''; $item->event->K2CommentsBlock = ''; if ($item->params->get('itemComments')) { //Trigger comments events $dispatcher =& JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart)); $item->event->K2CommentsCounter = trim(implode("\n", $results)); $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart)); $item->event->K2CommentsBlock = trim(implode("\n", $results)); //Load K2 native comments system only if there are no plugins overriding it if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) { //Load reCAPTCHA script if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) { if ($item->params->get('recaptcha') && $user->guest) { $document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js'); $js = 'function showRecaptcha(){ Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", { theme: "' . $item->params->get('recaptcha_theme', 'clean') . '" }); } window.addEvent(\'load\', function(){ showRecaptcha(); })'; $document->addScriptDeclaration($js); } //Auto complete some fields for registered users if (!$user->guest) { $js = "window.addEvent('domready', function(){\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('value','" . $user->name . "');\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('disabled','disabled');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('value','" . $user->email . "');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('disabled','disabled');\n\n\t\t\t\t\t\t\t\t})"; $document->addScriptDeclaration($js); } } $limit = $params->get('commentsLimit'); $comments = $model->getItemComments($item->id, $limitstart, $limit); $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@"; for ($i = 0; $i < sizeof($comments); $i++) { $comments[$i]->commentText = nl2br($comments[$i]->commentText); $comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText); $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth')); if ($comments[$i]->userID > 0) { $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID); } else { $comments[$i]->userLink = $comments[$i]->commentURL; } } $item->comments = $comments; jimport('joomla.html.pagination'); $total = $item->numOfComments; $pagination = new JPagination($total, $limitstart, $limit); } } //Author's latest items if ($params->get('itemAuthorLatest') && $item->created_by_alias == '') { $model =& $this->getModel('itemlist'); $authorLatestItems = $model->getAuthorLatest($item->id, $params->get('itemAuthorLatestLimit'), $item->created_by); if (count($authorLatestItems)) { for ($i = 0; $i < sizeof($authorLatestItems); $i++) { $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias)))); } $this->assignRef('authorLatestItems', $authorLatestItems); } } //Related items if ($params->get('itemRelated') && isset($item->tags) && count($item->tags)) { $model =& $this->getModel('itemlist'); $relatedItems = $model->getRelatedItems($item->id, $item->tags, $params->get('itemRelatedLimit')); if (count($relatedItems)) { for ($i = 0; $i < sizeof($relatedItems); $i++) { $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias)))); } $this->assignRef('relatedItems', $relatedItems); } } //Navigation (previous and next item) if ($params->get('itemNavigation')) { $model =& $this->getModel('item'); $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering); if (!is_null($nextItem)) { $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias)))); $item->nextTitle = $nextItem->title; } $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering); if (!is_null($previousItem)) { $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias)))); $item->previousTitle = $previousItem->title; } } // Absolute URL $uri =& JURI::getInstance(); $item->absoluteURL = $uri->_uri; //Email link $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . base64_encode($item->absoluteURL)); //Twitter link if ($params->get('itemTwitterLink') && $params->get('twitterUsername')) { $itemURLForTwitter = $params->get('tinyURL') ? @file_get_contents('http://tinyurl.com/api-create.php?url=' . $item->absoluteURL) : $item->absoluteURL; $item->twitterURL = 'http://twitter.com/home/?status=' . urlencode('Reading @' . $params->get('twitterUsername') . ' ' . $item->title . ' ' . $itemURLForTwitter); } //Social link $item->socialLink = urlencode($item->absoluteURL); //Look for template files in component folders $this->_addPath('template', JPATH_COMPONENT . DS . 'templates'); $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default'); //Look for overrides in template folder (K2 template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default'); //Look for overrides in template folder (Joomla! template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2'); //Look for specific K2 theme files if ($item->params->get('theme')) { $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme')); } //Assign data $this->assignRef('item', $item); $this->assignRef('user', $user); $this->assignRef('params', $item->params); $this->assignRef('pagination', $pagination); parent::display($tpl); }
public static function getListItems($cid, &$params) { $mainframe = JFactory::getApplication(); $limit = $params->get('itemCount', 5); $ordering = $params->get('itemsOrdering', ''); $user = JFactory::getUser(); $aid = $user->get('aid'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams"; if ($ordering == 'best') { $query .= ", (r.rating_sum/r.rating_count) AS rating"; } if ($ordering == 'comments') { $query .= ", COUNT(comments.id) AS numOfComments"; } $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid"; if ($ordering == 'best') { $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id"; } if ($ordering == 'comments') { $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id"; } if (K2_JVERSION != '15') { $query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND c.trash = 0"; } else { $query .= " 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 .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )"; $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )"; if (!is_null($cid)) { if (is_array($cid)) { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { JArrayHelper::toInteger($cid); $query .= " AND i.catid IN(" . implode(',', $cid) . ")"; } } else { if ($params->get('getChildren')) { $itemListModel = K2Model::getInstance('Itemlist', 'K2Model'); $categories = $itemListModel->getCategoryTree($cid); $sql = @implode(',', $categories); $query .= " AND i.catid IN ({$sql})"; } else { $query .= " AND i.catid=" . (int) $cid; } } } if ($params->get('FeaturedItems') == '0') { $query .= " AND i.featured != 1"; } if ($params->get('FeaturedItems') == '2') { $query .= " AND i.featured = 1"; } if ($params->get('videosOnly')) { $query .= " AND (i.video IS NOT NULL AND i.video!='')"; } if ($ordering == 'comments') { $query .= " AND comments.published = 1"; } if (K2_JVERSION != '15') { if ($mainframe->getLanguageFilter()) { $languageTag = JFactory::getLanguage()->getTag(); $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")"; } } switch ($ordering) { case 'date': $orderby = 'i.created ASC'; break; case 'rdate': $orderby = 'i.created DESC'; break; case 'alpha': $orderby = 'i.title'; break; case 'ralpha': $orderby = 'i.title DESC'; break; case 'order': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering'; } else { $orderby = 'i.ordering'; } break; case 'rorder': if ($params->get('FeaturedItems') == '2') { $orderby = 'i.featured_ordering DESC'; } else { $orderby = 'i.ordering DESC'; } break; case 'hits': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $orderby = 'i.hits DESC'; break; case 'rand': $orderby = 'RAND()'; break; case 'best': $orderby = 'rating DESC'; break; case 'comments': if ($params->get('popularityRange')) { $datenow = JFactory::getDate(); $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) "; } $query .= " GROUP BY i.id "; $orderby = 'numOfComments DESC'; break; case 'modified': $orderby = 'lastChanged DESC'; break; case 'publishUp': $orderby = 'i.publish_up DESC'; break; default: $orderby = 'i.id DESC'; break; } $query .= " ORDER BY " . $orderby; $db->setQuery($query, 0, $limit); $items = $db->loadObjectList(); $model = K2Model::getInstance('Item', 'K2Model'); $show_introtext = $params->get('item_desc_display', 0); $introtext_limit = $params->get('item_desc_max_characs', 100); $show_title = $params->get('item_title_display', 1); $title_limit = $params->get('item_title_max_characs', 20); $item_title_ending_char = $params->get('item_title_ending_char', ''); $item_desc_ending_char = $params->get('item_desc_ending_char', ''); $show_other_title = $params->get('other_title_display', 1); $other_title_limit = $params->get('other_title_max_characs', 20); $other_item_title_ending_char = $params->get('other_item_title_ending_char', ''); if (count($items)) { foreach ($items as $item) { //Clean title $item->title = JFilterOutput::ampReplace($item->title); $item->displaytitle = $show_title ? self::truncate($item->title, $title_limit, $item_title_ending_char) : ''; //Read more link $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias)))); //Author if (!empty($item->created_by_alias)) { $item->author = $item->created_by_alias; $item->authorGender = NULL; $item->authorDescription = NULL; if ($params->get('itemAuthorAvatar')) { $item->authorAvatar = K2HelperUtilities::getAvatar('alias'); } $item->authorLink = Juri::root(true); } else { $author = JFactory::getUser($item->created_by); $item->author = $author->name; $query = "SELECT `description`, `gender` FROM #__k2_users WHERE userID=" . (int) $author->id; $db->setQuery($query, 0, 1); $result = $db->loadObject(); if ($result) { $item->authorGender = $result->gender; $item->authorDescription = $result->description; } else { $item->authorGender = NULL; $item->authorDescription = NULL; } if ($params->get('itemAuthorAvatar')) { $item->authorAvatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth')); } //Author Link $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by)); } //Tags $item->tags = ''; if ($params->get('item_tags_display')) { $tags = $model->getItemTags($item->id); for ($i = 0; $i < sizeof($tags); $i++) { $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)); } $item->tags = $tags; } // Restore the intotext variable after plugins execution self::getK2Images($item, $params); //Clean the plugin tags $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext); if ($item->fulltext != '') { $item->fulltext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->fulltext); $item->_introtext = self::_cleanText($item->introtext . $item->fulltext); } else { $item->_introtext = self::_cleanText($item->introtext); } $item->displayIntrotext = $show_introtext ? self::truncate($item->_introtext, $introtext_limit, $item_desc_ending_char) : ''; $item->othertitle = self::truncate($item->title, $other_title_limit, $other_item_title_ending_char); $rows[] = $item; } return $rows; } }
<?php echo JHTML::_('date', $this->item->created, JText::_('DATE_FORMAT_LC3')); ?> </span> <?php } ?> <?php if ($this->item->params->get('catItemAuthor')) { ?> <!-- Item Author --> <span class="createby"> <?php echo K2HelperUtilities::writtenBy($this->item->author->profile->gender); ?> <a href="<?php echo $this->item->author->link; ?> "><?php echo $this->item->author->name; ?> </a> </span> <?php } ?> </div> </div>
?> </h2> <?php } ?> <?php } ?> <?php } else { ?> <?php foreach ($block->items as $item) { K2HelperUtilities::setDefaultImage($item, 'latest', $this->params); ?> <?php $this->item = $item; echo $this->loadTemplate('item'); ?> <?php } ?> <?php } ?> </div> <!-- End Item list -->
function getTopCommenters(&$params) { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables'); $limit = $params->get('commenters_limit', '5'); $user =& JFactory::getUser(); $aid = $user->get('aid'); $db =& JFactory::getDBO(); $query = "SELECT COUNT(id) as counter, userName, userID, commentEmail FROM #__k2_comments WHERE userID > 0 AND published = 1 GROUP BY userID ORDER BY counter DESC"; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@"; require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php'; $model = new K2ModelItem(); $componentParams =& JComponentHelper::getParams('com_k2'); if (count($rows)) { foreach ($rows as $row) { if ($row->counter > 0) { $row->link = JRoute::_(K2HelperRoute::getUserRoute($row->userID)); if ($params->get('commentAvatar')) { $row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth')); } if ($params->get('commenterLatestComment')) { $query = "SELECT * FROM #__k2_comments WHERE userID = " . (int) $row->userID . " AND published = 1 ORDER BY commentDate DESC"; $db->setQuery($query, 0, 1); $comment = $db->loadObject(); $item =& JTable::getInstance('K2Item', 'Table'); $item->load($comment->itemID); $category =& JTable::getInstance('K2Category', 'Table'); $category->load($item->catid); $row->latestCommentText = $comment->commentText; $row->latestCommentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->latestCommentText); $row->latestCommentLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($category->alias)))) . "#comment{$comment->id}"; $row->latestCommentDate = $comment->commentDate; } $commenters[] = $row; } } if (isset($commenters)) { return $commenters; } } }
echo $user->name; ?> </a> <?php } ?> <?php if ($params->get('userDescription') && $user->description) { ?> <div class="ubUserDescription"> <?php if ($params->get('userDescriptionWordLimit')) { ?> <?php echo K2HelperUtilities::wordLimit($user->description, $params->get('userDescriptionWordLimit')); ?> <?php } else { ?> <?php echo $user->description; ?> <?php } ?> </div> <?php } ?>
function sendReport() { JRequest::checkToken() or jexit('Invalid Token'); $params = K2HelperUtilities::getParams('com_k2'); $user = JFactory::getUser(); if (!$params->get('comments') || !$params->get('commentsReporting') || ($params->get('commentsReporting') == '2' && $user->guest)) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } K2Model::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'models'); $model = K2Model::getInstance('Comments', 'K2Model'); $model->setState('id', JRequest::getInt('id')); $model->setState('name', JRequest::getString('name')); $model->setState('reportReason', JRequest::getString('reportReason')); if (!$model->report()) { echo $model->getError(); } else { echo JText::_('K2_REPORT_SUBMITTED'); } $mainframe = JFactory::getApplication(); $mainframe->close(); }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $params = K2HelperUtilities::getParams('com_k2'); $document = JFactory::getDocument(); if (K2_JVERSION == '15') { $document->setMimeEncoding('application/json'); $document->setType('json'); } $model = $this->getModel('itemlist'); //Set limit for model $limit = JRequest::getInt('limit'); if ($limit > 100 || $limit == 0) { $limit = 100; JRequest::setVar('limit', $limit); } $page = JRequest::getInt('page'); if ($page <= 0) { $limitstart = 0; } else { $page--; $limitstart = $page * $limit; } JRequest::setVar('limitstart', $limitstart); $view = JRequest::getWord('view'); $task = JRequest::getWord('task'); $response = new JObject(); unset($response->_errors); // Site $response->site = new stdClass(); $uri = JURI::getInstance(); $response->site->url = $uri->toString(array('scheme', 'host', 'port')); $config = JFactory::getConfig(); $response->site->name = K2_JVERSION == '30' ? $config->get('sitename') : $config->getValue('config.sitename'); $moduleID = JRequest::getInt('moduleID'); if ($moduleID) { $result = $model->getModuleItems($moduleID); $items = $result->items; $title = $result->title; $prefix = 'cat'; } else { //Get data depending on task switch ($task) { case 'category': //Get category $id = JRequest::getInt('id'); JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $category = JTable::getInstance('K2Category', 'Table'); $category->load($id); // State Check if (!$category->published || $category->trash) { JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND')); } //Access check $user = JFactory::getUser(); if (K2_JVERSION != '15') { if (!in_array($category->access, $user->getAuthorisedViewLevels())) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } $languageFilter = $mainframe->getLanguageFilter(); $languageTag = JFactory::getLanguage()->getTag(); if ($languageFilter && $category->language != $languageTag && $category->language != '*') { return; } } else { if ($category->access > $user->get('aid', 0)) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } } //Merge params $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params); if ($cparams->get('inheritFrom')) { $masterCategory = JTable::getInstance('K2Category', 'Table'); $masterCategory->load($cparams->get('inheritFrom')); $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params); } $params->merge($cparams); //Category link $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias)))); //Category image $category->image = K2HelperUtilities::getCategoryImage($category->image, $params); //Category plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $category->text = $category->description; if (K2_JVERSION != '15') { $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart)); } else { $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart)); } $category->description = $category->text; //Category K2 plugins $category->event->K2CategoryDisplay = ''; JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart)); $category->event->K2CategoryDisplay = trim(implode("\n", $results)); $category->text = $category->description; $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart)); $category->description = $category->text; //Category children $ordering = $params->get('subCatOrdering'); $children = $model->getCategoryFirstChildren($id, $ordering); $subCategories = array(); if (count($children)) { foreach ($children as $child) { if ($params->get('subCatTitleItemCounter')) { $child->numOfItems = $model->countCategoryItems($child->id); } $child->image = K2HelperUtilities::getCategoryImage($child->image, $params); $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias)))); unset($child->params); unset($child->access); unset($child->published); unset($child->trash); unset($child->language); $subCategories[] = $child; } } //Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); //Set title $title = $category->name; // Set ordering if ($params->get('singleCatOrdering')) { $ordering = $params->get('singleCatOrdering'); } else { $ordering = $params->get('catOrdering'); } // Set parameters prefix $prefix = 'cat'; // Prepare the JSON category object; $row = new JObject(); unset($row->_errors); $row->id = $category->id; $row->name = $category->name; $row->alias = $category->alias; $row->link = $category->link; $row->parent = $category->parent; $row->extraFieldsGroup = $category->extraFieldsGroup; $row->image = $category->image; $row->ordering = $category->ordering; //$row->plugins = $category->plugins; $row->events = $category->event; $row->chidlren = $subCategories; $response->category = $row; break; case 'user': //Get user $id = JRequest::getInt('id'); $userObject = JFactory::getUser($id); //Check user status if ($userObject->block) { JError::raiseError(404, JText::_('K2_USER_NOT_FOUND')); } //Get K2 user profile $userObject->profile = $model->getUserProfile(); //User image $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth')); //User K2 plugins $userObject->event->K2UserDisplay = ''; if (is_object($userObject->profile) && $userObject->profile->id > 0) { $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart)); $userObject->event->K2UserDisplay = trim(implode("\n", $results)); $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8'); } //Set title $title = $userObject->name; // Set ordering $ordering = $params->get('userOrdering'); // Set parameters prefix $prefix = 'user'; // Prepare the JSON user object; $row = new JObject(); unset($row->_errors); //$row->id = $userObject->id; $row->name = $userObject->name; //$row->username = $userObject->username; if (isset($userObject->profile->plugins)) { unset($userObject->profile->plugins); } $row->profile = $userObject->profile; $row->avatar = $userObject->avatar; $row->events = $userObject->event; $response->user = $row; break; case 'tag': //Set limit $limit = $params->get('tagItemCount'); //set title $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag'); // Set ordering $ordering = $params->get('tagOrdering'); // Set parameters prefix $prefix = 'tag'; $response->tag = JRequest::getVar('tag'); break; case 'search': //Set title $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword'); // Set parameters prefix $prefix = 'generic'; $response->search = JRequest::getVar('searchword'); break; case 'date': // Set title if (JRequest::getInt('day')) { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day')); $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } else { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month')); $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } // Set ordering $ordering = 'rdate'; // Set parameters prefix $prefix = 'generic'; $response->date = JHTML::_('date', $date, $dateFormat); break; default: $user = JFactory::getUser(); //Set limit $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links'); //Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); //Set title $title = $params->get('page_title'); // Set ordering $ordering = $params->get('catOrdering'); // Set parameters prefix $prefix = 'cat'; break; } if (!isset($ordering)) { $items = $model->getData(); } else { $items = $model->getData($ordering); } } //Prepare items $user = JFactory::getUser(); $cache = JFactory::getCache('com_k2_extended'); $model = JModelLegacy::getInstance('item', 'K2Model'); $rows = array(); for ($i = 0; $i < sizeof($items); $i++) { //Item group if ($task == "category" || $task == "") { $items[$i]->itemGroup = 'links'; if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) { $items[$i]->itemGroup = 'links'; } if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) { $items[$i]->itemGroup = 'secondary'; } if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) { $items[$i]->itemGroup = 'primary'; } if ($i < $params->get('num_leading_items')) { $items[$i]->itemGroup = 'leading'; } } else { $items[$i]->itemGroup = ''; } $itemParams = class_exists('JParameter') ? new JParameter($items[$i]->params) : new JRegistry($items[$i]->params); $itemParams->set($prefix . 'ItemIntroText', true); $itemParams->set($prefix . 'ItemFullText', true); $itemParams->set($prefix . 'ItemTags', true); $itemParams->set($prefix . 'ItemExtraFields', true); $itemParams->set($prefix . 'ItemAttachments', true); $itemParams->set($prefix . 'ItemRating', true); $itemParams->set($prefix . 'ItemAuthor', true); $itemParams->set($prefix . 'ItemImageGallery', true); $itemParams->set($prefix . 'ItemVideo', true); $itemParams->set($prefix . 'ItemImage', true); $items[$i]->params = $itemParams->toString(); //Check if model should use cache for preparing item even if user is logged in if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') { $cacheFlag = true; } else { $cacheFlag = true; if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) { $cacheFlag = false; } } //Prepare item if ($cacheFlag) { $hits = $items[$i]->hits; $items[$i]->hits = 0; JTable::getInstance('K2Category', 'Table'); $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task); $items[$i]->hits = $hits; } else { $items[$i] = $model->prepareItem($items[$i], $view, $task); } //Plugins $items[$i]->params->set('genericItemIntroText', $params->get('catItemIntroText')); $items[$i] = $model->execPlugins($items[$i], $view, $task); //Trigger comments counter event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart)); $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results)); // Set default image if ($task == 'user' || $task == 'tag' || $task == 'search' || $task == 'date') { $items[$i]->image = isset($items[$i]->imageGeneric) ? $items[$i]->imageGeneric : ''; } else { if (!$moduleID) { K2HelperUtilities::setDefaultImage($items[$i], $view, $params); } } $rows[] = $model->prepareJSONItem($items[$i]); } $response->items = $rows; // Prevent spammers from using the tag view if ($task == 'tag' && !count($response->items)) { $tag = JRequest::getString('tag'); $db = JFactory::getDBO(); $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag)); $tagID = $db->loadResult(); if (!$tagID) { JError::raiseError(404, JText::_('K2_NOT_FOUND')); return false; } } // Output $json = json_encode($response); $callback = JRequest::getCmd('callback'); if ($callback) { $document->setMimeEncoding('application/javascript'); echo $callback . '(' . $json . ')'; } else { echo $json; } }
function media() { K2HelperHTML::loadjQuery(true, true); JRequest::setVar('tmpl', 'component'); $params = K2HelperUtilities::getParams('com_k2'); $document = JFactory::getDocument(); $language = JFactory::getLanguage(); $language->load('com_k2', JPATH_ADMINISTRATOR); $user = JFactory::getUser(); if ($user->guest) { $uri = JFactory::getURI(); if (K2_JVERSION != '15') { $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()); } else { $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString()); } $mainframe = JFactory::getApplication(); $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice'); $mainframe->redirect(JRoute::_($url, false)); } // CSS $document->addStyleSheet(JURI::root(true) . '/media/k2/assets/css/k2.css?v=2.6.8'); // JS K2HelperHTML::loadjQuery(true); $document->addScript(JURI::root(true) . '/media/k2/assets/js/k2.js?v=2.6.8&sitepath=' . JURI::root(true) . '/'); $this->addViewPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views'); $view = $this->getView('media', 'html'); $view->addTemplatePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'media' . DS . 'tmpl'); $view->setLayout('default'); $view->display(); }
<span class="lcComment"><?php echo $comment->commentText; ?> </span> <?php } ?> <?php if ($comment->userImage) { ?> <a class="k2Avatar lcAvatar" href="<?php echo $comment->link; ?> " title="<?php echo K2HelperUtilities::cleanHtml($comment->commentText); ?> "> <img src="<?php echo $comment->userImage; ?> " alt="<?php echo JFilterOutput::cleanText($comment->userName); ?> " style="width:<?php echo $lcAvatarWidth; ?> px;height:auto;" /> </a> <?php }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $params = K2HelperUtilities::getParams('com_k2'); $document = JFactory::getDocument(); $model = $this->getModel('itemlist'); $limitstart = JRequest::getInt('limitstart'); $moduleID = JRequest::getInt('moduleID'); if ($moduleID) { $result = $model->getModuleItems($moduleID); $items = $result->items; $title = $result->title; } else { //Get data depending on task $task = JRequest::getCmd('task'); switch ($task) { case 'category': //Get category $id = JRequest::getInt('id'); JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $category = JTable::getInstance('K2Category', 'Table'); $category->load($id); // State check if (!$category->published || $category->trash) { JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND')); } //Access check $user = JFactory::getUser(); if (K2_JVERSION != '15') { if (!in_array($category->access, $user->getAuthorisedViewLevels())) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()); $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } $languageFilter = $mainframe->getLanguageFilter(); $languageTag = JFactory::getLanguage()->getTag(); if ($languageFilter && $category->language != $languageTag && $category->language != '*') { return; } } else { if ($category->access > $user->get('aid', 0)) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString()); $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } } //Merge params $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params); if ($cparams->get('inheritFrom')) { $masterCategory = JTable::getInstance('K2Category', 'Table'); $masterCategory->load($cparams->get('inheritFrom')); $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params); } $params->merge($cparams); //Category link $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias)))); //Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); //Set title $title = $category->name; // Set ordering if ($params->get('singleCatOrdering')) { $ordering = $params->get('singleCatOrdering'); } else { $ordering = $params->get('catOrdering'); } break; case 'user': //Get user $id = JRequest::getInt('id'); $userObject = JFactory::getUser($id); //Check user status if ($userObject->block) { JError::raiseError(404, JText::_('K2_USER_NOT_FOUND')); } //Set title $title = $userObject->name; // Set ordering $ordering = $params->get('userOrdering'); break; case 'tag': //set title $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag'); // Set ordering $ordering = $params->get('tagOrdering'); break; case 'search': //Set title $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword'); break; case 'date': // Set title if (JRequest::getInt('day')) { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day')); $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } else { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month')); $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } // Set ordering $ordering = 'rdate'; break; default: //Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); //Set title $title = $params->get('page_title'); // Set ordering $ordering = $params->get('catOrdering'); break; } // Various Feed Validations $title = JFilterOutput::ampReplace($title); // Get items if (!isset($ordering)) { $items = $model->getData(); } else { $items = $model->getData($ordering); } } // Prepare feed items //$model = &$this->getModel('itemlist'); foreach ($items as $item) { $item = $model->prepareFeedItem($item); $item->title = $this->escape($item->title); $item->title = html_entity_decode($item->title); $feedItem = new JFeedItem(); $feedItem->title = $item->title; $feedItem->link = $item->link; $feedItem->description = $item->description; $feedItem->date = $item->created; $feedItem->category = $item->category->name; $feedItem->author = $item->author->name; if ($params->get('feedBogusEmail')) { $feedItem->authorEmail = $params->get('feedBogusEmail'); } else { if ($mainframe->getCfg('feed_email') == 'author') { $feedItem->authorEmail = $item->author->email; } else { $feedItem->authorEmail = $mainframe->getCfg('mailfrom'); } } // Add item $document->addItem($feedItem); } // Set title $document = JFactory::getDocument(); $menus = JSite::getMenu(); $menu = $menus->getActive(); if (is_object($menu)) { $menu_params = class_exists('JParameter') ? new JParameter($menu->params) : new JRegistry($menu->params); if (!$menu_params->get('page_title')) { $params->set('page_title', $title); } } else { $params->set('page_title', $title); } if (K2_JVERSION != '15') { if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title')); $params->set('page_title', $title); } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename')); $params->set('page_title', $title); } } $document->setTitle($params->get('page_title')); // Prevent spammers from using the tag view if ($task == 'tag' && !count($items)) { $tag = JRequest::getString('tag'); $db = JFactory::getDBO(); $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag)); $tagID = $db->loadResult(); if (!$tagID) { JError::raiseError(404, JText::_('K2_NOT_FOUND')); return false; } } }
<?php else: ?> <h2 class="latestItemTitleList"> <?php if ($item->params->get('latestItemTitleLinked')): ?> <a href="<?php echo $item->link; ?>"> <?php echo $item->title; ?> </a> <?php else: ?> <?php echo $item->title; ?> <?php endif; ?> </h2> <?php endif; ?> <?php endforeach; ?> <?php else: ?> <?php foreach ($block->items as $item): K2HelperUtilities::setDefaultImage($item, 'latest', $this->params); ?> <?php $this->item=$item; echo $this->loadTemplate('item'); ?> <?php endforeach; ?> <?php endif; ?> </div> <!-- End Item list --> </div> <?php if(($key+1)%($this->params->get('latestItemsCols'))==0): ?> <div class="clr"></div> <?php endif; ?> <?php endforeach; ?> <div class="clr"></div>
<?php } ?> </ul> <?php } ?> <?php if ($params->get('itemCustomLink')) { ?> <a class="moduleCustomLink" href="<?php echo $params->get('itemCustomLinkURL'); ?> " title="<?php echo K2HelperUtilities::cleanHtml($itemCustomLinkTitle); ?> "><?php echo $itemCustomLinkTitle; ?> </a> <?php } ?> <?php if ($params->get('feed')) { ?> <div class="k2FeedIcon"> <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&format=feed&moduleID=' . $module->id);
function getRelatedItems($itemID, $tags, $limit) { $params =& JComponentHelper::getParams('com_k2'); $itemID = (int) $itemID; foreach ($tags as $tag) { $tagIDs[] = $tag->id; } JArrayHelper::toInteger($tagIDs); $sql = implode(',', $tagIDs); $user =& JFactory::getUser(); $aid = (int) $user->get('aid'); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT itemID FROM #__k2_tags_xref WHERE tagID IN ({$sql}) AND itemID!={$itemID}"; $db->setQuery($query); $itemsIDs = $db->loadResultArray(); if (!count($itemsIDs)) { return array(); } $sql = implode(',', $itemsIDs); $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i" . " LEFT JOIN #__k2_categories c ON c.id = i.catid" . " WHERE i.published = 1" . " 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) . " )" . " AND i.access <= {$aid}" . " AND i.trash = 0" . " AND c.published = 1" . " AND c.access <= {$aid}" . " AND c.trash = 0" . " AND (i.id) IN ({$sql})" . " ORDER BY i.created DESC"; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); foreach ($rows as $item) { //Image $item->imageXSmall = ''; $item->imageSmall = ''; $item->imageMedium = ''; $item->imageLarge = ''; $item->imageXLarge = ''; if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) { $item->imageXSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg'; } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) { $item->imageSmall = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg'; } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) { $item->imageMedium = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg'; } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) { $item->imageLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg'; } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) { $item->imageXLarge = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg'; } if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) { $item->imageGeneric = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg'; } //Author if (!empty($item->created_by_alias)) { $item->author->name = $item->created_by_alias; $item->author->avatar = K2HelperUtilities::getAvatar('alias'); } else { $author =& JFactory::getUser($item->created_by); $item->author = $author; $item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by)); $item->author->profile = K2ModelItem::getUserProfile($item->created_by); $item->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth')); } if (!is_object($item->author->profile)) { $item->author->profile = new JObject(); $item->author->profile->gender = NULL; } } return $rows; }
function report() { $id = $this->getState('id'); $name = JString::trim($this->getState('name')); $reportReason = JString::trim($this->getState('reportReason')); $params =& K2HelperUtilities::getParams('com_k2'); $user = JFactory::getUser(); $row = JTable::getInstance('K2Comment', 'Table'); $row->load($id); if (!$row->published) { $this->setError(JText::_('K2_COMMENT_NOT_FOUND')); return false; } if (empty($name)) { $this->setError(JText::_('K2_PLEASE_TYPE_YOUR_NAME')); return false; } if (empty($reportReason)) { $this->setError(JText::_('K2_PLEASE_TYPE_THE_REPORT_REASON')); return false; } if (($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') && $user->guest) { if (!function_exists('_recaptcha_qsencode')) { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'recaptchalib.php'; } $privatekey = $params->get('recaptcha_private_key'); $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $this->setError(JText::_('K2_THE_WORDS_YOU_TYPED_DID_NOT_MATCH_THE_ONES_DISPLAYED_PLEASE_TRY_AGAIN')); return false; } } $mainframe = JFactory::getApplication(); $mail = JFactory::getMailer(); $senderEmail = $mainframe->getCfg('mailfrom'); $senderName = $mainframe->getCfg('fromname'); $mail->setSender(array($senderEmail, $senderName)); $mail->setSubject(JText::_('K2_COMMENT_REPORT')); $mail->IsHTML(true); switch (substr(strtoupper(PHP_OS), 0, 3)) { case 'WIN': $mail->LE = "\r\n"; break; case 'MAC': case 'DAR': $mail->LE = "\r"; default: break; } $body = "\n <strong>" . JText::_('K2_NAME') . "</strong>: " . $name . " <br/>\n <strong>" . JText::_('K2_REPORT_REASON') . "</strong>: " . $reportReason . " <br/>\n <strong>" . JText::_('K2_COMMENT') . "</strong>: " . nl2br($row->commentText) . " <br/>\n "; $mail->setBody($body); $mail->ClearAddresses(); $mail->AddAddress($params->get('commentsReportRecipient', $mainframe->getCfg('mailfrom'))); $mail->Send(); return true; }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $document = JFactory::getDocument(); $params = K2HelperUtilities::getParams('com_k2'); $limitstart = JRequest::getInt('limitstart', 0); $view = JRequest::getWord('view'); $task = JRequest::getWord('task'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); $this->setLayout('item'); // Add link if (K2HelperPermissions::canAddItem()) { $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component'); } $this->assignRef('addLink', $addLink); // Get item $model = $this->getModel(); $item = $model->getData(); $item->event = new stdClass(); // Does the item exists? if (!is_object($item) || !$item->id) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } // Prepare item $item = $model->prepareItem($item, $view, $task); // Plugins $item = $model->execPlugins($item, $view, $task); // User K2 plugins $item->event->K2UserDisplay = ''; if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) { $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart)); $item->event->K2UserDisplay = trim(implode("\n", $results)); $item->author->profile->url = htmlspecialchars($item->author->profile->url, ENT_QUOTES, 'UTF-8'); } // Access check if ($this->getLayout() == 'form') { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } if (K2_JVERSION != '15') { if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels())) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()); $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice'); $mainframe->redirect(JRoute::_($url, false)); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } } else { if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString()); $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice'); $mainframe->redirect(JRoute::_($url, false)); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } } // Published check if (!$item->published || $item->trash) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if ($item->publish_up != $nullDate && $item->publish_up > $now) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if ($item->publish_down != $nullDate && $item->publish_down < $now) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if (!$item->category->published || $item->category->trash) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } // Increase hits counter $model->hit($item->id); // Set default image K2HelperUtilities::setDefaultImage($item, $view); // Comments $item->event->K2CommentsCounter = ''; $item->event->K2CommentsBlock = ''; if ($item->params->get('itemComments')) { // Trigger comments events $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart)); $item->event->K2CommentsCounter = trim(implode("\n", $results)); $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart)); $item->event->K2CommentsBlock = trim(implode("\n", $results)); // Load K2 native comments system only if there are no plugins overriding it if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) { $limit = $params->get('commentsLimit'); $comments = $model->getItemComments($item->id, $limitstart, $limit); $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@"; for ($i = 0; $i < sizeof($comments); $i++) { $comments[$i]->commentText = nl2br($comments[$i]->commentText); $comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText); $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth')); if ($comments[$i]->userID > 0) { $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID); } else { $comments[$i]->userLink = $comments[$i]->commentURL; } } $item->comments = $comments; jimport('joomla.html.pagination'); $total = $item->numOfComments; $pagination = new JPagination($total, $limitstart, $limit); } } // Author's latest items if ($item->params->get('itemAuthorLatest') && $item->created_by_alias == '') { $model = $this->getModel('itemlist'); $authorLatestItems = $model->getAuthorLatest($item->id, $item->params->get('itemAuthorLatestLimit'), $item->created_by); if (count($authorLatestItems)) { for ($i = 0; $i < sizeof($authorLatestItems); $i++) { $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias)))); } $this->assignRef('authorLatestItems', $authorLatestItems); } } // Related items if ($item->params->get('itemRelated') && isset($item->tags) && count($item->tags)) { $model = $this->getModel('itemlist'); $relatedItems = $model->getRelatedItems($item->id, $item->tags, $item->params); if (count($relatedItems)) { for ($i = 0; $i < sizeof($relatedItems); $i++) { $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias)))); } $this->assignRef('relatedItems', $relatedItems); } } // Navigation (previous and next item) if ($item->params->get('itemNavigation')) { $model = $this->getModel('item'); $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering); if (!is_null($nextItem)) { $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias)))); $item->nextTitle = $nextItem->title; } $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering); if (!is_null($previousItem)) { $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias)))); $item->previousTitle = $previousItem->title; } } // Absolute URL $uri = JURI::getInstance(); $item->absoluteURL = $uri->toString(); // Email link if (K2_JVERSION != '15') { require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php'; $template = $mainframe->getTemplate(); $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($item->absoluteURL)); } else { require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php'; $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . MailToHelper::addLink($item->absoluteURL)); } // Twitter link (legacy code) if ($params->get('twitterUsername')) { $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&url=' . urlencode($item->absoluteURL) . '&via=' . $params->get('twitterUsername'); } else { $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&url=' . urlencode($item->absoluteURL); } // Social link $item->socialLink = urlencode($item->absoluteURL); // Look for template files in component folders $this->_addPath('template', JPATH_COMPONENT . DS . 'templates'); $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default'); // Look for overrides in template folder (K2 template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default'); // Look for overrides in template folder (Joomla! template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2'); // Look for specific K2 theme files if ($item->params->get('theme')) { $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme')); } // Assign data $this->assignRef('item', $item); $this->assignRef('user', $user); $this->assignRef('params', $item->params); $this->assignRef('pagination', $pagination); parent::display($tpl); }
function getRelatedItems($itemID, $tags, $params) { $mainframe =& JFactory::getApplication(); $limit = $params->get('itemRelatedLimit', 10); $itemID = (int) $itemID; foreach ($tags as $tag) { $tagIDs[] = $tag->id; } JArrayHelper::toInteger($tagIDs); $sql = implode(',', $tagIDs); $user =& JFactory::getUser(); $aid = (int) $user->get('aid'); $db =& JFactory::getDBO(); $jnow =& JFactory::getDate(); $now = $jnow->toMySQL(); $nullDate = $db->getNullDate(); $query = "SELECT DISTINCT itemID FROM #__k2_tags_xref WHERE tagID IN ({$sql}) AND itemID!={$itemID}"; $db->setQuery($query); $itemsIDs = $db->loadResultArray(); if (!count($itemsIDs)) { return array(); } $sql = implode(',', $itemsIDs); $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i \n\t\t\t\tLEFT JOIN #__k2_categories c ON c.id = i.catid \n\t\t\t\tWHERE i.published = 1 \n\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " ) \n\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " ) "; if (K2_JVERSION == '16') { $query .= " AND i.access IN(" . implode(',', $user->authorisedLevels()) . ") "; if ($mainframe->getLanguageFilter()) { $query .= " AND i.language IN(" . $db->Quote(JFactory::getLanguage()->getTag()) . ", " . $db->Quote('*') . ")"; } } else { $query .= " AND i.access <= {$aid} "; } $query .= " AND i.trash = 0 \n\t\t\t\tAND c.published = 1 "; if (K2_JVERSION == '16') { $query .= " AND c.access IN(" . implode(',', $user->authorisedLevels()) . ") "; if ($mainframe->getLanguageFilter()) { $query .= " AND c.language IN(" . $db->Quote(JFactory::getLanguage()->getTag()) . ", " . $db->Quote('*') . ")"; } } else { $query .= " AND c.access <= {$aid} "; } $query .= " AND c.trash = 0 \n\t\t\t\tAND (i.id) IN ({$sql}) \n\t\t\t\tORDER BY i.created DESC"; $db->setQuery($query, 0, $limit); $rows = $db->loadObjectList(); JModel::addIncludePath(JPATH_COMPONENT . DS . 'models'); $model =& JModel::getInstance('Item', 'K2Model'); for ($key = 0; $key < sizeof($rows); $key++) { $rows[$key] = $model->prepareItem($rows[$key], 'relatedByTag', ''); $rows[$key] = $model->execPlugins($rows[$key], 'relatedByTag', ''); K2HelperUtilities::setDefaultImage($rows[$key], 'relatedByTag', $params); } return $rows; }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $params = K2HelperUtilities::getParams('com_k2'); $model = $this->getModel('itemlist'); $limitstart = JRequest::getInt('limitstart'); $view = JRequest::getWord('view'); $task = JRequest::getWord('task'); $db = JFactory::getDBO(); // Add link if (K2HelperPermissions::canAddItem()) { $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component'); } $this->assignRef('addLink', $addLink); // Get data depending on task switch ($task) { case 'category': // Get category $id = JRequest::getInt('id'); JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $category = JTable::getInstance('K2Category', 'Table'); $category->load($id); $category->event = new stdClass(); // State check if (!$category->published || $category->trash) { JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND')); } // Access check $user = JFactory::getUser(); if (K2_JVERSION != '15') { if (!in_array($category->access, $user->getAuthorisedViewLevels())) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString()); $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } $languageFilter = $mainframe->getLanguageFilter(); $languageTag = JFactory::getLanguage()->getTag(); if ($languageFilter && $category->language != $languageTag && $category->language != '*') { return; } } else { if ($category->access > $user->get('aid', 0)) { if ($user->guest) { $uri = JFactory::getURI(); $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString()); $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST')); } else { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); return; } } } // Hide the add new item link if user cannot post in the specific category if (!K2HelperPermissions::canAddItem($id)) { unset($this->addLink); } // Merge params $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params); // Get the meta information before merging params since we do not want them to be inherited $category->metaDescription = $cparams->get('catMetaDesc'); $category->metaKeywords = $cparams->get('catMetaKey'); $category->metaRobots = $cparams->get('catMetaRobots'); $category->metaAuthor = $cparams->get('catMetaAuthor'); if ($cparams->get('inheritFrom')) { $masterCategory = JTable::getInstance('K2Category', 'Table'); $masterCategory->load($cparams->get('inheritFrom')); $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params); } $params->merge($cparams); // Category link $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias)))); // Category image $category->image = K2HelperUtilities::getCategoryImage($category->image, $params); // Category plugins $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $category->text = $category->description; if (K2_JVERSION != '15') { $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart)); } else { $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart)); } $category->description = $category->text; // Category K2 plugins $category->event->K2CategoryDisplay = ''; JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart)); $category->event->K2CategoryDisplay = trim(implode("\n", $results)); $category->text = $category->description; $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart)); $category->description = $category->text; $this->assignRef('category', $category); $this->assignRef('user', $user); // Category children $ordering = $params->get('subCatOrdering'); $children = $model->getCategoryFirstChildren($id, $ordering); if (count($children)) { foreach ($children as $child) { if ($params->get('subCatTitleItemCounter')) { $child->numOfItems = $model->countCategoryItems($child->id); } $child->image = K2HelperUtilities::getCategoryImage($child->image, $params); $child->name = htmlspecialchars($child->name, ENT_QUOTES); $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias)))); $subCategories[] = $child; } $this->assignRef('subCategories', $subCategories); } // Set limit $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links'); // Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); // Set layout $this->setLayout('category'); // Set title $title = $category->name; $category->name = htmlspecialchars($category->name, ENT_QUOTES); // Set ordering if ($params->get('singleCatOrdering')) { $ordering = $params->get('singleCatOrdering'); } else { $ordering = $params->get('catOrdering'); } $addHeadFeedLink = $params->get('catFeedLink'); break; case 'user': // Get user $id = JRequest::getInt('id'); $userObject = JFactory::getUser($id); $userObject->event = new stdClass(); // Check user status if ($userObject->block) { JError::raiseError(404, JText::_('K2_USER_NOT_FOUND')); } // Get K2 user profile $userObject->profile = $model->getUserProfile(); // User image $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth')); // User K2 plugins $userObject->event->K2UserDisplay = ''; if (is_object($userObject->profile) && $userObject->profile->id > 0) { $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart)); $userObject->event->K2UserDisplay = trim(implode("\n", $results)); $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8'); } $this->assignRef('user', $userObject); $date = JFactory::getDate(); $now = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); $this->assignRef('now', $now); // Set layout $this->setLayout('user'); // Set limit $limit = $params->get('userItemCount'); // Set title $title = $userObject->name; $userObject->name = htmlspecialchars($userObject->name, ENT_QUOTES); // Set ordering $ordering = $params->get('userOrdering'); $addHeadFeedLink = $params->get('userFeedLink', 1); break; case 'tag': // Set layout $this->setLayout('tag'); // Set limit $limit = $params->get('tagItemCount'); // Set title $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag'); // Set ordering $ordering = $params->get('tagOrdering'); $addHeadFeedLink = $params->get('tagFeedLink', 1); break; case 'search': // Set layout $this->setLayout('generic'); // Set limit $limit = $params->get('genericItemCount'); // Set title $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword'); $addHeadFeedLink = $params->get('genericFeedLink', 1); break; case 'date': // Set layout $this->setLayout('generic'); // Set limit $limit = $params->get('genericItemCount'); // Fix wrong timezone if (function_exists('date_default_timezone_get')) { $originalTimezone = date_default_timezone_get(); } if (function_exists('date_default_timezone_set')) { date_default_timezone_set('UTC'); } // Set title if (JRequest::getInt('day')) { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day')); $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } else { $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month')); $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y'; $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat); } // Restore the original timezone if (function_exists('date_default_timezone_set') && isset($originalTimezone)) { date_default_timezone_set($originalTimezone); } // Set ordering $ordering = 'rdate'; $addHeadFeedLink = $params->get('genericFeedLink', 1); break; default: // Set layout $this->setLayout('category'); $user = JFactory::getUser(); $this->assignRef('user', $user); // Set limit $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links'); // Set featured flag JRequest::setVar('featured', $params->get('catFeaturedItems')); // Set title $title = $params->get('page_title'); // Set ordering $ordering = $params->get('catOrdering'); $addHeadFeedLink = $params->get('catFeedLink', 1); break; } // Set limit for model if (!$limit) { $limit = 10; } JRequest::setVar('limit', $limit); // Get items if (!isset($ordering)) { $items = $model->getData(); } else { $items = $model->getData($ordering); } // Pagination jimport('joomla.html.pagination'); $total = count($items) ? $model->getTotal() : 0; $pagination = new JPagination($total, $limitstart, $limit); //Prepare items $user = JFactory::getUser(); $cache = JFactory::getCache('com_k2_extended'); $model = $this->getModel('item'); for ($i = 0; $i < sizeof($items); $i++) { //Item group if ($task == "category" || $task == "") { if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) { $items[$i]->itemGroup = 'links'; } if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) { $items[$i]->itemGroup = 'secondary'; } if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) { $items[$i]->itemGroup = 'primary'; } if ($i < $params->get('num_leading_items')) { $items[$i]->itemGroup = 'leading'; } } // Check if the model should use the cache for preparing the item even if the user is logged in if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') { $cacheFlag = true; } else { $cacheFlag = true; if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) { $cacheFlag = false; } } // Prepare item if ($cacheFlag) { $hits = $items[$i]->hits; $items[$i]->hits = 0; JTable::getInstance('K2Category', 'Table'); $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task); $items[$i]->hits = $hits; } else { $items[$i] = $model->prepareItem($items[$i], $view, $task); } // Plugins $items[$i] = $model->execPlugins($items[$i], $view, $task); // Trigger comments counter event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart)); $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results)); } // Set title $document = JFactory::getDocument(); $application = JFactory::getApplication(); $menus = $application->getMenu(); $menu = $menus->getActive(); if (is_object($menu)) { if (is_string($menu->params)) { $menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params); } else { $menu_params = $menu->params; } if (!$menu_params->get('page_title')) { $params->set('page_title', $title); } } else { $params->set('page_title', $title); } // We're adding a new variable here which won't get the appended/prepended site title, // when enabled via Joomla!'s SEO/SEF settings $params->set('page_title_clean', $title); if (K2_JVERSION != '15') { if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) { $tmpTitle = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title')); $params->set('page_title', $tmpTitle); } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) { $tmpTitle = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename')); $params->set('page_title', $tmpTitle); } } $document->setTitle($params->get('page_title')); // Search - Update the Google Search results container (K2 v2.6.6+) if ($task == 'search') { $googleSearchContainerID = trim($params->get('googleSearchContainer', 'k2GoogleSearchContainer')); if ($googleSearchContainerID == 'k2Container') { $googleSearchContainerID = 'k2GoogleSearchContainer'; } $params->set('googleSearchContainer', $googleSearchContainerID); } // Set metadata for category if ($task == 'category') { if ($category->metaDescription) { $document->setDescription($category->metaDescription); } else { $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $this->category->description); $metaDescItem = strip_tags($metaDescItem); $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150)); $metaDescItem = htmlspecialchars($metaDescItem, ENT_QUOTES, 'UTF-8'); $document->setDescription($metaDescItem); } if ($category->metaKeywords) { $document->setMetadata('keywords', $category->metaKeywords); } if ($category->metaRobots) { $document->setMetadata('robots', $category->metaRobots); } if ($category->metaAuthor) { $document->setMetadata('author', $category->metaAuthor); } } if (K2_JVERSION != '15') { // Menu metadata options if ($params->get('menu-meta_description')) { $document->setDescription($params->get('menu-meta_description')); } if ($params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $params->get('menu-meta_keywords')); } if ($params->get('robots')) { $document->setMetadata('robots', $params->get('robots')); } // Menu page display options if ($params->get('page_heading')) { $params->set('page_title', $params->get('page_heading')); } $params->set('show_page_title', $params->get('show_page_heading')); } // Pathway $pathway = $mainframe->getPathWay(); if (!isset($menu->query['task'])) { $menu->query['task'] = ''; } if ($menu) { switch ($task) { case 'category': if ($menu->query['task'] != 'category' || $menu->query['id'] != JRequest::getInt('id')) { $pathway->addItem($title, ''); } break; case 'user': if ($menu->query['task'] != 'user' || $menu->query['id'] != JRequest::getInt('id')) { $pathway->addItem($title, ''); } break; case 'tag': if ($menu->query['task'] != 'tag' || $menu->query['tag'] != JRequest::getVar('tag')) { $pathway->addItem($title, ''); } break; case 'search': case 'date': $pathway->addItem($title, ''); break; } } // Feed link $config = JFactory::getConfig(); $menu = $application->getMenu(); $default = $menu->getDefault(); $active = $menu->getActive(); if ($task == 'tag') { $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag')); } else { $link = ''; } $sef = K2_JVERSION == '30' ? $config->get('sef') : $config->getValue('config.sef'); if (!is_null($active) && $active->id == $default->id && $sef) { $link .= '&Itemid=' . $active->id . '&format=feed&limitstart='; } else { $link .= '&format=feed&limitstart='; } $feed = JRoute::_($link); $this->assignRef('feed', $feed); // Add head feed link if ($addHeadFeedLink) { $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'); $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs); $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'); $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs); } // Assign data if ($task == "category" || $task == "") { $leading = @array_slice($items, 0, $params->get('num_leading_items')); $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items')); $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items')); $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links')); $this->assignRef('leading', $leading); $this->assignRef('primary', $primary); $this->assignRef('secondary', $secondary); $this->assignRef('links', $links); } else { $this->assignRef('items', $items); } // Set default values to avoid division by zero if ($params->get('num_leading_columns') == 0) { $params->set('num_leading_columns', 1); } if ($params->get('num_primary_columns') == 0) { $params->set('num_primary_columns', 1); } if ($params->get('num_secondary_columns') == 0) { $params->set('num_secondary_columns', 1); } if ($params->get('num_links_columns') == 0) { $params->set('num_links_columns', 1); } $this->assignRef('params', $params); $this->assignRef('pagination', $pagination); // Set Facebook meta data $document = JFactory::getDocument(); $uri = JURI::getInstance(); $document->setMetaData('og:url', $uri->toString()); $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8')); $document->setMetaData('og:type', 'website'); if ($task == 'category' && $this->category->image && strpos($this->category->image, 'placeholder/category.png') === false) { $image = substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $this->category->image); $document->setMetaData('og:image', $image); $document->setMetaData('image', $image); } $document->setMetaData('og:description', htmlspecialchars(strip_tags($document->getDescription()), ENT_QUOTES, 'UTF-8')); // Look for template files in component folders $this->_addPath('template', JPATH_COMPONENT . DS . 'templates'); $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default'); // Look for overrides in template folder (K2 template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default'); // Look for overrides in template folder (Joomla! template structure) $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default'); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2'); // Look for specific K2 theme files if ($params->get('theme')) { $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme')); $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme')); } $nullDate = $db->getNullDate(); $this->assignRef('nullDate', $nullDate); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $dispatcher->trigger('onK2BeforeViewDisplay'); // Prevent spammers from using the tag view if ($task == 'tag' && !count($this->items)) { $tag = JRequest::getString('tag'); $db = JFactory::getDBO(); $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag)); $tagID = $db->loadResult(); if (!$tagID) { JError::raiseError(404, JText::_('K2_NOT_FOUND')); return false; } } parent::display($tpl); }
<?php if ($this->item->params->get('catItemAttachments') && count($this->item->attachments)) { ?> <!-- Item attachments --> <div class="catItemAttachmentsBlock"> <span><?php echo JText::_('K2_DOWNLOAD_ATTACHMENTS'); ?> </span> <ul class="catItemAttachments"> <?php foreach ($this->item->attachments as $attachment) { ?> <li> <a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?> " href="<?php echo $attachment->link; ?> "> <?php echo $attachment->title; ?> </a> <?php if ($this->item->params->get('catItemAttachmentsCounter')) { ?> <span>(<?php echo $attachment->hits; ?>
?> "> <?php foreach ($tags as $tag) { ?> <?php if (!empty($tag->tag)) { ?> <a href="<?php echo $tag->link; ?> " style="font-size:<?php echo $tag->size; ?> %" title="<?php echo $tag->count . ' ' . JText::_('K2_ITEMS_TAGGED_WITH') . ' ' . K2HelperUtilities::cleanHtml($tag->tag); ?> "> <?php echo $tag->tag; ?> </a> <?php } ?> <?php } ?> <div class="clr"></div> </div>
?> <div class="k2UserBlockDetails"> <?php if ($params->get('userAvatar')) { ?> <a class="k2Avatar ubAvatar" href="<?php echo JRoute::_(K2HelperRoute::getUserRoute($user->id)); ?> " title="<?php echo JText::_('K2_MY_PAGE'); ?> "> <img src="<?php echo K2HelperUtilities::getAvatar($user->id, $user->email); ?> " alt="<?php echo K2HelperUtilities::cleanHtml($user->name); ?> " style="width:<?php echo $avatarWidth; ?> px;height:auto;" /> </a> <?php } ?> <span class="ubName"><?php echo $user->name; ?> </span> <span class="ubCommentsCount"><?php echo JText::_('K2_YOU_HAVE'); ?> <b><?php
function display($tpl = null) { $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $document = JFactory::getDocument(); if (K2_JVERSION == '15') { $document->setMimeEncoding('application/json'); $document->setType('json'); } $params = K2HelperUtilities::getParams('com_k2'); $view = JRequest::getWord('view'); $task = JRequest::getWord('task'); $db = JFactory::getDBO(); $jnow = JFactory::getDate(); $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql(); $nullDate = $db->getNullDate(); // Get item $model = $this->getModel(); $item = $model->getData(); // Does the item exists? if (!is_object($item) || !$item->id) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } // Override some params because we want to show all elements in JSON $itemParams = class_exists('JParameter') ? new JParameter($item->params) : new JRegistry($item->params); $itemParams->set('itemIntroText', true); $itemParams->set('itemFullText', true); $itemParams->set('itemTags', true); $itemParams->set('itemExtraFields', true); $itemParams->set('itemAttachments', true); $itemParams->set('itemRating', true); $itemParams->set('itemAuthor', true); $itemParams->set('itemImageGallery', true); $itemParams->set('itemVideo', true); $item->params = $itemParams->toString(); // Prepare item $item = $model->prepareItem($item, $view, $task); // Plugins $item = $model->execPlugins($item, $view, $task); // Access check if (K2_JVERSION != '15') { if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels())) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } } else { if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } } // Published check if (!$item->published || $item->trash) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if ($item->publish_up != $nullDate && $item->publish_up > $now) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if ($item->publish_down != $nullDate && $item->publish_down < $now) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } if (!$item->category->published || $item->category->trash) { JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND')); } // Set default image K2HelperUtilities::setDefaultImage($item, $view); // Build the output object $row = $model->prepareJSONItem($item); // Output $response = new stdClass(); // Site $response->site = new stdClass(); $uri = JURI::getInstance(); $response->site->url = $uri->toString(array('scheme', 'host', 'port')); $config = JFactory::getConfig(); $response->site->name = K2_JVERSION == '30' ? $config->get('sitename') : $config->getValue('config.sitename'); $response->item = $row; $json = json_encode($response); $callback = JRequest::getCmd('callback'); if ($callback) { $document->setMimeEncoding('application/javascript'); echo $callback . '(' . $json . ')'; } else { echo $json; } }