first commit
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Adapted from the Joomla Search.categories plugin - plugins/search/categories/categories.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Categories search plugin.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class PlgWfSearchCategories extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Determine areas searchable by this plugin.
|
||||
*
|
||||
* @return array An array of search areas.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onContentSearchAreas()
|
||||
{
|
||||
static $areas = array(
|
||||
'categories' => 'PLG_SEARCH_CATEGORIES_CATEGORIES',
|
||||
);
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search content (categories).
|
||||
*
|
||||
* The SQL must return the following fields that are used in a common display
|
||||
* routine: href, title, section, created, text, browsernav.
|
||||
*
|
||||
* @param string $text Target search string.
|
||||
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
|
||||
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
|
||||
* @param mixed $areas An array if the search is to be restricted to areas or null to search all areas.
|
||||
*
|
||||
* @return array Search results.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$user = JFactory::getUser();
|
||||
$app = JFactory::getApplication();
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$searchText = $text;
|
||||
|
||||
if (is_array($areas) && !array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$limit = $this->params->def('search_limit', 50);
|
||||
$text = trim($text);
|
||||
|
||||
if ($text === '') {
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($ordering) {
|
||||
case 'alpha':
|
||||
$order = 'a.title ASC';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
case 'popular':
|
||||
case 'newest':
|
||||
case 'oldest':
|
||||
default:
|
||||
$order = 'a.title DESC';
|
||||
}
|
||||
|
||||
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// SQLSRV changes.
|
||||
$case_when = ' CASE WHEN ';
|
||||
$case_when .= $query->charLength('a.alias', '!=', '0');
|
||||
$case_when .= ' THEN ';
|
||||
$a_id = $query->castAsChar('a.id');
|
||||
$case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
||||
$case_when .= ' ELSE ';
|
||||
$case_when .= $a_id . ' END as slug';
|
||||
|
||||
$query->select('a.title, a.description AS text, a.id AS catid, a.created_time, a.language, ' . $case_when);
|
||||
$query->from('#__categories AS a');
|
||||
$query->where(
|
||||
'(a.title LIKE ' . $text . ' OR a.description LIKE ' . $text . ') AND a.published = 1 AND a.extension = '
|
||||
. $db->quote('com_content') . 'AND a.access IN (' . $groups . ')'
|
||||
);
|
||||
|
||||
$query->group('a.id, a.title, a.description, a.alias, a.created_time');
|
||||
$query->order($order);
|
||||
|
||||
$db->setQuery($query, 0, $limit);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
} catch (RuntimeException $e) {
|
||||
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
|
||||
}
|
||||
|
||||
if ($rows) {
|
||||
foreach ($rows as $i => $row) {
|
||||
$rows[$i]->href = JHelperRoute::getCategoryRoute($row->slug, $row->language, 'com_content');
|
||||
$rows[$i]->section = JText::_('JCATEGORY');
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Adapted from the Joomla Search.contacts plugin - plugins/search/contacts/contacts.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Contacts search plugin.
|
||||
*/
|
||||
class PlgWfSearchContacts extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Determine areas searchable by this plugin.
|
||||
*
|
||||
* @return array An array of search areas.
|
||||
*/
|
||||
public function onContentSearchAreas()
|
||||
{
|
||||
static $areas = array(
|
||||
'contacts' => 'PLG_SEARCH_CONTACTS_CONTACTS'
|
||||
);
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search content (contacts).
|
||||
*
|
||||
* The SQL must return the following fields that are used in a common display
|
||||
* routine: href, title, section, created, text, browsernav.
|
||||
*
|
||||
* @param string $text Target search string.
|
||||
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
|
||||
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
|
||||
* @param string $areas An array if the search is to be restricted to areas or null to search all areas.
|
||||
*
|
||||
* @return array Search results.
|
||||
*/
|
||||
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$app = JFactory::getApplication();
|
||||
$user = JFactory::getUser();
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
|
||||
// create a new RouteHelper instance
|
||||
$router = new JHelperRoute();
|
||||
|
||||
if (is_array($areas) && !array_intersect($areas, array_keys($this->onContentSearchAreas())))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$limit = $this->params->def('search_limit', 50);
|
||||
|
||||
$text = trim($text);
|
||||
|
||||
if ($text === '')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$section = JText::_('PLG_SEARCH_CONTACTS_CONTACTS');
|
||||
|
||||
switch ($ordering)
|
||||
{
|
||||
case 'alpha':
|
||||
$order = 'a.name ASC';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$order = 'c.title ASC, a.name ASC';
|
||||
break;
|
||||
|
||||
case 'popular':
|
||||
case 'newest':
|
||||
case 'oldest':
|
||||
default:
|
||||
$order = 'a.name DESC';
|
||||
}
|
||||
|
||||
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// SQLSRV changes.
|
||||
$case_when = ' CASE WHEN ';
|
||||
$case_when .= $query->charLength('a.alias', '!=', '0');
|
||||
$case_when .= ' THEN ';
|
||||
$a_id = $query->castAsChar('a.id');
|
||||
$case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
||||
$case_when .= ' ELSE ';
|
||||
$case_when .= $a_id . ' END as slug';
|
||||
|
||||
$case_when1 = ' CASE WHEN ';
|
||||
$case_when1 .= $query->charLength('c.alias', '!=', '0');
|
||||
$case_when1 .= ' THEN ';
|
||||
$c_id = $query->castAsChar('c.id');
|
||||
$case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
|
||||
$case_when1 .= ' ELSE ';
|
||||
$case_when1 .= $c_id . ' END as catslug';
|
||||
|
||||
$query->select(
|
||||
'a.name AS title, a.con_position, a.misc, a.language, '
|
||||
. $case_when . ',' . $case_when1 . ', '
|
||||
. $query->concatenate(array('a.name', 'a.con_position', 'a.misc'), ',') . ' AS text'
|
||||
);
|
||||
$query->from('#__contact_details AS a')
|
||||
->join('INNER', '#__categories AS c ON c.id = a.catid')
|
||||
->where(
|
||||
'(a.name LIKE ' . $text . ' OR a.misc LIKE ' . $text . ' OR a.con_position LIKE ' . $text
|
||||
. ' OR a.address LIKE ' . $text . ' OR a.suburb LIKE ' . $text . ' OR a.state LIKE ' . $text
|
||||
. ' OR a.country LIKE ' . $text . ' OR a.postcode LIKE ' . $text . ' OR a.telephone LIKE ' . $text
|
||||
. ' OR a.fax LIKE ' . $text . ') AND a.published = 1 AND c.published = 1 '
|
||||
. ' AND a.access IN (' . $groups . ') AND c.access IN (' . $groups . ')'
|
||||
)
|
||||
->order($order);
|
||||
|
||||
$db->setQuery($query, 0, $limit);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$rows = array();
|
||||
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
|
||||
}
|
||||
|
||||
if ($rows)
|
||||
{
|
||||
// create a new RouteHelper instance
|
||||
$router = new JHelperRoute();
|
||||
|
||||
foreach ($rows as $key => $row)
|
||||
{
|
||||
$rows[$key]->href = $router->getRoute($row->slug, 'com_contact.contact', '', $row->language, $row->catslug);
|
||||
$rows[$key]->text = $row->title;
|
||||
$rows[$key]->text .= $row->con_position ? ', ' . $row->con_position : '';
|
||||
$rows[$key]->text .= $row->misc ? ', ' . $row->misc : '';
|
||||
|
||||
$rows[$key]->section = $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Adapted from the Joomla Search.content plugin - plugins/search/content/content.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Content search plugin.
|
||||
*
|
||||
*/
|
||||
class PlgWfSearchContent extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Determine areas searchable by this plugin.
|
||||
*
|
||||
* @return array An array of search areas.
|
||||
*
|
||||
*/
|
||||
public function onContentSearchAreas()
|
||||
{
|
||||
static $areas = array(
|
||||
'content' => 'JGLOBAL_ARTICLES',
|
||||
);
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search content (articles).
|
||||
* The SQL must return the following fields that are used in a common display
|
||||
* routine: href, title, section, created, text, browsernav.
|
||||
*
|
||||
* @param string $text Target search string.
|
||||
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
|
||||
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
|
||||
* @param mixed $areas An array if the search it to be restricted to areas or null to search all areas.
|
||||
*
|
||||
* @return array Search results.
|
||||
*
|
||||
*/
|
||||
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$serverType = $db->getServerType();
|
||||
$app = JFactory::getApplication();
|
||||
$user = JFactory::getUser();
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$tag = JFactory::getLanguage()->getTag();
|
||||
|
||||
$searchText = $text;
|
||||
|
||||
if (is_array($areas) && !array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$limit = $this->params->def('search_limit', 50);
|
||||
|
||||
$nullDate = $db->getNullDate();
|
||||
$date = JFactory::getDate();
|
||||
$now = $date->toSql();
|
||||
|
||||
$text = trim($text);
|
||||
|
||||
if ($text === '') {
|
||||
return array();
|
||||
}
|
||||
|
||||
$relevance = array();
|
||||
|
||||
switch ($phrase) {
|
||||
case 'exact':
|
||||
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
|
||||
$wheres2 = array();
|
||||
$wheres2[] = 'a.title LIKE ' . $text;
|
||||
$wheres2[] = 'a.introtext LIKE ' . $text;
|
||||
$wheres2[] = 'a.fulltext LIKE ' . $text;
|
||||
|
||||
$relevance[] = ' CASE WHEN ' . $wheres2[0] . ' THEN 5 ELSE 0 END ';
|
||||
|
||||
$where = '(' . implode(') OR (', $wheres2) . ')';
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
case 'any':
|
||||
default:
|
||||
$words = explode(' ', $text);
|
||||
$wheres = array();
|
||||
|
||||
foreach ($words as $word) {
|
||||
$word = $db->quote('%' . $db->escape($word, true) . '%', false);
|
||||
$wheres2 = array();
|
||||
$wheres2[] = 'LOWER(a.title) LIKE LOWER(' . $word . ')';
|
||||
$wheres2[] = 'LOWER(a.introtext) LIKE LOWER(' . $word . ')';
|
||||
$wheres2[] = 'LOWER(a.fulltext) LIKE LOWER(' . $word . ')';
|
||||
|
||||
$relevance[] = ' CASE WHEN ' . $wheres2[0] . ' THEN 5 ELSE 0 END ';
|
||||
|
||||
$wheres[] = implode(' OR ', $wheres2);
|
||||
}
|
||||
|
||||
$where = '(' . implode(($phrase === 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($ordering) {
|
||||
case 'oldest':
|
||||
$order = 'a.created ASC';
|
||||
break;
|
||||
|
||||
case 'popular':
|
||||
$order = 'a.hits DESC';
|
||||
break;
|
||||
|
||||
case 'alpha':
|
||||
$order = 'a.title ASC';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$order = 'c.title ASC, a.title ASC';
|
||||
break;
|
||||
|
||||
case 'newest':
|
||||
default:
|
||||
$order = 'a.created DESC';
|
||||
break;
|
||||
}
|
||||
|
||||
$rows = array();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Search articles.
|
||||
if ($limit > 0) {
|
||||
//sqlsrv changes
|
||||
$case_when1 = ' CASE WHEN ';
|
||||
$case_when1 .= $query->charLength('a.alias', '!=', '0');
|
||||
$case_when1 .= ' THEN ';
|
||||
$a_id = $query->castAsChar('a.id');
|
||||
$case_when1 .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
||||
$case_when1 .= ' ELSE ';
|
||||
$case_when1 .= $a_id . ' END as slug';
|
||||
|
||||
$case_when2 = ' CASE WHEN ';
|
||||
$case_when2 .= $query->charLength('b.alias', '!=', '0');
|
||||
$case_when2 .= ' THEN ';
|
||||
$c_id = $query->castAsChar('b.id');
|
||||
$case_when2 .= $query->concatenate(array($c_id, 'b.alias'), ':');
|
||||
$case_when2 .= ' ELSE ';
|
||||
$case_when2 .= $c_id . ' END as catslug';
|
||||
|
||||
$case = ',' . $case_when1 . ',' . $case_when2;
|
||||
|
||||
if (!empty($relevance)) {
|
||||
$query->select(implode(' + ', $relevance) . ' AS relevance');
|
||||
$order = ' relevance DESC, ' . $order;
|
||||
}
|
||||
|
||||
$query->select('a.id AS slug, b.id AS catslug, a.alias, a.state, a.title AS title, a.access, ' . $query->concatenate(array('a.introtext', 'a.fulltext')) . ' AS text, a.language' . $case);
|
||||
$query->from('#__content AS a');
|
||||
$query->innerJoin('#__categories AS b ON b.id = a.catid');
|
||||
$query->where('(' . $where . ') AND a.state = 1 AND b.published = 1');
|
||||
|
||||
if (!$user->authorise('core.admin')) {
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
$query->where('b.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
$query->order($order);
|
||||
|
||||
$db->setQuery($query, 0, $limit);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
} catch (RuntimeException $e) {
|
||||
$rows = array();
|
||||
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
|
||||
}
|
||||
|
||||
if ($rows) {
|
||||
// create a new RouteHelper instance
|
||||
$router = new JHelperRoute();
|
||||
|
||||
foreach ($rows as $key => $row) {
|
||||
$rows[$key]->href = $router->getRoute($row->slug, 'com_content.article', '', $row->language, $row->catslug);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Adapted from the Joomla Search.tags plugin - plugins/search/tags/tags.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Tags search plugin.
|
||||
*
|
||||
*/
|
||||
class PlgWfSearchTags extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Determine areas searchable by this plugin.
|
||||
*
|
||||
* @return array An array of search areas.
|
||||
*
|
||||
*/
|
||||
public function onContentSearchAreas()
|
||||
{
|
||||
static $areas = array(
|
||||
'tags' => 'PLG_SEARCH_TAGS_TAGS'
|
||||
);
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search content (tags).
|
||||
*
|
||||
* The SQL must return the following fields that are used in a common display
|
||||
* routine: href, title, section, created, text, browsernav.
|
||||
*
|
||||
* @param string $text Target search string.
|
||||
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
|
||||
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
|
||||
* @param string $areas An array if the search is to be restricted to areas or null to search all areas.
|
||||
*
|
||||
* @return array Search results.
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$app = JFactory::getApplication();
|
||||
$user = JFactory::getUser();
|
||||
$lang = JFactory::getLanguage();
|
||||
|
||||
$section = JText::_('PLG_SEARCH_TAGS_TAGS');
|
||||
$limit = $this->params->def('search_limit', 50);
|
||||
|
||||
if (is_array($areas) && !array_intersect($areas, array_keys($this->onContentSearchAreas())))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$text = trim($text);
|
||||
|
||||
if ($text === '')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
|
||||
|
||||
switch ($ordering)
|
||||
{
|
||||
case 'alpha':
|
||||
$order = 'a.title ASC';
|
||||
break;
|
||||
|
||||
case 'newest':
|
||||
$order = 'a.created_time DESC';
|
||||
break;
|
||||
|
||||
case 'oldest':
|
||||
$order = 'a.created_time ASC';
|
||||
break;
|
||||
|
||||
case 'popular':
|
||||
default:
|
||||
$order = 'a.title DESC';
|
||||
}
|
||||
|
||||
$query->select('a.id, a.title, a.alias, a.note, a.published, a.access'
|
||||
. ', a.checked_out, a.checked_out_time, a.created_user_id'
|
||||
. ', a.path, a.parent_id, a.level, a.lft, a.rgt'
|
||||
. ', a.language, a.created_time AS created, a.description');
|
||||
|
||||
$case_when_item_alias = ' CASE WHEN ';
|
||||
$case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
|
||||
$case_when_item_alias .= ' THEN ';
|
||||
$a_id = $query->castAsChar('a.id');
|
||||
$case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
||||
$case_when_item_alias .= ' ELSE ';
|
||||
$case_when_item_alias .= $a_id . ' END as slug';
|
||||
$query->select($case_when_item_alias);
|
||||
|
||||
$query->from('#__tags AS a');
|
||||
$query->where('a.alias <> ' . $db->quote('root'));
|
||||
|
||||
$query->where('(a.title LIKE ' . $text . ' OR a.alias LIKE ' . $text . ')');
|
||||
|
||||
$query->where($db->qn('a.published') . ' = 1');
|
||||
|
||||
if (!$user->authorise('core.admin'))
|
||||
{
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
$query->order($order);
|
||||
|
||||
$db->setQuery($query, 0, $limit);
|
||||
|
||||
try
|
||||
{
|
||||
$rows = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$rows = array();
|
||||
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
|
||||
}
|
||||
|
||||
if ($rows)
|
||||
{
|
||||
// create a new RouteHelper instance
|
||||
$router = new JHelperRoute();
|
||||
|
||||
foreach ($rows as $key => $row)
|
||||
{
|
||||
$rows[$key]->href = $router->getRoute($row->slug, 'com_tags.tag', '', $row->language);
|
||||
$rows[$key]->text = ($row->description !== '' ? $row->description : $row->title);
|
||||
$rows[$key]->text .= $row->note;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Adapted from the Joomla Search.weblinks plugin - plugins/search/weblinks/weblinks.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
require_once JPATH_SITE . '/components/com_weblinks/helpers/route.php';
|
||||
|
||||
/**
|
||||
* Weblinks search plugin.
|
||||
*
|
||||
*/
|
||||
class PlgWfSearchWeblinks extends JPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Determine areas searchable by this plugin.
|
||||
*
|
||||
* @return array An array of search areas.
|
||||
*
|
||||
*/
|
||||
public function onContentSearchAreas()
|
||||
{
|
||||
static $areas = array(
|
||||
'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS'
|
||||
);
|
||||
|
||||
return $areas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search content (weblinks).
|
||||
*
|
||||
* The SQL must return the following fields that are used in a common display
|
||||
* routine: href, title, section, created, text, browsernav
|
||||
*
|
||||
* @param string $text Target search string.
|
||||
* @param string $phrase Matching option (possible values: exact|any|all). Default is "any".
|
||||
* @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest".
|
||||
* @param mixed $areas An array if the search it to be restricted to areas or null to search all areas.
|
||||
*
|
||||
* @return array Search results.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$groups = implode(',', JFactory::getUser()->getAuthorisedViewLevels());
|
||||
|
||||
$searchText = $text;
|
||||
|
||||
if (is_array($areas))
|
||||
{
|
||||
if (!array_intersect($areas, array_keys($this->onContentSearchAreas())))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
$limit = $this->params->def('search_limit', 50);
|
||||
$state = array();
|
||||
|
||||
$text = trim($text);
|
||||
|
||||
if ($text == '')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
switch ($phrase)
|
||||
{
|
||||
case 'exact':
|
||||
$text = $db->quote('%' . $db->escape($text, true) . '%', false);
|
||||
$wheres2 = array();
|
||||
$wheres2[] = 'a.url LIKE ' . $text;
|
||||
$wheres2[] = 'a.description LIKE ' . $text;
|
||||
$wheres2[] = 'a.title LIKE ' . $text;
|
||||
$where = '(' . implode(') OR (', $wheres2) . ')';
|
||||
break;
|
||||
|
||||
case 'all':
|
||||
case 'any':
|
||||
default:
|
||||
$words = explode(' ', $text);
|
||||
$wheres = array();
|
||||
|
||||
foreach ($words as $word)
|
||||
{
|
||||
$word = $db->quote('%' . $db->escape($word, true) . '%', false);
|
||||
$wheres2 = array();
|
||||
$wheres2[] = 'a.url LIKE ' . $word;
|
||||
$wheres2[] = 'a.description LIKE ' . $word;
|
||||
$wheres2[] = 'a.title LIKE ' . $word;
|
||||
$wheres[] = implode(' OR ', $wheres2);
|
||||
}
|
||||
|
||||
$where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($ordering)
|
||||
{
|
||||
case 'oldest':
|
||||
$order = 'a.created ASC';
|
||||
break;
|
||||
|
||||
case 'popular':
|
||||
$order = 'a.hits DESC';
|
||||
break;
|
||||
|
||||
case 'alpha':
|
||||
$order = 'a.title ASC';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$order = 'c.title ASC, a.title ASC';
|
||||
break;
|
||||
|
||||
case 'newest':
|
||||
default:
|
||||
$order = 'a.created DESC';
|
||||
}
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// SQLSRV changes.
|
||||
$case_when = ' CASE WHEN ';
|
||||
$case_when .= $query->charLength('a.alias', '!=', '0');
|
||||
$case_when .= ' THEN ';
|
||||
$a_id = $query->castAsChar('a.id');
|
||||
$case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
|
||||
$case_when .= ' ELSE ';
|
||||
$case_when .= $a_id . ' END as slug';
|
||||
|
||||
$case_when1 = ' CASE WHEN ';
|
||||
$case_when1 .= $query->charLength('c.alias', '!=', '0');
|
||||
$case_when1 .= ' THEN ';
|
||||
$c_id = $query->castAsChar('c.id');
|
||||
$case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
|
||||
$case_when1 .= ' ELSE ';
|
||||
$case_when1 .= $c_id . ' END as catslug';
|
||||
|
||||
$query->select('a.title AS title, a.created AS created, a.url, a.description AS text, a.language, ' . $case_when . "," . $case_when1)
|
||||
->from('#__weblinks AS a')
|
||||
->join('INNER', '#__categories as c ON c.id = a.catid')
|
||||
->where('(' . $where . ') AND a.state = 1 AND c.published = 1 AND c.access IN (' . $groups . ')')
|
||||
->order($order);
|
||||
|
||||
$db->setQuery($query, 0, $limit);
|
||||
$rows = $db->loadObjectList();
|
||||
|
||||
if ($rows)
|
||||
{
|
||||
foreach ($rows as $key => $row)
|
||||
{
|
||||
$rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug, $row->language);
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
1
components/com_jce/editor/extensions/search/css/link.css
Normal file
1
components/com_jce/editor/extensions/search/css/link.css
Normal file
@@ -0,0 +1 @@
|
||||
#search-browser,#searchbox{position:relative}#search-browser button{padding:0 .5em}#search-browser button .uk-icon{margin:auto}#searchbox{z-index:1}div#search-browser input[type=checkbox],div#search-browser input[type=radio]{vertical-align:middle}.phrases-box input[type=radio]{margin:-3px 5px 0 0}#searchbox input{border-top-right-radius:0;border-bottom-right-radius:0;margin:0}#searchbox+div{margin-left:-1px;padding:0}#search-button{border-top-left-radius:0;border-bottom-left-radius:0}#search-clear{display:none}#search-clear.uk-active{display:block}#search-browser .uk-icon-spinner{display:none;right:0}#search-browser.loading .uk-icon-spinner{display:block;opacity:1}#search-result{width:100%;height:100%;position:absolute;display:none;overflow:auto;overflow-x:hidden;margin:2px 0}#search-result dl{margin:5px 0;padding:10px}#search-result dl dt{cursor:pointer;font-weight:700;text-overflow:ellipsis;overflow:hidden;white-space:pre;text-decoration:underline}div#search-browser div#search-result dl.odd{background-color:#F5F5F5}div#search-browser div#search-result dl dd.anchor{line-height:32px;cursor:pointer}div#search-browser #search-options{width:100%;padding:5px;margin:2px 0 0}div#search-browser #search-options fieldset{margin:0;padding:0}div#search-browser #search-options fieldset>div{margin:5px 0}div#search-browser #search-options label{min-width:40px}#search-options-button{line-height:1}#search-options .search_only ul{list-style:none;padding:0;margin:0}#search-options .search_only ul li{display:inline-block}@media (max-width:375px){#search-button span{display:none}}
|
||||
1
components/com_jce/editor/extensions/search/index.html
Normal file
1
components/com_jce/editor/extensions/search/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
2
components/com_jce/editor/extensions/search/js/link.js
Normal file
2
components/com_jce/editor/extensions/search/js/link.js
Normal file
@@ -0,0 +1,2 @@
|
||||
/* jce - 2.9.32 | 2022-11-01 | https://www.joomlacontenteditor.net | Copyright (C) 2006 - 2022 Ryan Demmer. All rights reserved | GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html */
|
||||
var WFLinkSearch=WFExtensions.add("LinkSearch",{options:{element:"#search-input",button:"#search-button",clear:"#search-clear",empty:"No Results",onClick:$.noop},init:function(options){$.extend(this.options,options);var self=this,el=this.options.element,btn=this.options.button;$(btn).on("click",function(e){self.search(),e.preventDefault()}).button({icons:{primary:"uk-icon-search"}}),$("#search-clear").on("click",function(e){$(this).hasClass("uk-active")&&($(this).removeClass("uk-active"),$(el).val(""),$("#search-result").empty().hide())}),$("#search-options-button").on("click",function(e){e.preventDefault(),$(this).addClass("uk-active");var $p=$("#search-options").parent();$("#search-options").height($p.parent().height()-$p.outerHeight()-15).toggle()}).on("close",function(){$(this).removeClass("uk-active"),$("#search-options").hide()}),$(el).on("change keyup",function(){""===this.value&&($("#search-result").empty().hide(),$("#search-clear").removeClass("uk-active"))})},search:function(){var self=this,s=this.options,el=s.element,$p=(s.button,$("#search-result").parent()),query=$(el).val();query&&!$(el).hasClass("placeholder")&&($("#search-clear").removeClass("uk-active"),$("#search-browser").addClass("loading"),query=$.trim(query.replace(/[\///<>#]/g,"")),Wf.JSON.request("doSearch",{json:[query]},function(results){if(results){if(results.error)return void Wf.Dialog.alert(results.error);$("#search-result").empty(),results.length?($.each(results,function(i,values){console.log(values),$.each(values,function(name,items){$("<h3>"+name+"</h3>").appendTo("#search-result"),$.each(items,function(i,item){var $dl=$('<dl class="uk-margin-small" />').appendTo("#search-result");$('<dt class="link uk-margin-small" />').text(item.title).on("click",function(){$.isFunction(self.options.onClick)&&self.options.onClick.call(this,Wf.String.decode(item.link))}).prepend('<i class="uk-icon uk-icon-file-text-o uk-margin-small-right" />').appendTo($dl),$('<dd class="text">'+item.text+"</dd>").appendTo($dl),item.anchors&&$.each(item.anchors,function(i,a){$('<dd class="anchor"><i role="presentation" class="uk-icon uk-icon-anchor uk-margin-small-right"></i>#'+a+"</dd>").on("click",function(){self.options.onClick.call(this,Wf.String.decode(item.link)+"#"+a)}).appendTo($dl)})})})}),$("dl:odd","#search-result").addClass("odd")):$("#search-result").append("<p>"+s.empty+"</p>"),$("#search-options-button").trigger("close"),$("#search-result").height($p.parent().height()-$p.outerHeight()-5).show()}$("#search-browser").removeClass("loading"),$("#search-clear").addClass("uk-active")},self))}});
|
||||
459
components/com_jce/editor/extensions/search/link.php
Normal file
459
components/com_jce/editor/extensions/search/link.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2009-2022 Ryan Demmer. All rights reserved
|
||||
* @license GNU/GPL 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* JCE is free software. This version may have been modified pursuant
|
||||
* to the GNU General Public License, and as distributed it includes or
|
||||
* is derivative of works licensed under the GNU General Public License or
|
||||
* other free or open source software licenses
|
||||
*/
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
class WFLinkSearchExtension extends WFSearchExtension
|
||||
{
|
||||
private $enabled = array();
|
||||
|
||||
protected function loadDefaultAdapter($plugin)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// create component name from plugin - special case for "contacts"
|
||||
$component = ($plugin == 'contacts') ? 'com_contact' : 'com_' . $plugin;
|
||||
|
||||
// check for associated component
|
||||
if (!JComponentHelper::isEnabled($component)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$adapter = __DIR__ . '/adapter/' . $plugin . '/' . $plugin . '.php';
|
||||
|
||||
if (!is_file($adapter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once $adapter;
|
||||
|
||||
// create classname, eg: PlgSearchContent
|
||||
$className = 'PlgWfSearch' . ucfirst($plugin);
|
||||
|
||||
if (!class_exists($className)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// simple plugin config
|
||||
$config = array(
|
||||
'name' => $plugin,
|
||||
'type' => 'search',
|
||||
'params' => array(
|
||||
'search_limit' => 10
|
||||
),
|
||||
);
|
||||
|
||||
// Joomla 4
|
||||
if (method_exists($app, 'getDispatcher')) {
|
||||
$dispatcher = $app->getDispatcher();
|
||||
$instance = new $className($dispatcher, (array) $config);
|
||||
$instance->registerListeners();
|
||||
} else {
|
||||
$dispatcher = JEventDispatcher::getInstance();
|
||||
$instance = new $className($dispatcher, (array) $config);
|
||||
}
|
||||
|
||||
$this->enabled[] = $plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor activating the default information of the class.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$request = WFRequest::getInstance();
|
||||
|
||||
$request->setRequest(array($this, 'doSearch'));
|
||||
$request->setRequest(array($this, 'getAreas'));
|
||||
|
||||
$wf = WFEditorPlugin::getInstance();
|
||||
|
||||
// get plugins
|
||||
$plugins = $wf->getParam('search.link.plugins', array());
|
||||
|
||||
// set defaults if empty
|
||||
if (empty($plugins)) {
|
||||
$plugins = array('categories', 'contacts', 'content', 'tags');
|
||||
}
|
||||
|
||||
// list core adapters
|
||||
$adapters = array('categories', 'contacts', 'content', 'tags', 'weblinks');
|
||||
|
||||
// check and load external search plugins
|
||||
foreach ($plugins as $plugin) {
|
||||
// process core search plugins
|
||||
if (in_array($plugin, $adapters)) {
|
||||
$this->loadDefaultAdapter($plugin);
|
||||
continue;
|
||||
}
|
||||
|
||||
// plugin must be enabled
|
||||
if (!JPluginHelper::isEnabled('search', $plugin)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// check plugin imports correctly - plugin may have a db entry, but is missing files
|
||||
if (JPluginHelper::importPlugin('search', $plugin)) {
|
||||
$this->enabled[] = $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
parent::display();
|
||||
|
||||
$document = WFDocument::getInstance();
|
||||
$document->addScript(array('link'), 'extensions.search.js');
|
||||
$document->addStylesheet(array('link'), 'extensions.search.css');
|
||||
}
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
$wf = WFEditorPlugin::getInstance();
|
||||
return (bool) $wf->getParam('search.link.enable', 1) && !empty($this->enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the search areas.
|
||||
*/
|
||||
public function getAreas()
|
||||
{
|
||||
$app = JFactory::getApplication('site');
|
||||
|
||||
$areas = array();
|
||||
$results = array();
|
||||
|
||||
$searchareas = $app->triggerEvent('onContentSearchAreas');
|
||||
|
||||
foreach ($searchareas as $area) {
|
||||
if (is_array($area)) {
|
||||
$areas = array_merge($areas, $area);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($areas as $k => $v) {
|
||||
$results[$k] = JText::_($v);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/*
|
||||
* Truncate search text
|
||||
* This method uses portions of components/com_finder/views/search/tmpl/default_result.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*/
|
||||
private function truncateText($text, $searchword)
|
||||
{
|
||||
// Calculate number of characters to display around the result
|
||||
$term_length = StringHelper::strlen($searchword);
|
||||
|
||||
$lang = JFactory::getLanguage();
|
||||
$desc_length = $lang->getSearchDisplayedCharactersNumber();
|
||||
|
||||
$pad_length = $term_length < $desc_length ? (int) floor(($desc_length - $term_length) / 2) : 0;
|
||||
|
||||
// Find the position of the search term
|
||||
$pos = $term_length ? StringHelper::strpos(StringHelper::strtolower($text), StringHelper::strtolower($searchword)) : false;
|
||||
|
||||
// Find a potential start point
|
||||
$start = ($pos && $pos > $pad_length) ? $pos - $pad_length : 0;
|
||||
|
||||
// Find a space between $start and $pos, start right after it.
|
||||
$space = StringHelper::strpos($text, ' ', $start > 0 ? $start - 1 : 0);
|
||||
$start = ($space && $space < $pos) ? $space + 1 : $start;
|
||||
|
||||
$text = JHtml::_('string.truncate', StringHelper::substr($text, $start), $desc_length, false);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Prepare search content by clean and truncating
|
||||
* This method uses portions of SearchHelper::prepareSearchContent from administrator/components/com_search/helpers/search.php
|
||||
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
||||
*/
|
||||
public function prepareSearchContent($text, $searchword)
|
||||
{
|
||||
// Replace line breaking tags with whitespace.
|
||||
$text = preg_replace("'<(br[^/>]*?/|hr[^/>]*?/|/(div|h[1-6]|li|p|td))>'si", ' ', $text);
|
||||
|
||||
// clean text
|
||||
$text = htmlspecialchars(strip_tags($text));
|
||||
|
||||
// remove shortcode
|
||||
$text = preg_replace('#{.+?}#', '', $text);
|
||||
|
||||
// truncate text based around searchword
|
||||
$text = $this->truncateText($text, $searchword);
|
||||
|
||||
// highlight searchword
|
||||
$text = preg_replace('#\b(' . preg_quote($searchword, '#') . ')\b#i', '<mark>$1</mark>', $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/*
|
||||
* Render Search fields
|
||||
* This method uses portions of SearchViewSearch::display from components/com_search/views/search/view.html.php
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
public function render()
|
||||
{
|
||||
if (!$this->isEnabled()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// built select lists
|
||||
$orders = array();
|
||||
$orders[] = JHtml::_('select.option', 'newest', JText::_('WF_SEARCH_NEWEST_FIRST'));
|
||||
$orders[] = JHtml::_('select.option', 'oldest', JText::_('WF_SEARCH_OLDEST_FIRST'));
|
||||
$orders[] = JHtml::_('select.option', 'popular', JText::_('WF_SEARCH_MOST_POPULAR'));
|
||||
$orders[] = JHtml::_('select.option', 'alpha', JText::_('WF_SEARCH_ALPHABETICAL'));
|
||||
$orders[] = JHtml::_('select.option', 'category', JText::_('WF_CATEGORY'));
|
||||
|
||||
$lists = array();
|
||||
$lists['ordering'] = JHtml::_('select.genericlist', $orders, 'ordering', 'class="inputbox"', 'value', 'text');
|
||||
|
||||
$searchphrases = array();
|
||||
$searchphrases[] = JHtml::_('select.option', 'all', JText::_('WF_SEARCH_ALL_WORDS'));
|
||||
$searchphrases[] = JHtml::_('select.option', 'any', JText::_('WF_SEARCH_ANY_WORDS'));
|
||||
$searchphrases[] = JHtml::_('select.option', 'exact', JText::_('WF_SEARCH_EXACT_PHRASE'));
|
||||
$lists['searchphrase'] = JHtml::_('select.radiolist', $searchphrases, 'searchphrase', '', 'value', 'text', 'all');
|
||||
|
||||
$view = $this->getView(array('name' => 'search', 'layout' => 'search'));
|
||||
|
||||
$view->searchareas = self::getAreas();
|
||||
$view->lists = $lists;
|
||||
|
||||
$view->display();
|
||||
}
|
||||
|
||||
private static function getSearchAreaFromUrl($url)
|
||||
{
|
||||
$query = parse_url($url, PHP_URL_QUERY);
|
||||
|
||||
if (empty($query)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
parse_str($query, $values);
|
||||
|
||||
if (!array_key_exists('option', $values)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$language = JFactory::getLanguage();
|
||||
|
||||
$option = $values['option'];
|
||||
|
||||
// load system language file
|
||||
$language->load($option . '.sys', JPATH_ADMINISTRATOR);
|
||||
$language->load($option, JPATH_ADMINISTRATOR);
|
||||
|
||||
return JText::_($option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process search.
|
||||
*
|
||||
* @param type $query Search query
|
||||
* @return array Search Results
|
||||
*
|
||||
* This method uses portions of SearchController::search from components/com_search/controller.php
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved
|
||||
*/
|
||||
public function doSearch($query)
|
||||
{
|
||||
$wf = WFEditorPlugin::getInstance();
|
||||
|
||||
$results = array();
|
||||
|
||||
if (empty($query)) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
// search area
|
||||
$area = null;
|
||||
|
||||
// available search areas
|
||||
$areas = $this->getAreas();
|
||||
|
||||
// query using a specific plugin
|
||||
if (strpos($query, ':') !== false) {
|
||||
preg_match('#^(' . implode('|', $areas) . ')\:(.+)#', $query, $matches);
|
||||
|
||||
if ($matches) {
|
||||
$area = array($matches[1]);
|
||||
$query = $matches[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists('JSite')) {
|
||||
// Load JSite class
|
||||
JLoader::register('JSite', JPATH_SITE . '/includes/application.php');
|
||||
}
|
||||
|
||||
$app = JFactory::getApplication('site');
|
||||
$filter = JFilterInput::getInstance();
|
||||
$router = $app::getRouter('site');
|
||||
|
||||
// get router mode
|
||||
$sef = (int) $wf->getParam('search.link.sef_url', 0);
|
||||
|
||||
$limit = (int) $wf->getParam('search.link.limit', 50);
|
||||
|
||||
// set router off so a raw url is returned by the Search plugin
|
||||
if ($router) {
|
||||
//$router->setMode(0);
|
||||
}
|
||||
|
||||
// slashes cause errors, <> get stripped anyway later on. # causes problems.
|
||||
$searchword = trim(str_replace(array('#', '>', '<', '\\'), '', $filter->clean($query)));
|
||||
|
||||
$ordering = null;
|
||||
$searchphrase = 'all';
|
||||
|
||||
// if searchword enclosed in double quotes, strip quotes and do exact match
|
||||
if (substr($searchword, 0, 1) == '"' && substr($searchword, -1) == '"') {
|
||||
$searchword = substr($searchword, 1, -1);
|
||||
$searchphrase = 'exact';
|
||||
}
|
||||
|
||||
$searchphrase = $app->input->post->getWord('searchphrase', $searchphrase);
|
||||
|
||||
// get passed through ordering
|
||||
$ordering = $app->input->post->getWord('ordering', $ordering);
|
||||
|
||||
// get passed through area
|
||||
$area = $app->input->post->getCmd('areas', (array) $area);
|
||||
|
||||
if (empty($area)) {
|
||||
$area = null;
|
||||
}
|
||||
|
||||
// trigger search on loaded plugins
|
||||
$searches = $app->triggerEvent('onContentSearch', array(
|
||||
$searchword,
|
||||
$searchphrase,
|
||||
$ordering,
|
||||
$area,
|
||||
));
|
||||
|
||||
$rows = array();
|
||||
|
||||
foreach ($searches as $search) {
|
||||
$rows = array_merge((array) $rows, (array) $search);
|
||||
}
|
||||
|
||||
// get first 10
|
||||
$rows = array_slice($rows, 0, $limit);
|
||||
|
||||
$areas = array();
|
||||
|
||||
for ($i = 0, $count = count($rows); $i < $count; ++$i) {
|
||||
$row = &$rows[$i];
|
||||
|
||||
if (empty($row->href) || empty($row->title)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$area = isset($row->section) ? $row->section : self::getSearchAreaFromUrl($row->href);
|
||||
|
||||
if (!isset($areas[$area])) {
|
||||
$areas[$area] = array();
|
||||
}
|
||||
|
||||
$result = new StdClass;
|
||||
|
||||
if ($searchphrase == 'exact') {
|
||||
$searchwords = array($searchword);
|
||||
$needle = $searchword;
|
||||
} else {
|
||||
$searchworda = preg_replace('#\xE3\x80\x80#s', ' ', $searchword);
|
||||
$searchwords = preg_split("/\s+/u", $searchworda);
|
||||
$needle = $searchwords[0];
|
||||
}
|
||||
|
||||
// get anchors if any...
|
||||
$row->anchors = self::getAnchors($row->text);
|
||||
|
||||
// prepare and truncate search text
|
||||
$row->text = $this->prepareSearchContent($row->text, $needle);
|
||||
|
||||
// remove base url
|
||||
if (JURI::base(true) && strpos($row->href, JURI::base(true)) !== false) {
|
||||
$row->href = substr_replace($row->href, '', 0, strlen(JURI::base(true)) + 1);
|
||||
}
|
||||
|
||||
// remove the alias or ItemId from a link
|
||||
$row->href = self::route($row->href);
|
||||
|
||||
$result->title = $row->title;
|
||||
$result->text = $row->text;
|
||||
$result->link = $row->href;
|
||||
|
||||
if (!empty($row->anchors)) {
|
||||
$result->anchors = $row->anchors;
|
||||
}
|
||||
|
||||
$areas[$area][] = $result;
|
||||
}
|
||||
|
||||
if (!empty($areas)) {
|
||||
$results[] = $areas;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private static function route($url)
|
||||
{
|
||||
$wf = WFEditorPlugin::getInstance();
|
||||
|
||||
if ((bool) $wf->getParam('search.link.remove_alias', 0)) {
|
||||
$url = WFLinkHelper::route($url);
|
||||
}
|
||||
|
||||
// remove Itemid if "home"
|
||||
$url = WFLinkHelper::removeHomeItemId($url);
|
||||
|
||||
// remove Itemid if set
|
||||
if ((bool) $wf->getParam('search.link.itemid', 1) === false) {
|
||||
$url = WFLinkHelper::removeItemId($url);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
private static function getAnchors($content)
|
||||
{
|
||||
preg_match_all('#<a([^>]+)(name|id)="([a-z]+[\w\-\:\.]*)"([^>]*)>#i', $content, $matches, PREG_SET_ORDER);
|
||||
|
||||
$anchors = array();
|
||||
|
||||
if (!empty($matches)) {
|
||||
foreach ($matches as $match) {
|
||||
if (strpos($match[0], 'href') === false) {
|
||||
$anchors[] = $match[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $anchors;
|
||||
}
|
||||
}
|
||||
36
components/com_jce/editor/extensions/search/link.xml
Normal file
36
components/com_jce/editor/extensions/search/link.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" ?>
|
||||
<extension version="3.4" type="plugin" group="jce" method="upgrade">
|
||||
<name>WF_LINK_SEARCH_TITLE</name>
|
||||
<version>2.9.32</version>
|
||||
<creationDate>01-11-2022</creationDate>
|
||||
<author>Ryan Demmer</author>
|
||||
<authorEmail>info@joomlacontenteditor.net</authorEmail>
|
||||
<authorUrl>https://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>WF_LINK_SEARCH_DESC</description>
|
||||
<files>
|
||||
<filename>link.php</filename>
|
||||
<folder>link</folder>
|
||||
</files>
|
||||
<fields name="link">
|
||||
<fieldset name="link">
|
||||
<field name="enable" type="yesno" default="1" label="WF_LABEL_EXTENSION_ENABLE" description="WF_LABEL_EXTENSION_ENABLE_DESC">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
<field name="plugins" type="searchplugins" multiple="true" label="WF_PARAM_LINK_SEARCH_PLUGINS" description="WF_PARAM_LINK_SEARCH_PLUGINS_DESC" default="categories,contacts,content,weblinks,tags" layout="joomla.form.field.list-fancy-select" />
|
||||
<field name="remove_alias" type="yesno" default="0" label="WF_LINK_SEARCH_REMOVE_ALIAS" description="WF_LINK_SEARCH_REMOVE_ALIAS_DESC">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
<field name="itemid" type="yesno" default="1" label="WF_LINK_SEARCH_ITEMID" description="WF_LINK_SEARCH_ITEMID_DESC">
|
||||
<option value="1">JYES</option>
|
||||
<option value="0">JNO</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
<plugins>link</plugins>
|
||||
<media></media>
|
||||
<languages></languages>
|
||||
</extension>
|
||||
Reference in New Issue
Block a user