diff --git a/administrator/components/com_fields/controller.php b/administrator/components/com_fields/Controller/Controller.php similarity index 73% rename from administrator/components/com_fields/controller.php rename to administrator/components/com_fields/Controller/Controller.php index b3bbeed9ff8ec..2200b0c66911b 100644 --- a/administrator/components/com_fields/controller.php +++ b/administrator/components/com_fields/Controller/Controller.php @@ -6,6 +6,8 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Controller; + defined('_JEXEC') or die; /** @@ -13,7 +15,7 @@ * * @since 3.7.0 */ -class FieldsController extends JControllerLegacy +class Controller extends \Joomla\CMS\Controller\Controller { /** * The default view. @@ -31,9 +33,9 @@ class FieldsController extends JControllerLegacy * you will need to override it in your own controllers. * * @param boolean $cachable If true, the view output will be cached - * @param array|bool $urlparams An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()} + * @param array|bool $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()} * - * @return JControllerLegacy|boolean A JControllerLegacy object to support chaining. + * @return Controller|boolean A Controller object to support chaining. * * @since 3.7.0 */ @@ -47,9 +49,9 @@ public function display($cachable = false, $urlparams = false) if ($vName == 'field' && !$this->checkEditId('com_fields.edit.field', $id)) { // Somehow the person just went to the form - we don't allow that. - $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); + $this->setError(\JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); - $this->setRedirect(JRoute::_('index.php?option=com_fields&view=fields&context=' . $this->input->get('context'), false)); + $this->setRedirect(\JRoute::_('index.php?option=com_fields&view=fields&context=' . $this->input->get('context'), false)); return false; } diff --git a/administrator/components/com_fields/controllers/field.php b/administrator/components/com_fields/Controller/Field.php similarity index 72% rename from administrator/components/com_fields/controllers/field.php rename to administrator/components/com_fields/Controller/Field.php index d2205e87d837a..26a3816109ffe 100644 --- a/administrator/components/com_fields/controllers/field.php +++ b/administrator/components/com_fields/Controller/Field.php @@ -6,8 +6,13 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Controller\Form; +use Joomla\CMS\Model\Model; +use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; use Joomla\Registry\Registry; /** @@ -15,7 +20,7 @@ * * @since 3.7.0 */ -class FieldsControllerField extends JControllerForm +class Field extends Form { private $internalContext; @@ -31,18 +36,23 @@ class FieldsControllerField extends JControllerForm protected $text_prefix = 'COM_FIELDS_FIELD'; /** - * Class constructor. + * Constructor. * - * @param array $config A named array of configuration variables. + * @param array $config An optional associative array of configuration settings. + * Recognized key values include 'name', 'default_task', 'model_path', and + * 'view_path' (this list is not meant to be comprehensive). + * @param MvcFactoryInterface $factory The factory. + * @param CmsApplication $app The JApplication for the dispatcher + * @param \JInput $input Input * * @since 3.7.0 */ - public function __construct($config = array()) + public function __construct($config = array(), MvcFactoryInterface $factory = null, $app = null, $input = null) { - parent::__construct($config); + parent::__construct($config, $factory, $app, $input); - $this->internalContext = JFactory::getApplication()->getUserStateFromRequest('com_fields.fields.context', 'context', 'com_content.article', 'CMD'); - $parts = FieldsHelper::extract($this->internalContext); + $this->internalContext = \JFactory::getApplication()->getUserStateFromRequest('com_fields.fields.context', 'context', 'com_content.article', 'CMD'); + $parts = \FieldsHelper::extract($this->internalContext); $this->component = $parts ? $parts[0] : null; } @@ -55,12 +65,12 @@ public function __construct($config = array()) */ public function storeform() { - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN')); - $app = JFactory::getApplication(); + $app = \JFactory::getApplication(); $data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array'); - $parts = FieldsHelper::extract($this->input->getCmd('context')); + $parts = \FieldsHelper::extract($this->input->getCmd('context')); if ($parts) { @@ -75,7 +85,7 @@ public function storeform() $redirectUrl = base64_decode($this->input->get->getBase64('return')); // Don't redirect to an external URL. - If (!JUri::isInternal($redirectUrl)) + If (!\JUri::isInternal($redirectUrl)) { $redirectUrl = 'index.php'; } @@ -95,7 +105,7 @@ public function storeform() */ protected function allowAdd($data = array()) { - return JFactory::getUser()->authorise('core.create', $this->component); + return \JFactory::getUser()->authorise('core.create', $this->component); } /** @@ -106,12 +116,12 @@ protected function allowAdd($data = array()) * * @return boolean * - * @since 1.6 + * @since 3.7.0 */ protected function allowEdit($data = array(), $key = 'id') { $recordId = (int) isset($data[$key]) ? $data[$key] : 0; - $user = JFactory::getUser(); + $user = \JFactory::getUser(); // Check general edit permission first. if ($user->authorise('core.edit', $this->component)) @@ -154,7 +164,7 @@ protected function allowEdit($data = array(), $key = 'id') */ public function batch($model = null) { - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Field'); @@ -195,14 +205,14 @@ protected function getRedirectToListAppend() /** * Function that allows child controller access to model data after the data has been saved. * - * @param JModelLegacy $model The data model object. - * @param array $validData The validated data. + * @param Model $model The data model object. + * @param array $validData The validated data. * * @return void * * @since 3.7.0 */ - protected function postSaveHook(JModelLegacy $model, $validData = array()) + protected function postSaveHook(Model $model, $validData = array()) { $item = $model->getItem(); diff --git a/administrator/components/com_fields/controllers/fields.php b/administrator/components/com_fields/Controller/Fields.php similarity index 57% rename from administrator/components/com_fields/controllers/fields.php rename to administrator/components/com_fields/Controller/Fields.php index 5d98d5a14c3b3..67fe17a7edd45 100644 --- a/administrator/components/com_fields/controllers/fields.php +++ b/administrator/components/com_fields/Controller/Fields.php @@ -6,14 +6,18 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Controller\Admin; + /** * Fields list controller class. * * @since 3.7.0 */ -class FieldsControllerFields extends JControllerAdmin +class Fields extends Admin { /** * The prefix to use with controller messages. @@ -27,15 +31,15 @@ class FieldsControllerFields extends JControllerAdmin /** * Proxy for getModel. * - * @param string $name The model name. Optional. - * @param string $prefix The class prefix. Optional. - * @param array $config The array of possible config values. Optional. + * @param string $name The name of the model. + * @param string $prefix The prefix for the PHP class name. + * @param array $config Array of configuration parameters. * - * @return FieldsModelField|boolean + * @return \Joomla\CMS\Model\Model * * @since 3.7.0 */ - public function getModel($name = 'Field', $prefix = 'FieldsModel', $config = array('ignore_request' => true)) + public function getModel($name = 'Field', $prefix = 'Administrator', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, $config); } diff --git a/administrator/components/com_fields/controllers/group.php b/administrator/components/com_fields/Controller/Group.php similarity index 70% rename from administrator/components/com_fields/controllers/group.php rename to administrator/components/com_fields/Controller/Group.php index aa3277e258838..b156fa3ade1b2 100644 --- a/administrator/components/com_fields/controllers/group.php +++ b/administrator/components/com_fields/Controller/Group.php @@ -6,8 +6,13 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Controller\Form; +use Joomla\CMS\Model\Model; +use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; use Joomla\Registry\Registry; /** @@ -15,7 +20,7 @@ * * @since 3.7.0 */ -class FieldsControllerGroup extends JControllerForm +class Group extends Form { /** * The prefix to use with controller messages. @@ -35,17 +40,22 @@ class FieldsControllerGroup extends JControllerForm private $component = ''; /** - * Class constructor. + * Constructor. * - * @param array $config A named array of configuration variables. + * @param array $config An optional associative array of configuration settings. + * Recognized key values include 'name', 'default_task', 'model_path', and + * 'view_path' (this list is not meant to be comprehensive). + * @param MvcFactoryInterface $factory The factory. + * @param CmsApplication $app The JApplication for the dispatcher + * @param \JInput $input Input * * @since 3.7.0 */ - public function __construct($config = array()) + public function __construct($config = array(), MvcFactoryInterface $factory = null, $app = null, $input = null) { - parent::__construct($config); + parent::__construct($config, $factory, $app, $input); - $parts = FieldsHelper::extract($this->input->getCmd('context')); + $parts = \FieldsHelper::extract($this->input->getCmd('context')); if ($parts) { @@ -64,7 +74,7 @@ public function __construct($config = array()) */ public function batch($model = null) { - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Group'); @@ -86,7 +96,7 @@ public function batch($model = null) */ protected function allowAdd($data = array()) { - return JFactory::getUser()->authorise('core.create', $this->component); + return \JFactory::getUser()->authorise('core.create', $this->component); } /** @@ -102,7 +112,7 @@ protected function allowAdd($data = array()) protected function allowEdit($data = array(), $key = 'parent_id') { $recordId = (int) isset($data[$key]) ? $data[$key] : 0; - $user = JFactory::getUser(); + $user = \JFactory::getUser(); // Check general edit permission first. if ($user->authorise('core.edit', $this->component)) @@ -137,14 +147,14 @@ protected function allowEdit($data = array(), $key = 'parent_id') /** * Function that allows child controller access to model data after the data has been saved. * - * @param JModelLegacy $model The data model object. - * @param array $validData The validated data. + * @param Model $model The data model object. + * @param array $validData The validated data. * * @return void * * @since 3.7.0 */ - protected function postSaveHook(JModelLegacy $model, $validData = array()) + protected function postSaveHook(Model $model, $validData = array()) { $item = $model->getItem(); diff --git a/administrator/components/com_fields/controllers/groups.php b/administrator/components/com_fields/Controller/Groups.php similarity index 57% rename from administrator/components/com_fields/controllers/groups.php rename to administrator/components/com_fields/Controller/Groups.php index 8b051a1fb13e9..466514ec448bd 100644 --- a/administrator/components/com_fields/controllers/groups.php +++ b/administrator/components/com_fields/Controller/Groups.php @@ -6,14 +6,18 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Controller\Admin; + /** * Groups list controller class. * * @since 3.7.0 */ -class FieldsControllerGroups extends JControllerAdmin +class Groups extends Admin { /** * The prefix to use with controller messages. @@ -27,15 +31,15 @@ class FieldsControllerGroups extends JControllerAdmin /** * Proxy for getModel. * - * @param string $name The model name. Optional. - * @param string $prefix The class prefix. Optional. - * @param array $config The array of possible config values. Optional. + * @param string $name The name of the model. + * @param string $prefix The prefix for the PHP class name. + * @param array $config Array of configuration parameters. * - * @return JModelLegacy|boolean Model object on success; otherwise false on failure. + * @return \Joomla\CMS\Model\Model * * @since 3.7.0 */ - public function getModel($name = 'Group', $prefix = 'FieldsModel', $config = array('ignore_request' => true)) + public function getModel($name = 'Group', $prefix = 'Administrator', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, $config); } diff --git a/administrator/components/com_fields/models/field.php b/administrator/components/com_fields/Model/Field.php similarity index 87% rename from administrator/components/com_fields/models/field.php rename to administrator/components/com_fields/Model/Field.php index 45debf58b2216..ebda14e616409 100644 --- a/administrator/components/com_fields/models/field.php +++ b/administrator/components/com_fields/Model/Field.php @@ -6,8 +6,14 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Model; + defined('_JEXEC') or die; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Model\Admin; +use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; +use Joomla\CMS\Plugin\PluginHelper; use Joomla\Registry\Registry; use Joomla\String\StringHelper; use Joomla\Utilities\ArrayHelper; @@ -17,7 +23,7 @@ * * @since 3.7.0 */ -class FieldsModelField extends JModelAdmin +class Field extends Admin { /** * @var null|string @@ -60,18 +66,19 @@ class FieldsModelField extends JModelAdmin private $valueCache = array(); /** - * Constructor. + * Constructor * - * @param array $config An optional associative array of configuration settings. + * @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request). + * @param MvcFactoryInterface $factory The factory. * - * @see JModelLegacy * @since 3.7.0 + * @throws \Exception */ - public function __construct($config = array()) + public function __construct($config = array(), MvcFactoryInterface $factory = null) { - parent::__construct($config); + parent::__construct($config, $factory); - $this->typeAlias = JFactory::getApplication()->input->getCmd('context', 'com_content.article') . '.field'; + $this->typeAlias = \JFactory::getApplication()->input->getCmd('context', 'com_content.article') . '.field'; } /** @@ -100,7 +107,7 @@ public function save($data) } // Alter the title for save as copy - $input = JFactory::getApplication()->input; + $input = \JFactory::getApplication()->input; if ($input->get('task') == 'save2copy') { @@ -126,7 +133,7 @@ public function save($data) } // Load the fields plugins, perhaps they want to do something - JPluginHelper::importPlugin('fields'); + PluginHelper::importPlugin('fields'); $message = $this->checkDefaultValue($data); @@ -166,7 +173,7 @@ public function save($data) $db->execute(); // Inset new assigned categories - $tupel = new stdClass; + $tupel = new \stdClass; $tupel->field_id = $id; foreach ($assignedCatIds as $catId) @@ -218,7 +225,7 @@ private function checkDefaultValue($data) return true; } - $types = FieldsHelper::getFieldTypes(); + $types = \FieldsHelper::getFieldTypes(); // Check if type exists if (!key_exists($data['type'], $types)) @@ -232,7 +239,7 @@ private function checkDefaultValue($data) if ($path) { // Add the lookup path for the rule - JFormHelper::addRulePath($path); + \JFormHelper::addRulePath($path); } // Create the fields object @@ -241,11 +248,11 @@ private function checkDefaultValue($data) $obj->fieldparams = new Registry(!empty($obj->fieldparams) ? $obj->fieldparams : array()); // Prepare the dom - $dom = new DOMDocument; - $node = $dom->appendChild(new DOMElement('form')); + $dom = new \DOMDocument; + $node = $dom->appendChild(new \DOMElement('form')); // Trigger the event to create the field dom node - JEventDispatcher::getInstance()->trigger('onCustomFieldsPrepareDom', array($obj, $node, new JForm($data['context']))); + \JEventDispatcher::getInstance()->trigger('onCustomFieldsPrepareDom', array($obj, $node, new \JForm($data['context']))); // Check if a node is created if (!$node->firstChild) @@ -257,7 +264,7 @@ private function checkDefaultValue($data) $type = $node->firstChild->getAttribute('validate') ? : $data['type']; // Load the rule - $rule = JFormHelper::loadRuleType($type); + $rule = \JFormHelper::loadRuleType($type); // When no rule exists, we allow the default value if (!$rule) @@ -271,9 +278,9 @@ private function checkDefaultValue($data) $result = $rule->test(simplexml_import_dom($node->firstChild), $data['default_value']); // Check if the test succeeded - return $result === true ? : JText::_('COM_FIELDS_FIELD_INVALID_DEFAULT_VALUE'); + return $result === true ? : \JText::_('COM_FIELDS_FIELD_INVALID_DEFAULT_VALUE'); } - catch (UnexpectedValueException $e) + catch (\UnexpectedValueException $e) { return $e->getMessage(); } @@ -284,7 +291,7 @@ private function checkDefaultValue($data) * * @param mixed $params The params. * - * @return stdClass Object on success, false on failure. + * @return \stdClass Object on success, false on failure. * * @since 3.7.0 */ @@ -321,7 +328,7 @@ public function getItem($pk = null) // Prime required properties. if (empty($result->id)) { - $result->context = JFactory::getApplication()->input->getCmd('context', $this->getState('field.context')); + $result->context = \JFactory::getApplication()->input->getCmd('context', $this->getState('field.context')); } if (property_exists($result, 'fieldparams')) @@ -342,11 +349,11 @@ public function getItem($pk = null) // Convert the created and modified dates to local user time for // display in the form. - $tz = new DateTimeZone(JFactory::getApplication()->get('offset')); + $tz = new \DateTimeZone(\JFactory::getApplication()->get('offset')); if ((int) $result->created_time) { - $date = new JDate($result->created_time); + $date = new \JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); @@ -358,7 +365,7 @@ public function getItem($pk = null) if ((int) $result->modified_time) { - $date = new JDate($result->modified_time); + $date = new \JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); @@ -379,20 +386,15 @@ public function getItem($pk = null) * @param string $prefix The class prefix. Optional. * @param array $options Configuration array for model. Optional. * - * @return JTable A JTable object + * @return Table A JTable object * * @since 3.7.0 - * @throws Exception + * @throws \Exception */ public function getTable($name = 'Field', $prefix = 'FieldsTable', $options = array()) { - if (strpos(JPATH_COMPONENT, 'com_fields') === false) - { - $this->addTablePath(JPATH_ADMINISTRATOR . '/components/com_fields/tables'); - } - // Default to text type - $table = JTable::getInstance($name, $prefix, $options); + $table = parent::getTable($name, $prefix, $options); $table->type = 'text'; return $table; @@ -474,20 +476,20 @@ public function delete(&$pks) * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * - * @return mixed A JForm object on success, false on failure + * @return mixed A \JForm object on success, false on failure * * @since 3.7.0 */ public function getForm($data = array(), $loadData = true) { $context = $this->getState('field.context'); - $jinput = JFactory::getApplication()->input; + $jinput = \JFactory::getApplication()->input; // A workaround to get the context into the model for save requests. if (empty($context) && isset($data['context'])) { $context = $data['context']; - $parts = FieldsHelper::extract($context); + $parts = \FieldsHelper::extract($context); $this->setState('field.context', $context); @@ -505,7 +507,7 @@ public function getForm($data = array(), $loadData = true) } // Load the fields plugin that they can add additional parameters to the form - JPluginHelper::importPlugin('fields'); + PluginHelper::importPlugin('fields'); // Get the form. $form = $this->loadForm( @@ -530,7 +532,7 @@ public function getForm($data = array(), $loadData = true) $fieldId = $jinput->get('id'); $assetKey = $this->state->get('field.component') . '.field.' . $fieldId; - if (!JFactory::getUser()->authorise('core.edit.state', $assetKey)) + if (!\JFactory::getUser()->authorise('core.edit.state', $assetKey)) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); @@ -566,7 +568,7 @@ public function setFieldValue($fieldId, $itemId, $value) } // Don't save the value when the user is not authorized to change it - if (!$field || !FieldsHelper::canEditFieldValue($field)) + if (!$field || !\FieldsHelper::canEditFieldValue($field)) { return false; } @@ -617,7 +619,7 @@ public function setFieldValue($fieldId, $itemId, $value) if ($needsInsert) { - $newObj = new stdClass; + $newObj = new \stdClass; $newObj->field_id = (int) $fieldId; $newObj->item_id = $itemId; @@ -632,7 +634,7 @@ public function setFieldValue($fieldId, $itemId, $value) if ($needsUpdate) { - $updateObj = new stdClass; + $updateObj = new \stdClass; $updateObj->field_id = (int) $fieldId; $updateObj->item_id = $itemId; @@ -780,9 +782,9 @@ protected function canDelete($record) return false; } - $parts = FieldsHelper::extract($record->context); + $parts = \FieldsHelper::extract($record->context); - return JFactory::getUser()->authorise('core.delete', $parts[0] . '.field.' . (int) $record->id); + return \JFactory::getUser()->authorise('core.delete', $parts[0] . '.field.' . (int) $record->id); } return false; @@ -800,8 +802,8 @@ protected function canDelete($record) */ protected function canEditState($record) { - $user = JFactory::getUser(); - $parts = FieldsHelper::extract($record->context); + $user = \JFactory::getUser(); + $parts = \FieldsHelper::extract($record->context); // Check for existing field. if (!empty($record->id)) @@ -821,7 +823,7 @@ protected function canEditState($record) */ protected function populateState() { - $app = JFactory::getApplication('administrator'); + $app = \JFactory::getApplication('administrator'); // Load the User state. $pk = $app->input->getInt('id'); @@ -829,7 +831,7 @@ protected function populateState() $context = $app->input->get('context', 'com_content.article'); $this->setState('field.context', $context); - $parts = FieldsHelper::extract($context); + $parts = \FieldsHelper::extract($context); // Extract the component name $this->setState('field.component', $parts[0]); @@ -838,7 +840,7 @@ protected function populateState() $this->setState('field.section', (count($parts) > 1) ? $parts[1] : null); // Load the parameters. - $params = JComponentHelper::getParams('com_fields'); + $params = ComponentHelper::getParams('com_fields'); $this->setState('params', $params); } @@ -866,7 +868,7 @@ protected function getReorderConditions($table) protected function loadFormData() { // Check the session for previously entered form data. - $app = JFactory::getApplication(); + $app = \JFactory::getApplication(); $data = $app->getUserState('com_fields.edit.field.data', array()); if (empty($data)) @@ -886,7 +888,7 @@ protected function loadFormData() $data->set('group_id', $app->input->getString('group_id', (!empty($filters['group_id']) ? $filters['group_id'] : null))); $data->set( 'access', - $app->input->getInt('access', (!empty($filters['access']) ? $filters['access'] : JFactory::getConfig()->get('access'))) + $app->input->getInt('access', (!empty($filters['access']) ? $filters['access'] : \JFactory::getConfig()->get('access'))) ); // Set the type if available from the request @@ -907,17 +909,17 @@ protected function loadFormData() /** * Method to allow derived classes to preprocess the form. * - * @param JForm $form A JForm object. + * @param \JForm $form A JForm object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * - * @see JFormField + * @see \JFormField * @since 3.7.0 - * @throws Exception if there is an error in the form event. + * @throws \Exception if there is an error in the form event. */ - protected function preprocessForm(JForm $form, $data, $group = 'content') + protected function preprocessForm(\JForm $form, $data, $group = 'content') { $component = $this->state->get('field.component'); $section = $this->state->get('field.section'); @@ -940,20 +942,20 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') // Allow to override the default value label and description through the plugin $key = 'PLG_FIELDS_' . strtoupper($dataObject->type) . '_DEFAULT_VALUE_LABEL'; - if (JFactory::getLanguage()->hasKey($key)) + if (\JFactory::getLanguage()->hasKey($key)) { $form->setFieldAttribute('default_value', 'label', $key); } $key = 'PLG_FIELDS_' . strtoupper($dataObject->type) . '_DEFAULT_VALUE_DESC'; - if (JFactory::getLanguage()->hasKey($key)) + if (\JFactory::getLanguage()->hasKey($key)) { $form->setFieldAttribute('default_value', 'description', $key); } } // Setting the context for the category field - $cat = JCategories::getInstance(str_replace('com_', '', $component)); + $cat = \JCategories::getInstance(str_replace('com_', '', $component)); if ($cat && $cat->get('root')->hasChildren()) { @@ -969,17 +971,17 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $form->setFieldAttribute('rules', 'component', $component); // Looking first in the component models/forms folder - $path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/models/forms/fields/' . $section . '.xml'); + $path = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/models/forms/fields/' . $section . '.xml'); if (file_exists($path)) { - $lang = JFactory::getLanguage(); + $lang = \JFactory::getLanguage(); $lang->load($component, JPATH_BASE, null, false, true); $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, true); if (!$form->loadFile($path, false)) { - throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); + throw new \Exception(\JText::_('JERROR_LOADFILE_FAILED')); } } @@ -999,7 +1001,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') */ protected function cleanCache($group = null, $client_id = 0) { - $context = JFactory::getApplication()->input->get('context'); + $context = \JFactory::getApplication()->input->get('context'); switch ($context) { @@ -1032,7 +1034,7 @@ protected function cleanCache($group = null, $client_id = 0) protected function batchCopy($value, $pks, $contexts) { // Set the variables - $user = JFactory::getUser(); + $user = \JFactory::getUser(); $table = $this->getTable(); $newIds = array(); $component = $this->state->get('filter.component'); @@ -1068,7 +1070,7 @@ protected function batchCopy($value, $pks, $contexts) } else { - $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); + $this->setError(\JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); return false; } @@ -1094,9 +1096,9 @@ protected function batchCopy($value, $pks, $contexts) protected function batchMove($value, $pks, $contexts) { // Set the variables - $user = JFactory::getUser(); + $user = \JFactory::getUser(); $table = $this->getTable(); - $context = explode('.', JFactory::getApplication()->getUserState('com_fields.fields.context')); + $context = explode('.', \JFactory::getApplication()->getUserState('com_fields.fields.context')); $value = (int) $value; foreach ($pks as $pk) @@ -1117,7 +1119,7 @@ protected function batchMove($value, $pks, $contexts) } else { - $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + $this->setError(\JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); return false; } diff --git a/administrator/components/com_fields/models/fields.php b/administrator/components/com_fields/Model/Fields.php similarity index 88% rename from administrator/components/com_fields/models/fields.php rename to administrator/components/com_fields/Model/Fields.php index ae656a222ad74..ef344f6b68581 100644 --- a/administrator/components/com_fields/models/fields.php +++ b/administrator/components/com_fields/Model/Fields.php @@ -6,8 +6,12 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Model; + defined('_JEXEC') or die; +use Joomla\CMS\Model\ListModel; +use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; @@ -16,17 +20,18 @@ * * @since 3.7.0 */ -class FieldsModelFields extends JModelList +class Fields extends ListModel { /** - * Constructor. + * Constructor * - * @param array $config An optional associative array of configuration settings. + * @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request). + * @param MvcFactoryInterface $factory The factory. * - * @see JModelLegacy * @since 3.7.0 + * @throws \Exception */ - public function __construct($config = array()) + public function __construct($config = array(), MvcFactoryInterface $factory = null) { if (empty($config['filter_fields'])) { @@ -51,7 +56,7 @@ public function __construct($config = array()) ); } - parent::__construct($config); + parent::__construct($config, $factory); } /** @@ -79,7 +84,7 @@ protected function populateState($ordering = null, $direction = null) $this->setState('filter.context', $context); // Split context into component and optional section - $parts = FieldsHelper::extract($context); + $parts = \FieldsHelper::extract($context); if ($parts) { @@ -117,7 +122,7 @@ protected function getStoreId($id = '') /** * Method to get a JDatabaseQuery object for retrieving the data set from a database. * - * @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. + * @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set. * * @since 3.7.0 */ @@ -126,8 +131,8 @@ protected function getListQuery() // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); - $user = JFactory::getUser(); - $app = JFactory::getApplication(); + $user = \JFactory::getUser(); + $app = \JFactory::getApplication(); // Select the required fields from the table. $query->select( @@ -182,12 +187,12 @@ protected function getListQuery() { $categories = (array) $categories; $categories = ArrayHelper::toInteger($categories); - $parts = FieldsHelper::extract($context); + $parts = \FieldsHelper::extract($context); if ($parts) { // Get the category - $cat = JCategories::getInstance(str_replace('com_', '', $parts[0])); + $cat = \JCategories::getInstance(str_replace('com_', '', $parts[0])); if ($cat) { @@ -214,40 +219,7 @@ protected function getListQuery() $categories = array_unique($categories); // Join over the assigned categories - $query->join('LEFT', $db->quoteName('#__fields_categories') . ' AS fc ON fc.field_id = a.id') - ->group( - array( - 'a.id', - 'a.title', - 'a.alias', - 'a.checked_out', - 'a.checked_out_time', - 'a.note', - 'a.state', - 'a.access', - 'a.created_time', - 'a.created_user_id', - 'a.ordering', - 'a.language', - 'a.fieldparams', - 'a.params', - 'a.type', - 'a.default_value', - 'a.context', - 'a.group_id', - 'a.label', - 'a.description', - 'a.required', - 'l.title', - 'l.image', - 'uc.name', - 'ag.title', - 'ua.name', - 'g.title', - 'g.access', - 'g.state' - ) - ); + $query->join('LEFT', $db->quoteName('#__fields_categories') . ' AS fc ON fc.field_id = a.id'); if (in_array('0', $categories)) { @@ -337,7 +309,7 @@ protected function getListQuery() $listOrdering = $this->state->get('list.ordering', 'a.ordering'); $orderDirn = $this->state->get('list.direction', 'DESC'); - $query->order($db->escape($listOrdering) . ' ' . $db->escape($orderDirn)); + $query->order($db->escape($listOrdering) . ' ' . $db->escape($orderDirn)); return $query; } @@ -352,7 +324,7 @@ protected function getListQuery() * @return array An array of results. * * @since 3.7.0 - * @throws RuntimeException + * @throws \RuntimeException */ protected function _getList($query, $limitstart = 0, $limit = 0) { @@ -376,7 +348,7 @@ protected function _getList($query, $limitstart = 0, $limit = 0) * @param array $data data * @param boolean $loadData load current data * - * @return JForm/false the JForm object or false + * @return \JForm/false the JForm object or false * * @since 3.7.0 */ @@ -403,7 +375,7 @@ public function getFilterForm($data = array(), $loadData = true) */ public function getGroups() { - $user = JFactory::getUser(); + $user = \JFactory::getUser(); $viewlevels = ArrayHelper::toInteger($user->getAuthorisedViewLevels()); $db = $this->getDbo(); diff --git a/administrator/components/com_fields/models/group.php b/administrator/components/com_fields/Model/Group.php similarity index 80% rename from administrator/components/com_fields/models/group.php rename to administrator/components/com_fields/Model/Group.php index 70d890db89acd..55086a7d92e72 100644 --- a/administrator/components/com_fields/models/group.php +++ b/administrator/components/com_fields/Model/Group.php @@ -6,14 +6,18 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Model; + defined('_JEXEC') or die; +use Joomla\CMS\Model\Admin; + /** * Group Model * * @since 3.7.0 */ -class FieldsModelGroup extends JModelAdmin +class Group extends Admin { /** * @var null|string @@ -44,7 +48,7 @@ class FieldsModelGroup extends JModelAdmin public function save($data) { // Alter the title for save as copy - $input = JFactory::getApplication()->input; + $input = \JFactory::getApplication()->input; // Save new group as unpublished if ($input->get('task') == 'save2copy') @@ -55,23 +59,6 @@ public function save($data) return parent::save($data); } - /** - * Method to get a table object, load it if necessary. - * - * @param string $name The table name. Optional. - * @param string $prefix The class prefix. Optional. - * @param array $options Configuration array for model. Optional. - * - * @return JTable A JTable object - * - * @since 3.7.0 - * @throws Exception - */ - public function getTable($name = 'Group', $prefix = 'FieldsTable', $options = array()) - { - return JTable::getInstance($name, $prefix, $options); - } - /** * Abstract method for getting the form from the model. * @@ -85,7 +72,7 @@ public function getTable($name = 'Group', $prefix = 'FieldsTable', $options = ar public function getForm($data = array(), $loadData = true) { $context = $this->getState('filter.context'); - $jinput = JFactory::getApplication()->input; + $jinput = \JFactory::getApplication()->input; if (empty($context) && isset($data['context'])) { @@ -113,7 +100,7 @@ public function getForm($data = array(), $loadData = true) $data['context'] = $context; } - if (!JFactory::getUser()->authorise('core.edit.state', $context . '.fieldgroup.' . $jinput->get('id'))) + if (!\JFactory::getUser()->authorise('core.edit.state', $context . '.fieldgroup.' . $jinput->get('id'))) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); @@ -143,7 +130,7 @@ protected function canDelete($record) return false; } - return JFactory::getUser()->authorise('core.delete', $record->context . '.fieldgroup.' . (int) $record->id); + return \JFactory::getUser()->authorise('core.delete', $record->context . '.fieldgroup.' . (int) $record->id); } /** @@ -158,7 +145,7 @@ protected function canDelete($record) */ protected function canEditState($record) { - $user = JFactory::getUser(); + $user = \JFactory::getUser(); // Check for existing fieldgroup. if (!empty($record->id)) @@ -183,14 +170,14 @@ protected function populateState() { parent::populateState(); - $context = JFactory::getApplication()->getUserStateFromRequest('com_fields.groups.context', 'context', 'com_fields', 'CMD'); + $context = \JFactory::getApplication()->getUserStateFromRequest('com_fields.groups.context', 'context', 'com_fields', 'CMD'); $this->setState('filter.context', $context); } /** * A protected method to get a set of ordering conditions. * - * @param JTable $table A JTable object. + * @param Table $table A Table object. * * @return array An array of conditions to add to ordering queries. * @@ -204,21 +191,21 @@ protected function getReorderConditions($table) /** * Method to preprocess the form. * - * @param JForm $form A JForm object. + * @param \JForm $form A JForm object. * @param mixed $data The data expected for the form. * @param string $group The name of the plugin group to import (defaults to "content"). * * @return void * - * @see JFormField + * @see \JFormField * @since 3.7.0 - * @throws Exception if there is an error in the form event. + * @throws \Exception if there is an error in the form event. */ - protected function preprocessForm(JForm $form, $data, $group = 'content') + protected function preprocessForm(\JForm $form, $data, $group = 'content') { parent::preprocessForm($form, $data, $group); - $parts = FieldsHelper::extract($this->state->get('filter.context')); + $parts = \FieldsHelper::extract($this->state->get('filter.context')); if ($parts) { @@ -237,7 +224,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') protected function loadFormData() { // Check the session for previously entered form data. - $app = JFactory::getApplication(); + $app = \JFactory::getApplication(); $data = $app->getUserState('com_fields.edit.group.data', array()); if (empty($data)) @@ -261,7 +248,7 @@ protected function loadFormData() ); $data->set( 'access', - $app->input->getInt('access', (!empty($filters['access']) ? $filters['access'] : JFactory::getConfig()->get('access'))) + $app->input->getInt('access', (!empty($filters['access']) ? $filters['access'] : \JFactory::getConfig()->get('access'))) ); } } @@ -291,11 +278,11 @@ public function getItem($pk = null) } // Convert the created and modified dates to local user time for display in the form. - $tz = new DateTimeZone(JFactory::getApplication()->get('offset')); + $tz = new \DateTimeZone(\JFactory::getApplication()->get('offset')); if ((int) $item->created) { - $date = new JDate($item->created); + $date = new \JDate($item->created); $date->setTimezone($tz); $item->created = $date->toSql(true); } @@ -306,7 +293,7 @@ public function getItem($pk = null) if ((int) $item->modified) { - $date = new JDate($item->modified); + $date = new \JDate($item->modified); $date->setTimezone($tz); $item->modified = $date->toSql(true); } @@ -331,7 +318,7 @@ public function getItem($pk = null) */ protected function cleanCache($group = null, $client_id = 0) { - $context = JFactory::getApplication()->input->get('context'); + $context = \JFactory::getApplication()->input->get('context'); parent::cleanCache($context); } diff --git a/administrator/components/com_fields/models/groups.php b/administrator/components/com_fields/Model/Groups.php similarity index 89% rename from administrator/components/com_fields/models/groups.php rename to administrator/components/com_fields/Model/Groups.php index beb82f0d2ad4b..43b15d2890ecd 100644 --- a/administrator/components/com_fields/models/groups.php +++ b/administrator/components/com_fields/Model/Groups.php @@ -6,8 +6,12 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Model; + defined('_JEXEC') or die; +use Joomla\CMS\Model\ListModel; +use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; use Joomla\Utilities\ArrayHelper; /** @@ -15,7 +19,7 @@ * * @since 3.7.0 */ -class FieldsModelGroups extends JModelList +class Groups extends ListModel { /** * Context string for the model type. This is used to handle uniqueness @@ -27,14 +31,15 @@ class FieldsModelGroups extends JModelList protected $context = 'com_fields.groups'; /** - * Constructor. + * Constructor * - * @param array $config An optional associative array of configuration settings. + * @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request). + * @param MvcFactoryInterface $factory The factory. * - * @see JModelLegacy * @since 3.7.0 + * @throws \Exception */ - public function __construct($config = array()) + public function __construct($config = array(), MvcFactoryInterface $factory = null) { if (empty($config['filter_fields'])) { @@ -54,7 +59,7 @@ public function __construct($config = array()) ); } - parent::__construct($config); + parent::__construct($config, $factory); } /** @@ -109,7 +114,7 @@ protected function getStoreId($id = '') /** * Method to get a JDatabaseQuery object for retrieving the data set from a database. * - * @return JDatabaseQuery A JDatabaseQuery object to retrieve the data set. + * @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set. * * @since 3.7.0 */ @@ -118,7 +123,7 @@ protected function getListQuery() // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); - $user = JFactory::getUser(); + $user = \JFactory::getUser(); // Select the required fields from the table. $query->select( diff --git a/administrator/components/com_fields/libraries/fieldslistplugin.php b/administrator/components/com_fields/Plugin/FieldsListPlugin.php similarity index 71% rename from administrator/components/com_fields/libraries/fieldslistplugin.php rename to administrator/components/com_fields/Plugin/FieldsListPlugin.php index d6ce3ca3e012b..1e5ae350c8157 100644 --- a/administrator/components/com_fields/libraries/fieldslistplugin.php +++ b/administrator/components/com_fields/Plugin/FieldsListPlugin.php @@ -6,9 +6,9 @@ * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ -defined('_JEXEC') or die; +namespace Joomla\Component\Fields\Administrator\Plugin; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); +defined('_JEXEC') or die; /** * Base plugin for all list based plugins @@ -20,15 +20,15 @@ class FieldsListPlugin extends FieldsPlugin /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * - * @param stdClass $field The field. - * @param DOMElement $parent The field node parent. - * @param JForm $form The form. + * @param \stdClass $field The field. + * @param \DOMElement $parent The field node parent. + * @param \JForm $form The form. * - * @return DOMElement + * @return \DOMElement * * @since 3.7.0 */ - public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) + public function onCustomFieldsPrepareDom($field, \DOMElement $parent, \JForm $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); @@ -41,8 +41,8 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form foreach ($this->getOptionsFromField($field) as $value => $name) { - $option = new DOMElement('option', htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); - $option->nodeValue = htmlspecialchars(JText::_($name), ENT_COMPAT, 'UTF-8'); + $option = new \DOMElement('option', htmlspecialchars($value, ENT_COMPAT, 'UTF-8')); + $option->nodeValue = htmlspecialchars(\JText::_($name), ENT_COMPAT, 'UTF-8'); $element = $fieldNode->appendChild($option); $element->setAttribute('value', $value); @@ -54,7 +54,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form /** * Returns an array of key values to put in a list from the given field. * - * @param stdClass $field The field. + * @param \stdClass $field The field. * * @return array * diff --git a/administrator/components/com_fields/libraries/fieldsplugin.php b/administrator/components/com_fields/Plugin/FieldsPlugin.php similarity index 80% rename from administrator/components/com_fields/libraries/fieldsplugin.php rename to administrator/components/com_fields/Plugin/FieldsPlugin.php index 84eca9a148988..0a219d231d97a 100644 --- a/administrator/components/com_fields/libraries/fieldsplugin.php +++ b/administrator/components/com_fields/Plugin/FieldsPlugin.php @@ -6,14 +6,19 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Plugin; + defined('_JEXEC') or die; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Plugin\PluginHelper; + /** * Abstract Fields Plugin * * @since 3.7.0 */ -abstract class FieldsPlugin extends JPlugin +abstract class FieldsPlugin extends CMSPlugin { protected $autoloadLanguage = true; @@ -31,7 +36,7 @@ public function onCustomFieldsGetTypes() // The root of the plugin $root = JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name; - foreach (JFolder::files($root . '/tmpl', '.php') as $layout) + foreach (\JFolder::files($root . '/tmpl', '.php') as $layout) { // Strip the extension $layout = str_replace('.php', '', $layout); @@ -50,12 +55,12 @@ public function onCustomFieldsGetTypes() // Needed attributes $data['type'] = $layout; - if (JFactory::getLanguage()->hasKey('PLG_FIELDS_' . $key . '_LABEL')) + if (\JFactory::getLanguage()->hasKey('PLG_FIELDS_' . $key . '_LABEL')) { - $data['label'] = JText::sprintf('PLG_FIELDS_' . $key . '_LABEL', strtolower($key)); + $data['label'] = \JText::sprintf('PLG_FIELDS_' . $key . '_LABEL', strtolower($key)); // Fix wrongly set parentheses in RTL languages - if (JFactory::getLanguage()->isRTL()) + if (\JFactory::getLanguage()->isRTL()) { $data['label'] = $data['label'] . '‎'; } @@ -91,9 +96,9 @@ public function onCustomFieldsGetTypes() /** * Prepares the field value. * - * @param string $context The context. - * @param stdclass $item The item. - * @param stdclass $field The field. + * @param string $context The context. + * @param \stdclass $item The item. + * @param \stdclass $field The field. * * @return string * @@ -112,7 +117,7 @@ public function onCustomFieldsPrepareField($context, $item, $field) $fieldParams->merge($field->fieldparams); // Get the path for the layout file - $path = JPluginHelper::getLayoutPath('fields', $field->type, $field->type); + $path = PluginHelper::getLayoutPath('fields', $field->type, $field->type); // Render the layout ob_start(); @@ -126,15 +131,15 @@ public function onCustomFieldsPrepareField($context, $item, $field) /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * - * @param stdClass $field The field. - * @param DOMElement $parent The field node parent. - * @param JForm $form The form. + * @param \stdClass $field The field. + * @param \DOMElement $parent The field node parent. + * @param \JForm $form The form. * - * @return DOMElement + * @return \DOMElement * * @since 3.7.0 */ - public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form) + public function onCustomFieldsPrepareDom($field, \DOMElement $parent, \JForm $form) { // Check if the field should be processed by us if (!$this->isTypeSupported($field->type)) @@ -142,7 +147,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form return null; } - $app = JFactory::getApplication(); + $app = \JFactory::getApplication(); // Detect if the field should be shown at all if ($field->params->get('show_on') == 1 && $app->isClient('administrator')) @@ -155,7 +160,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form } // Create the node - $node = $parent->appendChild(new DOMElement('field')); + $node = $parent->appendChild(new \DOMElement('field')); // Set the attributes $node->setAttribute('name', $field->name); @@ -189,7 +194,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form } // Check if it is allowed to edit the field - if (!FieldsHelper::canEditFieldValue($field)) + if (!\FieldsHelper::canEditFieldValue($field)) { $node->setAttribute('disabled', 'true'); } @@ -202,14 +207,14 @@ public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form * The form event. Load additional parameters when available into the field form. * Only when the type of the form is of interest. * - * @param JForm $form The form - * @param stdClass $data The data + * @param \JForm $form The form + * @param \stdClass $data The data * * @return void * * @since 3.7.0 */ - public function onContentPrepareForm(JForm $form, $data) + public function onContentPrepareForm(\JForm $form, $data) { // Check if the field form is calling us if (strpos($form->getName(), 'com_fields.field') !== 0) diff --git a/administrator/components/com_fields/tables/field.php b/administrator/components/com_fields/Table/Field.php similarity index 87% rename from administrator/components/com_fields/tables/field.php rename to administrator/components/com_fields/Table/Field.php index 0d64971277bee..b65f4a59f9ee2 100644 --- a/administrator/components/com_fields/tables/field.php +++ b/administrator/components/com_fields/Table/Field.php @@ -6,21 +6,27 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Table; + defined('_JEXEC') or die; +use Joomla\CMS\Access\Rules; +use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Table\Table; use Joomla\Registry\Registry; +use Joomla\String\StringHelper; /** * Fields Table * * @since 3.7.0 */ -class FieldsTableField extends JTable +class Field extends Table { /** * Class constructor. * - * @param JDatabaseDriver $db JDatabaseDriver object. + * @param \JDatabaseDriver $db \JDatabaseDriver object. * * @since 3.7.0 */ @@ -42,7 +48,7 @@ public function __construct($db = null) * @return boolean True on success. * * @since 3.7.0 - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function bind($src, $ignore = '') { @@ -63,7 +69,7 @@ public function bind($src, $ignore = '') // Bind the rules. if (isset($src['rules']) && is_array($src['rules'])) { - $rules = new JAccessRules($src['rules']); + $rules = new Rules($src['rules']); $this->setRules($rules); } @@ -96,21 +102,21 @@ public function check() $this->name = $this->title; } - $this->name = JApplicationHelper::stringURLSafe($this->name, $this->language); + $this->name = ApplicationHelper::stringURLSafe($this->name, $this->language); if (trim(str_replace('-', '', $this->name)) == '') { - $this->name = Joomla\String\StringHelper::increment($this->name, 'dash'); + $this->name = StringHelper::increment($this->name, 'dash'); } $this->name = str_replace(',', '-', $this->name); // Verify that the name is unique - $table = JTable::getInstance('Field', 'FieldsTable', array('dbo' => $this->_db)); + $table = new Field($this->_db); if ($table->load(array('name' => $this->name)) && ($table->id != $this->id || $this->id == 0)) { - $this->setError(JText::_('COM_FIELDS_ERROR_UNIQUE_NAME')); + $this->setError(\JText::_('COM_FIELDS_ERROR_UNIQUE_NAME')); return false; } @@ -122,8 +128,8 @@ public function check() $this->type = 'text'; } - $date = JFactory::getDate(); - $user = JFactory::getUser(); + $date = \JFactory::getDate(); + $user = \JFactory::getUser(); if ($this->id) { @@ -192,14 +198,14 @@ protected function _getAssetTitle() * The extended class can define a table and id to lookup. If the * asset does not exist it will be created. * - * @param JTable $table A JTable object for the asset parent. + * @param Table $table A JTable object for the asset parent. * @param integer $id Id to look up * * @return integer * * @since 3.7.0 */ - protected function _getAssetParentId(JTable $table = null, $id = null) + protected function _getAssetParentId(Table $table = null, $id = null) { $contextArray = explode('.', $this->context); $component = $contextArray[0]; diff --git a/administrator/components/com_fields/tables/group.php b/administrator/components/com_fields/Table/Group.php similarity index 89% rename from administrator/components/com_fields/tables/group.php rename to administrator/components/com_fields/Table/Group.php index ec160ddc46336..57876dd090b5d 100644 --- a/administrator/components/com_fields/tables/group.php +++ b/administrator/components/com_fields/Table/Group.php @@ -6,8 +6,12 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\Table; + defined('_JEXEC') or die; +use Joomla\CMS\Access\Rules; +use Joomla\CMS\Table\Table; use Joomla\Registry\Registry; /** @@ -15,12 +19,12 @@ * * @since 3.7.0 */ -class FieldsTableGroup extends JTable +class Group extends Table { /** * Class constructor. * - * @param JDatabaseDriver $db JDatabaseDriver object. + * @param \JDatabaseDriver $db \JDatabaseDriver object. * * @since 3.7.0 */ @@ -42,7 +46,7 @@ public function __construct($db = null) * @return boolean True on success. * * @since 3.7.0 - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function bind($src, $ignore = '') { @@ -56,7 +60,7 @@ public function bind($src, $ignore = '') // Bind the rules. if (isset($src['rules']) && is_array($src['rules'])) { - $rules = new JAccessRules($src['rules']); + $rules = new Rules($src['rules']); $this->setRules($rules); } @@ -84,8 +88,8 @@ public function check() return false; } - $date = JFactory::getDate(); - $user = JFactory::getUser(); + $date = \JFactory::getDate(); + $user = \JFactory::getUser(); if ($this->id) { @@ -148,14 +152,14 @@ protected function _getAssetTitle() * The extended class can define a table and id to lookup. If the * asset does not exist it will be created. * - * @param JTable $table A JTable object for the asset parent. + * @param Table $table A JTable object for the asset parent. * @param integer $id Id to look up * * @return integer * * @since 3.7.0 */ - protected function _getAssetParentId(JTable $table = null, $id = null) + protected function _getAssetParentId(Table $table = null, $id = null) { $component = explode('.', $this->context); $db = $this->getDbo(); diff --git a/administrator/components/com_fields/views/field/view.html.php b/administrator/components/com_fields/View/Field/Html.php similarity index 73% rename from administrator/components/com_fields/views/field/view.html.php rename to administrator/components/com_fields/View/Field/Html.php index d5875afb64f11..14a92a47934be 100644 --- a/administrator/components/com_fields/views/field/view.html.php +++ b/administrator/components/com_fields/View/Field/Html.php @@ -6,31 +6,36 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\View\Field; + defined('_JEXEC') or die; +use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\View\HtmlView; + /** * Field View * * @since 3.7.0 */ -class FieldsViewField extends JViewLegacy +class Html extends HtmlView { /** - * @var JForm + * @var \JForm * * @since 3.7.0 */ protected $form; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ protected $item; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ @@ -43,7 +48,7 @@ class FieldsViewField extends JViewLegacy * * @return mixed A string if successful, otherwise an Error object. * - * @see JViewLegacy::loadTemplate() + * @see HtmlView::loadTemplate() * @since 3.7.0 */ public function display($tpl = null) @@ -52,17 +57,17 @@ public function display($tpl = null) $this->item = $this->get('Item'); $this->state = $this->get('State'); - $this->canDo = JHelperContent::getActions($this->state->get('field.component'), 'field', $this->item->id); + $this->canDo = \JHelperContent::getActions($this->state->get('field.component'), 'field', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) { - JError::raiseError(500, implode("\n", $errors)); + \JError::raiseError(500, implode("\n", $errors)); return false; } - JFactory::getApplication()->input->set('hidemainmenu', true); + \JFactory::getApplication()->input->set('hidemainmenu', true); $this->addToolbar(); @@ -80,7 +85,7 @@ protected function addToolbar() { $component = $this->state->get('field.component'); $section = $this->state->get('field.section'); - $userId = JFactory::getUser()->get('id'); + $userId = \JFactory::getUser()->get('id'); $canDo = $this->canDo; $isNew = ($this->item->id == 0); @@ -93,14 +98,14 @@ protected function addToolbar() } // Load component language file - $lang = JFactory::getLanguage(); + $lang = \JFactory::getLanguage(); $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + || $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); - $title = JText::sprintf('COM_FIELDS_VIEW_FIELD_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', JText::_(strtoupper($component))); + $title = \JText::sprintf('COM_FIELDS_VIEW_FIELD_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', \JText::_(strtoupper($component))); // Prepare the toolbar. - JToolbarHelper::title( + ToolbarHelper::title( $title, 'puzzle field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-$section" : '') . '-field-' . ($isNew ? 'add' : 'edit') @@ -109,7 +114,7 @@ protected function addToolbar() // For new records, check the create permission. if ($isNew) { - JToolbarHelper::saveGroup( + ToolbarHelper::saveGroup( [ ['apply', 'field.apply'], ['save', 'field.save'], @@ -118,7 +123,7 @@ protected function addToolbar() 'btn-success' ); - JToolbarHelper::cancel('field.cancel'); + ToolbarHelper::cancel('field.cancel'); } else { @@ -146,14 +151,14 @@ protected function addToolbar() $toolbarButtons[] = ['save2copy', 'field.save2copy']; } - JToolbarHelper::saveGroup( + ToolbarHelper::saveGroup( $toolbarButtons, 'btn-success' ); - JToolbarHelper::cancel('field.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('field.cancel', 'JTOOLBAR_CLOSE'); } - JToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELDS_EDIT'); + ToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELDS_EDIT'); } } diff --git a/administrator/components/com_fields/views/fields/view.html.php b/administrator/components/com_fields/View/Fields/Html.php similarity index 56% rename from administrator/components/com_fields/views/fields/view.html.php rename to administrator/components/com_fields/View/Fields/Html.php index b2e731b07fec9..a76cf8567e9a6 100644 --- a/administrator/components/com_fields/views/fields/view.html.php +++ b/administrator/components/com_fields/View/Fields/Html.php @@ -6,17 +6,24 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\View\Fields; + defined('_JEXEC') or die; +use Joomla\CMS\Layout\FileLayout; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\View\HtmlView; + /** * Fields View * * @since 3.7.0 */ -class FieldsViewFields extends JViewLegacy +class Html extends HtmlView { /** - * @var JForm + * @var \JForm * * @since 3.7.0 */ @@ -37,14 +44,14 @@ class FieldsViewFields extends JViewLegacy protected $items; /** - * @var JPagination + * @var \JPagination * * @since 3.7.0 */ protected $pagination; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ @@ -78,16 +85,16 @@ public function display($tpl = null) // Check for errors. if (count($errors = $this->get('Errors'))) { - JError::raiseError(500, implode("\n", $errors)); + \JError::raiseError(500, implode("\n", $errors)); return false; } // Display a warning if the fields system plugin is disabled - if (!JPluginHelper::isEnabled('system', 'fields')) + if (!PluginHelper::isEnabled('system', 'fields')) { - $link = JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . FieldsHelper::getFieldsPluginId()); - JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED', $link), 'warning'); + $link = \JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . \FieldsHelper::getFieldsPluginId()); + \JFactory::getApplication()->enqueueMessage(\JText::sprintf('COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED', $link), 'warning'); } // Only add toolbar when not in modal window. @@ -96,8 +103,8 @@ public function display($tpl = null) $this->addToolbar(); } - FieldsHelper::addSubmenu($this->state->get('filter.context'), 'fields'); - $this->sidebar = JHtmlSidebar::render(); + \FieldsHelper::addSubmenu($this->state->get('filter.context'), 'fields'); + $this->sidebar = \JHtmlSidebar::render(); return parent::display($tpl); } @@ -114,10 +121,10 @@ protected function addToolbar() $fieldId = $this->state->get('filter.field_id'); $component = $this->state->get('filter.component'); $section = $this->state->get('filter.section'); - $canDo = JHelperContent::getActions($component, 'field', $fieldId); + $canDo = \JHelperContent::getActions($component, 'field', $fieldId); // Get the toolbar object instance - $bar = JToolbar::getInstance('toolbar'); + $bar = \JToolbar::getInstance('toolbar'); // Avoid nonsense situation. if ($component == 'com_fields') @@ -126,44 +133,44 @@ protected function addToolbar() } // Load extension language file - $lang = JFactory::getLanguage(); + $lang = \JFactory::getLanguage(); $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + || $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); - $title = JText::sprintf('COM_FIELDS_VIEW_FIELDS_TITLE', JText::_(strtoupper($component))); + $title = \JText::sprintf('COM_FIELDS_VIEW_FIELDS_TITLE', \JText::_(strtoupper($component))); // Prepare the toolbar. - JToolbarHelper::title($title, 'puzzle fields ' . substr($component, 4) . ($section ? "-$section" : '') . '-fields'); + ToolbarHelper::title($title, 'puzzle fields ' . substr($component, 4) . ($section ? "-$section" : '') . '-fields'); if ($canDo->get('core.create')) { - JToolbarHelper::addNew('field.add'); + ToolbarHelper::addNew('field.add'); } if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) { - JToolbarHelper::editList('field.edit'); + ToolbarHelper::editList('field.edit'); } if ($canDo->get('core.edit.state')) { - JToolbarHelper::publish('fields.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('fields.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolbarHelper::archiveList('fields.archive'); + ToolbarHelper::publish('fields.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('fields.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::archiveList('fields.archive'); } - if (JFactory::getUser()->authorise('core.admin')) + if (\JFactory::getUser()->authorise('core.admin')) { - JToolbarHelper::checkin('fields.checkin'); + ToolbarHelper::checkin('fields.checkin'); } // Add a batch button if ($canDo->get('core.create') && $canDo->get('core.edit') && $canDo->get('core.edit.state')) { - $title = JText::_('JTOOLBAR_BATCH'); + $title = \JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button - $layout = new JLayoutFile('joomla.toolbar.batch'); + $layout = new FileLayout('joomla.toolbar.batch'); $dhtml = $layout->render( array( @@ -176,19 +183,19 @@ protected function addToolbar() if ($canDo->get('core.admin') || $canDo->get('core.options')) { - JToolbarHelper::preferences($component); + ToolbarHelper::preferences($component); } if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete', $component)) { - JToolbarHelper::deleteList('', 'fields.delete', 'JTOOLBAR_EMPTY_TRASH'); + ToolbarHelper::deleteList('', 'fields.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { - JToolbarHelper::trash('fields.trash'); + ToolbarHelper::trash('fields.trash'); } - JToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELDS'); + ToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELDS'); } /** @@ -201,13 +208,13 @@ protected function addToolbar() protected function getSortFields() { return array( - 'a.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'a.state' => JText::_('JSTATUS'), - 'a.title' => JText::_('JGLOBAL_TITLE'), - 'a.type' => JText::_('COM_FIELDS_FIELD_TYPE_LABEL'), - 'a.access' => JText::_('JGRID_HEADING_ACCESS'), - 'language' => JText::_('JGRID_HEADING_LANGUAGE'), - 'a.id' => JText::_('JGRID_HEADING_ID'), + 'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'), + 'a.state' => \JText::_('JSTATUS'), + 'a.title' => \JText::_('JGLOBAL_TITLE'), + 'a.type' => \JText::_('COM_FIELDS_FIELD_TYPE_LABEL'), + 'a.access' => \JText::_('JGRID_HEADING_ACCESS'), + 'language' => \JText::_('JGRID_HEADING_LANGUAGE'), + 'a.id' => \JText::_('JGRID_HEADING_ID'), ); } } diff --git a/administrator/components/com_fields/views/group/view.html.php b/administrator/components/com_fields/View/Group/Html.php similarity index 72% rename from administrator/components/com_fields/views/group/view.html.php rename to administrator/components/com_fields/View/Group/Html.php index f555b94722e21..33a31b99042ed 100644 --- a/administrator/components/com_fields/views/group/view.html.php +++ b/administrator/components/com_fields/View/Group/Html.php @@ -6,31 +6,36 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\View\Group; + defined('_JEXEC') or die; +use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\View\HtmlView; + /** * Group View * * @since 3.7.0 */ -class FieldsViewGroup extends JViewLegacy +class Html extends HtmlView { /** - * @var JForm + * @var \JForm * * @since 3.7.0 */ protected $form; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ protected $item; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ @@ -39,7 +44,7 @@ class FieldsViewGroup extends JViewLegacy /** * The actions the user is authorised to perform * - * @var JObject + * @var \JObject * * @since 3.7.0 */ @@ -63,24 +68,24 @@ public function display($tpl = null) $this->state = $this->get('State'); $component = ''; - $parts = FieldsHelper::extract($this->state->get('filter.context')); + $parts = \FieldsHelper::extract($this->state->get('filter.context')); if ($parts) { $component = $parts[0]; } - $this->canDo = JHelperContent::getActions($component, 'fieldgroup', $this->item->id); + $this->canDo = \JHelperContent::getActions($component, 'fieldgroup', $this->item->id); // Check for errors. if (count($errors = $this->get('Errors'))) { - JError::raiseError(500, implode("\n", $errors)); + \JError::raiseError(500, implode("\n", $errors)); return false; } - JFactory::getApplication()->input->set('hidemainmenu', true); + \JFactory::getApplication()->input->set('hidemainmenu', true); $this->addToolbar(); @@ -97,14 +102,14 @@ public function display($tpl = null) protected function addToolbar() { $component = ''; - $parts = FieldsHelper::extract($this->state->get('filter.context')); + $parts = \FieldsHelper::extract($this->state->get('filter.context')); if ($parts) { $component = $parts[0]; } - $userId = JFactory::getUser()->get('id'); + $userId = \JFactory::getUser()->get('id'); $canDo = $this->canDo; $isNew = ($this->item->id == 0); @@ -117,14 +122,14 @@ protected function addToolbar() } // Load component language file - $lang = JFactory::getLanguage(); + $lang = \JFactory::getLanguage(); $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + || $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); - $title = JText::sprintf('COM_FIELDS_VIEW_GROUP_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', JText::_(strtoupper($component))); + $title = \JText::sprintf('COM_FIELDS_VIEW_GROUP_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', \JText::_(strtoupper($component))); // Prepare the toolbar. - JToolbarHelper::title( + ToolbarHelper::title( $title, 'puzzle field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . '-group-' . ($isNew ? 'add' : 'edit') @@ -135,7 +140,7 @@ protected function addToolbar() // For new records, check the create permission. if ($isNew) { - JToolbarHelper::saveGroup( + ToolbarHelper::saveGroup( [ ['apply', 'group.apply'], ['save', 'group.save'], @@ -144,7 +149,7 @@ protected function addToolbar() 'btn-success' ); - JToolbarHelper::cancel('group.cancel'); + ToolbarHelper::cancel('group.cancel'); } else { @@ -172,14 +177,14 @@ protected function addToolbar() $toolbarButtons[] = ['save2copy', 'group.save2copy']; } - JToolbarHelper::saveGroup( + ToolbarHelper::saveGroup( $toolbarButtons, 'btn-success' ); - JToolbarHelper::cancel('group.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('group.cancel', 'JTOOLBAR_CLOSE'); } - JToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELD_GROUPS_EDIT'); + ToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELD_GROUPS_EDIT'); } } diff --git a/administrator/components/com_fields/views/groups/view.html.php b/administrator/components/com_fields/View/Groups/Html.php similarity index 54% rename from administrator/components/com_fields/views/groups/view.html.php rename to administrator/components/com_fields/View/Groups/Html.php index f0bdcec38b51f..711297c814ddc 100644 --- a/administrator/components/com_fields/views/groups/view.html.php +++ b/administrator/components/com_fields/View/Groups/Html.php @@ -6,17 +6,25 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Administrator\View\Groups; + defined('_JEXEC') or die; +use Joomla\CMS\Layout\FileLayout; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Toolbar\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; +use Joomla\CMS\View\HtmlView; + /** * Groups View * * @since 3.7.0 */ -class FieldsViewGroups extends JViewLegacy +class Html extends HtmlView { /** - * @var JForm + * @var \JForm * * @since 3.7.0 */ @@ -37,14 +45,14 @@ class FieldsViewGroups extends JViewLegacy protected $items; /** - * @var JPagination + * @var \JPagination * * @since 3.7.0 */ protected $pagination; /** - * @var JObject + * @var \JObject * * @since 3.7.0 */ @@ -64,7 +72,7 @@ class FieldsViewGroups extends JViewLegacy * * @return mixed A string if successful, otherwise an Error object. * - * @see JViewLegacy::loadTemplate() + * @see HtmlView::loadTemplate() * @since 3.7.0 */ public function display($tpl = null) @@ -78,22 +86,22 @@ public function display($tpl = null) // Check for errors. if (count($errors = $this->get('Errors'))) { - JError::raiseError(500, implode("\n", $errors)); + \JError::raiseError(500, implode("\n", $errors)); return false; } // Display a warning if the fields system plugin is disabled - if (!JPluginHelper::isEnabled('system', 'fields')) + if (!PluginHelper::isEnabled('system', 'fields')) { - $link = JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . FieldsHelper::getFieldsPluginId()); - JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED', $link), 'warning'); + $link = \JRoute::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . \FieldsHelper::getFieldsPluginId()); + \JFactory::getApplication()->enqueueMessage(\JText::sprintf('COM_FIELDS_SYSTEM_PLUGIN_NOT_ENABLED', $link), 'warning'); } $this->addToolbar(); - FieldsHelper::addSubmenu($this->state->get('filter.context'), 'groups'); - $this->sidebar = JHtmlSidebar::render(); + \FieldsHelper::addSubmenu($this->state->get('filter.context'), 'groups'); + $this->sidebar = \JHtmlSidebar::render(); return parent::display($tpl); } @@ -109,17 +117,17 @@ protected function addToolbar() { $groupId = $this->state->get('filter.group_id'); $component = ''; - $parts = FieldsHelper::extract($this->state->get('filter.context')); + $parts = \FieldsHelper::extract($this->state->get('filter.context')); if ($parts) { $component = $parts[0]; } - $canDo = JHelperContent::getActions($component, 'fieldgroup', $groupId); + $canDo = \JHelperContent::getActions($component, 'fieldgroup', $groupId); // Get the toolbar object instance - $bar = JToolbar::getInstance('toolbar'); + $bar = Toolbar::getInstance('toolbar'); // Avoid nonsense situation. if ($component == 'com_fields') @@ -128,44 +136,44 @@ protected function addToolbar() } // Load component language file - $lang = JFactory::getLanguage(); + $lang = \JFactory::getLanguage(); $lang->load($component, JPATH_ADMINISTRATOR) - || $lang->load($component, JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); + || $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component)); - $title = JText::sprintf('COM_FIELDS_VIEW_GROUPS_TITLE', JText::_(strtoupper($component))); + $title = \JText::sprintf('COM_FIELDS_VIEW_GROUPS_TITLE', \JText::_(strtoupper($component))); // Prepare the toolbar. - JToolbarHelper::title($title, 'puzzle fields ' . substr($component, 4) . '-groups'); + ToolbarHelper::title($title, 'puzzle fields ' . substr($component, 4) . '-groups'); if ($canDo->get('core.create')) { - JToolbarHelper::addNew('group.add'); + ToolbarHelper::addNew('group.add'); } if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) { - JToolbarHelper::editList('group.edit'); + ToolbarHelper::editList('group.edit'); } if ($canDo->get('core.edit.state')) { - JToolbarHelper::publish('groups.publish', 'JTOOLBAR_PUBLISH', true); - JToolbarHelper::unpublish('groups.unpublish', 'JTOOLBAR_UNPUBLISH', true); - JToolbarHelper::archiveList('groups.archive'); + ToolbarHelper::publish('groups.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('groups.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::archiveList('groups.archive'); } - if (JFactory::getUser()->authorise('core.admin')) + if (\JFactory::getUser()->authorise('core.admin')) { - JToolbarHelper::checkin('groups.checkin'); + ToolbarHelper::checkin('groups.checkin'); } // Add a batch button if ($canDo->get('core.create') && $canDo->get('core.edit') && $canDo->get('core.edit.state')) { - $title = JText::_('JTOOLBAR_BATCH'); + $title = \JText::_('JTOOLBAR_BATCH'); // Instantiate a new JLayoutFile instance and render the batch button - $layout = new JLayoutFile('joomla.toolbar.batch'); + $layout = new FileLayout('joomla.toolbar.batch'); $dhtml = $layout->render( array( @@ -178,19 +186,19 @@ protected function addToolbar() if ($canDo->get('core.admin') || $canDo->get('core.options')) { - JToolbarHelper::preferences($component); + ToolbarHelper::preferences($component); } if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete', $component)) { - JToolbarHelper::deleteList('', 'groups.delete', 'JTOOLBAR_EMPTY_TRASH'); + ToolbarHelper::deleteList('', 'groups.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { - JToolbarHelper::trash('groups.trash'); + ToolbarHelper::trash('groups.trash'); } - JToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELD_GROUPS'); + ToolbarHelper::help('JHELP_COMPONENTS_FIELDS_FIELD_GROUPS'); } /** @@ -203,13 +211,13 @@ protected function addToolbar() protected function getSortFields() { return array( - 'a.ordering' => JText::_('JGRID_HEADING_ORDERING'), - 'a.state' => JText::_('JSTATUS'), - 'a.title' => JText::_('JGLOBAL_TITLE'), - 'a.access' => JText::_('JGRID_HEADING_ACCESS'), - 'language' => JText::_('JGRID_HEADING_LANGUAGE'), - 'a.context' => JText::_('JGRID_HEADING_CONTEXT'), - 'a.id' => JText::_('JGRID_HEADING_ID'), + 'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'), + 'a.state' => \JText::_('JSTATUS'), + 'a.title' => \JText::_('JGLOBAL_TITLE'), + 'a.access' => \JText::_('JGRID_HEADING_ACCESS'), + 'language' => \JText::_('JGRID_HEADING_LANGUAGE'), + 'a.context' => \JText::_('JGRID_HEADING_CONTEXT'), + 'a.id' => \JText::_('JGRID_HEADING_ID'), ); } } diff --git a/administrator/components/com_fields/dispatcher.php b/administrator/components/com_fields/dispatcher.php new file mode 100644 index 0000000000000..effbe1fb587c5 --- /dev/null +++ b/administrator/components/com_fields/dispatcher.php @@ -0,0 +1,56 @@ +getUserStateFromRequest( + 'com_fields.groups.context', + 'context', + $app->getUserStateFromRequest('com_fields.fields.context', 'context', 'com_content.article', 'CMD'), + 'CMD' + ); + + $parts = FieldsHelper::extract($context); + + if (!$parts || !$this->app->getIdentity()->authorise('core.manage', $parts[0])) + { + throw new \Joomla\CMS\Access\Exception\Notallowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); + } + } +} diff --git a/administrator/components/com_fields/fields.php b/administrator/components/com_fields/fields.php deleted file mode 100644 index ef0dbf01d9c9a..0000000000000 --- a/administrator/components/com_fields/fields.php +++ /dev/null @@ -1,30 +0,0 @@ -getUserStateFromRequest( - 'com_fields.groups.context', - 'context', - $app->getUserStateFromRequest('com_fields.fields.context', 'context', 'com_content.article', 'CMD'), - 'CMD' -); - -$parts = FieldsHelper::extract($context); - -if (!$parts || !JFactory::getUser()->authorise('core.manage', $parts[0])) -{ - return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); -} - -$controller = JControllerLegacy::getInstance('Fields'); -$controller->execute($app->input->get('task')); -$controller->redirect(); diff --git a/administrator/components/com_fields/helpers/fields.php b/administrator/components/com_fields/helpers/fields.php index 2980ad647d67a..2e09cf6ab2b24 100644 --- a/administrator/components/com_fields/helpers/fields.php +++ b/administrator/components/com_fields/helpers/fields.php @@ -91,12 +91,7 @@ public static function getFields($context, $item = null, $prepareValue = false, if (self::$fieldsCache === null) { // Load the model - JLoader::import('joomla.application.component.model'); - JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fields/models', 'FieldsModel'); - - self::$fieldsCache = JModelLegacy::getInstance('Fields', 'FieldsModel', array( - 'ignore_request' => true) - ); + self::$fieldsCache = new \Joomla\Component\Fields\Administrator\Model\Fields(array('ignore_request' => true)); self::$fieldsCache->setState('filter.state', 1); self::$fieldsCache->setState('list.limit', 0); @@ -142,7 +137,7 @@ public static function getFields($context, $item = null, $prepareValue = false, { if (self::$fieldCache === null) { - self::$fieldCache = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); + self::$fieldCache = new \Joomla\Component\Fields\Administrator\Model\Field(array('ignore_request' => true)); } $fieldIds = array_map( @@ -404,9 +399,6 @@ function categoryHasChanged(element) { $fieldsPerGroup[$field->group_id][] = $field; } - // On the front, sometimes the admin fields path is not included - JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fields/tables'); - // Looping through the groups foreach ($fieldsPerGroup as $group_id => $groupFields) { @@ -427,7 +419,7 @@ function categoryHasChanged(element) { if ($group_id) { - $group = JTable::getInstance('Group', 'FieldsTable'); + $group = new \Joomla\Component\Fields\Administrator\Table\Group(JFactory::getDbo()); $group->load($group_id); if ($group->id) @@ -499,7 +491,7 @@ function categoryHasChanged(element) { // Loading the XML fields string into the form $form->load($xml->saveXML()); - $model = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); + $model = new \Joomla\Component\Fields\Administrator\Model\Field(array('ignore_request' => true)); if ((!isset($data->id) || !$data->id) && JFactory::getApplication()->input->getCmd('controller') == 'config.display.modules' && JFactory::getApplication()->isClient('site')) diff --git a/components/com_fields/Controller/Controller.php b/components/com_fields/Controller/Controller.php new file mode 100644 index 0000000000000..62ec5c2c66eab --- /dev/null +++ b/components/com_fields/Controller/Controller.php @@ -0,0 +1,49 @@ +get('view') === 'fields' && $input->get('layout') === 'modal') + { + // Load the backend language file. + $app->getLanguage()->load('com_fields', JPATH_ADMINISTRATOR); + + $config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR; + } + + parent::__construct($config, $factory, $app, $input); + } +} diff --git a/components/com_fields/controllers/field.php b/components/com_fields/Controller/Field.php similarity index 72% rename from components/com_fields/controllers/field.php rename to components/com_fields/Controller/Field.php index b37183e29fdcf..9e321bbed7089 100644 --- a/components/com_fields/controllers/field.php +++ b/components/com_fields/Controller/Field.php @@ -6,14 +6,18 @@ * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Fields\Site\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Controller\Controller; + /** * Fields controller class for Fields Component. * * @since 3.7.0 */ -class FieldsControllerField extends JControllerLegacy +class Field extends Controller { /** * Stores the form content into the user session. @@ -24,11 +28,11 @@ class FieldsControllerField extends JControllerLegacy */ public function storeform() { - JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + \JSession::checkToken() or jexit(\JText::_('JINVALID_TOKEN')); - $app = JFactory::getApplication(); + $app = \JFactory::getApplication(); $data = $this->input->get($this->input->get('formcontrol', 'jform'), array(), 'array'); - $parts = FieldsHelper::extract($this->input->getCmd('context')); + $parts = \FieldsHelper::extract($this->input->getCmd('context')); if ($parts) { @@ -38,7 +42,7 @@ public function storeform() $redirectUrl = base64_decode($this->input->get->getBase64('return')); // Don't redirect to an external URL. - If (!JUri::isInternal($redirectUrl)) + If (!\JUri::isInternal($redirectUrl)) { $redirectUrl = 'index.php'; } diff --git a/components/com_fields/controller.php b/components/com_fields/controller.php deleted file mode 100644 index 55e9127f60369..0000000000000 --- a/components/com_fields/controller.php +++ /dev/null @@ -1,43 +0,0 @@ -input = JFactory::getApplication()->input; - - // Frontpage Editor Fields Button proxying: - if ($this->input->get('view') === 'fields' && $this->input->get('layout') === 'modal') - { - // Load the backend language file. - $lang = JFactory::getLanguage(); - $lang->load('com_fields', JPATH_ADMINISTRATOR); - - $config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR; - } - - parent::__construct($config); - } -} diff --git a/components/com_fields/dispatcher.php b/components/com_fields/dispatcher.php new file mode 100644 index 0000000000000..4989c312cf45b --- /dev/null +++ b/components/com_fields/dispatcher.php @@ -0,0 +1,43 @@ +option = \JComponentHelper::getComponentName($this, $r[1]); + $this->option = ComponentHelper::getComponentName($this, $r[1]); } // Set the view name @@ -306,6 +308,19 @@ public function __construct($config = array(), MvcFactoryInterface $factory = nu $this->event_clean_cache = 'onContentCleanCache'; } + if (!$factory) + { + $reflect = new \ReflectionClass($this); + if ($reflect->getNamespaceName()) + { + // Guess the root namespace + $ns = explode('\\', $reflect->getNamespaceName()); + $ns = implode('\\', array_slice($ns, 0, 3)); + + $factory = new MvcFactory($ns, \JFactory::getApplication()); + } + } + $this->factory = $factory ? : new LegacyFactory; } diff --git a/plugins/fields/calendar/calendar.php b/plugins/fields/calendar/calendar.php index 5ae7d9eb48110..08edbb362aa0b 100644 --- a/plugins/fields/calendar/calendar.php +++ b/plugins/fields/calendar/calendar.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Calendar Plugin * * @since 3.7.0 */ -class PlgFieldsCalendar extends FieldsPlugin +class PlgFieldsCalendar extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. diff --git a/plugins/fields/color/color.php b/plugins/fields/color/color.php index 08bff7c8a04b9..e7a93387cea57 100644 --- a/plugins/fields/color/color.php +++ b/plugins/fields/color/color.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Color Plugin * * @since 3.7.0 */ -class PlgFieldsColor extends FieldsPlugin +class PlgFieldsColor extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. diff --git a/plugins/fields/editor/editor.php b/plugins/fields/editor/editor.php index cd5dacaccee4e..40e5b7112ceb1 100644 --- a/plugins/fields/editor/editor.php +++ b/plugins/fields/editor/editor.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Editor Plugin * * @since 3.7.0 */ -class PlgFieldsEditor extends FieldsPlugin +class PlgFieldsEditor extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. diff --git a/plugins/fields/integer/integer.php b/plugins/fields/integer/integer.php index db1e9932d37ce..dd78549b6cfbc 100644 --- a/plugins/fields/integer/integer.php +++ b/plugins/fields/integer/integer.php @@ -9,13 +9,11 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Integer Plugin * * @since 3.7.0 */ -class PlgFieldsInteger extends FieldsPlugin +class PlgFieldsInteger extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { } diff --git a/plugins/fields/media/media.php b/plugins/fields/media/media.php index 5bc64f3a48997..480a1e838e753 100644 --- a/plugins/fields/media/media.php +++ b/plugins/fields/media/media.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Media Plugin * * @since 3.7.0 */ -class PlgFieldsMedia extends FieldsPlugin +class PlgFieldsMedia extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. diff --git a/plugins/fields/text/text.php b/plugins/fields/text/text.php index b22ac02d42579..1c41165c49e02 100644 --- a/plugins/fields/text/text.php +++ b/plugins/fields/text/text.php @@ -9,13 +9,11 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Text Plugin * * @since 3.7.0 */ -class PlgFieldsText extends FieldsPlugin +class PlgFieldsText extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { } diff --git a/plugins/fields/textarea/textarea.php b/plugins/fields/textarea/textarea.php index bdfa4963e565d..57683bc894da2 100644 --- a/plugins/fields/textarea/textarea.php +++ b/plugins/fields/textarea/textarea.php @@ -9,13 +9,11 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Textarea Plugin * * @since 3.7.0 */ -class PlgFieldsTextarea extends FieldsPlugin +class PlgFieldsTextarea extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { } diff --git a/plugins/fields/url/url.php b/plugins/fields/url/url.php index 15399320fc9c9..d384ba9302947 100644 --- a/plugins/fields/url/url.php +++ b/plugins/fields/url/url.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields URL Plugin * * @since 3.7.0 */ -class PlgFieldsUrl extends FieldsPlugin +class PlgFieldsUrl extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. diff --git a/plugins/fields/user/user.php b/plugins/fields/user/user.php index bc88a76c01f60..a6658ad681f05 100644 --- a/plugins/fields/user/user.php +++ b/plugins/fields/user/user.php @@ -9,14 +9,12 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields User Plugin * * @since 3.7.0 */ -class PlgFieldsUser extends FieldsPlugin +class PlgFieldsUser extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { /** diff --git a/plugins/fields/usergrouplist/usergrouplist.php b/plugins/fields/usergrouplist/usergrouplist.php index a9083a8e134f9..a6ff826ae2a5d 100644 --- a/plugins/fields/usergrouplist/usergrouplist.php +++ b/plugins/fields/usergrouplist/usergrouplist.php @@ -9,13 +9,11 @@ defined('_JEXEC') or die; -JLoader::import('components.com_fields.libraries.fieldsplugin', JPATH_ADMINISTRATOR); - /** * Fields Usergrouplist Plugin * * @since 3.7.0 */ -class PlgFieldsUsergrouplist extends FieldsPlugin +class PlgFieldsUsergrouplist extends \Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin { } diff --git a/plugins/system/fields/fields.php b/plugins/system/fields/fields.php index f94c94b557585..16ac1678c1da0 100644 --- a/plugins/system/fields/fields.php +++ b/plugins/system/fields/fields.php @@ -80,7 +80,7 @@ public function onContentAfterSave($context, $item, $isNew, $data = array()) $fieldsData = !empty($data['com_fields']) ? $data['com_fields'] : array(); // Loading the model - $model = JModelLegacy::getInstance('Field', 'FieldsModel', array('ignore_request' => true)); + $model = new \Joomla\Component\Fields\Administrator\Model\Field(array('ignore_request' => true)); // Loop over the fields foreach ($fields as $field)