Пример #1
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);
 }
Пример #2
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);
    }
Пример #3
0
    function display($tpl = null)
    {
        $mainframe = JFactory::getApplication();
        $user = JFactory::getUser();
        $document = JFactory::getDocument();
        $params = K2HelperUtilities::getParams('com_k2');
        $limitstart = JRequest::getInt('limitstart', 0);
        $view = JRequest::getWord('view');
        $task = JRequest::getWord('task');
        $db = JFactory::getDBO();
        $jnow = JFactory::getDate();
        $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();
        $nullDate = $db->getNullDate();
        $this->setLayout('item');
        // Add link
        if (K2HelperPermissions::canAddItem()) {
            $addLink = JRoute::_('index.php?option=com_k2&view=item&task=add&tmpl=component');
        }
        $this->assignRef('addLink', $addLink);
        // Get item
        $model = $this->getModel();
        $item = $model->getData();
        // Does the item exists?
        if (!is_object($item) || !$item->id) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Prepare item
        $item = $model->prepareItem($item, $view, $task);
        // Plugins
        $item = $model->execPlugins($item, $view, $task);
        // User K2 plugins
        $item->event->K2UserDisplay = '';
        if (isset($item->author) && is_object($item->author->profile) && isset($item->author->profile->id)) {
            $dispatcher = JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2UserDisplay', array(&$item->author->profile, &$params, $limitstart));
            $item->event->K2UserDisplay = trim(implode("\n", $results));
            $item->author->profile->url = htmlspecialchars($item->author->profile->url, ENT_QUOTES, 'UTF-8');
        }
        // Access check
        if ($this->getLayout() == 'form') {
            JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
        }
        if (K2_JVERSION != '15') {
            if (!in_array($item->access, $user->getAuthorisedViewLevels()) || !in_array($item->category->access, $user->getAuthorisedViewLevels())) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $url = 'index.php?option=com_users&view=login&return=' . base64_encode($uri->toString());
                    $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                    $mainframe->redirect(JRoute::_($url, false));
                } else {
                    JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                    return;
                }
            }
        } else {
            if ($item->access > $user->get('aid', 0) || $item->category->access > $user->get('aid', 0)) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $url = 'index.php?option=com_user&view=login&return=' . base64_encode($uri->toString());
                    $mainframe->enqueueMessage(JText::_('K2_YOU_NEED_TO_LOGIN_FIRST'), 'notice');
                    $mainframe->redirect(JRoute::_($url, false));
                } else {
                    JError::raiseError(403, JText::_('K2_ALERTNOTAUTH'));
                    return;
                }
            }
        }
        // Published check
        if (!$item->published || $item->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_up != $nullDate && $item->publish_up > $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if ($item->publish_down != $nullDate && $item->publish_down < $now) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        if (!$item->category->published || $item->category->trash) {
            JError::raiseError(404, JText::_('K2_ITEM_NOT_FOUND'));
        }
        // Increase hits counter
        $model->hit($item->id);
        // Set default image
        K2HelperUtilities::setDefaultImage($item, $view);
        // Pass the old parameter to the view in order to avoid layout changes
        if ($params->get('antispam') == 'recaptcha' || $params->get('antispam') == 'both') {
            $params->set('recaptcha', true);
            $item->params->set('recaptcha', true);
        } else {
            $params->set('recaptcha', false);
            $item->params->set('recaptcha', false);
        }
        // Comments
        $item->event->K2CommentsCounter = '';
        $item->event->K2CommentsBlock = '';
        if ($item->params->get('itemComments')) {
            // Trigger comments events
            $dispatcher = JDispatcher::getInstance();
            JPluginHelper::importPlugin('k2');
            $results = $dispatcher->trigger('onK2CommentsCounter', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsCounter = trim(implode("\n", $results));
            $results = $dispatcher->trigger('onK2CommentsBlock', array(&$item, &$params, $limitstart));
            $item->event->K2CommentsBlock = trim(implode("\n", $results));
            // Load K2 native comments system only if there are no plugins overriding it
            if (empty($item->event->K2CommentsCounter) && empty($item->event->K2CommentsBlock)) {
                // Load reCAPTCHA script
                if (!JRequest::getInt('print') && ($item->params->get('comments') == '1' || $item->params->get('comments') == '2' && K2HelperPermissions::canAddComment($item->catid))) {
                    if ($params->get('recaptcha') && ($user->guest || $params->get('recaptchaForRegistered', 1))) {
                        $document->addScript('https://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
                        $js = '
						function showRecaptcha(){
							Recaptcha.create("' . $item->params->get('recaptcha_public_key') . '", "recaptcha", {
								theme: "' . $item->params->get('recaptcha_theme', 'clean') . '"
							});
						}
						$K2(window).load(function() {
							showRecaptcha();
						});
						';
                        $document->addScriptDeclaration($js);
                    }
                }
                // Check for inline comment moderation
                if (!$user->guest && $user->id == $item->created_by && $params->get('inlineCommentsModeration')) {
                    $inlineCommentsModeration = true;
                    $commentsPublished = false;
                } else {
                    $inlineCommentsModeration = false;
                    $commentsPublished = true;
                }
                $this->assignRef('inlineCommentsModeration', $inlineCommentsModeration);
                // Flag spammer link
                $reportSpammerFlag = false;
                if (K2_JVERSION != '15') {
                    if ($user->authorise('core.admin', 'com_k2')) {
                        $reportSpammerFlag = true;
                        $document = JFactory::getDocument();
                        $document->addScriptDeclaration('var K2Language = ["' . JText::_('K2_REPORT_USER_WARNING', true) . '"];');
                    }
                } else {
                    if ($user->gid > 24) {
                        $reportSpammerFlag = true;
                    }
                }
                $limit = $params->get('commentsLimit');
                $comments = $model->getItemComments($item->id, $limitstart, $limit, $commentsPublished);
                for ($i = 0; $i < sizeof($comments); $i++) {
                    $comments[$i]->commentText = nl2br($comments[$i]->commentText);
                    // Convert URLs to links properly
                    $comments[$i]->commentText = preg_replace("/([^\\w\\/])(www\\.[a-z0-9\\-]+\\.[a-z0-9\\-]+)/i", "\$1http://\$2", $comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace("/([\\w]+:\\/\\/[\\w-?&;#~=\\.\\/\\@]+[\\w\\/])/i", "<a target=\"_blank\" rel=\"nofollow\" href=\"\$1\">\$1</A>", $comments[$i]->commentText);
                    $comments[$i]->commentText = preg_replace("/([\\w-?&;#~=\\.\\/]+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?))/i", "<a href=\"mailto:\$1\">\$1</A>", $comments[$i]->commentText);
                    $comments[$i]->userImage = K2HelperUtilities::getAvatar($comments[$i]->userID, $comments[$i]->commentEmail, $params->get('commenterImgWidth'));
                    if ($comments[$i]->userID > 0) {
                        $comments[$i]->userLink = K2HelperRoute::getUserRoute($comments[$i]->userID);
                    } else {
                        $comments[$i]->userLink = $comments[$i]->commentURL;
                    }
                    if ($reportSpammerFlag && $comments[$i]->userID > 0) {
                        $comments[$i]->reportUserLink = JRoute::_('index.php?option=com_k2&view=comments&task=reportSpammer&id=' . $comments[$i]->userID . '&format=raw');
                    } else {
                        $comments[$i]->reportUserLink = false;
                    }
                }
                $item->comments = $comments;
                if (!isset($item->numOfComments)) {
                    $item->numOfComments = 0;
                }
                jimport('joomla.html.pagination');
                $total = $item->numOfComments;
                $pagination = new JPagination($total, $limitstart, $limit);
            }
        }
        // Author's latest items
        if ($item->params->get('itemAuthorLatest') && $item->created_by_alias == '') {
            $model = $this->getModel('itemlist');
            $authorLatestItems = $model->getAuthorLatest($item->id, $item->params->get('itemAuthorLatestLimit'), $item->created_by);
            if (count($authorLatestItems)) {
                for ($i = 0; $i < sizeof($authorLatestItems); $i++) {
                    $authorLatestItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($authorLatestItems[$i]->id . ':' . urlencode($authorLatestItems[$i]->alias), $authorLatestItems[$i]->catid . ':' . urlencode($authorLatestItems[$i]->categoryalias))));
                }
                $this->assignRef('authorLatestItems', $authorLatestItems);
            }
        }
        // Related items
        if ($item->params->get('itemRelated') && isset($item->tags) && count($item->tags)) {
            $model = $this->getModel('itemlist');
            $relatedItems = $model->getRelatedItems($item->id, $item->tags, $item->params);
            if (count($relatedItems)) {
                for ($i = 0; $i < sizeof($relatedItems); $i++) {
                    $relatedItems[$i]->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($relatedItems[$i]->id . ':' . urlencode($relatedItems[$i]->alias), $relatedItems[$i]->catid . ':' . urlencode($relatedItems[$i]->categoryalias))));
                }
                $this->assignRef('relatedItems', $relatedItems);
            }
        }
        // Navigation (previous and next item)
        if ($item->params->get('itemNavigation')) {
            $model = $this->getModel('item');
            $nextItem = $model->getNextItem($item->id, $item->catid, $item->ordering);
            if (!is_null($nextItem)) {
                $item->nextLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($nextItem->id . ':' . urlencode($nextItem->alias), $nextItem->catid . ':' . urlencode($item->category->alias))));
                $item->nextTitle = $nextItem->title;
                $date = JFactory::getDate($item->modified);
                $timestamp = '?t=' . $date->toUnix();
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_XS.jpg')) {
                    $item->nextImageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_XS.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_S.jpg')) {
                    $item->nextImageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_S.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_M.jpg')) {
                    $item->nextImageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_M.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_L.jpg')) {
                    $item->nextImageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_L.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_XL.jpg')) {
                    $item->nextImageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_XL.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $nextItem->id) . '_Generic.jpg')) {
                    $item->nextImageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $nextItem->id) . '_Generic.jpg' . $timestamp;
                }
            }
            $previousItem = $model->getPreviousItem($item->id, $item->catid, $item->ordering);
            if (!is_null($previousItem)) {
                $item->previousLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($previousItem->id . ':' . urlencode($previousItem->alias), $previousItem->catid . ':' . urlencode($item->category->alias))));
                $item->previousTitle = $previousItem->title;
                $date = JFactory::getDate($item->modified);
                $timestamp = '?t=' . $date->toUnix();
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_XS.jpg')) {
                    $item->previousImageXSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_XS.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_S.jpg')) {
                    $item->previousImageSmall = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_S.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_M.jpg')) {
                    $item->previousImageMedium = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_M.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_L.jpg')) {
                    $item->previousImageLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_L.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_XL.jpg')) {
                    $item->previousImageXLarge = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_XL.jpg' . $timestamp;
                }
                if (JFile::exists(JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . md5("Image" . $previousItem->id) . '_Generic.jpg')) {
                    $item->previousImageGeneric = JURI::base(true) . '/media/k2/items/cache/' . md5("Image" . $previousItem->id) . '_Generic.jpg' . $timestamp;
                }
            }
        }
        // Absolute URL
        $uri = JURI::getInstance();
        $item->absoluteURL = $uri->toString();
        // Email link
        if (K2_JVERSION != '15') {
            require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php';
            $template = $mainframe->getTemplate();
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($item->absoluteURL));
        } else {
            require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php';
            $item->emailLink = JRoute::_('index.php?option=com_mailto&tmpl=component&link=' . MailToHelper::addLink($item->absoluteURL));
        }
        // Twitter link (legacy code)
        if ($params->get('twitterUsername')) {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL) . '&amp;via=' . $params->get('twitterUsername');
        } else {
            $item->twitterURL = 'http://twitter.com/intent/tweet?text=' . urlencode($item->title) . '&amp;url=' . urlencode($item->absoluteURL);
        }
        // Social link
        $item->socialLink = urlencode($item->absoluteURL);
        // Set page title
        $menus = $mainframe->getMenu();
        $menu = $menus->getActive();
        if (is_object($menu) && isset($menu->query['view']) && $menu->query['view'] == 'item' && isset($menu->query['id']) && $menu->query['id'] == $item->id) {
            if (is_string($menu->params)) {
                $menu_params = K2_JVERSION == '15' ? new JParameter($menu->params) : new JRegistry($menu->params);
            } else {
                $menu_params = $menu->params;
            }
            if (!$menu_params->get('page_title')) {
                $params->set('page_title', $item->cleanTitle);
            }
        } else {
            $params->set('page_title', $item->cleanTitle);
        }
        if (K2_JVERSION != '15') {
            if ($mainframe->getCfg('sitename_pagetitles', 0) == 1) {
                $title = JText::sprintf('JPAGETITLE', $mainframe->getCfg('sitename'), $params->get('page_title'));
                $params->set('page_title', $title);
            } elseif ($mainframe->getCfg('sitename_pagetitles', 0) == 2) {
                $title = JText::sprintf('JPAGETITLE', $params->get('page_title'), $mainframe->getCfg('sitename'));
                $params->set('page_title', $title);
            }
        }
        $document->setTitle($params->get('page_title'));
        // Set pathway
        $menus = $mainframe->getMenu();
        $menu = $menus->getActive();
        $pathway = $mainframe->getPathWay();
        if ($menu) {
            if (isset($menu->query['view']) && ($menu->query['view'] != 'item' || $menu->query['id'] != $item->id)) {
                if (!isset($menu->query['task']) || $menu->query['task'] != 'category' || $menu->query['id'] != $item->catid) {
                    $pathway->addItem($item->category->name, $item->category->link);
                }
                $pathway->addItem($item->cleanTitle, '');
            }
        }
        // Set metadata
        if ($item->metadesc) {
            $document->setDescription(K2_JVERSION == '15' ? htmlspecialchars($item->metadesc, ENT_QUOTES, 'UTF-8') : $item->metadesc);
        } else {
            $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $item->introtext . ' ' . $item->fulltext);
            $metaDescItem = strip_tags($metaDescItem);
            $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $params->get('metaDescLimit', 150));
            $document->setDescription(K2_JVERSION == '15' ? $metaDescItem : html_entity_decode($metaDescItem));
        }
        if ($item->metakey) {
            $document->setMetadata('keywords', $item->metakey);
        } else {
            if (isset($item->tags) && count($item->tags)) {
                $tmp = array();
                foreach ($item->tags as $tag) {
                    $tmp[] = $tag->name;
                }
                $document->setMetadata('keywords', implode(',', $tmp));
            }
        }
        // Menu metadata for Joomla! 2.5+ (overrides the current metadata if set)
        if (K2_JVERSION != '15') {
            if ($params->get('menu-meta_description')) {
                $document->setDescription($params->get('menu-meta_description'));
            }
            if ($params->get('menu-meta_keywords')) {
                $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
            }
            if ($params->get('robots')) {
                $document->setMetadata('robots', $params->get('robots'));
            }
            // Menu page display options
            if ($params->get('page_heading')) {
                $params->set('page_title', $params->get('page_heading'));
            }
            $params->set('show_page_title', $params->get('show_page_heading'));
        }
        if ($mainframe->getCfg('MetaTitle') == '1') {
            $document->setMetadata('title', $item->cleanTitle);
        }
        if ($mainframe->getCfg('MetaAuthor') == '1' && isset($item->author->name)) {
            $document->setMetadata('author', $item->author->name);
        }
        $mdata = class_exists('JParameter') ? new JParameter($item->metadata) : new JRegistry($item->metadata);
        $mdata = $mdata->toArray();
        foreach ($mdata as $k => $v) {
            if ($k == 'robots' || $k == 'author') {
                if ($v) {
                    $document->setMetadata($k, $v);
                }
            }
        }
        // Set Facebook meta data
        $document = JFactory::getDocument();
        $uri = JURI::getInstance();
        $document->setMetaData('og:url', $uri->toString());
        $document->setMetaData('og:title', K2_JVERSION == '15' ? htmlspecialchars($document->getTitle(), ENT_QUOTES, 'UTF-8') : $document->getTitle());
        $document->setMetaData('og:type', 'article');
        $facebookImage = 'image' . $params->get('facebookImage', 'Small');
        if ($item->{$facebookImage}) {
            $parts = parse_url($item->{$facebookImage});
            if (JFile::exists(JPATH_SITE . $parts['path'])) {
                $image = substr(JURI::root(), 0, -1) . str_replace(JURI::root(true), '', $item->{$facebookImage});
                $document->setMetaData('og:image', $image);
                $document->setMetaData('image', $image);
            }
        }
        $document->setMetaData('og:description', strip_tags($document->getDescription()));
        // Look for template files in component folders
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates');
        $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (K2 template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . 'default');
        // Look for overrides in template folder (Joomla! template structure)
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'default');
        $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2');
        // Look for specific K2 theme files
        if ($item->params->get('theme')) {
            $this->_addPath('template', JPATH_COMPONENT . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . 'templates' . DS . $item->params->get('theme'));
            $this->_addPath('template', JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'html' . DS . 'com_k2' . DS . $item->params->get('theme'));
        }
        // Assign data
        $this->assignRef('item', $item);
        $this->assignRef('user', $user);
        $this->assignRef('params', $item->params);
        $this->assignRef('pagination', $pagination);
        parent::display($tpl);
    }
Пример #4
0
 /**
  * This method is to load neccessary access
  * for PageBuilder need
  *
  * @return void
  */
 public function onBeforeRender()
 {
     // Check if JoomlaShine extension framework is enabled?
     $framework = JTable::getInstance('Extension');
     $framework->load(array('element' => 'jsnframework', 'type' => 'plugin', 'folder' => 'system'));
     // Do nothing if JSN Extension framework not found.
     if (!$framework->extension_id) {
         return;
     }
     $app = JFactory::getApplication();
     $tpl = $app->input->getInt('tp', 0);
     if ($app->isAdmin() || $tpl) {
         return;
     }
     // Get requested component, view and task
     $option = $app->input->getCmd('option', '');
     $view = $app->input->getCmd('view', '');
     $layout = $app->input->getCmd('layout', '');
     $user = JFactory::getUser();
     if ($app->isSite() && $option == 'com_content' && $view == 'form' && $layout == 'edit' && $user->get('id') > 0) {
         return;
     }
     $doc = JFactory::getDocument();
     if (get_class($doc) != "JDocumentHTML") {
         return;
     }
     if ($app->isSite() && $option == 'com_k2' && $view == 'item' && $app->input->getInt('id', 0)) {
         if (file_exists(JPATH_ROOT . '/administrator/components/com_pagebuilder/helpers/shortcode.php')) {
             if (class_exists('K2HelperUtilities')) {
                 include_once JPATH_ROOT . '/administrator/components/com_pagebuilder/helpers/shortcode.php';
                 $shortCodeRegex = JSNPagebuilderHelpersShortcode::getShortcodeRegex();
                 JModelLegacy::addIncludePath(JPATH_ROOT . '/components/com_k2/models');
                 $K2ModelItem = JModelLegacy::getInstance('k2modelitem');
                 $k2Item = $K2ModelItem->getData();
                 if (count($k2Item)) {
                     $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $k2Item->introtext . ' ' . $k2Item->fulltext);
                     $metaDescItem = strip_tags($metaDescItem);
                     $k2params = K2HelperUtilities::getParams('com_k2');
                     $metaDescItem = self::removeShortCode($metaDescItem, $shortCodeRegex);
                     $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $k2params->get('metaDescLimit', 150));
                     if ($doc->getMetaData('og:description') != null) {
                         $doc->setMetaData('og:description', $metaDescItem);
                     }
                     if ($doc->getDescription() != '') {
                         $doc->setDescription($metaDescItem);
                     }
                 }
             }
         }
     }
     // Get PageBuilder configuration.
     $params = JSNConfigHelper::get('com_pagebuilder');
     // Check if it's enabled or not.
     $isEnabled = $params->get('enable_pagebuilder', 1);
     // Do nothing if PageBuilder not enabled;
     if (!$isEnabled) {
     }
     // Register autoloaded classes
     JSN_Loader::register(JSNPB_ADMIN_ROOT . '/helpers', 'JSNPagebuilderHelpers');
     JSN_Loader::register(JSNPB_ADMIN_ROOT . '/helpers/shortcode', 'JSNPBShortcode');
     //JSN_Loader::register(JPATH_ROOT . '/plugins/pagebuilder/' , 'JSNPBShortcode');
     //JSN_Loader::register(JPATH_ROOT . '/administrator/components/com_pagebuilder/elements/' , 'JSNPBShortcode');
     JSN_Loader::register(JPATH_ROOT . '/plugins/jsnpagebuilder/defaultelements/', 'JSNPBShortcode');
     //load ElementAssets
     self::loadElementAssets();
     /*
      * Move all css files of PageBuilder
      * to the end of css list
      *
      */
     $data = $doc->getHeadData();
     $styleSheetList = $data['styleSheets'];
     $_tmpList = array();
     if (count($styleSheetList)) {
         foreach ($styleSheetList as $cssUrl => $css) {
             // Check if the file belongs to PageBuilder
             if (strpos($cssUrl, 'plugins/pagebuilder/') !== false || strpos($cssUrl, 'com_pagebuilder') !== false) {
                 $_tmpList[$cssUrl] = $css;
                 unset($styleSheetList[$cssUrl]);
             }
         }
     }
     $styleSheetList = array_merge($styleSheetList, $_tmpList);
     $data['styleSheets'] = $styleSheetList;
     $doc->setHeadData($data);
 }
Пример #5
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);
        //User K2 plugins
        $item->event->K2UserDisplay = '';
        if (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::_("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 = "\n\t\t\t\t\t\t\t\t\t\twindow.addEvent('domready', function(){\n\t\t\t\t\t\t\t\t\t\t\t\$('userName').setProperty('value','" . $user->name . "');\n\t\t\t\t\t\t\t\t\t\t\t\$('userName').setProperty('disabled','disabled');\n\t\t\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('value','" . $user->email . "');\n\t\t\t\t\t\t\t\t\t\t\t\$('commentEmail').setProperty('disabled','disabled');\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\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);
        //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);
        }
        $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->title, '');
            }
        }
        //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));
            $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));
            }
        }
        if ($mainframe->getCfg('MetaTitle') == '1') {
            $mainframe->addMetaTag('title', $item->title);
        }
        if ($mainframe->getCfg('MetaAuthor') == '1' && isset($item->author->name)) {
            $mainframe->addMetaTag('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);
                }
            }
        }
        //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
 protected function setMetadata($resource)
 {
     $params = JComponentHelper::getParams('com_k2');
     if (!$this->isActive) {
         // Detect title
         $title = isset($resource->title) ? $resource->title : $resource->name;
         // Set the browser title according to the settings
         $this->setTitle($title);
         // Hide page heading since the current menu item is inherited
         $this->params->set('show_page_heading', false);
         // Update pathway
         $application = JFactory::getApplication();
         $pathway = $application->getPathWay();
         $pathway->addItem($title, '');
     }
     // Detect and set metadata
     if (isset($resource->metadata) && ($metadata = $resource->metadata)) {
         if ($metadata->get('description')) {
             $this->document->setDescription($metadata->get('description'));
         }
         if ($metadata->get('kewords')) {
             $this->document->setMetadata('keywords', $metadata->get('kewords'));
         }
         if ($metadata->get('robots')) {
             $this->document->setMetadata('robots', $metadata->get('robots'));
         }
         if ($metadata->get('author')) {
             $this->document->setMetadata('author', $metadata->get('author'));
         }
     }
     // If meta description is empty ( this means it was not set in the menu or item/category form ) then use the content of the resource
     if (!$this->document->getDescription()) {
         $resourceType = get_class($resource);
         if ($resourceType == 'K2Items') {
             $description = $resource->introtext . ' ' . $resource->fulltext;
         } else {
             if ($resourceType == 'K2Categories') {
                 $description = $resource->description;
             } else {
                 if ($resourceType == 'K2Users') {
                     $description = $resource->description;
                 }
             }
         }
         if (isset($description)) {
             $description = strip_tags($description);
             $description = K2HelperUtilities::characterLimit($description, $params->get('metaDescLimit', 150));
             $this->document->setDescription($description);
         }
     }
 }