From 09bcc32e22b5265995f46d3d6c00a3f1e95a9194 Mon Sep 17 00:00:00 2001 From: trabisdementia Date: Wed, 1 Mar 2017 23:44:52 +0000 Subject: [PATCH 1/2] Plugins module initial commit. --- htdocs/modules/plugins/admin/about.php | 29 +++ htdocs/modules/plugins/admin/header.php | 23 ++ htdocs/modules/plugins/admin/index.php | 34 +++ htdocs/modules/plugins/admin/menu.php | 35 +++ htdocs/modules/plugins/admin/plugins.php | 151 +++++++++++ htdocs/modules/plugins/class/helper.php | 51 ++++ htdocs/modules/plugins/class/index.html | 1 + htdocs/modules/plugins/class/manager.php | 89 +++++++ htdocs/modules/plugins/class/plugin.php | 242 ++++++++++++++++++ htdocs/modules/plugins/images/index.html | 1 + htdocs/modules/plugins/images/logo.png | Bin 0 -> 4451 bytes htdocs/modules/plugins/locale/en_US/en_US.php | 43 ++++ .../plugins/locale/en_US/help/help.html | 18 ++ .../plugins/locale/en_US/help/index.html | 1 + .../modules/plugins/locale/en_US/index.html | 1 + .../modules/plugins/locale/en_US/locale.php | 25 ++ htdocs/modules/plugins/locale/index.html | 1 + htdocs/modules/plugins/preloads/index.html | 1 + htdocs/modules/plugins/preloads/preload.php | 56 ++++ htdocs/modules/plugins/sql/index.html | 1 + htdocs/modules/plugins/sql/mysql.sql | 15 ++ htdocs/modules/plugins/sql/schema.yml | 92 +++++++ .../plugins/templates/admin/index.html | 1 + .../templates/admin/plugins_admin_plugins.tpl | 36 +++ htdocs/modules/plugins/templates/index.html | 1 + htdocs/modules/plugins/xoops_version.php | 70 +++++ htdocs/xoops_lib/Xoops/Module/Plugin.php | 3 + 27 files changed, 1021 insertions(+) create mode 100644 htdocs/modules/plugins/admin/about.php create mode 100644 htdocs/modules/plugins/admin/header.php create mode 100644 htdocs/modules/plugins/admin/index.php create mode 100644 htdocs/modules/plugins/admin/menu.php create mode 100644 htdocs/modules/plugins/admin/plugins.php create mode 100644 htdocs/modules/plugins/class/helper.php create mode 100644 htdocs/modules/plugins/class/index.html create mode 100644 htdocs/modules/plugins/class/manager.php create mode 100644 htdocs/modules/plugins/class/plugin.php create mode 100644 htdocs/modules/plugins/images/index.html create mode 100644 htdocs/modules/plugins/images/logo.png create mode 100644 htdocs/modules/plugins/locale/en_US/en_US.php create mode 100644 htdocs/modules/plugins/locale/en_US/help/help.html create mode 100644 htdocs/modules/plugins/locale/en_US/help/index.html create mode 100644 htdocs/modules/plugins/locale/en_US/index.html create mode 100644 htdocs/modules/plugins/locale/en_US/locale.php create mode 100644 htdocs/modules/plugins/locale/index.html create mode 100644 htdocs/modules/plugins/preloads/index.html create mode 100644 htdocs/modules/plugins/preloads/preload.php create mode 100644 htdocs/modules/plugins/sql/index.html create mode 100644 htdocs/modules/plugins/sql/mysql.sql create mode 100644 htdocs/modules/plugins/sql/schema.yml create mode 100644 htdocs/modules/plugins/templates/admin/index.html create mode 100644 htdocs/modules/plugins/templates/admin/plugins_admin_plugins.tpl create mode 100644 htdocs/modules/plugins/templates/index.html create mode 100644 htdocs/modules/plugins/xoops_version.php diff --git a/htdocs/modules/plugins/admin/about.php b/htdocs/modules/plugins/admin/about.php new file mode 100644 index 00000000..d52e57ef --- /dev/null +++ b/htdocs/modules/plugins/admin/about.php @@ -0,0 +1,29 @@ + + * @version $Id$ + */ + +include __DIR__ . '/header.php'; +$xoops = Xoops::getInstance(); +$xoops->header(); +$aboutAdmin = new \Xoops\Module\Admin(); +$aboutAdmin->displayNavigation('about.php'); +$aboutAdmin->displayAbout(true); +$xoops->footer(); diff --git a/htdocs/modules/plugins/admin/header.php b/htdocs/modules/plugins/admin/header.php new file mode 100644 index 00000000..0cac07cb --- /dev/null +++ b/htdocs/modules/plugins/admin/header.php @@ -0,0 +1,23 @@ + + * @version $Id$ + */ + +require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; diff --git a/htdocs/modules/plugins/admin/index.php b/htdocs/modules/plugins/admin/index.php new file mode 100644 index 00000000..6737ed2c --- /dev/null +++ b/htdocs/modules/plugins/admin/index.php @@ -0,0 +1,34 @@ + + * @version $Id$ + */ + +include __DIR__ . '/header.php'; +$xoops = Xoops::getInstance(); + +// header +$xoops->header(); + +$admin_page = new \Xoops\Module\Admin(); +$admin_page->displayNavigation('index.php'); +$admin_page->displayIndex(); + +// footer +$xoops->footer(); diff --git a/htdocs/modules/plugins/admin/menu.php b/htdocs/modules/plugins/admin/menu.php new file mode 100644 index 00000000..896fd86a --- /dev/null +++ b/htdocs/modules/plugins/admin/menu.php @@ -0,0 +1,35 @@ + + * @version $Id$ + */ + +$adminmenu = array(); +$i = 1; +$adminmenu[$i]['title'] = XoopsLocale::HOME; +$adminmenu[$i]['link'] = "admin/index.php"; +$adminmenu[$i]['icon'] = 'home.png'; +++$i; +$adminmenu[$i]['title'] = PluginsLocale::PLUGINS_MANAGER; +$adminmenu[$i]['link'] = "admin/plugins.php"; +$adminmenu[$i]['icon'] = 'synchronized.png'; +++$i; +$adminmenu[$i]['title'] = XoopsLocale::ABOUT; +$adminmenu[$i]['link'] = 'admin/about.php'; +$adminmenu[$i]['icon'] = 'about.png'; diff --git a/htdocs/modules/plugins/admin/plugins.php b/htdocs/modules/plugins/admin/plugins.php new file mode 100644 index 00000000..e2274739 --- /dev/null +++ b/htdocs/modules/plugins/admin/plugins.php @@ -0,0 +1,151 @@ +getHandlerPlugin(); + +//Adds new plugins if available and remove them if modules were deactivated +PluginsManager::updatePlugins(); + +// Call header +$xoops->header('admin:plugins/plugins_admin_plugins.tpl'); +// Get Action type +$op = Request::getCmd('op', 'list'); +// Get start pager +$start = Request::getInt('start', 0); +// Listener +$listener = Request::getCmd('listener'); +// Caller +$caller = Request::getCmd('caller'); + +$admin_page = new \Xoops\Module\Admin(); +$admin_page->renderNavigation('plugins.php'); + +switch ($op) { + case 'update': + $orders = Request::getArray('order'); + foreach ($orders as $id => $order) { + $handler->updateOrder((int) $id, (int) $order); + } + $statuses = Request::getArray('status'); + foreach ($statuses as $id => $status) { + $handler->updateStatus((int) $id, (int) $status); + } + $xoops->tpl()->assign('infoMsg', $xoops->alert('success', XoopsLocale::S_DATA_UPDATED)); + //No break; + case 'list': + default: + $admin_page->addTips(t::TIPS_PLUGINS); + $admin_page->renderTips(); + + if ($listener) { + $objects = $handler->getByListener($listener); + } else if ($caller) { + $objects = $handler->getByCaller($caller); + } else { + $objects = $handler->getThemAll(); + } + + //In the impossible case no plugins were found, we alert the user + if (!$objects) { + $xoops->tpl()->assign('errorMsg', $xoops->alert('info', t::NO_PLUGINS_FOUND)); + break; + } + + $plugins = array(); + foreach ($objects as $object) { + /* @var $object XoopsObject */ + $plugin = $object->toArray(); + $plugin['plugin_caller_name'] = $xoops->getModuleByDirname($plugin['plugin_caller'])->getVar('name'); + $plugin['plugin_listener_name'] = $xoops->getModuleByDirname($plugin['plugin_listener'])->getVar('name'); + + //Add order field + $order = new \Xoops\Form\Text('', 'order[' . $plugin['plugin_id'] . ']', 2, 2, $plugin['plugin_order']); + $order->set('style', 'width:3em'); + $plugin['plugin_order_field'] = $order->render(); + //Add status field + $status = new \Xoops\Form\RadioYesNo('', 'status[' . $plugin['plugin_id'] . ']', $plugin['plugin_status'], false); + $plugin['plugin_status_field'] = $status->render(); + $plugins[] = $plugin; + } + $xoops->tpl()->assign('pluginsCount', count($plugins)); + $xoops->tpl()->assign('plugins', $plugins); + + //Listeners form + $objects = $handler->getListeners(); + $form = new \Xoops\Form\ThemeForm('', 'listenersForm', 'plugins.php', 'post'); + $form->addElement(new \Xoops\Form\Hidden('op', 'list')); + $select = new \Xoops\Form\Select('', 'listener', $listener); + $select->set("onchange", 'submit()'); + $select->addOption('', XoopsLocale::ALL_TYPES); + foreach ($objects as $l => $name) { + $select->addOption($l, $name); + } + $form->addElement($select); + $xoops->tpl()->assign('listenersForm', $form->render()); + + //Callers form + $objects = $handler->getCallers(); + $form = new \Xoops\Form\ThemeForm('', 'callersForm', 'plugins.php', 'post'); + $form->addElement(new \Xoops\Form\Hidden('op', 'list')); + $select = new \Xoops\Form\Select('', 'caller', $caller); + $select->set("onchange", 'submit()'); + $select->addOption('', XoopsLocale::ALL_TYPES); + foreach ($objects as $c => $name) { + $select->addOption($c, $name); + } + $form->addElement($select); + $xoops->tpl()->assign('callersForm', $form->render()); + + //Submit button + $submitButton = new \Xoops\Form\Button(XoopsLocale::A_SUBMIT, 'submit', XoopsLocale::A_SUBMIT, 'submit'); + $xoops->tpl()->assign('submitButton', $submitButton->render()); + + //Hidden fields + $hiddenFields = ''; + $hidden = new \Xoops\Form\Hidden('op', 'update'); + $hiddenFields .= $hidden->render(); + $hidden = new \Xoops\Form\Hidden('listener', $listener); + $hiddenFields .= $hidden->render(); + $hidden = new \Xoops\Form\Hidden('caller', $caller); + $hiddenFields .= $hidden->render(); + $xoops->tpl()->assign('hiddenFields', $hiddenFields); + break; + case 'status': + // Get the plugin id + $id = Request::getInt('id', 0); + // Get new status + $status = Request::getInt('status', 0); + if ($object = $handler->get($id)) { + $object->setVar('plugin_status', $status); + return $handler->insert($object); + } + return false; + break; +} +$xoops->footer(); \ No newline at end of file diff --git a/htdocs/modules/plugins/class/helper.php b/htdocs/modules/plugins/class/helper.php new file mode 100644 index 00000000..f114acbb --- /dev/null +++ b/htdocs/modules/plugins/class/helper.php @@ -0,0 +1,51 @@ + + * @version $Id$ + */ + +class Plugins extends Xoops\Module\Helper\HelperAbstract +{ + /** + * Init the module + * + * @return null|void + */ + public function init() + { + $this->setDirname('plugins'); + } + + /** + * @return Plugins|\Xoops\Module\Helper\HelperAbstract + */ + public static function getInstance() + { + return parent::getInstance(); + } + + /** + * @return PluginsPluginHandler + */ + public function getHandlerPlugin() + { + return $this->getHandler('plugin'); + } + +} diff --git a/htdocs/modules/plugins/class/index.html b/htdocs/modules/plugins/class/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/class/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/class/manager.php b/htdocs/modules/plugins/class/manager.php new file mode 100644 index 00000000..fb97018f --- /dev/null +++ b/htdocs/modules/plugins/class/manager.php @@ -0,0 +1,89 @@ + + */ +class PluginsManager +{ + + /** + * @return array returns an array of listeners in the form of listener=>caller + */ + public static function getListeners() + { + $xoops = \Xoops::getInstance(); + $dirNames = $xoops->getActiveModules(); + $listeners = array(); + + foreach ($dirNames as $listener) { + foreach ($dirNames as $caller) { + //Make sure to load the interface + if (\XoopsLoad::loadFile($xoops->path("modules/{$caller}/class/plugin/interface.php"))) { + if (\XoopsLoad::loadFile($xoops->path("modules/{$listener}/class/plugin/{$caller}.php"))) { + $interfaceName = '\\' . ucfirst($caller) . "PluginInterface"; + if ($ref = new ReflectionClass($interfaceName)) { + if ($ref->implementsInterface($interfaceName)) { + $listeners[$listener][] = $caller; + } + } + } + } + } + + } + return $listeners; + } + + /** + * Checks if new plugins are available and adds them to database + * + * @return bool + */ + public static function updatePlugins() + { + $ret = true; + $handler = Plugins::getInstance()->getHandlerPlugin(); + $xoops = \Xoops::getInstance(); + + $listeners = $handler->getListeners(); + foreach ($listeners as $key => $name ) { + if (!$xoops->isActiveModule($key)) { + $handler->deleteLC($key); + } + } + $callers = $handler->getCallers(); + foreach ($callers as $key => $name) { + if (!$xoops->isActiveModule($key)) { + $handler->deleteLC($key); + } + } + + //Gets Listeners from file + $plugins = self::getListeners(); + foreach ($plugins as $listener => $callers) { + foreach ($callers as $caller) { + if (!$object = $handler->getLC($listener, $caller)) { + if (!$handler->addNew($listener, $caller)) { + $ret = false; + }; + } + } + } + + + + return $ret; + } +} diff --git a/htdocs/modules/plugins/class/plugin.php b/htdocs/modules/plugins/class/plugin.php new file mode 100644 index 00000000..ce6b8d24 --- /dev/null +++ b/htdocs/modules/plugins/class/plugin.php @@ -0,0 +1,242 @@ + + * @version $Id$ + */ + +use Xoops\Core\Database\Connection; +use Xoops\Core\Kernel\XoopsObject; +use Xoops\Core\Kernel\XoopsPersistableObjectHandler; +use Xoops\Core\Kernel\Dtype; +use Xoops\Core\Kernel\Criteria; +use Xoops\Core\Kernel\CriteriaCompo; + +class PluginsPlugin extends XoopsObject +{ + /** + * Constructor + */ + public function __construct() + { + $this->initVar('plugin_id', Dtype::TYPE_INTEGER, null, false); + $this->initVar('plugin_caller', Dtype::TYPE_TEXT_BOX, null, false); + $this->initVar('plugin_listener', Dtype::TYPE_TEXT_BOX, null, false); + $this->initVar('plugin_status', Dtype::TYPE_INTEGER, null, 1); + $this->initVar('plugin_order', Dtype::TYPE_INTEGER, null, false, 0); + } +} + +class PluginsPluginHandler extends XoopsPersistableObjectHandler +{ + /** + * @param null|Connection $db database + */ + public function __construct(Connection $db = null) + { + parent::__construct($db, 'plugins_plugin', 'PluginsPlugin', 'plugin_id', 'plugin_caller'); + } + + /** + * @param string $listener + * @param string $caller + * @return bool|PluginsPlugin + */ + public function getLC($listener, $caller) + { + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('plugin_listener', $listener)); + $criteria->add(new Criteria('plugin_caller', $caller)); + + //Expecting only one result; + if ($objects = $this->getObjects($criteria)) { + return $objects[0]; + } else { + return false; + } + } + + /** + * @param string $listener + * @return array Array of PluginsPlugin + */ + public function getByListener($listener) + { + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('plugin_listener', (string)$listener)); + $criteria->setSort('plugin_status DESC, plugin_order'); + $criteria->setOrder('ASC'); + return $this->getObjects($criteria); + } + + /** + * @param string $caller + * @return array Array of PluginsPlugin + */ + public function getByCaller($caller) + { + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('plugin_caller', (string)$caller)); + $criteria->setSort('plugin_status DESC, plugin_order'); + $criteria->setOrder('ASC'); + return $this->getObjects($criteria); + } + + + /** + * @return array Array of PluginsPlugin + */ + public function getThemAll() + { + $criteria = new CriteriaCompo(); + $criteria->setSort('plugin_status DESC, plugin_order'); + $criteria->setOrder('ASC'); + return $this->getObjects($criteria); + } + + /** + * @return array Array of Listeners + */ + public function getListeners() + { + $ret = array(); + $qb = $this->db2->createXoopsQueryBuilder(); + $qb->select('plugin_listener') + ->fromPrefix('plugins_plugin', '') + ->groupBy('plugin_listener'); + $result = $qb->execute(); + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { + $ret[$row['plugin_listener']] = $this->getModuleName($row['plugin_listener']); + } + return $ret; + } + + /** + * @return array Array of Callers + */ + public function getCallers() + { + $ret = array(); + $qb = $this->db2->createXoopsQueryBuilder(); + $qb->select('plugin_caller') + ->fromPrefix('plugins_plugin', '') + ->groupBy('plugin_caller'); + $result = $qb->execute(); + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { + $ret[$row['plugin_caller']] = $this->getModuleName($row['plugin_caller']); + } + return $ret; + } + + /** + * Gets the module name but checks if it is active or not + * There is a preload that calls this method before deleting deactivated module entries + * + * @param string $dirname + * @return mixed + */ + public function getModuleName(string $dirname) + { + if ($module = \Xoops::getInstance()->getModuleByDirname((string)$dirname)) { + return $module->getVar('name'); + } else { + return $dirname; + } + } + + /** + * @param string $listener + * @param string $caller + * @param int $status + * @param int $order + * @return bool + */ + public function addNew($listener, $caller, $status = 1, $order = 0) + { + $object = new PluginsPlugin(); + $object->setNew(); + $object->setVar('plugin_listener', $listener); + $object->setVar('plugin_caller', $caller); + $object->setVar('plugin_status', $status); + $object->setVar('plugin_order', $order); + return $this->insert($object, true); + } + + /** + * Updates the order value after a post request + * + * @param int $id + * @param int $order + */ + public function updateOrder(int $id, int $order) + { + $this->updateAll('plugin_order', $order, new Criteria('plugin_id', $id)); + } + + /** + * Updates the status value after a post request + * + * @param int $id + * @param int $status + */ + public function updateStatus(int $id, int $status) + { + $this->updateAll('plugin_status', $status, new Criteria('plugin_id', $id)); + } + + /** + * Get Listeners By Caller + * Check if the module is active in case it was deactivated + * + * @param string $caller + * @return array + */ + public function getActiveListenersByCaller(string $caller) + { + $xoops = \Xoops::getInstance(); + $ret = array(); + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('plugin_caller', (string)$caller)); + $criteria->add(new Criteria('plugin_status', 1)); + $criteria->setSort('plugin_order'); + $criteria->setOrder('ASC'); + $plugins = $this->getAll($criteria, 'plugin_listener', false, false); + foreach ($plugins as $plugin) { + if ($xoops->isActiveModule($plugin['plugin_listener'])) { + $ret[$plugin['plugin_listener']] = $plugin['plugin_listener']; + } + } + return $ret; + + } + + /** + * Deletes all entries by name + * Useful when a module is deleted + * + * @param string $name + * @return bool + */ + public function deleteLC(string $name) + { + $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('plugin_caller', (string)$name)); + $criteria->add(new Criteria('plugin_listener', (string)$name), 'OR'); + return $this->deleteAll($criteria, true); + } +} diff --git a/htdocs/modules/plugins/images/index.html b/htdocs/modules/plugins/images/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/images/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/images/logo.png b/htdocs/modules/plugins/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..b02073e2720d3df04099b7ea3a169ae4b1d58a61 GIT binary patch literal 4451 zcmd^Dc{G&!{~r=j+9XOCYbMJq7-O1I%veVDL2_+_!DP%ZGZ@R1B}-%}B9*2H*|S}t z>}AOog)F68MAn4tzT+=TxOfs7Kxd*miGr4%uc?y;l3dZ!7uAg+ z#@-mB2gx9iM#Kl2Sh@syx@fvepVI=Om`DzR7m+~#GQG$YI+BT&{*xEUS??Z$rGbBn zFg(%H|2E3T*bIoF(uhEH6;)*y2ows0!&RVa>Tozz2?&EgVPFX7f-6JSkm_(GOau7W zkmhKkxw;`OuzG*#;_T4U9t?&z5)AhD_gC>(RiV<{!B9<2&0P){OqnC0Ob?(i2ux)P zUFH`9mPmJ@k-QlsDh0U9NN}e5GSJc-OaJYHm$wDU-Gf2@o18-bD_EScftdtvFjNHs zru`|i>)$VwvGM;#czOLTO=nmT|6}}r<)>Q)coV@EL^{=%=EBLMo6J8{{clCPf`9pd zG$znIiJUCz5y*7npD&D!k)|BuNfZJZOLg(}B2pMQELz&vm*k2>sA{Wes6#a&SPeBS z77EqTgQ{Vma7|rKQ1uY%y1xki3FP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osKOl0FbriP6>d*#&C&B?g9y^syk zXB?Ny!siwhU`Sg>W}I06yJf!MrS&wU7N4Qj)m8dLS%O5_N1xzLFc&WXL*-cxQ3 literal 0 HcmV?d00001 diff --git a/htdocs/modules/plugins/locale/en_US/en_US.php b/htdocs/modules/plugins/locale/en_US/en_US.php new file mode 100644 index 00000000..d090bf44 --- /dev/null +++ b/htdocs/modules/plugins/locale/en_US/en_US.php @@ -0,0 +1,43 @@ + + * @version $Id$ + */ +class PluginsLocaleEn_US extends XoopsLocaleEn_US +{ + // Module + const MODULE_NAME = "Plugins"; + const MODULE_DESC = "Module for managing plugins"; + const DONATION_DESC = "Donation for module Plugins"; + + // Admin menu + const PLUGINS_MANAGER = "Plugins Manager"; + + //Admin + const TIPS_PLUGINS = "Activate or deactivate plugins and choose the desired execution order."; + const NO_PLUGINS_FOUND = "No plugins were found!"; + + //Objects + const OBJECT_PLUGIN_ID = "ID"; + const OBJECT_PLUGIN_CALLER = "Caller"; + const OBJECT_PLUGIN_LISTENER = "Listener"; + const OBJECT_PLUGIN_STATUS = "Enabled"; + const OBJECT_PLUGIN_ORDER = "Order"; + +} diff --git a/htdocs/modules/plugins/locale/en_US/help/help.html b/htdocs/modules/plugins/locale/en_US/help/help.html new file mode 100644 index 00000000..b1b65df0 --- /dev/null +++ b/htdocs/modules/plugins/locale/en_US/help/help.html @@ -0,0 +1,18 @@ +

Description

+

+ Plugins are module components that extend functionality of other modules. + For example, a Search module might use a News plugin to search for news. + A News module might use a Tags plugin for tags, or a Comments plugin for comments. +

+
+

Callers and Listeners

+

+ In the above example, the search module is a caller and the news module is a listener. + The News module is also a caller having the Tag module as a listener. +

+
+

Activation and Ordering

+

+ The Plugins module allows you to deactivate this relationships between callers and listeners and to choose the order you want the listeners to respond. + Relationships with lower values will execute first. By default, this value is set to 0. If you want some relationship to happen last, just give it the higher value. +

\ No newline at end of file diff --git a/htdocs/modules/plugins/locale/en_US/help/index.html b/htdocs/modules/plugins/locale/en_US/help/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/locale/en_US/help/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/locale/en_US/index.html b/htdocs/modules/plugins/locale/en_US/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/locale/en_US/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/locale/en_US/locale.php b/htdocs/modules/plugins/locale/en_US/locale.php new file mode 100644 index 00000000..403f14e4 --- /dev/null +++ b/htdocs/modules/plugins/locale/en_US/locale.php @@ -0,0 +1,25 @@ + + * @version $Id$ + */ + +class PluginsLocale extends PluginsLocaleEn_US +{ +} diff --git a/htdocs/modules/plugins/locale/index.html b/htdocs/modules/plugins/locale/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/locale/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/preloads/index.html b/htdocs/modules/plugins/preloads/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/preloads/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/preloads/preload.php b/htdocs/modules/plugins/preloads/preload.php new file mode 100644 index 00000000..996e813a --- /dev/null +++ b/htdocs/modules/plugins/preloads/preload.php @@ -0,0 +1,56 @@ + + * @version $Id$ + */ +class PluginsPreload extends PreloadItem +{ + /** + * listen for core.include.common.classmaps + * add any module specific class map entries + * + * @param mixed $args not used + * + * @return void + */ + public static function eventCoreIncludeCommonClassmaps($args) + { + $path = dirname(__DIR__); + XoopsLoad::addMap(array( + 'plugins' => $path . '/class/helper.php', + 'pluginsmanager' => $path . '/class/manager.php', + )); + } + + /** + * Filters an orders plugin listeners + * + * @param array $args + */ + public static function eventCoreModulePluginGetPlugins($args) + { + //Don't run during uninstall + if (\Xoops::getInstance()->isActiveModule('plugins')) { + $args[0] = Plugins::getInstance()->getHandlerPlugin()->getActiveListenersByCaller($args[1]); + } + } + +} diff --git a/htdocs/modules/plugins/sql/index.html b/htdocs/modules/plugins/sql/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/sql/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/sql/mysql.sql b/htdocs/modules/plugins/sql/mysql.sql new file mode 100644 index 00000000..7e5c3f82 --- /dev/null +++ b/htdocs/modules/plugins/sql/mysql.sql @@ -0,0 +1,15 @@ +# +# Table structure for table `plugins_plugin` +# + +CREATE TABLE plugins_plugin ( + plugin_id smallint(5) unsigned NOT NULL auto_increment, + plugin_caller varchar(255) NOT NULL default '', + plugin_listener varchar(255) NOT NULL default '', + plugin_status tinyint(1) NOT NULL default '1', + plugin_order smallint(1) NOT NULL default '0', + PRIMARY KEY (plugin_id), + KEY idxcaller (plugin_caller), + KEY idxlistener (plugin_listener), + KEY idxevent (plugin_status) +) ENGINE=MyISAM; diff --git a/htdocs/modules/plugins/sql/schema.yml b/htdocs/modules/plugins/sql/schema.yml new file mode 100644 index 00000000..1ec05454 --- /dev/null +++ b/htdocs/modules/plugins/sql/schema.yml @@ -0,0 +1,92 @@ +tables: + plugins_plugin: + options: + charset: utf8mb4 + collate: utf8mb4_unicode_ci + columns: + plugin_id: + name: plugin_id + type: smallint + default: null + notnull: true + length: null + precision: 10 + scale: 0 + fixed: false + unsigned: true + autoincrement: true + columnDefinition: null + comment: '' + plugin_caller: + name: plugin_caller + type: string + default: '' + notnull: true + length: 255 + precision: 10 + scale: 0 + fixed: false + unsigned: false + autoincrement: false + columnDefinition: null + comment: '' + plugin_listener: + name: plugin_listener + type: string + default: '' + notnull: true + length: 255 + precision: 10 + scale: 0 + fixed: false + unsigned: false + autoincrement: false + columnDefinition: null + comment: '' + plugin_status: + name: plugin_status + type: boolean + default: '1' + notnull: true + length: null + precision: 10 + scale: 0 + fixed: false + unsigned: false + autoincrement: false + columnDefinition: null + comment: '' + plugin_order: + name: plugin_order + type: smallint + default: '0' + notnull: true + length: null + precision: 10 + scale: 0 + fixed: false + unsigned: false + autoincrement: false + columnDefinition: null + comment: '' + indexes: + PRIMARY: + name: PRIMARY + columns: [plugin_id] + unique: true + primary: true + idxcaller: + name: idxcaller + columns: [plugin_caller] + unique: false + primary: false + idxlistener: + name: idxlistener + columns: [plugin_listener] + unique: false + primary: false + idxstatus: + name: idxstatus + columns: [plugin_status] + unique: false + primary: false diff --git a/htdocs/modules/plugins/templates/admin/index.html b/htdocs/modules/plugins/templates/admin/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/templates/admin/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/templates/admin/plugins_admin_plugins.tpl b/htdocs/modules/plugins/templates/admin/plugins_admin_plugins.tpl new file mode 100644 index 00000000..801e3d79 --- /dev/null +++ b/htdocs/modules/plugins/templates/admin/plugins_admin_plugins.tpl @@ -0,0 +1,36 @@ +<{include file="admin:system/admin_navigation.tpl"}> +<{include file="admin:system/admin_tips.tpl"}> +<{include file="admin:system/admin_buttons.tpl"}> + +<{$infoMsg|default:''}> +<{$errorMsg|default:''}> + +<{if $pluginsCount|default:false}> +

<{translate key="PLUGINS_MANAGER" dirname='plugins'}>

+ + + + + + + + + +
<{translate key="OBJECT_PLUGIN_CALLER" dirname='plugins'}><{$callersForm}><{translate key="OBJECT_PLUGIN_LISTENER" dirname='plugins'}><{$listenersForm}><{translate key="OBJECT_PLUGIN_STATUS" dirname='plugins'}><{translate key="OBJECT_PLUGIN_ORDER" dirname='plugins'}>
+
+ + + <{foreach item=$plugin from=$plugins}> + + + + + + + <{/foreach}> + +
<{$plugin.plugin_caller_name}><{$plugin.plugin_listener_name}><{$plugin.plugin_status_field}><{$plugin.plugin_order_field}>
+ <{$hiddenFields}> + <{$submitButton}> +
+<{/if}> diff --git a/htdocs/modules/plugins/templates/index.html b/htdocs/modules/plugins/templates/index.html new file mode 100644 index 00000000..990cbd60 --- /dev/null +++ b/htdocs/modules/plugins/templates/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/htdocs/modules/plugins/xoops_version.php b/htdocs/modules/plugins/xoops_version.php new file mode 100644 index 00000000..71e02f78 --- /dev/null +++ b/htdocs/modules/plugins/xoops_version.php @@ -0,0 +1,70 @@ + + * @version $Id$ + */ + +use PluginsLocale as t; + +$modversion = array(); +$modversion['name'] = t::MODULE_NAME; +$modversion['description'] = t::MODULE_DESC; +$modversion['version'] = 0.1; +$modversion['author'] = 'Ricardo Costa'; +$modversion['nickname'] = 'trabis'; +$modversion['credits'] = 'The XOOPS Project'; +$modversion['license'] = 'GNU GPL 2.0'; +$modversion['license_url'] = 'http://www.gnu.org/licenses/gpl-2.0.html'; +$modversion['official'] = 1; +$modversion['help'] = 'page=help'; +$modversion['image'] = 'images/logo.png'; +$modversion['dirname'] = basename(__DIR__); + +//about +$modversion['release_date'] = '2017/02/27'; +$modversion['module_website_url'] = 'http://www.xoops.org/'; +$modversion['module_website_name'] = 'XOOPS'; +$modversion['module_status'] = 'ALPHA'; +$modversion['min_php'] = '5.3.7'; +$modversion['min_xoops'] = '2.6.0'; + +// paypal +$modversion['paypal'] = array(); +$modversion['paypal']['business'] = 'xoopsfoundation@gmail.com'; +$modversion['paypal']['item_name'] = t::DONATION_DESC; +$modversion['paypal']['amount'] = 0; +$modversion['paypal']['currency_code'] = 'USD'; + +// Admin menu +// Set to 1 if you want to display menu generated by system module +$modversion['system_menu'] = 1; + +// Admin things +$modversion['hasAdmin'] = 1; +$modversion['adminindex'] = 'admin/index.php'; +$modversion['adminmenu'] = 'admin/menu.php'; + +// table definitions +$modversion['schema'] = 'sql/schema.yml'; +$modversion['sqlfile']['mysql'] = 'sql/mysql.sql'; + +// Tables created by sql file or schema (without prefix!) +$modversion['tables'] = array( + 'plugins_plugin', +); \ No newline at end of file diff --git a/htdocs/xoops_lib/Xoops/Module/Plugin.php b/htdocs/xoops_lib/Xoops/Module/Plugin.php index f43eea57..0e153bf5 100644 --- a/htdocs/xoops_lib/Xoops/Module/Plugin.php +++ b/htdocs/xoops_lib/Xoops/Module/Plugin.php @@ -64,6 +64,9 @@ public static function getPlugins($pluginName = 'system', $inactiveModules = fal } $dirnames = $xoops->getActiveModules(); + + \Xoops::getInstance()->events()->triggerEvent('core.module.plugin.get.plugins', array(&$dirnames, $pluginName)); + if (is_array($inactiveModules)) { $dirnames = array_merge($dirnames, $inactiveModules); } From c4ddeaddea924e70887400fd32a2c175ac445013 Mon Sep 17 00:00:00 2001 From: trabisdementia Date: Wed, 1 Mar 2017 23:57:24 +0000 Subject: [PATCH 2/2] Fix for: Module breaks during uninstall. --- htdocs/modules/plugins/preloads/preload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/modules/plugins/preloads/preload.php b/htdocs/modules/plugins/preloads/preload.php index 996e813a..cc493e9a 100644 --- a/htdocs/modules/plugins/preloads/preload.php +++ b/htdocs/modules/plugins/preloads/preload.php @@ -47,8 +47,8 @@ public static function eventCoreIncludeCommonClassmaps($args) */ public static function eventCoreModulePluginGetPlugins($args) { - //Don't run during uninstall - if (\Xoops::getInstance()->isActiveModule('plugins')) { + //Don't run during uninstall, getActiveModule('plugins') won't work. + if (\Xoops::getInstance()->getModuleByDirname('plugins')) { $args[0] = Plugins::getInstance()->getHandlerPlugin()->getActiveListenersByCaller($args[1]); } }