Ejemplo n.º 1
0
function getTagsFilter($catid)
{
    $items = getCats($catid);
    $catTags = array();
    $allTags = array();
    $tags = array();
    if (count($items)) {
        require_once JPATH_BASE . '/components/com_k2/models/item.php';
        $K2ModelItem = new K2ModelItem();
        foreach ($items as $item) {
            $catTags[] = $K2ModelItem->getItemTags($item->id);
        }
        if (!empty($catTags)) {
            foreach ($catTags as $catTag) {
                if (!empty($catTag)) {
                    foreach ($catTag as $tag) {
                        $allTags[] = $tag->name;
                    }
                }
            }
        }
        $tags = array_unique($allTags);
    }
    return $tags;
}
Ejemplo n.º 2
0
 function display($cachable = false, $urlparams = false)
 {
     error_reporting(E_ALL ^ E_NOTICE);
     JRequest::setVar('task', 'search');
     JRequest::setVar('view', 'itemlist');
     $model = $this->getModel('Itemlist', 'JAK2FilterModel');
     $modelitems = new K2ModelItem();
     $modelitems->getData();
     $document = JFactory::getDocument();
     $viewType = $document->getType();
     $view = $this->getView('itemlist', $viewType, 'JAK2FilterView');
     $view->setModel($model);
     $view->setModel($modelitems);
     $user = JFactory::getUser();
     $cache = false;
     parent::display($cache);
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
	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;
	}
Ejemplo n.º 5
0
 /**
  *
  * Get list K2 items
  * @param string $catid categories id
  * @param object $params
  * @return array
  */
 function getListK2($catids, $params)
 {
     if (file_exists(JPATH_SITE . '/components/com_k2/helpers/route.php')) {
         require_once JPATH_SITE . "/components/com_k2/helpers/route.php";
         require_once JPATH_ADMINISTRATOR . "/components/com_k2/models/model.php";
         require_once JPATH_SITE . "/components/com_k2/models/item.php";
     }
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $date = JFactory::getDate();
     //$now = $date->toMySQL();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $now = $date->toSql();
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $now = $date->toMySQL();
         } else {
             $now = $date->toMySQL();
         }
     }
     $user = JFactory::getUser();
     $aid = $user->get('aid') ? $user->get('aid') : 1;
     $jnow = JFactory::getDate();
     //$now = $jnow->toMySQL();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $now = $jnow->toSql();
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $now = $jnow->toMySQL();
         } else {
             $now = $jnow->toMySQL();
         }
     }
     $nullDate = $db->getNullDate();
     $sql = array();
     //do not select category
     /*if ((!empty($catids)) && ($catids[0]==0)) {
     			return $data = array();
     		}*/
     if (!empty($catids)) {
         $catids_new = $catids;
         foreach ($catids as $k => $catid) {
             if ($catid != 0) {
                 $subcatids = modJacontentsliderHelper::getK2CategoryChildren($catid, true);
                 if ($subcatids) {
                     $catids_new = array_merge($catids_new, array_diff($subcatids, $catids_new));
                 }
             }
         }
     }
     $query = array();
     $arr_cate = '';
     JArrayHelper::toInteger($catids_new);
     if (!empty($catids_new)) {
         $arr_cate = '(' . implode(',', $catids_new) . ')';
     }
     $select = 'SELECT items.*, cate.name AS cateName, cate.alias AS categoryalias';
     $from = ' FROM #__k2_categories as cate INNER JOIN #__k2_items as items ON cate.id = items.catid';
     $where = ' WHERE cate.published = 1 AND items.published = 1';
     $where .= " AND items.access <= {$aid}" . " AND items.trash = 0" . " AND cate.access <= {$aid}" . " AND cate.trash = 0";
     $where .= " AND ( items.publish_up = " . $db->Quote($nullDate) . " OR items.publish_up <= " . $db->Quote($now) . " )";
     $where .= " AND ( items.publish_down = " . $db->Quote($nullDate) . " OR items.publish_down >= " . $db->Quote($now) . " )";
     if (!empty($arr_cate)) {
         $where .= ' AND items.catid IN ' . $arr_cate . ' ';
     }
     // language filter
     $lang = JFactory::getLanguage();
     $languageTag = $lang->getTag();
     if ($app->getLanguageFilter()) {
         $where .= " AND items.language IN ('{$languageTag}','*') ";
     }
     // order by
     $order = $params->get('sort_order_field', 'created');
     $orderDir = $params->get('sort_order', 'DESC');
     switch ($order) {
         case 'created':
             $orderBy = " items.created {$orderDir}";
             break;
         case 'ordering':
             $orderBy = " items.ordering {$orderDir}";
             break;
         case 'hits':
             $orderBy = " items.hits {$orderDir}";
             break;
         default:
             $orderBy = " RAND() ";
             break;
     }
     $query = $select . $from . $where . ' ORDER BY ' . $orderBy;
     $query .= ' LIMIT 0,' . $params->get('maxitems', 10);
     $db->setQuery($query);
     $data = $db->loadObjectlist();
     if (empty($data)) {
         $data = array();
     }
     $config = array();
     $model = new K2ModelItem($config);
     foreach ($data as $i => $row) {
         $data[$i]->id = $row->id;
         $data[$i]->text = $data[$i]->introtext;
         $data[$i]->title = $data[$i]->title;
         $data[$i]->introtext = $row->introtext;
         $data[$i]->catid = $row->catid;
         $data[$i]->cateName = $row->cateName;
         $data[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->id . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->categoryalias))));
         $data[$i]->featured = $row->featured;
         // Get rating data from K2 Components
         $sqlRating = "SELECT * FROM #__k2_rating WHERE itemID = '" . intval($data[$i]->id) . "'  ";
         $db->setQuery($sqlRating);
         $rating = $db->loadRow();
         $data[$i]->rating = $rating;
         $image = modJacontentsliderHelper::parseImages($data[$i], $params, 'k2');
         if ($image) {
             $data[$i]->image = modJacontentsliderHelper::renderImage($row->title, $data[$i]->link, $image, $params, $params->get('iwidth'), $params->get('iheight'));
         } else {
             $data[$i]->image = '';
         }
         $data[$i] = modJacontentsliderHelper::processIntrotext($data[$i], $params->get('numchar', 0));
         $data[$i]->params = new JRegistry($data[$i]->params);
         if ($params->get('show_extra_fields', 0)) {
             $data[$i]->extra_fields = $model->getItemExtraFields($data[$i]->extra_fields, $data[$i]);
         }
     }
     return $data;
 }
