예제 #1
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;
 }
 function generateLayout($config, $data)
 {
     /*
     	Available variables:
     	{TITLE} - article title
     			{TEXT} - article text
     			{URL} - article URL
     			{IMAGE_SRC} - article image URL
     			{AUTHOR_EMAIL} - article autor e-mail 
     			{AUTHOR_NAME} - article author name
     			{AUTHOR_URL} - article author URL
     			{CATEGORY} - article category name
     			{CATEGORY_URL} - article category URL
     			{HITS} - article hits
     			{DATE} - article date (gets format from the information block settings)
     			{RATING} - article rating
     	K2 specific variables:
     	{TAGS} - article tag lists
     			{VIDEO_HTML} - HTML of the article video
     			{CATEGORY_IMAGE_SRC} - article category image URL
     			{AVATAR_URL} - user avatar URL
     	{{extra_field_alias}} - value of the extra field with specific alias
     			{{extra_field_alias_X}} - value of X-nth element in the array of the extra field data - indexing starts with 0
     */
     //
     // Get the values
     //
     // Image
     $viewClass = 'NSP_GK5_' . $config['source_name'] . '_View';
     // Basic data
     $title = NSP_GK5_Utils::cutText($data['title'], $config, 'title_limit');
     $text = NSP_GK5_Utils::cutText($data['text'], $config, 'news_limit');
     // URL
     $url = '';
     if (isset($data['url'])) {
         $url = $data['url'];
     } else {
         $url = call_user_func(array($viewClass, 'itemLink'), $data, $config);
     }
     // PHP 5.3:
     //$image_src = $viewClass::image($config, $data, true);
     $image_src = call_user_func(array($viewClass, 'image'), $config, $data, true);
     // Author data
     $author_email = $data['author_email'];
     $author_name = $data['author_username'];
     $author_url = call_user_func(array($viewClass, 'authorLink'), $data);
     // Category data
     $category = $data['catname'];
     $category_url = '';
     if (isset($data['caturl'])) {
         $category_url = $data['caturl'];
     } else {
         $category_url = call_user_func(array($viewClass, 'categoryLink'), $data);
     }
     // detect K2
     $avatar = '';
     if (isset($data['video'])) {
         $avatar = K2HelperUtilities::getAvatar($data['author_id'], $data['author_email'], $config['avatar_size']);
     }
     // Other data
     $hits = $data['hits'];
     $date = JHTML::_('date', $data['date'], $config['date_format']);
     $rating = $item['rating_count'] > 0 ? number_format($data['rating_sum'] / $data['rating_count'], 2) : 0;
     //
     // Get the layout text
     //
     if ($config['article_format'] != '-1' && is_file(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'article_formats' . DS . $config['article_format']) || $config['article_format'] == '-1' && $config['article_format_text'] != '') {
         // read the format file
         $format_file = $config['article_format_text'];
         if ($config['article_format'] != '-1') {
             $format_file = file_get_contents(JPATH_ROOT . DS . 'modules' . DS . 'mod_news_pro_gk5' . DS . 'article_formats' . DS . $config['article_format']);
         }
         // replace values
         $to_replace = array('{TITLE}', '{TEXT}', '{URL}', '{IMAGE_SRC}', '{AUTHOR_EMAIL}', '{AUTHOR_NAME}', '{AUTHOR_URL}', '{CATEGORY}', '{CATEGORY_URL}', '{HITS}', '{DATE}', '{RATING}', '{AVATAR_URL}');
         // values for the replacement
         $replacement = array($title, $text, $url, $image_src, $author_email, $author_name, $author_url, $category, $category_url, $hits, $date, $rating, $avatar);
         // replace values in the format file
         $format_file = str_replace($to_replace, $replacement, $format_file);
         // replacements only for K2
         if (stripos($config['data_source'], 'k2_') !== FALSE) {
             // tags list value
             $tags = '';
             // if tags exists
             if (isset($data['tags']) && count($data['tags']) > 0) {
                 $i = 0;
                 foreach ($data['tags'] as $tag) {
                     $link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tag)));
                     if ($i == 0) {
                         $tags .= '<a href="' . $link . '">' . $tag . '</a>';
                     } else {
                         $tags .= ', <a href="' . $link . '">' . $tag . '</a>';
                     }
                     //
                     $i++;
                 }
             }
             // video HTML value
             $video_html = $data['video'];
             // category image URL value
             $category_image_src = '';
             // if the category image exists
             if ($data['cat_image'] != '') {
                 $category_image_src = JURI::root() . 'media/k2/categories/' . $data['cat_image'];
             }
             // replace values
             $to_replace = array('{TAGS}', '{VIDEO_HTML}', '{CATEGORY_IMAGE_SRC}');
             // values for the replacement
             $replacement = array($tags, $video_html, $category_image_src);
             // replace values in the format file
             $format_file = str_replace($to_replace, $replacement, $format_file);
             // if using of the extra fields is enabled
             if ($config['k2_get_extra_fields'] == 1) {
                 $keywords = array_keys($data['extra_fields']);
                 $to_replace = array();
                 $replacement = array();
                 // prepare the replacement arrays
                 foreach ($keywords as $keyword) {
                     if (is_array($data['extra_fields'][$keyword])) {
                         for ($i = 0; $i < count($data['extra_fields'][$keyword]); $i++) {
                             array_push($to_replace, '{{' . $keyword . '_' . $i . '}}');
                             array_push($replacement, $data['extra_fields'][$keyword][$i]);
                         }
                     } else {
                         array_push($to_replace, '{{' . $keyword . '}}');
                         array_push($replacement, $data['extra_fields'][$keyword]);
                     }
                 }
                 // replace values in the format file
                 $format_file = str_replace($to_replace, $replacement, $format_file);
             }
         }
         // parse lang rules
         $matches = array();
         preg_match_all('@{{.*?}}@', $format_file, $matches);
         if (count($matches) > 0) {
             for ($i = 0; $i < count($matches); $i++) {
                 $phrase = $matches[$i][0];
                 $phrase = JText::_(str_replace(array('{{', '}}'), '', $phrase));
                 $format_file = str_replace($matches[$i][0], $phrase, $format_file);
             }
         }
         // PARSING PLUGINS
         if ($config['parse_plugins'] == TRUE) {
             $format_file = JHtml::_('content.prepare', $format_file);
         }
         // CLEANING PLUGINS
         if ($config['clean_plugins'] == TRUE) {
             $format_file = preg_replace("/(\\{.+?\\}.+?\\{.+?})|(\\{.+?\\})/", "", $format_file);
         }
         return $format_file;
     } else {
         return '';
     }
 }
예제 #3
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);
    }
예제 #4
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     $document = JFactory::getDocument();
     if (K2_JVERSION == '15') {
         $document->setMimeEncoding('application/json');
         $document->setType('json');
     }
     $model = $this->getModel('itemlist');
     //Set limit for model
     $limit = JRequest::getInt('limit');
     if ($limit > 100 || $limit == 0) {
         $limit = 100;
         JRequest::setVar('limit', $limit);
     }
     $page = JRequest::getInt('page');
     if ($page <= 0) {
         $limitstart = 0;
     } else {
         $page--;
         $limitstart = $page * $limit;
     }
     JRequest::setVar('limitstart', $limitstart);
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     $response = new JObject();
     unset($response->_errors);
     // Site
     $response->site = new stdClass();
     $uri = JURI::getInstance();
     $response->site->url = $uri->toString(array('scheme', 'host', 'port'));
     $config = JFactory::getConfig();
     $response->site->name = K2_JVERSION == '30' ? $config->get('sitename') : $config->getValue('config.sitename');
     $moduleID = JRequest::getInt('moduleID');
     if ($moduleID) {
         $result = $model->getModuleItems($moduleID);
         $items = $result->items;
         $title = $result->title;
         $prefix = 'cat';
     } else {
         //Get data depending on task
         switch ($task) {
             case 'category':
                 //Get category
                 $id = JRequest::getInt('id');
                 JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
                 $category = JTable::getInstance('K2Category', 'Table');
                 $category->load($id);
                 // State Check
                 if (!$category->published || $category->trash) {
                     JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
                 }
                 //Access check
                 $user = JFactory::getUser();
                 if (K2_JVERSION != '15') {
                     if (!in_array($category->access, $user->getAuthorisedViewLevels())) {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                     }
                     $languageFilter = $mainframe->getLanguageFilter();
                     $languageTag = JFactory::getLanguage()->getTag();
                     if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                         return;
                     }
                 } else {
                     if ($category->access > $user->get('aid', 0)) {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                     }
                 }
                 //Merge params
                 $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
                 if ($cparams->get('inheritFrom')) {
                     $masterCategory = JTable::getInstance('K2Category', 'Table');
                     $masterCategory->load($cparams->get('inheritFrom'));
                     $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
                 }
                 $params->merge($cparams);
                 //Category link
                 $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
                 //Category image
                 $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
                 //Category plugins
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('content');
                 $category->text = $category->description;
                 if (K2_JVERSION != '15') {
                     $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
                 } else {
                     $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
                 }
                 $category->description = $category->text;
                 //Category K2 plugins
                 $category->event->K2CategoryDisplay = '';
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
                 $category->event->K2CategoryDisplay = trim(implode("\n", $results));
                 $category->text = $category->description;
                 $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
                 $category->description = $category->text;
                 //Category children
                 $ordering = $params->get('subCatOrdering');
                 $children = $model->getCategoryFirstChildren($id, $ordering);
                 $subCategories = array();
                 if (count($children)) {
                     foreach ($children as $child) {
                         if ($params->get('subCatTitleItemCounter')) {
                             $child->numOfItems = $model->countCategoryItems($child->id);
                         }
                         $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                         $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                         unset($child->params);
                         unset($child->access);
                         unset($child->published);
                         unset($child->trash);
                         unset($child->language);
                         $subCategories[] = $child;
                     }
                 }
                 //Set featured flag
                 JRequest::setVar('featured', $params->get('catFeaturedItems'));
                 //Set title
                 $title = $category->name;
                 // Set ordering
                 if ($params->get('singleCatOrdering')) {
                     $ordering = $params->get('singleCatOrdering');
                 } else {
                     $ordering = $params->get('catOrdering');
                 }
                 // Set parameters prefix
                 $prefix = 'cat';
                 // Prepare the JSON category object;
                 $row = new JObject();
                 unset($row->_errors);
                 $row->id = $category->id;
                 $row->name = $category->name;
                 $row->alias = $category->alias;
                 $row->link = $category->link;
                 $row->parent = $category->parent;
                 $row->extraFieldsGroup = $category->extraFieldsGroup;
                 $row->image = $category->image;
                 $row->ordering = $category->ordering;
                 //$row->plugins = $category->plugins;
                 $row->events = $category->event;
                 $row->chidlren = $subCategories;
                 $response->category = $row;
                 break;
             case 'user':
                 //Get user
                 $id = JRequest::getInt('id');
                 $userObject = JFactory::getUser($id);
                 //Check user status
                 if ($userObject->block) {
                     JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
                 }
                 //Get K2 user profile
                 $userObject->profile = $model->getUserProfile();
                 //User image
                 $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
                 //User K2 plugins
                 $userObject->event->K2UserDisplay = '';
                 if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                     $dispatcher = JDispatcher::getInstance();
                     JPluginHelper::importPlugin('k2');
                     $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                     $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                     $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8');
                 }
                 //Set title
                 $title = $userObject->name;
                 // Set ordering
                 $ordering = $params->get('userOrdering');
                 // Set parameters prefix
                 $prefix = 'user';
                 // Prepare the JSON user object;
                 $row = new JObject();
                 unset($row->_errors);
                 //$row->id = $userObject->id;
                 $row->name = $userObject->name;
                 //$row->username = $userObject->username;
                 if (isset($userObject->profile->plugins)) {
                     unset($userObject->profile->plugins);
                 }
                 $row->profile = $userObject->profile;
                 $row->avatar = $userObject->avatar;
                 $row->events = $userObject->event;
                 $response->user = $row;
                 break;
             case 'tag':
                 //Set limit
                 $limit = $params->get('tagItemCount');
                 //set title
                 $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
                 // Set ordering
                 $ordering = $params->get('tagOrdering');
                 // Set parameters prefix
                 $prefix = 'tag';
                 $response->tag = JRequest::getVar('tag');
                 break;
             case 'search':
                 //Set title
                 $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
                 // Set parameters prefix
                 $prefix = 'generic';
                 $response->search = JRequest::getVar('searchword');
                 break;
             case 'date':
                 // Set title
                 if (JRequest::getInt('day')) {
                     $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                     $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                     $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
                 } else {
                     $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                     $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                     $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
                 }
                 // Set ordering
                 $ordering = 'rdate';
                 // Set parameters prefix
                 $prefix = 'generic';
                 $response->date = JHTML::_('date', $date, $dateFormat);
                 break;
             default:
                 $user = JFactory::getUser();
                 //Set limit
                 $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
                 //Set featured flag
                 JRequest::setVar('featured', $params->get('catFeaturedItems'));
                 //Set title
                 $title = $params->get('page_title');
                 // Set ordering
                 $ordering = $params->get('catOrdering');
                 // Set parameters prefix
                 $prefix = 'cat';
                 break;
         }
         if (!isset($ordering)) {
             $items = $model->getData();
         } else {
             $items = $model->getData($ordering);
         }
     }
     //Prepare items
     $user = JFactory::getUser();
     $cache = JFactory::getCache('com_k2_extended');
     $model = JModelLegacy::getInstance('item', 'K2Model');
     $rows = array();
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             $items[$i]->itemGroup = 'links';
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         } else {
             $items[$i]->itemGroup = '';
         }
         $itemParams = class_exists('JParameter') ? new JParameter($items[$i]->params) : new JRegistry($items[$i]->params);
         $itemParams->set($prefix . 'ItemIntroText', true);
         $itemParams->set($prefix . 'ItemFullText', true);
         $itemParams->set($prefix . 'ItemTags', true);
         $itemParams->set($prefix . 'ItemExtraFields', true);
         $itemParams->set($prefix . 'ItemAttachments', true);
         $itemParams->set($prefix . 'ItemRating', true);
         $itemParams->set($prefix . 'ItemAuthor', true);
         $itemParams->set($prefix . 'ItemImageGallery', true);
         $itemParams->set($prefix . 'ItemVideo', true);
         $itemParams->set($prefix . 'ItemImage', true);
         $items[$i]->params = $itemParams->toString();
         //Check if model should use cache for preparing item even if user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         //Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         //Plugins
         $items[$i]->params->set('genericItemIntroText', $params->get('catItemIntroText'));
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         //Trigger comments counter event
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
         // Set default image
         if ($task == 'user' || $task == 'tag' || $task == 'search' || $task == 'date') {
             $items[$i]->image = isset($items[$i]->imageGeneric) ? $items[$i]->imageGeneric : '';
         } else {
             if (!$moduleID) {
                 K2HelperUtilities::setDefaultImage($items[$i], $view, $params);
             }
         }
         $rows[] = $model->prepareJSONItem($items[$i]);
     }
     $response->items = $rows;
     // Prevent spammers from using the tag view
     if ($task == 'tag' && !count($response->items)) {
         $tag = JRequest::getString('tag');
         $db = JFactory::getDBO();
         $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag));
         $tagID = $db->loadResult();
         if (!$tagID) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
             return false;
         }
     }
     // Output
     $json = json_encode($response);
     $callback = JRequest::getCmd('callback');
     if ($callback) {
         $document->setMimeEncoding('application/javascript');
         echo $callback . '(' . $json . ')';
     } else {
         echo $json;
     }
 }
예제 #5
0
파일: view.raw.php 프로젝트: emavro/k2
 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);
 }
예제 #6
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;
         }
     }
 }
예제 #7
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $params =& K2HelperUtilities::getParams('com_k2');
     $model =& $this->getModel('itemlist');
     $limitstart = JRequest::getInt('limitstart');
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     //Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     //Get data depending on task
     switch ($task) {
         case 'category':
             //Get category
             $id = JRequest::getInt('id');
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $category =& JTable::getInstance('K2Category', 'Table');
             $category->load($id);
             // State Check
             if (!$category->published || $category->trash) {
                 JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
             }
             //Access check
             $user =& JFactory::getUser();
             if (K2_JVERSION == '16') {
                 if (!in_array($category->access, $user->authorisedLevels())) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
                 $languageFilter = $mainframe->getLanguageFilter();
                 $languageTag = JFactory::getLanguage()->getTag();
                 if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                     return;
                 }
             } else {
                 if ($category->access > $user->get('aid', 0)) {
                     JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                 }
             }
             // Hide the add new item link if user cannot post in the specific category
             if (!K2HelperPermissions::canAddItem($id)) {
                 unset($this->addLink);
             }
             //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 link
             $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
             //Category image
             $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
             //Category plugins
             $dispatcher =& JDispatcher::getInstance();
             JPluginHelper::importPlugin('content');
             $category->text = $category->description;
             if (K2_JVERSION == '16') {
                 $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
             } else {
                 $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
             }
             $category->description = $category->text;
             //Category K2 plugins
             $category->event->K2CategoryDisplay = '';
             JPluginHelper::importPlugin('k2');
             $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
             $category->event->K2CategoryDisplay = trim(implode("\n", $results));
             $category->text = $category->description;
             $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
             $category->description = $category->text;
             $this->assignRef('category', $category);
             $this->assignRef('user', $user);
             //Category children
             $ordering = $params->get('subCatOrdering');
             $children = $model->getCategoryFirstChildren($id, $ordering);
             if (count($children)) {
                 foreach ($children as $child) {
                     if ($params->get('subCatTitleItemCounter')) {
                         $child->numOfItems = $model->countCategoryItems($child->id);
                     }
                     $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                     $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                     $subCategories[] = $child;
                 }
                 $this->assignRef('subCategories', $subCategories);
             }
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set layout
             $this->setLayout('category');
             //Set title
             $title = $category->name;
             // Set ordering
             if ($params->get('singleCatOrdering')) {
                 $ordering = $params->get('singleCatOrdering');
             } else {
                 $ordering = $params->get('catOrdering');
             }
             break;
         case 'user':
             //Get user
             $id = JRequest::getInt('id');
             $userObject =& JFactory::getUser($id);
             //Check user status
             if ($userObject->block) {
                 JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
             }
             //Get K2 user profile
             $userObject->profile = $model->getUserProfile();
             //User image
             $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
             //User K2 plugins
             $userObject->event->K2UserDisplay = '';
             if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                 $userObject->event->K2UserDisplay = trim(implode("\n", $results));
             }
             $this->assignRef('user', $userObject);
             //Set layout
             $this->setLayout('user');
             //Set limit
             $limit = $params->get('userItemCount');
             //Set title
             $title = $userObject->name;
             // Set ordering
             $ordering = $params->get('userOrdering');
             break;
         case 'tag':
             //Set layout
             $this->setLayout('tag');
             //Set limit
             $limit = $params->get('tagItemCount');
             //set title
             $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
             // Set ordering
             $ordering = $params->get('tagOrdering');
             break;
         case 'search':
             //Set layout
             $this->setLayout('generic');
             $tpl = JRequest::getCmd('tpl', null);
             //Set limit
             $limit = $params->get('genericItemCount');
             //Set title
             $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
             break;
         case 'date':
             //Set layout
             $this->setLayout('generic');
             //Set limit
             $limit = $params->get('genericItemCount');
             // Set title
             if (JRequest::getInt('day')) {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                 $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             } else {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                 $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             }
             // Set ordering
             $ordering = 'rdate';
             break;
         default:
             //Set layout
             $this->setLayout('category');
             $user =& JFactory::getUser();
             $this->assignRef('user', $user);
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set title
             $title = $params->get('page_title');
             // Set ordering
             $ordering = $params->get('catOrdering');
             break;
     }
     //Set limit for model
     JRequest::setVar('limit', $limit);
     if (!isset($ordering)) {
         $items = $model->getData();
     } else {
         $items = $model->getData($ordering);
     }
     //Pagination
     jimport('joomla.html.pagination');
     $total = $model->getTotal();
     $pagination = new JPagination($total, $limitstart, $limit);
     //Prepare items
     $user =& JFactory::getUser();
     $cache =& JFactory::getCache('com_k2_extended');
     $model =& $this->getModel('item');
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         }
         //Check if model should use cache for preparing item even if user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         //Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         //Plugins
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         //Trigger comments counter event
         $dispatcher =& JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
     }
     //Pathway
     $pathway =& $mainframe->getPathWay();
     $pathway->addItem($title);
     //Feed link
     $config =& JFactory::getConfig();
     $menu =& JSite::getMenu();
     $default = $menu->getDefault();
     $active = $menu->getActive();
     if ($task == 'tag') {
         $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag'));
     } else {
         $link = '';
     }
     if (!is_null($active) && $active->id == $default->id && $config->getValue('config.sef')) {
         $link .= '&Itemid=' . $active->id . '&format=feed&limitstart=';
     } else {
         $link .= '&format=feed&limitstart=';
     }
     $feed = JRoute::_($link);
     $this->assignRef('feed', $feed);
     //Assign data
     if ($task == "category" || $task == "") {
         $leading = @array_slice($items, 0, $params->get('num_leading_items'));
         $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items'));
         $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items'));
         $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links'));
         $this->assignRef('leading', $leading);
         $this->assignRef('primary', $primary);
         $this->assignRef('secondary', $secondary);
         $this->assignRef('links', $links);
     } else {
         $this->assignRef('items', $items);
     }
     //Set default values to avoid division by zero
     if ($params->get('num_leading_columns') == 0) {
         $params->set('num_leading_columns', 1);
     }
     if ($params->get('num_primary_columns') == 0) {
         $params->set('num_primary_columns', 1);
     }
     if ($params->get('num_secondary_columns') == 0) {
         $params->set('num_secondary_columns', 1);
     }
     if ($params->get('num_links_columns') == 0) {
         $params->set('num_links_columns', 1);
     }
     $this->assignRef('params', $params);
     $this->assignRef('pagination', $pagination);
     //Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     //Look for specific K2 theme files
     if ($params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme'));
     }
     $db =& JFactory::getDBO();
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     parent::display($tpl);
 }
예제 #8
0
 static function info($config, $item, $num = 1)
 {
     // %AUTHOR %DATE %HITS %CATEGORY
     $news_info = '';
     //
     if ($num == 1) {
         if ($config['news_content_info_pos'] != 'disabled') {
             $class = 'nspInfo1 t' . $config['news_content_info_pos'] . ' f' . $config['news_content_info_float'];
         }
     } else {
         if ($config['news_content_info2_pos'] != 'disabled') {
             $class = 'nspInfo2 t' . $config['news_content_info2_pos'] . ' f' . $config['news_content_info2_float'];
         }
     }
     //
     if ($config['news_content_info_pos'] != 'disabled' && $num == 1 || $config['news_content_info2_pos'] != 'disabled' && $num == 2) {
         $news_info = '<p class="nspInfo ' . $class . '">' . $config['info' . ($num == 2 ? '2' : '') . '_format'] . '</p>';
         //
         $author = trim(htmlspecialchars($item['author_alias'])) != '' ? htmlspecialchars($item['author_alias']) : htmlspecialchars($item['author_username']);
         $info_author = $config['user_avatar'] == 1 ? '<span><img src="' . K2HelperUtilities::getAvatar($item['author_id'], $item['author_email'], $config['avatar_size']) . '" alt="' . $author . ' - avatar" class="nspAvatar" width="' . $config['avatar_size'] . '" height="' . $config['avatar_size'] . '" /> ' . $author . '</span>' : $author;
         //
         $info_date = JHTML::_('date', $item['date'], $config['date_format']);
         //
         $info_hits = JText::_('MOD_NEWS_PRO_GK5_NHITS') . $item['hits'];
         $info_rate = $item['rating_count'] > 0 ? '<span class="nspRate">' . JText::_('MOD_NEWS_PRO_GK5_NSP_RATE') . ' ' . number_format($item['rating_sum'] / $item['rating_count'], 2) . '</span>' : '';
         $info_category = $config['category_link'] == 1 ? '<a href="' . NSP_GK5_com_k2_View::categoryLink($item) . '" >' . $item['catname'] . '</a>' : $item['catname'];
         $info_comments = JText::_('MOD_NEWS_PRO_GK5_NO_COMMENTS');
         //
         if (isset($item['comments'])) {
             if ($item['comments'] == 1) {
                 $info_comments = JText::_('MOD_NEWS_PRO_GK5_1COMMENT');
             } else {
                 if ($item['comments'] > 1 && $item['comments'] < 5) {
                     $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MORECOMMENTS');
                 } else {
                     if ($item['comments'] >= 5) {
                         $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MUCHMORECOMMENTS');
                     }
                 }
             }
         }
         //
         $info_tags = '';
         if (isset($item['tags']) && count($item['tags']) > 0) {
             $i = 0;
             foreach ($item['tags'] as $tag) {
                 $link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tag)));
                 if ($i == 0) {
                     $info_tags .= '<a href="' . $link . '">' . $tag . '</a>';
                 } else {
                     $info_tags .= ', <a href="' . $link . '">' . $tag . '</a>';
                 }
                 //
                 $i++;
             }
         }
         //
         $news_info = str_replace('%AUTHOR', $info_author, $news_info);
         $news_info = str_replace('%DATE', $info_date, $news_info);
         $news_info = str_replace('%HITS', $info_hits, $news_info);
         $news_info = str_replace('%CATEGORY', $info_category, $news_info);
         $news_info = str_replace('%RATE', $info_rate, $news_info);
         $news_info = str_replace('%COMMENTS', $info_comments, $news_info);
         $news_info = str_replace('%TAGS', $info_tags, $news_info);
     } else {
         return '';
     }
     //
     return $news_info;
 }
예제 #9
0
 static function info($config, $item, $num = 1)
 {
     // %AUTHOR %DATE %HITS %CATEGORY
     $news_info = '';
     //
     if ($num == 1) {
         if ($config['news_content_info_pos'] != 'disabled') {
             $class = 'nspInfo1 t' . $config['news_content_info_pos'] . ' f' . $config['news_content_info_float'];
         }
     } else {
         if ($config['news_content_info2_pos'] != 'disabled') {
             $class = 'nspInfo2 t' . $config['news_content_info2_pos'] . ' f' . $config['news_content_info2_float'];
         }
     }
     //
     if ($config['news_content_info_pos'] != 'disabled' && $num == 1 || $config['news_content_info2_pos'] != 'disabled' && $num == 2) {
         $news_info_tag = stripos($config['info' . ($num == 2 ? '2' : '') . '_format'], '%CART') !== FALSE ? 'div' : 'p';
         $news_info = '<' . $news_info_tag . ' class="nspInfo ' . $class . '">' . $config['info' . ($num == 2 ? '2' : '') . '_format'] . '</' . $news_info_tag . '>';
         //
         $author = trim(htmlspecialchars($item['author_alias'])) != '' ? htmlspecialchars($item['author_alias']) : htmlspecialchars($item['author_username']);
         $info_author = $config['user_avatar'] == 1 ? '<span><img src="' . K2HelperUtilities::getAvatar($item['author_id'], $item['author_email'], $config['avatar_size']) . '" alt="' . $author . ' - avatar" class="nspAvatar" width="' . $config['avatar_size'] . '" height="' . $config['avatar_size'] . '" /> ' . $author . '</span>' : $author;
         //
         $info_date = JHTML::_('date', $item['date'], $config['date_format']);
         //
         $info_hits = JText::_('MOD_NEWS_PRO_GK5_NHITS') . $item['hits'];
         // case when there is no rates
         if ($item['rating_count'] == 0) {
             $item['rating_count'] = 1;
         }
         $info_rate = $item['rating_count'] > 0 ? '<span class="nspRate">' . JText::_('MOD_NEWS_PRO_GK5_NSP_RATE') . ' ' . number_format($item['rating_sum'] / $item['rating_count'], 2) . '</span>' : '';
         $info_stars = '<span class="nsp-stars">';
         $stars_count = floor($item['rating_sum'] / $item['rating_count']);
         for ($i = 0; $i < 5; $i++) {
             $info_stars .= $i < $stars_count ? '<span class="nsp-star-1"></span>' : '<span class="nsp-star-0"></span>';
         }
         $info_stars .= '</span>';
         $info_category = $config['category_link'] == 1 ? '<a href="' . NSP_GK5_com_k2_View::categoryLink($item) . '" >' . $item['catname'] . '</a>' : $item['catname'];
         $info_comments = JText::_('MOD_NEWS_PRO_GK5_NO_COMMENTS');
         //
         if (isset($item['comments'])) {
             if ($item['comments'] == 1) {
                 $info_comments = JText::_('MOD_NEWS_PRO_GK5_1COMMENT');
             } else {
                 if ($item['comments'] > 1 && $item['comments'] < 5) {
                     $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MORECOMMENTS');
                 } else {
                     if ($item['comments'] >= 5) {
                         $info_comments = $item['comments'] . ' ' . JText::_('MOD_NEWS_PRO_GK5_MUCHMORECOMMENTS');
                     }
                 }
             }
         }
         //
         $info_comments_short = '0';
         $link = NSP_GK5_com_k2_View::itemLink($item);
         //
         if (isset($item['comments'])) {
             $info_comments_short = $item['comments'];
         }
         $info_comments_short = '<a href="' . $link . '">' . $info_comments_short . '</a>';
         //
         $info_tags = '';
         if (isset($item['tags']) && count($item['tags']) > 0) {
             $i = 0;
             foreach ($item['tags'] as $tag) {
                 $link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tag)));
                 if ($i == 0) {
                     $info_tags .= '<a href="' . $link . '">' . $tag . '</a>';
                 } else {
                     $info_tags .= ', <a href="' . $link . '">' . $tag . '</a>';
                 }
                 //
                 $i++;
             }
         }
         // get k2 store data
         $k2store_data = array('cart' => '', 'price' => '');
         // get K2Store data if necessary
         if (stripos($news_info, '%CART') !== FALSE || stripos($news_info, '%PRICE') !== FALSE) {
             $k2store_data = NSP_GK5_com_k2_View::k2Store($item);
             if (stripos($news_info, '%CART') !== FALSE) {
                 // load K2Store scripts
                 $uri = JURI::getInstance();
                 $document = JFactory::getDocument();
                 $headData = $document->getHeadData();
                 // generate keys of script section
                 $headData_keys = array_keys($headData["scripts"]);
                 // set variable for false
                 $engine_founded = false;
                 // searching phrase mootools in scripts paths
                 if (array_search($uri->root() . 'media/k2store/js/k2store.js', $headData_keys) > 0) {
                     $engine_founded = true;
                 }
                 // if engine doesn't exists in the head section
                 if (!$engine_founded) {
                     // add new script tag connected with mootools from module
                     $document->addScript($uri->root() . 'media/k2store/js/k2store.noconflict.js');
                     $document->addScript($uri->root() . 'media/k2store/js/k2store.js');
                 }
             }
         }
         //
         $news_info = str_replace('%AUTHOR', $info_author, $news_info);
         $news_info = str_replace('%DATE', $info_date, $news_info);
         $news_info = str_replace('%HITS', $info_hits, $news_info);
         $news_info = str_replace('%CATEGORY', $info_category, $news_info);
         $news_info = str_replace('%STARS', $info_stars, $news_info);
         $news_info = str_replace('%RATE', $info_rate, $news_info);
         $news_info = str_replace('%COMMENTS_SHORT', $info_comments_short, $news_info);
         $news_info = str_replace('%COMMENTS', $info_comments, $news_info);
         $news_info = str_replace('%TAGS', $info_tags, $news_info);
         $news_info = str_replace('%CART', $k2store_data['cart'], $news_info);
         $news_info = str_replace('%PRICE', $k2store_data['price'], $news_info);
     } else {
         return '';
     }
     //
     return $news_info;
 }
예제 #10
0
// no direct access
defined('_JEXEC') or die;

?>

<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2UserBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">

	<?php if($userGreetingText): ?>
	<p class="ubGreeting"><?php echo $userGreetingText; ?></p>
  <?php endif; ?>

	<div class="k2UserBlockDetails">
	  <?php if($params->get('userAvatar')): ?>
	  <a class="k2Avatar ubAvatar" href="<?php echo JRoute::_(K2HelperRoute::getUserRoute($user->id)); ?>" title="<?php echo JText::_('K2_MY_PAGE'); ?>">
	  	<img src="<?php echo K2HelperUtilities::getAvatar($user->id, $user->email); ?>" alt="<?php echo K2HelperUtilities::cleanHtml($user->name); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
	  </a>
	  <?php 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>
예제 #11
0
파일: view.html.php 프로젝트: emavro/k2
    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);
    }
예제 #12
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;
         }
     }
 }
예제 #13
0
function getAvatar($userId,$wallversion)
{	
$path=JURI::base(); 
$temp='plugins/content/loadjomwall/';
$path=str_replace($temp,'',$path);
$db =& JFactory::getDBO();
$app = JFactory::getApplication('site');
$config =  & $app->getParams('com_awdwall');
$template 		= $config->get('temp', 'blue');
$avatarintergration 		= $config->get('avatarintergration', '0');
		$query 	= "SELECT facebook_id FROM #__jconnector_ids WHERE user_id = "  . (int)$userId;
		$db->setQuery($query);
		$facebook_id = $db->loadResult();
		if($facebook_id)
		{
			$avatar='https://graph.facebook.com/'.$facebook_id.'/picture?type=square';
		}
		else
		{
			
			$query 	= 'SELECT avatar FROM #__awd_wall_users WHERE user_id = ' . (int)$userId;
			$db 	= & JFactory::getDBO();
			$db->setQuery($query);
			$img = $db->loadResult();		
			
			if($img == NULL){
				$avatar = $path . "components/com_awdwall/images/".$template."/".$template."32.png";
			}else{
				$avatar = $path. "images/wallavatar/" . $userId . "/thumb/tn32" . $img;
			}
			
		}
	    if($avatarintergration==1) // k2
		{
				if(file_exists(JPATH_SITE . '/components/com_k2/k2.php'))
				{
					require_once (JPATH_SITE . '/components/com_k2/helpers/utilities.php');
				
				$avatar=K2HelperUtilities::getAvatar($userId);
				}
		}
		else if($avatarintergration==2) // easyblog
		{
				if(file_exists(JPATH_SITE . '/components/com_easyblog/easyblog.php'))
				{
					require_once (JPATH_SITE . '/components/com_easyblog/helpers/helper.php');
				
				$blogger	= EasyBlogHelper::getTable( 'Profile', 'Table');
				$blogger->load( $userId );
				$avatar=$blogger->getAvatar();
				}
		}
		else if($avatarintergration==3) // alphauserpoint
		{
				if(file_exists(JPATH_SITE . '/components/com_alphauserpoints/alphauserpoints.php'))
				{
					require_once (JPATH_SITE . '/components/com_alphauserpoints/helper.php');
					require_once (JPATH_SITE . '/components/com_alphauserpoints/helpers/helpers.php');
				
					$_user_info = AlphaUserPointsHelper::getUserInfo ( $referrerid='', $userId  );
					$com_params = &JComponentHelper::getParams( 'com_alphauserpoints' );
					$useAvatarFrom = $com_params->get('useAvatarFrom');
					$height = 32;
					$width=32;
					$avatar = getAvatar( $useAvatarFrom, $_user_info, $height,$width);	
					$doc = new DOMDocument();
					$doc->loadHTML($avatar);
					$imageTags = $doc->getElementsByTagName('img');
					
					foreach($imageTags as $tag) {
						$avatar=$tag->getAttribute('src');
					}
				}
		}
		return $avatar;
}
예제 #14
0
 function info_k2($config, $news_catname, $news_cid, $news_cat_alias, $news_author, $news_author_id, $news_author_email, $news_date, $news_hits, $news_id, $news_alias, $comments, $rating_count, $rating_sum, $num = 1)
 {
     //
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php';
     require_once JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php';
     // %AUTHOR %COMMENTS %DATE %HITS %CATEGORY %RATE
     $news_info = '';
     //
     if ($num == 1) {
         if ($config['news_content_info_pos'] != 'disabled') {
             $class = ' nspInfo1 t' . $config['news_content_info_pos'] . ' f' . $config['news_content_info_float'];
         }
     } else {
         if ($config['news_content_info2_pos'] != 'disabled') {
             $class = ' nspInfo2 t' . $config['news_content_info2_pos'] . ' f' . $config['news_content_info2_float'];
         }
     }
     //
     if ($config['news_content_info_pos'] != 'disabled' && $num == 1 || $config['news_content_info2_pos'] != 'disabled' && $num == 2) {
         $news_info = '<p class="nspInfo ' . $class . '">' . $config['info' . ($num == 2 ? '2' : '') . '_format'] . '</p>';
         //
         $info_category = $config['category_link'] == 1 ? '<a href="' . urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($news_cid . ':' . urlencode($news_cat_alias)))) . '" >' . $news_catname . '</a>' : $news_catname;
         $info_author = $config['user_avatar'] == 1 ? '<span><img src="' . K2HelperUtilities::getAvatar($news_author_id, $news_author_email, $config['avatar_size']) . '" alt="' . htmlspecialchars($news_author) . ' - avatar" class="nspAvatar" width="' . $config['avatar_size'] . '" height="' . $config['avatar_size'] . '" /> ' . $news_author . '</span>' : $news_author;
         $info_date = JHTML::_('date', $news_date, $config['date_format']);
         $info_hits = JText::_('MOD_NEWS_PRO_GK4_NHITS') . $news_hits;
         //
         if ($config['no_comments_text'] && (!isset($comments['art' . $news_id]) || $comments['art' . $news_id] == 0)) {
             $comments_amount = JText::_('MOD_NEWS_PRO_GK4_NO_COMMENTS');
         } else {
             $comments_amount = JText::_('MOD_NEWS_PRO_GK4_COMMENTS') . ' (' . (isset($comments['art' . $news_id]) ? $comments['art' . $news_id] : '0') . ')';
         }
         $info_comments = '<a class="nspComments" href="' . urldecode(JRoute::_(K2HelperRoute::getItemRoute($news_id . ':' . urlencode($news_alias), $news_cid . ':' . urlencode($news_cat_alias)))) . '#itemCommentsAnchor">' . $comments_amount . '</a>';
         //
         $info_rate = $rating_count > 0 ? '<span class="nspRate">' . JText::_('MOD_NEWS_PRO_GK4_NSP_RATE') . ' <strong>' . number_format($rating_sum / $rating_count, 2) . '</strong></span>' : '';
         //
         $news_info = str_replace('%AUTHOR', $info_author, $news_info);
         $news_info = str_replace('%COMMENTS', $info_comments, $news_info);
         $news_info = str_replace('%DATE', $info_date, $news_info);
         $news_info = str_replace('%HITS', $info_hits, $news_info);
         $news_info = str_replace('%CATEGORY', $info_category, $news_info);
         $news_info = str_replace('%RATE', $info_rate, $news_info);
     }
     //
     return $news_info;
 }
예제 #15
0
파일: comment.php 프로젝트: Tommar/remate
 public function getListComment($portfolioId, $limit, $limitstart, $orderDir)
 {
     // Create a new query object.
     $db = JFactory::getDBO();
     $query = $db->getQuery(true);
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     // Select fields
     $query->select('*');
     // From the bt portfolio_comments table
     $query->from('#__bt_portfolio_comments');
     $query->where('published = 1');
     $query->where('item_id = ' . $portfolioId);
     $query->order('created ' . $orderDir);
     if (!$limit) {
         $limit = $app->getCfg('list_limit', 0);
     }
     $items = $this->_getList($query, $limitstart, $limit);
     $params = JComponentHelper::getParams("com_bt_portfolio");
     $user->image = '';
     $user->link = '';
     $avatar_type = $params->get('avatars_integrated');
     foreach ($items as $item) {
         $item->image = '';
         $item->link = '';
         $item->admin = false;
         if ($user->authorise('core.admin')) {
             $item->admin = true;
         }
         switch ($avatar_type) {
             case 'k2':
                 if (is_file(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php')) {
                     JLoader::register('K2HelperRoute', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'route.php');
                     JLoader::register('K2HelperUtilities', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php');
                     $item->image = K2HelperUtilities::getAvatar($item->user_id, $item->email);
                     if ($item->user_id) {
                         $item->link = JRoute::_(K2HelperRoute::getUserRoute($item->user_id));
                     } else {
                         $item->link = "#";
                     }
                 }
                 break;
             case 'cb':
                 global $_CB_framework, $_CB_database, $ueConfig, $mainframe, $_SERVER;
                 if (defined('JPATH_ADMINISTRATOR')) {
                     if (!file_exists(JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php')) {
                         echo 'CB not installed';
                         break;
                     }
                     include_once JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php';
                 } else {
                     if (!file_exists($mainframe->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.foundation.php')) {
                         echo 'CB not installed';
                         break;
                     }
                     include_once $mainframe->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.foundation.php';
                 }
                 $cbUser =& CBuser::getInstance($item->user_id);
                 $item->image = $cbUser->avatarFilePath();
                 if ($item->user_id) {
                     $item->link = JRoute::_('index.php?option=com_comprofiler&task=userProfile&user=' . $item->user_id);
                 }
                 break;
             default:
                 break;
         }
     }
     return $items;
 }
예제 #16
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;
     }
 }
예제 #17
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);
 }
예제 #18
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;
     }
 }
예제 #19
0
 function prepareItem($item, $view, $task)
 {
     jimport('joomla.filesystem.file');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $limitstart = JRequest::getInt('limitstart');
     //Initialize params
     if ($view != 'item') {
         $component = JComponentHelper::getComponent('com_k2');
         $params = new JParameter($component->params);
         $itemid = JRequest::getInt('Itemid');
         if ($itemid) {
             $menu = JSite::getMenu();
             $menuparams = $menu->getParams($itemid);
             $params->merge($menuparams);
         }
     } else {
         $params =& JComponentHelper::getParams('com_k2');
     }
     //Category
     $db =& JFactory::getDBO();
     $query = "SELECT * FROM #__k2_categories WHERE id={$item->catid}";
     $db->setQuery($query, 0, 1);
     $category = $db->loadObject();
     $item->category = $category;
     $item->category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
     //Read more link
     $link = K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->category->alias));
     $item->link = urldecode(JRoute::_($link));
     //Print link
     $item->printLink = urldecode(JRoute::_($link . '&tmpl=component&print=1'));
     //Params
     $cparams = new JParameter($category->params);
     $iparams = new JParameter($item->params);
     $item->params = $params;
     if ($cparams->get('inheritFrom')) {
         $masterCategoryID = $cparams->get('inheritFrom');
         $query = "SELECT * FROM #__k2_categories WHERE id={$masterCategoryID}";
         $db->setQuery($query, 0, 1);
         $masterCategory = $db->loadObject();
         $cparams = new JParameter($masterCategory->params);
     }
     $item->params->merge($cparams);
     $item->params->merge($iparams);
     //Edit link
     if (K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         $item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid=' . $item->id . '&tmpl=component');
     }
     //Tags
     if ($view == 'item' && ($item->params->get('itemTags') || $item->params->get('itemRelated')) || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemTags') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemTags') || $view == 'latest' && $params->get('latestItemTags')) {
         $tags = K2ModelItem::getItemTags($item->id);
         for ($i = 0; $i < sizeof($tags); $i++) {
             $tags[$i]->link = urldecode(JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name)));
         }
         $item->tags = $tags;
     }
     //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';
     }
     //Extra fields
     if ($view == 'item' && $item->params->get('itemExtraFields') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemExtraFields') || $view == 'itemlist' && ($task == 'search' || $task == 'tag' || $task == 'date') && $item->params->get('genericItemExtraFields')) {
         $item->extra_fields = K2ModelItem::getItemExtraFields($item->extra_fields);
     }
     //Attachments
     if ($view == 'item' && $item->params->get('itemAttachments') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemAttachments')) {
         $item->attachments = K2ModelItem::getItemAttachments($item->id);
     }
     //Import plugins
     $dispatcher =& JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     //Gallery
     if ($view == 'item' && $item->params->get('itemImageGallery') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemImageGallery')) {
         $params->set('galleries_rootfolder', 'media/k2/galleries');
         $params->set('popup_engine', 'mootools_slimbox');
         $params->set('enabledownload', '0');
         $item->text = $item->gallery;
         $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
         $item->gallery = $item->text;
     }
     //Video
     if ($view == 'item' && $item->params->get('itemVideo') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemVideo') || $view == 'latest' && $item->params->get('latestItemVideo')) {
         if (!empty($item->video) && JString::substr($item->video, 0, 1) !== '{') {
             $item->video = $item->video;
             $item->videoType = 'embedded';
         } else {
             $item->videoType = 'allvideos';
             $params->set('vfolder', 'media/k2/videos');
             if ($view == 'item') {
                 $params->set('vwidth', $item->params->get('itemVideoWidth'));
                 $params->set('vheight', $item->params->get('itemVideoHeight'));
                 $params->set('autoplay', $item->params->get('itemVideoAutoPlay'));
             } else {
                 if ($view == 'latest') {
                     $params->set('vwidth', $item->params->get('latestItemVideoWidth'));
                     $params->set('vheight', $item->params->get('latestItemVideoHeight'));
                     $params->set('autoplay', $item->params->get('latestItemVideoAutoPlay'));
                 } else {
                     $params->set('vwidth', $item->params->get('catItemVideoWidth'));
                     $params->set('vheight', $item->params->get('catItemVideoHeight'));
                     $params->set('autoplay', $item->params->get('catItemVideoAutoPlay'));
                 }
             }
             $item->text = $item->video;
             $dispatcher->trigger('onPrepareContent', array(&$item, &$params, $limitstart));
             $item->video = $item->text;
         }
     }
     //Rating
     if ($view == 'item' && $item->params->get('itemRating') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemRating')) {
         $item->votingPercentage = K2ModelItem::getVotesPercentage($item->id);
         $item->numOfvotes = K2ModelItem::getVotesNum($item->id);
     }
     //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);
     }
     if ($item->params->get('catItemIntroTextWordLimit') && $task == 'category') {
         $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
     }
     //Plugins
     $item->text = '';
     $params->set('vfolder', NULL);
     $params->set('vwidth', NULL);
     $params->set('vheight', NULL);
     $params->set('autoplay', NULL);
     $params->set('galleries_rootfolder', NULL);
     $params->set('popup_engine', NULL);
     $params->set('enabledownload', NULL);
     if ($view == 'item') {
         if ($item->params->get('itemIntroText')) {
             $item->text .= $item->introtext;
         }
         if ($item->params->get('itemFullText')) {
             $item->text .= '{K2Splitter}' . $item->fulltext;
         }
     } else {
         switch ($task) {
             case '':
             case 'category':
                 if ($item->params->get('catItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
             case 'user':
                 if ($item->params->get('userItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
             default:
                 if ($item->params->get('genericItemIntroText')) {
                     $item->text .= $item->introtext;
                 }
                 break;
         }
     }
     $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));
     //Author
     if ($view == 'item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor')) || $view == 'itemlist' && ($task == '' || $task == 'category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) || $view == 'itemlist' && $task == 'user') {
         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;
         }
     }
     //Num of comments
     $item->numOfComments = K2ModelItem::countItemComments($item->id);
     //K2 plugins
     $item->event->K2BeforeDisplay = '';
     $item->event->K2AfterDisplay = '';
     $item->event->K2AfterDisplayTitle = '';
     $item->event->K2BeforeDisplayContent = '';
     $item->event->K2AfterDisplayContent = '';
     if ($view == 'item' && $item->params->get('itemK2Plugins') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemK2Plugins') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemK2Plugins')) {
         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 ($view == 'item') {
         @(list($item->introtext, $item->fulltext) = explode('{K2Splitter}', $item->text));
     } else {
         $item->introtext = $item->text;
     }
     return $item;
 }
예제 #20
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);
 }
예제 #21
0
파일: helper.php 프로젝트: Tommar/remate
 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;
 }
예제 #22
0
 function display($tpl = null)
 {
     $mainframe =& JFactory::getApplication();
     $params =& JComponentHelper::getParams('com_k2');
     $model =& $this->getModel('itemlist');
     $limitstart = JRequest::getInt('limitstart');
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     //Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     //Get data depending on task
     switch ($task) {
         case 'category':
             //Get category
             $id = JRequest::getInt('id');
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $category =& JTable::getInstance('K2Category', 'Table');
             $category->load($id);
             //Access check
             $user =& JFactory::getUser();
             if ($category->access > $user->get('aid', 0)) {
                 JError::raiseError(403, JText::_("ALERTNOTAUTH"));
             }
             if (!$category->published || $category->trash) {
                 JError::raiseError(404, JText::_("Category not found"));
             }
             //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 link
             $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
             //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;
             $this->assignRef('category', $category);
             $this->assignRef('user', $user);
             //Category childs
             $ordering = $params->get('subCatOrdering');
             $childs = $model->getCategoryFirstChilds($id, $ordering);
             if (count($childs)) {
                 foreach ($childs as $child) {
                     if ($params->get('subCatTitleItemCounter')) {
                         $child->numOfItems = $model->countCategoryItems($child->id);
                     }
                     if (!empty($child->image)) {
                         $child->image = JURI::root() . 'media/k2/categories/' . $child->image;
                     } else {
                         if ($params->get('catImageDefault')) {
                             $child->image = JURI::root() . 'components/com_k2/images/placeholder/category.png';
                         }
                     }
                     $child->name = htmlspecialchars($child->name, ENT_QUOTES);
                     $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                     $subCategories[] = $child;
                 }
                 $this->assignRef('subCategories', $subCategories);
             }
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set layout
             $this->setLayout('category');
             //Set title
             $title = $category->name;
             $category->name = htmlspecialchars($category->name, ENT_QUOTES);
             break;
         case 'user':
             //Get user
             $id = JRequest::getInt('id');
             $user =& JFactory::getUser($id);
             //Check user status
             if ($user->block) {
                 JError::raiseError(404, JText::_('User not found'));
             }
             //Get K2 user profile
             $user->profile = $model->getUserProfile();
             //User image
             $user->avatar = K2HelperUtilities::getAvatar($user->id, $user->email, $params->get('userImageWidth'));
             //User K2 plugins
             $user->event->K2UserDisplay = '';
             if (is_object($user->profile) && $user->profile->id > 0) {
                 $dispatcher =& JDispatcher::getInstance();
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2UserDisplay', array(&$user->profile, &$params, $limitstart));
                 $user->event->K2UserDisplay = trim(implode("\n", $results));
             }
             $this->assignRef('user', $user);
             $db =& JFactory::getDBO();
             $nullDate = $db->getNullDate();
             $date =& JFactory::getDate();
             $now = $date->toMySQL();
             $this->assignRef('nullDate', $nullDate);
             $this->assignRef('now', $now);
             //Set layout
             $this->setLayout('user');
             //Set limit
             $limit = $params->get('userItemCount');
             //Set title
             $title = $user->name;
             $user->name = htmlspecialchars($user->name, ENT_QUOTES);
             break;
         case 'tag':
             //Set layout
             $this->setLayout('generic');
             //Set limit
             $limit = $params->get('genericItemCount');
             //set title
             $title = JText::_('Displaying items by tag:') . ' ' . JRequest::getVar('tag');
             break;
         case 'search':
             //Set layout
             $this->setLayout('generic');
             //Set limit
             $limit = $params->get('genericItemCount');
             //Set title
             $title = JText::_('Search results for:') . ' ' . JRequest::getVar('searchword');
             break;
         case 'date':
             //Set layout
             $this->setLayout('generic');
             //Set limit
             $limit = $params->get('genericItemCount');
             //Set title
             if (JRequest::getInt('day')) {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                 $title = JText::_('Items filtered by date:') . ' ' . JHTML::_('date', $date, '%A, %d %B %Y');
             } else {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                 $title = JText::_('Items filtered by date:') . ' ' . JHTML::_('date', $date, '%B %Y');
             }
             break;
         default:
             //Set layout
             $this->setLayout('category');
             $user =& JFactory::getUser();
             $this->assignRef('user', $user);
             //Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             //Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             //Set title
             $title = $params->get('page_title');
             break;
     }
     //Set limit for model
     if (!$limit) {
         $limit = 10;
     }
     JRequest::setVar('limit', $limit);
     //Get ordering
     if ($task == 'tag') {
         $ordering = $params->get('tagOrdering');
     } else {
         $ordering = $params->get('catOrdering');
     }
     //Get items
     $items = $model->getData($ordering);
     //Pagination
     jimport('joomla.html.pagination');
     $total = $model->getTotal();
     $pagination = new JPagination($total, $limitstart, $limit);
     //Prepare items
     $user =& JFactory::getUser();
     $cache =& JFactory::getCache('com_k2_extended');
     $model =& $this->getModel('item');
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         }
         if ($user->guest) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             $items[$i] = $cache->call(array('K2ModelItem', 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         //Plugins
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         //Trigger comments counter event
         $dispatcher =& JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
     }
     //Set title
     $document =& JFactory::getDocument();
     $menus =& JSite::getMenu();
     $menu = $menus->getActive();
     if (is_object($menu)) {
         $menu_params = new JParameter($menu->params);
         if (!$menu_params->get('page_title')) {
             $params->set('page_title', $title);
         }
     } else {
         $params->set('page_title', $title);
     }
     $document->setTitle($params->get('page_title'));
     //Pathway
     $pathway =& $mainframe->getPathWay();
     if (!isset($menu->query['task'])) {
         $menu->query['task'] = '';
     }
     if ($menu) {
         switch ($task) {
             case 'category':
                 if ($menu->query['task'] != 'category' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'user':
                 if ($menu->query['task'] != 'user' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'tag':
                 if ($menu->query['task'] != 'tag' || $menu->query['tag'] != JRequest::getVar('tag')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'search':
             case 'date':
                 $pathway->addItem($title, '');
                 break;
         }
     }
     //Feed link
     $config =& JFactory::getConfig();
     $menu =& JSite::getMenu();
     $default = $menu->getDefault();
     $active = $menu->getActive();
     if ($task == 'tag') {
         $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag'));
     } else {
         $link = '';
     }
     if (!is_null($active) && $active->id == $default->id && $config->getValue('config.sef')) {
         $link .= '&Itemid=' . $active->id . '&format=feed&limitstart=';
     } else {
         $link .= '&format=feed&limitstart=';
     }
     $feed = JRoute::_($link);
     $this->assignRef('feed', $feed);
     //Add head feed link
     if ($params->get('feedLink', 1)) {
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     //Assign data
     if ($task == "category" || $task == "") {
         $leading = @array_slice($items, 0, $params->get('num_leading_items'));
         $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items'));
         $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items'));
         $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links'));
         $this->assignRef('leading', $leading);
         $this->assignRef('primary', $primary);
         $this->assignRef('secondary', $secondary);
         $this->assignRef('links', $links);
     } else {
         $this->assignRef('items', $items);
     }
     //Set default values to avoid division by zero
     if ($params->get('num_leading_columns') == 0) {
         $params->set('num_leading_columns', 1);
     }
     if ($params->get('num_primary_columns') == 0) {
         $params->set('num_primary_columns', 1);
     }
     if ($params->get('num_secondary_columns') == 0) {
         $params->set('num_secondary_columns', 1);
     }
     if ($params->get('num_links_columns') == 0) {
         $params->set('num_links_columns', 1);
     }
     $this->assignRef('params', $params);
     $this->assignRef('pagination', $pagination);
     //Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     //Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     //Look for specific K2 theme files
     if ($params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme'));
     }
     parent::display($tpl);
 }
예제 #23
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;
 }
예제 #24
0
파일: item.php 프로젝트: grchis/Site-Auto
 function prepareItem($item, $view, $task)
 {
     jimport('joomla.filesystem.file');
     JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
     $limitstart = JRequest::getInt('limitstart');
     $application = JFactory::getApplication();
     //Initialize params
     if ($view != 'item') {
         if (K2_JVERSION == '30') {
             $params = $application->getParams('com_k2');
         } else {
             $component = JComponentHelper::getComponent('com_k2');
             $params = class_exists('JParameter') ? new JParameter($component->params) : new JRegistry($component->params);
             $itemid = JRequest::getInt('Itemid');
             if ($itemid) {
                 $menu = $application->getMenu();
                 $menuparams = $menu->getParams($itemid);
                 $params->merge($menuparams);
             }
         }
     } else {
         $params = K2HelperUtilities::getParams('com_k2');
     }
     //Category
     $db = JFactory::getDBO();
     $category = JTable::getInstance('K2Category', 'Table');
     $category->load($item->catid);
     $item->category = $category;
     $item->category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
     //Read more link
     $link = K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->category->alias));
     $item->link = urldecode(JRoute::_($link));
     //Print link
     $item->printLink = urldecode(JRoute::_($link . '&tmpl=component&print=1'));
     //Params
     $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
     $iparams = class_exists('JParameter') ? new JParameter($item->params) : new JRegistry($item->params);
     $item->params = version_compare(PHP_VERSION, '5.0.0', '>=') ? clone $params : $params;
     if ($cparams->get('inheritFrom')) {
         $masterCategoryID = $cparams->get('inheritFrom');
         $masterCategory = JTable::getInstance('K2Category', 'Table');
         $masterCategory->load((int) $masterCategoryID);
         $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
     }
     $item->params->merge($cparams);
     $item->params->merge($iparams);
     //Edit link
     if (K2HelperPermissions::canEditItem($item->created_by, $item->catid)) {
         $item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid=' . $item->id . '&tmpl=component');
     }
     //Tags
     if ($view == 'item' && ($item->params->get('itemTags') || $item->params->get('itemRelated')) || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemTags') || $view == 'itemlist' && $task == 'user' && $item->params->get('userItemTags') || $view == 'latest' && $params->get('latestItemTags')) {
         $tags = $this->getItemTags($item->id);
         for ($i = 0; $i < sizeof($tags); $i++) {
             $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
         }
         $item->tags = $tags;
     }
     //Image
     $item->imageXSmall = '';
     $item->imageSmall = '';
     $item->imageMedium = '';
     $item->imageLarge = '';
     $item->imageXLarge = '';
     $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 ($params->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 ($params->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 ($params->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 ($params->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 ($params->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 ($params->get('imageTimestamp')) {
             $item->imageGeneric .= $timestamp;
         }
     }
     //Extra fields
     if ($view == 'item' && $item->params->get('itemExtraFields') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemExtraFields') || $view == 'itemlist' && $task == 'tag' && $item->params->get('tagItemExtraFields') || $view == 'itemlist' && ($task == 'search' || $task == 'date') && $item->params->get('genericItemExtraFields')) {
         $item->extra_fields = $this->getItemExtraFields($item->extra_fields, $item);
     }
     //Attachments
     if ($view == 'item' && $item->params->get('itemAttachments') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemAttachments')) {
         $item->attachments = $this->getItemAttachments($item->id);
     }
     //Rating
     if ($view == 'item' && $item->params->get('itemRating') || $view == 'itemlist' && ($task == '' || $task == 'category') && $item->params->get('catItemRating')) {
         $item->votingPercentage = $this->getVotesPercentage($item->id);
         $item->numOfvotes = $this->getVotesNum($item->id);
     }
     //Filtering
     if ($params->get('introTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('introTextCleanupTagAttr')));
         $filterAttrs = array_filter($filterAttrs);
         $item->introtext = K2HelperUtilities::cleanTags($item->introtext, $filterTags);
         if (count($filterAttrs)) {
             $item->introtext = K2HelperUtilities::cleanAttributes($item->introtext, $filterTags, $filterAttrs);
         }
     }
     if ($params->get('fullTextCleanup')) {
         $filterTags = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupExcludeTags')));
         $filterAttrs = preg_split('#[,\\s]+#', trim($params->get('fullTextCleanupTagAttr')));
         $filterAttrs = array_filter($filterAttrs);
         $item->fulltext = K2HelperUtilities::cleanTags($item->fulltext, $filterTags);
         if (count($filterAttrs)) {
             $item->fulltext = K2HelperUtilities::cleanAttributes($item->fulltext, $filterTags, $filterAttrs);
         }
     }
     if ($item->params->get('catItemIntroTextWordLimit') && $task == 'category') {
         $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
     }
     $item->cleanTitle = $item->title;
     $item->title = htmlspecialchars($item->title, ENT_QUOTES);
     $item->image_caption = htmlspecialchars($item->image_caption, ENT_QUOTES);
     //Author
     if ($view == 'item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor')) || $view == 'itemlist' && ($task == '' || $task == 'category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) || $view == 'itemlist' && $task == 'user' || $view == 'relatedByTag') {
         if (!empty($item->created_by_alias)) {
             $item->author = new stdClass();
             $item->author->name = $item->created_by_alias;
             $item->author->avatar = K2HelperUtilities::getAvatar('alias');
             $item->author->link = JURI::root();
         } else {
             $author = JFactory::getUser($item->created_by);
             $item->author = $author;
             $item->author->link = JRoute::_(K2HelperRoute::getUserRoute($item->created_by));
             $item->author->profile = $this->getUserProfile($item->created_by);
             $item->author->avatar = K2HelperUtilities::getAvatar($author->id, $author->email, $params->get('userImageWidth'));
         }
         if (!isset($item->author->profile) || is_null($item->author->profile)) {
             $item->author->profile = new JObject();
             $item->author->profile->gender = NULL;
         }
     }
     //Num of comments
     if ($params->get('comments', 0) > 0) {
         $user = JFactory::getUser();
         if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
             $item->numOfComments = $this->countItemComments($item->id, false);
         } else {
             $item->numOfComments = $this->countItemComments($item->id);
         }
     }
     return $item;
 }
예제 #25
0
 function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     $params = K2HelperUtilities::getParams('com_k2');
     $model = $this->getModel('itemlist');
     $limitstart = JRequest::getInt('limitstart');
     $view = JRequest::getWord('view');
     $task = JRequest::getWord('task');
     $db = JFactory::getDBO();
     // Add link
     if (K2HelperPermissions::canAddItem()) {
         $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
     }
     $this->assignRef('addLink', $addLink);
     // Get data depending on task
     switch ($task) {
         case 'category':
             // Get category
             $id = JRequest::getInt('id');
             JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
             $category = JTable::getInstance('K2Category', 'Table');
             $category->load($id);
             $category->event = new stdClass();
             // State check
             if (!$category->published || $category->trash) {
                 JError::raiseError(404, JText::_('K2_CATEGORY_NOT_FOUND'));
             }
             // Access check
             $user = JFactory::getUser();
             if (K2_JVERSION != '15') {
                 if (!in_array($category->access, $user->getAuthorisedViewLevels())) {
                     if ($user->guest) {
                         $uri = JFactory::getURI();
                         $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString());
                         $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
                     } else {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                         return;
                     }
                 }
                 $languageFilter = $mainframe->getLanguageFilter();
                 $languageTag = JFactory::getLanguage()->getTag();
                 if ($languageFilter && $category->language != $languageTag && $category->language != '*') {
                     return;
                 }
             } else {
                 if ($category->access > $user->get('aid', 0)) {
                     if ($user->guest) {
                         $uri = JFactory::getURI();
                         $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString());
                         $mainframe->redirect(JRoute::_($url, false), JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'));
                     } else {
                         JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                         return;
                     }
                 }
             }
             // Hide the add new item link if user cannot post in the specific category
             if (!K2HelperPermissions::canAddItem($id)) {
                 unset($this->addLink);
             }
             // Merge params
             $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params);
             // Get the meta information before merging params since we do not want them to be inherited
             $category->metaDescription = $cparams->get('catMetaDesc');
             $category->metaKeywords = $cparams->get('catMetaKey');
             $category->metaRobots = $cparams->get('catMetaRobots');
             $category->metaAuthor = $cparams->get('catMetaAuthor');
             if ($cparams->get('inheritFrom')) {
                 $masterCategory = JTable::getInstance('K2Category', 'Table');
                 $masterCategory->load($cparams->get('inheritFrom'));
                 $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params);
             }
             $params->merge($cparams);
             // Category link
             $category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id . ':' . urlencode($category->alias))));
             // Category image
             $category->image = K2HelperUtilities::getCategoryImage($category->image, $params);
             // Category plugins
             $dispatcher = JDispatcher::getInstance();
             JPluginHelper::importPlugin('content');
             $category->text = $category->description;
             if (K2_JVERSION != '15') {
                 $dispatcher->trigger('onContentPrepare', array('com_k2.category', &$category, &$params, $limitstart));
             } else {
                 $dispatcher->trigger('onPrepareContent', array(&$category, &$params, $limitstart));
             }
             $category->description = $category->text;
             // Category K2 plugins
             $category->event->K2CategoryDisplay = '';
             JPluginHelper::importPlugin('k2');
             $results = $dispatcher->trigger('onK2CategoryDisplay', array(&$category, &$params, $limitstart));
             $category->event->K2CategoryDisplay = trim(implode("\n", $results));
             $category->text = $category->description;
             $dispatcher->trigger('onK2PrepareContent', array(&$category, &$params, $limitstart));
             $category->description = $category->text;
             $this->assignRef('category', $category);
             $this->assignRef('user', $user);
             // Category children
             $ordering = $params->get('subCatOrdering');
             $children = $model->getCategoryFirstChildren($id, $ordering);
             if (count($children)) {
                 foreach ($children as $child) {
                     if ($params->get('subCatTitleItemCounter')) {
                         $child->numOfItems = $model->countCategoryItems($child->id);
                     }
                     $child->image = K2HelperUtilities::getCategoryImage($child->image, $params);
                     $child->name = htmlspecialchars($child->name, ENT_QUOTES);
                     $child->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($child->id . ':' . urlencode($child->alias))));
                     $subCategories[] = $child;
                 }
                 $this->assignRef('subCategories', $subCategories);
             }
             // Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             // Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             // Set layout
             $this->setLayout('category');
             // Set title
             $title = $category->name;
             $category->name = htmlspecialchars($category->name, ENT_QUOTES);
             // Set ordering
             if ($params->get('singleCatOrdering')) {
                 $ordering = $params->get('singleCatOrdering');
             } else {
                 $ordering = $params->get('catOrdering');
             }
             $addHeadFeedLink = $params->get('catFeedLink');
             break;
         case 'user':
             // Get user
             $id = JRequest::getInt('id');
             $userObject = JFactory::getUser($id);
             $userObject->event = new stdClass();
             // Check user status
             if ($userObject->block) {
                 JError::raiseError(404, JText::_('K2_USER_NOT_FOUND'));
             }
             // Get K2 user profile
             $userObject->profile = $model->getUserProfile();
             // User image
             $userObject->avatar = K2HelperUtilities::getAvatar($userObject->id, $userObject->email, $params->get('userImageWidth'));
             // User K2 plugins
             $userObject->event->K2UserDisplay = '';
             if (is_object($userObject->profile) && $userObject->profile->id > 0) {
                 $dispatcher = JDispatcher::getInstance();
                 JPluginHelper::importPlugin('k2');
                 $results = $dispatcher->trigger('onK2UserDisplay', array(&$userObject->profile, &$params, $limitstart));
                 $userObject->event->K2UserDisplay = trim(implode("\n", $results));
                 $userObject->profile->url = htmlspecialchars($userObject->profile->url, ENT_QUOTES, 'UTF-8');
             }
             $this->assignRef('user', $userObject);
             $date = JFactory::getDate();
             $now = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql();
             $this->assignRef('now', $now);
             // Set layout
             $this->setLayout('user');
             // Set limit
             $limit = $params->get('userItemCount');
             // Set title
             $title = $userObject->name;
             $userObject->name = htmlspecialchars($userObject->name, ENT_QUOTES);
             // Set ordering
             $ordering = $params->get('userOrdering');
             $addHeadFeedLink = $params->get('userFeedLink', 1);
             break;
         case 'tag':
             // Set layout
             $this->setLayout('tag');
             // Set limit
             $limit = $params->get('tagItemCount');
             // Set title
             $title = JText::_('K2_DISPLAYING_ITEMS_BY_TAG') . ' ' . JRequest::getVar('tag');
             // Set ordering
             $ordering = $params->get('tagOrdering');
             $addHeadFeedLink = $params->get('tagFeedLink', 1);
             break;
         case 'search':
             // Set layout
             $this->setLayout('generic');
             // Set limit
             $limit = $params->get('genericItemCount');
             // Set title
             $title = JText::_('K2_SEARCH_RESULTS_FOR') . ' ' . JRequest::getVar('searchword');
             $addHeadFeedLink = $params->get('genericFeedLink', 1);
             break;
         case 'date':
             // Set layout
             $this->setLayout('generic');
             // Set limit
             $limit = $params->get('genericItemCount');
             // Fix wrong timezone
             if (function_exists('date_default_timezone_get')) {
                 $originalTimezone = date_default_timezone_get();
             }
             if (function_exists('date_default_timezone_set')) {
                 date_default_timezone_set('UTC');
             }
             // Set title
             if (JRequest::getInt('day')) {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month') . '-' . JRequest::getInt('day'));
                 $dateFormat = K2_JVERSION == '15' ? '%A, %d %B %Y' : 'l, d F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             } else {
                 $date = strtotime(JRequest::getInt('year') . '-' . JRequest::getInt('month'));
                 $dateFormat = K2_JVERSION == '15' ? '%B %Y' : 'F Y';
                 $title = JText::_('K2_ITEMS_FILTERED_BY_DATE') . ' ' . JHTML::_('date', $date, $dateFormat);
             }
             // Restore the original timezone
             if (function_exists('date_default_timezone_set') && isset($originalTimezone)) {
                 date_default_timezone_set($originalTimezone);
             }
             // Set ordering
             $ordering = 'rdate';
             $addHeadFeedLink = $params->get('genericFeedLink', 1);
             break;
         default:
             // Set layout
             $this->setLayout('category');
             $user = JFactory::getUser();
             $this->assignRef('user', $user);
             // Set limit
             $limit = $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items') + $params->get('num_links');
             // Set featured flag
             JRequest::setVar('featured', $params->get('catFeaturedItems'));
             // Set title
             $title = $params->get('page_title');
             // Set ordering
             $ordering = $params->get('catOrdering');
             $addHeadFeedLink = $params->get('catFeedLink', 1);
             break;
     }
     // Set limit for model
     if (!$limit) {
         $limit = 10;
     }
     JRequest::setVar('limit', $limit);
     // Get items
     if (!isset($ordering)) {
         $items = $model->getData();
     } else {
         $items = $model->getData($ordering);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $total = count($items) ? $model->getTotal() : 0;
     $pagination = new JPagination($total, $limitstart, $limit);
     //Prepare items
     $user = JFactory::getUser();
     $cache = JFactory::getCache('com_k2_extended');
     $model = $this->getModel('item');
     for ($i = 0; $i < sizeof($items); $i++) {
         //Item group
         if ($task == "category" || $task == "") {
             if ($i < $params->get('num_links') + $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items')) {
                 $items[$i]->itemGroup = 'links';
             }
             if ($i < $params->get('num_secondary_items') + $params->get('num_leading_items') + $params->get('num_primary_items')) {
                 $items[$i]->itemGroup = 'secondary';
             }
             if ($i < $params->get('num_primary_items') + $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'primary';
             }
             if ($i < $params->get('num_leading_items')) {
                 $items[$i]->itemGroup = 'leading';
             }
         }
         // Check if the model should use the cache for preparing the item even if the user is logged in
         if ($user->guest || $task == 'tag' || $task == 'search' || $task == 'date') {
             $cacheFlag = true;
         } else {
             $cacheFlag = true;
             if (K2HelperPermissions::canEditItem($items[$i]->created_by, $items[$i]->catid)) {
                 $cacheFlag = false;
             }
         }
         // Prepare item
         if ($cacheFlag) {
             $hits = $items[$i]->hits;
             $items[$i]->hits = 0;
             JTable::getInstance('K2Category', 'Table');
             $items[$i] = $cache->call(array($model, 'prepareItem'), $items[$i], $view, $task);
             $items[$i]->hits = $hits;
         } else {
             $items[$i] = $model->prepareItem($items[$i], $view, $task);
         }
         // Plugins
         $items[$i] = $model->execPlugins($items[$i], $view, $task);
         // Trigger comments counter event
         $dispatcher = JDispatcher::getInstance();
         JPluginHelper::importPlugin('k2');
         $results = $dispatcher->trigger('onK2CommentsCounter', array(&$items[$i], &$params, $limitstart));
         $items[$i]->event->K2CommentsCounter = trim(implode("\n", $results));
     }
     // Set title
     $document = JFactory::getDocument();
     $application = JFactory::getApplication();
     $menus = $application->getMenu();
     $menu = $menus->getActive();
     if (is_object($menu)) {
         if (is_string($menu->params)) {
             $menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params);
         } else {
             $menu_params = $menu->params;
         }
         if (!$menu_params->get('page_title')) {
             $params->set('page_title', $title);
         }
     } else {
         $params->set('page_title', $title);
     }
     // We're adding a new variable here which won't get the appended/prepended site title,
     // when enabled via Joomla!'s SEO/SEF settings
     $params->set('page_title_clean', $title);
     if (K2_JVERSION != '15') {
         if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) {
             $tmpTitle = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title'));
             $params->set('page_title', $tmpTitle);
         } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) {
             $tmpTitle = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename'));
             $params->set('page_title', $tmpTitle);
         }
     }
     $document->setTitle($params->get('page_title'));
     // Search - Update the Google Search results container (K2 v2.6.6+)
     if ($task == 'search') {
         $googleSearchContainerID = trim($params->get('googleSearchContainer', 'k2GoogleSearchContainer'));
         if ($googleSearchContainerID == 'k2Container') {
             $googleSearchContainerID = 'k2GoogleSearchContainer';
         }
         $params->set('googleSearchContainer', $googleSearchContainerID);
     }
     // Set metadata for category
     if ($task == 'category') {
         if ($category->metaDescription) {
             $document->setDescription($category->metaDescription);
         } else {
             $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $this->category->description);
             $metaDescItem = strip_tags($metaDescItem);
             $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
             $metaDescItem = htmlspecialchars($metaDescItem, ENT_QUOTES, 'UTF-8');
             $document->setDescription($metaDescItem);
         }
         if ($category->metaKeywords) {
             $document->setMetadata('keywords', $category->metaKeywords);
         }
         if ($category->metaRobots) {
             $document->setMetadata('robots', $category->metaRobots);
         }
         if ($category->metaAuthor) {
             $document->setMetadata('author', $category->metaAuthor);
         }
     }
     if (K2_JVERSION != '15') {
         // Menu metadata options
         if ($params->get('menu-meta_description')) {
             $document->setDescription($params->get('menu-meta_description'));
         }
         if ($params->get('menu-meta_keywords')) {
             $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
         }
         if ($params->get('robots')) {
             $document->setMetadata('robots', $params->get('robots'));
         }
         // Menu page display options
         if ($params->get('page_heading')) {
             $params->set('page_title', $params->get('page_heading'));
         }
         $params->set('show_page_title', $params->get('show_page_heading'));
     }
     // Pathway
     $pathway = $mainframe->getPathWay();
     if (!isset($menu->query['task'])) {
         $menu->query['task'] = '';
     }
     if ($menu) {
         switch ($task) {
             case 'category':
                 if ($menu->query['task'] != 'category' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'user':
                 if ($menu->query['task'] != 'user' || $menu->query['id'] != JRequest::getInt('id')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'tag':
                 if ($menu->query['task'] != 'tag' || $menu->query['tag'] != JRequest::getVar('tag')) {
                     $pathway->addItem($title, '');
                 }
                 break;
             case 'search':
             case 'date':
                 $pathway->addItem($title, '');
                 break;
         }
     }
     // Feed link
     $config = JFactory::getConfig();
     $menu = $application->getMenu();
     $default = $menu->getDefault();
     $active = $menu->getActive();
     if ($task == 'tag') {
         $link = K2HelperRoute::getTagRoute(JRequest::getVar('tag'));
     } else {
         $link = '';
     }
     $sef = K2_JVERSION == '30' ? $config->get('sef') : $config->getValue('config.sef');
     if (!is_null($active) && $active->id == $default->id && $sef) {
         $link .= '&Itemid=' . $active->id . '&format=feed&limitstart=';
     } else {
         $link .= '&format=feed&limitstart=';
     }
     $feed = JRoute::_($link);
     $this->assignRef('feed', $feed);
     // Add head feed link
     if ($addHeadFeedLink) {
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     // Assign data
     if ($task == "category" || $task == "") {
         $leading = @array_slice($items, 0, $params->get('num_leading_items'));
         $primary = @array_slice($items, $params->get('num_leading_items'), $params->get('num_primary_items'));
         $secondary = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items'), $params->get('num_secondary_items'));
         $links = @array_slice($items, $params->get('num_leading_items') + $params->get('num_primary_items') + $params->get('num_secondary_items'), $params->get('num_links'));
         $this->assignRef('leading', $leading);
         $this->assignRef('primary', $primary);
         $this->assignRef('secondary', $secondary);
         $this->assignRef('links', $links);
     } else {
         $this->assignRef('items', $items);
     }
     // Set default values to avoid division by zero
     if ($params->get('num_leading_columns') == 0) {
         $params->set('num_leading_columns', 1);
     }
     if ($params->get('num_primary_columns') == 0) {
         $params->set('num_primary_columns', 1);
     }
     if ($params->get('num_secondary_columns') == 0) {
         $params->set('num_secondary_columns', 1);
     }
     if ($params->get('num_links_columns') == 0) {
         $params->set('num_links_columns', 1);
     }
     $this->assignRef('params', $params);
     $this->assignRef('pagination', $pagination);
     // Set Facebook meta data
     $document = JFactory::getDocument();
     $uri = JURI::getInstance();
     $document->setMetaData('og:url', $uri->toString());
     $document->setMetaData('og:title', htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8'));
     $document->setMetaData('og:type', 'website');
     if ($task == 'category' && $this->category->image && strpos($this->category->image, 'placeholder/category.png') === false) {
         $image = substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $this->category->image);
         $document->setMetaData('og:image', $image);
         $document->setMetaData('image', $image);
     }
     $document->setMetaData('og:description', htmlspecialchars(strip_tags($document->getDescription()), ENT_QUOTES, 'UTF-8'));
     // Look for template files in component folders
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
     $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (K2 template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
     // Look for overrides in template folder (Joomla! template structure)
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
     $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
     // Look for specific K2 theme files
     if ($params->get('theme')) {
         $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $params->get('theme'));
         $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $params->get('theme'));
     }
     $nullDate = $db->getNullDate();
     $this->assignRef('nullDate', $nullDate);
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('k2');
     $dispatcher->trigger('onK2BeforeViewDisplay');
     // Prevent spammers from using the tag view
     if ($task == 'tag' && !count($this->items)) {
         $tag = JRequest::getString('tag');
         $db = JFactory::getDBO();
         $db->setQuery('SELECT id FROM #__k2_tags WHERE name = ' . $db->quote($tag));
         $tagID = $db->loadResult();
         if (!$tagID) {
             JError::raiseError(404, JText::_('K2_NOT_FOUND'));
             return false;
         }
     }
     parent::display($tpl);
 }
예제 #26
0
	function prepareItem($item, $view, $task){

		jimport('joomla.filesystem.file');
		JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
		$limitstart=JRequest::getInt('limitstart');

		//Initialize params
		if ($view!='item'){

			$component = JComponentHelper::getComponent( 'com_k2' );
			$params = new JParameter( $component->params );
			$itemid = JRequest::getInt( 'Itemid' );
			if ($itemid) {
				$menu = JSite::getMenu();
				$menuparams = $menu->getParams( $itemid );
				$params->merge( $menuparams );
			}

		}
		else {
			$params = & JComponentHelper::getParams('com_k2');
		}

		//Category
		$db = & JFactory::getDBO();
		$query = "SELECT * FROM #__k2_categories WHERE id=".(int)$item->catid;
		$db->setQuery($query, 0, 1);
		$category = $db->loadObject();

		$item->category=$category;
		$item->category->link=urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id.':'.urlencode($category->alias))));

		//Read more link
		$link = K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias),$item->catid.':'.urlencode($item->category->alias));
		$item->link=urldecode(JRoute::_($link));

		//Print link
		$item->printLink = urldecode(JRoute::_($link.'&tmpl=component&print=1'));

		//Params
		$cparams = new JParameter( $category->params );
		$iparams = new JParameter( $item->params );
		$item->params= $params;
		if ($cparams->get('inheritFrom')){
			$masterCategoryID = $cparams->get('inheritFrom');
			$query = "SELECT * FROM #__k2_categories WHERE id=".(int)$masterCategoryID;
			$db->setQuery($query, 0, 1);
			$masterCategory = $db->loadObject();
			$cparams = new JParameter( $masterCategory->params );
		}
		$item->params->merge($cparams);
		$item->params->merge($iparams);

		//Edit link
		if (K2HelperPermissions::canEditItem($item->created_by,$item->catid))
		$item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid='.$item->id.'&tmpl=component');

		//Tags
		if(
		($view=='item' && ($item->params->get('itemTags') || $item->params->get('itemRelated'))) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemTags')) ||
		($view=='itemlist' && $task=='user' && $item->params->get('userItemTags')) ||
		($view=='latest' && $params->get('latestItemTags'))
		)
		{
			$tags = K2ModelItem::getItemTags($item->id);
			for ($i=0; $i<sizeof($tags); $i++) {
				$tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
			}
			$item->tags=$tags;
		}


		//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';


		//Extra fields
		if(
		($view=='item' && $item->params->get('itemExtraFields')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemExtraFields')) ||
		($view=='itemlist' && ($task=='search' || $task=='tag' || $task=='date') && $item->params->get('genericItemExtraFields'))
		)
		{
			$item->extra_fields=K2ModelItem::getItemExtraFields($item->extra_fields);
		}

		//Attachments
		if(
		($view=='item' && $item->params->get('itemAttachments')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemAttachments'))
		)
		{
			$item->attachments=K2ModelItem::getItemAttachments($item->id);
		}


		//Rating
		if(
		($view=='item' && $item->params->get('itemRating')) ||
		($view=='itemlist' && ($task=='' || $task=='category') && $item->params->get('catItemRating'))
		)
		{
			$item->votingPercentage = K2ModelItem::getVotesPercentage($item->id);
			$item->numOfvotes = K2ModelItem::getVotesNum($item->id);

		}

		//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 );
		}

		if ($item->params->get('catItemIntroTextWordLimit') && $task=='category'){
			$item->introtext = K2HelperUtilities::wordLimit($item->introtext, $item->params->get('catItemIntroTextWordLimit'));
		}

		$item->cleanTitle = $item->title;
		$item->title = htmlspecialchars($item->title, ENT_QUOTES);
		$item->image_caption = htmlspecialchars($item->image_caption, ENT_QUOTES);

		//Author
		if(
		($view=='item' && ($item->params->get('itemAuthorBlock') || $item->params->get('itemAuthor'))) ||
		($view=='itemlist' && ($task=='' || $task=='category') && ($item->params->get('catItemAuthorBlock') || $item->params->get('catItemAuthor')) ) ||
		($view=='itemlist' && $task=='user')
		)
		{
			if (!empty($item->created_by_alias)){
				$item->author->name = $item->created_by_alias;
				$item->author->avatar = K2HelperUtilities::getAvatar('alias');
				$item->author->link = JURI::root();
			}
			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 (!isset($item->author->profile) || is_null($item->author->profile)){

				$item->author->profile = new JObject;
				$item->author->profile->gender = NULL;

			}


		}

		//Num of comments
		$item->numOfComments = K2ModelItem::countItemComments($item->id);

		return $item;
	}
