Merge pull request #517 from joomdonation/convert_weblink_system_plugin
Convert System - Weblinks plugin to service provider
This commit is contained in:
commit
4bb87b8845
|
@ -52,6 +52,7 @@ class Com_WeblinksInstallerScript
|
||||||
'/plugins/search/weblinks/weblinks.php',
|
'/plugins/search/weblinks/weblinks.php',
|
||||||
'/plugins/finder/weblinks/weblinks.php',
|
'/plugins/finder/weblinks/weblinks.php',
|
||||||
'/plugins/editors-xtd/weblink/weblink.php',
|
'/plugins/editors-xtd/weblink/weblink.php',
|
||||||
|
'plugins/system/weblinks/weblinks.php',
|
||||||
];
|
];
|
||||||
|
|
||||||
$folders = [
|
$folders = [
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package Joomla.Plugin
|
||||||
|
* @subpackage System.weblinks
|
||||||
|
*
|
||||||
|
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||||
|
* @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);
|
||||||
|
$database = $container->get(DatabaseInterface::class);
|
||||||
|
|
||||||
|
return new Weblinks(
|
||||||
|
$dispatcher,
|
||||||
|
(array) PluginHelper::getPlugin('system', 'weblinks'),
|
||||||
|
$database
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,125 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @package Joomla.Administrator
|
||||||
|
* @subpackage Weblinks
|
||||||
|
*
|
||||||
|
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
|
||||||
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Joomla\Plugin\System\Weblinks\Extension;
|
||||||
|
|
||||||
|
use Joomla\CMS\Component\ComponentHelper;
|
||||||
|
use Joomla\CMS\Language\Text;
|
||||||
|
use Joomla\CMS\Plugin\CMSPlugin;
|
||||||
|
use Joomla\Database\DatabaseAwareTrait;
|
||||||
|
use Joomla\Database\DatabaseInterface;
|
||||||
|
use Joomla\Event\DispatcherInterface;
|
||||||
|
use Joomla\Event\Event;
|
||||||
|
use Joomla\Event\SubscriberInterface;
|
||||||
|
|
||||||
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* System plugin for Joomla Web Links.
|
||||||
|
*
|
||||||
|
* @since __DEPLOY_VERSION__
|
||||||
|
*/
|
||||||
|
final class Weblinks extends CMSPlugin implements SubscriberInterface
|
||||||
|
{
|
||||||
|
use DatabaseAwareTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the language file on instantiation.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @since __DEPLOY_VERSION__
|
||||||
|
*/
|
||||||
|
protected $autoloadLanguage = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supported Extensions
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @since __DEPLOY_VERSION__
|
||||||
|
*/
|
||||||
|
private $supportedExtensions = [
|
||||||
|
'mod_stats',
|
||||||
|
'mod_stats_admin',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param DispatcherInterface $dispatcher
|
||||||
|
* @param array $config
|
||||||
|
* @param DatabaseInterface $database
|
||||||
|
*/
|
||||||
|
public function __construct(DispatcherInterface $dispatcher, array $config, DatabaseInterface $database)
|
||||||
|
{
|
||||||
|
parent::__construct($dispatcher, $config);
|
||||||
|
|
||||||
|
$this->setDatabase($database);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of CMS events this plugin will listen to and the respective handlers.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since __DEPLOY_VERSION__
|
||||||
|
*/
|
||||||
|
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 void
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $event->getArgument('result', []);
|
||||||
|
$result[] = [
|
||||||
|
[
|
||||||
|
'title' => Text::_('PLG_SYSTEM_WEBLINKS_STATISTICS'),
|
||||||
|
'icon' => 'out-2',
|
||||||
|
'data' => $webLinks,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$event->setArgument('result', $result);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,88 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @package Joomla.Administrator
|
|
||||||
* @subpackage Weblinks
|
|
||||||
*
|
|
||||||
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
|
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
defined('_JEXEC') or die;
|
|
||||||
|
|
||||||
use Joomla\CMS\Component\ComponentHelper;
|
|
||||||
use Joomla\CMS\Language\Text;
|
|
||||||
use Joomla\CMS\Plugin\CMSPlugin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* System plugin for Joomla Web Links.
|
|
||||||
*
|
|
||||||
* @since __DEPLOY_VERSION__
|
|
||||||
*/
|
|
||||||
class PlgSystemWeblinks extends CMSPlugin
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Database Driver Instance
|
|
||||||
*
|
|
||||||
* @var \Joomla\Database\DatabaseDriver
|
|
||||||
* @since 4.0.0
|
|
||||||
*/
|
|
||||||
protected $db;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the language file on instantiation.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
* @since __DEPLOY_VERSION__
|
|
||||||
*/
|
|
||||||
protected $autoloadLanguage = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supported Extensions
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @since __DEPLOY_VERSION__
|
|
||||||
*/
|
|
||||||
private $supportedExtensions = array(
|
|
||||||
'mod_stats',
|
|
||||||
'mod_stats_admin',
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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($extension)
|
|
||||||
{
|
|
||||||
if (!in_array($extension, $this->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
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,6 +9,7 @@
|
||||||
<authorUrl>www.joomla.org</authorUrl>
|
<authorUrl>www.joomla.org</authorUrl>
|
||||||
<version>##VERSION##</version>
|
<version>##VERSION##</version>
|
||||||
<description>PLG_SYSTEM_WEBLINKS_XML_DESCRIPTION</description>
|
<description>PLG_SYSTEM_WEBLINKS_XML_DESCRIPTION</description>
|
||||||
|
<namespace path="src">Joomla\Plugin\System\Weblinks</namespace>
|
||||||
<files>
|
<files>
|
||||||
##FILES##
|
##FILES##
|
||||||
</files>
|
</files>
|
||||||
|
|
Loading…
Reference in New Issue