Merge branch '4.0-dev' into convert_weblink_editor_xtd_plugin

This commit is contained in:
Tuan Pham Ngoc 2023-03-16 17:55:50 +07:00
commit 510c296a7a
12 changed files with 316 additions and 102 deletions

View File

@ -48,6 +48,9 @@ class Com_WeblinksInstallerScript
'/language/en-GB/en-GB.mod_weblinks.sys.ini', '/language/en-GB/en-GB.mod_weblinks.sys.ini',
'/language/en-GB/en-GB.pkg_weblinks.sys.ini', '/language/en-GB/en-GB.pkg_weblinks.sys.ini',
'/modules/mod_weblinks/helper.php', '/modules/mod_weblinks/helper.php',
'/modules/mod_weblinks/mod_weblinks.php',
'/plugins/search/weblinks/weblinks.php',
'/plugins/finder/weblinks/weblinks.php',
]; ];
$folders = [ $folders = [

View File

@ -1,24 +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\Helper\ModuleHelper;
use Joomla\Module\Weblinks\Site\Helper\WeblinksHelper;
$list = WeblinksHelper::getList($params, $app);
if (empty($list))
{
return;
}
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
require ModuleHelper::getLayoutPath('mod_weblinks', $params->get('layout', 'default'));

View File

@ -12,7 +12,6 @@
<namespace path="src">Joomla\Module\Weblinks</namespace> <namespace path="src">Joomla\Module\Weblinks</namespace>
<files> <files>
##MODULE_FILES## ##MODULE_FILES##
<file module="mod_weblinks">mod_weblinks.php</file>
</files> </files>
<languages folder="language"> <languages folder="language">
##LANGUAGE_FILES## ##LANGUAGE_FILES##

View File

@ -0,0 +1,41 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_weblinks
*
* @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\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
/**
* The weblinks module services provider.
*
* @since __DEPLOY_VERSION__
*/
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->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Weblinks'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Weblinks\\Site\\Helper'));
$container->registerServiceProvider(new Module());
}
};

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Site
* @subpackage mod_weblinks
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Module\Weblinks\Site\Dispatcher;
use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Dispatcher class for mod_weblinks
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;
/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
$data['list'] = $this->getHelperFactory()->getHelper('WeblinksHelper')->getWeblinks(
$data['params'],
$this->getApplication()
);
$data['moduleclass_sfx'] = htmlspecialchars($data['params']->get('moduleclass_sfx', ''));
return $data;
}
}

View File

@ -29,14 +29,13 @@ class WeblinksHelper
* @param Registry $params The module parameters * @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application * @param CMSApplicationInterface $app The application
* *
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks. * @return array Array containing all the weblinks.
* *
* @since 1.5 * @since __DEPLOY_VERSION__
**/ **/
public static function getList($params, $app) public function getWeblinks($params, $app)
{ {
// @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model // @var \Joomla\Component\Weblinks\Site\Model\CategoryModel $model
$model = $app->bootComponent('com_weblinks')->getMVCFactory() $model = $app->bootComponent('com_weblinks')->getMVCFactory()
->createModel('Category', 'Site', ['ignore_request' => true]); ->createModel('Category', 'Site', ['ignore_request' => true]);
@ -73,7 +72,7 @@ class WeblinksHelper
$case_when1 .= $query->charLength('a.alias', '!=', '0'); $case_when1 .= $query->charLength('a.alias', '!=', '0');
$case_when1 .= ' THEN '; $case_when1 .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id'); $a_id = $query->castAs('CHAR', 'a.id');
$case_when1 .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when1 .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when1 .= ' ELSE '; $case_when1 .= ' ELSE ';
$case_when1 .= $a_id . ' END as slug'; $case_when1 .= $a_id . ' END as slug';
@ -81,7 +80,7 @@ class WeblinksHelper
$case_when2 .= $query->charLength('c.alias', '!=', '0'); $case_when2 .= $query->charLength('c.alias', '!=', '0');
$case_when2 .= ' THEN '; $case_when2 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id'); $c_id = $query->castAs('CHAR', 'c.id');
$case_when2 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when2 .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when2 .= ' ELSE '; $case_when2 .= ' ELSE ';
$case_when2 .= $c_id . ' END as catslug'; $case_when2 .= $c_id . ' END as catslug';
@ -120,4 +119,21 @@ class WeblinksHelper
return []; return [];
} }
/**
* Retrieve list of weblinks
*
* @param Registry $params The module parameters
* @param CMSApplicationInterface $app The application
*
* @return mixed Null if no weblinks based on input parameters else an array containing all the weblinks.
*
* @since 1.5
*
* @deprecated 5.0 Use the none static function getWeblinks
**/
public static function getList($params, $app)
{
return (new self())->getWeblinks($params, $app);
}
} }