Ejemplo n.º 6
0
 function getItems(&$params, $format = 'html')
 {
     jimport('joomla.filesystem.file');
     $limit = $params->get('itemCount', 5);
     $cid = $params->get('category_id', NULL);
     $ordering = $params->get('itemsOrdering', '');
     $componentParams =& JComponentHelper::getParams('com_k2');
     $limitstart = JRequest::getInt('limitstart');
     $user =& JFactory::getUser();
     $aid = $user->get('aid');
     $db =& JFactory::getDBO();
     $jnow =& JFactory::getDate();
     $now = $jnow->toMySQL();
     $nullDate = $db->getNullDate();
     if ($params->get('source') == 'specific') {
         $value = $params->get('items');
         $current = array();
         if (is_string($value) && !empty($value)) {
             $current[] = $value;
         }
         if (is_array($value)) {
             $current = $value;
         }
         $items = array();
         foreach ($current as $id) {
             $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
             $query .= " FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
             $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) . " )";
             $query .= " AND i.id={$id}";
             $db->setQuery($query);
             $item = $db->loadObject();
             if ($item) {
                 $items[] = $item;
             }
         }
     } else {
         $query = "SELECT i.*, 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 LEFT 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";
         }
         $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 ($params->get('catfilter')) {
             if (!is_null($cid)) {
                 if (is_array($cid)) {
                     if ($params->get('getChildren')) {
                         require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                         $allChildren = array();
                         foreach ($cid as $id) {
                             $categories = K2ModelItemlist::getCategoryChilds($id, true);
                             $categories[] = $id;
                             $categories = @array_unique($categories);
                             $allChildren = @array_merge($allChildren, $categories);
                         }
                         $allChildren = @array_unique($allChildren);
                         JArrayHelper::toInteger($allChildren);
                         $sql = @implode(',', $allChildren);
                         $query .= " AND i.catid IN ({$sql})";
                     } else {
                         JArrayHelper::toInteger($cid);
                         $query .= " AND i.catid IN(" . implode(',', $cid) . ")";
                     }
                 } else {
                     if ($params->get('getChildren')) {
                         require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'itemlist.php';
                         $categories = K2ModelItemlist::getCategoryChilds($cid, true);
                         $categories[] = $cid;
                         $categories = @array_unique($categories);
                         JArrayHelper::toInteger($categories);
                         $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";
         }
         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 = $datenow->toMySQL();
                     $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 = $datenow->toMySQL();
                     $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
                 }
                 $query .= " GROUP BY i.id ";
                 $orderby = 'numOfComments DESC';
                 break;
             case 'modified':
                 $orderby = 'i.modified DESC';
                 break;
             default:
                 $orderby = 'i.id DESC';
                 break;
         }
         $query .= " ORDER BY " . $orderby;
         $db->setQuery($query, 0, $limit);
         $items = $db->loadObjectList();
     }
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     if (count($items)) {
         foreach ($items as $item) {
             //Clean title
             $item->title = JFilterOutput::ampReplace($item->title);
             //Images
             if ($params->get('itemImage')) {
                 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';
                 }
                 $image = 'image' . $params->get('itemImgSize', 'Small');
                 if (isset($item->{$image})) {
                     $item->image = $item->{$image};
                 }
             }
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //Tags
             if ($params->get('itemTags')) {
                 $tags = $model->getItemTags($item->id);
                 for ($i = 0; $i < sizeof($tags); $i++) {
                     $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
                 }
                 $item->tags = $tags;
             }
             //Category link
             if ($params->get('itemCategory')) {
                 $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             }
             //Extra fields
             if ($params->get('itemExtraFields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields);
             }
             //Comments counter
             if ($params->get('itemCommentsCounter')) {
                 $item->numOfComments = $model->countItemComments($item->id);
             }
             //Attachments
             if ($params->get('itemAttachments')) {
                 $item->attachments = $model->getItemAttachments($item->id);
             }
             //Import plugins
             if ($format != 'feed') {
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
             }
             //Video
             if ($params->get('itemVideo') && $format != 'feed') {
                 $params->set('vfolder', 'media/k2/videos');
                 $item->text = $item->video;
                 $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                 $item->video = $item->text;
             }
             // Introtext
             $item->text = '';
             if ($params->get('itemIntroText')) {
                 // Word limit
                 if ($params->get('itemIntroTextWordLimit')) {
                     $item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
                 } else {
                     $item->text .= $item->introtext;
                 }
             }
             if ($format != 'feed') {
                 $params->set('parsedInModule', 1);
                 // for plugins to know when they are parsed inside this module
                 if ($params->get('JPlugins', 1)) {
                     //Plugins
                     $results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
                     $item->event->BeforeDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplayTitle = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->BeforeDisplayContent = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->AfterDisplayContent = trim(implode("\n", $results));
                     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                     $item->introtext = $item->text;
                 }
                 //Init K2 plugin events
                 $item->event->K2BeforeDisplay = '';
                 $item->event->K2AfterDisplay = '';
                 $item->event->K2AfterDisplayTitle = '';
                 $item->event->K2BeforeDisplayContent = '';
                 $item->event->K2AfterDisplayContent = '';
                 $item->event->K2CommentsCounter = '';
                 if ($params->get('K2Plugins', 1)) {
                     //K2 plugins
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayContent = trim(implode("\n", $results));
                     $dispatcher->trigger('onK2PrepareContent', array(&$item, &$params, $limitstart));
                     $item->introtext = $item->text;
                     if ($params->get('itemCommentsCounter')) {
                         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
                         $item->event->K2CommentsCounter = trim(implode("\n", $results));
                     }
                 }
             }
             //Clean the plugin tags
             $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext);
             //Author
             if ($params->get('itemAuthor')) {
                 if (!empty($item->created_by_alias)) {
                     $item->author = $item->created_by_alias;
                     $item->authorGender = NULL;
                     if ($params->get('itemAuthorAvatar')) {
                         $item->authorAvatar = K2HelperUtilities::getAvatar('alias');
                     }
                 } else {
                     $author =& JFactory::getUser($item->created_by);
                     $item->author = $author->name;
                     $query = "SELECT `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                     $db->setQuery($query, 0, 1);
                     $item->authorGender = $db->loadResult();
                     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));
                 }
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }
Ejemplo n.º 7
0
 function remove()
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     $params =& JComponentHelper::getParams('com_k2');
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'item.php';
     $itemModel = new K2ModelItem();
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('cid');
     $row =& JTable::getInstance('K2Item', 'Table');
     JPluginHelper::importPlugin('finder');
     $dispatcher = JDispatcher::getInstance();
     foreach ($cid as $id) {
         $row->load($id);
         $row->id = (int) $row->id;
         //Delete images
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg');
         }
         //Delete gallery
         if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id)) {
             JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id);
         }
         //Delete video
         preg_match_all("#^{(.*?)}(.*?){#", $row->video, $matches, PREG_PATTERN_ORDER);
         $videotype = $matches[1][0];
         $videofile = $matches[2][0];
         $videoExtensions = array('flv', 'mp4', 'ogv', 'webm', 'f4v', 'm4v', '3gp', '3g2', 'mov', 'mpeg', 'mpg', 'avi', 'wmv', 'divx', 'swf');
         $audioExtensions = array('mp3', 'aac', 'mp4', 'ogg', 'wma');
         if (in_array($videotype, $videoExtensions) || in_array($videotype, $audioExtensions)) {
             if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) {
                 JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype);
             }
             if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) {
                 JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype);
             }
         }
         //Delete attachments
         $path = $params->get('attachmentsFolder', NULL);
         if (is_null($path)) {
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
         } else {
             $savepath = $path;
         }
         $attachments = $itemModel->getAttachments($row->id);
         foreach ($attachments as $attachment) {
             if (JFile::exists($savepath . DS . $attachment->filename)) {
                 JFile::delete($savepath . DS . $attachment->filename);
             }
         }
         $query = "DELETE FROM #__k2_attachments WHERE itemID={$row->id}";
         $db->setQuery($query);
         $db->query();
         //Delete tags
         $query = "DELETE FROM #__k2_tags_xref WHERE itemID={$row->id}";
         $db->setQuery($query);
         $db->query();
         //Delete comments
         $query = "DELETE FROM #__k2_comments WHERE itemID={$row->id}";
         $db->setQuery($query);
         $db->query();
         $row->delete($id);
         $dispatcher->trigger('onFinderAfterDelete', array('com_k2.item', $row));
     }
     $cache =& JFactory::getCache('com_k2');
     $cache->clean();
     $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('K2_DELETE_COMPLETED'));
 }
Ejemplo n.º 8
0
 function remove()
 {
     $mainframe =& JFactory::getApplication();
     jimport('joomla.filesystem.file');
     $params =& JComponentHelper::getParams('com_k2');
     require_once JPATH_COMPONENT . DS . 'models' . DS . 'item.php';
     $itemModel = new K2ModelItem();
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('cid');
     $row =& JTable::getInstance('K2Item', 'Table');
     foreach ($cid as $id) {
         $row->load($id);
         //Delete images
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . md5("Image" . $row->id) . '.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg');
         }
         if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) {
             JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg');
         }
         //Delete gallery
         if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id)) {
             JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $row->id);
         }
         //Delete video
         preg_match_all("#^{(.*?)}(.*?){#", $row->video, $matches, PREG_PATTERN_ORDER);
         $videotype = $matches[1][0];
         $videofile = $matches[2][0];
         if ($videotype == 'flv' || $videotype == 'swf' || $videotype == 'wmv' || $videotype == 'mov' || $videotype == 'mp4' || $videotype == '3gp' || $videotype == 'divx') {
             if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) {
                 JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype);
             }
         }
         //Delete attachments
         $path = $params->get('attachmentsFolder', NULL);
         if (is_null($path)) {
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
         } else {
             $savepath = $path;
         }
         $attachments = $itemModel->getAttachments($row->id);
         foreach ($attachments as $attachment) {
             if (JFile::exists($savepath . DS . $attachment->filename)) {
                 JFile::delete($savepath . DS . $attachment->filename);
             }
         }
         $query = "DELETE FROM #__k2_attachments WHERE itemID={$row->id}";
         $db->setQuery($query);
         $db->query();
         //Delete tags
         $query = "DELETE FROM #__k2_tags_xref WHERE itemID={$row->id}";
         $db->setQuery($query);
         $db->query();
         $row->delete($id);
     }
     $cache =& JFactory::getCache('com_k2');
     $cache->clean();
     $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Delete Completed'));
 }
Ejemplo n.º 9
0
 public static function getItems(&$params, $format = 'html')
 {
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $limit = $params->get('itemCount', 5);
     $cid = $params->get('category_id', NULL);
     $ordering = $params->get('itemsOrdering', '');
     $componentParams = JComponentHelper::getParams('com_k2');
     $limitstart = JRequest::getInt('limitstart');
     $user = JFactory::getUser();
     $aid = $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     if ($params->get('source') == 'specific') {
         $value = $params->get('items');
         $current = array();
         if (is_string($value) && !empty($value)) {
             $current[] = $value;
         }
         if (is_array($value)) {
             $current = $value;
         }
         $items = array();
         foreach ($current as $id) {
             $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams \n\t\t\t\tFROM #__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 ";
             if (K2_JVERSION != '15') {
                 $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             } else {
                 $query .= " AND i.access<={$aid} ";
             }
             $query .= " AND i.trash = 0 AND c.published = 1 ";
             if (K2_JVERSION != '15') {
                 $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             } else {
                 $query .= " AND c.access<={$aid} ";
             }
             $query .= " AND c.trash = 0 \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) . " ) \n\t\t\t\tAND i.id={$id}";
             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('*') . ")";
                 }
             }
             $db->setQuery($query);
             $item = $db->loadObject();
             if ($item) {
                 $items[] = $item;
             }
         }
     } else {
         $query = "SELECT i.*,";
         if ($ordering == 'modified') {
             $query .= " CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged,";
         }
         $query .= "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 ($params->get('catfilter')) {
             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');
     if (count($items)) {
         foreach ($items as $item) {
             $item->event = new stdClass();
             //Clean title
             $item->title = JFilterOutput::ampReplace($item->title);
             //Images
             if ($params->get('itemImage')) {
                 $date = JFactory::getDate($item->modified);
                 $timestamp = '?t=' . $date->toUnix();
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XS.jpg')) {
                     $item->imageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XS.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageXSmall .= $timestamp;
                     }
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_S.jpg')) {
                     $item->imageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageSmall .= $timestamp;
                     }
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_M.jpg')) {
                     $item->imageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_M.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageMedium .= $timestamp;
                     }
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
                     $item->imageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_L.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageLarge .= $timestamp;
                     }
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_XL.jpg')) {
                     $item->imageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_XL.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageXLarge .= $timestamp;
                     }
                 }
                 if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_Generic.jpg')) {
                     $item->imageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $item->id) . '_Generic.jpg';
                     if ($componentParams->get('imageTimestamp')) {
                         $item->imageGeneric .= $timestamp;
                     }
                 }
                 $image = 'image' . $params->get('itemImgSize', 'Small');
                 if (isset($item->{$image})) {
                     $item->image = $item->{$image};
                 }
             }
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //Tags
             if ($params->get('itemTags')) {
                 $tags = $model->getItemTags($item->id);
                 for ($i = 0; $i < sizeof($tags); $i++) {
                     $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
                 }
                 $item->tags = $tags;
             }
             //Category link
             if ($params->get('itemCategory')) {
                 $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             }
             //Extra fields
             if ($params->get('itemExtraFields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
             }
             //Comments counter
             if ($params->get('itemCommentsCounter')) {
                 $item->numOfComments = $model->countItemComments($item->id);
             }
             //Attachments
             if ($params->get('itemAttachments')) {
                 $item->attachments = $model->getItemAttachments($item->id);
             }
             //Import plugins
             if ($format != 'feed') {
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
             }
             //Video
             if ($params->get('itemVideo') && $format != 'feed') {
                 $params->set('vfolder', 'media/k2/videos');
                 $params->set('afolder', 'media/k2/audio');
                 $item->text = $item->video;
                 if (K2_JVERSION == '15') {
                     $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                 } else {
                     $dispatcher->trigger('onContentPrepare', array('mod_k2_content.', &$item, &$params, $limitstart));
                 }
                 $item->video = $item->text;
             }
             // Introtext
             $item->text = '';
             if ($params->get('itemIntroText')) {
                 // Word limit
                 if ($params->get('itemIntroTextWordLimit')) {
                     $item->text .= K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
                 } else {
                     $item->text .= $item->introtext;
                 }
             }
             if ($format != 'feed') {
                 $params->set('parsedInModule', 1);
                 // for plugins to know when they are parsed inside this module
                 $item->event = new stdClass();
                 $item->event->BeforeDisplay = '';
                 $item->event->AfterDisplay = '';
                 $item->event->AfterDisplayTitle = '';
                 $item->event->BeforeDisplayContent = '';
                 $item->event->AfterDisplayContent = '';
                 if ($params->get('JPlugins', 1)) {
                     //Plugins
                     if (K2_JVERSION != '15') {
                         $item->event->BeforeDisplay = '';
                         $item->event->AfterDisplay = '';
                         $dispatcher->trigger('onContentPrepare', array('mod_k2_content', &$item, &$params, $limitstart));
                         $results = $dispatcher->trigger('onContentAfterTitle', array('mod_k2_content', &$item, &$params, $limitstart));
                         $item->event->AfterDisplayTitle = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onContentBeforeDisplay', array('mod_k2_content', &$item, &$params, $limitstart));
                         $item->event->BeforeDisplayContent = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onContentAfterDisplay', array('mod_k2_content', &$item, &$params, $limitstart));
                         $item->event->AfterDisplayContent = trim(implode("\n", $results));
                     } else {
                         $results = $dispatcher->trigger('onBeforeDisplay', array(&$item, &$params, $limitstart));
                         $item->event->BeforeDisplay = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onAfterDisplay', array(&$item, &$params, $limitstart));
                         $item->event->AfterDisplay = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
                         $item->event->AfterDisplayTitle = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
                         $item->event->BeforeDisplayContent = trim(implode("\n", $results));
                         $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
                         $item->event->AfterDisplayContent = trim(implode("\n", $results));
                         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
                     }
                 }
                 //Init K2 plugin events
                 $item->event->K2BeforeDisplay = '';
                 $item->event->K2AfterDisplay = '';
                 $item->event->K2AfterDisplayTitle = '';
                 $item->event->K2BeforeDisplayContent = '';
                 $item->event->K2AfterDisplayContent = '';
                 $item->event->K2CommentsCounter = '';
                 if ($params->get('K2Plugins', 1)) {
                     //K2 plugins
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplay', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplay = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                     $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$item, &$params, $limitstart));
                     $item->event->K2AfterDisplayContent = trim(implode("\n", $results));
                     $dispatcher->trigger('onK2PrepareContent', array(&$item, &$params, $limitstart));
                     if ($params->get('itemCommentsCounter')) {
                         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
                         $item->event->K2CommentsCounter = trim(implode("\n", $results));
                     }
                 }
             }
             // Restore the intotext variable after plugins execution
             $item->introtext = $item->text;
             //Clean the plugin tags
             $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext);
             //Author
             if ($params->get('itemAuthor')) {
                 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));
                 }
             }
             // Extra fields plugins
             if (is_array($item->extra_fields)) {
                 foreach ($item->extra_fields as $key => $extraField) {
                     if ($extraField->type == 'textarea' || $extraField->type == 'textfield') {
                         $tmp = new JObject();
                         $tmp->text = $extraField->value;
                         if ($params->get('JPlugins', 1)) {
                             if (K2_JVERSION != '15') {
                                 $dispatcher->trigger('onContentPrepare', array('mod_k2_content', &$tmp, &$params, $limitstart));
                             } else {
                                 $dispatcher->trigger('onPrepareContent', array(&$tmp, &$params, $limitstart));
                             }
                         }
                         if ($params->get('K2Plugins', 1)) {
                             $dispatcher->trigger('onK2PrepareContent', array(&$tmp, &$params, $limitstart));
                         }
                         $extraField->value = $tmp->text;
                     }
                 }
             }
             $A = new K2ModelItem();
             $item->votingPercentage = $A->getVotesPercentage($item->id);
             $item->numOfvotes = $A->getVotesNum($item->id);
             $rows[] = $item;
         }
         return $rows;
     }
 }
