/** * Execute and display a template script. * * @param string $tpl The name of the template file to parse; automatically searches through the template paths. * * @return mixed A string if successful, otherwise an Error object. */ public function display($tpl = null) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $dispatcher = JEventDispatcher::getInstance(); $this->item = $this->get('Item'); $this->print = $app->input->getBool('print'); $this->state = $this->get('State'); $this->user = $user; // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // Create a shortcut for $item. $item = $this->item; $item->tagLayout = new JLayoutFile('joomla.content.tags'); // Add router helpers. $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id; $item->catslug = $item->category_alias ? $item->catid . ':' . $item->category_alias : $item->catid; $item->parent_slug = $item->parent_alias ? $item->parent_id . ':' . $item->parent_alias : $item->parent_id; // No link for ROOT category if ($item->parent_alias == 'root') { $item->parent_slug = null; } // TODO: Change based on shownoauth $item->readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language)); // Merge article params. If this is single-article view, menu params override article params // Otherwise, article params override menu item params $this->params = $this->state->get('params'); $active = $app->getMenu()->getActive(); $temp = clone $this->params; // Check to see which parameters should take priority if ($active) { $currentLink = $active->link; // If the current view is the active item and an article view for this article, then the menu item params take priority if (strpos($currentLink, 'view=article') && strpos($currentLink, '&id=' . (string) $item->id)) { // Load layout from active query (in case it is an alternative menu item) if (isset($active->query['layout'])) { $this->setLayout($active->query['layout']); } elseif ($layout = $item->params->get('article_layout')) { $this->setLayout($layout); } // $item->params are the article params, $temp are the menu item params // Merge so that the menu item params take priority $item->params->merge($temp); } else { // Current view is not a single article, so the article params take priority here // Merge the menu item params with the article params so that the article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article if ($layout = $item->params->get('article_layout')) { $this->setLayout($layout); } } } else { // Merge so that article params take priority $temp->merge($item->params); $item->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article if ($layout = $item->params->get('article_layout')) { $this->setLayout($layout); } } $offset = $this->state->get('list.offset'); // Check the view access to the article (the model has already computed the values). if ($item->params->get('access-view') == false && $item->params->get('show_noauth', '0') == '0') { $app->enqueueMessage(JText::_('JERROR_ALERTNOAUTHOR'), 'error'); $app->setHeader('status', 403, true); return; } if ($item->params->get('show_intro', '1') == '1') { $item->text = $item->introtext . ' ' . $item->fulltext; } elseif ($item->fulltext) { $item->text = $item->fulltext; } else { $item->text = $item->introtext; } $item->tags = new JHelperTags(); $item->tags->getItemTags('com_content.article', $this->item->id); if ($item->params->get('show_associations')) { $item->associations = ContentHelperAssociation::displayAssociations($item->id); } // Process the content plugins. JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentPrepare', array('com_content.article', &$item, &$item->params, $offset)); $item->event = new stdClass(); $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$item->params, $offset)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$item->params, $offset)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$item->params, $offset)); $item->event->afterDisplayContent = trim(implode("\n", $results)); // Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx')); $this->_prepareDocument(); parent::display($tpl); }
/** * Method to get a list of articles. * * Overriden to inject convert the attribs field into a JParameter object. * * @return mixed An array of objects on success, false on failure. * * @since 1.6 */ public function getItems() { $items = parent::getItems(); $user = JFactory::getUser(); $userId = $user->get('id'); $guest = $user->get('guest'); $groups = $user->getAuthorisedViewLevels(); $input = JFactory::getApplication()->input; // Get the global params $globalParams = JComponentHelper::getParams('com_content', true); // Convert the parameter fields into objects. foreach ($items as &$item) { $articleParams = new Registry($item->attribs); // Unpack readmore and layout params $item->alternative_readmore = $articleParams->get('alternative_readmore'); $item->layout = $articleParams->get('layout'); $item->params = clone $this->getState('params'); /*For blogs, article params override menu item params only if menu param = 'use_article' Otherwise, menu item params control the layout If menu item is 'use_article' and there is no article param, use global*/ if ($input->getString('layout') == 'blog' || $input->getString('view') == 'featured' || $this->getState('params')->get('layout_type') == 'blog') { // Create an array of just the params set to 'use_article' $menuParamsArray = $this->getState('params')->toArray(); $articleArray = array(); foreach ($menuParamsArray as $key => $value) { if ($value === 'use_article') { // If the article has a value, use it if ($articleParams->get($key) != '') { // Get the value from the article $articleArray[$key] = $articleParams->get($key); } else { // Otherwise, use the global value $articleArray[$key] = $globalParams->get($key); } } } // Merge the selected article params if (count($articleArray) > 0) { $articleParams = new Registry($articleArray); $item->params->merge($articleParams); } } else { // For non-blog layouts, merge all of the article params $item->params->merge($articleParams); } // Get display date switch ($item->params->get('list_show_date')) { case 'modified': $item->displayDate = $item->modified; break; case 'published': $item->displayDate = $item->publish_up == 0 ? $item->created : $item->publish_up; break; default: case 'created': $item->displayDate = $item->created; break; } // Compute the asset access permissions. // Technically guest could edit an article, but lets not check that to improve performance a little. if (!$guest) { $asset = 'com_content.article.' . $item->id; // Check general edit permission first. if ($user->authorise('core.edit', $asset)) { $item->params->set('access-edit', true); } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) { // Check for a valid user and that they are the owner. if ($userId == $item->created_by) { $item->params->set('access-edit', true); } } } $access = $this->getState('filter.access'); if ($access) { // If the access filter has been set, we already have only the articles this user can view. $item->params->set('access-view', true); } else { // If no access filter is set, the layout takes some responsibility for display of limited information. if ($item->catid == 0 || $item->category_access === null) { $item->params->set('access-view', in_array($item->access, $groups)); } else { $item->params->set('access-view', in_array($item->access, $groups) && in_array($item->category_access, $groups)); } } // Get the tags if ($item->params->get('show_tags')) { $item->tags = new JHelperTags(); $item->tags->getItemTags('com_content.article', $item->id); } if ($item->params->get('show_associations')) { $item->associations = ContentHelperAssociation::displayAssociations($item->id); } } return $items; }
public function getAssociatedArticle($id) { $associated_id = 0; require_once JPATH_SITE . '/components/com_content/helpers/route.php'; require_once JPATH_SITE . '/components/com_content/helpers/association.php'; $result = ContentHelperAssociation::getAssociations($id, 'article'); $tag = JFactory::getLanguage()->getTag(); if (isset($result[$tag])) { $parts = JString::parse_url($result[$tag]); parse_str($parts['query'], $vars); if (isset($vars['id'])) { $splits = explode(':', $vars['id']); } $associated_id = (int) $splits[0]; } if (isset($associated_id) && $associated_id) { $id = $associated_id; } return $id; }
$link = new JUri(JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId, false)); $link->setVar('return', base64_encode(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language))); ?> <a href="<?php echo $link; ?> " class="register"> <?php echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE'); ?> </a> <?php if (JLanguageAssociations::isEnabled() && $this->params->get('show_associations')) { ?> <?php $associations = ContentHelperAssociation::displayAssociations($article->id); ?> <?php foreach ($associations as $association) { ?> <?php if ($this->params->get('flags', 1)) { ?> <?php $flag = JHtml::_('image', 'mod_languages/' . $association['language']->image . '.gif', $association['language']->title_native, array('title' => $association['language']->title_native), true); ?> <a href="<?php echo JRoute::_($association['item']); ?> "><?php echo $flag;