예제 #27
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;
     }
 }
예제 #28
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);
    }
예제 #29
0
</p>
<?php 
}
?>
<div class="k2UserBlockDetails">
	<?php 
if ($params->get('userAvatar')) {
    ?>
	<a class="k2Avatar ubAvatar" href="<?php 
    echo JRoute::_(K2HelperRoute::getUserRoute($user->id));
    ?>
" title="<?php 
    echo JText::_('K2_MY_PAGE');
    ?>
"> <img src="<?php 
    echo K2HelperUtilities::getAvatar($user->id, $user->email);
    ?>
" alt="<?php 
    echo K2HelperUtilities::cleanHtml($user->name);
    ?>
" style="width:<?php 
    echo $avatarWidth;
    ?>
px;height:auto;" /> </a>
	<?php 
}
?>
	<span class="ubName"><?php 
echo $user->name;
?>
</span> <span class="ubCommentsCount"><?php 
예제 #30
0
 public static function getItems($cid, &$params)
 {
     jimport('joomla.filesystem.file');
     $mainframe = JFactory::getApplication();
     $limit = $params->get('itemCount', 5);
     $start = 0;
     //$limit*(JRequest::getInt('page',1)-1);
     $ordering = $params->get('itemsOrdering', '');
     $componentParams = JComponentHelper::getParams('com_k2');
     $limitstart = JRequest::getInt('limitstart');
     $user = JFactory::getUser();
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     $now = $jnow->toSql();
     $nullDate = $db->getNullDate();
     if ($params->get('source') == 'specific') {
         $value = $params->get('items');
         $current = array();
         if (is_string($value) && !empty($value)) {
             $current[] = $value;
         }
         if (is_array($value)) {
             $current = $value;
         }
         $items = array();
         if (count($current) > 0) {
             $query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams\n\t\t\t\t\t\t\tFROM #__k2_items as i\n\t\t\t\t\t\t\tLEFT JOIN #__k2_categories c ON c.id = i.catid\n\t\t\t\t\t\t\tWHERE i.published = 1 ";
             $query .= " AND i.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             $query .= " AND i.trash = 0 AND c.published = 1 ";
             $query .= " AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") ";
             $query .= " AND c.trash = 0\n\t\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\t\t\t\tAND ( i.publish_down = " . $db->Quote($nullDate) . " OR i.publish_down >= " . $db->Quote($now) . " )\n\t\t\t\t\t\t\t\t\tAND i.id IN(" . implode(',', $current) . ") ";
             if ($mainframe->getLanguageFilter()) {
                 $languageTag = JFactory::getLanguage()->getTag();
                 $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")";
             }
             $db->setQuery($query);
             $items = $db->loadObjectList();
         }
     } else {
         $query = "SELECT i.*, CASE WHEN i.modified = 0 THEN i.created ELSE i.modified END as lastChanged, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams";
         if ($ordering == 'best') {
             $query .= ", (r.rating_sum/r.rating_count) AS rating";
         }
         if ($ordering == 'comments') {
             $query .= ", COUNT(comments.id) AS numOfComments";
         }
         $query .= " FROM #__k2_items as i 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 IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND i.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ")  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 ($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 = $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 = $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, $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
             //Read more link
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             //Tags
             if ($params->get('itemTags')) {
                 $tags = $model->getItemTags($item->id);
                 for ($i = 0; $i < sizeof($tags); $i++) {
                     $tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
                 }
                 $item->tags = $tags;
             }
             //Category link
             if ($params->get('itemCategory')) {
                 $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             }
             //Extra fields
             if ($params->get('itemExtraFields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
             }
             //Comments counter
             if ($params->get('itemCommentsCounter')) {
                 $item->numOfComments = $model->countItemComments($item->id);
             }
             //Attachments
             if ($params->get('itemAttachments')) {
                 $item->attachments = $model->getItemAttachments($item->id);
             }
             if ($params->get('JPlugins', 0)) {
                 //Import plugins
                 $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;
                 $dispatcher->trigger('onContentPrepare', array('mod_k2_content.', &$item, &$params, $limitstart));
                 $item->video = $item->text;
             }
             // Introtext
             $item->text = '';
             // 					if ($params->get('itemIntroText'))
             // 					{
             $item->text .= self::_cleanText($item->introtext);
             // 					}
             $params->set('parsedInModule', 1);
             // for plugins to know when they are parsed inside this module
             if ($params->get('JPlugins', 0)) {
                 //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));
             }
             //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', 0)) {
                 //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->displayIntrotext = $item->text;
             //Clean the plugin tags
             $item->displayIntrotext = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->displayIntrotext);
             //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', 0)) {
                             $dispatcher->trigger('onPrepareContent', array(&$tmp, &$params, $limitstart));
                         }
                         if ($params->get('K2Plugins', 0)) {
                             $dispatcher->trigger('onK2PrepareContent', array(&$tmp, &$params, $limitstart));
                         }
                         $extraField->value = $tmp->text;
                     }
                 }
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }