- md5
- 15e5ca1bdc2dddb435e1e641e4f7cad4
- sha1
- 6d6565a6fbe04dc0826a3536d5c26f95ddc47294
- sha256
- ad956dc24a2ed378b6549b717af8526ca7e6fc73e822dca5f63f1746197a47ee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
<?php
/**
* @package Joomla.Site
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Site\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
\JLoader::register('ContentHelperRoute', JPATH_SITE . '/components/com_content/helpers/route.php');
/**
* Content Component Association Helper
*
* @since 3.0
*/
abstract class AssociationHelper extends CategoryAssociationHelper
{
/**
* Cached array of the content item id.
*
* @var array
* @since 4.0.0
*/
protected static $filters = array();
/**
* 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)
{
$jinput = Factory::getApplication()->input;
$view = $view ?? $jinput->get('view');
$id = empty($id) ? $jinput->getInt('id') : $id;
$user = Factory::getUser();
$groups = $user->getAuthorisedViewLevels();
if ($view === 'article')
{
if ($id)
{
if (!isset(static::$filters[$id]))
{
$associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $id);
$return = array();
foreach ($associations as $tag => $item)
{
if ($item->language != Factory::getLanguage()->getTag())
{
$arrId = explode(':', $item->id);
$assocId = $arrId[0];
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('state'))
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' = ' . (int) $assocId)
->whereIn($db->qn('access'), $groups);
$db->setQuery($query);
$result = (int) $db->loadResult();
if ($result > 0)
{
$return[$tag] = \ContentHelperRoute::getArticleRoute((int) $item->id, (int) $item->catid, $item->language);
}
}
static::$filters[$id] = $return;
}
if (count($associations) === 0)
{
static::$filters[$id] = array();
}
}
return static::$filters[$id];
}
}
if ($view === 'category' || $view === 'categories')
{
return self::getCategoryAssociations($id, 'com_content');
}
return array();
}
/**
* Method to display in frontend the associations for a given article
*
* @param integer $id Id of the article
*
* @return array An array containing the association URL and the related language object
*
* @since 3.7.0
*/
public static function displayAssociations($id)
{
$return = array();
if ($associations = self::getAssociations($id, 'article'))
{
$levels = Factory::getUser()->getAuthorisedViewLevels();
$languages = LanguageHelper::getLanguages();
foreach ($languages as $language)
{
// Do not display language when no association
if (empty($associations[$language->lang_code]))
{
continue;
}
// Do not display language without frontend UI
if (!array_key_exists($language->lang_code, LanguageHelper::getInstalledLanguages(0)))
{
continue;
}
// Do not display language without specific home menu
if (!array_key_exists($language->lang_code, Multilanguage::getSiteHomePages()))
{
continue;
}
// Do not display language without authorized access level
if (isset($language->access) && $language->access && !in_array($language->access, $levels))
{
continue;
}
$return[$language->lang_code] = array('item' => $associations[$language->lang_code], 'language' => $language);
}
}
return $return;
}
}
No other release has this exact content. See every version of this file.