Esempio n. 1
0
 /**
  * Retrieves the profile link
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return	
  */
 public function getLink()
 {
     if (!$this->exists()) {
         return parent::getLink();
     }
     $link = K2HelperRoute::getUserRoute($this->profile->id);
     return $link;
 }
Esempio n. 2
0
 function getAuthors(&$params)
 {
     $componentParams =& JComponentHelper::getParams('com_k2');
     $where = '';
     $cid = $params->get('authors_module_category');
     if ($cid > 0) {
         $categories = modK2ToolsHelper::getCategoryChildren($cid);
         $categories[] = $cid;
         JArrayHelper::toInteger($categories);
         $where = " catid IN(" . implode(',', $categories) . ") AND ";
     }
     $user =& JFactory::getUser();
     $aid = (int) $user->get('aid');
     $db =& JFactory::getDBO();
     $jnow =& JFactory::getDate();
     $now = $jnow->toMySQL();
     $nullDate = $db->getNullDate();
     $query = "SELECT DISTINCT created_by FROM #__k2_items  WHERE {$where} published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     $authors = array();
     if (count($rows)) {
         foreach ($rows as $row) {
             $author = JFactory::getUser($row->created_by);
             $author->link = JRoute::_(K2HelperRoute::getUserRoute($author->id));
             $query = "SELECT id, gender, description, image, url, `group`, plugins FROM #__k2_users WHERE userID=" . (int) $author->id;
             $db->setQuery($query);
             $author->profile = $db->loadObject();
             if ($params->get('authorAvatar')) {
                 $author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth'));
             }
             $query = "SELECT i.*, c.alias as categoryalias FROM #__k2_items as i\n        LEFT JOIN #__k2_categories c ON c.id = i.catid\n        WHERE i.created_by = " . (int) $author->id . "\n        AND i.published = 1\n        AND i.access <= {$aid}\n        AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n        AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n        AND i.trash = 0 AND created_by_alias='' AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0 ORDER BY created DESC";
             $db->setQuery($query, 0, 1);
             $author->latest = $db->loadObject();
             $author->latest->id = (int) $author->latest->id;
             $author->latest->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($author->latest->id . ':' . urlencode($author->latest->alias), $author->latest->catid . ':' . urlencode($author->latest->categoryalias))));
             $query = "SELECT COUNT(*) FROM #__k2_comments WHERE published=1 AND itemID={$author->latest->id}";
             $db->setQuery($query);
             $author->latest->numOfComments = $db->loadResult();
             if ($params->get('authorItemsCounter')) {
                 $query = "SELECT COUNT(*) FROM #__k2_items  WHERE {$where} published=1 AND ( publish_up = " . $db->Quote($nullDate) . " OR publish_up <= " . $db->Quote($now) . " ) AND ( publish_down = " . $db->Quote($nullDate) . " OR publish_down >= " . $db->Quote($now) . " ) AND trash=0 AND access<={$aid} AND created_by_alias='' AND created_by={$row->created_by} AND EXISTS (SELECT * FROM #__k2_categories WHERE id= #__k2_items.catid AND published=1 AND trash=0 AND access<={$aid} )";
                 $db->setQuery($query);
                 $numofitems = $db->loadResult();
                 $author->items = $numofitems;
             }
             $authors[] = $author;
         }
     }
     return $authors;
 }
Esempio n. 3
0
 public function go($allGet)
 {
     $uri = JUri::getInstance();
     $currentLink = $uri->toString(array('path', 'query'));
     $start = JFactory::getApplication()->input->getInt('start', 0);
     JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_k2/tables');
     $limitstring = '';
     if ($start > 0) {
         $limits = $this->params->get('limits', 5);
         if ($start % $limits != 0) {
             $start = intval($start / $limits) * $limits;
         }
         $limitstring .= "?start=" . $start;
     }
     if ($allGet['view'] == 'item' && $allGet['task'] == '') {
         $item = JTable::getInstance('K2Item', 'Table');
         $item->load($allGet['id']);
         $category = JTable::getInstance('K2Category', 'Table');
         $category->load($item->catid);
         $original_link = JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($category->alias)), false);
     } else {
         if ($allGet['view'] == 'itemlist' && $allGet['task'] == 'category') {
             $category = JTable::getInstance('K2Category', 'Table');
             $category->load((int) $allGet['id']);
             $original_link = JRoute::_(K2HelperRoute::getCategoryRoute((int) $allGet['id'] . ':' . urlencode($category->alias)), false) . $limitstring;
         } else {
             if ($allGet['view'] == 'itemlist' && $allGet['task'] == 'user') {
                 $original_link = JRoute::_(K2HelperRoute::getUserRoute((int) $allGet['id']), false) . $limitstring;
             } else {
                 return false;
             }
         }
     }
     if ($original_link && $original_link != $currentLink) {
         $this->shRedirect($original_link);
     }
     return true;
 }
Esempio 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 = 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;
 }
Esempio n. 5
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $params =& JComponentHelper::getParams('com_k2');
     $user =& JFactory::getUser();
     $cache =& JFactory::getCache('com_k2_extended');
     $limit = $params->get('latestItemsLimit', 3);
     $limitstart = JRequest::getInt('limitstart');
     $model =& $this->getModel('itemlist');
     $itemModel =& $this->getModel('item');
     if ($params->get('source')) {
         $categoryIDs = $params->get('categoryIDs');
         if (is_string($categoryIDs) && !empty($categoryIDs)) {
             $categoryIDs = array();
             $categoryIDs[] = $params->get('$categoryIDs');
         }
         $categories = array();
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables');
         foreach ($categoryIDs as $categoryID) {
             $category =& JTable::getInstance('K2Category', 'Table');
             $category->load($categoryID);
             if ($category->published && $category->access <= $user->get('aid', 0)) {
                 //Merge params
                 $cparams = new JParameter($category->params);
                 if ($cparams->get('inheritFrom')) {
                     $masterCategory =& JTable::getInstance('K2Category', 'Table');
                     $masterCategory->load($cparams->get('inheritFrom'));
                     $cparams = new JParameter($masterCategory->params);
                 }
                 $params->merge($cparams);
                 //Category image
                 if (!empty($category->image)) {
                     $category->image = JURI::root() . 'media/k2/categories/' . $category->image;
                 } else {
                     if ($params->get('catImageDefault')) {
                         $category->image = JURI::root() . 'components/com_k2/images/placeholder/category.png';
                     }
                 }
                 //Category plugins
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
                 $category->text = $category->description;
                 $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
                 $category->description = $category->text;
                 //Category K2 plugins
                 $category->event->K2CategoryDisplay = '';
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
                 $category->event->K2CategoryDisplay = trim(implode("\n", $results));
                 $category->text = $category->description;
                 $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
                 $category->description = $category->text;
                 //Category link
                 $link = urldecode(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias)));
                 $category->link = JRoute::_($link);
                 $category->feed = JRoute::_($link . '&format=feed');
                 JRequest::setVar('view', 'itemlist');
                 JRequest::setVar('task', 'category');
                 JRequest::setVar('id', $category->id);
                 JRequest::setVar('featured', 1);
                 JRequest::setVar('limit', $limit);
                 $category->items = $model->getData('rdate');
                 JRequest::setVar('view', 'latest');
                 JRequest::setVar('task', '');
                 for ($i = 0; $i < sizeof($category->items); $i++) {
                     if ($user->guest) {
                         $hits = $category->items[$i]->hits;
                         $category->items[$i]->hits = 0;
                         $category->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $category->items[$i], 'latest', '');
                         $category->items[$i]->hits = $hits;
                     } else {
                         $category->items[$i] = $itemModel->prepareItem($category->items[$i], 'latest', '');
                     }
                 }
                 $categories[] = $category;
             }
         }
         $source = 'categories';
         $this->assignRef('blocks', $categories);
     } else {
         $usersIDs = $params->get('userIDs');
         if (is_string($usersIDs) && !empty($usersIDs)) {
             $usersIDs = array();
             $usersIDs[] = $params->get('userIDs');
         }
         $users = array();
         foreach ($usersIDs as $userID) {
             $userObject = JFactory::getUser($userID);
             if (!$userObject->block) {
                 //User profile
                 $userObject->profile = $model->getUserProfile($userID);
                 //User image
                 $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
                 //User K2 plugins
                 $userObject->event->K2UserDisplay = '';
                 if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                     $dispatcher =& JDispatcher::getInstance();
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                     $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                 }
                 $link = K2HelperRoute::getUserRoute($userObject->id);
                 $userObject->link = JRoute::_($link);
                 $userObject->feed = JRoute::_($link . '&format=feed');
                 $userObject->items = $model->getAuthorLatest(0, $limit, $userID);
                 for ($i = 0; $i < sizeof($userObject->items); $i++) {
                     if ($user->guest) {
                         $hits = $userObject->items[$i]->hits;
                         $userObject->items[$i]->hits = 0;
                         $userObject->items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $userObject->items[$i], 'latest', '');
                         $userObject->items[$i]->hits = $hits;
                     } else {
                         $userObject->items[$i] = $itemModel->prepareItem($userObject->items[$i], 'latest', '');
                     }
                 }
                 $users[] = $userObject;
             }
         }
         $source = 'users';
         $this->assignRef('blocks', $users);
     }
     //Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     //Assign params
     $this->assignRef('params', $params);
     $this->assignRef('source', $source);
     //Set layout
     $this->setLayout('latest');
     //Display
     parent::display($tpl);
 }
Esempio n. 6
0
File: k2.php Progetto: Tommar/vino
 /**
  * get the list of k2 items
  *
  * @param JParameter $params;
  * @return Array
  */
 public function getList()
 {
     // check k2 existing
     if (!is_file(JPATH_SITE . "/components/com_k2/k2.php")) {
         return array();
     }
     $params =& $this->_params;
     // Init vars
     $show_title = $params->get('show_title', 1);
     $titleMaxChars = $params->get('title_max_chars', '100');
     $limit_title_by = $params->get('limit_title_by', 'char');
     $replacer = $params->get('replacer', '...');
     $isStrips = $params->get("auto_strip_tags", 1);
     $stringtags = '';
     if ($isStrips) {
         $allow_tags = $params->get("allow_tags", '');
         $stringtags = '';
         if (!is_array($allow_tags)) {
             $allow_tags = explode(',', $allow_tags);
         }
         foreach ($allow_tags as $tag) {
             $stringtags .= '<' . $tag . '>';
         }
     }
     if (!$params->get('default_thumb', 1)) {
         $this->_defaultThumb = '';
     }
     /* intro */
     $show_intro = $params->get('show_intro', 1);
     $maxDesciption = $params->get('description_max_chars', 100);
     $limitDescriptionBy = $params->get('limit_description_by', 'char');
     $ordering = $params->get('ordering', 'created-desc');
     $limit = $params->get('limit_items', 12);
     // Set ordering
     $ordering = explode('-', $ordering);
     if (trim($ordering[0]) == 'rand') {
         $ordering = ' RAND() ';
     } else {
         $ordering = $ordering[0] . ' ' . $ordering[1];
     }
     $user = JFactory::getUser();
     $isThumb = $params->get('image_thumb', 1);
     $thumbWidth = (int) $params->get('thumbnail_width', 280);
     $thumbHeight = (int) $params->get('thumbnail_height', 150);
     $quality = (int) $params->get('image_quality', 80);
     $db = JFactory::getDBO();
     $date = JFactory::getDate();
     $now = $date->toSQL();
     $dateFormat = $params->get('date_format', 'DATE_FORMAT_LC3');
     $show_author = $params->get('show_author', 0);
     // main query
     $query = "SELECT  a.*, c.name as category_title,\n\t\t\t\t\t\tc.id as categoryid, c.alias as categoryalias, c.params as categoryparams, c.image as category_image" . " 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 ";
     // filter by user
     $userId = $user->get('id');
     switch ($params->get('user_id')) {
         case 'by_me':
             $query .= 'AND a.created_by = ' . $userId;
             break;
         case 'not_me':
             $query .= 'AND a.created_by != ' . $userId;
             break;
         case 0:
             break;
         default:
             $query .= 'AND a.created_by = ' . $userId;
             break;
     }
     // filter by featured params
     if ($params->get('show_featured', '1') == 2) {
         $query .= " AND a.featured != 1";
     } elseif ($params->get('show_featured', '1') == 3) {
         $query .= " AND a.featured = 1";
     }
     // valid publish date
     $jnow = JFactory::getDate();
     $now = $jnow->toSql();
     $nullDate = $db->getNullDate();
     $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) . " )";
     //filter by language
     $languageTag = JFactory::getLanguage()->getTag();
     $query .= " AND a.language IN (" . $db->quote($languageTag) . "," . $db->quote('*') . ") AND c.language IN (" . $db->quote($languageTag) . "," . $db->quote('*') . ")";
     //Get data
     $data = array();
     $source = trim($this->_params->get('source', 'k2_category'));
     $catids = self::getCategoryIds();
     if ($source == 'k2_category' && !empty($catids) && $this->_params->get('limit_items_for_each')) {
         $db->setQuery('SELECT id from #__k2_categories where id in (' . implode($catids, ',') . ') order by ordering');
         $catids = $db->loadColumn();
         foreach ($catids as $catid) {
             $condition = ' AND  a.catid = ' . $catid . ' ';
             $db->setQuery($query . $condition . ' ORDER BY ' . $ordering . ($limit ? ' LIMIT ' . $limit : ''));
             $data = array_merge($data, $db->loadObjectlist());
         }
     } else {
         $condition = $this->buildConditionQuery($source, $catids);
         $db->setQuery($query . $condition . ' ORDER BY ' . $ordering . ($limit ? ' LIMIT ' . $limit : ''));
         $data = array_merge($data, $db->loadObjectlist());
     }
     // Rebuild data
     foreach ($data as $key => &$item) {
         // authorise
         if (in_array($item->access, $user->getAuthorisedViewLevels())) {
             $item->link = JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid . ':' . $item->categoryalias));
         } else {
             $item->link = JRoute::_('index.php?option=com_users&view=login');
         }
         // format date
         $item->date = JHtml::_('date', $item->created, JText::_($dateFormat));
         //cut title
         if ($limit_title_by == 'word' && $titleMaxChars > 0) {
             $item->title_cut = self::substrword($item->title, $titleMaxChars, $replacer, $isStrips);
         } elseif ($limit_title_by == 'char' && $titleMaxChars > 0) {
             $item->title_cut = self::substring($item->title, $titleMaxChars, $replacer, $isStrips);
         }
         // escape html characters
         $item->title = htmlspecialchars($item->title);
         // import joomla content prepare plugin
         if ($params->get('content_plugin')) {
             $item->introtext = JHtml::_('content.prepare', $item->introtext);
         }
         // cut introtext
         if ($limitDescriptionBy == 'word') {
             $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
         } else {
             $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
         }
         $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
         // get author name & link
         if ($show_author) {
             if (!empty($item->created_by_alias)) {
                 $item->author = $item->created_by_alias;
             } else {
                 $author = JFactory::getUser($item->created_by);
                 $item->author = $author->name;
             }
             $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
         }
         // make thumbnail
         $item->thumbnail = '';
         $item->mainImage = '';
         if ($params->get('show_image')) {
             $item = $this->generateImages($item, $isThumb, $quality);
         }
         //get extrafields
         $showExtrafields = $params->get('show_extrafields', array());
         if (count($showExtrafields) && $item->extra_fields) {
             $item->extra_fields = json_decode($item->extra_fields);
             if (count($item->extra_fields)) {
                 $exIds = array();
                 foreach ($item->extra_fields as $ex) {
                     $exIds[] = $ex->id;
                 }
                 $exIds = implode(',', $exIds);
                 $query = 'SELECT name FROM #__k2_extra_fields WHERE id IN (' . $exIds . ') ORDER BY ordering';
                 $db->setQuery($query);
                 $rs = $db->loadObjectlist();
                 foreach ($item->extra_fields as $key => &$ex) {
                     $ex->name = $rs[$key]->name;
                 }
             }
         }
     }
     return $data;
 }
