first commit
This commit is contained in:
21
plugins/extension/finder/finder.xml
Normal file
21
plugins/extension/finder/finder.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="extension" method="upgrade">
|
||||
<name>plg_extension_finder</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2018-06</creationDate>
|
||||
<copyright>(C) 2019 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_EXTENSION_FINDER_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Extension\Finder</namespace>
|
||||
<files>
|
||||
<folder plugin="finder">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_finder.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_finder.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
47
plugins/extension/finder/services/provider.php
Normal file
47
plugins/extension/finder/services/provider.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.finder
|
||||
*
|
||||
* @copyright (C) 2022 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\Extension\Finder\Extension\Finder;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$dispatcher = $container->get(DispatcherInterface::class);
|
||||
$plugin = new Finder(
|
||||
$dispatcher,
|
||||
(array) PluginHelper::getPlugin('extension', 'finder')
|
||||
);
|
||||
$plugin->setDatabase($container->get(DatabaseInterface::class));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
190
plugins/extension/finder/src/Extension/Finder.php
Normal file
190
plugins/extension/finder/src/Extension/Finder.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.Finder
|
||||
*
|
||||
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Extension\Finder\Extension;
|
||||
|
||||
use Joomla\CMS\Installer\Installer;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Component\Finder\Administrator\Indexer\Helper;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Finder extension plugin
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class Finder extends CMSPlugin
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
|
||||
/**
|
||||
* Add common words to finder after language got installed
|
||||
*
|
||||
* @param Installer $installer Installer object
|
||||
* @param integer $eid Extension Identifier
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterInstall($installer, $eid)
|
||||
{
|
||||
if (!$eid) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName(['element', 'client_id']))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('extension_id') . ' = :eid',
|
||||
$db->quoteName('type') . ' = ' . $db->quote('language'),
|
||||
]
|
||||
)
|
||||
->bind(':eid', $eid, ParameterType::INTEGER);
|
||||
|
||||
$extension = $db->setQuery($query)->loadObject();
|
||||
|
||||
if ($extension) {
|
||||
$this->addCommonWords($extension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add common words to finder after language got updated
|
||||
*
|
||||
* @param Installer $installer Installer object
|
||||
* @param integer $eid Extension identifier
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterUpdate($installer, $eid)
|
||||
{
|
||||
$this->onExtensionAfterInstall($installer, $eid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove common words to finder after language got uninstalled
|
||||
*
|
||||
* @param Installer $installer Installer instance
|
||||
* @param integer $eid Extension id
|
||||
* @param boolean $removed Installation result
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterUninstall($installer, $eid, $removed)
|
||||
{
|
||||
// Check that the language was successfully uninstalled.
|
||||
if ($eid && $removed && $installer->extension->type === 'language') {
|
||||
$this->removeCommonWords($installer->extension);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add common words from a txt file to com_finder
|
||||
*
|
||||
* @param object $extension Extension object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function addCommonWords($extension)
|
||||
{
|
||||
if ($extension->client_id == 0) {
|
||||
$path = JPATH_SITE . '/language/' . $extension->element . '/com_finder.commonwords.txt';
|
||||
} else {
|
||||
$path = JPATH_ADMINISTRATOR . '/language/' . $extension->element . '/com_finder.commonwords.txt';
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->removeCommonWords($extension);
|
||||
|
||||
$file_content = file_get_contents($path);
|
||||
$words = explode("\n", $file_content);
|
||||
$words = array_map(
|
||||
function ($word) {
|
||||
// Remove comments
|
||||
if (StringHelper::strpos($word, ';') !== false) {
|
||||
$word = StringHelper::substr($word, 0, StringHelper::strpos($word, ';'));
|
||||
}
|
||||
|
||||
return $word;
|
||||
},
|
||||
$words
|
||||
);
|
||||
|
||||
$words = array_filter(array_map('trim', $words));
|
||||
$words = array_unique($words);
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$lang = Helper::getPrimaryLanguage($extension->element);
|
||||
|
||||
$query->insert($db->quoteName('#__finder_terms_common'))
|
||||
->columns($db->quoteName(['term', 'language', 'custom']));
|
||||
|
||||
foreach ($words as $word) {
|
||||
$bindNames = $query->bindArray([$word, $lang], ParameterType::STRING);
|
||||
|
||||
$query->values(implode(',', $bindNames) . ', 0');
|
||||
}
|
||||
|
||||
try {
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
} catch (\Exception $ex) {
|
||||
// It would be nice if the common word is stored to the DB, but it isn't super important
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove common words of a language from com_finder
|
||||
*
|
||||
* @param object $extension Extension object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected function removeCommonWords($extension)
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$lang = Helper::getPrimaryLanguage($extension->element);
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
$query->delete($db->quoteName('#__finder_terms_common'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('language') . ' = :lang',
|
||||
$db->quoteName('custom') . ' = 0',
|
||||
]
|
||||
)
|
||||
->bind(':lang', $lang);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
}
|
||||
218
plugins/extension/jce/jce.php
Normal file
218
plugins/extension/jce/jce.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved
|
||||
* @copyright Copyright (C) 2018 Ryan Demmer. All rights reserved
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* JCE extension plugin.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
class PlgExtensionJce extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Check the installer is for a valid plugin group.
|
||||
*
|
||||
* @param JInstaller $installer Installer object
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
private function isValidPlugin($installer)
|
||||
{
|
||||
if (empty($installer->manifest)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (array('type', 'group') as $var) {
|
||||
$$var = (string) $installer->manifest->attributes()->{$var};
|
||||
}
|
||||
|
||||
return $type === 'plugin' && $group === 'jce';
|
||||
}
|
||||
|
||||
public function onExtensionBeforeInstall($method, $type, $manifest, $extension = 0)
|
||||
{
|
||||
if ((string) $type === "file") {
|
||||
|
||||
// get a reference to the current installer
|
||||
$manifestPath = JInstaller::getInstance()->getPath('manifest');
|
||||
|
||||
if (empty($manifestPath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// get the filename of the manifest file, eg: pkg_jce_de-DE
|
||||
$element = basename($manifestPath, '.xml');
|
||||
|
||||
// if this matches the current install...
|
||||
if (strpos($element, 'pkg_jce_') !== false) {
|
||||
// find an existing legacy language install, eg: jce-de-DE
|
||||
$element = str_replace('pkg_jce_', 'jce-', $element);
|
||||
|
||||
$table = JTable::getInstance('extension');
|
||||
$id = $table->find(array('type' => 'file', 'element' => $element));
|
||||
|
||||
if ($id) {
|
||||
$installer = new JInstaller();
|
||||
|
||||
// try unisntall, if this fails, delete database entry
|
||||
if (!$installer->uninstall('file', $id)) {
|
||||
$table->delete($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handle post extension install update sites.
|
||||
*
|
||||
* @param JInstaller $installer Installer object
|
||||
* @param int $eid Extension Identifier
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public function onExtensionAfterInstall($installer, $eid)
|
||||
{
|
||||
if ($eid) {
|
||||
if (!$this->isValidPlugin($installer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$basename = basename($installer->getPath('extension_root'));
|
||||
|
||||
if (strpos($basename, '-') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/plugins.php';
|
||||
|
||||
// enable plugin
|
||||
$plugin = JTable::getInstance('extension');
|
||||
$plugin->load($eid);
|
||||
$plugin->publish();
|
||||
|
||||
$parts = explode('-', $basename);
|
||||
$type = $parts[0];
|
||||
$name = $parts[1];
|
||||
|
||||
$plugin = new StdClass();
|
||||
$plugin->name = $name;
|
||||
|
||||
if ($type === 'editor') {
|
||||
$plugin->icon = (string) $installer->manifest->icon;
|
||||
$plugin->row = (int) (string) $installer->manifest->attributes()->row;
|
||||
$plugin->type = 'plugin';
|
||||
} else {
|
||||
$plugin->type = 'extension';
|
||||
}
|
||||
|
||||
$plugin->path = $installer->getPath('extension_root');
|
||||
|
||||
JcePluginsHelper::postInstall('install', $plugin, $installer);
|
||||
|
||||
// clean up legacy extensions
|
||||
if ($plugin->type == 'extension') {
|
||||
jimport('joomla.filesystem.folder');
|
||||
jimport('joomla.filesystem.file');
|
||||
|
||||
$path = JPATH_SITE . '/components/com_jce/editor/extensions/' . $type;
|
||||
|
||||
// delete manifest
|
||||
if (is_file($path . '/' . $plugin->name . '.xml')) {
|
||||
JFile::delete($path . '/' . $plugin->name . '.xml');
|
||||
}
|
||||
// delete file
|
||||
if (is_file($path . '/' . $plugin->name . '.php')) {
|
||||
JFile::delete($path . '/' . $plugin->name . '.php');
|
||||
}
|
||||
// delete folder
|
||||
if (is_dir($path . '/' . $plugin->name)) {
|
||||
JFolder::delete($path . '/' . $plugin->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle extension uninstall.
|
||||
*
|
||||
* @param JInstaller $installer Installer instance
|
||||
* @param int $eid Extension id
|
||||
* @param int $result Installation result
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onExtensionAfterUninstall($installer, $eid, $result)
|
||||
{
|
||||
if ($eid) {
|
||||
if (!$this->isValidPlugin($installer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$basename = basename($installer->getPath('extension_root'));
|
||||
|
||||
if (strpos($basename, '-') === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
require_once JPATH_ADMINISTRATOR . '/components/com_jce/helpers/plugins.php';
|
||||
|
||||
$parts = explode('-', $basename);
|
||||
$type = $parts[0];
|
||||
$name = $parts[1];
|
||||
|
||||
$plugin = new StdClass();
|
||||
$plugin->name = $name;
|
||||
|
||||
if ($type === 'editor') {
|
||||
$plugin->icon = (string) $installer->manifest->icon;
|
||||
$plugin->row = (int) (string) $installer->manifest->attributes()->row;
|
||||
$plugin->type = 'plugin';
|
||||
}
|
||||
|
||||
$plugin->path = $installer->getPath('extension_root');
|
||||
|
||||
JcePluginsHelper::postInstall('uninstall', $plugin, $installer);
|
||||
}
|
||||
}
|
||||
|
||||
public function onExtensionAfterSave($context, $table, $result)
|
||||
{
|
||||
if ($context !== 'com_config.component') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($table->element !== 'com_jce') {
|
||||
return;
|
||||
}
|
||||
|
||||
$params = json_decode($table->params, true);
|
||||
|
||||
if ($params && !empty($params['updates_key'])) {
|
||||
$updatesite = JTable::getInstance('Updatesite');
|
||||
|
||||
// sanitize key
|
||||
$key = preg_replace("/[^a-zA-Z0-9]/", "", $params['updates_key']);
|
||||
|
||||
$db = JFactory::getDBO();
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->qn('update_site_id'))->from('#__update_sites_extensions')->where($db->qn('extension_id') . '=' . (int) $table->package_id);
|
||||
$db->setQuery($query);
|
||||
$update_site_id = $db->loadResult();
|
||||
|
||||
if ($update_site_id) {
|
||||
if ($updatesite->load($update_site_id)) {
|
||||
$updatesite->bind(array('extra_query' => 'key=' . $key));
|
||||
$updatesite->check();
|
||||
$updatesite->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
plugins/extension/jce/jce.xml
Normal file
19
plugins/extension/jce/jce.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.8" type="plugin" group="extension" method="upgrade">
|
||||
<name>plg_extension_jce</name>
|
||||
<version>2.9.32</version>
|
||||
<creationDate>01-11-2022</creationDate>
|
||||
<author>Ryan Demmer</author>
|
||||
<authorEmail>info@joomlacontenteditor.net</authorEmail>
|
||||
<authorUrl>http://www.joomlacontenteditor.net</authorUrl>
|
||||
<copyright>Copyright (C) 2006 - 2022 Ryan Demmer. All rights reserved</copyright>
|
||||
<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
|
||||
<description>PLG_EXTENSION_JCE_XML_DESCRIPTION</description>
|
||||
<files folder="plugins/extension/jce">
|
||||
<filename plugin="jce">jce.php</filename>
|
||||
</files>
|
||||
<languages folder="administrator/language/en-GB">
|
||||
<language tag="en-GB">en-GB.plg_extension_jce.ini</language>
|
||||
<language tag="en-GB">en-GB.plg_extension_jce.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
21
plugins/extension/joomla/joomla.xml
Normal file
21
plugins/extension/joomla/joomla.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="extension" method="upgrade">
|
||||
<name>plg_extension_joomla</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2010-05</creationDate>
|
||||
<copyright>(C) 2010 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>3.0.0</version>
|
||||
<description>PLG_EXTENSION_JOOMLA_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Extension\Joomla</namespace>
|
||||
<files>
|
||||
<folder plugin="joomla">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_joomla.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_joomla.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
47
plugins/extension/joomla/services/provider.php
Normal file
47
plugins/extension/joomla/services/provider.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.joomla
|
||||
*
|
||||
* @copyright (C) 2022 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\Extension\Joomla\Extension\Joomla;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$dispatcher = $container->get(DispatcherInterface::class);
|
||||
$plugin = new Joomla(
|
||||
$dispatcher,
|
||||
(array) PluginHelper::getPlugin('extension', 'joomla')
|
||||
);
|
||||
$plugin->setDatabase($container->get(DatabaseInterface::class));
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
293
plugins/extension/joomla/src/Extension/Joomla.php
Normal file
293
plugins/extension/joomla/src/Extension/Joomla.php
Normal file
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.joomla
|
||||
*
|
||||
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Extension\Joomla\Extension;
|
||||
|
||||
use Joomla\CMS\Installer\Installer;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Database\DatabaseAwareTrait;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Joomla! main extension plugin.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
final class Joomla extends CMSPlugin
|
||||
{
|
||||
use DatabaseAwareTrait;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
private $eid = 0;
|
||||
|
||||
/**
|
||||
* @var Installer
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
private $installer = null;
|
||||
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Adds an update site to the table if it doesn't exist.
|
||||
*
|
||||
* @param string $name The friendly name of the site
|
||||
* @param string $type The type of site (e.g. collection or extension)
|
||||
* @param string $location The URI for the site
|
||||
* @param boolean $enabled If this site is enabled
|
||||
* @param string $extraQuery Any additional request query to use when updating
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
private function addUpdateSite($name, $type, $location, $enabled, $extraQuery = '')
|
||||
{
|
||||
// Look if the location is used already; doesn't matter what type you can't have two types at the same address, doesn't make sense
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select($db->quoteName('update_site_id'))
|
||||
->from($db->quoteName('#__update_sites'))
|
||||
->where($db->quoteName('location') . ' = :location')
|
||||
->bind(':location', $location);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$update_site_id = (int) $db->loadResult();
|
||||
|
||||
// If it doesn't exist, add it!
|
||||
if (!$update_site_id) {
|
||||
$enabled = (int) $enabled;
|
||||
$query->clear()
|
||||
->insert($db->quoteName('#__update_sites'))
|
||||
->columns($db->quoteName(['name', 'type', 'location', 'enabled', 'extra_query']))
|
||||
->values(':name, :type, :location, :enabled, :extra_query')
|
||||
->bind(':name', $name)
|
||||
->bind(':type', $type)
|
||||
->bind(':location', $location)
|
||||
->bind(':enabled', $enabled, ParameterType::INTEGER)
|
||||
->bind(':extra_query', $extraQuery);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
if ($db->execute()) {
|
||||
// Link up this extension to the update site
|
||||
$update_site_id = $db->insertid();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it has an update site id (creation might have failed)
|
||||
if ($update_site_id) {
|
||||
// Look for an update site entry that exists
|
||||
$query->clear()
|
||||
->select($db->quoteName('update_site_id'))
|
||||
->from($db->quoteName('#__update_sites_extensions'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('update_site_id') . ' = :updatesiteid',
|
||||
$db->quoteName('extension_id') . ' = :extensionid',
|
||||
]
|
||||
)
|
||||
->bind(':updatesiteid', $update_site_id, ParameterType::INTEGER)
|
||||
->bind(':extensionid', $this->eid, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$tmpid = (int) $db->loadResult();
|
||||
|
||||
if (!$tmpid) {
|
||||
// Link this extension to the relevant update site
|
||||
$query->clear()
|
||||
->insert($db->quoteName('#__update_sites_extensions'))
|
||||
->columns($db->quoteName(['update_site_id', 'extension_id']))
|
||||
->values(':updatesiteid, :eid')
|
||||
->bind(':updatesiteid', $update_site_id, ParameterType::INTEGER)
|
||||
->bind(':eid', $this->eid, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle post extension install update sites
|
||||
*
|
||||
* @param Installer $installer Installer object
|
||||
* @param integer $eid Extension Identifier
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onExtensionAfterInstall($installer, $eid)
|
||||
{
|
||||
if ($eid) {
|
||||
$this->installer = $installer;
|
||||
$this->eid = (int) $eid;
|
||||
|
||||
// After an install we only need to do update sites
|
||||
$this->processUpdateSites();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle extension uninstall
|
||||
*
|
||||
* @param Installer $installer Installer instance
|
||||
* @param integer $eid Extension id
|
||||
* @param boolean $removed Installation result
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onExtensionAfterUninstall($installer, $eid, $removed)
|
||||
{
|
||||
// If we have a valid extension ID and the extension was successfully uninstalled wipe out any
|
||||
// update sites for it
|
||||
if ($eid && $removed) {
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
$eid = (int) $eid;
|
||||
|
||||
$query->delete($db->quoteName('#__update_sites_extensions'))
|
||||
->where($db->quoteName('extension_id') . ' = :eid')
|
||||
->bind(':eid', $eid, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
// Delete any unused update sites
|
||||
$query->clear()
|
||||
->select($db->quoteName('update_site_id'))
|
||||
->from($db->quoteName('#__update_sites_extensions'));
|
||||
|
||||
$db->setQuery($query);
|
||||
$results = $db->loadColumn();
|
||||
|
||||
if (is_array($results)) {
|
||||
// So we need to delete the update sites and their associated updates
|
||||
$updatesite_delete = $db->getQuery(true);
|
||||
$updatesite_delete->delete($db->quoteName('#__update_sites'));
|
||||
|
||||
$updatesite_query = $db->getQuery(true);
|
||||
$updatesite_query->select($db->quoteName('update_site_id'))
|
||||
->from($db->quoteName('#__update_sites'));
|
||||
|
||||
// If we get results back then we can exclude them
|
||||
if (count($results)) {
|
||||
$updatesite_query->whereNotIn($db->quoteName('update_site_id'), $results);
|
||||
$updatesite_delete->whereNotIn($db->quoteName('update_site_id'), $results);
|
||||
}
|
||||
|
||||
// So let's find what update sites we're about to nuke and remove their associated extensions
|
||||
$db->setQuery($updatesite_query);
|
||||
$update_sites_pending_delete = $db->loadColumn();
|
||||
|
||||
if (is_array($update_sites_pending_delete) && count($update_sites_pending_delete)) {
|
||||
// Nuke any pending updates with this site before we delete it
|
||||
// @todo: investigate alternative of using a query after the delete below with a query and not in like above
|
||||
$query->clear()
|
||||
->delete($db->quoteName('#__updates'))
|
||||
->whereIn($db->quoteName('update_site_id'), $update_sites_pending_delete);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
// Note: this might wipe out the entire table if there are no extensions linked
|
||||
$db->setQuery($updatesite_delete);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
// Last but not least we wipe out any pending updates for the extension
|
||||
$query->clear()
|
||||
->delete($db->quoteName('#__updates'))
|
||||
->where($db->quoteName('extension_id') . ' = :eid')
|
||||
->bind(':eid', $eid, ParameterType::INTEGER);
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* After update of an extension
|
||||
*
|
||||
* @param Installer $installer Installer object
|
||||
* @param integer $eid Extension identifier
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onExtensionAfterUpdate($installer, $eid)
|
||||
{
|
||||
if ($eid) {
|
||||
$this->installer = $installer;
|
||||
$this->eid = (int) $eid;
|
||||
|
||||
// Handle any update sites
|
||||
$this->processUpdateSites();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the list of update sites for an extension.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
private function processUpdateSites()
|
||||
{
|
||||
$manifest = $this->installer->getManifest();
|
||||
$updateservers = $manifest->updateservers;
|
||||
|
||||
if ($updateservers) {
|
||||
$children = $updateservers->children();
|
||||
} else {
|
||||
$children = [];
|
||||
}
|
||||
|
||||
if (count($children)) {
|
||||
foreach ($children as $child) {
|
||||
$attrs = $child->attributes();
|
||||
$this->addUpdateSite((string) $attrs['name'], (string) $attrs['type'], trim($child), true, $this->installer->extraQuery);
|
||||
}
|
||||
} else {
|
||||
$data = trim((string) $updateservers);
|
||||
|
||||
if ($data !== '') {
|
||||
// We have a single entry in the update server line, let us presume this is an extension line
|
||||
$this->addUpdateSite(Text::_('PLG_EXTENSION_JOOMLA_UNKNOWN_SITE'), 'extension', $data, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
plugins/extension/namespacemap/namespacemap.xml
Normal file
21
plugins/extension/namespacemap/namespacemap.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="extension" method="upgrade">
|
||||
<name>plg_extension_namespacemap</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2017-05</creationDate>
|
||||
<copyright>(C) 2017 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_EXTENSION_NAMESPACEMAP_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Extension\NamespaceMap</namespace>
|
||||
<files>
|
||||
<folder plugin="namespacemap">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_namespacemap.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_extension_namespacemap.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
46
plugins/extension/namespacemap/services/provider.php
Normal file
46
plugins/extension/namespacemap/services/provider.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.namespacemap
|
||||
*
|
||||
* @copyright (C) 2022 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\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Extension\NamespaceMap\Extension\NamespaceMap;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$dispatcher = $container->get(DispatcherInterface::class);
|
||||
$plugin = new NamespaceMap(
|
||||
$dispatcher,
|
||||
new JNamespacePsr4Map(),
|
||||
(array) PluginHelper::getPlugin('extension', 'namespacemap')
|
||||
);
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
110
plugins/extension/namespacemap/src/Extension/NamespaceMap.php
Normal file
110
plugins/extension/namespacemap/src/Extension/NamespaceMap.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Extension.namespacemap
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Extension\NamespaceMap\Extension;
|
||||
|
||||
use Joomla\CMS\Installer\Installer;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Joomla! namespace map creator / updater.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class NamespaceMap extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* The namespace map file creator
|
||||
*
|
||||
* @var \JNamespacePsr4Map
|
||||
*/
|
||||
private $fileCreator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param DispatcherInterface $subject The object to observe
|
||||
* @param \JNamespacePsr4Map $map The namespace map creator
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'group', 'params', 'language'
|
||||
* (this list is not meant to be comprehensive).
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct(DispatcherInterface $subject, \JNamespacePsr4Map $map, $config = [])
|
||||
{
|
||||
$this->fileCreator = $map;
|
||||
|
||||
parent::__construct($subject, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update / Create map on extension install
|
||||
*
|
||||
* @param Installer $installer Installer instance
|
||||
* @param integer $eid Extension id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterInstall($installer, $eid)
|
||||
{
|
||||
// Check that we have a valid extension
|
||||
if ($eid) {
|
||||
// Update / Create new map
|
||||
$this->fileCreator->create();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update / Create map on extension uninstall
|
||||
*
|
||||
* @param Installer $installer Installer instance
|
||||
* @param integer $eid Extension id
|
||||
* @param boolean $removed Installation result
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterUninstall($installer, $eid, $removed)
|
||||
{
|
||||
// Check that we have a valid extension and that it has been removed
|
||||
if ($eid && $removed) {
|
||||
// Update / Create new map
|
||||
$this->fileCreator->create();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update map on extension update
|
||||
*
|
||||
* @param Installer $installer Installer instance
|
||||
* @param integer $eid Extension id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onExtensionAfterUpdate($installer, $eid)
|
||||
{
|
||||
// Check that we have a valid extension
|
||||
if ($eid) {
|
||||
// Update / Create new map
|
||||
$this->fileCreator->create();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user