Ejemplo n.º 10
0
 function download()
 {
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     $model->download(true);
 }
Ejemplo n.º 11
0
    function edit()
    {
        $mainframe =& JFactory::getApplication();
        jimport('joomla.filesystem.file');
        jimport('joomla.html.pane');
        $db =& JFactory::getDBO();
        JHTML::_('behavior.mootools');
        $document =& JFactory::getDocument();
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/Autocompleter.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/observer.js');
        $document->addScript(JURI::root() . 'administrator/components/com_k2/lib/simpletabs_1.3.js');
        //$document->addScript(JURI::root().'administrator/components/com_k2/js/k2.js'); // Core JS
        $document->addScript(JURI::root() . 'administrator/components/com_k2/js/k2.mootools.js');
        // Mootools based JS
        $document->addCustomTag('
        
<!-- K2 by JoomlaWorks (start) -->
		
	<!-- Load Khepri styling -->
	<link rel="stylesheet" href="' . JURI::root() . 'administrator/templates/system/css/system.css" type="text/css" />
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/template.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/templates/khepri/css/ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="' . JURI::root() . 'administrator/templates/khepri/css/rounded.css" />
	
	<!-- Load K2 styling -->
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2.css" rel="stylesheet" type="text/css" />
	<!--[if IE 7]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie7.css" rel="stylesheet" type="text/css" />
	<![endif]-->
	<!--[if lte IE 6]>
	<link href="' . JURI::root() . 'administrator/components/com_k2/css/k2_ie6.css" rel="stylesheet" type="text/css" />
	<![endif]-->
		
<!-- K2 by JoomlaWorks (end) -->

		');
        JRequest::setVar('tmpl', 'component');
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
        $model = new K2ModelItem();
        $task = JRequest::getCmd('task');
        $user =& JFactory::getUser();
        if ($task == 'edit') {
            $item = $model->getData();
            JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'video');
            if (!K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            if (JTable::isCheckedOut($user->get('id'), $item->checked_out)) {
                $msg = JText::sprintf('DESCBEINGEDITTED', JText::_('The item'), $item->title);
                $mainframe->redirect('index.php?option=com_k2&view=item&id=' . $item->id . '&tmpl=component', $msg);
            }
        } elseif ($task == 'add') {
            if (!K2HelperPermissions::canAddItem()) {
                JError::raiseError(403, JText::_("ALERTNOTAUTH"));
            }
            JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
            $item =& JTable::getInstance('K2Item', 'Table');
            $createdate =& JFactory::getDate();
            $item->published = 1;
            $item->publish_up = $createdate->toUnix();
            $item->publish_down = JText::_('Never');
            $item->created = $createdate->toUnix();
            $item->modified = $db->getNullDate();
        }
        if ($item->id) {
            $item->checkout($user->get('id'));
        }
        $item->created = JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S');
        $item->publish_up = JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S');
        if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate()) {
            $item->publish_down = JText::_('Never');
        } else {
            $item->publish_down = JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S');
        }
        $params =& JComponentHelper::getParams('com_k2');
        $wysiwyg =& JFactory::getEditor();
        if ($params->get("mergeEditors")) {
            if (JString::strlen($item->fulltext) > 1) {
                $textValue = $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext;
            } else {
                $textValue = $item->introtext;
            }
            $text = $wysiwyg->display('text', $textValue, '100%', '400', '40', '5', array('pagebreak'));
            $this->assignRef('text', $text);
        } else {
            $introtext = $wysiwyg->display('introtext', $item->introtext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('introtext', $introtext);
            $fulltext = $wysiwyg->display('fulltext', $item->fulltext, '100%', '400', '40', '5', array('pagebreak', 'readmore'));
            $this->assignRef('fulltext', $fulltext);
        }
        $lists = array();
        $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
        $lists['access'] = JHTML::_('list.accesslevel', $item);
        $query = "SELECT ordering AS value, title AS text FROM #__k2_items WHERE catid={$item->catid}";
        $lists['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories = $categoriesModel->categoriesTree();
        $lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox"', 'value', 'text', $item->catid);
        $lists['checkSIG'] = $model->checkSIG();
        $lists['checkAllVideos'] = $model->checkAllVideos();
        $remoteVideo = false;
        $providerVideo = false;
        $embedVideo = false;
        $options['startOffset'] = 0;
        if (stristr($item->video, 'remote}') !== false) {
            $remoteVideo = true;
            $options['startOffset'] = 1;
        }
        $providers = $model->getVideoProviders();
        if (count($providers)) {
            foreach ($providers as $provider) {
                $providersOptions[] = JHTML::_('select.option', $provider, $provider);
                if (stristr($item->video, "{{$provider}}") !== false) {
                    $providerVideo = true;
                    $options['startOffset'] = 2;
                }
            }
        }
        if (JString::substr($item->video, 0, 1) !== '{') {
            $embedVideo = true;
            $options['startOffset'] = 3;
        }
        $lists['uploadedVideo'] = !$remoteVideo && !$providerVideo && !$embedVideo ? true : false;
        if ($lists['uploadedVideo']) {
            $options['startOffset'] = 0;
        }
        $lists['remoteVideo'] = $remoteVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['remoteVideoType'] = $remoteVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideo'] = $providerVideo ? preg_replace('%\\{[a-z0-9-_]*\\}(.*)\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['providerVideoType'] = $providerVideo ? preg_replace('%\\{([a-z0-9-_]*)\\}.*\\{/[a-z0-9-_]*\\}%i', '\\1', $item->video) : '';
        $lists['embedVideo'] = $embedVideo ? $item->video : '';
        if (count($providers)) {
            $lists['providers'] = JHTML::_('select.genericlist', $providersOptions, 'videoProvider', '', 'value', 'text', $lists['providerVideoType']);
        }
        JPluginHelper::importPlugin('content', 'jw_sigpro');
        JPluginHelper::importPlugin('content', 'jw_sig');
        JPluginHelper::importPlugin('content', 'jw_allvideos');
        $dispatcher =& JDispatcher::getInstance();
        $params->set('galleries_rootfolder', 'media/k2/galleries');
        $params->set('thb_width', '150');
        $params->set('thb_height', '120');
        $params->set('popup_engine', 'mootools_slimbox');
        $params->set('enabledownload', '0');
        $item->text = $item->gallery;
        $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
        $item->gallery = $item->text;
        if (!$embedVideo) {
            $params->set('vfolder', 'media/k2/videos');
            $item->text = $item->video;
            $dispatcher->trigger('onPrepareContent', array(&$item, &$params, null));
            $item->video = $item->text;
        } else {
            $item->video = '<div>' . $item->video . '</div>';
        }
        if (isset($item->created_by)) {
            $author =& JUser::getInstance($item->created_by);
            $item->author = $author->name;
        }
        if (isset($item->modified_by)) {
            $moderator =& JUser::getInstance($item->modified_by);
            $item->moderator = $moderator->name;
        }
        if ($task == 'edit') {
            $item->editor = $item->author;
        } else {
            $item->editor = $user->name;
        }
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'categories.php';
        $categoriesModel = new K2ModelCategories();
        $categories_option[] = JHTML::_('select.option', 0, JText::_('- Select category -'));
        $categories = $categoriesModel->categoriesTree();
        if (($task == 'add' || $task == 'edit') && !$user->authorize('com_k2', 'add', 'category', 'all')) {
            for ($i = 0; $i < sizeof($categories); $i++) {
                if (!$user->authorize('com_k2', 'add', 'category', $categories[$i]->value)) {
                    $categories[$i]->disable = true;
                }
            }
        }
        $categories_options = @array_merge($categories_option, $categories);
        $lists['categories'] = JHTML::_('select.genericlist', $categories_options, 'catid', '', 'value', 'text', $item->catid);
        JTable::addIncludePath(JPATH_COMPONENT . DS . 'tables');
        $category =& JTable::getInstance('K2Category', 'Table');
        $category->load($item->catid);
        require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php';
        $extraFieldModel = new K2ModelExtraField();
        if ($category->extraFieldsGroup) {
            $extraFields = $extraFieldModel->getExtraFieldsByGroup($category->extraFieldsGroup);
        } else {
            $extraFields = NULL;
        }
        for ($i = 0; $i < sizeof($extraFields); $i++) {
            $extraFields[$i]->element = $extraFieldModel->renderExtraField($extraFields[$i], $item->id);
        }
        if ($item->id) {
            $item->attachments = $model->getAttachments($item->id);
        } else {
            $item->attachments = NULL;
        }
        $tags = $model->getAvailableTags($item->id);
        $lists['tags'] = JHTML::_('select.genericlist', $tags, 'tags', 'multiple="multiple" size="10" ', 'id', 'name');
        if (isset($item->id)) {
            $item->tags = $model->getCurrentTags($item->id);
            $lists['selectedTags'] = JHTML::_('select.genericlist', $item->tags, 'selectedTags[]', 'multiple="multiple" size="10" ', 'id', 'name');
        } else {
            $lists['selectedTags'] = '<select size="10" multiple="multiple" id="selectedTags" name="selectedTags[]"></select>';
        }
        if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $item->id) . '_L.jpg')) {
            $item->image = 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) . '_S.jpg')) {
            $item->thumb = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $item->id) . '_S.jpg';
        }
        $lists['metadata'] = new JParameter($item->metadata);
        JPluginHelper::importPlugin('k2');
        $dispatcher =& JDispatcher::getInstance();
        $K2PluginsItemContent = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'content'));
        $this->assignRef('K2PluginsItemContent', $K2PluginsItemContent);
        $K2PluginsItemImage = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'image'));
        $this->assignRef('K2PluginsItemImage', $K2PluginsItemImage);
        $K2PluginsItemGallery = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'gallery'));
        $this->assignRef('K2PluginsItemGallery', $K2PluginsItemGallery);
        $K2PluginsItemVideo = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'video'));
        $this->assignRef('K2PluginsItemVideo', $K2PluginsItemVideo);
        $K2PluginsItemExtraFields = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'extra-fields'));
        $this->assignRef('K2PluginsItemExtraFields', $K2PluginsItemExtraFields);
        $K2PluginsItemAttachments = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'attachments'));
        $this->assignRef('K2PluginsItemAttachments', $K2PluginsItemAttachments);
        $K2PluginsItemOther = $dispatcher->trigger('onRenderAdminForm', array(&$item, 'item', 'other'));
        $this->assignRef('K2PluginsItemOther', $K2PluginsItemOther);
        $form = new JParameter('', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.xml');
        $form->loadINI($item->params);
        $this->assignRef('form', $form);
        $this->assignRef('extraFields', $extraFields);
        $this->assignRef('options', $options);
        $this->assignRef('row', $item);
        $this->assignRef('lists', $lists);
        $this->assignRef('params', $params);
        parent::display();
    }
Ejemplo n.º 12
0
 function getData($number)
 {
     nextendimport('nextend.database.database');
     $db = NextendDatabase::getInstance();
     $data = array();
     $category = array_map('intval', explode('||', $this->_data->get('k2itemssourcecategory', '')));
     $query = 'SELECT ';
     $query .= 'con.id, ';
     $query .= 'con.title, ';
     $query .= 'con.alias, ';
     $query .= 'con.introtext, ';
     $query .= 'con.fulltext, ';
     $query .= 'con.catid, ';
     $query .= 'cat.name AS cat_title, ';
     $query .= 'cat.alias AS cat_alias, ';
     $query .= 'con.created_by, ';
     $query .= 'usr.name AS created_by_alias, ';
     $query .= 'con.hits, ';
     $query .= 'con.image_caption, ';
     $query .= 'con.image_credits, ';
     $query .= 'con.extra_fields ';
     $query .= 'FROM #__k2_items AS con ';
     $query .= 'LEFT JOIN #__users AS usr ON usr.id = con.created_by ';
     $query .= 'LEFT JOIN #__k2_categories AS cat ON cat.id = con.catid ';
     $query .= 'WHERE con.catid IN (' . implode(',', $category) . ') ';
     $sourceuserid = intval($this->_data->get('k2itemssourceuserid', ''));
     if ($sourceuserid) {
         $query .= 'AND con.created_by = ' . $sourceuserid . ' ';
     }
     if ($this->_data->get('k2itemssourcepublished', 1)) {
         $jnow = JFactory::getDate();
         $now = version_compare(JVERSION, '1.6.0', '<') ? $jnow->toMySQL() : $jnow->toSql();
         $query .= "AND con.published = 1 AND (con.publish_up = '0000-00-00 00:00:00' OR con.publish_up < '" . $now . "') AND (con.publish_down = '0000-00-00 00:00:00' OR con.publish_down > '" . $now . "') ";
     }
     $query .= 'AND con.trash = 0 ';
     if ($this->_data->get('k2itemssourcefeatured', 0)) {
         $query .= 'AND con.featured = 1 ';
     }
     $language = $this->_data->get('k2itemssourcelanguage', '*');
     if ($language) {
         $query .= 'AND con.language = ' . $db->quote($language) . ' ';
     }
     $order = NextendParse::parse($this->_data->get('k2itemsorder1', 'con.title|*|asc'));
     if ($order[0]) {
         $query .= 'ORDER BY ' . $order[0] . ' ' . $order[1] . ' ';
         $order = NextendParse::parse($this->_data->get('k2itemsorder2', 'con.title|*|asc'));
         if ($order[0]) {
             $query .= ', ' . $order[0] . ' ' . $order[1] . ' ';
         }
     }
     $query .= 'LIMIT 0, ' . $number . ' ';
     $db->setQuery($query);
     $result = $db->loadAssocList();
     $this->loadExtraFields();
     require_once JPATH_SITE . '/components/com_k2/helpers/utilities.php';
     require_once JPATH_SITE . '/components/com_k2/models/item.php';
     $k2item = new K2ModelItem();
     for ($i = 0; $i < count($result); $i++) {
         $result[$i]['url'] = 'index.php?option=com_k2&view=item&id=' . $result[$i]['id'] . ':' . $result[$i]['alias'];
         $result[$i]['categoryurl'] = 'index.php?option=com_k2&view=itemlist&task=category&id=' . $result[$i]['catid'] . ':' . $result[$i]['cat_alias'];
         $result[$i]['thumbnail'] = $result[$i]['image'] = "media/k2/items/cache/" . md5("Image" . $result[$i]['id']) . "_XL.jpg";
         if (!NextendFilesystem::fileexists(JPATH_SITE . '/' . $result[$i]['image'])) {
             $result[$i]['thumbnail'] = $result[$i]['image'] = '';
         }
         $result[$i]['description'] = $result[$i]['introtext'];
         $result[$i]['url_label'] = 'View article';
         $result[$i]['author_name'] = $result[$i]['created_by_alias'];
         $result[$i]['author_url'] = '#';
         $item = (object) $result[$i];
         $extras = $k2item->getItemExtraFields($result[$i]['extra_fields'], $item);
         if (is_array($extras) && count($extras) > 0) {
             foreach ($extras as $field) {
                 $result[$i]['extra' . $field->id . '_' . preg_replace("/\\W|_/", "", $this->extraFields[$field->id]['group_name'] . '_' . $this->extraFields[$field->id]['name'])] = $field->value;
             }
         }
     }
     return $result;
 }