Esempio n. 7
0
    function display($tpl = null)
    {
        $mainframe = JFactory::getApplication();
        $user = JFactory::getUser();
        $document = JFactory::getDocument();
        $params = K2HelperUtilities::getParams('com_k2');
        $limitstart = JRequest::getInt('limitstart', 0);
        $view = JRequest::getWord('view');
        $task = JRequest::getWord('task');
        $db = JFactory::getDBO();
        $jnow = JFactory::getDate();
        $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
        $nullDate = $db->getNullDate();
        $this->setLayout('item');
        // Add link
        if (K2HelperPermissions::canAddItem()) {
            $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
        }
        $this->assignRef('addLink', $addLink);
        // Get item
        $model = $this->getModel();
        $item = $model->getData();
        // Does the item exists?
        if (!is_object($item) || !$item->id) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Prepare item
        $item = $model->prepareItem($item, $view, $task);
        // Plugins
        $item = $model->execPlugins($item, $view, $task);
        // User K2 plugins
        $item->event->K2UserDisplay = '';
        if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) {
            $dispatcher = JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart));
            $item->event->K2UserDisplay = trim(implode("\n", $results));
            $item->author->profile->url = htmlspecialchars($item->author->profile->url, ENT_QUOTES, 'UTF-8');
        }
        // Access check
        if ($this->getLayout() == 'form') {
            JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
        }
        if (K2_JVERSION != '15') {
            if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels())) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString());
                    $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                    $mainframe->redirect(JRoute::_($url, false));
                } else {
                    JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                    return;
                }
            }
        } else {
            if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString());
                    $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                    $mainframe->redirect(JRoute::_($url, false));
                } else {
                    JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                    return;
                }
            }
        }
        // Published check
        if (!$item->published || $item->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_up != $nullDate && $item->publish_up > $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_down != $nullDate && $item->publish_down < $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if (!$item->category->published || $item->category->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Increase hits counter
        $model->hit($item->id);
        // Set default image
        K2HelperUtilities::setDefaultImage($item, $view);
        // Pass the old parameter to the view in order to avoid layout changes
        if ($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') {
            $params->set('recaptcha', true);
            $item->params->set('recaptcha', true);
        } else {
            $params->set('recaptcha', false);
            $item->params->set('recaptcha', false);
        }
        // Comments
        $item->event->K2CommentsCounter = '';
        $item->event->K2CommentsBlock = '';
        if ($item->params->get('itemComments')) {
            // Trigger comments events
            $dispatcher = JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsCounter = trim(implode("\n", $results));
            $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsBlock = trim(implode("\n", $results));
            // Load K2 native comments system only if there are no plugins overriding it
            if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
                // Load reCAPTCHA script
                if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
                    if ($params->get('recaptcha') && ($user->guest || $params->get('recaptchaForRegistered', 1))) {
                        $document->addScript('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
                        $js = '
						function showRecaptcha(){
							Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
								theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
							});
						}
						$K2(window).load(function() {
							showRecaptcha();
						});
						';
                        $document->addScriptDeclaration($js);
                    }
                }
                // Check for inline comment moderation
                if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
                    $inlineCommentsModeration = true;
                    $commentsPublished = false;
                } else {
                    $inlineCommentsModeration = false;
                    $commentsPublished = true;
                }
                $this->assignRef('inlineCommentsModeration', $inlineCommentsModeration);
                // Flag spammer link
                $reportSpammerFlag = false;
                if (K2_JVERSION != '15') {
                    if ($user->authorise('core.admin', 'com_k2')) {
                        $reportSpammerFlag = true;
                        $document = JFactory::getDocument();
                        $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
                    }
                } else {
                    if ($user->gid > 24) {
                        $reportSpammerFlag = true;
                    }
                }
                $limit = $params->get('commentsLimit');
                $comments = $model->getItemComments($item->id, $limitstart, $limit, $commentsPublished);
                for ($i = 0; $i < sizeof($comments); $i++) {
                    $comments[$i]->commentText = nl2br($comments[$i]->commentText);
                    // Convert URLs to links properly
                    $comments[$i]->commentText = preg_replace("/([^\\w\\/])(www\\.[a-z0-9\\-]+\\.[a-z0-9\\-]+)/i", "\$1http://\$2", $comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace("/([\\w]+:\\/\\/[\\w-?&;#~=\\.\\/\\@]+[\\w\\/])/i", "<a target=\"_blank\" rel=\"nofollow\" href=\"\$1\">\$1</A>", $comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace("/([\\w-?&;#~=\\.\\/]+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?))/i", "<a href=\"mailto:\$1\">\$1</A>", $comments[$i]->commentText);
                    $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
                    if ($comments[$i]->userID > 0) {
                        $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
                    } else {
                        $comments[$i]->userLink = $comments[$i]->commentURL;
                    }
                    if ($reportSpammerFlag && $comments[$i]->userID > 0) {
                        $comments[$i]->reportUserLink = JRoute::_('index.php?option=com_k2&view=comments&task=reportSpammer&id=' . $comments[$i]->userID . '&format=raw');
                    } else {
                        $comments[$i]->reportUserLink = false;
                    }
                }
                $item->comments = $comments;
                if (!isset($item->numOfComments)) {
                    $item->numOfComments = 0;
                }
                jimport('joomla.html.pagination');
                $total = $item->numOfComments;
                $pagination = new JPagination($total, $limitstart, $limit);
            }
        }
        // Author's latest items
        if ($item->params->get('itemAuthorLatest') && $item->created_by_alias == '') {
            $model = $this->getModel('itemlist');
            $authorLatestItems = $model->getAuthorLatest($item->id, $item->params->get('itemAuthorLatestLimit'), $item->created_by);
            if (count($authorLatestItems)) {
                for ($i = 0; $i < sizeof($authorLatestItems); $i++) {
                    $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias))));
                }
                $this->assignRef('authorLatestItems', $authorLatestItems);
            }
        }
        // Related items
        if ($item->params->get('itemRelated') && isset($item->tags) && count($item->tags)) {
            $model = $this->getModel('itemlist');
            $relatedItems = $model->getRelatedItems($item->id, $item->tags, $item->params);
            if (count($relatedItems)) {
                for ($i = 0; $i < sizeof($relatedItems); $i++) {
                    $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias))));
                }
                $this->assignRef('relatedItems', $relatedItems);
            }
        }
        // Navigation (previous and next item)
        if ($item->params->get('itemNavigation')) {
            $model = $this->getModel('item');
            $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);
            if (!is_null($nextItem)) {
                $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias))));
                $item->nextTitle = $nextItem->title;
                $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" . $nextItem->id) . '_XS.jpg')) {
                    $item->nextImageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_XS.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_S.jpg')) {
                    $item->nextImageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_S.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_M.jpg')) {
                    $item->nextImageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_M.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_L.jpg')) {
                    $item->nextImageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_L.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_XL.jpg')) {
                    $item->nextImageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_XL.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_Generic.jpg')) {
                    $item->nextImageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_Generic.jpg' . $timestamp;
                }
            }
            $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);
            if (!is_null($previousItem)) {
                $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias))));
                $item->previousTitle = $previousItem->title;
                $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" . $previousItem->id) . '_XS.jpg')) {
                    $item->previousImageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_XS.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_S.jpg')) {
                    $item->previousImageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_S.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_M.jpg')) {
                    $item->previousImageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_M.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_L.jpg')) {
                    $item->previousImageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_L.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_XL.jpg')) {
                    $item->previousImageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_XL.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_Generic.jpg')) {
                    $item->previousImageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_Generic.jpg' . $timestamp;
                }
            }
        }
        // Absolute URL
        $uri = JURI::getInstance();
        $item->absoluteURL = $uri->toString();
        // Email link
        if (K2_JVERSION != '15') {
            require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php';
            $template = $mainframe->getTemplate();
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($item->absoluteURL));
        } else {
            require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php';
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . MailToHelper::addLink($item->absoluteURL));
        }
        // Twitter link (legacy code)
        if ($params->get('twitterUsername')) {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL) . '&amp;via=' . $params->get('twitterUsername');
        } else {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL);
        }
        // Social link
        $item->socialLink = urlencode($item->absoluteURL);
        // Set page title
        $menus = $mainframe->getMenu();
        $menu = $menus->getActive();
        if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'item' && isset($menu->query['id']) && $menu->query['id'] == $item->id) {
            if (is_string($menu->params)) {
                $menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params);
            } else {
                $menu_params = $menu->params;
            }
            if (!$menu_params->get('page_title')) {
                $params->set('page_title', $item->cleanTitle);
            }
        } else {
            $params->set('page_title', $item->cleanTitle);
        }
        if (K2_JVERSION != '15') {
            if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) {
                $title = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title'));
                $params->set('page_title', $title);
            } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) {
                $title = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename'));
                $params->set('page_title', $title);
            }
        }
        $document->setTitle($params->get('page_title'));
        // Set pathway
        $menus = $mainframe->getMenu();
        $menu = $menus->getActive();
        $pathway = $mainframe->getPathWay();
        if ($menu) {
            if (isset($menu->query['view']) && ($menu->query['view'] != 'item' || $menu->query['id'] != $item->id)) {
                if (!isset($menu->query['task']) || $menu->query['task'] != 'category' || $menu->query['id'] != $item->catid) {
                    $pathway->addItem($item->category->name, $item->category->link);
                }
                $pathway->addItem($item->cleanTitle, '');
            }
        }
        // Set metadata
        if ($item->metadesc) {
            $document->setDescription(K2_JVERSION == '15' ? htmlspecialchars($item->metadesc, ENT_QUOTES, 'UTF-8') : $item->metadesc);
        } else {
            $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext . ' ' . $item->fulltext);
            $metaDescItem = strip_tags($metaDescItem);
            $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
            $document->setDescription(K2_JVERSION == '15' ? $metaDescItem : html_entity_decode($metaDescItem));
        }
        if ($item->metakey) {
            $document->setMetadata('keywords', $item->metakey);
        } else {
            if (isset($item->tags) && count($item->tags)) {
                $tmp = array();
                foreach ($item->tags as $tag) {
                    $tmp[] = $tag->name;
                }
                $document->setMetadata('keywords', implode(',', $tmp));
            }
        }
        // Menu metadata for Joomla! 2.5+ (overrides the current metadata if set)
        if (K2_JVERSION != '15') {
            if ($params->get('menu-meta_description')) {
                $document->setDescription($params->get('menu-meta_description'));
            }
            if ($params->get('menu-meta_keywords')) {
                $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
            }
            if ($params->get('robots')) {
                $document->setMetadata('robots', $params->get('robots'));
            }
            // Menu page display options
            if ($params->get('page_heading')) {
                $params->set('page_title', $params->get('page_heading'));
            }
            $params->set('show_page_title', $params->get('show_page_heading'));
        }
        if ($mainframe->getCfg('MetaTitle') == '1') {
            $document->setMetadata('title', $item->cleanTitle);
        }
        if ($mainframe->getCfg('MetaAuthor') == '1' && isset($item->author->name)) {
            $document->setMetadata('author', $item->author->name);
        }
        $mdata = class_exists('JParameter') ? new JParameter($item->metadata) : new JRegistry($item->metadata);
        $mdata = $mdata->toArray();
        foreach ($mdata as $k => $v) {
            if ($k == 'robots' || $k == 'author') {
                if ($v) {
                    $document->setMetadata($k, $v);
                }
            }
        }
        // Set Facebook meta data
        $document = JFactory::getDocument();
        $uri = JURI::getInstance();
        $document->setMetaData('og:url', $uri->toString());
        $document->setMetaData('og:title', K2_JVERSION == '15' ? htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8') : $document->getTitle());
        $document->setMetaData('og:type', 'article');
        $facebookImage = 'image' . $params->get('facebookImage', 'Small');
        if ($item->{$facebookImage}) {
            $parts = parse_url($item->{$facebookImage});
            if (JFile::exists(JPATH_SITE . $parts['path'])) {
                $image = substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $item->{$facebookImage});
                $document->setMetaData('og:image', $image);
                $document->setMetaData('image', $image);
            }
        }
        $document->setMetaData('og:description', strip_tags($document->getDescription()));
        // Look for template files in component folders
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (K2 template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (Joomla! template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
        // Look for specific K2 theme files
        if ($item->params->get('theme')) {
            $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme'));
        }
        // Assign data
        $this->assignRef('item', $item);
        $this->assignRef('user', $user);
        $this->assignRef('params', $item->params);
        $this->assignRef('pagination', $pagination);
        parent::display($tpl);
    }
Esempio n. 8
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;
 }
Esempio n. 9
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $document = JFactory::getDocument();
     $params = K2HelperUtilities::getParams('com_k2');
     $limitstart = JRequest::getInt('limitstart', 0);
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     $this->setLayout('item');
     // Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     // Get item
     $model = $this->getModel();
     $item = $model->getData();
     $item->event = new stdClass();
     // Does the item exists?
     if (!is_object($item) || !$item->id) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     // Prepare item
     $item = $model->prepareItem($item, $view, $task);
     // Plugins
     $item = $model->execPlugins($item, $view, $task);
     // User K2 plugins
     $item->event->K2UserDisplay = '';
     if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) {
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart));
         $item->event->K2UserDisplay = trim(implode("\n", $results));
         $item->author->profile->url = htmlspecialchars($item->author->profile->url, ENT_QUOTES, 'UTF-8');
     }
     // Access check
     if ($this->getLayout() == 'form') {
         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
     }
     if (K2_JVERSION != '15') {
         if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels())) {
             if ($user->guest) {
                 $uri = JFactory::getURI();
                 $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString());
                 $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                 $mainframe->redirect(JRoute::_($url, false));
             } else {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 return;
             }
         }
     } else {
         if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
             if ($user->guest) {
                 $uri = JFactory::getURI();
                 $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString());
                 $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                 $mainframe->redirect(JRoute::_($url, false));
             } else {
                 JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 return;
             }
         }
     }
     // Published check
     if (!$item->published || $item->trash) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     if ($item->publish_up != $nullDate && $item->publish_up > $now) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     if ($item->publish_down != $nullDate && $item->publish_down < $now) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     if (!$item->category->published || $item->category->trash) {
         JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
     }
     // Increase hits counter
     $model->hit($item->id);
     // Set default image
     K2HelperUtilities::setDefaultImage($item, $view);
     // Comments
     $item->event->K2CommentsCounter = '';
     $item->event->K2CommentsBlock = '';
     if ($item->params->get('itemComments')) {
         // Trigger comments events
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
         $item->event->K2CommentsCounter = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
         $item->event->K2CommentsBlock = trim(implode("\n", $results));
         // Load K2 native comments system only if there are no plugins overriding it
         if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
             $limit = $params->get('commentsLimit');
             $comments = $model->getItemComments($item->id, $limitstart, $limit);
             $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
             for ($i = 0; $i < sizeof($comments); $i++) {
                 $comments[$i]->commentText = nl2br($comments[$i]->commentText);
                 $comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText);
                 $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
                 if ($comments[$i]->userID > 0) {
                     $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
                 } else {
                     $comments[$i]->userLink = $comments[$i]->commentURL;
                 }
             }
             $item->comments = $comments;
             jimport('joomla.html.pagination');
             $total = $item->numOfComments;
             $pagination = new JPagination($total, $limitstart, $limit);
         }
     }
     // Author's latest items
     if ($item->params->get('itemAuthorLatest') && $item->created_by_alias == '') {
         $model = $this->getModel('itemlist');
         $authorLatestItems = $model->getAuthorLatest($item->id, $item->params->get('itemAuthorLatestLimit'), $item->created_by);
         if (count($authorLatestItems)) {
             for ($i = 0; $i < sizeof($authorLatestItems); $i++) {
                 $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias))));
             }
             $this->assignRef('authorLatestItems', $authorLatestItems);
         }
     }
     // Related items
     if ($item->params->get('itemRelated') && isset($item->tags) && count($item->tags)) {
         $model = $this->getModel('itemlist');
         $relatedItems = $model->getRelatedItems($item->id, $item->tags, $item->params);
         if (count($relatedItems)) {
             for ($i = 0; $i < sizeof($relatedItems); $i++) {
                 $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias))));
             }
             $this->assignRef('relatedItems', $relatedItems);
         }
     }
     // Navigation (previous and next item)
     if ($item->params->get('itemNavigation')) {
         $model = $this->getModel('item');
         $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);
         if (!is_null($nextItem)) {
             $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias))));
             $item->nextTitle = $nextItem->title;
         }
         $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);
         if (!is_null($previousItem)) {
             $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias))));
             $item->previousTitle = $previousItem->title;
         }
     }
     // Absolute URL
     $uri = JURI::getInstance();
     $item->absoluteURL = $uri->toString();
     // Email link
     if (K2_JVERSION != '15') {
         require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php';
         $template = $mainframe->getTemplate();
         $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($item->absoluteURL));
     } else {
         require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php';
         $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . MailToHelper::addLink($item->absoluteURL));
     }
     // Twitter link (legacy code)
     if ($params->get('twitterUsername')) {
         $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL) . '&amp;via=' . $params->get('twitterUsername');
     } else {
         $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL);
     }
     // Social link
     $item->socialLink = urlencode($item->absoluteURL);
     // Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     // Look for specific K2 theme files
     if ($item->params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme'));
     }
     // Assign data
     $this->assignRef('item', $item);
     $this->assignRef('user', $user);
     $this->assignRef('params', $item->params);
     $this->assignRef('pagination', $pagination);
     parent::display($tpl);
 }
Esempio n. 10
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     $document = JFactory::getDocument();
     $user = JFactory::getUser();
     $cache = JFactory::getCache('com_k2_extended');
     $limit = $params->get('latestItemsLimit');
     $limitstart = JRequest::getInt('limitstart');
     $model = $this->getModel('itemlist');
     $itemModel = $this->getModel('item');
     $theme = $params->get('theme');
     if ($params->get('source')) {
         $categoryIDs = $params->get('categoryIDs');
         if (is_string($categoryIDs) && !empty($categoryIDs)) {
             $categoryIDs = array();
             $categoryIDs[] = $params->get('categoryIDs');
         }
         $categories = array();
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables');
         if (is_array($categoryIDs)) {
             foreach ($categoryIDs as $categoryID) {
                 $category = JTable::getInstance('K2Category', 'Table');
                 $category->load($categoryID);
                 $category->event = new stdClass();
                 $languageCheck = true;
                 if (K2_JVERSION != '15') {
                     $accessCheck = in_array($category->access, $user->getAuthorisedViewLevels());
                     if ($mainframe->getLanguageFilter()) {
                         $languageTag = JFactory::getLanguage()->getTag();
                         $languageCheck = in_array($category->language, array($languageTag, '*'));
                     }
                 } else {
                     $accessCheck = $category->access <= $user->get('aid', 0);
                 }
                 if ($category->published && $accessCheck && $languageCheck) {
                     //Merge params
                     $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
                     if ($cparams->get('inheritFrom')) {
                         $masterCategory = JTable::getInstance('K2Category', 'Table');
                         $masterCategory->load($cparams->get('inheritFrom'));
                         $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
                     }
                     $params->merge($cparams);
                     //Category image
                     $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
                     //Category plugins
                     $dispatcher = JDispatcher::getInstance();
                     JPluginHelper::importPlugin('content');
                     $category->text = $category->description;
                     if (K2_JVERSION != '15') {
                         $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
                     } else {
                         $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
                     }
                     $category->description = $category->text;
                     //Category K2 plugins
                     $category->event->K2CategoryDisplay = '';
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
                     $category->event->K2CategoryDisplay = trim(implode("\n", $results));
                     $category->text = $category->description;
                     $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
                     $category->description = $category->text;
                     //Category link
                     $link = urldecode(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias)));
                     $category->link = JRoute::_($link);
                     $category->feed = JRoute::_($link . '&format=feed');
                     JRequest::setVar('view', 'itemlist');
                     JRequest::setVar('task', 'category');
                     JRequest::setVar('id', $category->id);
                     JRequest::setVar('featured', 1);
                     JRequest::setVar('limit', $limit);
                     JRequest::setVar('clearFlag', true);
                     $category->name = htmlspecialchars($category->name, ENT_QUOTES);
                     if ($limit) {
                         $category->items = $model->getData('rdate');
                         JRequest::setVar('view', 'latest');
                         JRequest::setVar('task', '');
                         for ($i = 0; $i < sizeof($category->items); $i++) {
                             $hits = $category->items[$i]->hits;
                             $category->items[$i]->hits = 0;
                             $category->items[$i] = $cache->call(array($itemModel, 'prepareItem'), $category->items[$i], 'latest', '');
                             $category->items[$i]->hits = $hits;
                             $category->items[$i] = $itemModel->execPlugins($category->items[$i], 'latest', '');
                             //Trigger comments counter event
                             $dispatcher = JDispatcher::getInstance();
                             JPluginHelper::importPlugin('k2');
                             $results = $dispatcher->trigger('onK2CommentsCounter', array(&$category->items[$i], &$params, $limitstart));
                             $category->items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
                         }
                     } else {
                         $category->items = array();
                     }
                     $categories[] = $category;
                 }
             }
         }
         $source = 'categories';
         $this->assignRef('blocks', $categories);
     } else {
         $usersIDs = $params->get('userIDs');
         if (is_string($usersIDs) && !empty($usersIDs)) {
             $usersIDs = array();
             $usersIDs[] = $params->get('userIDs');
         }
         $users = array();
         if (is_array($usersIDs)) {
             foreach ($usersIDs as $userID) {
                 $userObject = JFactory::getUser($userID);
                 if (!$userObject->block) {
                     $userObject->event = new stdClass();
                     //User profile
                     $userObject->profile = $model->getUserProfile($userID);
                     //User image
                     $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
                     //User K2 plugins
                     $userObject->event->K2UserDisplay = '';
                     if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                         $dispatcher = JDispatcher::getInstance();
                         JPluginHelper::importPlugin('k2');
                         $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                         $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                         $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8');
                     }
                     $link = K2HelperRoute::getUserRoute($userObject->id);
                     $userObject->link = JRoute::_($link);
                     $userObject->feed = JRoute::_($link . '&format=feed');
                     $userObject->name = htmlspecialchars($userObject->name, ENT_QUOTES);
                     if ($limit) {
                         $userObject->items = $model->getAuthorLatest(0, $limit, $userID);
                         for ($i = 0; $i < sizeof($userObject->items); $i++) {
                             $hits = $userObject->items[$i]->hits;
                             $userObject->items[$i]->hits = 0;
                             $userObject->items[$i] = $cache->call(array($itemModel, 'prepareItem'), $userObject->items[$i], 'latest', '');
                             $userObject->items[$i]->hits = $hits;
                             //Plugins
                             $userObject->items[$i] = $itemModel->execPlugins($userObject->items[$i], 'latest', '');
                             //Trigger comments counter event
                             $dispatcher = JDispatcher::getInstance();
                             JPluginHelper::importPlugin('k2');
                             $results = $dispatcher->trigger('onK2CommentsCounter', array(&$userObject->items[$i], &$params, $limitstart));
                             $userObject->items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
                         }
                     } else {
                         $userObject->items = array();
                     }
                     $users[] = $userObject;
                 }
             }
         }
         $source = 'users';
         $this->assignRef('blocks', $users);
     }
     // Set menu metadata for Joomla! 2.5+
     if (K2_JVERSION != '15') {
         if ($params->get('menu-meta_description')) {
             $document->setDescription($params->get('menu-meta_description'));
         }
         if ($params->get('menu-meta_keywords')) {
             $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
         }
         if ($params->get('robots')) {
             $document->setMetadata('robots', $params->get('robots'));
         }
         // Menu page display options
         if ($params->get('page_heading')) {
             $params->set('page_title', $params->get('page_heading'));
         }
         $params->set('show_page_title', $params->get('show_page_heading'));
     }
     // Set Facebook meta data
     $document = JFactory::getDocument();
     $uri = JURI::getInstance();
     $document->setMetaData('og:url', $uri->toString());
     $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8'));
     $document->setMetaData('og:type', 'website');
     $document->setMetaData('og:description', htmlspecialchars(strip_tags($document->getDescription()), ENT_QUOTES, 'UTF-8'));
     //Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     // Look for specific K2 theme files
     if ($theme) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $theme);
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $theme);
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $theme);
     }
     //Assign params
     $this->assignRef('params', $params);
     $this->assignRef('source', $source);
     //Set layout
     $this->setLayout('latest');
     //Display
     parent::display($tpl);
 }
Esempio n. 11
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;
	}
Esempio n. 12
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;
     }
 }
Esempio n. 13
0
 public static function getItems($cid, &$params, $counttotal = false)
 {
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $app = JFactory::getApplication();
     $appParams = $app->getParams();
     $itemCount = '';
     $limit = 0;
     $limitation = $params->get('itemCount');
     $start = $app->input->getInt('ajax_reslisting_start', 0);
     if (isset($limitation) && (int) $limitation >= 0) {
         $limit = (int) $limitation;
     }
     //$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();
     $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
     if ($ordering == 'best') {
         $query .= ", (r.rating_sum/r.rating_count) AS rating";
     }
     if ($ordering == 'comments') {
         $query .= ", COUNT(comments.id) AS numOfComments";
     }
     $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid";
     if ($ordering == 'best') {
         $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id";
     }
     if ($ordering == 'comments') {
         $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id";
     }
     if (K2_JVERSION != '15') {
         $query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ")  AND c.trash = 0";
     } else {
         $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
     }
     $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
     $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
     if (!is_null($cid)) {
         if (is_array($cid)) {
             $catidpreload = $params->get('category_preload');
             $list = self::getCategoriesFull($cid, $params);
             $catids = array();
             if (!empty($list)) {
                 foreach ($list as $item) {
                     $catids[] = $item->id;
                 }
             }
             if (in_array($catidpreload, $catids)) {
                 array_unshift($catids, $catidpreload);
             }
             $cids = array_unique($catids);
             JArrayHelper::toInteger($cids);
             $query .= " AND i.catid IN(" . implode(',', $cids) . ")";
         }
     }
     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;
     if ($counttotal) {
         $db->setQuery($query);
         $items = $db->loadObjectList();
         return count($items);
     } else {
         $db->setQuery($query, $start, $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);
             $item->rating = $model->getRating($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 = $item->introtext;
             // 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
             // 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;
                     }
                 }
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }
Esempio n. 14
0
	  	<img src="<?php echo K2HelperUtilities::getAvatar($user->id, $user->email); ?>" alt="<?php echo K2HelperUtilities::cleanHtml($user->name); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
	  </a>
	  <?php endif; ?>
	  <span class="ubName"><?php echo $user->name; ?></span>
		<span class="ubCommentsCount"><?php echo JText::_('K2_YOU_HAVE'); ?> <b><?php echo $user->numOfComments; ?></b> <?php if($user->numOfComments==1) echo JText::_('K2_PUBLISHED_COMMENT'); else echo JText::_('K2_PUBLISHED_COMMENTS'); ?></span>
	  <div class="clr"></div>
	</div>

  <ul class="k2UserBlockActions">
		<?php if(is_object($user->profile) && isset($user->profile->addLink)): ?>
		<li>
			<a class="modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php echo $user->profile->addLink; ?>"><?php echo JText::_('K2_ADD_NEW_ITEM'); ?></a>
		</li>
		<?php endif; ?>
		<li>
			<a href="<?php echo JRoute::_(K2HelperRoute::getUserRoute($user->id)); ?>"><?php echo JText::_('K2_MY_PAGE'); ?></a>
		</li>
		<li>
			<a href="<?php echo JRoute::_((K2_JVERSION != '15') ? 'index.php?option=com_users&view=profile&layout=edit' : 'index.php?option=com_user&view=user&task=edit'); ?>"><?php echo JText::_('K2_MY_ACCOUNT'); ?></a>
		</li>
		<li>
			<a class="modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php echo JRoute::_('index.php?option=com_k2&view=comments&tmpl=component'); ?>"><?php echo JText::_('K2_MODERATE_COMMENTS_TO_MY_PUBLISHED_ITEMS'); ?></a>
		</li>
	</ul>

	<ul class="k2UserBlockRenderedMenu">
		<?php $level = 1; foreach($menu as $key => $link): $level++; ?>
		<li class="linkItemId<?php echo $link->id; ?>">
			<?php if($link->type=='url' && $link->browserNav==0): ?>
			<a href="<?php echo $link->route; ?>"><?php echo $link->name; ?></a>
			<?php elseif(strpos($link->link,'option=com_k2&view=item&layout=itemform') || $link->browserNav==2): ?>
Esempio n. 15
0
 static function authorLink($item)
 {
     return urldecode(JRoute::_(K2HelperRoute::getUserRoute($item['author_id'])));
 }
Esempio n. 16
0
 public function getUrl()
 {
     if (!isset($this->url)) {
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $this->alias = JFilterOutput::stringURLUnicodeSlug($this->name);
         } else {
             $this->alias = JFilterOutput::stringURLSafe($this->name);
         }
         $this->url = JRoute::_(K2HelperRoute::getUserRoute($this->id . ':' . $this->alias), true, -1);
     }
     return $this->url;
 }
Esempio n. 17
0
 public static function getUsers(&$params)
 {
     $mainframe = JFactory::getApplication();
     $user = JFactory::getUser();
     $aid = (int) $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     $userObjects = array();
     if (K2_JVERSION != '15') {
         $itemAccessCheck = " i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
         $categoryAccessCheck = " c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
         $languageCheck = '';
         if ($mainframe->getLanguageFilter()) {
             $languageTag = JFactory::getLanguage()->getTag();
             $languageCheck = " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")";
         }
     } else {
         $itemAccessCheck = " i.access <= {$aid} ";
         $categoryAccessCheck = " c.access <= {$aid} ";
         $languageCheck = '';
     }
     if ($params->get('source') == 'specific' && $params->get('userIDs')) {
         $IDs = array();
         if (is_string($params->get('userIDs'))) {
             $IDs[] = $params->get('userIDs');
         } else {
             $IDs = $params->get('userIDs');
         }
         JArrayHelper::toInteger($IDs);
         $query = "SELECT users.name,users.email, users.id AS UID, profiles.* FROM #__users AS users\n\t\t\tLEFT JOIN #__k2_users AS profiles ON users.id=profiles.userID\n\t\t\tWHERE users.block=0 AND users.id IN (" . implode(',', $IDs) . ")";
         $db->setQuery($query);
         $userObjects = $db->loadObjectList();
         $newUserObjects = array();
         foreach ($IDs as $id) {
             foreach ($userObjects as $uO) {
                 if ($uO->UID == $id) {
                     $newUserObjects[] = $uO;
                     break;
                 }
             }
         }
         $userObjects = $newUserObjects;
     } else {
         switch ($params->get('filter', 0)) {
             case 0:
                 $query = "SELECT users.name,users.email,users.id AS UID, profiles.*";
                 if ($params->get('ordering') == 'recent') {
                     $query .= ", MAX(i.created) AS counter";
                 }
                 $query .= " FROM #__users AS users\n\t\t\t\t\tLEFT JOIN #__k2_users AS profiles ON users.id=profiles.userID";
                 if ($params->get('ordering') == 'recent') {
                     $query .= " LEFT JOIN #__k2_items AS i ON users.id=i.created_by\n\t\t\t\t\t\t\t\tLEFT JOIN #__k2_categories AS c ON i.catid=c.id";
                 }
                 $query .= " WHERE users.block=0 AND profiles.`group`=" . (int) $params->get('K2UserGroup');
                 if ($params->get('ordering') == 'recent') {
                     $query .= " AND\n\t\t\t\t\t\ti.published = 1 AND {$itemAccessCheck} AND i.trash = 0 AND c.published = 1 AND {$categoryAccessCheck} AND c.trash = 0\n\t\t\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\t\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\t\tAND i.created_by_alias=''";
                     $query .= $languageCheck;
                 }
                 if ($params->get('ordering') == 'alpha') {
                     $query .= " ORDER BY users.name";
                 } elseif ($params->get('ordering') == 'random') {
                     $query .= " ORDER BY RAND()";
                 } elseif ($params->get('ordering') == 'recent') {
                     $query .= " GROUP BY users.id ORDER BY counter DESC";
                 }
                 break;
             case 1:
                 $query = "SELECT users.name,users.email,users.id AS UID, profiles.*, COUNT(i.id) AS counter FROM #__users AS users\n\t\t\t\t\tLEFT JOIN #__k2_users AS profiles ON users.id=profiles.userID\n\t\t\t\t\tLEFT JOIN #__k2_items AS i ON users.id=i.created_by\n\t\t\t\t\tLEFT JOIN #__k2_categories AS c ON i.catid=c.id\n\t\t\t\t\tWHERE users.block=0 AND\n\t\t\t\t\ti.published = 1 AND {$itemAccessCheck} AND i.trash = 0 AND c.published = 1 AND {$categoryAccessCheck} AND c.trash = 0\n\t\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\tAND i.created_by_alias=''\n\t\t\t\t\t{$languageCheck}\n\t\t\t\t\tGROUP BY users.id ORDER BY counter DESC";
                 break;
             case 2:
                 $query = "SELECT users.name,users.email,users.id AS UID, profiles.*, MAX(i.hits) AS counter FROM #__users AS users\n\t\t\t\t\tLEFT JOIN #__k2_users AS profiles ON users.id=profiles.userID\n\t\t\t\t\tLEFT JOIN #__k2_items AS i ON users.id=i.created_by\n\t\t\t\t\tLEFT JOIN #__k2_categories AS c ON i.catid=c.id\n\t\t\t\t\tWHERE users.block=0 AND\n\t\t\t\t\ti.published = 1 AND {$itemAccessCheck} AND i.trash = 0 AND c.published = 1 AND {$categoryAccessCheck} AND c.trash = 0\n\t\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\tAND i.created_by_alias=''\n\t\t\t\t\t{$languageCheck}\n\t\t\t\t\tGROUP BY users.id ORDER BY counter DESC";
                 break;
             case 3:
                 $query = "SELECT users.name,users.email,users.id AS UID, profiles.*, COUNT(comment.id) AS counter FROM #__users AS users\n\t\t\t\t\tLEFT JOIN #__k2_users AS profiles ON users.id=profiles.userID\n\t\t\t\t\tLEFT JOIN #__k2_items AS i ON users.id=i.created_by\n\t\t\t\t\tLEFT JOIN #__k2_categories AS c ON i.catid=c.id\n\t\t\t\t\tLEFT JOIN #__k2_comments AS comment ON i.id=comment.itemID\n\t\t\t\t\tWHERE users.block=0 AND\n\t\t\t\t\ti.published = 1 AND {$itemAccessCheck} AND i.trash = 0 AND c.published = 1 AND {$categoryAccessCheck} AND c.trash = 0\n\t\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\tAND i.created_by_alias=''\n\t\t\t\t\tAND comment.published=1\n\t\t\t\t\t{$languageCheck}\n\t\t\t\t\tGROUP BY users.id ORDER BY counter DESC";
                 break;
         }
         $db->setQuery($query, 0, $params->get('limit', 4));
         $userObjects = $db->loadObjectList();
     }
     if (count($userObjects)) {
         foreach ($userObjects as $userObject) {
             $userObject->avatar = K2HelperUtilities::getAvatar($userObject->UID, $userObject->email, $params->get('userImageWidth'));
             $userObject->link = JRoute::_(K2HelperRoute::getUserRoute($userObject->UID));
             $userObject->feed = JRoute::_(K2HelperRoute::getUserRoute($userObject->UID) . '&format=feed');
             $userObject->url = htmlspecialchars($userObject->url, ENT_QUOTES, 'UTF-8');
             if ($params->get('userItemCount')) {
                 $query = "SELECT i.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams FROM #__k2_items as i LEFT JOIN #__k2_categories AS c ON c.id = i.catid WHERE i.published = 1\n\t\t\t\t\tAND {$itemAccessCheck}\n\t\t\t\t\tAND i.trash = 0\n\t\t\t\t\tAND c.published = 1\n\t\t\t\t\tAND {$categoryAccessCheck}\n\t\t\t\t\tAND c.trash = 0\n\t\t\t\t\tAND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )\n\t\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\tAND i.created_by=" . (int) $userObject->UID . "\n\t\t\t\t\tAND i.created_by_alias=''\n\t\t\t\t\t{$languageCheck}\n\t\t\t\t\tORDER BY i.created DESC";
                 $db->setQuery($query, 0, $params->get('userItemCount'));
                 $userObject->items = $db->loadObjectList();
                 if (count($userObject->items)) {
                     foreach ($userObject->items as $item) {
                         $link = K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias));
                         $item->link = urldecode(JRoute::_($link));
                         $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
                     }
                 }
             } else {
                 $userObject->items = null;
             }
         }
     }
     return $userObjects;
 }
Esempio n. 18
0
    function display($tpl = null)
    {
        $mainframe =& JFactory::getApplication();
        $user =& JFactory::getUser();
        $document =& JFactory::getDocument();
        $params =& K2HelperUtilities::getParams('com_k2');
        $limitstart = JRequest::getInt('limitstart', 0);
        $view = JRequest::getWord('view');
        $task = JRequest::getWord('task');
        $db =& JFactory::getDBO();
        $jnow =& JFactory::getDate();
        $now = $jnow->toMySQL();
        $nullDate = $db->getNullDate();
        $this->setLayout('item');
        // Add link
        if (K2HelperPermissions::canAddItem()) {
            $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
        }
        $this->assignRef('addLink', $addLink);
        // Get item
        $model =& $this->getModel();
        $item = $model->getData();
        // Does the item exists?
        if (!is_object($item) || !$item->id) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Prepare item
        $item = $model->prepareItem($item, $view, $task);
        // Plugins
        $item = $model->execPlugins($item, $view, $task);
        // User K2 plugins
        $item->event->K2UserDisplay = '';
        if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) {
            $dispatcher =& JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart));
            $item->event->K2UserDisplay = trim(implode("\n", $results));
        }
        // Access check
        if ($this->getLayout() == 'form') {
            JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
        }
        if (K2_JVERSION == '16') {
            if (!in_array($item->access, $user->authorisedLevels()) || !in_array($item->category->access, $user->authorisedLevels())) {
                JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
            }
        } else {
            if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
                JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
            }
        }
        // Published check
        if (!$item->published || $item->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_up != $nullDate && $item->publish_up > $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_down != $nullDate && $item->publish_down < $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if (!$item->category->published || $item->category->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Increase hits counter
        $model->hit($item->id);
        // Set default image
        K2HelperUtilities::setDefaultImage($item, $view);
        // Comments
        $item->event->K2CommentsCounter = '';
        $item->event->K2CommentsBlock = '';
        if ($item->params->get('itemComments')) {
            // Trigger comments events
            $dispatcher =& JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsCounter = trim(implode("\n", $results));
            $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsBlock = trim(implode("\n", $results));
            // Load K2 native comments system only if there are no plugins overriding it
            if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
                // Load reCAPTCHA script
                if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
                    if ($item->params->get('recaptcha') && $user->guest) {
                        $document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js');
                        $js = '
						function showRecaptcha(){
							Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
								theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
							});
						}
						$K2(window).load(function() {
							showRecaptcha();
						});
						';
                        $document->addScriptDeclaration($js);
                    }
                }
                // Check for inline comment moderation
                if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
                    $inlineCommentsModeration = true;
                    $commentsPublished = false;
                } else {
                    $inlineCommentsModeration = false;
                    $commentsPublished = true;
                }
                $this->assignRef('inlineCommentsModeration', $inlineCommentsModeration);
                // Flag spammer link
                $reportSpammerFlag = false;
                if (K2_JVERSION == '16') {
                    if ($user->authorise('core.admin', 'com_k2')) {
                        $reportSpammerFlag = true;
                        $document =& JFactory::getDocument();
                        $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
                    }
                } else {
                    if ($user->gid > 24) {
                        $reportSpammerFlag = true;
                    }
                }
                $limit = $params->get('commentsLimit');
                $comments = $model->getItemComments($item->id, $limitstart, $limit, $commentsPublished);
                $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
                for ($i = 0; $i < sizeof($comments); $i++) {
                    $comments[$i]->commentText = nl2br($comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText);
                    $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
                    if ($comments[$i]->userID > 0) {
                        $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
                    } else {
                        $comments[$i]->userLink = $comments[$i]->commentURL;
                    }
                    if ($reportSpammerFlag && $comments[$i]->userID > 0) {
                        $comments[$i]->reportUserLink = JRoute::_('index.php?option=com_k2&view=comments&task=reportSpammer&id=' . $comments[$i]->userID . '&format=raw');
                    } else {
                        $comments[$i]->reportUserLink = false;
                    }
                }
                $item->comments = $comments;
                jimport('joomla.html.pagination');
                $total = $item->numOfComments;
                $pagination = new JPagination($total, $limitstart, $limit);
            }
        }
        // Author's latest items
        if ($item->params->get('itemAuthorLatest') && $item->created_by_alias == '') {
            $model =& $this->getModel('itemlist');
            $authorLatestItems = $model->getAuthorLatest($item->id, $item->params->get('itemAuthorLatestLimit'), $item->created_by);
            if (count($authorLatestItems)) {
                for ($i = 0; $i < sizeof($authorLatestItems); $i++) {
                    $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias))));
                }
                $this->assignRef('authorLatestItems', $authorLatestItems);
            }
        }
        // Related items
        if ($item->params->get('itemRelated') && isset($item->tags) && count($item->tags)) {
            $model =& $this->getModel('itemlist');
            $relatedItems = $model->getRelatedItems($item->id, $item->tags, $item->params);
            if (count($relatedItems)) {
                for ($i = 0; $i < sizeof($relatedItems); $i++) {
                    $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias))));
                }
                $this->assignRef('relatedItems', $relatedItems);
            }
        }
        // Navigation (previous and next item)
        if ($item->params->get('itemNavigation')) {
            $model =& $this->getModel('item');
            $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);
            if (!is_null($nextItem)) {
                $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias))));
                $item->nextTitle = $nextItem->title;
            }
            $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);
            if (!is_null($previousItem)) {
                $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias))));
                $item->previousTitle = $previousItem->title;
            }
        }
        // Absolute URL
        $uri =& JURI::getInstance();
        $item->absoluteURL = $uri->toString();
        // Email link
        if (K2_JVERSION == '16') {
            require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php';
            $template = $mainframe->getTemplate();
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($item->absoluteURL));
        } else {
            require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php';
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . MailToHelper::addLink($item->absoluteURL));
        }
        // Twitter link (legacy code)
        if ($params->get('twitterUsername')) {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL) . '&amp;via=' . $params->get('twitterUsername');
        } else {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL);
        }
        // Social link
        $item->socialLink = urlencode($item->absoluteURL);
        // Set page title
        $menus =& JSite::getMenu();
        $menu = $menus->getActive();
        if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'item' && isset($menu->query['id']) && $menu->query['id'] == $item->id) {
            $menu_params = new JParameter($menu->params);
            if (!$menu_params->get('page_title')) {
                $params->set('page_title', $item->cleanTitle);
            }
        } else {
            $params->set('page_title', $item->cleanTitle);
        }
        if (K2_JVERSION == '16') {
            if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) {
                $title = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title'));
                $params->set('page_title', $title);
            } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) {
                $title = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename'));
                $params->set('page_title', $title);
            }
        }
        $document->setTitle($params->get('page_title'));
        // Set pathway
        $menus =& JSite::getMenu();
        $menu = $menus->getActive();
        $pathway =& $mainframe->getPathWay();
        if ($menu) {
            if ($menu->query['view'] != 'item' || $menu->query['id'] != $item->id) {
                if (!isset($menu->query['task']) || $menu->query['task'] != 'category' || $menu->query['id'] != $item->catid) {
                    $pathway->addItem($item->category->name, $item->category->link);
                }
                $pathway->addItem($item->cleanTitle, '');
            }
        }
        // Set metadata
        if ($item->metadesc) {
            $document->setDescription($item->metadesc);
        } else {
            $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext . ' ' . $item->fulltext);
            $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
            $metaDescItem = htmlentities($metaDescItem, ENT_QUOTES, 'utf-8');
            $document->setDescription($metaDescItem);
        }
        if ($item->metakey) {
            $document->setMetadata('keywords', $item->metakey);
        } else {
            if (isset($item->tags) && count($item->tags)) {
                $tmp = array();
                foreach ($item->tags as $tag) {
                    $tmp[] = $tag->name;
                }
                $document->setMetadata('keywords', implode(',', $tmp));
            }
        }
        // Menu metadata for Joomla! 1.6/1.7 (Overrides the current metadata if set)
        if (K2_JVERSION == '16') {
            if ($params->get('menu-meta_description')) {
                $document->setDescription($params->get('menu-meta_description'));
            }
            if ($params->get('menu-meta_keywords')) {
                $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
            }
            if ($params->get('robots')) {
                $document->setMetadata('robots', $params->get('robots'));
            }
            // Menu page display options
            if ($params->get('page_heading')) {
                $params->set('page_title', $params->get('page_heading'));
            }
            $params->set('show_page_title', $params->get('show_page_heading'));
        }
        if ($mainframe->getCfg('MetaTitle') == '1') {
            $document->setMetadata('title', $item->title);
        }
        if ($mainframe->getCfg('MetaAuthor') == '1' && isset($item->author->name)) {
            $document->setMetadata('author', $item->author->name);
        }
        $mdata = new JParameter($item->metadata);
        $mdata = $mdata->toArray();
        foreach ($mdata as $k => $v) {
            if ($k == 'robots' || $k == 'author') {
                if ($v) {
                    $document->setMetadata($k, $v);
                }
            }
        }
        // Load Facebook meta tag for item image
        $facebookImage = 'image' . $params->get('facebookImage', 'Small');
        if ($item->{$facebookImage}) {
            $document->setMetaData('image', substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $item->{$facebookImage}));
        }
        // Look for template files in component folders
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (K2 template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (Joomla! template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
        // Look for specific K2 theme files
        if ($item->params->get('theme')) {
            $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme'));
        }
        // Assign data
        $this->assignRef('item', $item);
        $this->assignRef('user', $user);
        $this->assignRef('params', $item->params);
        $this->assignRef('pagination', $pagination);
        parent::display($tpl);
    }
Esempio n. 19
0
 function getTopCommenters(&$params)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables');
     $limit = $params->get('commenters_limit', '5');
     $user =& JFactory::getUser();
     $aid = $user->get('aid');
     $db =& JFactory::getDBO();
     $query = "SELECT COUNT(id) as counter, userName, userID, commentEmail FROM #__k2_comments WHERE userID > 0 AND published = 1 GROUP BY userID ORDER BY counter DESC";
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     $componentParams =& JComponentHelper::getParams('com_k2');
     if (count($rows)) {
         foreach ($rows as $row) {
             if ($row->counter > 0) {
                 $row->link = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
                 if ($params->get('commentAvatar')) {
                     $row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
                 }
                 if ($params->get('commenterLatestComment')) {
                     $query = "SELECT * FROM #__k2_comments WHERE userID = " . (int) $row->userID . " AND published = 1 ORDER BY commentDate DESC";
                     $db->setQuery($query, 0, 1);
                     $comment = $db->loadObject();
                     $item =& JTable::getInstance('K2Item', 'Table');
                     $item->load($comment->itemID);
                     $category =& JTable::getInstance('K2Category', 'Table');
                     $category->load($item->catid);
                     $row->latestCommentText = $comment->commentText;
                     $row->latestCommentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $row->latestCommentText);
                     $row->latestCommentLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($category->alias)))) . "#comment{$comment->id}";
                     $row->latestCommentDate = $comment->commentDate;
                 }
                 $commenters[] = $row;
             }
         }
         if (isset($commenters)) {
             return $commenters;
         }
     }
 }
Esempio n. 20
0
 public function getLink()
 {
     if ($this->komentoprofile) {
         return JRoute::_('index.php?option=com_komento&view=profile&id=' . $this->profile->id);
     }
     return K2HelperRoute::getUserRoute($this->profile->id);
 }
Esempio n. 21
0
 public static function getList($params)
 {
     $app = JFactory::getApplication();
     $lang = JFactory::getLanguage();
     $user = JFactory::getUser();
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     // Source
     $source = $params->get('source', 'categories');
     $exclude = $params->get('exclude', array());
     $articles_k2 = $params->get('articles_k2', array());
     $categories_k2 = $params->get('categories_k2', array());
     // General
     $readmore = $params->get('readmore', '');
     $ordering = $params->get('ordering', 'random');
     $item_counts = $params->get('item_counts', 5);
     $skip_counts = $params->get('skip_counts', 0);
     $limit_intro = $params->get('limit_intro', 200);
     // Display
     $show_date = $params->get('show_date', 1);
     $show_hits = $params->get('show_hits', 1);
     $show_tags = $params->get('show_tags', 1);
     $show_image = $params->get('show_image', 1);
     $show_intro = $params->get('show_intro', 1);
     $show_title = $params->get('show_title', 1);
     $show_author = $params->get('show_author', 1);
     $show_avatar = $params->get('show_avatar', 1);
     $show_rating = $params->get('show_rating', 1);
     $show_profile = $params->get('show_profile', 1);
     $show_category = $params->get('show_category', 1);
     $show_comments = $params->get('show_comments', 1);
     // Date
     $date_type = $params->get('date_type', 'created');
     $date_format = $params->get('date_format', 'd F Y');
     // Image
     $image_width = $params->get('image_width', 200);
     $image_height = $params->get('image_height', 100);
     $image_quality = $params->get('image_quality', 100);
     $image_link = $params->get('image_link', 'none');
     $image_title = $params->get('image_title', 1);
     $image_resize = $params->get('image_resize', 1);
     $image_source = $params->get('image_source', 'auto');
     // 3rd-party
     $avatar_width = $params->get('avatar_width', 60);
     $avatar_height = $params->get('avatar_height', 60);
     $avatar_system = $params->get('avatar_system', 'kunena');
     $profile_system = $params->get('profile_system', 'kunena');
     $comments_system = $params->get('comments_system', 'komento');
     // User access
     $authorised = implode(',', $user->getAuthorisedViewLevels());
     // Clean HTML tags
     $clean_intro = $params->get('clean_intro', 1);
     $allowed_tags = str_replace(' ', '', $params->get('allowed_tags'));
     $allowed_tags = "<" . str_replace(',', '><', $allowed_tags) . ">";
     // Content filtering
     $tags_k2 = $params->get('tags_k2', array());
     $author = $params->get('author', array());
     $featured = $params->get('featured', 0);
     // Featured label/ribbon
     $featured_label = $params->get('featured_label', 0);
     $featured_label_text = $params->get('featured_label_text', 'Featured');
     $featured_label_color = $params->get('featured_label_color', '#e52626');
     // Link
     $title_link = $params->get('title_link', 1);
     $category_link = $params->get('category_link', 1);
     if (JFile::exists(JPATH_SITE . '/components/com_k2/k2.php')) {
         if ($source == 'categories' && $categories_k2) {
             if ($categories_k2[0] != '') {
                 $categories_k2 = count($categories_k2) == 1 ? ' = ' . $categories_k2[0] . '' : 'IN (' . implode(',', $categories_k2) . ')';
                 $query->where('a.catid ' . $categories_k2);
             }
             $exclude ? $query->where('a.id NOT IN (' . $exclude . ')') : '';
         } else {
             if ($source == 'articles' && $articles_k2) {
                 $query->where('a.id IN (' . implode(',', $articles_k2) . ')');
             } else {
                 echo JText::_('MOD_GIANTCONTENT_ERROR_SOURCE');
                 return;
             }
         }
     } else {
         echo JText::_('MOD_GIANTCONTENT_ERROR_TYPE_K2');
         return;
     }
     // Ordering
     switch ($ordering) {
         case 'random':
             $orderBy = 'RAND()';
             break;
         case 'id_asc':
             $orderBy = 'a.id ASC';
             break;
         case 'id_desc':
             $orderBy = 'a.id DESC';
             break;
         case 'title_asc':
             $orderBy = 'a.title ASC';
             break;
         case 'title_desc':
             $orderBy = 'a.title DESC';
             break;
         case 'popular_last':
             $orderBy = 'a.hits ASC';
             break;
         case 'popular_first':
             $orderBy = 'a.hits DESC';
             break;
         case 'created_oldest':
             $orderBy = 'date ASC';
             break;
         case 'created_newest':
             $orderBy = 'date DESC';
             break;
         case 'most_rated':
             $orderBy = 'rating_total DESC, r.rating_count DESC';
             break;
         case 'least_rated':
             $orderBy = 'rating_total ASC, r.rating_count ASC';
             break;
         case 'most_commented':
             $orderBy = 'comments_count DESC, comments_date DESC';
             break;
         case 'latest_commented':
             $orderBy = 'comments_date DESC, date DESC';
             break;
     }
     // Content
     $query->select('a.id, a.title, a.alias, a.introtext, a.fulltext, a.hits');
     $query->from('#__k2_items AS a');
     // Category
     $query->select('a.catid AS category_id, c.name AS category_name, c.alias AS category_alias');
     $query->join('LEFT', '#__k2_categories AS c ON c.id = a.catid');
     // Join user
     $query->select('u.id AS user_id, u.email AS user_email, u.name AS user_name, a.created_by_alias AS user_alias');
     $query->join('LEFT', '#__users AS u ON u.id = a.created_by');
     // Join rating
     $query->select('ROUND(AVG(r.rating_sum / r.rating_count), 2) AS rating_average, r.rating_count');
     $query->join('LEFT', '#__k2_rating AS r ON r.itemID = a.id');
     // Select date
     if ($date_type !== 'created') {
         $query->select('CASE WHEN a.' . $date_type . ' = "0000-00-00 00:00:00" THEN a.created ELSE a.' . $date_type . ' END AS date');
     } else {
         $query->select('a.created AS date');
     }
     // Join avatar for author
     if ($show_avatar) {
         switch ($avatar_system) {
             // K2 avatar integration - http://getk2.org
             case 'k2':
                 if (JFile::exists(JPATH_SITE . '/components/com_k2/k2.php')) {
                     $query->select('ua.image AS avatar_user');
                     $query->join('LEFT', '#__k2_users AS ua ON ua.userID = u.id');
                     $avatar_path = 'media/k2/users/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_K2');
                     return;
                 }
                 break;
                 // Kunena avatar integration - http://kunena.org
             // Kunena avatar integration - http://kunena.org
             case 'kunena':
                 if (JFile::exists(JPATH_SITE . '/components/com_kunena/kunena.php')) {
                     $query->select('ua.avatar AS avatar_user');
                     $query->join('LEFT', '#__kunena_users AS ua ON ua.userid = u.id');
                     $avatar_path = 'media/kunena/avatars/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_KUNENA');
                     return;
                 }
                 break;
                 // JomSocial avatar integration - http://jomsocial.com
             // JomSocial avatar integration - http://jomsocial.com
             case 'jomsocial':
                 if (JFile::exists(JPATH_SITE . '/components/com_community/community.php')) {
                     $query->select("ua.avatar AS avatar_user");
                     $query->join('LEFT', '#__community_users AS ua ON ua.userid = u.id');
                     $avatar_path = '';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_JOMSOCIAL');
                     return;
                 }
                 break;
                 // Comprofiler avatar integration - http://joomlapolis.com
             // Comprofiler avatar integration - http://joomlapolis.com
             case 'comprofiler':
                 if (JFile::exists(JPATH_SITE . '/components/com_comprofiler/comprofiler.php')) {
                     $query->select('ua.avatar AS avatar_user');
                     $query->join('LEFT', '#__comprofiler AS ua ON ua.user_id = u.id');
                     $avatar_path = 'images/comprofiler/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_COMPROFILER');
                     return;
                 }
                 break;
                 // EasyBlog avatar integration - http://stackideas.com
             // EasyBlog avatar integration - http://stackideas.com
             case 'easyblog':
                 if (JFile::exists(JPATH_SITE . '/components/com_easyblog/easyblog.php')) {
                     $query->select("ua.avatar AS avatar_user");
                     $query->join('LEFT', '#__easyblog_users AS ua ON ua.id = u.id');
                     $avatar_path = 'images/easyblog_avatar/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_EASYBLOG');
                     return;
                 }
                 break;
                 // EasySocial avatar integration - http://stackideas.com
             // EasySocial avatar integration - http://stackideas.com
             case 'easysocial':
                 if (JFile::exists(JPATH_SITE . '/components/com_easysocial/easysocial.php')) {
                     $query->select("ua.large AS avatar_user");
                     $query->join('LEFT', '#__social_avatars AS ua ON ua.uid = u.id');
                     $avatar_path = 'media/com_easysocial/avatars/users/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_EASYSOCIAL');
                     return;
                 }
                 break;
                 // EasyDiscuss avatar integration - http://stackideas.com
             // EasyDiscuss avatar integration - http://stackideas.com
             case 'easydiscuss':
                 if (JFile::exists(JPATH_SITE . '/components/com_easydiscuss/easydiscuss.php')) {
                     $query->select("ua.avatar AS avatar_user");
                     $query->join('LEFT', '#__discuss_users AS ua ON ua.id = u.id');
                     $avatar_path = 'images/discuss_avatar/';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_AVATAR_SYSTEM_EASYDISCUSS');
                     return;
                 }
                 break;
         }
     }
     // Join comments for content
     if ($show_comments || $ordering == 'most_commented' || $ordering == 'latest_commented') {
         switch ($comments_system) {
             // Default comment system
             case 'default':
                 $query->select('COUNT(cm.id) AS comments_count, MAX(cm.commentDate) AS comments_date');
                 $query->join('LEFT', '#__k2_comments AS cm ON cm.itemID = a.id AND cm.published = 1');
                 $comments_link = '#itemCommentsAnchor';
                 break;
                 // Komento comment integration - http://stackideas.com
             // Komento comment integration - http://stackideas.com
             case 'komento':
                 if (JFile::exists(JPATH_SITE . '/components/com_komento/komento.php')) {
                     $query->select('COUNT(cm.id) AS comments_count, MAX(cm.created) AS comments_date');
                     $query->join('LEFT', '#__komento_comments AS cm ON cm.cid = a.id AND cm.component = "com_k2" AND cm.published = 1');
                     $comments_link = '#section-kmt';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_COMMENTS_SYSTEM_KOMENTO');
                     return;
                 }
                 break;
                 // CComment comment integration - http://compojoom.com
             // CComment comment integration - http://compojoom.com
             case 'ccomment':
                 if (JFile::exists(JPATH_SITE . '/components/com_comment/comment.php')) {
                     $query->select('COUNT(cm.id) AS comments_count, MAX(cm.date) AS comments_date');
                     $query->join('LEFT', '#__comment AS cm ON cm.contentid = a.id AND cm.component = "com_k2" AND cm.published = 1');
                     $comments_link = '#!/ccomment';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_COMMENTS_SYSTEM_CCOMMENT');
                     return;
                 }
                 break;
                 // JComments comment integration - http://joomlatune.com
             // JComments comment integration - http://joomlatune.com
             case 'jcomments':
                 if (JFile::exists(JPATH_SITE . '/components/com_jcomments/jcomments.php')) {
                     $query->select('COUNT(cm.id) AS comments_count, MAX(cm.date) AS comments_date');
                     $query->join('LEFT', '#__jcomments AS cm ON cm.object_id = a.id AND cm.object_group = "com_k2" AND cm.published = 1');
                     $comments_link = '#comments';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_COMMENTS_SYSTEM_JCOMMENTS');
                     return;
                 }
                 break;
                 // JA Comment comment integration - http://joomlart.com
             // JA Comment comment integration - http://joomlart.com
             case 'jacomment':
                 if (JFile::exists(JPATH_SITE . '/components/com_jacomment/jacomment.php')) {
                     $query->select('COUNT(cm.id) AS comments_count, MAX(cm.date) AS comments_date');
                     $query->join('LEFT', '#__jacomment_items AS cm ON cm.contentid = a.id AND cm.option = "com_k2" AND cm.published = 1');
                     $comments_link = '#jac-wrapper';
                 } else {
                     echo JText::_('MOD_GIANTCONTENT_ERROR_COMMENTS_SYSTEM_JACOMMENT');
                     return;
                 }
                 break;
         }
     }
     // Filter tags
     if ($tags_k2) {
         $query->join('INNER', '#__k2_tags_xref AS t ON t.itemID = a.id');
         $query->where('t.tagID IN (' . implode(',', $tags_k2) . ')');
     }
     // Filter author
     if ($author) {
         $query->where('a.created_by IN (' . implode(',', $author) . ')');
     }
     // Filter featured
     if ($featured) {
         $query->where('a.featured = 1');
     }
     // Access or published
     $query->where('a.trash = 0 AND c.trash = 0 AND a.published = 1 AND c.published = 1 AND a.access IN (' . $authorised . ') AND c.access IN (' . $authorised . ') AND a.publish_up <= "' . JFactory::getDate() . '"');
     $query->group('a.id');
     $query->order($orderBy);
     $db->setQuery($query, $skip_counts, $item_counts);
     $items = $db->loadObjectList();
     $lists = array();
     foreach ($items as $i => &$item) {
         $lists[$i] = new stdClass();
         $lists[$i]->id = $item->id;
         $lists[$i]->date = '';
         $lists[$i]->hits = '';
         $lists[$i]->link = '';
         $lists[$i]->tags = '';
         $lists[$i]->intro = '';
         $lists[$i]->image = '';
         $lists[$i]->title = '';
         $lists[$i]->author = '';
         $lists[$i]->avatar = '';
         $lists[$i]->rating = '';
         $lists[$i]->featured = '';
         $lists[$i]->category = '';
         $lists[$i]->comments = '';
         $lists[$i]->readmore = '';
         $lists[$i]->fulltext = $item->fulltext;
         $lists[$i]->introtext = $item->introtext;
         $lists[$i]->category_id = $item->category_id;
         $lists[$i]->category_alias = $item->category_alias;
         // Content link
         $lists[$i]->link = JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->category_id));
         // Readmore link
         $lists[$i]->readmore = $readmore ? '<a href="' . $lists[$i]->link . '"><span>' . $readmore . '</span></a>' : '';
         // Show content date
         $lists[$i]->date = $show_date ? JHtml::_('date', $item->date, $date_format) : '';
         // Show content hits
         $lists[$i]->hits = $show_hits ? '<span>' . $item->hits . '</span>' : '';
         // Show content image
         if ($show_image) {
             $img = array();
             $image = md5("Image" . $item->id);
             if (JFile::exists(JPATH_SITE . '/media/k2/items/src/' . $image . '.jpg')) {
                 $image = 'media/k2/items/src/' . $image . '.jpg';
             } else {
                 $image = '';
             }
             if ($image_source == 'auto') {
                 if (@$image) {
                     $img_source = 'media';
                 } else {
                     $img_source = 'content';
                 }
             } else {
                 $img_source = $image_source;
             }
             if ($img_source == 'media') {
                 if (@$image) {
                     $img['src'] = $image;
                     $img['alt'] = $item->title;
                     $img['ttl'] = $item->title;
                 }
             } else {
                 $pattern = '/<img[^>]+>/i';
                 preg_match($pattern, $item->introtext, $img_tag);
                 if (!count($img_tag)) {
                     preg_match($pattern, $item->fulltext, $img_tag);
                 }
                 if (count($img_tag)) {
                     preg_match_all('/(src|alt|title)\\s*=\\s*(["\'])(.*?)\\2/i', $img_tag[0], $img_elem);
                     $img_elem = array_combine($img_elem[1], $img_elem[3]);
                     if (@$img_elem['src']) {
                         $img['src'] = trim(@$img_elem['src']);
                         $img['alt'] = trim(@$img_elem['alt']);
                         $img['ttl'] = trim(@$img_elem['title']);
                         $item->introtext = preg_replace($pattern, '', $item->introtext, 1);
                     }
                 }
             }
             if (!@$img['src']) {
                 // Default image
                 $img['src'] = 'modules/mod_giantcontent/assets/images/default.png';
                 $img['alt'] = $item->title;
             }
             if ($img['src']) {
                 $img_src = $img_attr = $img_title = '';
                 // Use timthumb to resize image
                 if ($image_resize) {
                     $img_src = JURI::base(true) . '/modules/mod_giantcontent/assets/libraries/includes/timthumb.php?src=';
                     $img_attr = '&amp;w=' . $image_width . '&amp;h=' . $image_height . '&amp;q=' . $image_quality;
                 }
                 $img_src = $img_src && strncasecmp($img['src'], "http", 4) !== 0 ? $img_src . JURI::base(true) . '/' : $img_src;
                 $img['ttl'] = $image_title ? $item->title : @$img['ttl'];
                 $img_title = $img['ttl'] ? 'title="' . $img['ttl'] . '"' : '';
                 $lists[$i]->image = '<img src="' . @$img_src . @$img['src'] . @$img_attr . '" alt="' . @$img['alt'] . '" ' . @$img_title . ' />';
                 switch ($image_link) {
                     case 'none':
                         $lists[$i]->image = $lists[$i]->image;
                         break;
                     case 'content':
                         $lists[$i]->image = '<a href="' . $lists[$i]->link . '">' . $lists[$i]->image . '</a>';
                         break;
                     case 'shadowbox':
                         $lists[$i]->image = '<a href="' . @$img['src'] . '" rel="shadowbox" ' . @$img_title . '>' . $lists[$i]->image . '</a>';
                         break;
                 }
                 $lists[$i]->image_src = @$img['src'];
                 $lists[$i]->image_alt = @$img['alt'];
                 $lists[$i]->image_title = @$img['ttl'];
             }
         }
         // Show author profile
         if ($show_profile) {
             switch ($profile_system) {
                 // K2 profile integration - http://getk2.org
                 case 'k2':
                     if (JFile::exists(JPATH_SITE . '/components/com_k2/k2.php')) {
                         require_once JPATH_SITE . '/components/com_k2/helpers/route.php';
                         $profile_link = JRoute::_(K2HelperRoute::getUserRoute($item->user_id));
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_K2');
                         return;
                     }
                     break;
                     // Kunena profile integration - http://kunena.org
                 // Kunena profile integration - http://kunena.org
                 case 'kunena':
                     if (JFile::exists(JPATH_SITE . '/components/com_kunena/kunena.php')) {
                         $profile_link = KunenaRoute::_('index.php?option=com_kunena&view=profile&userid=' . $item->user_id);
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_KUNENA');
                         return;
                     }
                     break;
                     // JomSocial profile integration - http://jomsocial.com
                 // JomSocial profile integration - http://jomsocial.com
                 case 'jomsocial':
                     if (JFile::exists(JPATH_SITE . '/components/com_community/community.php')) {
                         require_once JPATH_SITE . '/components/com_community/libraries/core.php';
                         $profile_link = CRoute::_('index.php?option=com_community&view=profile&userid=' . $item->user_id);
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_JOMSOCIAL');
                         return;
                     }
                     break;
                     // Comprofiler profile integration - http://joomlapolis.com
                 // Comprofiler profile integration - http://joomlapolis.com
                 case 'comprofiler':
                     if (JFile::exists(JPATH_SITE . '/components/com_comprofiler/comprofiler.php')) {
                         $profile_link = JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='******'MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_COMPROFILER');
                         return;
                     }
                     break;
                     // EasyBlog profile integration - http://stackideas.com
                 // EasyBlog profile integration - http://stackideas.com
                 case 'easyblog':
                     if (JFile::exists(JPATH_SITE . '/components/com_easyblog/easyblog.php')) {
                         require_once JPATH_SITE . '/components/com_easyblog/helpers/router.php';
                         $profile_link = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $item->user_id);
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_EASYBLOG');
                         return;
                     }
                     break;
                     // EasySocial profile integration - http://stackideas.com
                 // EasySocial profile integration - http://stackideas.com
                 case 'easysocial':
                     if (JFile::exists(JPATH_SITE . '/components/com_easysocial/easysocial.php')) {
                         $profile_link = Foundry::user($item->user_id)->getPermalink();
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_EASYSOCIAL');
                         return;
                     }
                     break;
                     // EasyDiscuss profile integration - http://stackideas.com
                 // EasyDiscuss profile integration - http://stackideas.com
                 case 'easydiscuss':
                     if (JFile::exists(JPATH_SITE . '/components/com_easydiscuss/easydiscuss.php')) {
                         require_once JPATH_SITE . '/components/com_easydiscuss/helpers/router.php';
                         $profile_link = DiscussHelper::getTable('Profile')->load($item->user_id)->getLink();
                     } else {
                         echo JText::_('MOD_GIANTCONTENT_ERROR_PROFILE_SYSTEM_EASYDISCUSS');
                         return;
                     }
                     break;
             }
         }
         // Show content intro
         if ($show_intro) {
             // Clean HTML tags
             if ($clean_intro) {
                 $item->introtext = strip_tags($item->introtext, $allowed_tags);
                 $item->introtext = str_replace('&nbsp;', ' ', $item->introtext);
                 $item->introtext = preg_replace('/\\s{2,}/u', ' ', trim($item->introtext));
             }
             $lists[$i]->intro = $limit_intro ? self::truncateText($item->introtext, $limit_intro) : $item->introtext;
         }
         // Show content title
         if ($show_title) {
             $lists[$i]->title_name = $item->title;
             $lists[$i]->title = $title_link ? '<a href="' . $lists[$i]->link . '">' . $lists[$i]->title_name . '</a>' : $lists[$i]->title_name;
         }
         // Show content category
         if ($show_category) {
             $lists[$i]->category_name = $item->category_name;
             $lists[$i]->category_link = JRoute::_(K2HelperRoute::getCategoryRoute($item->category_id . ':' . $item->category_alias));
             $lists[$i]->category = $category_link ? '<a href="' . $lists[$i]->category_link . '">' . $lists[$i]->category_name . '</a>' : $lists[$i]->category_name;
         }
         // Show content comments
         if ($show_comments) {
             $lists[$i]->comments_count = $item->comments_count;
             $lists[$i]->comments_link = $lists[$i]->link . $comments_link;
             $lists[$i]->comments = '<a href="' . $lists[$i]->comments_link . '">' . $item->comments_count . '</a>';
         }
         // Show content author
         if ($show_author) {
             $lists[$i]->author_name = $item->user_alias ? $item->user_alias : $item->user_name;
             $lists[$i]->author = $show_profile ? '<a href="' . $profile_link . '">' . $lists[$i]->author_name . '</a>' : $lists[$i]->author_name;
         }
         // Show profile avatar
         if ($show_avatar) {
             $avatar_src = 'modules/mod_giantcontent/assets/libraries/includes/timthumb.php?src=' . JURI::base(true) . '/';
             $avatar_attr = '&amp;w=' . $avatar_width . '&amp;h=' . $avatar_height;
             $avatar_default = '<img src="' . $avatar_src . '/modules/mod_giantcontent/assets/images/avatar.png' . $avatar_attr . '"  alt="' . $item->user_name . '" />';
             $lists[$i]->avatar_user = $item->avatar_user;
             if ($avatar_system == 'easysocial') {
                 $avatar_img = $avatar_path . $item->user_id . '/' . $item->avatar_user;
             } else {
                 $avatar_img = $avatar_path . $item->avatar_user;
             }
             if (JFile::exists($avatar_img)) {
                 $lists[$i]->avatar = '<img src="' . $avatar_src . $avatar_img . $avatar_attr . '" alt="' . $item->user_name . '" />';
                 $lists[$i]->avatar = $show_profile ? '<a href="' . $profile_link . '">' . $lists[$i]->avatar . '</a>' : $lists[$i]->avatar;
             } else {
                 $lists[$i]->avatar = $show_profile ? '<a href="' . $profile_link . '">' . $avatar_default . '</a>' : $avatar_default;
             }
         }
         // Show content rating
         if ($show_rating) {
             if ($item->rating_count > 0) {
                 $lists[$i]->rating_count = $item->rating_count;
                 $lists[$i]->rating_average = $item->rating_average;
             } else {
                 $lists[$i]->rating_count = 0;
                 $lists[$i]->rating_average = 0.0;
             }
             $rating_current = $item->rating_average * 20;
             $lists[$i]->rating = '<span class="gc-rating-list"><span style="width:' . $rating_current . '%;" class="gc-rating-current"></span></span>';
         }
         // Show content tags
         if ($show_tags) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('t.id, t.name AS title');
             $query->from('#__k2_tags AS t');
             $query->join('LEFT', '#__k2_tags_xref AS tm ON tm.tagID = t.id');
             $query->where('t.published = 1 AND tm.itemID = ' . $item->id);
             $db->setQuery($query);
             $tags = $db->loadObjectList();
             $list_tags = '';
             if ($tags) {
                 foreach ($tags as $tag) {
                     $link_tags = JRoute::_(K2HelperRoute::getTagRoute($tag->title));
                     $list_tags .= '<a class="gc-tag" href="' . $link_tags . '">' . $tag->title . '</a>';
                 }
             }
             $lists[$i]->tags = $list_tags;
         }
         // Show featured label
         if ($featured_label) {
             $db = JFactory::getDbo();
             $db->setQuery('SELECT * FROM #__k2_items WHERE id = ' . $item->id . ' AND featured = 1');
             $featured = $db->loadResult();
             if ($featured) {
                 $lists[$i]->featured = '<span class="gc-featured" style="background: ' . $featured_label_color . '">' . $featured_label_text . '</span>';
             }
         }
     }
     return $lists;
 }
