- md5
- 245d2574cd195e6c992f779a45b20b76
- sha1
- a4c8dd72c69f53f8fccef415c49ae14b65a28fa0
- sha256
- 5127c9e840143d1a6959b4c894d7acee0186c7fe095388e9b671810ce89a930f
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
/**
* @package Joomla.API
* @subpackage com_plugins
*
* @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\Plugins\Api\Controller;
\defined('_JEXEC') or die;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\CMS\MVC\Controller\Exception;
use Joomla\CMS\Router\Exception\RouteNotFoundException;
use Joomla\String\Inflector;
use Tobscure\JsonApi\Exception\InvalidParameterException;
/**
* The plugins controller
*
* @since 4.0.0
*/
class PluginsController extends ApiController
{
/**
* The content type of the item.
*
* @var string
* @since 4.0.0
*/
protected $contentType = 'plugins';
/**
* The default view for the display method.
*
* @var string
*
* @since 3.0
*/
protected $default_view = 'plugins';
/**
* Method to edit an existing record.
*
* @return static A \JControllerLegacy object to support chaining.
*
* @since 4.0.0
*/
public function edit()
{
$recordId = $this->input->getInt('id');
if (!$recordId)
{
throw new Exception\ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
}
$data = json_decode($this->input->json->getRaw(), true);
foreach ($data as $key => $value)
{
if (!in_array($key, ['enabled', 'access', 'ordering']))
{
throw new InvalidParameterException("Invalid parameter {$key}.", 400);
}
}
/** @var \Joomla\Component\Plugins\Administrator\Model\PluginModel $model */
$model = $this->getModel(Inflector::singularize($this->contentType), '', ['ignore_request' => true]);
if (!$model)
{
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
}
$item = $model->getItem($recordId);
if (!isset($item->extension_id))
{
throw new RouteNotFoundException('Item does not exist');
}
$data['folder'] = $item->folder;
$data['element'] = $item->element;
$this->input->set('data', $data);
return parent::edit();
}
/**
* Plugin list view with filtering of data
*
* @return static A BaseController object to support chaining.
*
* @since 4.0.0
*/
public function displayList()
{
$apiFilterInfo = $this->input->get('filter', [], 'array');
$filter = InputFilter::getInstance();
if (array_key_exists('element', $apiFilterInfo))
{
$this->modelState->set('filter.element', $filter->clean($apiFilterInfo['element'], 'STRING'));
}
if (array_key_exists('status', $apiFilterInfo))
{
$this->modelState->set('filter.enabled', $filter->clean($apiFilterInfo['status'], 'INT'));
}
if (array_key_exists('search', $apiFilterInfo))
{
$this->modelState->set('filter.search', $filter->clean($apiFilterInfo['search'], 'STRING'));
}
if (array_key_exists('type', $apiFilterInfo))
{
$this->modelState->set('filter.folder', $filter->clean($apiFilterInfo['type'], 'STRING'));
}
return parent::displayList();
}
}
No other release has this exact content. See every version of this file.