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 prepareFeedItem(&$item){ JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables'); $params = & JComponentHelper::getParams('com_k2'); $limitstart=0; //Category $category = & JTable::getInstance('K2Category', 'Table'); $category->load($item->catid); $item->category=$category; //Read more link $item->link=urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.$item->alias,$item->catid.':'.urlencode($item->category->alias)))); //Filtering if ($params->get('introTextCleanup')){ $filterTags = preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupExcludeTags' ) ) ); $filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'introTextCleanupTagAttr' ) ) ); $filter = new JFilterInput( $filterTags, $filterAttrs, 0, 1 ); $item->introtext= $filter->clean( $item->introtext ); } if ($params->get('fullTextCleanup')){ $filterTags = preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupExcludeTags' ) ) ); $filterAttrs = preg_split( '#[,\s]+#', trim( $params->get( 'fullTextCleanupTagAttr' ) ) ); $filter = new JFilterInput( $filterTags, $filterAttrs, 0, 1 ); $item->fulltext= $filter->clean( $item->fulltext ); } //Description $item->description = ''; //Item image if ($params->get('feedItemImage') && JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_'.$params->get('feedImgSize').'.jpg')){ $item->description.= '<div class="K2FeedImage"><img src="'.JURI::root().'/media/k2/items/cache/'.md5('Image'.$item->id).'_'.$params->get('feedImgSize').'.jpg" alt="'.$item->title.'" /></div>'; } //Item Introtext if($params->get('feedItemIntroText')){ //Introtext word limit if ($params->get('feedTextWordLimit') && $item->introtext){ $item->introtext=K2HelperUtilities::wordLimit($item->introtext,$params->get('feedTextWordLimit')); } $item->description.= '<div class="K2FeedIntroText">'.$item->introtext.'</div>'; } //Item Fulltext if($params->get('feedItemFullText') && $item->fulltext){ $item->description.= '<div class="K2FeedFullText">'.$item->fulltext.'</div>'; } //Item Tags if($params->get('feedItemTags')){ $tags = K2ModelItem::getItemTags($item->id); if(count($tags)){ $item->description.='<div class="K2FeedTags"><ul>'; foreach($tags as $tag){ $item->description.='<li>'.$tag->name.'</li>'; } $item->description.='<ul></div>'; } } //Item Video if($params->get('feedItemVideo') && $item->video){ if (!empty($item->video) && JString::substr($item->video, 0, 1) !== '{') { $item->description.= '<div class="K2FeedVideo">'.$item->video.'</div>'; } else { $params->set('vfolder', 'media/k2/videos'); if(JString::strpos($item->video, 'remote}')){ preg_match("#}(.*?){/#s",$item->video, $matches); if(!JString::strpos($matches[1], 'http://}')) $item->video = str_replace($matches[1], JURI::root().$matches[1], $item->video); } $dispatcher = &JDispatcher::getInstance(); JPluginHelper::importPlugin ('content'); $item->text=$item->video; $dispatcher->trigger ( 'onPrepareContent', array (&$item, &$params, $limitstart ) ); $item->description.= '<div class="K2FeedVideo">'.$item->text.'</div>'; } } //Item gallery if($params->get('feedItemGallery') && $item->gallery){ $params->set('galleries_rootfolder', 'media/k2/galleries'); $params->set('popup_engine', 'mootools_slimbox'); $params->set('enabledownload', '0'); $dispatcher = &JDispatcher::getInstance(); JPluginHelper::importPlugin ('content'); $item->text=$item->gallery; $dispatcher->trigger ( 'onPrepareContent', array (&$item, &$params, $limitstart ) ); $item->description.= '<div class="K2FeedGallery">'.$item->text.'</div>'; } //Item attachments if($params->get('feedItemAttachments')){ $attachments = K2ModelItem::getItemAttachments($item->id); if(count($attachments)){ $item->description.='<div class="K2FeedAttachments"><ul>'; foreach($attachments as $attachment){ $item->description.='<li><a title="'.htmlentities($attachment->titleAttribute, ENT_QUOTES, 'UTF-8').'" href="'.JRoute::_('index.php?option=com_k2&view=item&task=download&id='.$attachment->id).'">'.$attachment->title.'</a></li>'; } $item->description.='<ul></div>'; } } //Author if (!empty($item->created_by_alias)){ $item->author->name = $item->created_by_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); } return $item; }
function prepareFeedItem(&$item) { JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables'); $params =& JComponentHelper::getParams('com_k2'); $limitstart = 0; //Category $category =& JTable::getInstance('K2Category', 'Table'); $category->load($item->catid); $item->category = $category; //Read more link $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid . ':' . urlencode($item->category->alias)))); //Filtering if ($params->get('introTextCleanup')) { $filterTags = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupExcludeTags'))); $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupTagAttr'))); $filter = new JFilterInput($filterTags, $filterAttrs, 0, 1); $item->introtext = $filter->clean($item->introtext); } if ($params->get('fullTextCleanup')) { $filterTags = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupExcludeTags'))); $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupTagAttr'))); $filter = new JFilterInput($filterTags, $filterAttrs, 0, 1); $item->fulltext = $filter->clean($item->fulltext); } //Description $item->description = ''; //Item image if ($params->get('feedItemImage') && JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_' . $params->get('feedImgSize') . '.jpg')) { $item->description .= '<div class="K2FeedImage"><img src="' . JURI::root() . '/media/k2/items/cache/' . md5('Image' . $item->id) . '_' . $params->get('feedImgSize') . '.jpg" alt="' . $item->title . '"/></div>'; } //Item Introtext if ($params->get('feedItemIntroText')) { //Introtext word limit if ($params->get('feedTextWordLimit')) { $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $params->get('feedTextWordLimit')); } $item->description .= '<div class="K2FeedIntroText">' . $item->introtext . '<div>'; } //Item Fulltext if ($params->get('feedItemFullText')) { $item->description .= '<div class="K2FeedFullText">' . $item->fulltext . '<div>'; } //Author if (!empty($item->created_by_alias)) { $item->author->name = $item->created_by_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); } return $item; }
<?php } ?> <?php if ($item->params->get('genericItemCategory')) { ?> <div class="catItemAdditionalInfo"> <span class="catItemCategory"> <?php if ($item->params->get('catItemAuthor')) { $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); ?> <span class="catItemAuthor"> <?php echo K2HelperUtilities::writtenBy($item->author->profile->gender); ?> <a rel="author" href="<?php echo $item->author->link; ?> "><?php echo $item->author->name; ?> </a> </span> <?php }