Esempio n. 22
0
 public static function getListItems($cid, &$params)
 {
     $mainframe = JFactory::getApplication();
     $limit = $params->get('itemCount', 5);
     $ordering = $params->get('itemsOrdering', '');
     $user = JFactory::getUser();
     $aid = $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
     $nullDate = $db->getNullDate();
     $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
     if ($ordering == 'best') {
         $query .= ", (r.rating_sum/r.rating_count) AS rating";
     }
     if ($ordering == 'comments') {
         $query .= ", COUNT(comments.id) AS numOfComments";
     }
     $query .= " FROM #__k2_items as i RIGHT JOIN #__k2_categories c ON c.id = i.catid";
     if ($ordering == 'best') {
         $query .= " LEFT JOIN #__k2_rating r ON r.itemID = i.id";
     }
     if ($ordering == 'comments') {
         $query .= " LEFT JOIN #__k2_comments comments ON comments.itemID = i.id";
     }
     if (K2_JVERSION != '15') {
         $query .= " WHERE i.published = 1 AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ")  AND c.trash = 0";
     } else {
         $query .= " WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
     }
     $query .= " AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
     $query .= " AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
     if (!is_null($cid)) {
         if (is_array($cid)) {
             if ($params->get('getChildren')) {
                 $itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
                 $categories = $itemListModel->getCategoryTree($cid);
                 $sql = @implode(',', $categories);
                 $query .= " AND i.catid IN ({$sql})";
             } else {
                 JArrayHelper::toInteger($cid);
                 $query .= " AND i.catid IN(" . implode(',', $cid) . ")";
             }
         } else {
             if ($params->get('getChildren')) {
                 $itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
                 $categories = $itemListModel->getCategoryTree($cid);
                 $sql = @implode(',', $categories);
                 $query .= " AND i.catid IN ({$sql})";
             } else {
                 $query .= " AND i.catid=" . (int) $cid;
             }
         }
     }
     if ($params->get('FeaturedItems') == '0') {
         $query .= " AND i.featured != 1";
     }
     if ($params->get('FeaturedItems') == '2') {
         $query .= " AND i.featured = 1";
     }
     if ($params->get('videosOnly')) {
         $query .= " AND (i.video IS NOT NULL AND i.video!='')";
     }
     if ($ordering == 'comments') {
         $query .= " AND comments.published = 1";
     }
     if (K2_JVERSION != '15') {
         if ($mainframe->getLanguageFilter()) {
             $languageTag = JFactory::getLanguage()->getTag();
             $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")";
         }
     }
     switch ($ordering) {
         case 'date':
             $orderby = 'i.created ASC';
             break;
         case 'rdate':
             $orderby = 'i.created DESC';
             break;
         case 'alpha':
             $orderby = 'i.title';
             break;
         case 'ralpha':
             $orderby = 'i.title DESC';
             break;
         case 'order':
             if ($params->get('FeaturedItems') == '2') {
                 $orderby = 'i.featured_ordering';
             } else {
                 $orderby = 'i.ordering';
             }
             break;
         case 'rorder':
             if ($params->get('FeaturedItems') == '2') {
                 $orderby = 'i.featured_ordering DESC';
             } else {
                 $orderby = 'i.ordering DESC';
             }
             break;
         case 'hits':
             if ($params->get('popularityRange')) {
                 $datenow = JFactory::getDate();
                 $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql();
                 $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
             }
             $orderby = 'i.hits DESC';
             break;
         case 'rand':
             $orderby = 'RAND()';
             break;
         case 'best':
             $orderby = 'rating DESC';
             break;
         case 'comments':
             if ($params->get('popularityRange')) {
                 $datenow = JFactory::getDate();
                 $date = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql();
                 $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $params->get('popularityRange') . " DAY) ";
             }
             $query .= " GROUP BY i.id ";
             $orderby = 'numOfComments DESC';
             break;
         case 'modified':
             $orderby = 'lastChanged DESC';
             break;
         case 'publishUp':
             $orderby = 'i.publish_up DESC';
             break;
         default:
             $orderby = 'i.id DESC';
             break;
     }
     $query .= " ORDER BY " . $orderby;
     $db->setQuery($query, 0, $limit);
     $items = $db->loadObjectList();
     $model = K2Model::getInstance('Item', 'K2Model');
     $show_introtext = $params->get('item_desc_display', 0);
     $introtext_limit = $params->get('item_desc_max_characs', 100);
     $show_title = $params->get('item_title_display', 1);
     $title_limit = $params->get('item_title_max_characs', 20);
     $item_title_ending_char = $params->get('item_title_ending_char', '');
     $item_desc_ending_char = $params->get('item_desc_ending_char', '');
     $show_other_title = $params->get('other_title_display', 1);
     $other_title_limit = $params->get('other_title_max_characs', 20);
     $other_item_title_ending_char = $params->get('other_item_title_ending_char', '');
     if (count($items)) {
         foreach ($items as $item) {
             //Clean title
             $item->title = JFilterOutput::ampReplace($item->title);
             $item->displaytitle = $show_title ? self::truncate($item->title, $title_limit, $item_title_ending_char) : '';
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //Author
             if (!empty($item->created_by_alias)) {
                 $item->author = $item->created_by_alias;
                 $item->authorGender = NULL;
                 $item->authorDescription = NULL;
                 if ($params->get('itemAuthorAvatar')) {
                     $item->authorAvatar = K2HelperUtilities::getAvatar('alias');
                 }
                 $item->authorLink = Juri::root(true);
             } else {
                 $author = JFactory::getUser($item->created_by);
                 $item->author = $author->name;
                 $query = "SELECT `description`, `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                 $db->setQuery($query, 0, 1);
                 $result = $db->loadObject();
                 if ($result) {
                     $item->authorGender = $result->gender;
                     $item->authorDescription = $result->description;
                 } else {
                     $item->authorGender = NULL;
                     $item->authorDescription = NULL;
                 }
                 if ($params->get('itemAuthorAvatar')) {
                     $item->authorAvatar = K2HelperUtilities::getAvatar($author->id, $author->email, $componentParams->get('userImageWidth'));
                 }
                 //Author Link
                 $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
             }
             //Tags
             $item->tags = '';
             if ($params->get('item_tags_display')) {
                 $tags = $model->getItemTags($item->id);
                 for ($i = 0; $i < sizeof($tags); $i++) {
                     $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
                 }
                 $item->tags = $tags;
             }
             // Restore the intotext variable after plugins execution
             self::getK2Images($item, $params);
             //Clean the plugin tags
             $item->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext);
             if ($item->fulltext != '') {
                 $item->fulltext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->fulltext);
                 $item->_introtext = self::_cleanText($item->introtext . $item->fulltext);
             } else {
                 $item->_introtext = self::_cleanText($item->introtext);
             }
             $item->displayIntrotext = $show_introtext ? self::truncate($item->_introtext, $introtext_limit, $item_desc_ending_char) : '';
             $item->othertitle = self::truncate($item->title, $other_title_limit, $other_item_title_ending_char);
             $rows[] = $item;
         }
         return $rows;
     }
 }
