CoreFiles by mySites.guru
OpensearchView.php89 lines, 3,067 bytes, from Joomla_4.2.2-Stable-Full_Package.zip
Raw History Compare with 4.2.1
md5
09e6fd62363e8ca67713cfc7fcdb96d1
sha1
ec64d67e805ebb0234f62d3d1c9a2c8406630740
sha256
5d412d6837d7d3dc68cf9cc2c507d6c89982ab3509c8055ea32ffc0efeb1b7a3
<?php

/**
 * @package     Joomla.Site
 * @subpackage  com_finder
 *
 * @copyright   (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Finder\Site\View\Search;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Document\Opensearch\OpensearchUrl;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * OpenSearch View class for Finder
 *
 * @since  2.5
 */
class OpensearchView extends AbstractView
{
    /**
     * Method to display the view.
     *
     * @param   string  $tpl  A template file to load. [optional]
     *
     * @return  void
     *
     * @since   2.5
     */
    public function display($tpl = null)
    {
        $app = Factory::getApplication();

        $params = ComponentHelper::getParams('com_finder');
        $this->document->setShortName($params->get('opensearch_name', $app->get('sitename', '')));
        $this->document->setDescription($params->get('opensearch_description', $app->get('MetaDesc', '')));

        // Prevent any output when OpenSearch Support is disabled
        if (!$params->get('opensearch', 1)) {
            return;
        }

        // 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 = Uri::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 . Route::_($searchUri, false);
        $this->document->addUrl($htmlSearch);

        // Add the RSS result view
        $htmlSearch           = new OpensearchUrl();
        $htmlSearch->template = $baseUrl . Route::_($searchUri . '&format=feed&type=rss', false);
        $htmlSearch->type     = 'application/rss+xml';
        $this->document->addUrl($htmlSearch);

        // Add the Atom result view
        $htmlSearch           = new OpensearchUrl();
        $htmlSearch->template = $baseUrl . Route::_($searchUri . '&format=feed&type=atom', false);
        $htmlSearch->type     = 'application/atom+xml';
        $this->document->addUrl($htmlSearch);

        // Add suggestions URL
        if ($params->get('show_autosuggest', 1)) {
            $htmlSearch           = new OpensearchUrl();
            $htmlSearch->template = $baseUrl . Route::_($suggestionsUri, false);
            $htmlSearch->type     = 'application/x-suggestions+json';
            $this->document->addUrl($htmlSearch);
        }
    }
}

The same content is in 10 releases, Joomla 4.2.2 to 4.3.0-alpha2. See them all, or every version of this file.