diff --git a/code/admin/api.php b/code/admin/api.php index 8d91462..271a3d6 100755 --- a/code/admin/api.php +++ b/code/admin/api.php @@ -8,18 +8,20 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\Controller\BaseController; // Access check. -if (!JFactory::getUser()->authorise('core.manage', 'com_api')) +if (!Factory::getUser()->authorise('core.manage', 'com_api')) { - throw new Exception(JText::_('JERROR_ALERTNOAUTHOR')); + throw new Exception(Text::_('JERROR_ALERTNOAUTHOR')); } require_once JPATH_SITE . '/components/com_api/defines.php'; // Include dependancies -jimport('joomla.application.component.controller'); -$controller = JControllerLegacy::getInstance('Api'); -$controller->execute(JFactory::getApplication()->input->get('task')); +$controller = BaseController::getInstance('Api'); +$controller->execute(Factory::getApplication()->input->get('task')); $controller->redirect(); diff --git a/code/admin/controller.php b/code/admin/controller.php index bc3ba1f..86a6eba 100644 --- a/code/admin/controller.php +++ b/code/admin/controller.php @@ -9,18 +9,22 @@ // No direct access defined('_JEXEC') or die(); +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\Factory; + /** * API Controller class * * @since 1.0 */ -class ApiController extends JControllerLegacy +class ApiController extends BaseController { /** * Method to display a view. * * @param boolean $cachable If true, the view output will be cached - * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. + * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link InputFilter::clean()}. * * @return JController This object to support chaining. * @@ -30,8 +34,8 @@ public function display($cachable = false, $urlparams = false) { require_once JPATH_COMPONENT . '/helpers/api.php'; - $view = JFactory::getApplication()->input->getCmd('view', 'keys'); - JFactory::getApplication()->input->set('view', $view); + $view = Factory::getApplication()->input->getCmd('view', 'keys'); + Factory::getApplication()->input->set('view', $view); parent::display($cachable, $urlparams); diff --git a/code/admin/controllers/key.php b/code/admin/controllers/key.php index f762e2a..aac1543 100644 --- a/code/admin/controllers/key.php +++ b/code/admin/controllers/key.php @@ -9,19 +9,20 @@ // No direct access defined('_JEXEC') or die(); -jimport('joomla.application.component.controllerform'); +use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\MVC\Controller\BaseController; /** * Key controller class. * * @since 1.0 */ -class ApiControllerKey extends JControllerForm +class ApiControllerKey extends FormController { /** * Constructor. * - * @see \JControllerLegacy + * @see \BaseController * @since 1.6 * @throws \Exception */ diff --git a/code/admin/controllers/keys.php b/code/admin/controllers/keys.php index e373c7e..5482e91 100644 --- a/code/admin/controllers/keys.php +++ b/code/admin/controllers/keys.php @@ -9,14 +9,16 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.controlleradmin'); +use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Factory; /** * Keys list controller class. * * @since 1.0 */ -class ApiControllerKeys extends JControllerAdmin +class ApiControllerKeys extends AdminController { /** * Method to get a model object, loading it if required. @@ -24,7 +26,7 @@ class ApiControllerKeys extends JControllerAdmin * @param string $name The model name. Optional. * @param string $prefix The class prefix. Optional. * - * @return \JModelLegacy|boolean Model object on success; otherwise false on failure. + * @return \BaseDatabaseModel|boolean Model object on success; otherwise false on failure. * * @since 3.0 */ @@ -45,7 +47,7 @@ public function getModel($name = 'key', $prefix = 'ApiModel') public function saveOrderAjax() { // Get the input - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $pks = $input->post->get('cid', array(), 'array'); $order = $input->post->get('order', array(), 'array'); @@ -65,6 +67,6 @@ public function saveOrderAjax() } // Close the application - JFactory::getApplication()->close(); + Factory::getApplication()->close(); } } diff --git a/code/admin/controllers/logs.php b/code/admin/controllers/logs.php index a64542f..461f24b 100644 --- a/code/admin/controllers/logs.php +++ b/code/admin/controllers/logs.php @@ -11,14 +11,15 @@ // No direct access. defined('_JEXEC') or die('Restricted access'); -jimport('joomla.application.component.controlleradmin'); +use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; /** * Logs list controller class. * * @since 1.0 */ -class ApiControllerLogs extends JControllerAdmin +class ApiControllerLogs extends AdminController { /** * Method to get a model object, loading it if required. @@ -27,7 +28,7 @@ class ApiControllerLogs extends JControllerAdmin * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \JModelLegacy|boolean Model object on success; otherwise false on failure. + * @return \BaseDatabaseModel|boolean Model object on success; otherwise false on failure. * * @since 3.0 */ diff --git a/code/admin/helpers/api.php b/code/admin/helpers/api.php index 1fbaca0..e9a0eee 100644 --- a/code/admin/helpers/api.php +++ b/code/admin/helpers/api.php @@ -9,6 +9,11 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Factory; + /** * Content component helper. * @@ -27,31 +32,34 @@ class ApiHelper */ public static function addSubmenu($vName = '') { - $submenus = array(); - $submenus[] = array( - 'title' => JText::_('COM_API_TITLE_KEYS'), 'link' => 'index.php?option=com_api&view=keys', 'view' => $vName == 'keys' - ); - $submenus[] = array( - 'title' => JText::_('COM_API_TITLE_LOGS'), 'link' => 'index.php?option=com_api&view=logs', 'view' => $vName == 'logs' - ); - - foreach ($submenus as $submenu) + if (JVERSION < '4.0.0') { - JHtmlSidebar::addEntry($submenu['title'], $submenu['link'], $submenu['view']); + $submenus = array(); + $submenus[] = array( + 'title' => Text::_('COM_API_TITLE_KEYS'), 'link' => 'index.php?option=com_api&view=keys', 'view' => $vName == 'keys' + ); + $submenus[] = array( + 'title' => Text::_('COM_API_TITLE_LOGS'), 'link' => 'index.php?option=com_api&view=logs', 'view' => $vName == 'logs' + ); + + foreach ($submenus as $submenu) + { + JHtmlSidebar::addEntry($submenu['title'], $submenu['link'], $submenu['view']); + } } } /** * Gets a list of the actions that can be performed. * - * @return JObject + * @return CMSObject * * @since 1.0 */ public static function getActions() { - $user = JFactory::getUser(); - $result = new JObject; + $user = Factory::getUser(); + $result = new CMSObject; $assetName = 'com_api'; diff --git a/code/admin/models/fields/createdby.php b/code/admin/models/fields/createdby.php index 16f8325..6fc3548 100644 --- a/code/admin/models/fields/createdby.php +++ b/code/admin/models/fields/createdby.php @@ -8,7 +8,8 @@ defined('JPATH_BASE') or die(); -jimport('joomla.form.formfield'); +use Joomla\CMS\Form\FormField; +use Joomla\CMS\Factory; /** * Abstract Form Field class @@ -42,11 +43,11 @@ protected function getInput() if ($userId) { - $user = JFactory::getUser($userId); + $user = Factory::getUser($userId); } else { - $user = JFactory::getUser(); + $user = Factory::getUser(); $html[] = ''; } diff --git a/code/admin/models/key.php b/code/admin/models/key.php index 067454e..ec93386 100644 --- a/code/admin/models/key.php +++ b/code/admin/models/key.php @@ -9,14 +9,17 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.modeladmin'); +use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Form\Form; +use Joomla\CMS\Factory; /** * Api model. * * @since 1.0 */ -class ApiModelKey extends JModelAdmin +class ApiModelKey extends AdminModel { /** * The prefix to use with controller messages. @@ -33,14 +36,14 @@ class ApiModelKey extends JModelAdmin * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \JTable A \JTable object + * @return \Table A \Table object * * @since 3.0 * @throws \Exception */ public function getTable($type = 'Key', $prefix = 'ApiTable', $config = array()) { - return JTable::getInstance($type, $prefix, $config); + return Table::getInstance($type, $prefix, $config); } /** @@ -49,14 +52,14 @@ public function getTable($type = 'Key', $prefix = 'ApiTable', $config = array()) * @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 \JForm|boolean A \JForm object on success, false on failure + * @return \Form|boolean A \Form object on success, false on failure * * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Get the form. $form = $this->loadForm('com_api.key', 'key', array('control' => 'jform', 'load_data' => $loadData)); @@ -79,7 +82,7 @@ public function getForm($data = array(), $loadData = true) protected function loadFormData() { // Check the session for previously entered form data. - $data = JFactory::getApplication()->getUserState('com_api.edit.key.data', array()); + $data = Factory::getApplication()->getUserState('com_api.edit.key.data', array()); if (empty($data)) { diff --git a/code/admin/models/keys.php b/code/admin/models/keys.php index f6a402b..885d71f 100644 --- a/code/admin/models/keys.php +++ b/code/admin/models/keys.php @@ -9,14 +9,17 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.modellist'); +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\Data\DataObject; /** * Methods supporting a list of keys records. * * @since 1.0 */ -class ApiModelKeys extends JModelList +class ApiModelKeys extends ListModel { /** * Constructor. @@ -54,7 +57,7 @@ public function __construct($config = array()) protected function populateState($ordering = null, $direction = null) { // Initialise variables. - $app = JFactory::getApplication('administrator'); + $app = Factory::getApplication('administrator'); // Load the filter state. $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); @@ -64,7 +67,7 @@ protected function populateState($ordering = null, $direction = null) $this->setState('filter.state', $state); // Load the parameters. - $params = JComponentHelper::getParams('com_api'); + $params = ComponentHelper::getParams('com_api'); $this->setState('params', $params); // List state information. @@ -96,7 +99,7 @@ protected function getStoreId($id = '') /** * Build an SQL query to load the list data. * - * @return JDatabaseQuery + * @return DataObjectbaseQuery * * @since 1.6 */ diff --git a/code/admin/models/log.php b/code/admin/models/log.php index 8807f6a..cf91f62 100644 --- a/code/admin/models/log.php +++ b/code/admin/models/log.php @@ -11,14 +11,17 @@ // No direct access. defined('_JEXEC') or die('Restricted access'); -jimport('joomla.application.component.modeladmin'); +use Joomla\CMS\MVC\Model\AdminModel; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Form\Form; +use Joomla\CMS\Factory; /** * Api model. * * @since 2.4.1 */ -class ApiModelLog extends JModelAdmin +class ApiModelLog extends AdminModel { /** * The prefix to use with controller messages. @@ -35,14 +38,14 @@ class ApiModelLog extends JModelAdmin * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * - * @return \JTable A \JTable object + * @return \Table A \Table object * * @since 2.4.1 * @throws \Exception */ public function getTable($type = 'Log', $prefix = 'ApiTable', $config = array()) { - return JTable::getInstance($type, $prefix, $config); + return Table::getInstance($type, $prefix, $config); } /** @@ -51,14 +54,14 @@ public function getTable($type = 'Log', $prefix = 'ApiTable', $config = array()) * @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 \JForm|boolean A \JForm object on success, false on failure + * @return \Form|boolean A \Form object on success, false on failure * * @since 2.4.1 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Get the form. $form = $this->loadForm('com_api.log', 'log', array('control' => 'jform', 'load_data' => $loadData)); diff --git a/code/admin/models/logs.php b/code/admin/models/logs.php index 6f967e8..f572a9d 100644 --- a/code/admin/models/logs.php +++ b/code/admin/models/logs.php @@ -8,21 +8,27 @@ defined('_JEXEC') or die(); -jimport('joomla.application.component.modellist'); +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\Data\DataObject; +use Joomla\CMS\Table\Table; + /** * Methods supporting a list of log records. * * @since 1.0 */ -class ApiModelLogs extends JModelList +class ApiModelLogs extends ListModel { /** * Constructor. * * @param array $config An optional associative array of configuration settings. * - * @see \JModelLegacy + * @see \BaseDatabaseModel * @since 1.6 */ public function __construct($config = array()) @@ -56,7 +62,7 @@ public function __construct($config = array()) protected function populateState($ordering = null, $direction = null) { // Initialise variables. - $app = JFactory::getApplication('administrator'); + $app = Factory::getApplication('administrator'); // Load the filter state. $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); @@ -66,7 +72,7 @@ protected function populateState($ordering = null, $direction = null) $this->setState('filter.state', $published); // Load the parameters. - $params = JComponentHelper::getParams('com_api'); + $params = ComponentHelper::getParams('com_api'); $this->setState('params', $params); // List state information. @@ -98,7 +104,7 @@ protected function getStoreId($id = '') /** * Build an SQL query to load the list data. * - * @return JDatabaseQuery + * @return DataObjectbaseQuery * * @since 1.6 */ @@ -164,7 +170,7 @@ protected function getListQuery() */ public function delete($cid) { - $table = JTable::getInstance('Log', 'ApiTable'); + $table = Table::getInstance('Log', 'ApiTable'); foreach ($cid as $id) { diff --git a/code/admin/sql/updates/mysql/3.0.0.sql b/code/admin/sql/updates/mysql/3.0.0.sql new file mode 100644 index 0000000..e25953f --- /dev/null +++ b/code/admin/sql/updates/mysql/3.0.0.sql @@ -0,0 +1,17 @@ +ALTER TABLE `#__api_keys` CHANGE `userid` `userid` int(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__api_keys` CHANGE `hash` `hash` varchar(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_keys` CHANGE `domain` `domain` varchar(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_keys` CHANGE `state` `state` tinyint(1) NOT NULL DEFAULT 0; +ALTER TABLE `#__api_keys` CHANGE `checked_out` `checked_out` int(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__api_keys` CHANGE `checked_out_time` `checked_out_time` datetime DEFAULT NULL; +ALTER TABLE `#__api_keys` CHANGE `created` `created` datetime DEFAULT NULL; +ALTER TABLE `#__api_keys` CHANGE `created_by` `created_by` int(11) NOT NULL DEFAULT 0; +ALTER TABLE `#__api_keys` CHANGE `last_used` `last_used` datetime DEFAULT NULL; +ALTER TABLE `#__api_keys` CHANGE `per_hour` `per_hour` int(10) NOT NULL DEFAULT 0; + +ALTER TABLE `#__api_logs` CHANGE `hash` `hash` varchar(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_logs` CHANGE `ip_address` `ip_address` varchar(20) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_logs` CHANGE `time` `time` timestamp ON UPDATE CURRENT_TIMESTAMP; +ALTER TABLE `#__api_logs` CHANGE `request_method` `request_method` varchar(20) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_logs` CHANGE `request` `request` varchar(255) NOT NULL DEFAULT ''; +ALTER TABLE `#__api_logs` CHANGE `post_data` `post_data` text DEFAULT NULL; diff --git a/code/admin/tables/key.php b/code/admin/tables/key.php index cbfd8da..eaae23f 100644 --- a/code/admin/tables/key.php +++ b/code/admin/tables/key.php @@ -9,12 +9,18 @@ // No direct access defined('_JEXEC') or die(); +use Joomla\CMS\Table\Table; +use Joomla\Data\DataObject; +use Joomla\CMS\Factory; +use Joomla\Registry\Registry; +use Joomla\CMS\Language\Text; + /** * key Table class * * @since 1.0 */ -class ApiTablekey extends JTable +class ApiTablekey extends Table { /** * Hashed string stored in table @@ -27,7 +33,7 @@ class ApiTablekey extends JTable /** * Constructor * - * @param JDatabaseDriver &$db Database object + * @param DataObjectbaseDriver &$db Database object * * @since 1.0 */ @@ -52,37 +58,37 @@ public function __construct(&$db) */ public function bind($array, $ignore = '') { - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $task = $input->getString('task', ''); - if (($task == 'save' || $task == 'apply') && (! JFactory::getUser()->authorise('core.edit.state', 'com_api') && $array['state'] == 1)) + if (($task == 'save' || $task == 'apply') && (! Factory::getUser()->authorise('core.edit.state', 'com_api') && $array['state'] == 1)) { $array['state'] = 0; } if ($array['id'] == 0) { - $array['created_by'] = JFactory::getUser()->id; + $array['created_by'] = Factory::getUser()->id; } if (isset($array['params']) && is_array($array['params'])) { - $registry = new JRegistry; + $registry = new Registry; $registry->loadArray($array['params']); $array['params'] = (string) $registry; } if (isset($array['metadata']) && is_array($array['metadata'])) { - $registry = new JRegistry; + $registry = new Registry; $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } - if (! JFactory::getUser()->authorise('core.admin', 'com_api.key.' . $array['id'])) + if (! Factory::getUser()->authorise('core.admin', 'com_api.key.' . $array['id'])) { - $actions = JFactory::getACL()->getActions('com_api', 'key'); - $defaultActions = JFactory::getACL()->getAssetRules('com_api.key.' . $array['id'])->getData(); + $actions = Factory::getACL()->getActions('com_api', 'key'); + $defaultActions = Factory::getACL()->getAssetRules('com_api.key.' . $array['id'])->getData(); $arrayJaccess = array(); foreach ($actions as $action) @@ -90,7 +96,7 @@ public function bind($array, $ignore = '') $arrayJaccess[$action->name] = $defaultActions[$action->name]; } - $array['rules'] = $this->JAccessRulestoArray($arrayJaccess); + $array['rules'] = $this->RulestoArray($arrayJaccess); } // Bind the rules for ACL where supported. @@ -103,15 +109,15 @@ public function bind($array, $ignore = '') } /** - * This function convert an array of JAccessRule objects into an rules array. + * This function convert an array of Rule objects into an rules array. * - * @param array $jaccessrules an array of JAccessRule objects. + * @param array $jaccessrules an array of Rule objects. * * @return array * * @since 1.0 */ - private function JAccessRulestoArray($jaccessrules) + private function RulestoArray($jaccessrules) { $rules = array(); @@ -143,7 +149,7 @@ public function check() { if (! $this->userid) { - JError::raiseWarning(100, JText::_('COM_API_KEY_NO_USER')); + JError::raiseWarning(100, Text::_('COM_API_KEY_NO_USER')); return false; } @@ -192,7 +198,7 @@ public function setLastUsed($hash) { $this->loadByHash($hash); - $date = JFactory::getDate(); + $date = Factory::getDate(); $this->last_used = $date->toSql(); $this->store(); } diff --git a/code/admin/tables/log.php b/code/admin/tables/log.php index bab62a7..132234a 100644 --- a/code/admin/tables/log.php +++ b/code/admin/tables/log.php @@ -9,17 +9,22 @@ // No direct access defined('_JEXEC') or die(); +use Joomla\CMS\Table\Table; +use Joomla\Data\DataObject; +use Joomla\CMS\Factory; +use Joomla\Registry\Registry; + /** * Log Table class * * @since 1.0 */ -class ApiTablelog extends JTable +class ApiTablelog extends Table { /** * Constructor * - * @param JDatabaseDriver &$db Database object + * @param DataObjectbaseDriver &$db Database object * * @since 1.0 */ @@ -43,32 +48,32 @@ public function __construct(&$db) */ public function bind($array, $ignore = '') { - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $task = $input->getString('task', ''); if ($array['id'] == 0) { - $array['created_by'] = JFactory::getUser()->id; + $array['created_by'] = Factory::getUser()->id; } if (isset($array['params']) && is_array($array['params'])) { - $registry = new JRegistry; + $registry = new Registry; $registry->loadArray($array['params']); $array['params'] = (string) $registry; } if (isset($array['metadata']) && is_array($array['metadata'])) { - $registry = new JRegistry; + $registry = new Registry; $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } - if (! JFactory::getUser()->authorise('core.admin', 'com_api.key.' . $array['id'])) + if (! Factory::getUser()->authorise('core.admin', 'com_api.key.' . $array['id'])) { - $actions = JFactory::getACL()->getActions('com_api', 'key'); - $defaultActions = JFactory::getACL()->getAssetRules('com_api.key.' . $array['id'])->getData(); + $actions = Factory::getACL()->getActions('com_api', 'key'); + $defaultActions = Factory::getACL()->getAssetRules('com_api.key.' . $array['id'])->getData(); $arrayJaccess = array(); foreach ($actions as $action) @@ -76,7 +81,7 @@ public function bind($array, $ignore = '') $arrayJaccess[$action->name] = $defaultActions[$action->name]; } - $array['rules'] = $this->JAccessRulestoArray($arrayJaccess); + $array['rules'] = $this->RulestoArray($arrayJaccess); } // Bind the rules for ACL where supported. @@ -89,15 +94,15 @@ public function bind($array, $ignore = '') } /** - * This function convert an array of JAccessRule objects into an rules array. + * This function convert an array of Rule objects into an rules array. * - * @param array $jaccessrules an array of JAccessRule objects. + * @param array $jaccessrules an array of Rule objects. * * @return array * * @since 1.0 */ - private function JAccessRulestoArray($jaccessrules) + private function RulestoArray($jaccessrules) { $rules = array(); diff --git a/code/admin/views/cpanel/tmpl/default.php b/code/admin/views/cpanel/tmpl/default.php index 342ec00..23b28e9 100644 --- a/code/admin/views/cpanel/tmpl/default.php +++ b/code/admin/views/cpanel/tmpl/default.php @@ -9,7 +9,9 @@ */ defined('_JEXEC') or die; -$template = JFactory::getApplication()->getTemplate(true)->template; +use Joomla\CMS\Factory; + +$template = Factory::getApplication()->getTemplate(true)->template; ?>
addStyleSheet('components/com_api/assets/css/api.css'); ?> @@ -42,20 +47,20 @@ } else { - if (task != 'key.cancel' && document.formvalidator.isValid(document.id('key-form'))) + if (task != 'key.cancel' && document.formvalidator.isValid(document.getElementById('key-form'))) { Joomla.submitform(task, document.getElementById('key-form')); } else { - alert('escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>'); + alert('escape(Text::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>'); } } }
-
+
@@ -89,7 +94,7 @@ if(empty($this->item->created_by)) { ?> - +
- +
diff --git a/code/admin/views/key/view.html.php b/code/admin/views/key/view.html.php index dd5a6b2..0cdb813 100644 --- a/code/admin/views/key/view.html.php +++ b/code/admin/views/key/view.html.php @@ -9,19 +9,23 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.view'); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Form\Form; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; /** * View class key form. * * @since 1.0 */ -class ApiViewKey extends JViewLegacy +class ApiViewKey extends HtmlView { /** * The model state. * - * @var JObject + * @var CMSObject * @since 1.0 */ protected $state; @@ -35,9 +39,9 @@ class ApiViewKey extends JViewLegacy protected $item; /** - * A JForm instance with filter fields. + * A Form instance with filter fields. * - * @var JForm + * @var Form * @since 1.0 */ protected $form; @@ -75,18 +79,18 @@ public function display($tpl = null) */ protected function addToolbar() { - JFactory::getApplication()->input->set('hidemainmenu', true); + Factory::getApplication()->input->set('hidemainmenu', true); - $user = JFactory::getUser(); + $user = Factory::getUser(); $isNew = ($this->item->id == 0); if ($isNew) { - $viewTitle = JText::_('COM_API_ADD_KEY'); + $viewTitle = Text::_('COM_API_ADD_KEY'); } else { - $viewTitle = JText::_('COM_API_EDIT_KEY'); + $viewTitle = Text::_('COM_API_EDIT_KEY'); } if (JVERSION >= '3.0') diff --git a/code/admin/views/keys/tmpl/default.php b/code/admin/views/keys/tmpl/default.php index 2084ce0..0087608 100644 --- a/code/admin/views/keys/tmpl/default.php +++ b/code/admin/views/keys/tmpl/default.php @@ -13,13 +13,18 @@ // No direct access. defined('_JEXEC') or die(); -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); // Import CSS -$document = JFactory::getDocument(); +$document = Factory::getDocument(); $document->addStyleSheet('components/com_api/assets/css/api.css'); -$user = JFactory::getUser(); +$user = Factory::getUser(); $userId = $user->get('id'); $listOrder = $this->state->get('list.ordering'); $listDirn = $this->state->get('list.direction'); @@ -29,7 +34,7 @@ if ($saveOrder) { $saveOrderingUrl = 'index.php?option=com_tjfields&task=countries.saveOrderAjax&tmpl=component'; - JHtml::_('sortablelist.sortable', 'countryList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); + HTMLHelper::_('sortablelist.sortable', 'countryList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); } $sortFields = $this->getSortFields(); @@ -64,7 +69,7 @@
sidebar)): ?> @@ -80,20 +85,20 @@
@@ -101,18 +106,18 @@ class="hasTooltip" = '3.0') : ?>
pagination->getLimitBox(); ?>
-
publish_states, "filter_state", 'class="input-medium" size="1" onchange="document.adminForm.submit();" name="filter_state"', "value", "text", $this->state->get('filter.state')); + echo HTMLHelper::_('select.genericlist', $this->publish_states, "filter_state", 'class="input-medium form-select" size="1" onchange="document.adminForm.submit();" name="filter_state"', "value", "text", $this->state->get('filter.state')); ?>
@@ -157,36 +162,37 @@ class="input-medium" onchange="Joomla.orderTable()"> items)) : ?>
 
- +
+
 
items[0]->state)): ?> items[0]->id)): ?> @@ -201,25 +207,25 @@ class="input-medium" onchange="Joomla.orderTable()"> items[0]->state)): ?> - + @@ -238,7 +244,7 @@ class="input-medium" onchange="Joomla.orderTable()"> - + diff --git a/code/admin/views/keys/view.html.php b/code/admin/views/keys/view.html.php index e355da9..a33e3aa 100644 --- a/code/admin/views/keys/view.html.php +++ b/code/admin/views/keys/view.html.php @@ -9,19 +9,23 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.view'); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Pagination\Pagination; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; /** * View class for list of keys * * @since 1.0 */ -class ApiViewKeys extends JViewLegacy +class ApiViewKeys extends HtmlView { /** * The model state. * - * @var JObject + * @var CMSObject * @since 1.0 */ protected $state; @@ -37,7 +41,7 @@ class ApiViewKeys extends JViewLegacy /** * The pagination object. * - * @var JPagination + * @var Pagination * @since 1.0 */ protected $pagination; @@ -64,7 +68,7 @@ public function display($tpl = null) ApiHelper::addSubmenu('keys'); $this->publish_states = array( - '' => JText::_('JOPTION_SELECT_PUBLISHED'), '1' => JText::_('JPUBLISHED'), '0' => JText::_('JUNPUBLISHED'), '*' => JText::_('JALL') + '' => Text::_('JOPTION_SELECT_PUBLISHED'), '1' => Text::_('JPUBLISHED'), '0' => Text::_('JUNPUBLISHED'), '*' => Text::_('JALL') ); $this->addToolbar(); @@ -93,11 +97,11 @@ protected function addToolbar() if (JVERSION >= '3.0') { - JToolBarHelper::title(JText::_('COM_API_TITLE_KEYS'), 'key'); + JToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'key'); } else { - JToolBarHelper::title(JText::_('COM_API_TITLE_KEYS'), 'keys.png'); + JToolBarHelper::title(Text::_('COM_API_TITLE_KEYS'), 'keys.png'); } // Check if the form exists before showing the add/edit buttons @@ -159,8 +163,8 @@ protected function addToolbar() protected function getSortFields() { return array( - 'a.id' => JText::_('JGRID_HEADING_ID'), 'a.userid' => JText::_('COM_API_KEYS_USERID'), 'a.domain' => JText::_('COM_API_KEYS_DOMAIN'), - 'a.state' => JText::_('JSTATUS'), 'a.last_used' => JText::_('COM_API_KEYS_LAST_USED') + 'a.id' => Text::_('JGRID_HEADING_ID'), 'a.userid' => Text::_('COM_API_KEYS_USERID'), 'a.domain' => Text::_('COM_API_KEYS_DOMAIN'), + 'a.state' => Text::_('JSTATUS'), 'a.last_used' => Text::_('COM_API_KEYS_LAST_USED') ); } } diff --git a/code/admin/views/logs/tmpl/default.php b/code/admin/views/logs/tmpl/default.php index fba96f6..607498b 100644 --- a/code/admin/views/logs/tmpl/default.php +++ b/code/admin/views/logs/tmpl/default.php @@ -11,13 +11,18 @@ // no direct access defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; + +HTMLHelper::addIncludePath(JPATH_COMPONENT.'/helpers/html'); // Import CSS -$document = JFactory::getDocument(); +$document = Factory::getDocument(); $document->addStyleSheet('components/com_api/assets/css/api.css'); -$user = JFactory::getUser(); +$user = Factory::getUser(); $userId = $user->get('id'); $listOrder = $this->state->get('list.ordering'); $listDirn = $this->state->get('list.direction'); @@ -27,7 +32,7 @@ if ($saveOrder) { $saveOrderingUrl = 'index.php?option=com_tjfields&task=countries.saveOrderAjax&tmpl=component'; - JHtml::_('sortablelist.sortable', 'countryList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); + HTMLHelper::_('sortablelist.sortable', 'countryList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); } $sortFields = $this->getSortFields(); @@ -62,7 +67,7 @@
sidebar)): ?> @@ -78,20 +83,20 @@
@@ -99,18 +104,18 @@ class="hasTooltip" = '3.0') : ?>
pagination->getLimitBox(); ?>
@@ -150,7 +155,7 @@ class="input-medium" onchange="Joomla.orderTable()"> items)) : ?>
 
- +
@@ -158,23 +163,23 @@ class="input-medium" onchange="Joomla.orderTable()">
- - + + @@ -182,14 +187,14 @@ class="input-medium" onchange="Joomla.orderTable()"> items as $i => $item) : ?> - +
- + - + - + - + - + - + - +
- id); ?> + id); ?> - state, $i, 'keys.', $canChange, 'cb'); ?> + state, $i, 'keys.', $canChange, 'cb'); ?> name; ?> -
userid; ?>
+
userid; ?>
checked_out) && $item->checked_out) : ?> - editor, $item->checked_out_time, 'keys.', $canCheckin); ?> + editor, $item->checked_out_time, 'keys.', $canCheckin); ?> domain; ?> hash; ?>last_used == '0000-00-00 00:00:00') ? JText::_('JNEVER') : $item->last_used; ?>last_used == '0000-00-00 00:00:00') ? Text::_('JNEVER') : $item->last_used; ?> id; ?>
- + - / - + / + - + - + - +
- id); ?> + id); ?> hash; ?> name) : ?>
name; ?>
ip_address; ?> @@ -217,7 +222,7 @@ class="input-medium" onchange="Joomla.orderTable()"> - + diff --git a/code/admin/views/logs/view.html.php b/code/admin/views/logs/view.html.php index cc2e37a..3b81ad6 100644 --- a/code/admin/views/logs/view.html.php +++ b/code/admin/views/logs/view.html.php @@ -9,19 +9,24 @@ // No direct access. defined('_JEXEC') or die(); -jimport('joomla.application.component.view'); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Pagination\Pagination; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + /** * View class for list of logs * * @since 1.0 */ -class ApiViewLogs extends JViewLegacy +class ApiViewLogs extends HtmlView { /** * The model state. * - * @var JObject + * @var CMSObject * @since 1.0 */ protected $state; @@ -37,7 +42,7 @@ class ApiViewLogs extends JViewLegacy /** * The pagination object. * - * @var JPagination + * @var Pagination * @since 1.0 */ protected $pagination; @@ -89,11 +94,11 @@ protected function addToolbar() if (JVERSION >= '3.0') { - JToolBarHelper::title(JText::_('COM_API_TITLE_LOGS'), 'list'); + JToolBarHelper::title(Text::_('COM_API_TITLE_LOGS'), 'list'); } else { - JToolBarHelper::title(JText::_('COM_API_TITLE_LOGS'), 'logs.png'); + JToolBarHelper::title(Text::_('COM_API_TITLE_LOGS'), 'logs.png'); } if ($canDo->get('core.edit.state')) @@ -141,11 +146,11 @@ protected function addToolbar() protected function getSortFields() { return array( - 'u.name' => JText::_('COM_API_LOGS_USER'), - 'a.hash' => JText::_('COM_API_KEYS_HASH'), - 'a.ip_address' => JText::_('COM_API_LOGS_IP_ADDRESS'), - 'a.time' => JText::_('COM_API_LOGS_TIME'), - 'a.request_method' => JText::_('COM_API_LOGS_REQUEST_METHOD') + 'u.name' => Text::_('COM_API_LOGS_USER'), + 'a.hash' => Text::_('COM_API_KEYS_HASH'), + 'a.ip_address' => Text::_('COM_API_LOGS_IP_ADDRESS'), + 'a.time' => Text::_('COM_API_LOGS_TIME'), + 'a.request_method' => Text::_('COM_API_LOGS_REQUEST_METHOD') ); } } diff --git a/code/api.xml b/code/api.xml index 8242ae5..6023500 100644 --- a/code/api.xml +++ b/code/api.xml @@ -1,13 +1,13 @@ com_api - 22nd Oct 2019 + 13th Jul 2022 Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL Techjoomla extensions@techjoomla.com https://techjoomla.com - 2.5.1 + 3.0.0 Multi-purpose REST API framework for Joomla diff --git a/code/plugins/authentication/tjapi/tjapi.php b/code/plugins/authentication/tjapi/tjapi.php index 10673f1..95a2c0a 100644 --- a/code/plugins/authentication/tjapi/tjapi.php +++ b/code/plugins/authentication/tjapi/tjapi.php @@ -9,12 +9,18 @@ defined('_JEXEC') or die('Unauthorized Access'); +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Authentication\Authentication; +use Joomla\CMS\Language\Text; +use Joomla\CMS\User\User; + /** * Class for Tjapi Authentication Plugin * * @since 1.0.0 */ -class PlgAuthenticationTjapi extends JPlugin +class PlgAuthenticationTjapi extends CMSPlugin { /** * Verify Api Key @@ -27,8 +33,8 @@ class PlgAuthenticationTjapi extends JPlugin public function verifyApiKey($userId, $key) { // Load table - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables'); - $table = JTable::getInstance('Key', 'ApiTable'); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables'); + $table = Table::getInstance('Key', 'ApiTable'); $table->load(array('userid' => $userId)); if ($key == $table->hash) @@ -59,8 +65,8 @@ public function onUserAuthenticate(&$credentials, $options, &$response) if (empty($uid) || empty($key)) { - $response->status = JAuthentication::STATUS_FAILURE; - $response->error_message = JText::_('JGLOBAL_AUTH_NO_USER'); + $response->status = Authentication::STATUS_FAILURE; + $response->error_message = Text::_('JGLOBAL_AUTH_NO_USER'); } else { @@ -70,7 +76,7 @@ public function onUserAuthenticate(&$credentials, $options, &$response) if ($match === true) { // Bring this in line with the rest of the authentication - $user = JUser::getInstance($uid); + $user = User::getInstance($uid); // Set response data. $response->username = $user->username; @@ -79,14 +85,14 @@ public function onUserAuthenticate(&$credentials, $options, &$response) $response->password = $user->password; $response->language = $user->getParam('language'); - $response->status = JAuthentication::STATUS_SUCCESS; + $response->status = Authentication::STATUS_SUCCESS; $response->error_message = ''; } else { // Invalid password - $response->status = JAuthentication::STATUS_FAILURE; - $response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS'); + $response->status = Authentication::STATUS_FAILURE; + $response->error_message = Text::_('JGLOBAL_AUTH_INVALID_PASS'); } } diff --git a/code/plugins/authentication/tjapi/tjapi.xml b/code/plugins/authentication/tjapi/tjapi.xml index 070c808..36e8d78 100644 --- a/code/plugins/authentication/tjapi/tjapi.xml +++ b/code/plugins/authentication/tjapi/tjapi.xml @@ -5,10 +5,10 @@ Techjoomla extensions@techjoomla.com https://techjoomla.com - 22nd Oct 2019 + 13th Jul 2022 Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - 2.5.1 + 3.0.0 tjapi.php diff --git a/code/plugins/system/tjtokenlogin/tjtokenlogin.php b/code/plugins/system/tjtokenlogin/tjtokenlogin.php index 39ff3a1..96a7d75 100644 --- a/code/plugins/system/tjtokenlogin/tjtokenlogin.php +++ b/code/plugins/system/tjtokenlogin/tjtokenlogin.php @@ -9,12 +9,17 @@ defined('_JEXEC') or die('Unauthorized Access'); -jimport('joomla.filesystem.file'); +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Router\Route; $jwtBasePath = JPATH_SITE . '/components/com_api/vendors/php-jwt/src'; $jwtFilePath = $jwtBasePath . '/JWT.php'; -if (!JFile::exists($jwtFilePath)) +if (!File::exists($jwtFilePath)) { return; } @@ -36,12 +41,12 @@ * * @since 1.0.0 */ -class PlgSystemTjtokenlogin extends JPlugin +class PlgSystemTjtokenlogin extends CMSPlugin { /** * Application object. * - * @var JApplicationCms + * @var CMSApplication * @since 1.0.0 */ protected $app; @@ -60,7 +65,7 @@ public function onAfterInitialise() // Get the application if not done by JPlugin. This may happen during upgrades from Joomla 2.5. if (!$this->app) { - $this->app = JFactory::getApplication(); + $this->app = Factory::getApplication(); } // No remember me for admin. @@ -70,7 +75,7 @@ public function onAfterInitialise() } // Get logintoken - $input = JFactory::getApplication()->input; + $input = Factory::getApplication()->input; $loginToken = $input->get->get('logintoken', '', 'STRING'); // If loginToken is not set, return @@ -99,8 +104,8 @@ public function onAfterInitialise() } // Load api key table - JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables'); - $table = JTable::getInstance('Key', 'ApiTable'); + Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables'); + $table = Table::getInstance('Key', 'ApiTable'); $table->load(array('userid' => $payload->id)); $key = $table->hash; @@ -129,7 +134,7 @@ public function onAfterInitialise() $redirect = $input->get->get('redirect', '', 'STRING'); $redirect = base64_decode($redirect); - $this->app->redirect(JRoute::_($redirect, false)); + $this->app->redirect(Route::_($redirect, false)); // } } diff --git a/code/plugins/system/tjtokenlogin/tjtokenlogin.xml b/code/plugins/system/tjtokenlogin/tjtokenlogin.xml index 0cd6028..4ea9f80 100644 --- a/code/plugins/system/tjtokenlogin/tjtokenlogin.xml +++ b/code/plugins/system/tjtokenlogin/tjtokenlogin.xml @@ -5,10 +5,10 @@ Techjoomla extensions@techjoomla.com https://techjoomla.com - 22nd Oct 2019 + 13th Jul 2022 Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL - 2.5.1 + 3.0.0 tjtokenlogin.php diff --git a/code/script.api.php b/code/script.api.php index cc56322..107470b 100644 --- a/code/script.api.php +++ b/code/script.api.php @@ -11,9 +11,11 @@ // No direct access. defined('_JEXEC') or die('Restricted access'); -jimport('joomla.filesystem.folder'); -jimport('joomla.filesystem.file'); -jimport('joomla.application.component.controller'); +use Joomla\CMS\Installer\Installer; +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Factory; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Filesystem\Folder; if (! defined('DS')) { @@ -91,7 +93,7 @@ public function preflight($type, $parent) * Runs after install, update or discover_update * * @param string $type install, update or discover_update - * @param JInstaller $parent parent + * @param Installer $parent parent * * @return mixed * @@ -121,7 +123,7 @@ public function install($parent) /** * Runs on uninstallation * - * @param JInstaller $parent parent + * @param Installer $parent parent * * @return mixed * @@ -159,9 +161,9 @@ private function renderPostInstallation() /** * Installs subextensions (modules, plugins) bundled with the main extension * - * @param JInstaller $parent parent + * @param Installer $parent parent * - * @return JObject The subextension installation status + * @return CMSObject The subextension installation status * * @since 1.0.0 */ @@ -169,9 +171,9 @@ private function installSubextensions($parent) { $src = $parent->getParent()->getPath('source'); - $db = JFactory::getDbo(); + $db = Factory::getDbo(); - $status = new JObject; + $status = new CMSObject; $status->modules = array(); $status->plugins = array(); @@ -224,7 +226,7 @@ private function installSubextensions($parent) $db->setQuery($sql); $count = $db->loadResult(); - $installer = new JInstaller; + $installer = new Installer; $result = $installer->install($path); $status->modules[] = array( 'name' => $module, 'client' => $folder, 'result' => $result, 'status' => $modulePreferences[1] @@ -345,7 +347,7 @@ private function installSubextensions($parent) $db->setQuery($query); $count = $db->loadResult(); - $installer = new JInstaller; + $installer = new Installer; $result = $installer->install($path); $status->plugins[] = array( @@ -384,7 +386,7 @@ private function installSubextensions($parent) $db->setQuery($query); $count = $db->loadResult(); - $installer = new JInstaller; + $installer = new Installer; $result = $installer->install($path); $status->libraries[] = array( @@ -424,12 +426,12 @@ protected function removeFilesAndFolders($removeList) { $file = JPATH_ROOT . '/' . $file; - if (!JFile::exists($file)) + if (!File::exists($file)) { continue; } - JFile::delete($file); + File::delete($file); } } @@ -439,12 +441,12 @@ protected function removeFilesAndFolders($removeList) { $folder = JPATH_ROOT . '/' . $folder; - if (!JFolder::exists($folder)) + if (!Folder::exists($folder)) { continue; } - JFolder::delete($folder); + Folder::delete($folder); } } } diff --git a/code/site/api.php b/code/site/api.php index e00504c..9cb22b2 100755 --- a/code/site/api.php +++ b/code/site/api.php @@ -11,7 +11,9 @@ */ defined('_JEXEC') or die('Restricted access'); -jimport('joomla.application.component.controller'); +use Joomla\CMS\Table\Table; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; $library_path = JPATH_COMPONENT . '/libraries'; @@ -32,11 +34,11 @@ JTable::addIncludePath(JPATH_ROOT . '/administrator/components/com_api/tables'); JLoader::discover('API', JPATH_COMPONENT . '/libraries/exceptions'); -$app = JFactory::getApplication(); +$app = Factory::getApplication(); $view = $app->input->get('view', '', 'CMD'); -if ($view) +if (in_array($view, array("api", "applogin", "documentation"))) { $c = $view; } @@ -55,7 +57,7 @@ else { // JError::raiseError(404, JText::_('COM_API_CONTROLLER_NOT_FOUND')); - throw new Exception(JText::_('COM_API_CONTROLLER_NOT_FOUND'), 404); + throw new Exception(Text::_('COM_API_CONTROLLER_NOT_FOUND'), 404); } $command = $app->input->get('task', 'display', 'CMD'); diff --git a/code/site/controllers/applogin.php b/code/site/controllers/applogin.php index e4dce70..803b353 100644 --- a/code/site/controllers/applogin.php +++ b/code/site/controllers/applogin.php @@ -10,6 +10,9 @@ defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\MVC\Controller\BaseController; + /** * Class for a Applogin Controller * @@ -24,9 +27,9 @@ class ApiControllerApplogin extends ApiController * you will need to override it in your own controllers. * * @param boolean $cachable If true, the view output will be cached - * @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \JFilterInput::clean()}. + * @param array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link \InputFilter::clean()}. * - * @return \JControllerLegacy A \JControllerLegacy object to support chaining. + * @return \BaseController A \BaseController object to support chaining. * * @since 3.0 */ diff --git a/code/site/controllers/documentation.php b/code/site/controllers/documentation.php index 788beab..4701190 100644 --- a/code/site/controllers/documentation.php +++ b/code/site/controllers/documentation.php @@ -10,8 +10,6 @@ defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.application.component.controller'); - class ApiControllerDocumentation extends ApiController { diff --git a/code/site/controllers/http.php b/code/site/controllers/http.php index f68c179..5afb853 100644 --- a/code/site/controllers/http.php +++ b/code/site/controllers/http.php @@ -11,8 +11,11 @@ */ defined('_JEXEC') or die('Restricted access'); -jimport('joomla.application.component.controller'); -jimport('joomla.plugin.helper'); +use Joomla\CMS\Filter\InputFilter; +use Joomla\CMS\Factory; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Uri\Uri; + /** * ApiControllerHttp class @@ -27,7 +30,7 @@ class ApiControllerHttp extends ApiController * Typical view method for MVC based architecture * * @param boolean $cachable If true, the view output will be cached - * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}. + * @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link InputFilter::clean()}. * * @return Mixed * @@ -36,15 +39,15 @@ class ApiControllerHttp extends ApiController public function display($cachable = false, $urlparams = array()) { $this->resetDocumentType(); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $name = $app->input->get('app', '', 'CMD'); - $params = JComponentHelper::getParams('com_api'); + $params = ComponentHelper::getParams('com_api'); $callMethod = $app->input->getMethod(); $httpOrigin = $app->input->server->getString('HTTP_REFERER', ''); - $JUriObj = JUri::getInstance($httpOrigin); - $referer = $JUriObj->toString(array('scheme', 'host', 'port')); + $UriObj = Uri::getInstance($httpOrigin); + $referer = $UriObj->toString(array('scheme', 'host', 'port')); // Special method for OPTIONS method if ((! empty($params->get("allow_cors")))) @@ -78,14 +81,16 @@ public function display($cachable = false, $urlparams = array()) try { - JResponse::setHeader('status', 200); + header("status: 200"); + //JResponse::setHeader('status', 200); $resource_response = ApiPlugin::getInstance($name)->fetchResource(); echo $this->respond($resource_response); } catch (Exception $e) { - JResponse::setHeader('status', $e->http_code); + header("status: " . $e->http_code); + //JResponse::setHeader('status', $e->http_code); echo $this->respond($e); } } @@ -101,7 +106,7 @@ public function display($cachable = false, $urlparams = array()) */ private function respond($response) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $accept = $app->input->server->get('HTTP_ACCEPT', 'application/json', 'STRING'); $compatibility = $app->input->server->get('HTTP_X_COMPATIBILITY_MODE', 0, 'INT'); @@ -170,6 +175,13 @@ private function respond($response) */ private function resetDocumentType() { - JResponse::clearHeaders(); + if (!headers_sent()) + { + foreach (headers_list() as $header) + { + header_remove($header); + } + } + //JResponse::clearHeaders(); } } diff --git a/code/site/defines.php b/code/site/defines.php index e87858c..93af439 100644 --- a/code/site/defines.php +++ b/code/site/defines.php @@ -9,11 +9,17 @@ // No direct access. defined('_JEXEC') or die(); +use Joomla\CMS\HTML\HTMLHelper; + // Define wrapper class define('COM_APIS_WRAPPER_CLASS', "api-wrapper"); -JHtml::_('behavior.tabstate'); -JHtml::_('behavior.tooltip'); -JHtml::_('bootstrap.tooltip'); -JHtml::_('behavior.multiselect'); -JHtml::_('formbehavior.chosen', 'select'); +if (JVERSION < '4.0.0') +{ + HTMLHelper::_('formbehavior.chosen', 'select'); + HTMLHelper::_('behavior.tabstate'); +} + +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('bootstrap.tooltip'); +HTMLHelper::_('behavior.multiselect'); diff --git a/code/site/libraries/admin/controller.php b/code/site/libraries/admin/controller.php index be65d5a..eefbe5f 100755 --- a/code/site/libraries/admin/controller.php +++ b/code/site/libraries/admin/controller.php @@ -10,7 +10,11 @@ defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.application.component.controller'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Session\Session; +use Joomla\CMS\Table\Table; + class ApiControllerAdmin extends ApiController { @@ -19,11 +23,11 @@ public function __construct($config=array()) { $this->registerTask('apply', 'save'); $this->registerTask('add', 'edit'); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $default_url = 'index.php?option='.$this->get('option'); - //$view = JRequest::getVar('view',''); + //$view = Factory::getApplication()->input->get('view',''); $view = $app->input->get('view','','STRING'); $task = $app->input->post->get('task','','STRING'); @@ -39,14 +43,14 @@ public function __construct($config=array()) { } public function display() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); - //$view = JRequest::getVar('view', ''); + //$view = Factory::getApplication()->input->get('view', ''); $view = $app->input->get('view','','STRING'); if (!$view) : - //JRequest::setVar('view', 'cpanel'); + //Factory::getApplication()->input->set('view', 'cpanel'); $app->input->set('view','cpanel'); endif; @@ -56,7 +60,7 @@ public function display() { } public function edit() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $view = $this->getEntityName(); $layout = 'default'; @@ -73,27 +77,27 @@ public function edit() { public function cancel() { //JRequest::checkToken() or jexit(JText::_('INVALID_TOKEN')); - JSession::checkToken() or jexit(JText::_('INVALID_TOKEN')); - $app = JFactory::getApplication(); - //$this->setRedirect(JRequest::getVar('ret', $this->get('default_url')), $msg); + Session::checkToken() or jexit(Text::_('INVALID_TOKEN')); + $app = Factory::getApplication(); + //$this->setRedirect(Factory::getApplication()->input->get('ret', $this->get('default_url')), $msg); $this->setRedirect($app->input->get('ret', $this->get('default_url'),'STRING'), $msg); } public function remove($hash='post') { - JSession::checkToken($hash) or jexit(JText::_('INVALID_TOKEN')); - $app = JFactory::getApplication(); + Session::checkToken($hash) or jexit(Text::_('INVALID_TOKEN')); + $app = Factory::getApplication(); $name = $this->getEntityName(); - //$post = JRequest::get('post'); + //$post = Factory::getApplication()->input->get('post'); $post = $app->input->post; $model = $this->getModel($name); - //$cid = JRequest::getVar('cid', array(), $hash, 'array'); + //$cid = Factory::getApplication()->input->get('cid', array(), $hash, 'array'); $cid = $app->input->post->get('cid',array(), 'ARRAY'); if (empty($cid)) : - //$cid = JRequest::getVar('id', 0, $hash, 'int'); + //$cid = Factory::getApplication()->input->get('id', 0, $hash, 'int'); $cid = $app->input->post->get('id', 0,'INT'); endif; @@ -102,11 +106,11 @@ public function remove($hash='post') { $msg = $model->getError(); $type = 'error'; else : - $msg = JText::_('COM_API_DELETE_SUCCESS'); + $msg = Text::_('COM_API_DELETE_SUCCESS'); $type = 'message'; endif; else : - $msg = JText::_('COM_API_NO_SELECTION'); + $msg = Text::_('COM_API_NO_SELECTION'); $type = 'error'; endif; @@ -115,9 +119,9 @@ public function remove($hash='post') { } public function save() { - JSession::checkToken() or jexit(JText::_('INVALID_TOKEN')); + Session::checkToken() or jexit(Text::_('INVALID_TOKEN')); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $name = $this->getEntityName(); @@ -139,14 +143,14 @@ public function save() { if (!$item = $model->save($post)) : $msg = $model->getError(); - //$url = JRequest::getVar('HTTP_REFERER', $this->get('default_url'), 'server'); + //$url = Factory::getApplication()->input->get('HTTP_REFERER', $this->get('default_url'), 'server'); $url = $app->input->server->get('HTTP_REFERER', $this->get('default_url'), 'STRING'); $this->setRedirect($url, $msg, 'error'); return; endif; $name = strtolower($name); - $msg = JText::_("COM_API_SAVE_SUCCESSFUL"); + $msg = Text::_("COM_API_SAVE_SUCCESSFUL"); if($this->getTask() == 'apply') : $url = "index.php?option=".$this->get('option')."&view=".$name."&cid[]=".$item->id; elseif (isset($post['ret'])) : @@ -160,9 +164,9 @@ public function save() { public function publish() { //JRequest::checkToken() or jexit(JText::_('INVALID_TOKEN')); - JSession::checkToken() or jexit(JText::_('INVALID_TOKEN')); + Session::checkToken() or jexit(Text::_('INVALID_TOKEN')); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->changeState(1); @@ -170,7 +174,7 @@ public function publish() { $msg = $error; $type = 'error'; else : - $msg = JText::_("COM_API_PUBLISH_SUCCESS"); + $msg = Text::_("COM_API_PUBLISH_SUCCESS"); $type = 'message'; endif; @@ -180,16 +184,16 @@ public function publish() { public function unpublish() { //JRequest::checkToken() or jexit(JText::_('INVALID_TOKEN')); - JSession::checkToken() or jexit(JText::_('INVALID_TOKEN')); + Session::checkToken() or jexit(Text::_('INVALID_TOKEN')); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->changeState(0); if ($error = $this->getError()) : $msg = $error; $type = 'error'; else : - $msg = JText::_("COM_API_UNPUBLISH_SUCCESS"); + $msg = Text::_("COM_API_UNPUBLISH_SUCCESS"); $type = 'message'; endif; @@ -198,7 +202,7 @@ public function unpublish() { protected function changeState($state, $cids=array(), $table_class=null) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); if (empty($cids)) : $cids = $app->input->post->get('cid', array(),'ARRAY'); @@ -206,7 +210,7 @@ protected function changeState($state, $cids=array(), $table_class=null) { $table_class = $table_class ? $table_class : $this->getEntityName(); - $table = JTable::getInstance($table_class, 'ApiTable'); + $table = Table::getInstance($table_class, 'ApiTable'); if (!$table->publish($cids, $state)) : $this->setError($table->getError()); diff --git a/code/site/libraries/authentication.php b/code/site/libraries/authentication.php index 63805a9..2ed1107 100644 --- a/code/site/libraries/authentication.php +++ b/code/site/libraries/authentication.php @@ -9,14 +9,20 @@ */ defined('_JEXEC') or die; -jimport('joomla.application.component.model'); + +use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\User\User; /** * Class for API authetication * * @since 1.0 */ -abstract class ApiAuthentication extends JObject +abstract class ApiAuthentication extends CMSObject { protected $auth_method = null; @@ -57,8 +63,8 @@ abstract public function authenticate(); */ public static function authenticateRequest() { - $params = JComponentHelper::getParams('com_api'); - $app = JFactory::getApplication(); + $params = ComponentHelper::getParams('com_api'); + $app = Factory::getApplication(); $className = 'APIAuthentication' . ucwords(self::getAuthMethod()); @@ -69,34 +75,36 @@ public static function authenticateRequest() { self::setAuthError($auth_handler->getError()); - return false; + return Factory::getUser(); } else { - $user = JFactory::getUser($user_id); + $user = Factory::getUser($user_id); if (!$user->id) { - self::setAuthError(JText::_("COM_API_USER_NOT_FOUND")); + self::setAuthError(Text::_("COM_API_USER_NOT_FOUND")); return false; } if ($user->block == 1) { - self::setAuthError(JText::_("COM_API_BLOCKED_USER")); + self::setAuthError(Text::_("COM_API_BLOCKED_USER")); return false; } /* V1.8.1 - to set admin info headers - $log_user = JFactory::getUser(); */ + $log_user = Factory::getUser(); */ $isroot = $user->authorise('core.admin'); if ($isroot) { - JResponse::setHeader('x-api', self::getCom_apiVersion()); - JResponse::setHeader('x-plugins', implode(',', self::getPluginsList())); + header("x-api: " . self::getCom_apiVersion()); + header("x-plugins: " . implode(',', self::getPluginsList())); + //JResponse::setHeader('x-api', self::getCom_apiVersion()); + //JResponse::setHeader('x-plugins', implode(',', self::getPluginsList())); } return $user; @@ -145,12 +153,12 @@ public static function getAuthError() */ public static function getPluginsList() { - $plugins = JPluginHelper::getPlugin('api'); + $plugins = PluginHelper::getPlugin('api'); $pluginsArr = array(); foreach ($plugins as $plg) { - $xml = JFactory::getXML(JPATH_SITE . '/plugins/api/' . $plg->name . '/' . $plg->name . '.xml'); + $xml = simplexml_load_file(JPATH_SITE . '/plugins/api/' . $plg->name . '/' . $plg->name . '.xml'); $version = (string) $xml->version; $pluginsArr[] = $plg->name . '-' . $version; } @@ -167,7 +175,7 @@ public static function getPluginsList() */ public static function getCom_apiVersion() { - $xml = JFactory::getXML(JPATH_ADMINISTRATOR . '/components/com_api/api.xml'); + $xml = simplexml_load_file(JPATH_ADMINISTRATOR . '/components/com_api/api.xml'); return $version = (string) $xml->version; } @@ -181,7 +189,7 @@ public static function getCom_apiVersion() */ private static function getAuthMethod() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $key = $app->input->get('key'); if (isset($_SERVER['HTTP_X_AUTH']) && $_SERVER['HTTP_X_AUTH']) @@ -283,7 +291,7 @@ private static function getAuthorizationHeader() */ public static function getImpersonateHeader() { - $jinput = JFactory::getApplication()->input; + $jinput = Factory::getApplication()->input; $xImpersonate = $jinput->server->get('X-Impersonate', '', 'STRING'); $httpXImpersonate = $jinput->server->get('HTTP_X_IMPERSONATE', '', 'STRING'); @@ -318,7 +326,7 @@ public static function getUserIdToImpersonate($tokenUserId) } // Get user from tokenUserId - $user = JFactory::getUser($tokenUserId); + $user = Factory::getUser($tokenUserId); $isSuperAdmin = $user->authorise('core.admin'); // If this user is not super admin user, return false @@ -346,7 +354,7 @@ public static function getUserIdToImpersonate($tokenUserId) } else { - ApiError::raiseError("400", JText::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); + ApiError::raiseError("400", Text::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); return false; } @@ -354,7 +362,7 @@ public static function getUserIdToImpersonate($tokenUserId) // If username or emailid exists ? if ($searchFor) { - $db = JFactory::getDbo(); + $db = Factory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__users')) @@ -367,7 +375,7 @@ public static function getUserIdToImpersonate($tokenUserId) } else { - ApiError::raiseError("400", JText::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); + ApiError::raiseError("400", Text::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); return false; } @@ -375,7 +383,7 @@ public static function getUserIdToImpersonate($tokenUserId) // If userid exists ? elseif ($userId) { - $table = JUser::getTable(); + $table = User::getTable(); if ($table->load($userId)) { @@ -383,7 +391,7 @@ public static function getUserIdToImpersonate($tokenUserId) } else { - ApiError::raiseError("400", JText::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); + ApiError::raiseError("400", Text::_('COM_API_INVALID_USER_TO_IMPERSONATE'), 'APIValidationException'); return false; } diff --git a/code/site/libraries/authentication/jfbconnect.php b/code/site/libraries/authentication/jfbconnect.php index cbdc911..b357bf1 100644 --- a/code/site/libraries/authentication/jfbconnect.php +++ b/code/site/libraries/authentication/jfbconnect.php @@ -19,8 +19,13 @@ // No direct access. defined('_JEXEC') or die('Restricted access'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\MVC\Model\BaseDatabaseModel; + /** * Jfbconnec ApiAuthentication class * @@ -43,18 +48,18 @@ public function authenticate() $this->validateInstall(); // Init vars - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $providerName = $app->input->json->get('provider', '', 'STRING'); $accessToken = $app->input->json->get('access_token', '', 'STRING'); if (empty($providerName)) { - ApiError::raiseError(400, JText::_('COM_API_JFBCONNECT_MISSING_PROVIDER')); + ApiError::raiseError(400, Text::_('COM_API_JFBCONNECT_MISSING_PROVIDER')); } if (empty($accessToken)) { - ApiError::raiseError(400, JText::_('COM_API_JFBCONNECT_MISSING_ACCESS_TOKEN')); + ApiError::raiseError(400, Text::_('COM_API_JFBCONNECT_MISSING_ACCESS_TOKEN')); } // Get provider object @@ -68,7 +73,7 @@ public function authenticate() } catch (Exception $e) { - ApiError::raiseError(400, JText::_('api auth error')); + ApiError::raiseError(400, Text::_('api auth error')); }*/ /*echo '
provider class is: ' . get_class($provider); @@ -97,16 +102,15 @@ public function authenticate() */ private function validateInstall() { - jimport('joomla.filesystem.file'); // Check if JFB is installed and enabled - if (JFile::exists(JPATH_ROOT . '/components/com_jfbconnect/jfbconnect.php') - && JComponentHelper::isEnabled('com_jfbconnect', true)) + if (File::exists(JPATH_ROOT . '/components/com_jfbconnect/jfbconnect.php') + && ComponentHelper::isEnabled('com_jfbconnect', true)) { return true; } - ApiError::raiseError(500, JText::_('PLG_API_JFBCONNECT_NOT_INSTALLED')); + ApiError::raiseError(500, Text::_('PLG_API_JFBCONNECT_NOT_INSTALLED')); return false; } @@ -129,7 +133,7 @@ private function jfbGetProvider($providerName) if (empty($provider->name)) { - ApiError::raiseError(500, JText::_('Invalid provider')); + ApiError::raiseError(500, Text::_('Invalid provider')); } return $provider; @@ -185,7 +189,7 @@ private function jfbRegisterUser($provider) { // Declare vars needed for JFB code to work BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_jfbconnect/models'); - $loginRegisterModel = JModelLegacy::getInstance('LoginRegister', 'JFBConnectModel'); + $loginRegisterModel = BaseDatabaseModel::getInstance('LoginRegister', 'JFBConnectModel'); $userMapModel = JFBCFactory::usermap(); $providerUserId = $provider->getProviderUserId(); $jUserId = 0; @@ -215,14 +219,14 @@ private function jfbRegisterUser($provider) if ($userMapModel->map($jUserEmailId, $providerUserId, strtolower($provider->name), $provider->client->getToken())) { - JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name)); + JFBCFactory::log(Text::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name)); // Update the temp jId so that we login below $jUserId = $jUserEmailId; } else { - JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name)); + JFBCFactory::log(Text::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name)); } } } @@ -234,13 +238,13 @@ private function jfbRegisterUser($provider) * !allowUserRegistration and !social_registration => registration not allowed * !allowUserRegistration and social_registration => registration allowed * allowUserRegistration and !social_registration => registration not allowed - * JComponentHelper::getParams('com_users')->get('allowUserRegistration') check is not needed since + * ComponentHelper::getParams('com_users')->get('allowUserRegistration') check is not needed since * we prioritized the JFBConnect social registration config */ if (JFBCFactory::config()->getSetting('social_registration') == 0 && !$jUserId) { - JFBCFactory::log(JText::_('COM_JFBCONNECT_MSG_USER_REGISTRATION_DISABLED'), 'notice'); + JFBCFactory::log(Text::_('COM_JFBCONNECT_MSG_USER_REGISTRATION_DISABLED'), 'notice'); // Commmented code below for com_api plugin diff --git a/code/site/libraries/authentication/key.php b/code/site/libraries/authentication/key.php index 37cd788..55faa91 100755 --- a/code/site/libraries/authentication/key.php +++ b/code/site/libraries/authentication/key.php @@ -9,7 +9,10 @@ */ defined('_JEXEC') or die; -jimport('joomla.application.component.model'); + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Table\Table; /** * API resource class @@ -29,7 +32,7 @@ class ApiAuthenticationKey extends ApiAuthentication */ public function authenticate() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $query_token = $app->input->get('key', '', 'STRING'); $header_token = $this->getBearerToken(); $key = $header_token ? $header_token : $query_token; @@ -47,7 +50,7 @@ public function authenticate() return $token->userid; } - $this->setError(JText::_('COM_API_KEY_NOT_FOUND')); + $this->setError(Text::_('COM_API_KEY_NOT_FOUND')); return false; } @@ -61,7 +64,7 @@ public function authenticate() */ public function loadTokenByHash($hash) { - $table = JTable::getInstance('Key', 'ApiTable'); + $table = Table::getInstance('Key', 'ApiTable'); $table->loadByHash($hash); return $table; diff --git a/code/site/libraries/authentication/login.php b/code/site/libraries/authentication/login.php index e1bfe98..6d1b479 100755 --- a/code/site/libraries/authentication/login.php +++ b/code/site/libraries/authentication/login.php @@ -10,6 +10,11 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Authentication\Authentication; +use Joomla\CMS\User\UserHelper; +use Joomla\CMS\Uri\Uri; + /** * ApiAuthenticationLogin class. * @@ -30,7 +35,7 @@ class ApiAuthenticationLogin extends ApiAuthentication */ public function authenticate() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $username = $app->input->post->get('username', '', 'STRING'); $password = $app->input->post->get('password', '', 'STRING'); @@ -38,7 +43,7 @@ public function authenticate() $userId = $this->loadUserByCredentials($username, $password); // Remove username and password from request for when it gets logged - $uri = JFactory::getURI(); + $uri = Uri::getInstance(); $uri->delVar('username'); $uri->delVar('password'); @@ -64,15 +69,14 @@ public function authenticate() */ public function loadUserByCredentials($user, $pass) { - jimport('joomla.user.authentication'); - $authenticate = JAuthentication::getInstance(); + $authenticate = Authentication::getInstance(); $response = $authenticate->authenticate(array('username' => $user, 'password' => $pass), $options = array()); - if ($response->status === JAuthentication::STATUS_SUCCESS) + if ($response->status === Authentication::STATUS_SUCCESS) { - $userId = JUserHelper::getUserId($response->username); + $userId = UserHelper::getUserId($response->username); if ($userId === false) { diff --git a/code/site/libraries/authentication/session.php b/code/site/libraries/authentication/session.php index e0bd694..284a0bd 100644 --- a/code/site/libraries/authentication/session.php +++ b/code/site/libraries/authentication/session.php @@ -11,7 +11,9 @@ */ defined('_JEXEC') or die(); -jimport('joomla.application.component.model'); + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; /** * API user authentication @@ -33,12 +35,12 @@ class ApiAuthenticationSession extends ApiAuthentication */ public function authenticate() { - $app = JFactory::getApplication(); - $user = JFactory::getUser(); + $app = Factory::getApplication(); + $user = Factory::getUser(); if (! $user->id) { - $this->setError(JText::_('COM_API_LOGIN_MSG')); + $this->setError(Text::_('COM_API_LOGIN_MSG')); return false; } diff --git a/code/site/libraries/authentication/user.php b/code/site/libraries/authentication/user.php index d0ac983..b7c0841 100755 --- a/code/site/libraries/authentication/user.php +++ b/code/site/libraries/authentication/user.php @@ -10,6 +10,10 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Authentication\Authentication; +use Joomla\CMS\User\User; + class ApiAuthenticationUser extends ApiAuthentication { protected $auth_method = null; @@ -17,18 +21,18 @@ class ApiAuthenticationUser extends ApiAuthentication public function authenticate() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $username = $app->input->post->get('username','','STRING'); $password = $app->input->post->get('password','','STRING'); - //$username = JRequest::getVar( 'username' ); - //$password = JRequest::getVar( 'password' ); + //$username = Factory::getApplication()->input->get( 'username' ); + //$password = Factory::getApplication()->input->get( 'password' ); $user = $this->loadUserByCredentials( $username, $password ); // Remove username and password from request for when it gets logged - $uri = JFactory::getURI(); + $uri = Factory::getURI(); $uri->delVar('username'); $uri->delVar('password'); @@ -42,13 +46,12 @@ public function authenticate() public function loadUserByCredentials( $user, $pass ) { - jimport('joomla.user.authentication'); - $authenticate = JAuthentication::getInstance(); + $authenticate = Authentication::getInstance(); $response = $authenticate->authenticate(array( 'username' => $user, 'password' => $pass )); - if ($response->status === JAuthentication::STATUS_SUCCESS) { - $instance = JUser::getInstance($response->username); + if ($response->status === Authentication::STATUS_SUCCESS) { + $instance = User::getInstance($response->username); if ( $instance === false ) { $this->setError( JError::getError() ); return false; diff --git a/code/site/libraries/cache.php b/code/site/libraries/cache.php index 0e5edfd..73b938b 100755 --- a/code/site/libraries/cache.php +++ b/code/site/libraries/cache.php @@ -10,6 +10,8 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; + class APICache { const CACHE_GROUP = 'com_api'; @@ -20,11 +22,11 @@ class APICache { public static function callback($object, $method, $args=array(), $cache_lifetime=null, $overrideConfig=false) { - $conf = JFactory::getConfig(); + $conf = Factory::getConfig(); $cacheactive = $conf->getValue('config.caching'); $cachetime = $conf->getValue('config.cachetime'); - $cache= & JFactory::getCache(self::CACHE_GROUP,'callback'); + $cache= & Factory::getCache(self::CACHE_GROUP,'callback'); if ($overrideConfig) : $cache->setCaching(1); //enable caching diff --git a/code/site/libraries/controller.php b/code/site/libraries/controller.php index 504eac9..db961f5 100755 --- a/code/site/libraries/controller.php +++ b/code/site/libraries/controller.php @@ -10,11 +10,13 @@ defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.application.component.controller'); -jimport('joomla.application.component.modellist'); +use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Table\Table; //class ApiController extends JController { -class ApiController extends JControllerLegacy { +class ApiController extends BaseController { /** * Base Controller Constructor @@ -27,13 +29,11 @@ class ApiController extends JControllerLegacy { public function __construct($config=array()) { parent::__construct(); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); - $this->set('option', $app->input->get('option','','STRING')); - - JModelList::addIncludePath(JPATH_SITE.'/components/com_api/models'); - JTable::addIncludePath(JPATH_ROOT.'/administrator/components/com_api/tables'); + $this->option = $app->input->get('option','','STRING'); + ListModel::addIncludePath(JPATH_SITE.'/components/com_api/models'); + Table::addIncludePath(JPATH_ROOT.'/administrator/components/com_api/tables'); } - } diff --git a/code/site/libraries/helper.php b/code/site/libraries/helper.php index f26d949..d8f98e0 100755 --- a/code/site/libraries/helper.php +++ b/code/site/libraries/helper.php @@ -10,6 +10,9 @@ defined( '_JEXEC' ) or die( 'Restricted access' ); +use Joomla\CMS\Factory; +use Joomla\CMS\User\User; + class APIHelper { function getAPIUserID() @@ -25,13 +28,13 @@ function getAPIUserID() function setSessionUser() { - $session =& JFactory::getSession(); - $session->set( 'user', JUser::getInstance( APIHelper::getAPIUserID() ) ); + $session =& Factory::getSession(); + $session->set( 'user', User::getInstance( APIHelper::getAPIUserID() ) ); } function unsetSessionUser() { - $session =& JFactory::getSession(); + $session =& Factory::getSession(); $session->clear( 'user' ); } } diff --git a/code/site/libraries/model.php b/code/site/libraries/model.php index aaf58c7..bc76618 100755 --- a/code/site/libraries/model.php +++ b/code/site/libraries/model.php @@ -10,9 +10,10 @@ defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.application.component.model'); +use Joomla\CMS\MVC\Model\BaseDatabaseModel; +use Joomla\CMS\Pagination\Pagination; -class ApiModel extends JModelLegacy { +class ApiModel extends BaseDatabaseModel { public function __construct($config=array()) { parent::__construct($config); @@ -25,8 +26,7 @@ public function getPagination() { endif; if (empty($this->pagination)) { - jimport('joomla.html.pagination'); - $this->pagination = new JPagination($this->get('total'), $this->getState('limitstart'), $this->getState('limit')); + $this->pagination = new Pagination($this->get('total'), $this->getState('limitstart'), $this->getState('limit')); } return $this->pagination; } diff --git a/code/site/libraries/plugin.php b/code/site/libraries/plugin.php index 29e3d6c..50b8b20 100755 --- a/code/site/libraries/plugin.php +++ b/code/site/libraries/plugin.php @@ -12,10 +12,14 @@ defined('_JEXEC') or die('Restricted access'); -jimport('joomla.plugin.plugin'); -jimport('joomla.filesystem.file'); -jimport('joomla.application.component.helper'); - +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Table\Table; +use Joomla\CMS\User\User; use Joomla\Registry\Registry; /** @@ -24,7 +28,7 @@ * * @since 1.0 */ -class ApiPlugin extends JPlugin +class ApiPlugin extends CMSPlugin { protected $user = null; @@ -69,49 +73,54 @@ class ApiPlugin extends JPlugin */ public static function getInstance($name) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $param_path = JPATH_BASE . self::$plg_path . $name . '.xml'; - $plugin = JPluginHelper::getPlugin('api', $name); + $plugin = PluginHelper::getPlugin('api', $name); + PluginHelper::importPlugin("api"); if (isset(self::$instances[$name])) { return self::$instances[$name]; } - if (version_compare(JVERSION, '3.0', 'ge')) + if (version_compare(JVERSION, '4.0', 'ge')) { - $dispatcher = JDispatcher::getInstance(); + $dispatcher = $app->getDispatcher(); } - else + else if (version_compare(JVERSION, '3.0', 'ge')) { $dispatcher = JEventDispatcher::getInstance(); + } + else + { self::$plg_path = self::$plg_path . $plugin->name . '/'; } if (empty($plugin)) { - ApiError::raiseError(400, JText::sprintf('COM_API_PLUGIN_CLASS_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); + ApiError::raiseError(400, Text::sprintf('COM_API_PLUGIN_CLASS_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); } $plgfile = JPATH_BASE . self::$plg_path . $name . '/' . $name . '.php'; - if (! JFile::exists($plgfile)) + if (!File::exists($plgfile)) { - ApiError::raiseError(400, JText::sprintf('COM_API_FILE_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); + ApiError::raiseError(400, Text::sprintf('COM_API_FILE_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); } include_once $plgfile; $class = self::$plg_prefix . ucwords($name); - if (! class_exists($class)) + if (!class_exists($class)) { - ApiError::raiseError(400, JText::sprintf('COM_API_PLUGIN_CLASS_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); + ApiError::raiseError(400, Text::sprintf('COM_API_PLUGIN_CLASS_NOT_FOUND', ucfirst($name)), 'APINotFoundException'); } - $cparams = JComponentHelper::getParams('com_api'); + $cparams = ComponentHelper::getParams('com_api'); + $enabled = PluginHelper::isEnabled("api", $name); + $handler = new $class($dispatcher, array('params' => $cparams)); $handler->set('params', $cparams); - $call_methd = $app->input->server->get('REQUEST_METHOD', '', 'STRING'); // Switch case for differ calling method @@ -284,8 +293,9 @@ final public function fetchResource($resource_name = null) } $user = APIAuthentication::authenticateRequest(); + $this->set('user', $user); - $session = JFactory::getSession(); + $session = Factory::getSession(); $session->set('user', $user); $access = $this->getResourceAccess($resource_name, $this->request_method); @@ -297,7 +307,7 @@ final public function fetchResource($resource_name = null) if (! $this->checkRequestLimit()) { - ApiError::raiseError(403, JText::_('COM_API_RATE_LIMIT_EXCEEDED'), 'APIUnauthorisedException'); + ApiError::raiseError(403, Text::_('COM_API_RATE_LIMIT_EXCEEDED'), 'APIUnauthorisedException'); } $this->lastUsed(); @@ -327,12 +337,12 @@ final private function checkInternally($resource_name) { if (! method_exists($this, $resource_name)) { - ApiError::raiseError(404, JText::sprintf('COM_API_PLUGIN_METHOD_NOT_FOUND', ucfirst($resource_name)), 'APINotFoundException'); + ApiError::raiseError(404, Text::sprintf('COM_API_PLUGIN_METHOD_NOT_FOUND', ucfirst($resource_name)), 'APINotFoundException'); } if (! is_callable(array($this, $resource_name))) { - ApiError::raiseError(404, JText::sprintf('COM_API_PLUGIN_METHOD_NOT_CALLABLE', ucfirst($resource_name)), 'APINotFoundException'); + ApiError::raiseError(404, Text::sprintf('COM_API_PLUGIN_METHOD_NOT_CALLABLE', ucfirst($resource_name)), 'APINotFoundException'); } return true; @@ -347,7 +357,7 @@ final private function checkInternally($resource_name) */ final private function checkRequestLimit() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $limit = $this->params->get('request_limit', 0); if ($limit == 0) @@ -378,7 +388,7 @@ final private function checkRequestLimit() $query_time = time() - $offset; - $db = JFactory::getDBO(); + $db = Factory::getDBO(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from($db->quoteName('#__api_logs')); @@ -413,14 +423,14 @@ final private function log() return; } - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // For exclude password from log - $params = JComponentHelper::getParams('com_api'); + $params = ComponentHelper::getParams('com_api'); $excludes = $params->get('exclude_log'); $raw_post = file_get_contents('php://input'); $redactions = explode(",", $excludes); - $req_url = JURI::current() . '?' . JFactory::getURI()->getQuery(); + $req_url = Uri::current() . '?' . Factory::getURI()->getQuery(); switch ($app->input->server->get('CONTENT_TYPE')) { @@ -446,8 +456,8 @@ final private function log() break; } - $table = JTable::getInstance('Log', 'ApiTable'); - $date = JFactory::getDate(); + $table = Table::getInstance('Log', 'ApiTable'); + $date = Factory::getDate(); $table->hash = $app->input->get('key', '', 'STRING'); $table->ip_address = $app->input->server->get('REMOTE_ADDR', '', 'STRING'); $table->time = $date->toSql(); @@ -467,8 +477,8 @@ final private function log() */ final private function lastUsed() { - $app = JFactory::getApplication(); - $table = JTable::getInstance('Key', 'ApiTable'); + $app = Factory::getApplication(); + $table = Table::getInstance('Key', 'ApiTable'); $hash = $app->input->get('key', '', 'STRING'); $table->setLastUsed($hash); @@ -485,6 +495,12 @@ final private function lastUsed() */ public function setResponse($data) { + // For backward compatability -- TODO + if (!isset($data->result)) + { + $data->result = clone $data; + } + $this->set('response', $data); } @@ -509,7 +525,7 @@ public function setApiResponse($error, $data) if ($error) { $result->err_code = $this->err_code; - $result->err_message = JText::_($this->err_message); + $result->err_message = Text::_($this->err_message); } else { @@ -528,7 +544,7 @@ public function setApiResponse($error, $data) */ public function encode() { - $document = JFactory::getDocument(); + $document = Factory::getDocument(); $document->setMimeEncoding($this->format); $format_name = $this->content_types[$this->format]; @@ -536,12 +552,12 @@ public function encode() if (! method_exists($this, $method)) { - ApiError::raiseError(406, JText::_('COM_API_PLUGIN_NO_ENCODER')); + ApiError::raiseError(406, Text::_('COM_API_PLUGIN_NO_ENCODER')); } if (! is_callable(array($this, $method))) { - ApiError::raiseError(404, JText::_('COM_API_PLUGIN_NO_ENCODER')); + ApiError::raiseError(404, Text::_('COM_API_PLUGIN_NO_ENCODER')); } return $this->$method(); @@ -550,10 +566,35 @@ public function encode() /** * Method to get current logged in API user * - * @return JUser + * @return User */ public function getUser() { return $this->user; } + + /** + * Method to get value of the property + * + * @return User + */ + public function get($property, $default = null) + { + if (!isset($this->$property)) + { + return $default; + } + + return $this->$property; + } + + /** + * Method to set value of the property + * + * @return User + */ + public function set($property, $value = null) + { + $this->$property = $value; + } } diff --git a/code/site/libraries/resource.php b/code/site/libraries/resource.php index 2b14404..032ae45 100755 --- a/code/site/libraries/resource.php +++ b/code/site/libraries/resource.php @@ -10,7 +10,9 @@ defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.plugin.plugin'); +use Joomla\CMS\Language\Text; +use Joomla\CMS\Filesystem\Path; + abstract class ApiResource { @@ -30,7 +32,7 @@ final public function invoke() { $this->$method_name(); else : - ApiError::raiseError(404, JText::_('COM_API_PLUGIN_METHOD_NOT_FOUND')); + ApiError::raiseError(404, Text::_('COM_API_PLUGIN_METHOD_NOT_FOUND')); endif; } @@ -39,7 +41,7 @@ final public static function getInstance($name, ApiPlugin $plugin, $prefix=null) if (is_null($prefix)) { - $prefix = $plugin->get('component').'ApiResource'; + $prefix = $plugin->get('component') . 'ApiResource'; } $type = preg_replace('/[^A-Z0-9_\.-]/i', '', $name); @@ -47,8 +49,7 @@ final public static function getInstance($name, ApiPlugin $plugin, $prefix=null) if (!class_exists( $resourceClass )) { - jimport('joomla.filesystem.path'); - if($path = JPath::find(self::addIncludePath(), strtolower($type).'.php')) + if($path = Path::find(self::addIncludePath(), strtolower($type).'.php')) { require_once $path; diff --git a/code/site/libraries/response/jsonresponse.php b/code/site/libraries/response/jsonresponse.php index 369c9b3..de43335 100644 --- a/code/site/libraries/response/jsonresponse.php +++ b/code/site/libraries/response/jsonresponse.php @@ -8,6 +8,8 @@ * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) */ +use Joomla\CMS\Factory; + /** * Class APIJSONResponse to convert the response of API in json * @@ -38,7 +40,7 @@ class APIJSONResponse */ public function __construct($response) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->data = new \stdClass; if ($response instanceof Exception) @@ -75,7 +77,7 @@ public function __construct($response) */ public function __toString() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $callback = $app->input->get($this->callbackname, '', 'CMD'); if ($callback) diff --git a/code/site/libraries/response/xmlresponse.php b/code/site/libraries/response/xmlresponse.php index 92524dd..3a5f77e 100644 --- a/code/site/libraries/response/xmlresponse.php +++ b/code/site/libraries/response/xmlresponse.php @@ -8,6 +8,8 @@ * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) */ +use Joomla\CMS\Factory; + /** * Class APIXMLResponse to convert the response of API in XML * @@ -36,7 +38,7 @@ class APIXMLResponse */ public function __construct($response) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->data = new \stdClass; if ($response instanceof Exception) diff --git a/code/site/libraries/view.php b/code/site/libraries/view.php index 9183040..e3138f1 100755 --- a/code/site/libraries/view.php +++ b/code/site/libraries/view.php @@ -10,9 +10,11 @@ defined('_JEXEC') or die; -jimport('joomla.application.component.view'); +use Joomla\CMS\MVC\View\HtmlView; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; -class ApiView extends JViewLegacy { +class ApiView extends HtmlView { protected $option = null; protected $view = null; @@ -20,7 +22,7 @@ class ApiView extends JViewLegacy { function __construct() { //vishal - for j3.2 changes - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $option = $app->input->get('option','','STRING'); @@ -29,8 +31,8 @@ function __construct() { } public function display($tpl = null) { - $app = JFactory::getApplication(); - if ($app->isAdmin()) : + $app = Factory::getApplication(); + if ($app->isClient("administrator")) : $this->generateSubmenu(); endif; @@ -49,8 +51,8 @@ private function generateSubmenu() { protected function getMainViews() { $views = array( - array('name' => JText::_('COM_API_CONTROL_PANEL'), 'view' => 'cpanel'), - array('name' => JText::_('COM_API_KEYS'), 'view' => 'keys'), + array('name' => Text::_('COM_API_CONTROL_PANEL'), 'view' => 'cpanel'), + array('name' => Text::_('COM_API_KEYS'), 'view' => 'keys'), ); return $views; } diff --git a/code/site/models/documentation.php b/code/site/models/documentation.php index 42bcf3f..4943a1e 100644 --- a/code/site/models/documentation.php +++ b/code/site/models/documentation.php @@ -9,9 +9,11 @@ */ defined('_JEXEC') or die; -jimport('joomla.application.component.model'); -jimport('joomla.filesystem.folder'); -jimport('joomla.filesystem.file'); + +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Filesystem\File; class ApiModelDocumentation extends ApiModel { @@ -28,7 +30,7 @@ public function __construct() { parent::__construct(); - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->option = $app->input->get('option','','CMD'); $this->view = $app->input->get('view','','CMD'); @@ -39,7 +41,7 @@ public function __construct() protected function populateState() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $search = $app->getUserStateFromRequest($this->context.'.filter.search', 'filter_search', '', 'string'); $this->setState('filter.search', $search); @@ -58,18 +60,17 @@ protected function populateState() } public function getList($override=false, $filter=true) { - JPluginHelper::importPlugin('api'); + PluginHelper::importPlugin('api'); - $dispatcher = JEventDispatcher::getInstance(); $api_paths = ApiResource::addIncludePath(); $methods = array ('get', 'post', 'put', 'delete', 'head'); foreach ($api_paths as $path) { - $resources = JFolder::files($path); + $resources = Folder::files($path); foreach ($resources as $resource) { $item = new stdClass; $item->app = basename($path); - $item->resource = JFile::stripExt(basename($resource)); + $item->resource = File::stripExt(basename($resource)); $class_name = ucfirst($item->app) . 'ApiResource' . ucfirst($item->resource); require_once $path . '/' . $resource; diff --git a/code/site/router.php b/code/site/router.php index ddccdff..9e6e270 100755 --- a/code/site/router.php +++ b/code/site/router.php @@ -10,12 +10,14 @@ defined('_JEXEC') or die; +use Joomla\CMS\Component\Router\RouterBase; + /** * Routing class from com_api * * @since 2.0.1 */ -class APIRouter extends JComponentRouterBase +class APIRouter extends RouterBase { private $views = array('documentation','applogin', 'keys'); diff --git a/code/site/views/applogin/tmpl/default.php b/code/site/views/applogin/tmpl/default.php index f95a2b2..2181f61 100644 --- a/code/site/views/applogin/tmpl/default.php +++ b/code/site/views/applogin/tmpl/default.php @@ -10,11 +10,13 @@ defined('_JEXEC') or die('Restricted access'); -$base_url = JUri::base(); -$formToken = JSession::getFormToken(); +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Session\Session; + +$base_url = Uri::base(); +$formToken = Session::getFormToken(); $url = base64_encode($base_url.'tjlogin-registration'); -// @use Joomla\CMS\Uri\Uri; ?>