Ejemplo n.º 13
0
				  <?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 
            }
Ejemplo n.º 14
0
 public static function getList(&$params)
 {
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $limit = $params->get('itemCount', 5) * 3;
     $cid = $params->get('category_id', NULL);
     $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();
     if ($params->get('source') == 'specific') {
         $value = $params->get('items');
         $current = array();
         if (is_string($value) && !empty($value)) {
             $current[] = $value;
         }
         if (is_array($value)) {
             $current = $value;
         }
         $items = array();
         foreach ($current as $id) {
             $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams\n\t\t\t\tFROM #__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 ";
             if (K2_JVERSION != '15') {
                 $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             } else {
                 $query .= " AND i.access<={$aid} ";
             }
             $query .= " AND i.trash = 0 AND c.published = 1 ";
             if (K2_JVERSION != '15') {
                 $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             } else {
                 $query .= " AND c.access<={$aid} ";
             }
             $query .= " AND c.trash = 0\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) . " )\n\t\t\t\tAND i.id={$id}";
             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('*') . ")";
                 }
             }
             $db->setQuery($query);
             $item = $db->loadObject();
             if ($item) {
                 $items[] = $item;
             }
         }
     } else {
         $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 ($params->get('catfilter')) {
             if (is_null($cid)) {
                 return;
             }
             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 'id':
                 $orderby = 'i.id ASC';
                 break;
             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);
     if (count($items)) {
         $rows = array();
         foreach ($items as $item) {
             $item->cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->categoryid . ':' . urlencode($item->categoryalias))));
             //Clean title
             $item->title = JFilterOutput::ampReplace($item->title);
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //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;
             } else {
                 $item->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) : '';
             //Comments counter
             if ($params->get('itemCommentsCounter')) {
                 $item->numOfComments = $model->countItemComments($item->id);
             }
             //author
             $item->author = JFactory::getUser($item->created_by)->name;
             $vote = new K2ModelItem();
             $item->votingPercentage = $vote->getVotesPercentage($item->id);
             $item->numOfvotes = $vote->getVotesNum($item->id);
             $rows[] = $item;
         }
         return $rows;
     }
 }