Esempio n. 23
0
 /**
  *
  * Get Articles of K2
  * @param array $catids categories of K2
  * @param object $helper
  * @param object $params
  * @return object
  */
 function getArticles($catids, &$helper, $params)
 {
     jimport('joomla.filesystem.file');
     $limit = (int) $params->get('introitems', $helper->get('introitems')) + (int) $params->get('linkitems', $helper->get('linkitems'));
     if (!$limit) {
         $limit = 4;
     }
     $ordering = $helper->get('ordering', '');
     //get params of K2 component
     $componentParams = JComponentHelper::getParams('com_k2');
     $limitstart = 0;
     $user = JFactory::getUser();
     $aid = $user->get('aid') ? $user->get('aid') : 1;
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     //$now 				= $jnow->toMySQL();
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $now = $jnow->toSql();
     } else {
         if (version_compare(JVERSION, '2.5', 'ge')) {
             $now = $jnow->toMySQL();
         } else {
             $now = $jnow->toMySQL();
         }
     }
     $nullDate = $db->getNullDate();
     $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.name as cattitle, c.params AS categoryparams";
     $query .= "\n FROM #__k2_items as i LEFT JOIN #__k2_categories c ON c.id = i.catid";
     $query .= "\n WHERE i.published = 1 AND i.access <= {$aid} AND i.trash = 0 AND c.published = 1 AND c.access <= {$aid} AND c.trash = 0";
     $query .= "\n AND i.catid IN ({$catids})";
     $query .= "\n AND ( i.publish_up = " . $db->Quote($nullDate) . " OR i.publish_up <= " . $db->Quote($now) . " )";
     $query .= "\n AND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )";
     if ($helper->get('featured') == 'hide') {
         $query .= "\n AND i.featured = 0";
     }
     if ($helper->get('featured') == 'only') {
         $query .= "\n AND i.featured = 1";
     }
     if ($helper->get('timerange') > 0) {
         $datenow = JFactory::getDate();
         //$date 		= $datenow->toMySQL();
         if (version_compare(JVERSION, '3.0', 'ge')) {
             $date = $datenow->toSql();
         } else {
             if (version_compare(JVERSION, '2.5', 'ge')) {
                 $date = $datenow->toMySQL();
             } else {
                 $date = $datenow->toMySQL();
             }
         }
         $query .= " AND i.created > DATE_SUB('{$date}',INTERVAL " . $helper->get('timerange') . " DAY) ";
     }
     $sort_order = $helper->get('sort_order', 'DESC');
     switch ($ordering) {
         case 'ordering':
             $ordering = 'ordering ' . $sort_order;
             break;
         case 'rand':
             $ordering = 'RAND()';
             break;
         case 'hits':
             $ordering = 'hits ' . $sort_order;
             break;
         case 'created':
             $ordering = 'created ' . $sort_order;
             break;
         case 'modified':
             $ordering = 'modified ' . $sort_order;
             break;
         case 'title':
             $ordering = 'title ' . $sort_order;
             break;
     }
     if ($ordering == 'RAND()') {
         $query .= "\n ORDER BY " . $ordering;
     } else {
         $query .= "\n ORDER BY i." . $ordering;
     }
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     $autoresize = intval(trim($helper->get('autoresize', 0)));
     $width_img = (int) $helper->get('width', 100) < 0 ? 100 : $helper->get('width', 100);
     $height_img = (int) $helper->get('height', 100) < 0 ? 100 : $helper->get('height', 100);
     $img_w = intval(trim($width_img));
     $img_h = intval(trim($height_img));
     //$img_w 				= intval(trim($helper->get('width', 100)));
     //$img_h 				= intval(trim($helper->get('height', 100)));
     $img_align = $helper->get('align', 'left');
     $showimage = $params->get('showimage', $helper->get('showimage', 0));
     $maxchars = intval(trim($helper->get('maxchars', 200)));
     $hiddenClasses = trim($helper->get('hiddenClasses', ''));
     $showdate = $helper->get('showdate', 0);
     $enabletimestamp = $helper->get('timestamp', 0);
     if (count($rows)) {
         foreach ($rows as $j => $row) {
             $row->introtext1 = "";
             $row->cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->categoryid . ':' . urlencode($row->categoryalias))));
             //Clean title
             $row->title = JFilterOutput::ampReplace($row->title);
             //Images
             $image = '';
             if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XL.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XL.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_XS.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_XS.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_L.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_L.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_S.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_S.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_M.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_M.jpg';
             } elseif (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $row->id) . '_Generic.jpg')) {
                 $image = JURI::root() . 'media/k2/items/cache/' . md5("Image" . $row->id) . '_Generic.jpg';
             }
             if ($image != '') {
                 $thumbnailMode = $helper->get('thumbnail_mode', 'crop');
                 $aspect = $helper->get('use_ratio', '1');
                 $crop = $thumbnailMode == 'crop' ? true : false;
                 $align = $img_align ? "align=\"{$img_align}\"" : "";
                 $jaimage = JAImage::getInstance();
                 if ($thumbnailMode != 'none' && $jaimage->sourceExited($image)) {
                     $imageURL = $jaimage->resize($image, $img_w, $img_h, $crop, $aspect);
                     $imageURL = str_replace(JURI::base(), '', $imageURL);
                     $imageURL = JURI::base() . $imageURL;
                     $row->image = $imageURL ? "<img class=\"{$img_align}\" src=\"" . $imageURL . "\" alt=\"{$row->title}\" {$align} />" : "";
                 } else {
                     $width = $img_w ? "width=\"{$img_w}\"" : "";
                     $height = $img_h ? "height=\"{$img_h}\"" : "";
                     $imageURL = str_replace(JURI::base(), '', $imageURL);
                     $imageURL = JURI::base() . $imageURL;
                     $row->image = "<img class=\"{$img_align}\" src=\"" . $image . "\" alt=\"{$row->title}\" {$img_w} {$img_h} {$align} />";
                 }
                 if ($maxchars && strlen($row->introtext) > $maxchars) {
                     $doc = JDocument::getInstance();
                     if (function_exists('mb_substr')) {
                         $row->introtext1 = SmartTrim::mb_trim($row->introtext, 0, $maxchars, $doc->_charset);
                     } else {
                         $row->introtext1 = SmartTrim::trim($row->introtext, 0, $maxchars);
                     }
                 } elseif ($maxchars == 0) {
                     $row->introtext1 = '';
                 }
                 $helper->replaceImage($row, $img_align, $autoresize, $maxchars, $showimage, $img_w, $img_h, $hiddenClasses);
             } else {
                 $row->image = $helper->replaceImage($row, $img_align, $autoresize, $maxchars, $showimage, $img_w, $img_h, $hiddenClasses);
                 if ($maxchars == 0) {
                     $row->introtext1 = '';
                 }
             }
             // Introtext
             $row->text = $row->introtext;
             //Read more link
             $row->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->id . ':' . urlencode($row->alias), $row->catid . ':' . urlencode($row->categoryalias))));
             $helper->_params->set('parsedInModule', 1);
             $dispatcher = JDispatcher::getInstance();
             if ($helper->get('JPlugins', 1)) {
                 //Plugins
                 $results = $dispatcher->trigger('onBeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onAfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onPrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Init K2 plugin events
             $row->event->K2BeforeDisplay = '';
             $row->event->K2AfterDisplay = '';
             $row->event->K2AfterDisplayTitle = '';
             $row->event->K2BeforeDisplayContent = '';
             $row->event->K2AfterDisplayContent = '';
             $row->event->K2CommentsCounter = '';
             //K2 plugins
             if ($helper->get('K2Plugins', 1)) {
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2BeforeDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplay', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplay = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayTitle', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayTitle = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2BeforeDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2BeforeDisplayContent = trim(implode("\n", $results));
                 $results = $dispatcher->trigger('onK2AfterDisplayContent', array(&$row, &$helper->_params, $limitstart));
                 $row->event->K2AfterDisplayContent = trim(implode("\n", $results));
                 $dispatcher->trigger('onK2PrepareContent', array(&$row, &$helper->_params, $limitstart));
                 $row->introtext = $row->text;
             }
             //Clean the plugin tags
             $row->introtext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $row->introtext);
             $row->introtext = '<p>' . $row->introtext . '</p>';
             //Author
             if ($helper->get('showcreator')) {
                 if (!empty($row->created_by_alias)) {
                     $row->author = $row->created_by_alias;
                     $row->authorGender = NULL;
                 } else {
                     $author = JFactory::getUser($row->created_by);
                     $row->author = $author->name;
                     $query = "SELECT `gender` FROM #__k2_users WHERE userID=" . (int) $author->id;
                     $db->setQuery($query, 0, 1);
                     $row->authorGender = $db->loadResult();
                     //Author Link
                     $row->authorLink = JRoute::_(K2HelperRoute::getUserRoute($row->created_by));
                 }
             }
             $row->created = $row->modified != '' && $row->modified != '0000-00-00 00:00:00' ? $row->modified : $row->created;
             if ($enabletimestamp) {
                 $row->created = $helper->generatTimeStamp($row->created);
             } else {
                 $row->created = JHTML::_('date', $row->created);
             }
             $rows[$j] = $row;
         }
     }
     return $rows;
 }
Esempio n. 24
0
 /**
  * get the list of k2 items
  * 
  * @param JParameter $params;
  * @return Array
  */
 public function __getList($params)
 {
     global $mainframe;
     $maxTitle = $params->get('max_title', '100');
     $maxDesciption = $params->get('max_description', 100);
     $openTarget = $params->get('open_target', 'parent');
     $formatter = $params->get('style_displaying', 'title');
     $titleMaxChars = $params->get('title_max_chars', '100');
     $descriptionMaxChars = $params->get('description_max_chars', 100);
     $condition = $this->buildConditionQuery($params);
     $ordering = $params->get('k2_ordering', 'created_asc');
     $limit = $params->get('limit_items', 5);
     $ordering = str_replace('_', '  ', $ordering);
     $my =& JFactory::getUser();
     $aid = $my->get('aid', 0);
     $limitDescriptionBy = $params->get('limit_description_by', 'char');
     $thumbWidth = (int) $params->get('thumbnail_width', 35);
     $thumbHeight = (int) $params->get('thumbnail_height', 60);
     $imageHeight = (int) $params->get('main_height', 300);
     $imageWidth = (int) $params->get('main_width', 660);
     $isThumb = $params->get('auto_renderthumb', 1);
     $isStripedTags = $params->get('auto_strip_tags', 1);
     $extraURL = $params->get('open_target') != 'modalbox' ? '' : '&tmpl=component';
     $db =& JFactory::getDBO();
     $date =& JFactory::getDate();
     $now = $date->toMySQL();
     require_once JPath::clean(JPATH_SITE . '/components/com_k2/helpers/route.php');
     $query = "SELECT a.*, cr.rating_sum/cr.rating_count as rating, c.name as category_title,\n\t\t\t\t\t\t\tc.id as categoryid, c.alias as categoryalias, c.params as categoryparams, cc.commentcount as commentcount" . " FROM #__k2_items as a" . " LEFT JOIN #__k2_categories c ON c.id = a.catid" . " LEFT JOIN #__k2_rating as cr ON a.id = cr.itemid" . " LEFT JOIN (select cm.itemid  as id, count(cm.id) as commentcount from #__k2_comments as cm\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\twhere cm.published=1 group by cm.itemid) as cc on a.id = cc.id";
     $query .= " WHERE a.published = 1" . " AND a.access IN (" . implode(',', $my->authorisedLevels()) . ")" . " AND a.trash = 0";
     if ($params->get('featured_items_show', '0') == 0) {
         $query .= " AND a.featured != 1";
     } elseif ($params->get('featured_items_show', '0') == 2) {
         $query .= " AND a.featured = 1";
     }
     $query .= $condition . ' ORDER BY ' . $ordering;
     $query .= $limit ? ' LIMIT ' . $limit : '';
     $db->setQuery($query);
     $data = $db->loadObjectlist();
     if (empty($data)) {
         return array();
     }
     foreach ($data as $key => &$item) {
         $item->link = JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . $item->alias, $item->catid . ':' . $item->categoryalias) . $extraURL);
         $item->date = JHtml::_('date', $item->created, JText::_('DATE_FORMAT_LC2'));
         $item->subtitle = $this->substring($item->title, $titleMaxChars);
         if ($limitDescriptionBy == 'word') {
             $string = preg_replace("/\\s+/", " ", strip_tags($item->introtext));
             $tmp = explode(" ", $string);
             $item->description = $descriptionMaxChars > count($tmp) ? $string : implode(" ", array_slice($tmp, 0, $descriptionMaxChars));
         } else {
             $item->description = self::substring($item->introtext, $descriptionMaxChars, '', $isStripedTags);
         }
         $item->rating = is_numeric($item->rating) ? floatval($item->rating / 5 * 100) : null;
         $item->author = $item->created_by;
         $item = $this->generateImages($item, $isThumb);
         $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
         if ($params->get('itemAuthor')) {
             if (!empty($item->created_by_alias)) {
                 $item->author = $item->created_by_alias;
                 $item->authorGender = NULL;
             } 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();
                 //Author Link
                 $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
             }
         }
     }
     return $data;
 }
