You've already forked joomla_test
first commit
This commit is contained in:
69
components/com_content/helpers/association.php
Normal file
69
components/com_content/helpers/association.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
JLoader::register('ContentHelper', JPATH_ADMINISTRATOR . '/components/com_content/helpers/content.php');
|
||||
JLoader::register('CategoryHelperAssociation', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/association.php');
|
||||
|
||||
/**
|
||||
* Content Component Association Helper
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class ContentHelperAssociation extends CategoryHelperAssociation
|
||||
{
|
||||
/**
|
||||
* Method to get the associations for a given item
|
||||
*
|
||||
* @param integer $id Id of the item
|
||||
* @param string $view Name of the view
|
||||
*
|
||||
* @return array Array of associations for the item
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
|
||||
public static function getAssociations($id = 0, $view = null)
|
||||
{
|
||||
jimport('helper.route', JPATH_COMPONENT_SITE);
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$jinput = $app->input;
|
||||
$view = is_null($view) ? $jinput->get('view') : $view;
|
||||
$id = empty($id) ? $jinput->getInt('id') : $id;
|
||||
|
||||
if ($view == 'article')
|
||||
{
|
||||
if ($id)
|
||||
{
|
||||
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id);
|
||||
|
||||
$return = array();
|
||||
|
||||
foreach ($associations as $tag => $item)
|
||||
{
|
||||
$return[$tag] = ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($view == 'category' || $view == 'categories')
|
||||
{
|
||||
return self::getCategoryAssociations($id, 'com_content');
|
||||
}
|
||||
|
||||
return array();
|
||||
|
||||
}
|
||||
}
|
28
components/com_content/helpers/category.php
Normal file
28
components/com_content/helpers/category.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Content Component Category Tree
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
* @since 1.6
|
||||
*/
|
||||
class ContentCategories extends JCategories
|
||||
{
|
||||
public function __construct($options = array())
|
||||
{
|
||||
$options['table'] = '#__content';
|
||||
$options['extension'] = 'com_content';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
}
|
274
components/com_content/helpers/icon.php
Normal file
274
components/com_content/helpers/icon.php
Normal file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Content Component HTML Helper
|
||||
*
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
* @since 1.5
|
||||
*/
|
||||
abstract class JHtmlIcon
|
||||
{
|
||||
/**
|
||||
* Method to generate a link to the create item page for the given category
|
||||
*
|
||||
* @param object $category The category information
|
||||
* @param JRegistry $params The item parameters
|
||||
* @param array $attribs Optional attributes for the link
|
||||
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
|
||||
*
|
||||
* @return string The HTML markup for the create item link
|
||||
*/
|
||||
public static function create($category, $params, $attribs = array(), $legacy = false)
|
||||
{
|
||||
JHtml::_('bootstrap.tooltip');
|
||||
|
||||
$uri = JUri::getInstance();
|
||||
|
||||
$url = 'index.php?option=com_content&task=article.add&return=' . base64_encode($uri) . '&a_id=0&catid=' . $category->id;
|
||||
|
||||
if ($params->get('show_icons'))
|
||||
{
|
||||
if ($legacy)
|
||||
{
|
||||
$text = JHtml::_('image', 'system/new.png', JText::_('JNEW'), null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = '<span class="icon-plus"></span> ' . JText::_('JNEW') . ' ';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = JText::_('JNEW') . ' ';
|
||||
}
|
||||
|
||||
// Add the button classes to the attribs array
|
||||
if (isset($attribs['class']))
|
||||
{
|
||||
$attribs['class'] = $attribs['class'] . ' btn btn-primary';
|
||||
}
|
||||
else
|
||||
{
|
||||
$attribs['class'] = 'btn btn-primary';
|
||||
}
|
||||
|
||||
$button = JHtml::_('link', JRoute::_($url), $text, $attribs);
|
||||
|
||||
$output = '<span class="hasTooltip" title="' . JHtml::tooltipText('COM_CONTENT_CREATE_ARTICLE') . '">' . $button . '</span>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate a link to the email item page for the given article
|
||||
*
|
||||
* @param object $article The article information
|
||||
* @param JRegistry $params The item parameters
|
||||
* @param array $attribs Optional attributes for the link
|
||||
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
|
||||
*
|
||||
* @return string The HTML markup for the email item link
|
||||
*/
|
||||
public static function email($article, $params, $attribs = array(), $legacy = false)
|
||||
{
|
||||
require_once JPATH_SITE . '/components/com_mailto/helpers/mailto.php';
|
||||
|
||||
$uri = JUri::getInstance();
|
||||
$base = $uri->toString(array('scheme', 'host', 'port'));
|
||||
$template = JFactory::getApplication()->getTemplate();
|
||||
$link = $base . JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid), false);
|
||||
$url = 'index.php?option=com_mailto&tmpl=component&template=' . $template . '&link=' . MailToHelper::addLink($link);
|
||||
|
||||
$status = 'width=400,height=350,menubar=yes,resizable=yes';
|
||||
|
||||
if ($params->get('show_icons'))
|
||||
{
|
||||
if ($legacy)
|
||||
{
|
||||
$text = JHtml::_('image', 'system/emailButton.png', JText::_('JGLOBAL_EMAIL'), null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = '<span class="icon-envelope"></span> ' . JText::_('JGLOBAL_EMAIL');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = JText::_('JGLOBAL_EMAIL');
|
||||
}
|
||||
|
||||
$attribs['title'] = JText::_('JGLOBAL_EMAIL');
|
||||
$attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
|
||||
|
||||
$output = JHtml::_('link', JRoute::_($url), $text, $attribs);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an edit icon for the article.
|
||||
*
|
||||
* This icon will not display in a popup window, nor if the article is trashed.
|
||||
* Edit access checks must be performed in the calling code.
|
||||
*
|
||||
* @param object $article The article information
|
||||
* @param JRegistry $params The item parameters
|
||||
* @param array $attribs Optional attributes for the link
|
||||
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
|
||||
*
|
||||
* @return string The HTML for the article edit icon.
|
||||
* @since 1.6
|
||||
*/
|
||||
public static function edit($article, $params, $attribs = array(), $legacy = false)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$uri = JUri::getInstance();
|
||||
|
||||
// Ignore if in a popup window.
|
||||
if ($params && $params->get('popup'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Ignore if the state is negative (trashed).
|
||||
if ($article->state < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JHtml::_('bootstrap.tooltip');
|
||||
|
||||
// Show checked_out icon if the article is checked out by a different user
|
||||
if (property_exists($article, 'checked_out') && property_exists($article, 'checked_out_time') && $article->checked_out > 0 && $article->checked_out != $user->get('id'))
|
||||
{
|
||||
$checkoutUser = JFactory::getUser($article->checked_out);
|
||||
$button = JHtml::_('image', 'system/checked_out.png', null, null, true);
|
||||
$date = JHtml::_('date', $article->checked_out_time);
|
||||
$tooltip = JText::_('JLIB_HTML_CHECKED_OUT') . ' :: ' . JText::sprintf('COM_CONTENT_CHECKED_OUT_BY', $checkoutUser->name) . ' <br /> ' . $date;
|
||||
|
||||
return '<span class="hasTooltip" title="' . JHtml::tooltipText($tooltip. '', 0) . '">' . $button . '</span>';
|
||||
}
|
||||
|
||||
$url = 'index.php?option=com_content&task=article.edit&a_id=' . $article->id . '&return=' . base64_encode($uri);
|
||||
|
||||
if ($article->state == 0)
|
||||
{
|
||||
$overlib = JText::_('JUNPUBLISHED');
|
||||
}
|
||||
else
|
||||
{
|
||||
$overlib = JText::_('JPUBLISHED');
|
||||
}
|
||||
|
||||
$date = JHtml::_('date', $article->created);
|
||||
$author = $article->created_by_alias ? $article->created_by_alias : $article->author;
|
||||
|
||||
$overlib .= '<br />';
|
||||
$overlib .= $date;
|
||||
$overlib .= '<br />';
|
||||
$overlib .= JText::sprintf('COM_CONTENT_WRITTEN_BY', htmlspecialchars($author, ENT_COMPAT, 'UTF-8'));
|
||||
|
||||
if ($legacy)
|
||||
{
|
||||
$icon = $article->state ? 'edit.png' : 'edit_unpublished.png';
|
||||
$text = JHtml::_('image', 'system/' . $icon, JText::_('JGLOBAL_EDIT'), null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$icon = $article->state ? 'edit' : 'eye-close';
|
||||
$text = '<span class="hasTooltip icon-' . $icon . ' tip" title="' . JHtml::tooltipText(JText::_('COM_CONTENT_EDIT_ITEM'), $overlib, 0) . '"></span> ' . JText::_('JGLOBAL_EDIT') . ' ';
|
||||
}
|
||||
|
||||
$output = JHtml::_('link', JRoute::_($url), $text, $attribs);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate a popup link to print an article
|
||||
*
|
||||
* @param object $article The article information
|
||||
* @param JRegistry $params The item parameters
|
||||
* @param array $attribs Optional attributes for the link
|
||||
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
|
||||
*
|
||||
* @return string The HTML markup for the popup link
|
||||
*/
|
||||
public static function print_popup($article, $params, $attribs = array(), $legacy = false)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$input = $app->input;
|
||||
$request = $input->request;
|
||||
|
||||
$url = ContentHelperRoute::getArticleRoute($article->slug, $article->catid);
|
||||
$url .= '&tmpl=component&print=1&layout=default&page=' . @ $request->limitstart;
|
||||
|
||||
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
|
||||
|
||||
// checks template image directory for image, if non found default are loaded
|
||||
if ($params->get('show_icons'))
|
||||
{
|
||||
if ($legacy)
|
||||
{
|
||||
$text = JHtml::_('image', 'system/printButton.png', JText::_('JGLOBAL_PRINT'), null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = '<span class="icon-print"></span> ' . JText::_('JGLOBAL_PRINT') . ' ';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = JText::_('JGLOBAL_PRINT');
|
||||
}
|
||||
|
||||
$attribs['title'] = JText::_('JGLOBAL_PRINT');
|
||||
$attribs['onclick'] = "window.open(this.href,'win2','" . $status . "'); return false;";
|
||||
$attribs['rel'] = 'nofollow';
|
||||
|
||||
return JHtml::_('link', JRoute::_($url), $text, $attribs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to generate a link to print an article
|
||||
*
|
||||
* @param object $article Not used, @deprecated for 4.0
|
||||
* @param JRegistry $params The item parameters
|
||||
* @param array $attribs Not used, @deprecated for 4.0
|
||||
* @param boolean $legacy True to use legacy images, false to use icomoon based graphic
|
||||
*
|
||||
* @return string The HTML markup for the popup link
|
||||
*/
|
||||
public static function print_screen($article, $params, $attribs = array(), $legacy = false)
|
||||
{
|
||||
// Checks template image directory for image, if none found default are loaded
|
||||
if ($params->get('show_icons'))
|
||||
{
|
||||
if ($legacy)
|
||||
{
|
||||
$text = JHtml::_('image', 'system/printButton.png', JText::_('JGLOBAL_PRINT'), null, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = '<span class="icon-print"></span> ' . JText::_('JGLOBAL_PRINT') . ' ';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = JText::_('JGLOBAL_PRINT');
|
||||
}
|
||||
|
||||
return '<a href="#" onclick="window.print();return false;">' . $text . '</a>';
|
||||
}
|
||||
|
||||
}
|
1
components/com_content/helpers/index.html
Normal file
1
components/com_content/helpers/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
267
components/com_content/helpers/query.php
Normal file
267
components/com_content/helpers/query.php
Normal file
@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Content Component Query Helper
|
||||
*
|
||||
* @static
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
* @since 1.5
|
||||
*/
|
||||
class ContentHelperQuery
|
||||
{
|
||||
/**
|
||||
* Translate an order code to a field for primary category ordering.
|
||||
*
|
||||
* @param string $orderby The ordering code.
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function orderbyPrimary($orderby)
|
||||
{
|
||||
switch ($orderby)
|
||||
{
|
||||
case 'alpha' :
|
||||
$orderby = 'c.path, ';
|
||||
break;
|
||||
|
||||
case 'ralpha' :
|
||||
$orderby = 'c.path DESC, ';
|
||||
break;
|
||||
|
||||
case 'order' :
|
||||
$orderby = 'c.lft, ';
|
||||
break;
|
||||
|
||||
default :
|
||||
$orderby = '';
|
||||
break;
|
||||
}
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate an order code to a field for secondary category ordering.
|
||||
*
|
||||
* @param string $orderby The ordering code.
|
||||
* @param string $orderDate The ordering code for the date.
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function orderbySecondary($orderby, $orderDate = 'created')
|
||||
{
|
||||
$queryDate = self::getQueryDate($orderDate);
|
||||
|
||||
switch ($orderby)
|
||||
{
|
||||
case 'date' :
|
||||
$orderby = $queryDate;
|
||||
break;
|
||||
|
||||
case 'rdate' :
|
||||
$orderby = $queryDate . ' DESC ';
|
||||
break;
|
||||
|
||||
case 'alpha' :
|
||||
$orderby = 'a.title';
|
||||
break;
|
||||
|
||||
case 'ralpha' :
|
||||
$orderby = 'a.title DESC';
|
||||
break;
|
||||
|
||||
case 'hits' :
|
||||
$orderby = 'a.hits DESC';
|
||||
break;
|
||||
|
||||
case 'rhits' :
|
||||
$orderby = 'a.hits';
|
||||
break;
|
||||
|
||||
case 'order' :
|
||||
$orderby = 'a.ordering';
|
||||
break;
|
||||
|
||||
case 'author' :
|
||||
$orderby = 'author';
|
||||
break;
|
||||
|
||||
case 'rauthor' :
|
||||
$orderby = 'author DESC';
|
||||
break;
|
||||
|
||||
case 'front' :
|
||||
$orderby = 'a.featured DESC, fp.ordering';
|
||||
break;
|
||||
|
||||
default :
|
||||
$orderby = 'a.ordering';
|
||||
break;
|
||||
}
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate an order code to a field for primary category ordering.
|
||||
*
|
||||
* @param string $orderDate The ordering code.
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
* @since 1.6
|
||||
*/
|
||||
public static function getQueryDate($orderDate)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
|
||||
switch ($orderDate)
|
||||
{
|
||||
case 'modified' :
|
||||
$queryDate = ' CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END';
|
||||
break;
|
||||
|
||||
// use created if publish_up is not set
|
||||
case 'published' :
|
||||
$queryDate = ' CASE WHEN a.publish_up = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.publish_up END ';
|
||||
break;
|
||||
|
||||
case 'created' :
|
||||
default :
|
||||
$queryDate = ' a.created ';
|
||||
break;
|
||||
}
|
||||
|
||||
return $queryDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get join information for the voting query.
|
||||
*
|
||||
* @param JRegistry $param An options object for the article.
|
||||
*
|
||||
* @return array A named array with "select" and "join" keys.
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function buildVotingQuery($params=null)
|
||||
{
|
||||
if (!$params)
|
||||
{
|
||||
$params = JComponentHelper::getParams('com_content');
|
||||
}
|
||||
|
||||
$voting = $params->get('show_vote');
|
||||
|
||||
if ($voting)
|
||||
{
|
||||
// calculate voting count
|
||||
$select = ' , ROUND(v.rating_sum / v.rating_count) AS rating, v.rating_count';
|
||||
$join = ' LEFT JOIN #__content_rating AS v ON a.id = v.content_id';
|
||||
}
|
||||
else
|
||||
{
|
||||
$select = '';
|
||||
$join = '';
|
||||
}
|
||||
|
||||
$results = array ('select' => $select, 'join' => $join);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to order the intro articles array for ordering
|
||||
* down the columns instead of across.
|
||||
* The layout always lays the introtext articles out across columns.
|
||||
* Array is reordered so that, when articles are displayed in index order
|
||||
* across columns in the layout, the result is that the
|
||||
* desired article ordering is achieved down the columns.
|
||||
*
|
||||
* @param array $articles Array of intro text articles
|
||||
* @param integer $numColumns Number of columns in the layout
|
||||
*
|
||||
* @return array Reordered array to achieve desired ordering down columns
|
||||
* @since 1.6
|
||||
*/
|
||||
public static function orderDownColumns(&$articles, $numColumns = 1)
|
||||
{
|
||||
$count = count($articles);
|
||||
|
||||
// just return the same array if there is nothing to change
|
||||
if ($numColumns == 1 || !is_array($articles) || $count <= $numColumns)
|
||||
{
|
||||
$return = $articles;
|
||||
}
|
||||
// we need to re-order the intro articles array
|
||||
else {
|
||||
// we need to preserve the original array keys
|
||||
$keys = array_keys($articles);
|
||||
|
||||
$maxRows = ceil($count / $numColumns);
|
||||
$numCells = $maxRows * $numColumns;
|
||||
$numEmpty = $numCells - $count;
|
||||
$index = array();
|
||||
|
||||
// calculate number of empty cells in the array
|
||||
|
||||
// fill in all cells of the array
|
||||
// put -1 in empty cells so we can skip later
|
||||
|
||||
for ($row = 1, $i = 1; $row <= $maxRows; $row++)
|
||||
{
|
||||
for ($col = 1; $col <= $numColumns; $col++)
|
||||
{
|
||||
if ($numEmpty > ($numCells - $i))
|
||||
{
|
||||
// put -1 in empty cells
|
||||
$index[$row][$col] = -1;
|
||||
}
|
||||
else {
|
||||
// put in zero as placeholder
|
||||
$index[$row][$col] = 0;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// layout the articles in column order, skipping empty cells
|
||||
$i = 0;
|
||||
for ($col = 1; ($col <= $numColumns) && ($i < $count); $col++)
|
||||
{
|
||||
for ($row = 1; ($row <= $maxRows) && ($i < $count); $row++)
|
||||
{
|
||||
if ($index[$row][$col] != - 1)
|
||||
{
|
||||
$index[$row][$col] = $keys[$i];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now read the $index back row by row to get articles in right row/col
|
||||
// so that they will actually be ordered down the columns (when read by row in the layout)
|
||||
$return = array();
|
||||
$i = 0;
|
||||
for ($row = 1; ($row <= $maxRows) && ($i < $count); $row++)
|
||||
{
|
||||
for ($col = 1; ($col <= $numColumns) && ($i < $count); $col++)
|
||||
{
|
||||
$return[$keys[$i]] = $articles[$index[$row][$col]];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
239
components/com_content/helpers/route.php
Normal file
239
components/com_content/helpers/route.php
Normal file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Content Component Route Helper
|
||||
*
|
||||
* @static
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
* @since 1.5
|
||||
*/
|
||||
abstract class ContentHelperRoute
|
||||
{
|
||||
protected static $lookup = array();
|
||||
|
||||
/**
|
||||
* @param integer The route of the content item
|
||||
*/
|
||||
public static function getArticleRoute($id, $catid = 0, $language = 0)
|
||||
{
|
||||
$needles = array(
|
||||
'article' => array((int) $id)
|
||||
);
|
||||
//Create the link
|
||||
$link = 'index.php?option=com_content&view=article&id='. $id;
|
||||
if ((int) $catid > 1)
|
||||
{
|
||||
$categories = JCategories::getInstance('Content');
|
||||
$category = $categories->get((int) $catid);
|
||||
if ($category)
|
||||
{
|
||||
$needles['category'] = array_reverse($category->getPath());
|
||||
$needles['categories'] = $needles['category'];
|
||||
$link .= '&catid='.$catid;
|
||||
}
|
||||
}
|
||||
if ($language && $language != "*" && JLanguageMultilang::isEnabled())
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('a.sef AS sef')
|
||||
->select('a.lang_code AS lang_code')
|
||||
->from('#__languages AS a');
|
||||
|
||||
$db->setQuery($query);
|
||||
$langs = $db->loadObjectList();
|
||||
foreach ($langs as $lang)
|
||||
{
|
||||
if ($language == $lang->lang_code)
|
||||
{
|
||||
$link .= '&lang='.$lang->sef;
|
||||
$needles['language'] = $language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($item = self::_findItem($needles))
|
||||
{
|
||||
$link .= '&Itemid='.$item;
|
||||
}
|
||||
elseif ($item = self::_findItem())
|
||||
{
|
||||
$link .= '&Itemid='.$item;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
public static function getCategoryRoute($catid, $language = 0)
|
||||
{
|
||||
if ($catid instanceof JCategoryNode)
|
||||
{
|
||||
$id = $catid->id;
|
||||
$category = $catid;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = (int) $catid;
|
||||
$category = JCategories::getInstance('Content')->get($id);
|
||||
}
|
||||
|
||||
if ($id < 1)
|
||||
{
|
||||
$link = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = 'index.php?option=com_content&view=category&id='.$id;
|
||||
|
||||
$needles = array(
|
||||
'category' => array($id)
|
||||
);
|
||||
|
||||
if ($language && $language != "*" && JLanguageMultilang::isEnabled())
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('a.sef AS sef')
|
||||
->select('a.lang_code AS lang_code')
|
||||
->from('#__languages AS a');
|
||||
|
||||
$db->setQuery($query);
|
||||
$langs = $db->loadObjectList();
|
||||
foreach ($langs as $lang)
|
||||
{
|
||||
if ($language == $lang->lang_code)
|
||||
{
|
||||
$link .= '&lang='.$lang->sef;
|
||||
$needles['language'] = $language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($item = self::_findItem($needles))
|
||||
{
|
||||
$link .= '&Itemid='.$item;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Create the link
|
||||
if ($category)
|
||||
{
|
||||
$catids = array_reverse($category->getPath());
|
||||
$needles['category'] = $catids;
|
||||
$needles['categories'] = $catids;
|
||||
|
||||
if ($item = self::_findItem($needles))
|
||||
{
|
||||
$link .= '&Itemid='.$item;
|
||||
}
|
||||
elseif ($item = self::_findItem())
|
||||
{
|
||||
$link .= '&Itemid='.$item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
public static function getFormRoute($id)
|
||||
{
|
||||
//Create the link
|
||||
if ($id)
|
||||
{
|
||||
$link = 'index.php?option=com_content&task=article.edit&a_id='. $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$link = 'index.php?option=com_content&task=article.edit&a_id=0';
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
protected static function _findItem($needles = null)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$menus = $app->getMenu('site');
|
||||
$language = isset($needles['language']) ? $needles['language'] : '*';
|
||||
|
||||
// Prepare the reverse lookup array.
|
||||
if (!isset(self::$lookup[$language]))
|
||||
{
|
||||
self::$lookup[$language] = array();
|
||||
|
||||
$component = JComponentHelper::getComponent('com_content');
|
||||
|
||||
$attributes = array('component_id');
|
||||
$values = array($component->id);
|
||||
|
||||
if ($language != '*')
|
||||
{
|
||||
$attributes[] = 'language';
|
||||
$values[] = array($needles['language'], '*');
|
||||
}
|
||||
|
||||
$items = $menus->getItems($attributes, $values);
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
if (isset($item->query) && isset($item->query['view']))
|
||||
{
|
||||
$view = $item->query['view'];
|
||||
if (!isset(self::$lookup[$language][$view]))
|
||||
{
|
||||
self::$lookup[$language][$view] = array();
|
||||
}
|
||||
if (isset($item->query['id'])) {
|
||||
|
||||
// here it will become a bit tricky
|
||||
// language != * can override existing entries
|
||||
// language == * cannot override existing entries
|
||||
if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
|
||||
{
|
||||
self::$lookup[$language][$view][$item->query['id']] = $item->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($needles)
|
||||
{
|
||||
foreach ($needles as $view => $ids)
|
||||
{
|
||||
if (isset(self::$lookup[$language][$view]))
|
||||
{
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
if (isset(self::$lookup[$language][$view][(int) $id]))
|
||||
{
|
||||
return self::$lookup[$language][$view][(int) $id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$active = $menus->getActive();
|
||||
if ($active && $active->component == 'com_content' && ($active->language == '*' || !JLanguageMultilang::isEnabled()))
|
||||
{
|
||||
return $active->id;
|
||||
}
|
||||
|
||||
// if not found, return language specific home link
|
||||
$default = $menus->getDefault($language);
|
||||
return !empty($default->id) ? $default->id : null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user