View File

@ -0,0 +1,47 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Finder.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\Finder\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('finder', 'weblinks'),
$database
);
}
);
}
};

View File

@ -7,15 +7,22 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
namespace Joomla\Plugin\Finder\Weblinks\Extension;
defined('JPATH_BASE') or die; defined('JPATH_BASE') or die;
use Joomla\CMS\Categories\Categories; use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Table\Table;
use Joomla\Component\Finder\Administrator\Indexer\Adapter; use Joomla\Component\Finder\Administrator\Indexer\Adapter;
use Joomla\Component\Finder\Administrator\Indexer\Helper; use Joomla\Component\Finder\Administrator\Indexer\Helper;
use Joomla\Component\Finder\Administrator\Indexer\Indexer; use Joomla\Component\Finder\Administrator\Indexer\Indexer;
use Joomla\Component\Finder\Administrator\Indexer\Result; use Joomla\Component\Finder\Administrator\Indexer\Result;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\DatabaseQuery;
use Joomla\Event\DispatcherInterface;
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
/** /**
@ -23,8 +30,10 @@ use Joomla\Registry\Registry;
* *
* @since 2.5 * @since 2.5
*/ */
class PlgFinderWeblinks extends Adapter final class Weblinks extends Adapter
{ {
use DatabaseAwareTrait;
/** /**
* The plugin identifier. * The plugin identifier.
* *
@ -73,6 +82,20 @@ class PlgFinderWeblinks extends Adapter
*/ */
protected $autoloadLanguage = true; protected $autoloadLanguage = true;
/**
* 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);
}
/** /**
* Method to update the item link information when the item category is * Method to update the item link information when the item category is
* changed. This is fired when the item category is published or unpublished * changed. This is fired when the item category is published or unpublished
@ -99,12 +122,12 @@ class PlgFinderWeblinks extends Adapter
* Method to remove the link information for items that have been deleted. * Method to remove the link information for items that have been deleted.
* *
* @param string $context The context of the action being performed. * @param string $context The context of the action being performed.
* @param JTable $table A JTable object containing the record to be deleted. * @param Table $table A JTable object containing the record to be deleted.
* *
* @return boolean True on success. * @return boolean True on success.
* *
* @throws \Exception on database error.
* @since 2.5 * @since 2.5
* @throws Exception on database error.
*/ */
public function onFinderAfterDelete($context, $table) public function onFinderAfterDelete($context, $table)
{ {
@ -132,13 +155,13 @@ class PlgFinderWeblinks extends Adapter
* the category to which it belongs has been changed. * the category to which it belongs has been changed.
* *
* @param string $context The context of the content passed to the plugin. * @param string $context The context of the content passed to the plugin.
* @param JTable $row A JTable object. * @param Table $row A JTable object.
* @param boolean $isNew True if the content has just been created. * @param boolean $isNew True if the content has just been created.
* *
* @return boolean True on success. * @return boolean True on success.
* *
* @throws \Exception on database error.
* @since 2.5 * @since 2.5
* @throws Exception on database error.
*/ */
public function onFinderAfterSave($context, $row, $isNew) public function onFinderAfterSave($context, $row, $isNew)
{ {
@ -174,13 +197,13 @@ class PlgFinderWeblinks extends Adapter
* This event is fired before the data is actually saved. * This event is fired before the data is actually saved.
* *
* @param string $context The context of the content passed to the plugin. * @param string $context The context of the content passed to the plugin.
* @param JTable $row A JTable object. * @param Table $row A JTable object.
* @param boolean $isNew True if the content is just about to be created. * @param boolean $isNew True if the content is just about to be created.
* *
* @return boolean True on success. * @return boolean True on success.
* *
* @throws \Exception on database error.
* @since 2.5 * @since 2.5
* @throws Exception on database error.
*/ */
public function onFinderBeforeSave($context, $row, $isNew) public function onFinderBeforeSave($context, $row, $isNew)
{ {
@ -238,12 +261,12 @@ class PlgFinderWeblinks extends Adapter
/** /**
* Method to index an item. The item must be a FinderIndexerResult object. * Method to index an item. The item must be a FinderIndexerResult object.
* *
* @param Result $item The item to index as an FinderIndexerResult object. * @param Result $item The item to index as an FinderIndexerResult object.
* *
* @return void * @return void
* *
* @throws \Exception on database error.
* @since 2.5 * @since 2.5
* @throws Exception on database error.
*/ */
protected function index(Result $item) protected function index(Result $item)
{ {
@ -256,7 +279,7 @@ class PlgFinderWeblinks extends Adapter
$item->setLanguage(); $item->setLanguage();
// Initialise the item parameters. // Initialise the item parameters.
$item->params = new Registry($item->params); $item->params = new Registry($item->params);
$item->metadata = new Registry($item->metadata); $item->metadata = new Registry($item->metadata);
// Build the necessary route and path information. // Build the necessary route and path information.
@ -323,16 +346,16 @@ class PlgFinderWeblinks extends Adapter
* *
* @param mixed $query A JDatabaseQuery object or null. * @param mixed $query A JDatabaseQuery object or null.
* *
* @return JDatabaseQuery A database object. * @return DatabaseQuery A database object.
* *
* @since 2.5 * @since 2.5
*/ */
protected function getListQuery($query = null) protected function getListQuery($query = null)
{ {
$db = $this->db; $db = $this->getDatabase();
// Check if we can use the supplied SQL query. // Check if we can use the supplied SQL query.
$query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true) $query = $query instanceof DatabaseQuery ? $query : $db->getQuery(true)
->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary') ->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary')
->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering') ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering')
->select('a.created_by_alias, a.modified, a.modified_by') ->select('a.created_by_alias, a.modified, a.modified_by')
@ -344,8 +367,8 @@ class PlgFinderWeblinks extends Adapter
$case_when_item_alias = ' CASE WHEN '; $case_when_item_alias = ' CASE WHEN ';
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0'); $case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
$case_when_item_alias .= ' THEN '; $case_when_item_alias .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id'); $a_id = $query->castAs('CHAR', 'a.id');
$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when_item_alias .= $query->concatenate([$a_id, 'a.alias'], ':');
$case_when_item_alias .= ' ELSE '; $case_when_item_alias .= ' ELSE ';
$case_when_item_alias .= $a_id . ' END as slug'; $case_when_item_alias .= $a_id . ' END as slug';
$query->select($case_when_item_alias); $query->select($case_when_item_alias);
@ -353,12 +376,11 @@ class PlgFinderWeblinks extends Adapter
$case_when_category_alias = ' CASE WHEN '; $case_when_category_alias = ' CASE WHEN ';
$case_when_category_alias .= $query->charLength('c.alias', '!=', '0'); $case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
$case_when_category_alias .= ' THEN '; $case_when_category_alias .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id'); $c_id = $query->castAs('CHAR', 'c.id');
$case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when_category_alias .= $query->concatenate([$c_id, 'c.alias'], ':');
$case_when_category_alias .= ' ELSE '; $case_when_category_alias .= ' ELSE ';
$case_when_category_alias .= $c_id . ' END as catslug'; $case_when_category_alias .= $c_id . ' END as catslug';
$query->select($case_when_category_alias) $query->select($case_when_category_alias)
->from('#__weblinks AS a') ->from('#__weblinks AS a')
->join('LEFT', '#__categories AS c ON c.id = a.catid'); ->join('LEFT', '#__categories AS c ON c.id = a.catid');
@ -370,15 +392,16 @@ class PlgFinderWeblinks extends Adapter
* *
* @param string $time The modified timestamp. * @param string $time The modified timestamp.
* *
* @return JDatabaseQuery A database object. * @return DatabaseQuery A database object.
* *
* @since 2.5 * @since 2.5
*/ */
protected function getUpdateQueryByTime($time) protected function getUpdateQueryByTime($time)
{ {
// Build an SQL query based on the modified time. // Build an SQL query based on the modified time.
$query = $this->db->getQuery(true) $db = $this->getDatabase();
->where('a.date >= ' . $this->db->quote($time)); $query = $db->getQuery(true)
->where('a.date >= ' . $db->quote($time));
return $query; return $query;
} }

View File

@ -9,6 +9,7 @@
<authorUrl>www.joomla.org</authorUrl> <authorUrl>www.joomla.org</authorUrl>
<version>##VERSION##</version> <version>##VERSION##</version>
<description>PLG_FINDER_WEBLINKS_XML_DESCRIPTION</description> <description>PLG_FINDER_WEBLINKS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Finder\Weblinks</namespace>
<files> <files>
##FILES## ##FILES##
</files> </files>

View File

@ -0,0 +1,50 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Search.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\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\Search\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) {
$app = Factory::getApplication();
$dispatcher = $container->get(DispatcherInterface::class);
$database = $container->get(DatabaseInterface::class);
return new Weblinks(
$dispatcher,
(array) PluginHelper::getPlugin('finder', 'weblinks'),
$app,
$database
);
}
);
}
};

View File

@ -7,37 +7,28 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt * @license GNU General Public License version 2 or later; see LICENSE.txt
*/ */
defined('_JEXEC') or die; namespace Joomla\Plugin\Search\Weblinks\Extension;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Search\Administrator\Helper\SearchHelper;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType; use Joomla\Database\ParameterType;
use Joomla\Event\DispatcherInterface;
defined('_JEXEC') or die;
/** /**
* Weblinks search plugin. * Weblinks search plugin.
* *
* @since 1.6 * @since 1.6
*/ */
class PlgSearchWeblinks extends CMSPlugin final class Weblinks extends CMSPlugin
{ {
/** use DatabaseAwareTrait;
* Application object
*
* @var \Joomla\CMS\Application\CMSApplicationInterface
* @since 4.0.0
*/
protected $app;
/**
* Database Driver Instance
*
* @var \Joomla\Database\DatabaseDriver
* @since 4.0.0
*/
protected $db;
/** /**
* Load the language file on instantiation. * Load the language file on instantiation.
@ -47,6 +38,22 @@ class PlgSearchWeblinks extends CMSPlugin
*/ */
protected $autoloadLanguage = true; protected $autoloadLanguage = true;
/**
* Constructor
*
* @param DispatcherInterface $dispatcher
* @param array $config
* @param CMSApplicationInterface $application
* @param DatabaseInterface $database
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $application, DatabaseInterface $database)
{
parent::__construct($dispatcher, $config);
$this->setApplication($application);
$this->setDatabase($database);
}
/** /**
* Determine areas searchable by this plugin. * Determine areas searchable by this plugin.
* *
@ -56,9 +63,9 @@ class PlgSearchWeblinks extends CMSPlugin
*/ */
public function onContentSearchAreas() public function onContentSearchAreas()
{ {
static $areas = array( static $areas = [
'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS' 'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS',
); ];
return $areas; return $areas;
} }
@ -80,23 +87,22 @@ class PlgSearchWeblinks extends CMSPlugin
*/ */
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
{ {
$db = $this->db; $app = $this->getApplication();
$groups = $this->app->getIdentity()->getAuthorisedViewLevels(); $db = $this->getDatabase();
$groups = $app->getIdentity()->getAuthorisedViewLevels();
$searchText = $text; $searchText = $text;
if (is_array($areas)) if (is_array($areas)
&& !array_intersect($areas, array_keys($this->onContentSearchAreas())))
{ {
if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) return [];
{
return array();
}
} }
$sContent = $this->params->get('search_content', 1); $sContent = $this->params->get('search_content', 1);
$sArchived = $this->params->get('search_archived', 1); $sArchived = $this->params->get('search_archived', 1);
$limit = $this->params->def('search_limit', 50); $limit = $this->params->def('search_limit', 50);
$state = array(); $state = [];
if ($sContent) if ($sContent)
{ {
@ -110,14 +116,14 @@ class PlgSearchWeblinks extends CMSPlugin
if (empty($state)) if (empty($state))
{ {
return array(); return [];
} }
$text = trim($text); $text = trim($text);
if ($text == '') if ($text == '')
{ {
return array(); return [];
} }
$searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS'); $searchWeblinks = Text::_('PLG_SEARCH_WEBLINKS');
@ -125,28 +131,28 @@ class PlgSearchWeblinks extends CMSPlugin
switch ($phrase) switch ($phrase)
{ {
case 'exact': case 'exact':
$text = $db->quote('%' . $db->escape($text, true) . '%', false); $text = $db->quote('%' . $db->escape($text, true) . '%', false);
$wheres2 = array(); $wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $text; $wheres2[] = 'a.url LIKE ' . $text;
$wheres2[] = 'a.description LIKE ' . $text; $wheres2[] = 'a.description LIKE ' . $text;
$wheres2[] = 'a.title LIKE ' . $text; $wheres2[] = 'a.title LIKE ' . $text;
$where = '(' . implode(') OR (', $wheres2) . ')'; $where = '(' . implode(') OR (', $wheres2) . ')';
break; break;
case 'all': case 'all':
case 'any': case 'any':
default: default:
$words = explode(' ', $text); $words = explode(' ', $text);
$wheres = array(); $wheres = [];
foreach ($words as $word) foreach ($words as $word)
{ {
$word = $db->quote('%' . $db->escape($word, true) . '%', false); $word = $db->quote('%' . $db->escape($word, true) . '%', false);
$wheres2 = array(); $wheres2 = [];
$wheres2[] = 'a.url LIKE ' . $word; $wheres2[] = 'a.url LIKE ' . $word;
$wheres2[] = 'a.description LIKE ' . $word; $wheres2[] = 'a.description LIKE ' . $word;
$wheres2[] = 'a.title LIKE ' . $word; $wheres2[] = 'a.title LIKE ' . $word;
$wheres[] = implode(' OR ', $wheres2); $wheres[] = implode(' OR ', $wheres2);
} }
$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
@ -182,21 +188,21 @@ class PlgSearchWeblinks extends CMSPlugin
$caseWhen = ' CASE WHEN '; $caseWhen = ' CASE WHEN ';
$caseWhen .= $query->charLength('a.alias', '!=', '0'); $caseWhen .= $query->charLength('a.alias', '!=', '0');
$caseWhen .= ' THEN '; $caseWhen .= ' THEN ';
$a_id = $query->castAs('CHAR', 'a.id'); $a_id = $query->castAs('CHAR', 'a.id');
$caseWhen .= $query->concatenate(array($a_id, 'a.alias'), ':'); $caseWhen .= $query->concatenate([$a_id, 'a.alias'], ':');
$caseWhen .= ' ELSE '; $caseWhen .= ' ELSE ';
$caseWhen .= $a_id . ' END as slug'; $caseWhen .= $a_id . ' END as slug';
$caseWhen1 = ' CASE WHEN '; $caseWhen1 = ' CASE WHEN ';
$caseWhen1 .= $query->charLength('c.alias', '!=', '0'); $caseWhen1 .= $query->charLength('c.alias', '!=', '0');
$caseWhen1 .= ' THEN '; $caseWhen1 .= ' THEN ';
$c_id = $query->castAs('CHAR', 'c.id'); $c_id = $query->castAs('CHAR', 'c.id');
$caseWhen1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $caseWhen1 .= $query->concatenate([$c_id, 'c.alias'], ':');
$caseWhen1 .= ' ELSE '; $caseWhen1 .= ' ELSE ';
$caseWhen1 .= $c_id . ' END as catslug'; $caseWhen1 .= $c_id . ' END as catslug';
$query->select('a.title AS title, a.created AS created, a.url, a.description AS text, ' . $caseWhen . "," . $caseWhen1) $query->select('a.title AS title, a.created AS created, a.url, a.description AS text, ' . $caseWhen . "," . $caseWhen1)
->select($query->concatenate(array($db->quote($searchWeblinks), 'c.title'), " / ") . ' AS section') ->select($query->concatenate([$db->quote($searchWeblinks), 'c.title'], " / ") . ' AS section')
->select('\'1\' AS browsernav') ->select('\'1\' AS browsernav')
->from('#__weblinks AS a') ->from('#__weblinks AS a')
->join('INNER', '#__categories as c ON c.id = a.catid') ->join('INNER', '#__categories as c ON c.id = a.catid')
@ -207,9 +213,10 @@ class PlgSearchWeblinks extends CMSPlugin
->order($order); ->order($order);
// Filter by language. // Filter by language.
if ($this->app->isClient('site') && Multilanguage::isEnabled())
if ($app->isClient('site') && Multilanguage::isEnabled())
{ {
$languages = [$this->app->getLanguage()->getTag(), '*']; $languages = [$app->getLanguage()->getTag(), '*'];
$query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING) $query->whereIn($db->quoteName('a.language'), $languages, ParameterType::STRING)
->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING); ->whereIn($db->quoteName('c.language'), $languages, ParameterType::STRING);
} }
@ -217,7 +224,7 @@ class PlgSearchWeblinks extends CMSPlugin
$db->setQuery($query, 0, $limit); $db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList(); $rows = $db->loadObjectList();
$return = array(); $return = [];
if ($rows) if ($rows)
{ {
@ -228,7 +235,7 @@ class PlgSearchWeblinks extends CMSPlugin
foreach ($rows as $weblink) foreach ($rows as $weblink)
{ {
if (SearchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) if (\searchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title']))
{ {
$return[] = $weblink; $return[] = $weblink;
} }

View File

@ -9,6 +9,7 @@
<authorUrl>www.joomla.org</authorUrl> <authorUrl>www.joomla.org</authorUrl>
<version>##VERSION##</version> <version>##VERSION##</version>
<description>PLG_SEARCH_WEBLINKS_XML_DESCRIPTION</description> <description>PLG_SEARCH_WEBLINKS_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Search\Weblinks</namespace>
<files> <files>
##FILES## ##FILES##
</files> </files>