diff --git a/plugins/content/pagenavigation/pagenavigation.xml b/plugins/content/pagenavigation/pagenavigation.xml index ba65a760a22ff..66656880fa97a 100644 --- a/plugins/content/pagenavigation/pagenavigation.xml +++ b/plugins/content/pagenavigation/pagenavigation.xml @@ -9,8 +9,10 @@ www.joomla.org 3.0.0 PLG_PAGENAVIGATION_XML_DESCRIPTION + Joomla\Plugin\Content\PageNavigation - pagenavigation.php + services + src tmpl diff --git a/plugins/content/pagenavigation/services/provider.php b/plugins/content/pagenavigation/services/provider.php new file mode 100644 index 0000000000000..80ba6554386ed --- /dev/null +++ b/plugins/content/pagenavigation/services/provider.php @@ -0,0 +1,49 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Extension\PluginInterface; +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\Database\DatabaseInterface; +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use Joomla\Event\DispatcherInterface; +use Joomla\Plugin\Content\PageNavigation\Extension\PageNavigation; + +return new class () implements ServiceProviderInterface { + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function register(Container $container): void + { + $container->set( + PluginInterface::class, + function (Container $container) { + $dispatcher = $container->get(DispatcherInterface::class); + $plugin = new PageNavigation( + $dispatcher, + (array) PluginHelper::getPlugin('content', 'pagenavigation') + ); + $plugin->setApplication(Factory::getApplication()); + $plugin->setDatabase($container->get(DatabaseInterface::class)); + + return $plugin; + } + ); + } +}; diff --git a/plugins/content/pagenavigation/pagenavigation.php b/plugins/content/pagenavigation/src/Extension/PageNavigation.php similarity index 95% rename from plugins/content/pagenavigation/pagenavigation.php rename to plugins/content/pagenavigation/src/Extension/PageNavigation.php index dd858a58af007..da174d2eb8dc1 100644 --- a/plugins/content/pagenavigation/pagenavigation.php +++ b/plugins/content/pagenavigation/src/Extension/PageNavigation.php @@ -6,16 +6,16 @@ * * @copyright (C) 2006 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt - - * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace */ +namespace Joomla\Plugin\Content\PageNavigation\Extension; + use Joomla\CMS\Access\Access; use Joomla\CMS\Factory; -use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; use Joomla\Component\Content\Site\Helper\RouteHelper; +use Joomla\Database\DatabaseAwareTrait; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects @@ -27,8 +27,10 @@ * * @since 1.5 */ -class PlgContentPagenavigation extends CMSPlugin +final class PageNavigation extends CMSPlugin { + use DatabaseAwareTrait; + /** * If in the article view and the parameter is enabled shows the page navigation * @@ -43,7 +45,7 @@ class PlgContentPagenavigation extends CMSPlugin */ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) { - $app = Factory::getApplication(); + $app = $this->getApplication(); $view = $app->getInput()->get('view'); $print = $app->getInput()->getBool('print'); @@ -52,9 +54,9 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) } if ($context === 'com_content.article' && $view === 'article' && $params->get('show_item_navigation')) { - $db = Factory::getDbo(); - $user = Factory::getUser(); - $lang = Factory::getLanguage(); + $db = $this->getDatabase(); + $user = $app->getIdentity(); + $lang = $app->getLanguage(); $now = Factory::getDate()->toSql(); $query = $db->getQuery(true); $uid = $row->id; @@ -210,7 +212,7 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) } if ($row->prev) { - $row->prev_label = ($this->params->get('display', 0) == 0) ? Text::_('JPREV') : $row->prev->title; + $row->prev_label = ($this->params->get('display', 0) == 0) ? $lang->_('JPREV') : $row->prev->title; $row->prev = RouteHelper::getArticleRoute($row->prev->slug, $row->prev->catid, $row->prev->language); } else { $row->prev_label = ''; @@ -218,7 +220,7 @@ public function onContentBeforeDisplay($context, &$row, &$params, $page = 0) } if ($row->next) { - $row->next_label = ($this->params->get('display', 0) == 0) ? Text::_('JNEXT') : $row->next->title; + $row->next_label = ($this->params->get('display', 0) == 0) ? $lang->_('JNEXT') : $row->next->title; $row->next = RouteHelper::getArticleRoute($row->next->slug, $row->next->catid, $row->next->language); } else { $row->next_label = '';