From b318b68d07e4c223b93b8887bb04af290b0cef76 Mon Sep 17 00:00:00 2001 From: Tuan Pham Ngoc Date: Sat, 19 Jun 2021 21:17:09 +0700 Subject: [PATCH] Make weblinks 4.0-compatible --- .../com_weblinks/helpers/weblinks.php | 148 +-------- .../com_weblinks/services/provider.php | 53 +-- .../Controller/DisplayController.php | 11 +- .../Controller/WeblinkController.php | 20 +- .../Controller/WeblinksController.php | 0 .../{ => src}/Extension/WeblinksComponent.php | 15 +- .../{ => src}/Field/Modal/WeblinkField.php | 0 .../src/Helper/AssociationsHelper.php | 210 ++++++++++++ .../src/Helper/WeblinksHelper.php | 24 ++ .../{ => src}/Model/WeblinkModel.php | 89 +++-- .../{ => src}/Model/WeblinksModel.php | 16 +- .../{ => src}/Table/WeblinkTable.php | 57 +++- .../{ => src}/View/Weblink/HtmlView.php | 60 ++-- .../{ => src}/View/Weblinks/HtmlView.php | 99 ++++-- .../com_weblinks/tmpl/weblink/edit.php | 23 +- .../com_weblinks/tmpl/weblinks/default.php | 307 +++++++++--------- .../weblinks}/default_batch_body.php | 11 +- .../weblinks}/default_batch_footer.php | 0 .../components/com_weblinks/weblinks.xml | 2 +- .../{models => }/forms/weblink.xml | 2 +- .../com_weblinks/helpers/category.php | 33 -- src/components/com_weblinks/helpers/route.php | 271 ---------------- src/components/com_weblinks/metadata.xml | 3 - src/components/com_weblinks/router.php | 295 ----------------- .../Controller/DisplayController.php} | 13 +- .../Controller/WeblinkController.php} | 46 +-- .../Helper/AssociationHelper.php} | 20 +- .../com_weblinks/src/Helper/RouteHelper.php | 115 +++++++ .../Model/CategoriesModel.php} | 26 +- .../Model/CategoryModel.php} | 46 ++- .../form.php => src/Model/FormModel.php} | 32 +- .../Model/WeblinkModel.php} | 39 ++- .../com_weblinks/src/Service/Category.php | 37 +++ .../com_weblinks/src/Service/Router.php | 298 +++++++++++++++++ .../src/View/Categories/HtmlView.php | 34 ++ .../View/Category/FeedView.php} | 6 +- .../src/View/Category/HtmlView.php | 114 +++++++ .../View/Form/HtmlView.php} | 71 ++-- .../View/Weblink/HtmlView.php} | 2 + .../tmpl => tmpl/categories}/default.php | 1 - .../tmpl => tmpl/categories}/default.xml | 0 .../categories}/default_items.php | 4 +- .../tmpl => tmpl/category}/default.php | 0 .../tmpl => tmpl/category}/default.xml | 0 .../category}/default_children.php | 0 .../tmpl => tmpl/category}/default_items.php | 8 +- .../{views => tmpl}/category/metadata.xml | 0 .../{views/form/tmpl => tmpl/form}/edit.php | 10 +- .../{views/form/tmpl => tmpl/form}/edit.xml | 0 .../{views => tmpl}/form/metadata.xml | 0 .../weblink/tmpl => tmpl/weblink}/default.php | 0 .../weblink/tmpl => tmpl/weblink}/default.xml | 0 .../views/categories/view.html.php | 83 ----- .../com_weblinks/views/category/view.html.php | 105 ------ src/components/com_weblinks/weblinks.php | 16 - 55 files changed, 1463 insertions(+), 1412 deletions(-) rename src/administrator/components/com_weblinks/{ => src}/Controller/DisplayController.php (86%) rename src/administrator/components/com_weblinks/{ => src}/Controller/WeblinkController.php (85%) rename src/administrator/components/com_weblinks/{ => src}/Controller/WeblinksController.php (100%) rename src/administrator/components/com_weblinks/{ => src}/Extension/WeblinksComponent.php (72%) rename src/administrator/components/com_weblinks/{ => src}/Field/Modal/WeblinkField.php (100%) create mode 100644 src/administrator/components/com_weblinks/src/Helper/AssociationsHelper.php create mode 100644 src/administrator/components/com_weblinks/src/Helper/WeblinksHelper.php rename src/administrator/components/com_weblinks/{ => src}/Model/WeblinkModel.php (81%) rename src/administrator/components/com_weblinks/{ => src}/Model/WeblinksModel.php (96%) rename src/administrator/components/com_weblinks/{ => src}/Table/WeblinkTable.php (76%) rename src/administrator/components/com_weblinks/{ => src}/View/Weblink/HtmlView.php (64%) rename src/administrator/components/com_weblinks/{ => src}/View/Weblinks/HtmlView.php (63%) rename src/administrator/components/com_weblinks/{views/weblinks/tmpl => tmpl/weblinks}/default_batch_body.php (69%) rename src/administrator/components/com_weblinks/{views/weblinks/tmpl => tmpl/weblinks}/default_batch_footer.php (100%) rename src/components/com_weblinks/{models => }/forms/weblink.xml (97%) delete mode 100644 src/components/com_weblinks/helpers/category.php delete mode 100644 src/components/com_weblinks/helpers/route.php delete mode 100644 src/components/com_weblinks/metadata.xml delete mode 100644 src/components/com_weblinks/router.php rename src/components/com_weblinks/{controller.php => src/Controller/DisplayController.php} (79%) rename src/components/com_weblinks/{controllers/weblink.php => src/Controller/WeblinkController.php} (82%) rename src/components/com_weblinks/{helpers/association.php => src/Helper/AssociationHelper.php} (54%) create mode 100644 src/components/com_weblinks/src/Helper/RouteHelper.php rename src/components/com_weblinks/{models/categories.php => src/Model/CategoriesModel.php} (86%) rename src/components/com_weblinks/{models/category.php => src/Model/CategoryModel.php} (87%) rename src/components/com_weblinks/{models/form.php => src/Model/FormModel.php} (72%) rename src/components/com_weblinks/{models/weblink.php => src/Model/WeblinkModel.php} (82%) create mode 100644 src/components/com_weblinks/src/Service/Category.php create mode 100644 src/components/com_weblinks/src/Service/Router.php create mode 100644 src/components/com_weblinks/src/View/Categories/HtmlView.php rename src/components/com_weblinks/{views/category/view.feed.php => src/View/Category/FeedView.php} (77%) create mode 100644 src/components/com_weblinks/src/View/Category/HtmlView.php rename src/components/com_weblinks/{views/form/view.html.php => src/View/Form/HtmlView.php} (71%) rename src/components/com_weblinks/{views/weblink/view.html.php => src/View/Weblink/HtmlView.php} (97%) rename src/components/com_weblinks/{views/categories/tmpl => tmpl/categories}/default.php (96%) rename src/components/com_weblinks/{views/categories/tmpl => tmpl/categories}/default.xml (100%) rename src/components/com_weblinks/{views/categories/tmpl => tmpl/categories}/default_items.php (94%) rename src/components/com_weblinks/{views/category/tmpl => tmpl/category}/default.php (100%) rename src/components/com_weblinks/{views/category/tmpl => tmpl/category}/default.xml (100%) rename src/components/com_weblinks/{views/category/tmpl => tmpl/category}/default_children.php (100%) rename src/components/com_weblinks/{views/category/tmpl => tmpl/category}/default_items.php (97%) rename src/components/com_weblinks/{views => tmpl}/category/metadata.xml (100%) rename src/components/com_weblinks/{views/form/tmpl => tmpl/form}/edit.php (92%) rename src/components/com_weblinks/{views/form/tmpl => tmpl/form}/edit.xml (100%) rename src/components/com_weblinks/{views => tmpl}/form/metadata.xml (100%) rename src/components/com_weblinks/{views/weblink/tmpl => tmpl/weblink}/default.php (100%) rename src/components/com_weblinks/{views/weblink/tmpl => tmpl/weblink}/default.xml (100%) delete mode 100644 src/components/com_weblinks/views/categories/view.html.php delete mode 100644 src/components/com_weblinks/views/category/view.html.php delete mode 100644 src/components/com_weblinks/weblinks.php diff --git a/src/administrator/components/com_weblinks/helpers/weblinks.php b/src/administrator/components/com_weblinks/helpers/weblinks.php index 4fee715..fbce322 100644 --- a/src/administrator/components/com_weblinks/helpers/weblinks.php +++ b/src/administrator/components/com_weblinks/helpers/weblinks.php @@ -14,153 +14,7 @@ defined('_JEXEC') or die; * * @since 1.6 */ -class WeblinksHelper extends JHelperContent +class WeblinksHelper extends \Joomla\Component\Weblinks\Administrator\Controller\WeblinksHelper { - /** - * Configure the Linkbar. - * - * @param string $vName The name of the active view. - * - * @return void - * - * @since 1.6 - */ - public static function addSubmenu($vName = 'weblinks') - { - JHtmlSidebar::addEntry( - JText::_('COM_WEBLINKS_SUBMENU_WEBLINKS'), - 'index.php?option=com_weblinks&view=weblinks', - $vName == 'weblinks' - ); - JHtmlSidebar::addEntry( - JText::_('COM_WEBLINKS_SUBMENU_CATEGORIES'), - 'index.php?option=com_categories&extension=com_weblinks', - $vName == 'categories' - ); - - if (JComponentHelper::isEnabled('com_fields') && JComponentHelper::getParams('com_weblinks')->get('custom_fields_enable', '1')) - { - JHtmlSidebar::addEntry( - JText::_('JGLOBAL_FIELDS'), - 'index.php?option=com_fields&context=com_weblinks.weblink', - $vName == 'fields.fields' - ); - - JHtmlSidebar::addEntry( - JText::_('JGLOBAL_FIELD_GROUPS'), - 'index.php?option=com_fields&view=groups&context=com_weblinks.weblink', - $vName == 'fields.groups' - ); - } - } - - /** - * Adds Count Items for WebLinks Category Manager. - * - * @param stdClass[] &$items The weblinks category objects. - * - * @return stdClass[] The weblinks category objects. - * - * @since 3.6.0 - */ - public static function countItems(&$items) - { - $db = JFactory::getDbo(); - - foreach ($items as $item) - { - $item->count_trashed = 0; - $item->count_archived = 0; - $item->count_unpublished = 0; - $item->count_published = 0; - - $query = $db->getQuery(true) - ->select('state, COUNT(*) AS count') - ->from($db->qn('#__weblinks')) - ->where($db->qn('catid') . ' = ' . (int) $item->id) - ->group('state'); - - $db->setQuery($query); - $weblinks = $db->loadObjectList(); - - foreach ($weblinks as $weblink) - { - if ($weblink->state == 1) - { - $item->count_published = $weblink->count; - } - elseif ($weblink->state == 0) - { - $item->count_unpublished = $weblink->count; - } - elseif ($weblink->state == 2) - { - $item->count_archived = $weblink->count; - } - elseif ($weblink->state == -2) - { - $item->count_trashed = $weblink->count; - } - } - } - - return $items; - } - - /** - * Adds Count Items for Tag Manager. - * - * @param stdClass[] &$items The weblink tag objects - * @param string $extension The name of the active view. - * - * @return stdClass[] - * - * @since 3.7.0 - */ - public static function countTagItems(&$items, $extension) - { - $db = JFactory::getDbo(); - - foreach ($items as $item) - { - $item->count_trashed = 0; - $item->count_archived = 0; - $item->count_unpublished = 0; - $item->count_published = 0; - - $query = $db->getQuery(true); - $query->select('published as state, count(*) AS count') - ->from($db->qn('#__contentitem_tag_map') . 'AS ct ') - ->where('ct.tag_id = ' . (int) $item->id) - ->where('ct.type_alias =' . $db->q($extension)) - ->join('LEFT', $db->qn('#__categories') . ' AS c ON ct.content_item_id=c.id') - ->group('state'); - - $db->setQuery($query); - $weblinks = $db->loadObjectList(); - - foreach ($weblinks as $weblink) - { - if ($weblink->state == 1) - { - $item->count_published = $weblink->count; - } - if ($weblink->state == 0) - { - $item->count_unpublished = $weblink->count; - } - if ($weblink->state == 2) - { - $item->count_archived = $weblink->count; - } - if ($weblink->state == -2) - { - $item->count_trashed = $weblink->count; - } - } - } - - return $items; - } } diff --git a/src/administrator/components/com_weblinks/services/provider.php b/src/administrator/components/com_weblinks/services/provider.php index da71ea9..1f78a99 100644 --- a/src/administrator/components/com_weblinks/services/provider.php +++ b/src/administrator/components/com_weblinks/services/provider.php @@ -9,11 +9,13 @@ defined('_JEXEC') or die; use Joomla\CMS\Categories\CategoryFactoryInterface; +use Joomla\CMS\Component\Router\RouterFactoryInterface; use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface; use Joomla\CMS\Extension\ComponentInterface; use Joomla\CMS\Extension\Service\Provider\CategoryFactory; use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory; use Joomla\CMS\Extension\Service\Provider\MVCFactory; +use Joomla\CMS\Extension\Service\Provider\RouterFactory; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\Component\Weblinks\Administrator\Extension\WeblinksComponent; use Joomla\DI\Container; @@ -26,30 +28,31 @@ use Joomla\DI\ServiceProviderInterface; */ return new class implements ServiceProviderInterface { - /** - * Registers the service provider with a DI container. - * - * @param Container $container The DI container. - * - * @return void - * - * @since 4.0.0 - */ - public function register(Container $container) - { - $container->registerServiceProvider(new CategoryFactory('\\Joomla\\Component\\Weblinks')); - $container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Weblinks')); - $container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Weblinks')); - $container->set( - ComponentInterface::class, - function (Container $container) - { - $component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class)); - $component->setMVCFactory($container->get(MVCFactoryInterface::class)); - $component->setCategoryFactory($container->get(CategoryFactoryInterface::class)); + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * + * @since 4.0.0 + */ + public function register(Container $container) + { + $container->registerServiceProvider(new CategoryFactory('\\Joomla\\Component\\Weblinks')); + $container->registerServiceProvider(new MVCFactory('\\Joomla\\Component\\Weblinks')); + $container->registerServiceProvider(new ComponentDispatcherFactory('\\Joomla\\Component\\Weblinks')); + $container->registerServiceProvider(new RouterFactory('\\Joomla\\Component\\Weblinks')); + $container->set( + ComponentInterface::class, + function (Container $container) { + $component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class)); + $component->setMVCFactory($container->get(MVCFactoryInterface::class)); + $component->setCategoryFactory($container->get(CategoryFactoryInterface::class)); + $component->setRouterFactory($container->get(RouterFactoryInterface::class)); - return $component; - } - ); - } + return $component; + } + ); + } }; diff --git a/src/administrator/components/com_weblinks/Controller/DisplayController.php b/src/administrator/components/com_weblinks/src/Controller/DisplayController.php similarity index 86% rename from src/administrator/components/com_weblinks/Controller/DisplayController.php rename to src/administrator/components/com_weblinks/src/Controller/DisplayController.php index ed1b7e9..67fcf1f 100644 --- a/src/administrator/components/com_weblinks/Controller/DisplayController.php +++ b/src/administrator/components/com_weblinks/src/Controller/DisplayController.php @@ -37,14 +37,12 @@ class DisplayController extends BaseController * @param array $urlparams An array of safe url parameters and their variable types, * for valid values see {@link JFilterInput::clean()}. * - * @return JControllerLegacy This object to support chaining. + * @return BaseController|boolean This object to support chaining. * * @since 1.5 */ public function display($cacheable = false, $urlparams = false) { - require_once JPATH_COMPONENT . '/helpers/weblinks.php'; - $view = $this->input->get('view', 'weblinks'); $layout = $this->input->get('layout', 'default'); $id = $this->input->getInt('id'); @@ -53,8 +51,11 @@ class DisplayController extends BaseController if ($view == 'weblink' && $layout == 'edit' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) { // Somehow the person just went to the form - we don't allow that. - $this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); - $this->setMessage($this->getError(), 'error'); + if (!\count($this->app->getMessageQueue())) + { + $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 'error'); + } + $this->setRedirect(Route::_('index.php?option=com_weblinks&view=weblinks', false)); return false; diff --git a/src/administrator/components/com_weblinks/Controller/WeblinkController.php b/src/administrator/components/com_weblinks/src/Controller/WeblinkController.php similarity index 85% rename from src/administrator/components/com_weblinks/Controller/WeblinkController.php rename to src/administrator/components/com_weblinks/src/Controller/WeblinkController.php index e5acd0a..1d42209 100644 --- a/src/administrator/components/com_weblinks/Controller/WeblinkController.php +++ b/src/administrator/components/com_weblinks/src/Controller/WeblinkController.php @@ -11,6 +11,7 @@ namespace Joomla\Component\Weblinks\Administrator\Controller; defined('_JEXEC') or die; +use Joomla\CMS\MVC\Controller\FormController; use Joomla\Utilities\ArrayHelper; /** @@ -18,7 +19,7 @@ use Joomla\Utilities\ArrayHelper; * * @since 1.6 */ -class WeblinkController extends \JControllerForm +class WeblinkController extends FormController { /** * Method override to check if you can add a new record. @@ -32,20 +33,15 @@ class WeblinkController extends \JControllerForm protected function allowAdd($data = array()) { $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int'); - $allow = null; + $allow = null; if ($categoryId) { // If the category has been passed in the URL check it. - $allow = \JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId); + return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow !== null) - { - return $allow; - } - - // In the absense of better information, revert to the component permissions. + // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); } @@ -78,7 +74,7 @@ class WeblinkController extends \JControllerForm return false; } - $user = \JFactory::getUser(); + $user = $this->app->getIdentity(); // Check if can edit own core.edit.own. $canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id; @@ -112,8 +108,8 @@ class WeblinkController extends \JControllerForm /** * 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 \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The data model object. + * @param array $validData The validated data. * * @return void * diff --git a/src/administrator/components/com_weblinks/Controller/WeblinksController.php b/src/administrator/components/com_weblinks/src/Controller/WeblinksController.php similarity index 100% rename from src/administrator/components/com_weblinks/Controller/WeblinksController.php rename to src/administrator/components/com_weblinks/src/Controller/WeblinksController.php diff --git a/src/administrator/components/com_weblinks/Extension/WeblinksComponent.php b/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php similarity index 72% rename from src/administrator/components/com_weblinks/Extension/WeblinksComponent.php rename to src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php index 1172396..74aeb3e 100644 --- a/src/administrator/components/com_weblinks/Extension/WeblinksComponent.php +++ b/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php @@ -15,17 +15,28 @@ use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Association\AssociationServiceTrait; use Joomla\CMS\Categories\CategoryServiceInterface; use Joomla\CMS\Categories\CategoryServiceTrait; +use Joomla\CMS\Component\Router\RouterServiceInterface; +use Joomla\CMS\Component\Router\RouterServiceTrait; use Joomla\CMS\Extension\MVCComponent; +use Joomla\CMS\Tag\TagServiceInterface; +use Joomla\CMS\Tag\TagServiceTrait; /** * Component class for com_contact * * @since 4.0.0 */ -class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface +class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface, + TagServiceInterface, RouterServiceInterface { use CategoryServiceTrait; use AssociationServiceTrait; + use RouterServiceTrait; + use CategoryServiceTrait, TagServiceTrait + { + CategoryServiceTrait::getTableNameForSection insteadof TagServiceTrait; + CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait; + } /** * Returns the table for the count items functions for the given section. @@ -52,6 +63,6 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface */ protected function getStateColumnForSection(string $section = null) { - return 'published'; + return 'state'; } } diff --git a/src/administrator/components/com_weblinks/Field/Modal/WeblinkField.php b/src/administrator/components/com_weblinks/src/Field/Modal/WeblinkField.php similarity index 100% rename from src/administrator/components/com_weblinks/Field/Modal/WeblinkField.php rename to src/administrator/components/com_weblinks/src/Field/Modal/WeblinkField.php diff --git a/src/administrator/components/com_weblinks/src/Helper/AssociationsHelper.php b/src/administrator/components/com_weblinks/src/Helper/AssociationsHelper.php new file mode 100644 index 0000000..cb20684 --- /dev/null +++ b/src/administrator/components/com_weblinks/src/Helper/AssociationsHelper.php @@ -0,0 +1,210 @@ +getType($typeName); + + $context = $this->extension . '.item'; + $catidField = 'catid'; + + if ($typeName === 'category') + { + $context = 'com_categories.item'; + $catidField = ''; + } + + // Get the associations. + $associations = Associations::getAssociations( + $this->extension, + $type['tables']['a'], + $context, + $id, + 'id', + 'alias', + $catidField + ); + + return $associations; + } + + /** + * Get item information + * + * @param string $typeName The item type + * @param int $id The id of item for which we need the associated items + * + * @return Table|null + * + * @since __DEPLOY_VERSION__ + */ + public function getItem($typeName, $id) + { + if (empty($id)) + { + return null; + } + + $table = null; + + switch ($typeName) + { + case 'weblink': + $table = Table::getInstance('Weblink', 'Joomla\\Component\\Weblinks\\Administrator\\Table\\'); + break; + + case 'category': + $table = Table::getInstance('Category'); + break; + } + + if (empty($table)) + { + return null; + } + + $table->load($id); + + return $table; + } + + /** + * Get information about the type + * + * @param string $typeName The item type + * + * @return array Array of item types + * + * @since __DEPLOY_VERSION__ + */ + public function getType($typeName = '') + { + $fields = $this->getFieldsTemplate(); + $tables = array(); + $joins = array(); + $support = $this->getSupportTemplate(); + $title = ''; + + if (in_array($typeName, $this->itemTypes)) + { + switch ($typeName) + { + case 'weblink': + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + $support['category'] = true; + $support['save2copy'] = true; + + $tables = array( + 'a' => '#__weblinks', + ); + + $title = 'weblink'; + break; + + case 'category': + $fields['created_user_id'] = 'a.created_user_id'; + $fields['ordering'] = 'a.lft'; + $fields['level'] = 'a.level'; + $fields['catid'] = ''; + $fields['state'] = 'a.published'; + + $support['state'] = true; + $support['acl'] = true; + $support['checkout'] = true; + $support['level'] = true; + + $tables = array( + 'a' => '#__categories', + ); + + $title = 'category'; + break; + } + } + + return array( + 'fields' => $fields, + 'support' => $support, + 'tables' => $tables, + 'joins' => $joins, + 'title' => $title, + ); + } +} diff --git a/src/administrator/components/com_weblinks/src/Helper/WeblinksHelper.php b/src/administrator/components/com_weblinks/src/Helper/WeblinksHelper.php new file mode 100644 index 0000000..823b8c7 --- /dev/null +++ b/src/administrator/components/com_weblinks/src/Helper/WeblinksHelper.php @@ -0,0 +1,24 @@ +id)) + if (empty($record->id) || $record->published != -2) { - if ($record->state != -2) - { - return; - } - - if ($record->catid) - { - return \JFactory::getUser()->authorise('core.delete', 'com_weblinks.category.' . (int) $record->catid); - } - - return parent::canDelete($record); + return false; } + + return Factory::getUser()->authorise('core.delete', 'com_contact.category.' . (int) $record->catid); } /** @@ -86,7 +83,7 @@ class WeblinkModel extends \JModelAdmin { if (!empty($record->catid)) { - return \JFactory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid); + return Factory::getUser()->authorise('core.edit.state', 'com_weblinks.category.' . (int) $record->catid); } return parent::canEditState($record); @@ -154,7 +151,7 @@ class WeblinkModel extends \JModelAdmin protected function loadFormData() { // Check the session for previously entered form data. - $data = \JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); + $data = Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); if (empty($data)) { @@ -163,7 +160,7 @@ class WeblinkModel extends \JModelAdmin // Prime some default values. if ($this->getState('weblink.id') == 0) { - $app = \JFactory::getApplication(); + $app = Factory::getApplication(); $data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int')); } } @@ -197,7 +194,7 @@ class WeblinkModel extends \JModelAdmin $item->images = $registry->toArray(); // Load associated web links items - $assoc = \JLanguageAssociations::isEnabled(); + $assoc = Associations::isEnabled(); if ($assoc) { @@ -205,7 +202,7 @@ class WeblinkModel extends \JModelAdmin if ($item->id != null) { - $associations = \JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id); + $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $item->id); foreach ($associations as $tag => $association) { @@ -228,7 +225,7 @@ class WeblinkModel extends \JModelAdmin /** * Prepare and sanitise the table data prior to saving. * - * @param JTable $table A reference to a JTable object. + * @param \Joomla\CMS\Table\Table $table A reference to a JTable object. * * @return void * @@ -236,15 +233,15 @@ class WeblinkModel extends \JModelAdmin */ protected function prepareTable($table) { - $date = \JFactory::getDate(); - $user = \JFactory::getUser(); + $date = Factory::getDate(); + $user = Factory::getUser(); $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES); - $table->alias = \JApplicationHelper::stringURLSafe($table->alias); + $table->alias = ApplicationHelper::stringURLSafe($table->alias); if (empty($table->alias)) { - $table->alias = \JApplicationHelper::stringURLSafe($table->title); + $table->alias = ApplicationHelper::stringURLSafe($table->title); } if (empty($table->id)) @@ -254,7 +251,7 @@ class WeblinkModel extends \JModelAdmin // Set ordering to the last item if not set if (empty($table->ordering)) { - $db = $this->getDbo(); + $db = $this->getDbo(); $query = $db->getQuery(true) ->select('MAX(ordering)') ->from($db->quoteName('#__weblinks')); @@ -279,7 +276,7 @@ class WeblinkModel extends \JModelAdmin /** * A protected method to get a set of ordering conditions. * - * @param JTable $table A JTable object. + * @param \Joomla\CMS\Table\Table $table A JTable object. * * @return array An array of conditions to add to ordering queries. * @@ -287,7 +284,7 @@ class WeblinkModel extends \JModelAdmin */ protected function getReorderConditions($table) { - $condition = array(); + $condition = array(); $condition[] = 'catid = ' . (int) $table->catid; return $condition; @@ -300,13 +297,11 @@ class WeblinkModel extends \JModelAdmin * * @return boolean True on success. * - * @since 3.1 + * @since 3.1 */ public function save($data) { - $app = \JFactory::getApplication(); - - \JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); + $app = Factory::getApplication(); // Cast catid to integer for comparison $catid = (int) $data['catid']; @@ -314,30 +309,30 @@ class WeblinkModel extends \JModelAdmin // Check if New Category exists if ($catid > 0) { - $catid = \CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks'); + $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks'); } // Save New Category if ($catid == 0 && $this->canCreateCategory()) { - $table = array(); - $table['title'] = $data['catid']; + $table = array(); + $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_weblinks'; - $table['language'] = $data['language']; + $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back - $data['catid'] = \CategoriesHelper::createCategory($table); + $data['catid'] = CategoriesHelper::createCategory($table); } // Alter the title for save as copy if ($app->input->get('task') == 'save2copy') { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); - $data['title'] = $name; - $data['alias'] = $alias; - $data['state'] = 0; + $data['title'] = $name; + $data['alias'] = $alias; + $data['state'] = 0; } return parent::save($data); @@ -363,10 +358,10 @@ class WeblinkModel extends \JModelAdmin { if ($name == $table->title) { - $name = \JString::increment($name); + $name = StringHelper::increment($name); } - $alias = \JString::increment($alias, 'dash'); + $alias = StringHelper::increment($alias, 'dash'); } return array($name, $alias); @@ -375,7 +370,7 @@ class WeblinkModel extends \JModelAdmin /** * Allows preprocessing of the JForm object. * - * @param JForm $form The form object + * @param \JForm $form The form object * @param array $data The data to be merged into the form object * @param string $group The plugin group to be executed * @@ -391,14 +386,14 @@ class WeblinkModel extends \JModelAdmin } // Association weblinks items - if (\JLanguageAssociations::isEnabled()) + if (Associations::isEnabled()) { - $languages = \JLanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc'); + $languages = LanguageHelper::getContentLanguages(false, true, null, 'ordering', 'asc'); if (count($languages) > 1) { $addform = new \SimpleXMLElement('
'); - $fields = $addform->addChild('fields'); + $fields = $addform->addChild('fields'); $fields->addAttribute('name', 'associations'); $fieldset = $fields->addChild('fieldset'); $fieldset->addAttribute('name', 'item_associations'); @@ -434,6 +429,6 @@ class WeblinkModel extends \JModelAdmin */ private function canCreateCategory() { - return \JFactory::getUser()->authorise('core.create', 'com_weblinks'); + return Factory::getUser()->authorise('core.create', 'com_weblinks'); } } diff --git a/src/administrator/components/com_weblinks/Model/WeblinksModel.php b/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php similarity index 96% rename from src/administrator/components/com_weblinks/Model/WeblinksModel.php rename to src/administrator/components/com_weblinks/src/Model/WeblinksModel.php index 2761fef..d64e6fb 100644 --- a/src/administrator/components/com_weblinks/Model/WeblinksModel.php +++ b/src/administrator/components/com_weblinks/src/Model/WeblinksModel.php @@ -11,8 +11,10 @@ namespace Joomla\Component\Weblinks\Administrator\Model; defined('_JEXEC') or die; -use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; +use Joomla\CMS\MVC\Model\ListModel; /** * Methods supporting a list of weblink records. @@ -24,7 +26,7 @@ class WeblinksModel extends ListModel /** * Constructor. * - * @param array $config An optional associative array of configuration settings. + * @param array $config An optional associative array of configuration settings. * @param MVCFactoryInterface $factory The factory. * * @see JControllerLegacy @@ -83,7 +85,7 @@ class WeblinksModel extends ListModel */ protected function populateState($ordering = 'a.title', $direction = 'asc') { - $app = \JFactory::getApplication(); + $app = Factory::getApplication(); $forcedLanguage = $app->input->get('forcedLanguage', '', 'cmd'); @@ -109,7 +111,7 @@ class WeblinksModel extends ListModel $this->setState('filter.level', $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level', '', 'cmd')); // Load the parameters. - $params = \JComponentHelper::getParams('com_weblinks'); + $params = ComponentHelper::getParams('com_weblinks'); $this->setState('params', $params); // Force a language. @@ -152,16 +154,16 @@ class WeblinksModel extends ListModel /** * Build an SQL query to load the list data. * - * @return JDatabaseQuery + * @return \JDatabaseQuery * * @since 1.6 */ protected function getListQuery() { // Create a new query object. - $db = $this->getDbo(); + $db = $this->getDbo(); $query = $db->getQuery(true); - $user = \JFactory::getUser(); + $user = Factory::getUser(); // Select the required fields from the table. $query->select( diff --git a/src/administrator/components/com_weblinks/Table/WeblinkTable.php b/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php similarity index 76% rename from src/administrator/components/com_weblinks/Table/WeblinkTable.php rename to src/administrator/components/com_weblinks/src/Table/WeblinkTable.php index 4e08601..c5cb4a8 100644 --- a/src/administrator/components/com_weblinks/Table/WeblinkTable.php +++ b/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php @@ -9,6 +9,15 @@ namespace Joomla\Component\Weblinks\Administrator\Table; +use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\String\PunycodeHelper; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Tag\TaggableTableInterface; +use Joomla\CMS\Tag\TaggableTableTrait; +use Joomla\CMS\Versioning\VersionableTableInterface; +use Joomla\String\StringHelper; + defined('_JEXEC') or die; /** @@ -16,8 +25,9 @@ defined('_JEXEC') or die; * * @since 1.5 */ -class WeblinkTable extends \JTable +class WeblinkTable extends Table implements VersionableTableInterface, TaggableTableInterface { + use TaggableTableTrait; /** * Ensure the params and metadata in json encoded in the bind method * @@ -29,22 +39,18 @@ class WeblinkTable extends \JTable /** * Constructor * - * @param JDatabaseDriver &$db A database connector object + * @param \JDatabaseDriver &$db A database connector object * * @since 1.5 */ public function __construct(&$db) { + $this->typeAlias = 'com_weblinks.weblink'; + parent::__construct('#__weblinks', 'id', $db); // Set the published column alias $this->setColumnAlias('published', 'state'); - - if (version_compare(JVERSION, '4.0', '<' ) == 1) - { - \JTableObserverTags::createObserver($this, array('typeAlias' => 'com_weblinks.weblink')); - \JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_weblinks.weblink')); - } } /** @@ -58,8 +64,8 @@ class WeblinkTable extends \JTable */ public function store($updateNulls = false) { - $date = \JFactory::getDate(); - $user = \JFactory::getUser(); + $date = Factory::getDate(); + $user = Factory::getUser(); $this->modified = $date->toSql(); @@ -107,7 +113,13 @@ class WeblinkTable extends \JTable } // Convert IDN urls to punycode - $this->url = \JStringPunycode::urlToPunycode($this->url); + $this->url = PunycodeHelper::urlToPunycode($this->url); + + // Set default value for xreference + if ($this->xreference === null) + { + $this->xreference = ''; + } return parent::store($updateNulls); } @@ -132,6 +144,7 @@ class WeblinkTable extends \JTable if (trim($this->title) == '') { $this->setError(\JText::_('COM_WEBLINKS_ERR_TABLES_TITLE')); + return false; } @@ -160,11 +173,11 @@ class WeblinkTable extends \JTable $this->alias = $this->title; } - $this->alias = \JApplicationHelper::stringURLSafe($this->alias, $this->language); + $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); if (trim(str_replace('-', '', $this->alias)) == '') { - $this->alias = \JFactory::getDate()->format("Y-m-d-H-i-s"); + $this->alias = Factory::getDate()->format("Y-m-d-H-i-s"); } // Check the publish down date is not earlier than publish up. @@ -183,9 +196,9 @@ class WeblinkTable extends \JTable { // Array of characters to remove $bad_characters = array("\n", "\r", "\"", "<", ">"); - $after_clean = \JString::str_ireplace($bad_characters, "", $this->metakey); - $keys = explode(',', $after_clean); - $clean_keys = array(); + $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey); + $keys = explode(',', $after_clean); + $clean_keys = array(); foreach ($keys as $key) { @@ -202,4 +215,16 @@ class WeblinkTable extends \JTable return parent::check(); } + + /** + * Get the type alias for the history table + * + * @return string The alias as described above + * + * @since 4.0.0 + */ + public function getTypeAlias() + { + return $this->typeAlias; + } } diff --git a/src/administrator/components/com_weblinks/View/Weblink/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php similarity index 64% rename from src/administrator/components/com_weblinks/View/Weblink/HtmlView.php rename to src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php index a91d570..ba84715 100644 --- a/src/administrator/components/com_weblinks/View/Weblink/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php @@ -11,18 +11,40 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblink; defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Toolbar\ToolbarHelper; + /** * View to edit a weblink. * * @since 1.5 */ -class HtmlView extends \Joomla\CMS\MVC\View\HtmlView +class HtmlView extends BaseHtmlView { - protected $state; + /** + * The \JForm object + * + * @var \JForm + */ + protected $form; + /** + * The active item + * + * @var object + */ protected $item; - protected $form; + /** + * The model state + * + * @var \JObject + */ + protected $state; /** * Display the view. @@ -40,13 +62,11 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView // Check for errors. if (count($errors = $this->get('Errors'))) { - \JError::raiseError(500, implode("\n", $errors)); - - return false; + throw new GenericDataException(implode("\n", $errors), 500); } // If we are forcing a language in modal (used for associations). - if ($this->getLayout() === 'modal' && $forcedLanguage = \JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) + if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) { // Set the language field to the forcedLanguage and disable changing it. $this->form->setValue('language', null, $forcedLanguage); @@ -73,47 +93,47 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView */ 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); $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id')); // Since we don't track these assets at the item level, use the category id. - $canDo = \JHelperContent::getActions('com_weblinks', 'category', $this->item->catid); + $canDo = ContentHelper::getActions('com_weblinks', 'category', $this->item->catid); - \JToolbarHelper::title($isNew ? \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : \JText::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks'); + ToolbarHelper::title($isNew ? Text::_('COM_WEBLINKS_MANAGER_WEBLINK_NEW') : Text::_('COM_WEBLINKS_MANAGER_WEBLINK_EDIT'), 'link weblinks'); // If not checked out, can save the item. if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create'))))) { - \JToolbarHelper::apply('weblink.apply'); - \JToolbarHelper::save('weblink.save'); + ToolbarHelper::apply('weblink.apply'); + ToolbarHelper::save('weblink.save'); } if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))) { - \JToolbarHelper::save2new('weblink.save2new'); + ToolbarHelper::save2new('weblink.save2new'); } // If an existing item, can save to a copy. if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)) { - \JToolbarHelper::save2copy('weblink.save2copy'); + ToolbarHelper::save2copy('weblink.save2copy'); } if (empty($this->item->id)) { - \JToolbarHelper::cancel('weblink.cancel'); + ToolbarHelper::cancel('weblink.cancel'); } else { if ($this->state->params->get('save_history', 0) && $user->authorise('core.edit')) { - \JToolbarHelper::versions('com_weblinks.weblink', $this->item->id); + ToolbarHelper::versions('com_weblinks.weblink', $this->item->id); } - \JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); + ToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE'); } - \JToolbarHelper::divider(); - \JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT'); + ToolbarHelper::divider(); + ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT'); } } diff --git a/src/administrator/components/com_weblinks/View/Weblinks/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php similarity index 63% rename from src/administrator/components/com_weblinks/View/Weblinks/HtmlView.php rename to src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php index 2c8e73f..2fff3c8 100644 --- a/src/administrator/components/com_weblinks/View/Weblinks/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php @@ -11,19 +11,58 @@ namespace Joomla\Component\Weblinks\Administrator\View\Weblinks; defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Helper\ContentHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\FileLayout; +use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Toolbar\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; + /** * View class for a list of weblinks. * * @since 1.5 */ -class HtmlView extends \Joomla\CMS\MVC\View\HtmlView +class HtmlView extends BaseHtmlView { + /** + * An array of items + * + * @var array + */ protected $items; + /** + * The pagination object + * + * @var \JPagination + */ protected $pagination; + /** + * The model state + * + * @var \JObject + */ protected $state; + /** + * Form object for search filters + * + * @var \JForm + */ + public $filterForm; + + /** + * The active search filters + * + * @var array + */ + public $activeFilters; + /** * Display the view. * @@ -39,16 +78,11 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); - // Modal layout doesn't need the submenu. - if ($this->getLayout() !== 'modal') - { - \WeblinksHelper::addSubmenu('weblinks'); - } - // Check for errors. if (count($errors = $this->get('Errors'))) { - \JError::raiseError(500, implode("\n", $errors)); + throw new GenericDataException(implode("\n", $errors), 500); + return false; } @@ -56,13 +90,12 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView if ($this->getLayout() !== 'modal') { $this->addToolbar(); - $this->sidebar = \JHtmlSidebar::render(); } else { // In article associations modal we need to remove language filter if forcing a language. // We also need to change the category filter to show show categories with All or the forced language. - if ($forcedLanguage = \JFactory::getApplication()->input->get('forcedLanguage', '', 'CMD')) + if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) { // If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field. $languageXml = new \SimpleXMLElement(''); @@ -88,54 +121,52 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView */ protected function addToolbar() { - require_once JPATH_COMPONENT . '/helpers/weblinks.php'; - $state = $this->get('State'); - $canDo = \JHelperContent::getActions('com_weblinks', 'category', $state->get('filter.category_id')); - $user = \JFactory::getUser(); + $canDo = ContentHelper::getActions('com_weblinks', 'category', $state->get('filter.category_id')); + $user = Factory::getUser(); // Get the toolbar object instance - $bar = \JToolbar::getInstance('toolbar'); + $bar = Toolbar::getInstance('toolbar'); - \JToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); + ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks'); if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0) { - \JToolbarHelper::addNew('weblink.add'); + ToolbarHelper::addNew('weblink.add'); } if ($canDo->get('core.edit') || $canDo->get('core.edit.own')) { - \JToolbarHelper::editList('weblink.edit'); + ToolbarHelper::editList('weblink.edit'); } if ($canDo->get('core.edit.state')) { - \JToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true); - \JToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true); + ToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true); - \JToolbarHelper::archiveList('weblinks.archive'); - \JToolbarHelper::checkin('weblinks.checkin'); + ToolbarHelper::archiveList('weblinks.archive'); + ToolbarHelper::checkin('weblinks.checkin'); } if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) { - \JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH'); + ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH'); } elseif ($canDo->get('core.edit.state')) { - \JToolbarHelper::trash('weblinks.trash'); + ToolbarHelper::trash('weblinks.trash'); } // Add a batch button if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks') && $user->authorise('core.edit.state', 'com_weblinks')) { - \JHtml::_('bootstrap.renderModal', 'collapseModal'); - $title = \JText::_('JTOOLBAR_BATCH'); + HTMLHelper::_('bootstrap.renderModal', 'collapseModal'); + $title = Text::_('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('title' => $title)); $bar->appendButton('Custom', $dhtml, 'batch'); @@ -143,10 +174,10 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks')) { - \JToolbarHelper::preferences('com_weblinks'); + ToolbarHelper::preferences('com_weblinks'); } - \JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS'); + ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS'); } /** @@ -160,12 +191,12 @@ class HtmlView extends \Joomla\CMS\MVC\View\HtmlView { return array( 'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'), - 'a.state' => \JText::_('JSTATUS'), - 'a.title' => \JText::_('JGLOBAL_TITLE'), - 'a.access' => \JText::_('JGRID_HEADING_ACCESS'), - 'a.hits' => \JText::_('JGLOBAL_HITS'), + 'a.state' => \JText::_('JSTATUS'), + 'a.title' => \JText::_('JGLOBAL_TITLE'), + 'a.access' => \JText::_('JGRID_HEADING_ACCESS'), + 'a.hits' => \JText::_('JGLOBAL_HITS'), 'a.language' => \JText::_('JGRID_HEADING_LANGUAGE'), - 'a.id' => \JText::_('JGRID_HEADING_ID') + 'a.id' => \JText::_('JGRID_HEADING_ID'), ); } } diff --git a/src/administrator/components/com_weblinks/tmpl/weblink/edit.php b/src/administrator/components/com_weblinks/tmpl/weblink/edit.php index 64e304f..594ca54 100644 --- a/src/administrator/components/com_weblinks/tmpl/weblink/edit.php +++ b/src/administrator/components/com_weblinks/tmpl/weblink/edit.php @@ -9,10 +9,8 @@ defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); JHtml::_('behavior.formvalidator'); -JHtml::_('formbehavior.chosen', 'select', null, array('disable_search_threshold' => 0 )); $app = JFactory::getApplication(); $input = $app->input; @@ -21,6 +19,7 @@ $assoc = JLanguageAssociations::isEnabled(); // Fieldsets to not automatically render by /layouts/joomla/edit/params.php $this->ignore_fieldsets = array('details', 'images', 'item_associations', 'jmetadata'); +$this->useCoreUI = true; // In case of modal $isModal = $input->get('layout') == 'modal' ? true : false; @@ -33,9 +32,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
- 'details')); ?> + 'details')); ?> - item->id) ? JText::_('COM_WEBLINKS_NEW_WEBLINK', true) : JText::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?> + item->id) ? JText::_('COM_WEBLINKS_NEW_WEBLINK', true) : JText::_('COM_WEBLINKS_EDIT_WEBLINK', true)); ?>
@@ -47,9 +46,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
- + - +
form->renderField('images'); ?> @@ -59,9 +58,9 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
- + - +
@@ -70,19 +69,19 @@ $tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=c
- + - + loadTemplate('associations'); ?> - + - +
diff --git a/src/administrator/components/com_weblinks/tmpl/weblinks/default.php b/src/administrator/components/com_weblinks/tmpl/weblinks/default.php index 21b2a0c..c841ae4 100644 --- a/src/administrator/components/com_weblinks/tmpl/weblinks/default.php +++ b/src/administrator/components/com_weblinks/tmpl/weblinks/default.php @@ -9,11 +9,16 @@ defined('_JEXEC') or die; -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\Router\Route; + +/** @var \Joomla\Component\Weblinks\Administrator\View\Weblinks\HtmlView $this */ JHtml::_('bootstrap.tooltip'); JHtml::_('behavior.multiselect'); -JHtml::_('formbehavior.chosen', 'select'); +//JHtml::_('formbehavior.chosen', 'select'); $user = JFactory::getUser(); $userId = $user->get('id'); @@ -26,164 +31,164 @@ $assoc = JLanguageAssociations::isEnabled(); if ($saveOrder) { $saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component'; - JHtml::_('sortablelist.sortable', 'weblinkList', 'adminForm', strtolower($listDirn), $saveOrderingUrl); + HTMLHelper::_('draggablelist.draggable'); } ?> - +
- sidebar)) : ?> -
- sidebar; ?> -
-
- -
- - $this)); ?> -
- items)) : ?> -
- -
- - - - - - - - - - - - - - - - - - - - - - - - items as $i => $item) : ?> - - cat_link = JRoute::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]=' . $item->catid); ?> - authorise('core.create', 'com_weblinks.category.' . $item->catid); ?> - authorise('core.edit', 'com_weblinks.category.' . $item->catid); ?> - authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || $item->checked_out == 0; ?> - authorise('core.edit.own', 'com_weblinks.category.' . $item->catid) && $item->created_by == $user->id; ?> - authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin; ?> - - + + + + + - - - -
+ + pagination->getListFooter(); ?> + + + authorise('core.create', 'com_weblinks') + && $user->authorise('core.edit', 'com_weblinks') + && $user->authorise('core.edit.state', 'com_weblinks')) : ?> + Text::_('com_weblinks_BATCH_OPTIONS'), + 'footer' => $this->loadTemplate('batch_footer') + ], + $this->loadTemplate('batch_body') + ); ?> + + + + + + +
+
diff --git a/src/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch_body.php b/src/administrator/components/com_weblinks/tmpl/weblinks/default_batch_body.php similarity index 69% rename from src/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch_body.php rename to src/administrator/components/com_weblinks/tmpl/weblinks/default_batch_body.php index e6ff658..6107d0b 100644 --- a/src/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch_body.php +++ b/src/administrator/components/com_weblinks/tmpl/weblinks/default_batch_body.php @@ -7,6 +7,9 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; + +use Joomla\CMS\Layout\LayoutHelper; + $published = $this->state->get('filter.published'); ?> @@ -14,12 +17,12 @@ $published = $this->state->get('filter.published');
- +
- +
@@ -27,13 +30,13 @@ $published = $this->state->get('filter.published'); = 0) : ?>
- + 'com_contact']); ?>
- +
diff --git a/src/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch_footer.php b/src/administrator/components/com_weblinks/tmpl/weblinks/default_batch_footer.php similarity index 100% rename from src/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch_footer.php rename to src/administrator/components/com_weblinks/tmpl/weblinks/default_batch_footer.php diff --git a/src/administrator/components/com_weblinks/weblinks.xml b/src/administrator/components/com_weblinks/weblinks.xml index a872b1c..1735e09 100644 --- a/src/administrator/components/com_weblinks/weblinks.xml +++ b/src/administrator/components/com_weblinks/weblinks.xml @@ -10,7 +10,7 @@ ##VERSION## COM_WEBLINKS_XML_DESCRIPTION script.php - Joomla\Component\Weblinks + Joomla\Component\Weblinks diff --git a/src/components/com_weblinks/models/forms/weblink.xml b/src/components/com_weblinks/forms/weblink.xml similarity index 97% rename from src/components/com_weblinks/models/forms/weblink.xml rename to src/components/com_weblinks/forms/weblink.xml index 34478a3..49ff543 100644 --- a/src/components/com_weblinks/models/forms/weblink.xml +++ b/src/components/com_weblinks/forms/weblink.xml @@ -1,6 +1,6 @@
-
+
array((int) $id)); - - // Create the link - $link = 'index.php?option=com_weblinks&view=weblink&id=' . $id; - - if ($catid > 1) - { - $categories = JCategories::getInstance('Weblinks'); - $category = $categories->get($catid); - - if ($category) - { - $needles['category'] = array_reverse($category->getPath()); - $needles['categories'] = $needles['category']; - $link .= '&catid=' . $catid; - } - } - - if ($language && $language != "*" && JLanguageMultilang::isEnabled()) - { - self::buildLanguageLookup(); - - if (isset(self::$lang_lookup[$language])) - { - $link .= '&lang=' . self::$lang_lookup[$language]; - $needles['language'] = $language; - } - } - - if ($item = self::_findItem($needles)) - { - $link .= '&Itemid=' . $item; - } - - return $link; - } - - /** - * Ge the form route - * - * @param integer $id The id of the weblink. - * @param string $return The return page variable. - * - * @return string - */ - public static function getFormRoute($id, $return = null) - { - // Create the link. - if ($id) - { - $link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id; - } - else - { - $link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0'; - } - - if ($return) - { - $link .= '&return=' . $return; - } - - return $link; - } - - /** - * Get the Category Route - * - * @param JCategoryNode|string|integer $catid JCategoryNode object or category ID - * @param integer $language Language code - * - * @return string - */ - public static function getCategoryRoute($catid, $language = 0) - { - if ($catid instanceof JCategoryNode) - { - $id = $catid->id; - $category = $catid; - } - else - { - $id = (int) $catid; - $category = JCategories::getInstance('Weblinks')->get($id); - } - - if ($id < 1 || !($category instanceof JCategoryNode)) - { - $link = ''; - } - else - { - $needles = array(); - - // Create the link - $link = 'index.php?option=com_weblinks&view=category&id=' . $id; - - $catids = array_reverse($category->getPath()); - $needles['category'] = $catids; - $needles['categories'] = $catids; - - if ($language && $language != "*" && JLanguageMultilang::isEnabled()) - { - self::buildLanguageLookup(); - - if (isset(self::$lang_lookup[$language])) - { - $link .= '&lang=' . self::$lang_lookup[$language]; - $needles['language'] = $language; - } - } - - if ($item = self::_findItem($needles)) - { - $link .= '&Itemid=' . $item; - } - } - - return $link; - } - - /** - * Do a language lookup - * - * @return void - */ - protected static function buildLanguageLookup() - { - if (count(self::$lang_lookup) == 0) - { - $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select('a.sef AS sef') - ->select('a.lang_code AS lang_code') - ->from('#__languages AS a'); - - $db->setQuery($query); - $langs = $db->loadObjectList(); - - foreach ($langs as $lang) - { - self::$lang_lookup[$lang->lang_code] = $lang->sef; - } - } - } - - /** - * Find items per given $needles - * - * @param array $needles A given array of needles to find - * - * @return void - */ - protected static function _findItem($needles = null) - { - $app = JFactory::getApplication(); - $menus = $app->getMenu('site'); - $language = isset($needles['language']) ? $needles['language'] : '*'; - - // Prepare the reverse lookup array. - if (!isset(self::$lookup[$language])) - { - self::$lookup[$language] = array(); - - $component = JComponentHelper::getComponent('com_weblinks'); - - $attributes = array('component_id'); - $values = array($component->id); - - if ($language != '*') - { - $attributes[] = 'language'; - $values[] = array($needles['language'], '*'); - } - - $items = $menus->getItems($attributes, $values); - - if ($items) - { - foreach ($items as $item) - { - if (isset($item->query) && isset($item->query['view'])) - { - $view = $item->query['view']; - - if (!isset(self::$lookup[$language][$view])) - { - self::$lookup[$language][$view] = array(); - } - - if (isset($item->query['id'])) - { - /** - * Here it will become a bit tricky - * language != * can override existing entries - * language == * cannot override existing entries - */ - if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*') - { - self::$lookup[$language][$view][$item->query['id']] = $item->id; - } - } - } - } - } - } - - if ($needles) - { - foreach ($needles as $view => $ids) - { - if (isset(self::$lookup[$language][$view])) - { - foreach ($ids as $id) - { - if (isset(self::$lookup[$language][$view][(int) $id])) - { - return self::$lookup[$language][$view][(int) $id]; - } - } - } - } - } - - // Check if the active menuitem matches the requested language - $active = $menus->getActive(); - - if ($active && ($language == '*' || in_array($active->language, array('*', $language)) || !JLanguageMultilang::isEnabled())) - { - return $active->id; - } - - // If not found, return language specific home link - $default = $menus->getDefault($language); - - return !empty($default->id) ? $default->id : null; - } -} diff --git a/src/components/com_weblinks/metadata.xml b/src/components/com_weblinks/metadata.xml deleted file mode 100644 index 9205b30..0000000 --- a/src/components/com_weblinks/metadata.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/com_weblinks/router.php b/src/components/com_weblinks/router.php deleted file mode 100644 index ee5253d..0000000 --- a/src/components/com_weblinks/router.php +++ /dev/null @@ -1,295 +0,0 @@ -getMenu(); - $params = JComponentHelper::getParams('com_weblinks'); - $advanced = $params->get('sef_advanced_link', 0); - - // We need a menu item. Either the one specified in the query, or the current active one if none specified - if (empty($query['Itemid'])) - { - $menuItem = $menu->getActive(); - } - else - { - $menuItem = $menu->getItem($query['Itemid']); - } - - $mView = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; - $mId = (empty($menuItem->query['id'])) ? null : $menuItem->query['id']; - - if (isset($query['view'])) - { - $view = $query['view']; - - if (empty($query['Itemid']) || empty($menuItem) || $menuItem->component != 'com_weblinks') - { - $segments[] = $query['view']; - } - - // We need to keep the view for forms since they never have their own menu item - if ($view != 'form') - { - unset($query['view']); - } - } - - // Are we dealing with an weblink that is attached to a menu item? - if (isset($query['view']) && ($mView == $query['view']) and (isset($query['id'])) and ($mId == (int) $query['id'])) - { - unset($query['view']); - unset($query['catid']); - unset($query['id']); - - return $segments; - } - - if (isset($view) and ($view == 'category' or $view == 'weblink')) - { - if ($mId != (int) $query['id'] || $mView != $view) - { - if ($view == 'weblink' && isset($query['catid'])) - { - $catid = $query['catid']; - } - elseif (isset($query['id'])) - { - $catid = $query['id']; - } - - $menuCatid = $mId; - $categories = JCategories::getInstance('Weblinks'); - $category = $categories->get($catid); - - if ($category) - { - // TODO Throw error that the category either not exists or is unpublished - $path = $category->getPath(); - $path = array_reverse($path); - - $array = array(); - - foreach ($path as $id) - { - if ((int) $id == (int) $menuCatid) - { - break; - } - - if ($advanced) - { - list($tmp, $id) = explode(':', $id, 2); - } - - $array[] = $id; - } - - $segments = array_merge($segments, array_reverse($array)); - } - - if ($view == 'weblink') - { - if ($advanced) - { - list($tmp, $id) = explode(':', $query['id'], 2); - } - else - { - $id = $query['id']; - } - - $segments[] = $id; - } - } - - unset($query['id']); - unset($query['catid']); - } - - if (isset($query['layout'])) - { - if (!empty($query['Itemid']) && isset($menuItem->query['layout'])) - { - if ($query['layout'] == $menuItem->query['layout']) - { - unset($query['layout']); - } - } - else - { - if ($query['layout'] == 'default') - { - unset($query['layout']); - } - } - } - - $total = count($segments); - - for ($i = 0; $i < $total; $i++) - { - $segments[$i] = str_replace(':', '-', $segments[$i]); - } - - return $segments; - } - - /** - * Parse the segments of a URL. - * - * @param array &$segments The segments of the URL to parse. - * - * @return array The URL attributes to be used by the application. - * - * @since 3.3 - */ - public function parse(&$segments) - { - $total = count($segments); - $vars = array(); - - for ($i = 0; $i < $total; $i++) - { - $segments[$i] = preg_replace('/-/', ':', $segments[$i], 1); - } - - // Get the active menu item. - $app = JFactory::getApplication(); - $menu = $app->getMenu(); - $item = $menu->getActive(); - $params = JComponentHelper::getParams('com_weblinks'); - $advanced = $params->get('sef_advanced_link', 0); - - // Count route segments - $count = count($segments); - - // Standard routing for weblinks. - if (!isset($item)) - { - $vars['view'] = $segments[0]; - $vars['id'] = $segments[$count - 1]; - - return $vars; - } - - // From the categories view, we can only jump to a category. - $id = (isset($item->query['id']) && $item->query['id'] > 1) ? $item->query['id'] : 'root'; - - $category = JCategories::getInstance('Weblinks')->get($id); - - $categories = $category->getChildren(); - $found = 0; - - foreach ($segments as $segment) - { - foreach ($categories as $category) - { - if (($category->slug == $segment) || ($advanced && $category->alias == str_replace(':', '-', $segment))) - { - $vars['id'] = $category->id; - $vars['view'] = 'category'; - $categories = $category->getChildren(); - $found = 1; - - break; - } - } - - if ($found == 0) - { - if ($advanced) - { - $db = JFactory::getDbo(); - $query = $db->getQuery(true) - ->select($db->quoteName('id')) - ->from('#__weblinks') - ->where($db->quoteName('catid') . ' = ' . (int) $vars['catid']) - ->where($db->quoteName('alias') . ' = ' . $db->quote(str_replace(':', '-', $segment))); - $db->setQuery($query); - $id = $db->loadResult(); - } - else - { - $id = $segment; - } - - $vars['id'] = $id; - $vars['view'] = 'weblink'; - - break; - } - - $found = 0; - } - - return $vars; - } -} - -/** - * Weblinks router functions - * - * @param array &$query An array of URL arguments - * - * @return array The URL arguments to use to assemble the subsequent URL. - * - * Note. These functions are proxies for the new router interface - * for old SEF extensions. - * - * @deprecated 4.0 Use Class based routers instead - */ -function WeblinksBuildRoute(&$query) -{ - $router = new WeblinksRouter; - - return $router->build($query); -} - -/** - * Weblinks router functions - * - * @param array $segments The segments of the URL to parse. - * - * @return array The URL attributes to be used by the application. - * - * Note. These functions are proxies for the new router interface - * for old SEF extensions. - * - * @deprecated 4.0 Use Class based routers instead - */ -function WeblinksParseRoute($segments) -{ - $router = new WeblinksRouter; - - return $router->parse($segments); -} diff --git a/src/components/com_weblinks/controller.php b/src/components/com_weblinks/src/Controller/DisplayController.php similarity index 79% rename from src/components/com_weblinks/controller.php rename to src/components/com_weblinks/src/Controller/DisplayController.php index 7516e40..acb1bec 100644 --- a/src/components/com_weblinks/controller.php +++ b/src/components/com_weblinks/src/Controller/DisplayController.php @@ -7,14 +7,19 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\Controller\BaseController; + /** * Weblinks Component Controller * * @since 1.5 */ -class WeblinksController extends JControllerLegacy +class DisplayController extends BaseController { /** * Method to display a view. @@ -23,7 +28,7 @@ class WeblinksController extends JControllerLegacy * @param array $urlparams An array of safe url parameters and their variable types, * for valid values see {@link JFilterInput::clean()}. * - * @return WeblinksController This object to support chaining. + * @return BaseController This object to support chaining. * * @since 1.5 */ @@ -41,7 +46,7 @@ class WeblinksController extends JControllerLegacy $vName = $this->input->get('view', 'categories'); $this->input->set('view', $vName); - if (JFactory::getUser()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories')) + if ($this->app->getIdentity()->id ||($this->input->getMethod() == 'POST' && $vName == 'categories')) { $cacheable = false; } @@ -59,7 +64,7 @@ class WeblinksController extends JControllerLegacy if ($vName == 'form' && !$this->checkEditId('com_weblinks.edit.weblink', $id)) { // Somehow the person just went to the form - we don't allow that. - return JError::raiseError(403, JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); + throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403); } return parent::display($cacheable, $safeurlparams); diff --git a/src/components/com_weblinks/controllers/weblink.php b/src/components/com_weblinks/src/Controller/WeblinkController.php similarity index 82% rename from src/components/com_weblinks/controllers/weblink.php rename to src/components/com_weblinks/src/Controller/WeblinkController.php index f219eb3..8773f93 100644 --- a/src/components/com_weblinks/controllers/weblink.php +++ b/src/components/com_weblinks/src/Controller/WeblinkController.php @@ -7,8 +7,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Controller; + defined('_JEXEC') or die; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\Uri\Uri; use Joomla\Utilities\ArrayHelper; /** @@ -16,7 +21,7 @@ use Joomla\Utilities\ArrayHelper; * * @since 1.5 */ -class WeblinksControllerWeblink extends JControllerForm +class WeblinkController extends FormController { /** * The URL view item variable. @@ -75,15 +80,10 @@ class WeblinksControllerWeblink extends JControllerForm if ($categoryId) { // If the category has been passed in the URL check it. - $allow = JFactory::getUser()->authorise('core.create', $this->option . '.category.' . $categoryId); + return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow !== null) - { - return $allow; - } - - // In the absense of better information, revert to the component permissions. + // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); } @@ -110,7 +110,7 @@ class WeblinksControllerWeblink extends JControllerForm if ($categoryId) { // The category has been set. Check the category permissions. - return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId); + return $this->app->getIdentity()->authorise('core.edit', $this->option . '.category.' . $categoryId); } // Since there is no asset tracking, revert to the component permissions. @@ -162,7 +162,7 @@ class WeblinksControllerWeblink extends JControllerForm * * @since 1.5 */ - public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true)) + public function getModel($name = 'form', $prefix = 'Site', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, $config); } @@ -207,9 +207,9 @@ class WeblinksControllerWeblink extends JControllerForm { $return = $this->input->get('return', null, 'base64'); - if (empty($return) || !JUri::isInternal(base64_decode($return))) + if (empty($return) || !Uri::isInternal(base64_decode($return))) { - return JUri::base(); + return Uri::base(); } return base64_decode($return); @@ -228,7 +228,7 @@ class WeblinksControllerWeblink extends JControllerForm public function save($key = null, $urlVar = 'w_id') { // Get the application - $app = JFactory::getApplication(); + $app = $this->app; // Get the data from POST $data = $this->input->post->get('jform', array(), 'array'); @@ -253,6 +253,8 @@ class WeblinksControllerWeblink extends JControllerForm * * @return void * + * @throws \Exception + * * @since 1.6 */ public function go() @@ -261,7 +263,7 @@ class WeblinksControllerWeblink extends JControllerForm $id = $this->input->getInt('id'); // Get the model, requiring published items - $modelLink = $this->getModel('Weblink', '', array('ignore_request' => true)); + $modelLink = $this->getModel('Weblink'); $modelLink->setState('filter.published', 1); // Get the item @@ -270,19 +272,19 @@ class WeblinksControllerWeblink extends JControllerForm // Make sure the item was found. if (empty($link)) { - return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); } // Check whether item access level allows access. - $groups = JFactory::getUser()->getAuthorisedViewLevels(); + $groups = $this->app->getIdentity()->getAuthorisedViewLevels(); if (!in_array($link->access, $groups)) { - return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); + throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); } // Check whether category access level allows access. - $modelCat = $this->getModel('Category', 'WeblinksModel', array('ignore_request' => true)); + $modelCat = $this->getModel('Category', 'Site', array('ignore_request' => true)); $modelCat->setState('filter.published', 1); // Get the category @@ -291,13 +293,13 @@ class WeblinksControllerWeblink extends JControllerForm // Make sure the category was found. if (empty($category)) { - return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); } // Check whether item access level allows access. if (!in_array($category->access, $groups)) { - return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); + throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); } // Redirect to the URL @@ -305,9 +307,9 @@ class WeblinksControllerWeblink extends JControllerForm if ($link->url) { $modelLink->hit($id); - JFactory::getApplication()->redirect($link->url, 301); + $this->app->redirect($link->url, 301); } - return JError::raiseWarning(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID')); + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_URL_INVALID'), 404); } } diff --git a/src/components/com_weblinks/helpers/association.php b/src/components/com_weblinks/src/Helper/AssociationHelper.php similarity index 54% rename from src/components/com_weblinks/helpers/association.php rename to src/components/com_weblinks/src/Helper/AssociationHelper.php index 88d26c2..279bc37 100644 --- a/src/components/com_weblinks/helpers/association.php +++ b/src/components/com_weblinks/src/Helper/AssociationHelper.php @@ -7,18 +7,20 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Helper; + defined('_JEXEC') or die; -JLoader::register('WeblinksHelper', JPATH_ADMINISTRATOR . '/components/com_weblinks/helpers/weblinks.php'); -JLoader::register('WeblinksHelperRoute', JPATH_SITE . '/components/com_weblinks/helpers/route.php'); -JLoader::register('CategoryHelperAssociation', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/association.php'); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Associations; +use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper; /** * Weblinks Component Association Helper * * @since 3.0 */ -abstract class WeblinksHelperAssociation extends CategoryHelperAssociation +abstract class AssociationHelper extends CategoryAssociationHelper { /** * Method to get the associations for a given item @@ -32,21 +34,21 @@ abstract class WeblinksHelperAssociation extends CategoryHelperAssociation */ public static function getAssociations($id = 0, $view = null) { - $jinput = JFactory::getApplication()->input; - $view = is_null($view) ? $jinput->get('view') : $view; - $id = empty($id) ? $jinput->getInt('id') : $id; + $input = Factory::getApplication()->input; + $view = is_null($view) ? $input->get('view') : $view; + $id = empty($id) ? $input->getInt('id') : $id; if ($view === 'weblink') { if ($id) { - $associations = JLanguageAssociations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id); + $associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $id); $return = array(); foreach ($associations as $tag => $item) { - $return[$tag] = WeblinksHelperRoute::getWeblinkRoute($item->id, (int) $item->catid, $item->language); + $return[$tag] = RouteHelper::getWeblinkRoute($item->id, (int) $item->catid, $item->language); } return $return; diff --git a/src/components/com_weblinks/src/Helper/RouteHelper.php b/src/components/com_weblinks/src/Helper/RouteHelper.php new file mode 100644 index 0000000..c85a2a2 --- /dev/null +++ b/src/components/com_weblinks/src/Helper/RouteHelper.php @@ -0,0 +1,115 @@ + 1) + { + $link .= '&catid=' . $catid; + } + + if ($language && $language !== '*' && Multilanguage::isEnabled()) + { + $link .= '&lang=' . $language; + } + + return $link; + } + + /** + * Ge the form route + * + * @param integer $id The id of the weblink. + * @param string $return The return page variable. + * + * @return string + */ + public static function getFormRoute($id, $return = null) + { + // Create the link. + if ($id) + { + $link = 'index.php?option=com_weblinks&task=weblink.edit&w_id=' . $id; + } + else + { + $link = 'index.php?option=com_weblinks&task=weblink.add&w_id=0'; + } + + if ($return) + { + $link .= '&return=' . $return; + } + + return $link; + } + + /** + * Get the Category Route + * + * @param CategoryNode|string|integer $catid JCategoryNode object or category ID + * @param integer $language Language code + * + * @return string + */ + public static function getCategoryRoute($catid, $language = 0) + { + if ($catid instanceof CategoryNode) + { + $id = $catid->id; + } + else + { + $id = (int) $catid; + } + + if ($id < 1) + { + $link = ''; + } + else + { + // Create the link + $link = 'index.php?option=com_weblinks&view=category&id=' . $id; + + if ($language && $language !== '*' && Multilanguage::isEnabled()) + { + $link .= '&lang=' . $language; + } + } + + return $link; + } +} diff --git a/src/components/com_weblinks/models/categories.php b/src/components/com_weblinks/src/Model/CategoriesModel.php similarity index 86% rename from src/components/com_weblinks/models/categories.php rename to src/components/com_weblinks/src/Model/CategoriesModel.php index 0ae095a..36b0913 100644 --- a/src/components/com_weblinks/models/categories.php +++ b/src/components/com_weblinks/src/Model/CategoriesModel.php @@ -7,6 +7,13 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Model; + +use Joomla\CMS\Categories\Categories; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\Registry\Registry; + defined('_JEXEC') or die; /** @@ -14,7 +21,7 @@ defined('_JEXEC') or die; * * @since 1.6 */ -class WeblinksModelCategories extends JModelList +class CategoriesModel extends ListModel { /** * Context string for the model type. This is used to handle uniqueness @@ -49,7 +56,7 @@ class WeblinksModelCategories extends JModelList */ protected function populateState($ordering = null, $direction = null) { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); $this->setState('filter.extension', $this->_extension); // Get the parent id if defined. @@ -92,21 +99,22 @@ class WeblinksModelCategories extends JModelList */ public function getItems() { - if (!count($this->_items)) + if ($this->_items === null) { - $app = JFactory::getApplication(); - $menu = $app->getMenu(); - $active = $menu->getActive(); - $params = new JRegistry; + $active = Factory::getApplication()->getMenu()->getActive(); if ($active) { - $params->loadString($active->params); + $params = $active->getParams(); + } + else + { + $params = new Registry; } $options = array(); $options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0); - $categories = JCategories::getInstance('Weblinks', $options); + $categories = Categories::getInstance('Weblinks', $options); $this->_parent = $categories->get($this->getState('filter.parentId', 'root')); if (is_object($this->_parent)) diff --git a/src/components/com_weblinks/models/category.php b/src/components/com_weblinks/src/Model/CategoryModel.php similarity index 87% rename from src/components/com_weblinks/models/category.php rename to src/components/com_weblinks/src/Model/CategoryModel.php index 9378226..f666f47 100644 --- a/src/components/com_weblinks/models/category.php +++ b/src/components/com_weblinks/src/Model/CategoryModel.php @@ -7,8 +7,17 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Model; + defined('_JEXEC') or die; +use Joomla\CMS\Categories\Categories; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Helper\TagsHelper; +use Joomla\CMS\Language\Multilanguage; +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Table\Table; use Joomla\Registry\Registry; /** @@ -16,7 +25,7 @@ use Joomla\Registry\Registry; * * @since 1.5 */ -class WeblinksModelCategory extends JModelList +class CategoryModel extends ListModel { /** * Category items data @@ -91,7 +100,7 @@ class WeblinksModelCategory extends JModelList } // Get the tags - $item->tags = new JHelperTags; + $item->tags = new TagsHelper(); $item->tags->getItemTags('com_weblinks.weblink', $item->id); } @@ -101,13 +110,13 @@ class WeblinksModelCategory extends JModelList /** * 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 1.6 */ protected function getListQuery() { - $groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels()); + $groups = implode(',', Factory::getUser()->getAuthorisedViewLevels()); // Create a new query object. $db = $this->getDbo(); @@ -164,7 +173,7 @@ class WeblinksModelCategory extends JModelList // Filter by start and end dates. $nullDate = $db->quote($db->getNullDate()); - $nowDate = $db->quote(JFactory::getDate()->toSql()); + $nowDate = $db->quote(Factory::getDate()->toSql()); if ($this->getState('filter.publish_date')) { @@ -175,7 +184,7 @@ class WeblinksModelCategory extends JModelList // Filter by language if ($this->getState('filter.language')) { - $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); + $query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } // Filter by search in title @@ -219,8 +228,8 @@ class WeblinksModelCategory extends JModelList */ protected function populateState($ordering = null, $direction = null) { - $app = JFactory::getApplication(); - $params = JComponentHelper::getParams('com_weblinks'); + $app = Factory::getApplication(); + $params = ComponentHelper::getParams('com_weblinks'); // List state information $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint'); @@ -253,7 +262,7 @@ class WeblinksModelCategory extends JModelList $id = $app->input->get('id', 0, 'int'); $this->setState('category.id', $id); - $user = JFactory::getUser(); + $user = Factory::getUser(); if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))) { @@ -264,7 +273,7 @@ class WeblinksModelCategory extends JModelList $this->setState('filter.publish_date', true); } - $this->setState('filter.language', JLanguageMultilang::isEnabled()); + $this->setState('filter.language', Multilanguage::isEnabled()); // Load the parameters. $this->setState('params', $params); @@ -281,21 +290,22 @@ class WeblinksModelCategory extends JModelList { if (!is_object($this->_item)) { - $app = JFactory::getApplication(); - $menu = $app->getMenu(); - $active = $menu->getActive(); - $params = new Registry; + $active = Factory::getApplication()->getMenu()->getActive(); if ($active) { - $params->loadString($active->params); + $params = $active->getParams(); + } + else + { + $params = new Registry; } $options = array(); $options['countItems'] = $params->get('show_cat_num_links_cat', 1) || $params->get('show_empty_categories', 0); - $categories = JCategories::getInstance('Weblinks', $options); + $categories = Categories::getInstance('Weblinks', $options); $this->_item = $categories->get($this->getState('category.id', 'root')); if (is_object($this->_item)) @@ -392,12 +402,12 @@ class WeblinksModelCategory extends JModelList */ public function hit($pk = 0) { - $hitcount = JFactory::getApplication()->input->getInt('hitcount', 1); + $hitcount = Factory::getApplication()->input->getInt('hitcount', 1); if ($hitcount) { $pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id'); - $table = JTable::getInstance('Category', 'JTable'); + $table = Table::getInstance('Category', 'JTable'); $table->load($pk); $table->hit($pk); } diff --git a/src/components/com_weblinks/models/form.php b/src/components/com_weblinks/src/Model/FormModel.php similarity index 72% rename from src/components/com_weblinks/models/form.php rename to src/components/com_weblinks/src/Model/FormModel.php index a7ef5f1..0436b0b 100644 --- a/src/components/com_weblinks/models/form.php +++ b/src/components/com_weblinks/src/Model/FormModel.php @@ -7,16 +7,21 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Model; + defined('_JEXEC') or die; -require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/weblink.php'; +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\CMS\Uri\Uri; +use Joomla\Component\Weblinks\Administrator\Model\WeblinkModel; /** * Weblinks model. * * @since 1.6 */ -class WeblinksModelForm extends WeblinksModelWeblink +class FormModel extends WeblinkModel { /** * Model typeAlias string. Used for version history. @@ -49,7 +54,7 @@ class WeblinksModelForm extends WeblinksModelWeblink */ protected function populateState() { - $app = JFactory::getApplication(); + $app = Factory::getApplication(); // Load state from the request. $pk = $app->input->getInt('w_id'); @@ -63,7 +68,7 @@ class WeblinksModelForm extends WeblinksModelWeblink $return = $app->input->get('return', null, 'base64'); - if (!JUri::isInternal(base64_decode($return))) + if (!Uri::isInternal(base64_decode($return))) { $return = null; } @@ -92,7 +97,7 @@ class WeblinksModelForm extends WeblinksModelWeblink $form = $this->loadForm('com_weblinks.form', 'weblink', array('control' => 'jform', 'load_data' => $loadData)); // Disable the buttons and just allow editor none for not authenticated users - if (JFactory::getUser()->guest) + if (Factory::getUser()->guest) { $form->setFieldAttribute('description', 'editor', 'none'); $form->setFieldAttribute('description', 'buttons', 'no'); @@ -100,4 +105,21 @@ class WeblinksModelForm extends WeblinksModelWeblink return $form; } + + /** + * 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 Table A Table object + * + * @since 4.0.0 + * @throws \Exception + */ + public function getTable($name = 'Weblink', $prefix = 'Administrator', $options = array()) + { + return parent::getTable($name, $prefix, $options); + } } diff --git a/src/components/com_weblinks/models/weblink.php b/src/components/com_weblinks/src/Model/WeblinkModel.php similarity index 82% rename from src/components/com_weblinks/models/weblink.php rename to src/components/com_weblinks/src/Model/WeblinkModel.php index 3c6ce13..f57b2db 100644 --- a/src/components/com_weblinks/models/weblink.php +++ b/src/components/com_weblinks/src/Model/WeblinkModel.php @@ -7,19 +7,23 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\Model; + defined('_JEXEC') or die; -use Joomla\Utilities\ArrayHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Multilanguage; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\Model\ItemModel; +use Joomla\CMS\Table\Table; use Joomla\Registry\Registry; -JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables'); - /** * Weblinks Component Model for a Weblink record * * @since 1.5 */ -class WeblinksModelWeblink extends JModelItem +class WeblinkModel extends ItemModel { /** * Model context string. @@ -39,7 +43,7 @@ class WeblinksModelWeblink extends JModelItem */ protected function populateState() { - $app = JFactory::getApplication('site'); + $app = Factory::getApplication(); // Load the object state. $pk = $app->input->getInt('id'); @@ -49,7 +53,7 @@ class WeblinksModelWeblink extends JModelItem $params = $app->getParams(); $this->setState('params', $params); - $user = JFactory::getUser(); + $user = $app->getIdentity(); if ((!$user->authorise('core.edit.state', 'com_weblinks')) && (!$user->authorise('core.edit', 'com_weblinks'))) { @@ -57,7 +61,7 @@ class WeblinksModelWeblink extends JModelItem $this->setState('filter.archived', 2); } - $this->setState('filter.language', JLanguageMultilang::isEnabled()); + $this->setState('filter.language', Multilanguage::isEnabled()); } /** @@ -69,7 +73,7 @@ class WeblinksModelWeblink extends JModelItem */ public function getItem($pk = null) { - $user = JFactory::getUser(); + $user = Factory::getUser(); $pk = (!empty($pk)) ? $pk : (int) $this->getState('weblink.id'); @@ -100,7 +104,7 @@ class WeblinksModelWeblink extends JModelItem // Filter by language if ($this->getState('filter.language')) { - $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); + $query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } // Join over the categories to get parent category titles @@ -111,9 +115,8 @@ class WeblinksModelWeblink extends JModelItem { // Filter by start and end dates. $nullDate = $db->quote($db->getNullDate()); - $date = JFactory::getDate(); - $nowDate = $db->quote($date->toSql()); + $nowDate = $db->quote(Factory::getDate()->toSql()); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')') ->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); @@ -134,13 +137,13 @@ class WeblinksModelWeblink extends JModelItem if (empty($data)) { - JError::raiseError(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); } // Check for published state if filter set. if ((is_numeric($published) || is_numeric($archived)) && (($data->state != $published) && ($data->state != $archived))) { - JError::raiseError(404, JText::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND')); + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_WEBLINK_NOT_FOUND'), 404); } // Convert parameter fields to objects. @@ -162,7 +165,7 @@ class WeblinksModelWeblink extends JModelItem $this->_item[$pk] = $data; } - catch (Exception $e) + catch (\Exception $e) { $this->setError($e); $this->_item[$pk] = false; @@ -179,13 +182,13 @@ class WeblinksModelWeblink extends JModelItem * @param string $prefix A prefix for the table class name. Optional. * @param array $config Configuration array for model. Optional. * - * @return JTable A database object + * @return Table A database object * * @since 1.6 */ - public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array()) + public function getTable($type = 'Weblink', $prefix = 'Administrator', $config = array()) { - return JTable::getInstance($type, $prefix, $config); + return parent::getTable($type, $prefix, $config); } /** @@ -202,6 +205,6 @@ class WeblinksModelWeblink extends JModelItem $pk = $this->getState('weblink.id'); } - return $this->getTable('Weblink', 'WeblinksTable')->hit($pk); + return $this->getTable('Weblink')->hit($pk); } } diff --git a/src/components/com_weblinks/src/Service/Category.php b/src/components/com_weblinks/src/Service/Category.php new file mode 100644 index 0000000..9070cc7 --- /dev/null +++ b/src/components/com_weblinks/src/Service/Category.php @@ -0,0 +1,37 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Component\Weblinks\Site\Service; + +\defined('_JEXEC') or die; + +use Joomla\CMS\Categories\Categories; + +/** + * Content Component Category Tree + * + * @since 1.6 + */ +class Category extends Categories +{ + /** + * Class constructor + * + * @param array $options Array of options + * + * @since 1.7.0 + */ + public function __construct($options = array()) + { + $options['table'] = '#__weblinks'; + $options['extension'] = 'com_weblinks'; + + parent::__construct($options); + } +} diff --git a/src/components/com_weblinks/src/Service/Router.php b/src/components/com_weblinks/src/Service/Router.php new file mode 100644 index 0000000..5a7a2c7 --- /dev/null +++ b/src/components/com_weblinks/src/Service/Router.php @@ -0,0 +1,298 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Component\Weblinks\Site\Service; + +\defined('_JEXEC') or die; + +use Joomla\CMS\Application\SiteApplication; +use Joomla\CMS\Categories\CategoryFactoryInterface; +use Joomla\CMS\Categories\CategoryInterface; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Component\Router\RouterView; +use Joomla\CMS\Component\Router\RouterViewConfiguration; +use Joomla\CMS\Component\Router\Rules\MenuRules; +use Joomla\CMS\Component\Router\Rules\NomenuRules; +use Joomla\CMS\Component\Router\Rules\StandardRules; +use Joomla\CMS\Menu\AbstractMenu; +use Joomla\Database\DatabaseInterface; +use Joomla\Database\ParameterType; + +/** + * Routing class from com_contact + * + * @since 3.3 + */ +class Router extends RouterView +{ + /** + * Flag to remove IDs + * + * @var boolean + */ + protected $noIDs = false; + + /** + * The category factory + * + * @var CategoryFactoryInterface + * + * @since 4.0.0 + */ + private $categoryFactory; + + /** + * The category cache + * + * @var array + * + * @since 4.0.0 + */ + private $categoryCache = []; + + /** + * The db + * + * @var DatabaseInterface + * + * @since 4.0.0 + */ + private $db; + + /** + * Content Component router constructor + * + * @param SiteApplication $app The application object + * @param AbstractMenu $menu The menu object to work with + * @param CategoryFactoryInterface $categoryFactory The category object + * @param DatabaseInterface $db The database object + */ + public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db) + { + $this->categoryFactory = $categoryFactory; + $this->db = $db; + + $params = ComponentHelper::getParams('com_weblinks'); + $this->noIDs = (bool) $params->get('sef_ids'); + $categories = new RouterViewConfiguration('categories'); + $categories->setKey('id'); + $this->registerView($categories); + $category = new RouterViewConfiguration('category'); + $category->setKey('id')->setParent($categories, 'catid')->setNestable(); + $this->registerView($category); + $webLink = new RouterViewConfiguration('weblink'); + $webLink->setKey('id')->setParent($category, 'catid'); + $this->registerView($webLink); + $form = new RouterViewConfiguration('form'); + $form->setKey('id'); + $this->registerView($form); + + parent::__construct($app, $menu); + + $this->attachRule(new MenuRules($this)); + $this->attachRule(new StandardRules($this)); + $this->attachRule(new NomenuRules($this)); + } + + /** + * Method to get the segment(s) for a category + * + * @param string $id ID of the category to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + */ + public function getCategorySegment($id, $query) + { + $category = $this->getCategories()->get($id); + + if ($category) + { + $path = array_reverse($category->getPath(), true); + $path[0] = '1:root'; + + if ($this->noIDs) + { + foreach ($path as &$segment) + { + list($id, $segment) = explode(':', $segment, 2); + } + } + + return $path; + } + + return array(); + } + + /** + * Method to get the segment(s) for a category + * + * @param string $id ID of the category to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + */ + public function getCategoriesSegment($id, $query) + { + return $this->getCategorySegment($id, $query); + } + + /** + * Method to get the segment(s) for a weblink + * + * @param string $id ID of the contact to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + */ + public function getWeblinkSegment($id, $query) + { + if (!strpos($id, ':')) + { + $id = (int) $id; + $dbquery = $this->db->getQuery(true); + $dbquery->select($this->db->quoteName('alias')) + ->from($this->db->quoteName('#__weblinks')) + ->where($this->db->quoteName('id') . ' = :id') + ->bind(':id', $id, ParameterType::INTEGER); + $this->db->setQuery($dbquery); + + $id .= ':' . $this->db->loadResult(); + } + + if ($this->noIDs) + { + list($void, $segment) = explode(':', $id, 2); + + return array($void => $segment); + } + + return array((int) $id => $id); + } + + /** + * Method to get the segment(s) for a form + * + * @param string $id ID of the contact form to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + * + * @since 4.0.0 + */ + public function getFormSegment($id, $query) + { + return $this->getWeblinkSegment($id, $query); + } + + /** + * Method to get the id for a category + * + * @param string $segment Segment to retrieve the ID for + * @param array $query The request that is parsed right now + * + * @return mixed The id of this item or false + */ + public function getCategoryId($segment, $query) + { + if (isset($query['id'])) + { + $category = $this->getCategories(['access' => false])->get($query['id']); + + if ($category) + { + foreach ($category->getChildren() as $child) + { + if ($this->noIDs) + { + if ($child->alias == $segment) + { + return $child->id; + } + } + else + { + if ($child->id == (int) $segment) + { + return $child->id; + } + } + } + } + } + + return false; + } + + /** + * Method to get the segment(s) for a category + * + * @param string $segment Segment to retrieve the ID for + * @param array $query The request that is parsed right now + * + * @return mixed The id of this item or false + */ + public function getCategoriesId($segment, $query) + { + return $this->getCategoryId($segment, $query); + } + + /** + * Method to get the segment(s) for a contact + * + * @param string $segment Segment of the contact to retrieve the ID for + * @param array $query The request that is parsed right now + * + * @return mixed The id of this item or false + */ + public function getWeblinkId($segment, $query) + { + if ($this->noIDs) + { + $dbquery = $this->db->getQuery(true); + $dbquery->select($this->db->quoteName('id')) + ->from($this->db->quoteName('#__weblinks')) + ->where( + [ + $this->db->quoteName('alias') . ' = :alias', + $this->db->quoteName('catid') . ' = :catid', + ] + ) + ->bind(':alias', $segment) + ->bind(':catid', $query['id'], ParameterType::INTEGER); + $this->db->setQuery($dbquery); + + return (int) $this->db->loadResult(); + } + + return (int) $segment; + } + + /** + * Method to get categories from cache + * + * @param array $options The options for retrieving categories + * + * @return CategoryInterface The object containing categories + * + * @since 4.0.0 + */ + private function getCategories(array $options = []): CategoryInterface + { + $key = serialize($options); + + if (!isset($this->categoryCache[$key])) + { + $this->categoryCache[$key] = $this->categoryFactory->createCategory($options); + } + + return $this->categoryCache[$key]; + } +} diff --git a/src/components/com_weblinks/src/View/Categories/HtmlView.php b/src/components/com_weblinks/src/View/Categories/HtmlView.php new file mode 100644 index 0000000..8e30794 --- /dev/null +++ b/src/components/com_weblinks/src/View/Categories/HtmlView.php @@ -0,0 +1,34 @@ +items as $item) + { + $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; + + if ($item->params->get('count_clicks', $this->params->get('count_clicks', 1)) == 1) + { + $item->link = Route::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id); + } + else + { + $item->link = $item->url; + } + + $temp = new Registry; + $temp->loadString($item->params); + $item->params = clone($this->params); + $item->params->merge($temp); + } + + return parent::display($tpl); + } + + /** + * Prepares the document + * + * @return void + */ + protected function prepareDocument() + { + parent::prepareDocument();; + + parent::addFeed(); + + + if ($this->menuItemMatchCategory) + { + // If the active menu item is linked directly to the category being displayed, no further process is needed + return; + } + + // Get ID of the category from active menu item + $menu = $this->menu; + + if ($menu && $menu->component == 'com_weblinks' && isset($menu->query['view']) + && in_array($menu->query['view'], ['categories', 'category'])) + { + $id = $menu->query['id']; + } + else + { + $id = 0; + } + + $path = [['title' => $this->category->title, 'link' => '']]; + $category = $this->category->getParent(); + + while ($category !== null && $category->id != $id && $category->id !== 'root') + { + $path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)]; + $category = $category->getParent(); + } + + $path = array_reverse($path); + + foreach ($path as $item) + { + $this->pathway->addItem($item['title'], $item['link']); + } + } +} diff --git a/src/components/com_weblinks/views/form/view.html.php b/src/components/com_weblinks/src/View/Form/HtmlView.php similarity index 71% rename from src/components/com_weblinks/views/form/view.html.php rename to src/components/com_weblinks/src/View/Form/HtmlView.php index 437ef72..73d8781 100644 --- a/src/components/com_weblinks/views/form/view.html.php +++ b/src/components/com_weblinks/src/View/Form/HtmlView.php @@ -7,23 +7,58 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\View\Form; + defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; + /** * HTML Article View class for the Weblinks component * * @since 1.5 */ -class WeblinksViewForm extends JViewLegacy +class HtmlView extends BaseHtmlView { + /** + * @var \Joomla\CMS\Form\Form + * @since 4.0.0 + */ protected $form; + /** + * @var object + * @since 4.0.0 + */ protected $item; + /** + * @var string + * @since 4.0.0 + */ protected $return_page; + /** + * @var string + * @since 4.0.0 + */ + protected $pageclass_sfx; + + /** + * @var \Joomla\Registry\Registry + * @since 4.0.0 + */ protected $state; + /** + * @var \Joomla\Registry\Registry + * @since 4.0.0 + */ + protected $params; + /** * Display the view. * @@ -33,7 +68,7 @@ class WeblinksViewForm extends JViewLegacy */ public function display($tpl = null) { - $user = JFactory::getUser(); + $user = Factory::getUser(); // Get model data. $this->state = $this->get('State'); @@ -52,15 +87,13 @@ class WeblinksViewForm extends JViewLegacy if ($authorised !== true) { - JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); - - return false; + throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403); } if (!empty($this->item)) { // Override the base weblink data with any data in the session. - $temp = (array) JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); + $temp = (array) Factory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array()); foreach ($temp as $k => $v) { @@ -73,9 +106,7 @@ class WeblinksViewForm extends JViewLegacy // Check for errors. if (count($errors = $this->get('Errors'))) { - JError::raiseWarning(500, implode("\n", $errors)); - - return false; + throw new GenericDataException(implode("\n", $errors), 500); } // Create a shortcut to the parameters. @@ -88,6 +119,7 @@ class WeblinksViewForm extends JViewLegacy $this->user = $user; $this->_prepareDocument(); + parent::display($tpl); } @@ -98,21 +130,19 @@ class WeblinksViewForm extends JViewLegacy */ protected function _prepareDocument() { - $app = JFactory::getApplication(); - $menus = $app->getMenu(); - $title = null; + $app = Factory::getApplication(); // Because the application sets a default page title, // we need to get it from the menu item itself - $menu = $menus->getActive(); + $menu = $app->getMenu()->getActive(); if (empty($this->item->id)) { - $head = JText::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK'); + $head = Text::_('COM_WEBLINKS_FORM_SUBMIT_WEBLINK'); } else { - $head = JText::_('COM_WEBLINKS_FORM_EDIT_WEBLINK'); + $head = Text::_('COM_WEBLINKS_FORM_EDIT_WEBLINK'); } if ($menu) @@ -126,16 +156,7 @@ class WeblinksViewForm extends JViewLegacy $title = $this->params->def('page_title', $head); - if ($app->get('sitename_pagetitles', 0) == 1) - { - $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title); - } - elseif ($app->get('sitename_pagetitles', 0) == 2) - { - $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename')); - } - - $this->document->setTitle($title); + $this->setDocumentTitle($title); if ($this->params->get('menu-meta_description')) { diff --git a/src/components/com_weblinks/views/weblink/view.html.php b/src/components/com_weblinks/src/View/Weblink/HtmlView.php similarity index 97% rename from src/components/com_weblinks/views/weblink/view.html.php rename to src/components/com_weblinks/src/View/Weblink/HtmlView.php index 045e31d..0077aa6 100644 --- a/src/components/com_weblinks/views/weblink/view.html.php +++ b/src/components/com_weblinks/src/View/Weblink/HtmlView.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +namespace Joomla\Component\Weblinks\Site\View\Weblink; + defined('_JEXEC') or die; /** diff --git a/src/components/com_weblinks/views/categories/tmpl/default.php b/src/components/com_weblinks/tmpl/categories/default.php similarity index 96% rename from src/components/com_weblinks/views/categories/tmpl/default.php rename to src/components/com_weblinks/tmpl/categories/default.php index 06aa428..150af0b 100644 --- a/src/components/com_weblinks/views/categories/tmpl/default.php +++ b/src/components/com_weblinks/tmpl/categories/default.php @@ -10,7 +10,6 @@ defined('_JEXEC') or die; JHtml::addIncludePath(JPATH_COMPONENT . '/helpers'); -JHtml::_('behavior.caption'); JFactory::getDocument()->addScriptDeclaration(" jQuery(function($) { diff --git a/src/components/com_weblinks/views/categories/tmpl/default.xml b/src/components/com_weblinks/tmpl/categories/default.xml similarity index 100% rename from src/components/com_weblinks/views/categories/tmpl/default.xml rename to src/components/com_weblinks/tmpl/categories/default.xml diff --git a/src/components/com_weblinks/views/categories/tmpl/default_items.php b/src/components/com_weblinks/tmpl/categories/default_items.php similarity index 94% rename from src/components/com_weblinks/views/categories/tmpl/default_items.php rename to src/components/com_weblinks/tmpl/categories/default_items.php index a702eca..89cd815 100644 --- a/src/components/com_weblinks/views/categories/tmpl/default_items.php +++ b/src/components/com_weblinks/tmpl/categories/default_items.php @@ -9,6 +9,8 @@ defined('_JEXEC') or die; +use Joomla\Component\Weblinks\Site\Helper\RouteHelper; + JHtml::_('bootstrap.tooltip'); $class = ' class="first"'; @@ -26,7 +28,7 @@ if (count($this->items[$this->parent->id]) > 0 && $this->maxLevelcat != 0) :
>
tags->getItemTags('com_weblinks.weblink', $item->id); ?> params->get('show_tags', 1)) : ?> - item->tagLayout = new JLayoutFile('joomla.content.tags'); ?> - item->tagLayout->render($tagsData); ?> + category->tagLayout = new JLayoutFile('joomla.content.tags'); ?> + category->tagLayout->render($tagsData); ?> params->get('show_link_description')) and ($item->description != '')) : ?> images); ?> diff --git a/src/components/com_weblinks/views/category/metadata.xml b/src/components/com_weblinks/tmpl/category/metadata.xml similarity index 100% rename from src/components/com_weblinks/views/category/metadata.xml rename to src/components/com_weblinks/tmpl/category/metadata.xml diff --git a/src/components/com_weblinks/views/form/tmpl/edit.php b/src/components/com_weblinks/tmpl/form/edit.php similarity index 92% rename from src/components/com_weblinks/views/form/tmpl/edit.php rename to src/components/com_weblinks/tmpl/form/edit.php index c878f25..b6f3934 100644 --- a/src/components/com_weblinks/views/form/tmpl/edit.php +++ b/src/components/com_weblinks/tmpl/form/edit.php @@ -9,10 +9,11 @@ defined('_JEXEC') or die; -JHtml::_('behavior.keepalive'); -JHtml::_('behavior.formvalidation'); -JHtml::_('formbehavior.chosen', 'select'); -JHtml::_('behavior.modal', 'a.modal_jform_contenthistory'); +use Joomla\CMS\HTML\HTMLHelper; + +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('behavior.formvalidator'); +// JHtml::_('behavior.modal', 'a.modal_jform_contenthistory'); $captchaEnabled = false; $captchaSet = $this->params->get('captcha', JFactory::getApplication()->get('captcha', '0')); @@ -35,7 +36,6 @@ $params = $this->state->get('params'); { if (task == 'weblink.cancel' || document.formvalidator.isValid(document.getElementById('adminForm'))) { - form->getField('description')->save(); ?> Joomla.submitform(task); } } diff --git a/src/components/com_weblinks/views/form/tmpl/edit.xml b/src/components/com_weblinks/tmpl/form/edit.xml similarity index 100% rename from src/components/com_weblinks/views/form/tmpl/edit.xml rename to src/components/com_weblinks/tmpl/form/edit.xml diff --git a/src/components/com_weblinks/views/form/metadata.xml b/src/components/com_weblinks/tmpl/form/metadata.xml similarity index 100% rename from src/components/com_weblinks/views/form/metadata.xml rename to src/components/com_weblinks/tmpl/form/metadata.xml diff --git a/src/components/com_weblinks/views/weblink/tmpl/default.php b/src/components/com_weblinks/tmpl/weblink/default.php similarity index 100% rename from src/components/com_weblinks/views/weblink/tmpl/default.php rename to src/components/com_weblinks/tmpl/weblink/default.php diff --git a/src/components/com_weblinks/views/weblink/tmpl/default.xml b/src/components/com_weblinks/tmpl/weblink/default.xml similarity index 100% rename from src/components/com_weblinks/views/weblink/tmpl/default.xml rename to src/components/com_weblinks/tmpl/weblink/default.xml diff --git a/src/components/com_weblinks/views/categories/view.html.php b/src/components/com_weblinks/views/categories/view.html.php deleted file mode 100644 index 2531105..0000000 --- a/src/components/com_weblinks/views/categories/view.html.php +++ /dev/null @@ -1,83 +0,0 @@ -get('State'); - $items = $this->get('Items'); - $parent = $this->get('Parent'); - - // Check for errors. - if (count($errors = $this->get('Errors'))) - { - JError::raiseWarning(500, implode("\n", $errors)); - return false; - } - - if ($items === false) - { - return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); - } - - if ($parent == false) - { - return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); - } - - $params = &$state->params; - - $items = array($parent->id => $items); - - // Escape strings for HTML output - $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); - - $this->maxLevelcat = $params->get('maxLevelcat', -1); - $this->params = &$params; - $this->parent = &$parent; - $this->items = &$items; - - return parent::display($tpl); - } -} diff --git a/src/components/com_weblinks/views/category/view.html.php b/src/components/com_weblinks/views/category/view.html.php deleted file mode 100644 index 78fe1fc..0000000 --- a/src/components/com_weblinks/views/category/view.html.php +++ /dev/null @@ -1,105 +0,0 @@ -items as $item) - { - $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; - - if ($item->params->get('count_clicks', $this->params->get('count_clicks', 1)) == 1) - { - $item->link = JRoute::_('index.php?option=com_weblinks&task=weblink.go&id=' . $item->id); - } - else - { - $item->link = $item->url; - } - - $temp = new JRegistry; - $temp->loadString($item->params); - $item->params = clone($this->params); - $item->params->merge($temp); - } - - return parent::display($tpl); - } - - /** - * Prepares the document - * - * @return void - */ - protected function prepareDocument() - { - parent::prepareDocument(); - - $app = JFactory::getApplication(); - $menus = $app->getMenu(); - $pathway = $app->getPathway(); - $title = null; - - // Because the application sets a default page title, - // we need to get it from the menu item itself - $menu = $menus->getActive(); - - if ($menu) - { - $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); - } - else - { - $this->params->def('page_heading', JText::_('COM_WEBLINKS_DEFAULT_PAGE_TITLE')); - } - - $id = (int) @$menu->query['id']; - - if ($menu && ($menu->query['option'] != 'com_weblinks' || $id != $this->category->id)) - { - $this->params->set('page_subheading', $this->category->title); - $path = array(array('title' => $this->category->title, 'link' => '')); - $category = $this->category->getParent(); - - while (($menu->query['option'] != 'com_weblinks' || $id != $category->id) && $category->id > 1) - { - $path[] = array('title' => $category->title, 'link' => WeblinksHelperRoute::getCategoryRoute($category->id)); - $category = $category->getParent(); - } - - $path = array_reverse($path); - - foreach ($path as $item) - { - $pathway->addItem($item['title'], $item['link']); - } - } - - parent::addFeed(); - } -} diff --git a/src/components/com_weblinks/weblinks.php b/src/components/com_weblinks/weblinks.php deleted file mode 100644 index e025468..0000000 --- a/src/components/com_weblinks/weblinks.php +++ /dev/null @@ -1,16 +0,0 @@ -execute(JFactory::getApplication()->input->get('task')); -$controller->redirect();