Source for file opensearch.php
Documentation is available at opensearch.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* OpenSearch class, provides an easy interface to display an OpenSearch document
* @package Joomla.Platform
* @see http://www.opensearch.org/
private $_shortName =
"";
private $_images =
array();
private $_urls =
array();
* @param array $options Associative array of options
$this->_type =
'opensearch';
$this->_mime =
'application/opensearchdescription+xml';
// Add the URL for self updating
$update->type =
'application/opensearchdescription+xml';
// Add the favicon as the default image
// Try to find a favicon by checking the template and root folder
$favicon->data =
JUri::base() .
$path .
'/favicon.ico';
$favicon->type =
'image/vnd.microsoft.icon';
* @param boolean $cache If true, cache the output
* @param array $params Associative array of attributes
* @return The rendered data
public function render($cache =
false, $params =
array())
$xml =
new DOMDocument('1.0', 'utf-8');
$xml->formatOutput =
true;
// The OpenSearch Namespace
$osns =
'http://a9.com/-/spec/opensearch/1.1/';
// Create the root element
$elOs =
$xml->createElementNS($osns, 'OpenSearchDescription');
$elShortName =
$xml->createElementNS($osns, 'ShortName');
$elShortName->appendChild($xml->createTextNode(htmlspecialchars($this->_shortName)));
$elOs->appendChild($elShortName);
$elDescription =
$xml->createElementNS($osns, 'Description');
$elOs->appendChild($elDescription);
// Always set the accepted input encoding to UTF-8
$elInputEncoding =
$xml->createElementNS($osns, 'InputEncoding');
$elInputEncoding->appendChild($xml->createTextNode('UTF-8'));
$elOs->appendChild($elInputEncoding);
foreach ($this->_images as $image)
$elImage =
$xml->createElementNS($osns, 'Image');
$elImage->setAttribute('type', $image->type);
$elImage->setAttribute('width', $image->width);
$elImage->setAttribute('height', $image->height);
$elOs->appendChild($elImage);
foreach ($this->_urls as $url)
$elUrl =
$xml->createElementNS($osns, 'Url');
$elUrl->setAttribute('type', $url->type);
// Results is the default value so we don't need to add it
if ($url->rel !=
'results')
$elUrl->setAttribute('rel', $url->rel);
$elUrl->setAttribute('template', $url->template);
$elOs->appendChild($elUrl);
$xml->appendChild($elOs);
* @param string $name The name.
* @return JDocumentOpensearch instance of $this to allow chaining
$this->_shortName =
$name;
* Adds an URL to the OpenSearch description.
* @param JOpenSearchUrl $url The url to add to the description.
* @return JDocumentOpensearch instance of $this to allow chaining
public function addUrl(JOpenSearchUrl $url)
* Adds an image to the OpenSearch description.
* @param JOpenSearchImage $image The image to add to the description.
* @return JDocumentOpensearch instance of $this to allow chaining
public function addImage(JOpenSearchImage $image)
$this->_images[] =
$image;
* JOpenSearchUrl is an internal class that stores the search URLs for the OpenSearch description
* @package Joomla.Platform
public $type =
'text/html';
* Template item element. Has to contain the {searchTerms} parameter to work.
* JOpenSearchImage is an internal class that stores Images for the OpenSearch Description
* @package Joomla.Platform
* URL of the image or the image as base64 encoded value
Documentation generated on Tue, 19 Nov 2013 15:09:48 +0100 by phpDocumentor 1.4.3