Esempio n. 25
0
 public function getProfileLink($defaultItemId = '')
 {
     static $instance = array();
     static $phpbbDB = null;
     static $phpbbpath = null;
     static $isBlogger = array();
     // since it's for avatar, we'll follow the avatar's integration
     $config = EasyBlogHelper::getConfig();
     $source = $config->get('layout_avatarIntegration');
     if (!$config->get('main_nonblogger_profile')) {
         // 1st check if this user a blogger or not.
         $showLink = false;
         if (isset($isBlogger[$this->id])) {
             $showLink = $isBlogger[$this->id];
         } else {
             $showLink = EasyBlogHelper::isBlogger($this->id);
             $isBlogger[$this->id] = $showLink;
         }
         if (!$showLink) {
             return 'javascript: void(0);';
         }
     }
     // phpbb case
     if ($source == 'phpbb' && $phpbbDB === null) {
         $phpbbpath = $config->get('layout_phpbb_path');
         $file = JPATH_ROOT . DIRECTORY_SEPARATOR . $phpbbpath . DIRECTORY_SEPARATOR . 'config.php';
         if (JFile::exists($file)) {
             require $file;
             $host = $dbhost;
             $user = $dbuser;
             $password = $dbpasswd;
             $database = $dbname;
             $prefix = $table_prefix;
             $driver = $dbms;
             $debug = 0;
             $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
             $phpbbDB = JDatabase::getInstance($options);
         } else {
             $phpbbDB = false;
         }
     }
     if ($phpbbDB === false) {
         // can't get phpbb's config file, fallback to default profile link
         $source = 'default';
     }
     // Always use the core linking if user does not wants this.
     if (!$config->get('layout_avatar_link_name')) {
         $source = 'default';
     }
     // to ensure the passed in value is only a number
     $defaultItemId = str_replace('&Itemid=', '', $defaultItemId);
     // to ensure the uniqueness of the key
     $key = $source . '-' . $defaultItemId;
     // this is where the magic starts
     if (!isset($instance[$this->id][$key])) {
         $defaultItemId = !empty($defaultItemId) ? '&Itemid=' . $defaultItemId : '';
         $defaultLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $this->id . $defaultItemId);
         switch ($source) {
             case 'k2':
                 $file1 = JPATH_ROOT . '/components/com_k2/helpers/route.php';
                 $file2 = JPATH_ROOT . '/components/com_k2/helpers/utilities.php';
                 jimport('joomla.filesystem.file');
                 if (JFile::exists($file1) && JFile::exists($file2)) {
                     require_once $file1;
                     require_once $file2;
                     $ret = K2HelperRoute::getUserRoute($this->id);
                 } else {
                     $ret = $defaultLink;
                 }
                 break;
             case 'mightyregistration':
                 $ret = JRoute::_('index.php?option=com_community&view=profile&user_id=' . $this->id, false);
                 break;
             case 'communitybuilder':
                 $ret = JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='******'easysocial':
                 $easysocial = EasyBlogHelper::getHelper('EasySocial');
                 $ret = '';
                 if ($easysocial->exists()) {
                     $easysocial->init();
                     $user = Foundry::user($this->id);
                     $ret = $user->getPermalink();
                 }
                 break;
             case 'jomsocial':
                 $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'core.php';
                 $ret = JFile::exists($file) && (require_once $file) ? CRoute::_('index.php?option=com_community&view=profile&userid=' . $this->id) : '';
                 break;
             case 'kunena':
                 $ret = JRoute::_('index.php?option=com_kunena&func=fbprofile&userid=' . $this->id, false);
                 break;
             case 'phpbb':
                 $juser = JFactory::getUser($this->id);
                 $query = 'SELECT ' . $phpbbDB->nameQuote('user_id') . ' ' . 'FROM ' . $phpbbDB->nameQuote('#__users') . ' WHERE LOWER(' . $phpbbDB->nameQuote('username') . ') = LOWER(' . $phpbbDB->quote($juser->username) . ') ';
                 $phpbbDB->setQuery($query, 0, 1);
                 $phpbbuserid = $phpbbDB->loadResult();
                 $ret = $phpbbuserid ? JURI::root() . rtrim($phpbbpath, '/') . '/memberlist.php?mode=viewprofile&u=' . $phpbbuserid : '';
                 break;
             case 'anahita':
                 $person = KFactory::get('lib.anahita.se.person.helper')->getPerson($this->id);
                 $ret = $person->getURL();
                 break;
             case 'easydiscuss':
                 $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easydiscuss' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'router.php';
                 $ret = JFile::exists($file) && (require_once $file) ? DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&id=' . $this->id, false) : '';
                 break;
             case 'gravatar':
             case 'default':
             default:
                 $ret = '';
                 break;
         }
         $instance[$this->id][$key] = $ret ? $ret : $defaultLink;
     }
     return $instance[$this->id][$key];
 }
Esempio n. 26
0
 function getTopCommenters(&$params)
 {
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables');
     $limit = $params->get('commenters_limit', '5');
     $user =& JFactory::getUser();
     $aid = $user->get('aid');
     $db =& JFactory::getDBO();
     $query = "SELECT COUNT(id) as counter, userName, userID, commentEmail FROM #__k2_comments" . " WHERE userID > 0" . " AND published = 1";
     " GROUP BY userID ORDER BY counter DESC";
     $db->setQuery($query, 0, $limit);
     $rows = $db->loadObjectList();
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models' . DS . 'item.php';
     $model = new K2ModelItem();
     $componentParams =& JComponentHelper::getParams('com_k2');
     if (count($rows)) {
         foreach ($rows as $row) {
             if ($row->counter > 0) {
                 $row->link = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
                 if ($params->get('commentAvatar')) {
                     $row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
                 }
                 if ($params->get('commenterLatestComment')) {
                     $query = "SELECT * FROM #__k2_comments" . " WHERE userID = {$row->userID}" . " AND published = 1" . " ORDER BY commentDate DESC";
                     $db->setQuery($query, 0, 1);
                     $comment = $db->loadObject();
                     $item =& JTable::getInstance('K2Item', 'Table');
                     $item->load($comment->itemID);
                     $category =& JTable::getInstance('K2Category', 'Table');
                     $category->load($item->catid);
                     $row->latestCommentText = $comment->commentText;
                     $row->latestCommentLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($category->alias)))) . "#comment{$comment->id}";
                     $row->latestCommentDate = $comment->commentDate;
                 }
                 $commenters[] = $row;
             }
         }
         if (isset($commenters)) {
             return $commenters;
         }
     }
 }
Esempio n. 27
0
    function display($tpl = null)
    {
        $mainframe =& JFactory::getApplication();
        $user =& JFactory::getUser();
        $document =& JFactory::getDocument();
        $params =& JComponentHelper::getParams('com_k2');
        $limitstart = JRequest::getInt('limitstart', 0);
        $view = JRequest::getWord('view');
        $task = JRequest::getWord('task');
        $db =& JFactory::getDBO();
        $jnow =& JFactory::getDate();
        $now = $jnow->toMySQL();
        $nullDate = $db->getNullDate();
        $this->setLayout('item');
        //Add link
        if (K2HelperPermissions::canAddItem()) {
            $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
        }
        $this->assignRef('addLink', $addLink);
        //Get item
        $model =& $this->getModel();
        $item = $model->getData();
        //Prepare item
        if ($user->guest) {
            $cache =& JFactory::getCache('com_k2_extended');
            $hits = $item->hits;
            $item->hits = 0;
            $item = $cache->call(array('K2ModelItem', 'prepareItem'), $item, $view, $task);
            $item->hits = $hits;
        } else {
            $item = $model->prepareItem($item, $view, $task);
        }
        //Plugins
        $item = $model->execPlugins($item, $view, $task);
        //Access check
        if ($this->getLayout() == 'form') {
            JError::raiseError(403, JText::_("ALERTNOTAUTH"));
        }
        if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
            JError::raiseError(403, JText::_("ALERTNOTAUTH"));
        }
        //Published check
        if (!$item->published || $item->trash) {
            JError::raiseError(404, JText::_("Item not found"));
        }
        if ($item->publish_up != $nullDate && $item->publish_up > $now) {
            JError::raiseError(404, JText::_("Item not found"));
        }
        if ($item->publish_down != $nullDate && $item->publish_down < $now) {
            JError::raiseError(404, JText::_("Item not found"));
        }
        if (!$item->category->published || $item->category->trash) {
            JError::raiseError(404, JText::_("Item not found"));
        }
        //Increase hits counter
        $model->hit($item->id);
        //Set default image
        K2HelperUtilities::setDefaultImage($item, $view);
        //Comments
        $item->event->K2CommentsCounter = '';
        $item->event->K2CommentsBlock = '';
        if ($item->params->get('itemComments')) {
            //Trigger comments events
            $dispatcher =& JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsCounter = trim(implode("\n", $results));
            $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsBlock = trim(implode("\n", $results));
            //Load K2 native comments system only if there are no plugins overriding it
            if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
                //Load reCAPTCHA script
                if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
                    if ($item->params->get('recaptcha') && $user->guest) {
                        $document->addScript('http://api.recaptcha.net/js/recaptcha_ajax.js');
                        $js = 'function showRecaptcha(){
								    Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
								        theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
								    });
								}
								window.addEvent(\'load\', function(){
									showRecaptcha();
								})';
                        $document->addScriptDeclaration($js);
                    }
                    //Auto complete some fields for registered users
                    if (!$user->guest) {
                        $js = "window.addEvent('domready', function(){\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('value','" . $user->name . "');\n\t\t\t\t\t\t\t\t\t\$('userName').setProperty('disabled','disabled');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('value','" . $user->email . "');\n\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('disabled','disabled');\n\n\t\t\t\t\t\t\t\t})";
                        $document->addScriptDeclaration($js);
                    }
                }
                $limit = $params->get('commentsLimit');
                $comments = $model->getItemComments($item->id, $limitstart, $limit);
                $pattern = "@\\b(https?://)?(([0-9a-zA-Z_!~*'().&=+\$%-]+:)?[0-9a-zA-Z_!~*'().&=+\$%-]+\\@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\\@&=+\$,%#-]+)*/?)@";
                for ($i = 0; $i < sizeof($comments); $i++) {
                    $comments[$i]->commentText = nl2br($comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\\0">\\0</a>', $comments[$i]->commentText);
                    $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
                    if ($comments[$i]->userID > 0) {
                        $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
                    } else {
                        $comments[$i]->userLink = $comments[$i]->commentURL;
                    }
                }
                $item->comments = $comments;
                jimport('joomla.html.pagination');
                $total = $item->numOfComments;
                $pagination = new JPagination($total, $limitstart, $limit);
            }
        }
        //Author's latest items
        if ($params->get('itemAuthorLatest') && $item->created_by_alias == '') {
            $model =& $this->getModel('itemlist');
            $authorLatestItems = $model->getAuthorLatest($item->id, $params->get('itemAuthorLatestLimit'), $item->created_by);
            if (count($authorLatestItems)) {
                for ($i = 0; $i < sizeof($authorLatestItems); $i++) {
                    $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias))));
                }
                $this->assignRef('authorLatestItems', $authorLatestItems);
            }
        }
        //Related items
        if ($params->get('itemRelated') && isset($item->tags) && count($item->tags)) {
            $model =& $this->getModel('itemlist');
            $relatedItems = $model->getRelatedItems($item->id, $item->tags, $params->get('itemRelatedLimit'));
            if (count($relatedItems)) {
                for ($i = 0; $i < sizeof($relatedItems); $i++) {
                    $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias))));
                }
                $this->assignRef('relatedItems', $relatedItems);
            }
        }
        //Navigation (previous and next item)
        if ($params->get('itemNavigation')) {
            $model =& $this->getModel('item');
            $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);
            if (!is_null($nextItem)) {
                $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias))));
                $item->nextTitle = $nextItem->title;
            }
            $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);
            if (!is_null($previousItem)) {
                $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias))));
                $item->previousTitle = $previousItem->title;
            }
        }
        // Absolute URL
        $uri =& JURI::getInstance();
        $item->absoluteURL = $uri->_uri;
        //Email link
        $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . base64_encode($item->absoluteURL));
        //Twitter link
        if ($params->get('itemTwitterLink') && $params->get('twitterUsername')) {
            $itemURLForTwitter = $params->get('tinyURL') ? @file_get_contents('http://tinyurl.com/api-create.php?url=' . $item->absoluteURL) : $item->absoluteURL;
            $item->twitterURL = 'http://twitter.com/home/?status=' . urlencode('Reading @' . $params->get('twitterUsername') . ' ' . $item->title . ' ' . $itemURLForTwitter);
        }
        //Social link
        $item->socialLink = urlencode($item->absoluteURL);
        //Look for template files in component folders
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
        //Look for overrides in template folder (K2 template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
        //Look for overrides in template folder (Joomla! template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
        //Look for specific K2 theme files
        if ($item->params->get('theme')) {
            $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme'));
        }
        //Assign data
        $this->assignRef('item', $item);
        $this->assignRef('user', $user);
        $this->assignRef('params', $item->params);
        $this->assignRef('pagination', $pagination);
        parent::display($tpl);
    }
Esempio n. 28
0
 private static function k2($profile)
 {
     $file1 = JPATH_ROOT . '/components/com_k2/helpers/route.php';
     $file2 = JPATH_ROOT . '/components/com_k2/helpers/utilities.php';
     if (!JFile::exists($file1) || !JFile::exists($file2)) {
         return false;
     }
     require_once $file1;
     require_once $file2;
     $db = DiscussHelper::getDBO();
     $query = 'SELECT * FROM ' . $db->nameQuote('#__k2_users') . ' ' . 'WHERE ' . $db->nameQuote('userID') . '=' . $db->Quote($profile->id);
     $db->setQuery($query);
     $result = $db->loadObject();
     if (!$result || !$result->image) {
         return false;
     }
     $avatarLink = DISCUSS_JURIROOT . '/media/k2/users/' . $result->image;
     $profileLink = K2HelperRoute::getUserRoute($profile->id);
     return array($avatarLink, $profileLink);
 }
Esempio n. 29
0
<ul class="k2UserBlockActions">
	<?php 
if (is_object($user->profile) && isset($user->profile->addLink)) {
    ?>
	<li> <a class="modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php 
    echo $user->profile->addLink;
    ?>
"><?php 
    echo JText::_('K2_ADD_NEW_ITEM');
    ?>
</a> </li>
	<?php 
}
?>
	<li> <a href="<?php 
echo JRoute::_(K2HelperRoute::getUserRoute($user->id));
?>
"><?php 
echo JText::_('K2_MY_PAGE');
?>
</a> </li>
	<li> <a href="<?php 
echo $profileLink;
?>
"><?php 
echo JText::_('K2_MY_ACCOUNT');
?>
</a> </li>
	<li> <a class="modal" rel="{handler:'iframe',size:{x:990,y:550}}" href="<?php 
echo JRoute::_('index.php?option=com_k2&view=comments&tmpl=component');
?>
Esempio n. 30
0
 /**
  * call back function for processing data before render
  */
 public static function onBeforeRender($item, $descriptionMaxChars = 100, $limitDescriptionBy = 'char', $isAuthor = false)
 {
     //Read more link
     $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
     $item->date = JHtml::_('date', $item->created, JText::_('DATE_FORMAT_LC3'));
     if ($limitDescriptionBy == 'word') {
         $string = preg_replace("/\\s+/", " ", strip_tags($item->introtext));
         $tmp = explode(" ", $string);
         $item->description = $descriptionMaxChars > count($tmp) ? $string : implode(" ", array_slice($tmp, 0, $descriptionMaxChars));
     } else {
         $item->description = self::substring($item->introtext, $descriptionMaxChars);
     }
     $item->rating = is_numeric($item->rating) ? floatval($item->rating / 5 * 100) : null;
     $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
     $item->authorLink = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
     if ($isAuthor) {
         if (!empty($item->created_by_alias)) {
             $item->author = $item->created_by_alias;
         } else {
             $author =& JFactory::getUser($item->created_by);
             $item->author = $author->name;
         }
     }
     return $item;
 }