mirror of
https://github.com/joomla/joomla-cms.git
synced 2024-09-06 02:14:40 +00:00
[4.0] Implementing OpenSearch in com_finder (#20936)
* Implementing OpenSearch in com_finder * Removing opensearch config options from mod_finder * Fixing Opensearch title parameter * Code cleanup * More code cleanup * Fix lanuage strings * Codestyle and fixing language strings
This commit is contained in:
parent
0650916437
commit
1b59d75de1
@ -176,11 +176,23 @@
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="opensearch"
|
||||
type="radio"
|
||||
label="COM_FINDER_CONFIG_OPENSEARCH_LABEL"
|
||||
class="switcher"
|
||||
default="1"
|
||||
>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="opensearch_name"
|
||||
type="text"
|
||||
label="COM_FINDER_CONFIG_FIELD_OPENSEARCH_NAME_LABEL"
|
||||
default=""
|
||||
showon="opensearch:1"
|
||||
/>
|
||||
|
||||
<field
|
||||
@ -190,6 +202,7 @@
|
||||
default=""
|
||||
cols="30"
|
||||
rows="2"
|
||||
showon="opensearch:1"
|
||||
/>
|
||||
|
||||
</fieldset>
|
||||
|
@ -23,6 +23,7 @@ COM_FINDER_CONFIG_LANGUAGE_DEFAULT_NONE="None"
|
||||
COM_FINDER_CONFIG_MEMORY_TABLE_LIMIT_LABEL="Memory Table Limit"
|
||||
COM_FINDER_CONFIG_META_MULTIPLIER_LABEL="Metadata Weight Multiplier"
|
||||
COM_FINDER_CONFIG_MISC_MULTIPLIER_LABEL="Misc. Text Weight Multiplier"
|
||||
COM_FINDER_CONFIG_OPENSEARCH_LABEL="Enable OpenSearch"
|
||||
COM_FINDER_CONFIG_PATH_MULTIPLIER_LABEL="Path Text Weight Multiplier"
|
||||
COM_FINDER_CONFIG_SHOW_ADVANCED_LABEL="Advanced Search"
|
||||
COM_FINDER_CONFIG_SHOW_ADVANCED_TIPS_LABEL="Advanced Tips"
|
||||
|
@ -38,7 +38,28 @@ class SuggestionsController extends BaseController
|
||||
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
|
||||
$app->sendHeaders();
|
||||
echo '{ "suggestions": ' . json_encode($suggestions) . ' }';
|
||||
$app->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to find search query suggestions for OpenSearch
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since __DEPLOY_VERSION__
|
||||
*/
|
||||
public function opensearchsuggest()
|
||||
{
|
||||
$app = $this->app;
|
||||
$app->mimeType = 'application/json';
|
||||
$result = array();
|
||||
$result[] = $app->input->request->get('q', '', 'string');
|
||||
|
||||
$result[] = $this->getSuggestions();
|
||||
|
||||
// Send the response.
|
||||
$app->setHeader('Content-Type', $app->mimeType . '; charset=' . $app->charSet);
|
||||
$app->sendHeaders();
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,8 @@ class FeedView extends BaseHtmlView
|
||||
$state = $this->get('State');
|
||||
$params = $state->get('params');
|
||||
$query = $this->get('Query');
|
||||
$results = $this->get('Results');
|
||||
$results = $this->get('Items');
|
||||
$total = $this->get('Total');
|
||||
|
||||
// Push out the query data.
|
||||
\JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
|
||||
@ -87,17 +88,7 @@ class FeedView extends BaseHtmlView
|
||||
$item->title = $result->title;
|
||||
$item->link = \JRoute::_($result->route);
|
||||
$item->description = $result->description;
|
||||
$item->date = (int) $result->start_date ? \JHtml::_('date', $result->start_date, 'l d F Y') : $result->indexdate;
|
||||
|
||||
// Get the taxonomy data.
|
||||
$taxonomy = $result->getTaxonomy();
|
||||
|
||||
// Add the category to the feed if available.
|
||||
if (isset($taxonomy['Category']))
|
||||
{
|
||||
$node = array_pop($taxonomy['Category']);
|
||||
$item->category = $node->title;
|
||||
}
|
||||
$item->date = date('r', strtotime($result->start_date));
|
||||
|
||||
// Loads item info into RSS array
|
||||
$this->document->addItem($item);
|
||||
|
@ -17,6 +17,10 @@ use Joomla\CMS\Pagination\Pagination;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Profiler\Profiler;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
/**
|
||||
* Search HTML view class for the Finder package.
|
||||
@ -320,6 +324,16 @@ class HtmlView extends BaseHtmlView
|
||||
$this->document->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
// Check for OpenSearch
|
||||
if ($this->params->get('opensearch', 1))
|
||||
{
|
||||
$ostitle = $this->params->get('opensearch_name', Text::_('COM_FINDER_OPENSEARCH_NAME') . ' ' . Factory::getApplication()->get('sitename'));
|
||||
Factory::getDocument()->addHeadLink(
|
||||
Uri::getInstance()->toString(array('scheme', 'host', 'port')) . Route::_('index.php?option=com_finder&view=search&format=opensearch'),
|
||||
'search', 'rel', array('title' => $ostitle, 'type' => 'application/opensearchdescription+xml')
|
||||
);
|
||||
}
|
||||
|
||||
// Add feed link to the document head.
|
||||
if ($this->params->get('show_feed_link', 1) == 1)
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ namespace Joomla\Component\Finder\Site\View\Search;
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Document\Opensearch\OpensearchUrl;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\View\AbstractView;
|
||||
|
||||
/**
|
||||
@ -31,27 +33,55 @@ class OpensearchView extends AbstractView
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$doc = \JFactory::getDocument();
|
||||
$app = \JFactory::getApplication();
|
||||
$doc = Factory::getDocument();
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$params = ComponentHelper::getParams('com_finder');
|
||||
$doc->setShortName($params->get('opensearch_name', $app->get('sitename')));
|
||||
$doc->setDescription($params->get('opensearch_description', $app->get('MetaDesc')));
|
||||
|
||||
// Add the URL for the search
|
||||
$searchUri = \JUri::base() . 'index.php?option=com_finder&q={searchTerms}';
|
||||
|
||||
// Find the menu item for the search
|
||||
$menu = $app->getMenu();
|
||||
$items = $menu->getItems('link', 'index.php?option=com_finder&view=search');
|
||||
|
||||
if (isset($items[0]))
|
||||
// Prevent any output when OpenSearch Support is disabled
|
||||
if (!$params->get('opensearch', 1))
|
||||
{
|
||||
$searchUri .= '&Itemid=' . $items[0]->id;
|
||||
return;
|
||||
}
|
||||
|
||||
$htmlSearch = new \JOpenSearchUrl;
|
||||
$htmlSearch->template = \JRoute::_($searchUri);
|
||||
// Add the URL for the search
|
||||
$searchUri = 'index.php?option=com_finder&view=search&q={searchTerms}';
|
||||
$suggestionsUri = 'index.php?option=com_finder&task=suggestions.opensearchsuggest&format=json&q={searchTerms}';
|
||||
$baseUrl = \JUri::getInstance()->toString(array('host', 'port', 'scheme'));
|
||||
$active = $app->getMenu()->getActive();
|
||||
|
||||
if ($active->component == 'com_finder')
|
||||
{
|
||||
$searchUri .= '&Itemid=' . $active->id;
|
||||
$suggestionsUri .= '&Itemid=' . $active->id;
|
||||
}
|
||||
|
||||
// Add the HTML result view
|
||||
$htmlSearch = new OpenSearchUrl;
|
||||
$htmlSearch->template = $baseUrl . \JRoute::_($searchUri, false);
|
||||
$doc->addUrl($htmlSearch);
|
||||
|
||||
// Add the RSS result view
|
||||
$htmlSearch = new OpenSearchUrl;
|
||||
$htmlSearch->template = $baseUrl . \JRoute::_($searchUri . '&format=feed&type=rss', false);
|
||||
$htmlSearch->type = 'application/rss+xml';
|
||||
$doc->addUrl($htmlSearch);
|
||||
|
||||
// Add the Atom result view
|
||||
$htmlSearch = new OpenSearchUrl;
|
||||
$htmlSearch->template = $baseUrl . \JRoute::_($searchUri . '&format=feed&type=atom', false);
|
||||
$htmlSearch->type = 'application/atom+xml';
|
||||
$doc->addUrl($htmlSearch);
|
||||
|
||||
// Add suggestions URL
|
||||
if ($params->get('show_autosuggest', 1))
|
||||
{
|
||||
$htmlSearch = new OpenSearchUrl;
|
||||
$htmlSearch->template = $baseUrl . \JRoute::_($suggestionsUri, false);
|
||||
$htmlSearch->type = 'application/x-suggestions+json';
|
||||
$doc->addUrl($htmlSearch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ COM_FINDER_FILTER_DATE2_DESC="Enter a date in YYYY-MM-DD format."
|
||||
COM_FINDER_FILTER_SELECT_ALL_LABEL="Search All"
|
||||
COM_FINDER_FILTER_WHEN_AFTER="After"
|
||||
COM_FINDER_FILTER_WHEN_BEFORE="Before"
|
||||
COM_FINDER_OPENSEARCH_NAME="Search"
|
||||
COM_FINDER_QUERY_DATE_CONDITION_AFTER="after"
|
||||
COM_FINDER_QUERY_DATE_CONDITION_BEFORE="before"
|
||||
COM_FINDER_QUERY_DATE_CONDITION_EXACT="exactly on"
|
||||
|
@ -21,8 +21,8 @@ MOD_FINDER_FIELDSET_BASIC_AUTOSUGGEST_LABEL="Search Suggestions"
|
||||
MOD_FINDER_FIELDSET_BASIC_SEARCHFILTER_LABEL="Search Filter"
|
||||
MOD_FINDER_FIELDSET_BASIC_SHOW_ADVANCED_LABEL="Advanced Search"
|
||||
MOD_FINDER_FIELDSET_BASIC_SHOW_ADVANCED_OPTION_LINK="Link to Component"
|
||||
MOD_FINDER_FIELD_OPENSEARCH_LABEL="OpenSearch Autodiscovery"
|
||||
MOD_FINDER_FIELD_OPENSEARCH_TEXT_LABEL="OpenSearch title"
|
||||
MOD_FINDER_FIELD_OPENSEARCH_LABEL="Enable OpenSearch"
|
||||
MOD_FINDER_FIELD_OPENSEARCH_TEXT_LABEL="OpenSearch Name"
|
||||
MOD_FINDER_SEARCHBUTTON_TEXT="Search"
|
||||
MOD_FINDER_SEARCH_BUTTON="Go"
|
||||
MOD_FINDER_SEARCH_VALUE="Search ..."
|
||||
|
@ -135,7 +135,7 @@ class OpensearchDocument extends Document
|
||||
$osns = 'http://a9.com/-/spec/opensearch/1.1/';
|
||||
|
||||
// Create the root element
|
||||
$elOs = $xml->createElementNs($osns, 'OpensearchDescription');
|
||||
$elOs = $xml->createElementNs($osns, 'OpenSearchDescription');
|
||||
|
||||
$elShortName = $xml->createElementNs($osns, 'ShortName');
|
||||
$elShortName->appendChild($xml->createTextNode(htmlspecialchars($this->_shortName)));
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Helper\ModuleHelper;
|
||||
use Joomla\Module\Finder\Site\Helper\FinderHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
@ -26,17 +27,17 @@ if (!defined('FINDER_PATH_INDEXER'))
|
||||
|
||||
JLoader::register('FinderIndexerQuery', FINDER_PATH_INDEXER . '/query.php');
|
||||
|
||||
$cparams = ComponentHelper::getParams('com_finder');
|
||||
|
||||
// Check for OpenSearch
|
||||
if ($params->get('opensearch', 1))
|
||||
if ($params->get('opensearch', $cparams->get('opensearch', 1)))
|
||||
{
|
||||
/*
|
||||
This code intentionally commented
|
||||
$ostitle = $params->get('opensearch_title', Text::_('MOD_FINDER_SEARCHBUTTON_TEXT') . ' ' . Factory::getApplication()->get('sitename'));
|
||||
$defaultTitle = Text::_('MOD_FINDER_OPENSEARCH_NAME') . ' ' . Factory::getApplication()->get('sitename');
|
||||
$ostitle = $params->get('opensearch_name', $cparams->get('opensearch_name', $defaultTitle));
|
||||
Factory::getDocument()->addHeadLink(
|
||||
Uri::getInstance()->toString(array('scheme', 'host', 'port')) . Route::_('&option=com_finder&format=opensearch'),
|
||||
Uri::getInstance()->toString(array('scheme', 'host', 'port')) . Route::_('index.php?option=com_finder&view=search&format=opensearch'),
|
||||
'search', 'rel', array('title' => $ostitle, 'type' => 'application/opensearchdescription+xml')
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
// Get the route.
|
||||
|
@ -90,13 +90,14 @@
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
|
||||
|
||||
<field
|
||||
name="opensearch_title"
|
||||
name="opensearch_name"
|
||||
type="text"
|
||||
label="MOD_FINDER_FIELD_OPENSEARCH_TEXT_LABEL"
|
||||
showon="opensearch:1"
|
||||
/>
|
||||
|
||||
|
||||
<field
|
||||
name="set_itemid"
|
||||
type="menuitem"
|
||||
|
Loading…
Reference in New Issue
Block a user