- md5
- 1eb5fd59e712e949c2092f9d06decfc7
- sha1
- b77ba70c2cd0982058d32868b700f98a011192e6
- sha256
- 8673f3eccae62d74e8c45d1583559616e9695edd67843afebb666a6aef6e98cf
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Installer\Administrator\Model;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Utilities\ArrayHelper;
/**
* Extension Manager Abstract Extension Model.
*
* @since 1.5
*/
class InstallerModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
*
* @see \Joomla\CMS\MVC\Model\ListModel
* @since 1.6
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'name',
'client_id',
'client', 'client_translated',
'enabled',
'type', 'type_translated',
'folder', 'folder_translated',
'extension_id',
);
}
parent::__construct($config, $factory);
}
/**
* Returns an object list
*
* @param DatabaseQuery $query The query
* @param int $limitstart Offset
* @param int $limit The number of records
*
* @return array
*/
protected function _getList($query, $limitstart = 0, $limit = 0)
{
$listOrder = $this->getState('list.ordering', 'name');
$listDirn = $this->getState('list.direction', 'asc');
// Replace slashes so preg_match will work
$search = $this->getState('filter.search');
$search = str_replace('/', ' ', $search);
$db = $this->getDbo();
// Define which fields have to be processed in a custom way because of translation.
$customOrderFields = array('name', 'client_translated', 'type_translated', 'folder_translated');
// Process searching, ordering and pagination for fields that need to be translated.
if (in_array($listOrder, $customOrderFields) || (!empty($search) && stripos($search, 'id:') !== 0))
{
// Get results from database and translate them.
$db->setQuery($query);
$result = $db->loadObjectList();
$this->translate($result);
// Process searching.
if (!empty($search) && stripos($search, 'id:') !== 0)
{
$escapedSearchString = $this->refineSearchStringToRegex($search, '/');
// By default search only the extension name field.
$searchFields = array('name');
// If in update sites view search also in the update site name field.
if ($this instanceof Updatesites)
{
$searchFields[] = 'update_site_name';
}
foreach ($result as $i => $item)
{
// Check if search string exists in any of the fields to be searched.
$found = 0;
foreach ($searchFields as $key => $field)
{
if (!$found && preg_match('/' . $escapedSearchString . '/i', $item->{$field}))
{
$found = 1;
}
}
// If search string was not found in any of the fields searched remove it from results array.
if (!$found)
{
unset($result[$i]);
}
}
}
// Process ordering.
// Sort array object by selected ordering and selected direction. Sort is case insensitive and using locale sorting.
$result = ArrayHelper::sortObjects($result, $listOrder, strtolower($listDirn) == 'desc' ? -1 : 1, false, true);
// Process pagination.
$total = count($result);
$this->cache[$this->getStoreId('getTotal')] = $total;
if ($total <= $limitstart)
{
$limitstart = 0;
$this->setState('list.limitstart', 0);
}
return array_slice($result, $limitstart, $limit ?: null);
}
// Process searching, ordering and pagination for regular database fields.
$query->order($db->quoteName($listOrder) . ' ' . $db->escape($listDirn));
$result = parent::_getList($query, $limitstart, $limit);
$this->translate($result);
return $result;
}
/**
* Translate a list of objects
*
* @param array $items The array of objects
*
* @return array The array of translated objects
*/
protected function translate(&$items)
{
$lang = Factory::getLanguage();
foreach ($items as &$item)
{
if (strlen($item->manifest_cache) && $data = json_decode($item->manifest_cache))
{
foreach ($data as $key => $value)
{
if ($key == 'type')
{
// Ignore the type field
continue;
}
$item->$key = $value;
}
}
$item->author_info = @$item->authorEmail . '<br>' . @$item->authorUrl;
$item->client = Text::_([0 => 'JSITE', 1 => 'JADMINISTRATOR', 3 => 'JAPI'][$item->client_id] ?? 'JSITE');
$item->client_translated = $item->client;
$item->type_translated = Text::_('COM_INSTALLER_TYPE_' . strtoupper($item->type));
$item->folder_translated = @$item->folder ? $item->folder : Text::_('COM_INSTALLER_TYPE_NONAPPLICABLE');
$path = $item->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE;
switch ($item->type)
{
case 'component':
$extension = $item->element;
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;
$lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source);
break;
case 'file':
$extension = 'files_' . $item->element;
$lang->load("$extension.sys", JPATH_SITE);
break;
case 'library':
$parts = explode('/', $item->element);
$vendor = (isset($parts[1]) ? $parts[0] : null);
$extension = 'lib_' . ($vendor ? implode('_', $parts) : $item->element);
if (!$lang->load("$extension.sys", $path))
{
$source = $path . '/libraries/' . ($vendor ? $vendor . '/' . $parts[1] : $item->element);
$lang->load("$extension.sys", $source);
}
break;
case 'module':
$extension = $item->element;
$source = $path . '/modules/' . $extension;
$lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source);
break;
case 'plugin':
$extension = 'plg_' . $item->folder . '_' . $item->element;
$source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element;
$lang->load("$extension.sys", JPATH_ADMINISTRATOR) || $lang->load("$extension.sys", $source);
break;
case 'template':
$extension = 'tpl_' . $item->element;
$source = $path . '/templates/' . $item->element;
$lang->load("$extension.sys", $path) || $lang->load("$extension.sys", $source);
break;
case 'package':
default:
$extension = $item->element;
$lang->load("$extension.sys", JPATH_SITE);
break;
}
// Translate the extension name if possible
$item->name = Text::_($item->name);
settype($item->description, 'string');
if (!in_array($item->type, array('language')))
{
$item->description = Text::_($item->description);
}
}
}
}
No other release has this exact content. See every version of this file.