Ejemplo n.º 15
0
 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;
 }
Ejemplo n.º 16
0
 function resetRating()
 {
     JRequest::checkToken() or jexit('Invalid Token');
     JRequest::setVar('tmpl', 'component');
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     $model->resetRating();
 }
Ejemplo n.º 17
0
 function getVotesPercentage($itemID = NULL)
 {
     $mainframe =& JFactory::getApplication();
     $user = JFactory::getUser();
     $db =& JFactory::getDBO();
     $xhr = false;
     $result = 0;
     if (is_null($itemID)) {
         $itemID = JRequest::getInt('itemID');
         $xhr = true;
     }
     $vote = K2ModelItem::getRating($itemID);
     if (!is_null($vote) && $vote->rating_count != 0) {
         $result = number_format(intval($vote->rating_sum) / intval($vote->rating_count), 2) * 20;
     }
     if ($xhr) {
         echo $result;
         $mainframe->close();
     } else {
         return $result;
     }
 }
Ejemplo n.º 18
0
<?php
Ejemplo n.º 19
0
 public static function getList($params, $count)
 {
     $catids = $params->get('k2catids', array());
     $ordering = $params->get('ordering', 'a.ordering');
     $ordering_direction = $params->get('ordering_direction', 'ASC');
     $user_id = $params->get('user_id');
     $show_featured = $params->get('show_featured');
     $user = JFactory::getUser();
     $aid = $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = $jnow->toSql();
     $nullDate = $db->getNullDate();
     $query = "SELECT a.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams" . " FROM #__k2_items as a" . " LEFT JOIN #__k2_categories c ON c.id = a.catid";
     $query .= " WHERE a.published = 1 AND a.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND a.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ")  AND c.trash = 0";
     // User filter
     $userId = JFactory::getUser()->get('id');
     switch ($params->get('user_id')) {
         case 'by_me':
             $query .= ' AND (a.created_by = ' . (int) $userId . ' OR a.modified_by = ' . (int) $userId . ')';
             break;
         case 'not_me':
             $query .= ' AND (a.created_by <> ' . (int) $userId . ' AND a.modified_by <> ' . (int) $userId . ')';
             break;
         case '0':
             break;
         default:
             $query .= ' AND (a.created_by = ' . (int) $userId . ' OR a.modified_by = ' . (int) $userId . ')';
             break;
     }
     //Added Category
     if (!is_null($catids)) {
         if (is_array($catids)) {
             JArrayHelper::toInteger($catids);
             $query .= " AND a.catid IN(" . implode(',', $catids) . ")";
         } else {
             $query .= " AND a.catid=" . (int) $catids;
         }
     }
     //  Featured items filter
     if ($show_featured == '0') {
         $query .= " AND a.featured != 1";
     }
     if ($show_featured == '1') {
         $query .= " AND a.featured = 1";
     }
     // ensure should be published
     $query .= " AND ( a.publish_up = " . $db->Quote($nullDate) . " OR a.publish_up <= " . $db->Quote($now) . " )";
     $query .= " AND ( a.publish_down = " . $db->Quote($nullDate) . " OR a.publish_down >= " . $db->Quote($now) . " )";
     //Ordering
     $orderby = $ordering . ' ' . $ordering_direction;
     //ordering
     $query .= " ORDER BY " . $orderby;
     $db->setQuery($query, 0, $count);
     $items = $db->loadObjectList();
     require_once JPATH_SITE . '/components/com_k2/models/item.php';
     $model = new K2ModelItem();
     if (count($items)) {
         foreach ($items as $item) {
             if (!empty($item->created_by_alias)) {
                 $item->author = $item->created_by_alias;
             } else {
                 $author = JFactory::getUser($item->created_by);
                 $item->author = $author->name;
             }
             $item->created = $item->created;
             $item->hits = $item->hits;
             $item->category = $item->categoryname;
             $item->cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             $item->image = self::getImage($item->id, $item->introtext);
             $item->title = htmlspecialchars($item->title);
             $item->introtext = $item->introtext;
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             $item->comment = '<a class="ns2-comments" href="' . $item->link . '#itemCommentsAnchor">' . JText::_('COMMENTS_TEXT') . ' (' . $model->countItemComments($item->id) . ')</a>';
             $item->rating = $model->getVotesPercentage($item->id);
             if ($params->get('article_extra_fields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }