[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_content 6 * 7 * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Content\Site\Helper; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Associations; 15 use Joomla\CMS\Language\LanguageHelper; 16 use Joomla\CMS\Language\Multilanguage; 17 use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Content Component Association Helper 25 * 26 * @since 3.0 27 */ 28 abstract class AssociationHelper extends CategoryAssociationHelper 29 { 30 /** 31 * Method to get the associations for a given item 32 * 33 * @param integer $id Id of the item 34 * @param string $view Name of the view 35 * @param string $layout View layout 36 * 37 * @return array Array of associations for the item 38 * 39 * @since 3.0 40 */ 41 public static function getAssociations($id = 0, $view = null, $layout = null) 42 { 43 $jinput = Factory::getApplication()->input; 44 $view = $view ?? $jinput->get('view'); 45 $component = $jinput->getCmd('option'); 46 $id = empty($id) ? $jinput->getInt('id') : $id; 47 48 if ($layout === null && $jinput->get('view') == $view && $component == 'com_content') { 49 $layout = $jinput->get('layout', '', 'string'); 50 } 51 52 if ($view === 'article') { 53 if ($id) { 54 $user = Factory::getUser(); 55 $groups = implode(',', $user->getAuthorisedViewLevels()); 56 $db = Factory::getDbo(); 57 $advClause = array(); 58 59 // Filter by user groups 60 $advClause[] = 'c2.access IN (' . $groups . ')'; 61 62 // Filter by current language 63 $advClause[] = 'c2.language != ' . $db->quote(Factory::getLanguage()->getTag()); 64 65 if (!$user->authorise('core.edit.state', 'com_content') && !$user->authorise('core.edit', 'com_content')) { 66 // Filter by start and end dates. 67 $date = Factory::getDate(); 68 69 $nowDate = $db->quote($date->toSql()); 70 71 $advClause[] = '(c2.publish_up IS NULL OR c2.publish_up <= ' . $nowDate . ')'; 72 $advClause[] = '(c2.publish_down IS NULL OR c2.publish_down >= ' . $nowDate . ')'; 73 74 // Filter by published 75 $advClause[] = 'c2.state = 1'; 76 } 77 78 $associations = Associations::getAssociations( 79 'com_content', 80 '#__content', 81 'com_content.item', 82 $id, 83 'id', 84 'alias', 85 'catid', 86 $advClause 87 ); 88 89 $return = array(); 90 91 foreach ($associations as $tag => $item) { 92 $return[$tag] = RouteHelper::getArticleRoute($item->id, (int) $item->catid, $item->language, $layout); 93 } 94 95 return $return; 96 } 97 } 98 99 if ($view === 'category' || $view === 'categories') { 100 return self::getCategoryAssociations($id, 'com_content', $layout); 101 } 102 103 return array(); 104 } 105 106 /** 107 * Method to display in frontend the associations for a given article 108 * 109 * @param integer $id Id of the article 110 * 111 * @return array An array containing the association URL and the related language object 112 * 113 * @since 3.7.0 114 */ 115 public static function displayAssociations($id) 116 { 117 $return = array(); 118 119 if ($associations = self::getAssociations($id, 'article')) { 120 $levels = Factory::getUser()->getAuthorisedViewLevels(); 121 $languages = LanguageHelper::getLanguages(); 122 123 foreach ($languages as $language) { 124 // Do not display language when no association 125 if (empty($associations[$language->lang_code])) { 126 continue; 127 } 128 129 // Do not display language without frontend UI 130 if (!array_key_exists($language->lang_code, LanguageHelper::getInstalledLanguages(0))) { 131 continue; 132 } 133 134 // Do not display language without specific home menu 135 if (!array_key_exists($language->lang_code, Multilanguage::getSiteHomePages())) { 136 continue; 137 } 138 139 // Do not display language without authorized access level 140 if (isset($language->access) && $language->access && !in_array($language->access, $levels)) { 141 continue; 142 } 143 144 $return[$language->lang_code] = array('item' => $associations[$language->lang_code], 'language' => $language); 145 } 146 } 147 148 return $return; 149 } 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |