diff --git a/src/plugins/system/weblinks/services/provider.php b/src/plugins/system/weblinks/services/provider.php new file mode 100644 index 0000000..f698b3d --- /dev/null +++ b/src/plugins/system/weblinks/services/provider.php @@ -0,0 +1,47 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +defined('_JEXEC') or die; + +use Joomla\CMS\Extension\PluginInterface; +use Joomla\CMS\Plugin\PluginHelper; +use Joomla\Database\DatabaseInterface; +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use Joomla\Event\DispatcherInterface; +use Joomla\Plugin\System\Weblinks\Extension\Weblinks; + +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) + { + $container->set( + PluginInterface::class, + function (Container $container) { + $dispatcher = $container->get(DispatcherInterface::class); + $db = $container->get(DatabaseInterface::class); + + return new Weblinks( + $dispatcher, + (array) PluginHelper::getPlugin('system', 'weblinks'), + $db + ); + } + ); + } +}; diff --git a/src/plugins/system/weblinks/src/Extension/Weblinks.php b/src/plugins/system/weblinks/src/Extension/Weblinks.php new file mode 100644 index 0000000..70448bc --- /dev/null +++ b/src/plugins/system/weblinks/src/Extension/Weblinks.php @@ -0,0 +1,122 @@ +setDatabase($database); + } + + /** + * Returns an array of CMS events this plugin will listen to and the respective handlers. + * + * @return array + * + * @since 4.2.0 + */ + public static function getSubscribedEvents(): array + { + return [ + 'onGetStats' => 'onGetStats', + ]; + } + + /** + * Method to add statistics information to Administrator control panel. + * + * @param string $extension The extension requesting information. + * + * @return array containing statistical information. + * + * @since __DEPLOY_VERSION__ + */ + public function onGetStats(Event $event) + { + if (!ComponentHelper::isEnabled('com_weblinks')) + { + return []; + } + + [$extension] = $event->getArguments(); + + if (!in_array($extension, $this->supportedExtensions)) + { + return []; + } + + $db = $this->getDatabase(); + $query = $db->getQuery(true) + ->select('COUNT(id) AS count_links') + ->from('#__weblinks') + ->where('state = 1'); + $webLinks = $db->setQuery($query)->loadResult(); + + if (!$webLinks) + { + return []; + } + + return [ + [ + 'title' => Text::_('PLG_SYSTEM_WEBLINKS_STATISTICS'), + 'icon' => 'out-2', + 'data' => $webLinks, + ], + ]; + } +} diff --git a/src/plugins/system/weblinks/weblinks.php b/src/plugins/system/weblinks/weblinks.php deleted file mode 100644 index 76ffde5..0000000 --- a/src/plugins/system/weblinks/weblinks.php +++ /dev/null @@ -1,88 +0,0 @@ -supportedExtensions)) - { - return array(); - } - - if (!ComponentHelper::isEnabled('com_weblinks')) - { - return array(); - } - - $query = $this->db->getQuery(true) - ->select('COUNT(id) AS count_links') - ->from('#__weblinks') - ->where('state = 1'); - $webLinks = $this->db->setQuery($query)->loadResult(); - - if (!$webLinks) - { - return array(); - } - - return array(array( - 'title' => Text::_('PLG_SYSTEM_WEBLINKS_STATISTICS'), - 'icon' => 'out-2', - 'data' => $webLinks - )); - } -} diff --git a/src/plugins/system/weblinks/weblinks.xml b/src/plugins/system/weblinks/weblinks.xml index 604c0f6..d922aed 100644 --- a/src/plugins/system/weblinks/weblinks.xml +++ b/src/plugins/system/weblinks/weblinks.xml @@ -10,7 +10,8 @@ ##VERSION## PLG_SYSTEM_WEBLINKS_XML_DESCRIPTION - ##FILES## + services + src ##LANGUAGE_FILES##