[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_installer 6 * 7 * @copyright (C) 2006 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\Installer\Administrator\Model; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\MVC\Factory\MVCFactoryInterface; 16 use Joomla\CMS\MVC\Model\ListModel; 17 use Joomla\Database\DatabaseQuery; 18 use Joomla\Utilities\ArrayHelper; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Extension Manager Abstract Extension Model. 26 * 27 * @since 1.5 28 */ 29 class InstallerModel extends ListModel 30 { 31 /** 32 * Constructor. 33 * 34 * @param array $config An optional associative array of configuration settings. 35 * @param MVCFactoryInterface $factory The factory. 36 * 37 * @see \Joomla\CMS\MVC\Model\ListModel 38 * @since 1.6 39 */ 40 public function __construct($config = array(), MVCFactoryInterface $factory = null) 41 { 42 if (empty($config['filter_fields'])) { 43 $config['filter_fields'] = array( 44 'name', 45 'client_id', 46 'client', 'client_translated', 47 'enabled', 48 'type', 'type_translated', 49 'folder', 'folder_translated', 50 'extension_id', 51 'creationDate', 52 ); 53 } 54 55 parent::__construct($config, $factory); 56 } 57 58 /** 59 * Returns an object list 60 * 61 * @param DatabaseQuery $query The query 62 * @param int $limitstart Offset 63 * @param int $limit The number of records 64 * 65 * @return array 66 */ 67 protected function _getList($query, $limitstart = 0, $limit = 0) 68 { 69 $listOrder = $this->getState('list.ordering', 'name'); 70 $listDirn = $this->getState('list.direction', 'asc'); 71 72 // Replace slashes so preg_match will work 73 $search = $this->getState('filter.search'); 74 $search = str_replace('/', ' ', $search); 75 $db = $this->getDatabase(); 76 77 // Define which fields have to be processed in a custom way because of translation. 78 $customOrderFields = array('name', 'client_translated', 'type_translated', 'folder_translated', 'creationDate'); 79 80 // Process searching, ordering and pagination for fields that need to be translated. 81 if (in_array($listOrder, $customOrderFields) || (!empty($search) && stripos($search, 'id:') !== 0)) { 82 // Get results from database and translate them. 83 $db->setQuery($query); 84 $result = $db->loadObjectList(); 85 $this->translate($result); 86 87 // Process searching. 88 if (!empty($search) && stripos($search, 'id:') !== 0) { 89 $escapedSearchString = $this->refineSearchStringToRegex($search, '/'); 90 91 // By default search only the extension name field. 92 $searchFields = array('name'); 93 94 // If in update sites view search also in the update site name field. 95 if ($this instanceof UpdatesitesModel) { 96 $searchFields[] = 'update_site_name'; 97 } 98 99 foreach ($result as $i => $item) { 100 // Check if search string exists in any of the fields to be searched. 101 $found = 0; 102 103 foreach ($searchFields as $key => $field) { 104 if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field})) { 105 $found = 1; 106 } 107 } 108 109 // If search string was not found in any of the fields searched remove it from results array. 110 if (!$found) { 111 unset($result[$i]); 112 } 113 } 114 } 115 116 // Process ordering. 117 // Sort array object by selected ordering and selected direction. Sort is case insensitive and using locale sorting. 118 $result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true); 119 120 // Process pagination. 121 $total = count($result); 122 $this->cache[$this->getStoreId('getTotal')] = $total; 123 124 if ($total <= $limitstart) { 125 $limitstart = 0; 126 $this->setState('list.limitstart', 0); 127 } 128 129 return array_slice($result, $limitstart, $limit ?: null); 130 } 131 132 // Process searching, ordering and pagination for regular database fields. 133 $query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn)); 134 $result = parent::_getList($query, $limitstart, $limit); 135 $this->translate($result); 136 137 return $result; 138 } 139 140 /** 141 * Translate a list of objects 142 * 143 * @param array $items The array of objects 144 * 145 * @return array The array of translated objects 146 */ 147 protected function translate(&$items) 148 { 149 $lang = Factory::getLanguage(); 150 151 foreach ($items as &$item) { 152 if (strlen($item->manifest_cache) && $data = json_decode($item->manifest_cache)) { 153 foreach ($data as $key => $value) { 154 if ($key == 'type') { 155 // Ignore the type field 156 continue; 157 } 158 159 $item->$key = $value; 160 } 161 } 162 163 $item->author_info = @$item->authorEmail . '<br>' . @$item->authorUrl; 164 $item->client = Text::_([0 => 'JSITE', 1 => 'JADMINISTRATOR', 3 => 'JAPI'][$item->client_id] ?? 'JSITE'); 165 $item->client_translated = $item->client; 166 $item->type_translated = Text::_('COM_INSTALLER_TYPE_' . strtoupper($item->type)); 167 $item->folder_translated = @$item->folder ? $item->folder : Text::_('COM_INSTALLER_TYPE_NONAPPLICABLE'); 168 169 $path = $item->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE; 170 171 switch ($item->type) { 172 case 'component': 173 $extension = $item->element; 174 $source = JPATH_ADMINISTRATOR . '/components/' . $extension; 175 $lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source); 176 break; 177 case 'file': 178 $extension = 'files_' . $item->element; 179 $lang->load("$extension.sys", JPATH_SITE); 180 break; 181 case 'library': 182 $parts = explode('/', $item->element); 183 $vendor = (isset($parts[1]) ? $parts[0] : null); 184 $extension = 'lib_' . ($vendor ? implode('_', $parts) : $item->element); 185 186 if (!$lang->load("$extension.sys", $path)) { 187 $source = $path . '/libraries/' . ($vendor ? $vendor . '/' . $parts[1] : $item->element); 188 $lang->load("$extension.sys", $source); 189 } 190 break; 191 case 'module': 192 $extension = $item->element; 193 $source = $path . '/modules/' . $extension; 194 $lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source); 195 break; 196 case 'plugin': 197 $extension = 'plg_' . $item->folder . '_' . $item->element; 198 $source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element; 199 $lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source); 200 break; 201 case 'template': 202 $extension = 'tpl_' . $item->element; 203 $source = $path . '/templates/' . $item->element; 204 $lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source); 205 break; 206 case 'package': 207 default: 208 $extension = $item->element; 209 $lang->load("$extension.sys", JPATH_SITE); 210 break; 211 } 212 213 // Translate the extension name if possible 214 $item->name = Text::_($item->name); 215 216 settype($item->description, 'string'); 217 218 if (!in_array($item->type, array('language'))) { 219 $item->description = Text::_($item->description); 220 } 221 } 222 } 223 }
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 |