Back to OpensearchDocument class

Method render

public string
render
(mixed $cache = false, mixed $params = array())
Render the document
Parameters
  • bool $cache If true, cache the output
  • array $params Associative array of attributes
Returns
  • string The rendered data
Since
  • 1.7.0

Method render - Source code

/**
 * Render the document
 *
 * @param   boolean  $cache   If true, cache the output
 * @param   array    $params  Associative array of attributes
 *
 * @return  string  The rendered data
 *
 * @since   1.7.0
 */
public function render($cache = false, $params = array())
{
    $xml = new \DOMDocument('1.0', 'utf-8');
    if (\defined('JDEBUG') && JDEBUG) {
        $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');
    $elDescription->appendChild($xml->createTextNode(htmlspecialchars($this->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);
        $elImage->appendChild($xml->createTextNode(htmlspecialchars($image->data)));
        $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);
    parent::render($cache, $params);
    return $xml->saveXML();
}