/** * Class constructor * * @param array $options Associative array of options * * @since 11.1 */ public function __construct($options = array()) { parent::__construct($options); // Set document type $this->_type = 'opensearch'; // Set mime type $this->_mime = 'application/opensearchdescription+xml'; // Add the URL for self updating $update = new Opensearch\Url(); $update->type = 'application/opensearchdescription+xml'; $update->rel = 'self'; $update->template = Route::_(Uri::getInstance()); $this->addUrl($update); // Add the favicon as the default image // Try to find a favicon by checking the template and root folder $app = Factory::getApplication(); $dirs = array(JPATH_THEMES . '/' . $app->getTemplate(), JPATH_BASE); foreach ($dirs as $dir) { if (file_exists($dir . '/favicon.ico')) { $path = str_replace(JPATH_BASE . '/', '', $dir); $path = str_replace('\\', '/', $path); $favicon = new Opensearch\Image(); $favicon->data = Uri::base() . $path . '/favicon.ico'; $favicon->height = '16'; $favicon->width = '16'; $favicon->type = 'image/vnd.microsoft.icon'; $this->addImage($favicon); break; } } }
/** * Translates an internal Joomla URL to a humanly readible URL. * * @param string $url Absolute or Relative URI to Joomla resource. * @param boolean $xhtml Replace & by & for XML compilance. * @param integer $ssl Secure state for the resolved URI. * 1: Make URI secure using global secure site URI. * 2: Make URI unsecure using the global unsecure site URI. * * @return The translated humanly readible URL. * * @since 11.1 */ public static function _($url, $xhtml = true, $ssl = null) { if (!self::$_router) { // Get the router. self::$_router = Factory::getApplication()->getRouter(); // Make sure that we have our router if (!self::$_router) { return null; } } if (strpos($url, '&') !== 0 && strpos($url, 'index.php') !== 0) { return $url; } // Build route. $uri = self::$_router->build($url); $url = $uri->toString(array('path', 'query', 'fragment')); // Replace spaces. $url = preg_replace('/\\s/u', '%20', $url); /* * Get the secure/unsecure URLs. * * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over * https and need to set our secure URL to the current request URL, if not, and the scheme is * 'http', then we need to do a quick string manipulation to switch schemes. */ if ((int) $ssl) { $uri = Uri::getInstance(); // Get additional parts. static $prefix; if (!$prefix) { $prefix = $uri->toString(array('host', 'port')); } // Determine which scheme we want. $scheme = (int) $ssl === 1 ? 'https' : 'http'; // Make sure our URL path begins with a slash. if (!preg_match('#^/#', $url)) { $url = '/' . $url; } // Build the URL. $url = $scheme . '://' . $prefix . $url; } if ($xhtml) { $url = htmlspecialchars($url); } return $url; }
/** * Method to load the system URI strings for the application. * * @param string $requestUri An optional request URI to use instead of detecting one from the * server environment variables. * * @return void * * @since 11.3 */ protected function loadSystemUris($requestUri = null) { // Set the request URI. // @codeCoverageIgnoreStart if (!empty($requestUri)) { $this->set('uri.request', $requestUri); } else { $this->set('uri.request', $this->detectRequestUri()); } // @codeCoverageIgnoreEnd // Check to see if an explicit base URI has been set. $siteUri = trim($this->get('site_uri')); if ($siteUri != '') { $uri = Uri::getInstance($siteUri); } else { // Start with the requested URI. $uri = Uri::getInstance($this->get('uri.request')); // If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF. if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) { // We aren't expecting PATH_INFO within PHP_SELF so this should work. $uri->setPath(rtrim(dirname($_SERVER['PHP_SELF']), '/\\')); } else { $uri->setPath(rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\')); } // Clear the unused parts of the requested URI. $uri->setQuery(null); $uri->setFragment(null); } // Get the host and path from the URI. $host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $path = rtrim($uri->toString(array('path')), '/\\'); // Check if the path includes "index.php". if (strpos($path, 'index.php') !== false) { // Remove the index.php portion of the path. $path = substr_replace($path, '', strpos($path, 'index.php'), 9); $path = rtrim($path, '/\\'); } // Set the base URI both as just a path and as the full URI. $this->set('uri.base.full', $host . $path . '/'); $this->set('uri.base.host', $host); $this->set('uri.base.path', $path . '/'); // Set the extended (non-base) part of the request URI as the route. $this->set('uri.route', substr_replace($this->get('uri.request'), '', 0, strlen($this->get('uri.base.full')))); // Get an explicitly set media URI is present. $mediaURI = trim($this->get('media_uri')); if ($mediaURI) { if (strpos($mediaURI, '://') !== false) { $this->set('uri.media.full', $mediaURI); $this->set('uri.media.path', $mediaURI); } else { // Normalise slashes. $mediaURI = trim($mediaURI, '/\\'); $mediaURI = !empty($mediaURI) ? '/' . $mediaURI . '/' : '/'; $this->set('uri.media.full', $this->get('uri.base.host') . $mediaURI); $this->set('uri.media.path', $mediaURI); } } else { $this->set('uri.media.full', $this->get('uri.base.full') . 'media/'); $this->set('uri.media.path', $this->get('uri.base.path') . 'media/'); } }
/** * Return a reference to the {@link JURI} object * * @param string $uri Uri name. * * @return Uri object * * @see JURI * @since 11.1 * @deprecated 13.3 Use JURI directly. */ public static function getURI($uri = 'SERVER') { Log::add(__METHOD__ . ' is deprecated. Use JURI directly.', Log::WARNING, 'deprecated'); return Uri::getInstance($uri); }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * * @return mixed The filtered value. * * @since 1.0 */ protected function filterField($element, $value) { // Make sure there is a valid SimpleXMLElement. if (!$element instanceof \SimpleXMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); $value = ArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $filterInput = new Filter\InputFilter(null, null, 1, 1); $return = $filterInput->clean($value, 'string'); break; // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See Rule\Url for list of these. // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See Rule\Url for list of these. case 'URL': if (empty($value)) { return false; } $filterInput = new Filter\InputFilter(); $value = $filterInput->clean($value, 'html'); $value = trim($value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http://. if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (substr($value, 0) == 'index.php') { $value = Uri::root() . $value; } // Otherwise we treat it is an external link. // Put the url back together. $value = $protocol . '://' . $value; } elseif (!$protocol && $element['relative']) { $host = Uri::getInstance('SERVER')->gethost(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) == $host) { $value = 'http://' . $value; } else { $value = Uri::root() . $value; } } $return = $value; break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // If it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $filterInput = new Filter\InputFilter(); $return = $filterInput->clean($value, $filter); } break; } return $return; }
/** * Render the feed. * * @param string $name The name of the element to render * @param array $params Array of values * @param string $content Override the output of the renderer * * @return string The output of the script * * @see JDocumentRenderer::render() * @since 11.1 */ public function render($name = '', $params = null, $content = null) { $app = Factory::getApplication(); // Gets and sets timezone offset from site configuration $tz = new DateTimeZone($app->getCfg('offset')); $now = Factory::getDate(); $now->setTimeZone($tz); $data = $this->_doc; $uri = Uri::getInstance(); $url = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port')); $syndicationURL = Route::_('&format=feed&type=rss'); if ($app->getCfg('sitename_pagetitles', 0) == 1) { $title = Text::sprintf('JPAGETITLE', $app->getCfg('sitename'), $data->title); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $title = Text::sprintf('JPAGETITLE', $data->title, $app->getCfg('sitename')); } else { $title = $data->title; } $feed_title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8'); $feed = "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; $feed .= "\t<channel>\n"; $feed .= "\t\t<title>" . $feed_title . "</title>\n"; $feed .= "\t\t<description><![CDATA[" . $data->description . "]]></description>\n"; $feed .= "\t\t<link>" . str_replace(' ', '%20', $url . $data->link) . "</link>\n"; $feed .= "\t\t<lastBuildDate>" . htmlspecialchars($now->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</lastBuildDate>\n"; $feed .= "\t\t<generator>" . $data->getGenerator() . "</generator>\n"; $feed .= ' <atom:link rel="self" type="application/rss+xml" href="' . str_replace(' ', '%20', $url . $syndicationURL) . "\"/>\n"; if ($data->image != null) { $feed .= "\t\t<image>\n"; $feed .= "\t\t\t<url>" . $data->image->url . "</url>\n"; $feed .= "\t\t\t<title>" . htmlspecialchars($data->image->title, ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= "\t\t\t<link>" . str_replace(' ', '%20', $data->image->link) . "</link>\n"; if ($data->image->width != "") { $feed .= "\t\t\t<width>" . $data->image->width . "</width>\n"; } if ($data->image->height != "") { $feed .= "\t\t\t<height>" . $data->image->height . "</height>\n"; } if ($data->image->description != "") { $feed .= "\t\t\t<description><![CDATA[" . $data->image->description . "]]></description>\n"; } $feed .= "\t\t</image>\n"; } if ($data->language != "") { $feed .= "\t\t<language>" . $data->language . "</language>\n"; } if ($data->copyright != "") { $feed .= "\t\t<copyright>" . htmlspecialchars($data->copyright, ENT_COMPAT, 'UTF-8') . "</copyright>\n"; } if ($data->editorEmail != "") { $feed .= "\t\t<managingEditor>" . htmlspecialchars($data->editorEmail, ENT_COMPAT, 'UTF-8') . ' (' . htmlspecialchars($data->editor, ENT_COMPAT, 'UTF-8') . ")</managingEditor>\n"; } if ($data->webmaster != "") { $feed .= "\t\t<webMaster>" . htmlspecialchars($data->webmaster, ENT_COMPAT, 'UTF-8') . "</webMaster>\n"; } if ($data->pubDate != "") { $pubDate = JFactory::getDate($data->pubDate); $pubDate->setTimeZone($tz); $feed .= "\t\t<pubDate>" . htmlspecialchars($pubDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n"; } if (empty($data->category) === false) { if (is_array($data->category)) { foreach ($data->category as $cat) { $feed .= "\t\t<category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } else { $feed .= "\t\t<category>" . htmlspecialchars($data->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } if ($data->docs != "") { $feed .= "\t\t<docs>" . htmlspecialchars($data->docs, ENT_COMPAT, 'UTF-8') . "</docs>\n"; } if ($data->ttl != "") { $feed .= "\t\t<ttl>" . htmlspecialchars($data->ttl, ENT_COMPAT, 'UTF-8') . "</ttl>\n"; } if ($data->rating != "") { $feed .= "\t\t<rating>" . htmlspecialchars($data->rating, ENT_COMPAT, 'UTF-8') . "</rating>\n"; } if ($data->skipHours != "") { $feed .= "\t\t<skipHours>" . htmlspecialchars($data->skipHours, ENT_COMPAT, 'UTF-8') . "</skipHours>\n"; } if ($data->skipDays != "") { $feed .= "\t\t<skipDays>" . htmlspecialchars($data->skipDays, ENT_COMPAT, 'UTF-8') . "</skipDays>\n"; } for ($i = 0, $count = count($data->items); $i < $count; $i++) { if (strpos($data->items[$i]->link, 'http://') === false && strpos($data->items[$i]->link, 'https://') === false) { $data->items[$i]->link = str_replace(' ', '%20', $url . $data->items[$i]->link); } $feed .= "\t\t<item>\n"; $feed .= "\t\t\t<title>" . htmlspecialchars(strip_tags($data->items[$i]->title), ENT_COMPAT, 'UTF-8') . "</title>\n"; $feed .= "\t\t\t<link>" . str_replace(' ', '%20', $data->items[$i]->link) . "</link>\n"; if (empty($data->items[$i]->guid) === true) { $feed .= "\t\t\t<guid isPermaLink=\"true\">" . str_replace(' ', '%20', $data->items[$i]->link) . "</guid>\n"; } else { $feed .= "\t\t\t<guid isPermaLink=\"false\">" . htmlspecialchars($data->items[$i]->guid, ENT_COMPAT, 'UTF-8') . "</guid>\n"; } $feed .= "\t\t\t<description><![CDATA[" . $this->_relToAbs($data->items[$i]->description) . "]]></description>\n"; if ($data->items[$i]->authorEmail != "") { $feed .= "\t\t\t<author>" . htmlspecialchars($data->items[$i]->authorEmail . ' (' . $data->items[$i]->author . ')', ENT_COMPAT, 'UTF-8') . "</author>\n"; } /* * @todo: On hold * if ($data->items[$i]->source!="") { * $data.= " <source>".htmlspecialchars($data->items[$i]->source, ENT_COMPAT, 'UTF-8')."</source>\n"; * } */ if (empty($data->items[$i]->category) === false) { if (is_array($data->items[$i]->category)) { foreach ($data->items[$i]->category as $cat) { $feed .= "\t\t\t<category>" . htmlspecialchars($cat, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } else { $feed .= "\t\t\t<category>" . htmlspecialchars($data->items[$i]->category, ENT_COMPAT, 'UTF-8') . "</category>\n"; } } if ($data->items[$i]->comments != "") { $feed .= "\t\t\t<comments>" . htmlspecialchars($data->items[$i]->comments, ENT_COMPAT, 'UTF-8') . "</comments>\n"; } if ($data->items[$i]->date != "") { $itemDate = Factory::getDate($data->items[$i]->date); $itemDate->setTimeZone($tz); $feed .= "\t\t\t<pubDate>" . htmlspecialchars($itemDate->toRFC822(true), ENT_COMPAT, 'UTF-8') . "</pubDate>\n"; } if ($data->items[$i]->enclosure != null) { $feed .= "\t\t\t<enclosure url=\""; $feed .= $data->items[$i]->enclosure->url; $feed .= "\" length=\""; $feed .= $data->items[$i]->enclosure->length; $feed .= "\" type=\""; $feed .= $data->items[$i]->enclosure->type; $feed .= "\"/>\n"; } $feed .= "\t\t</item>\n"; } $feed .= "\t</channel>\n"; $feed .= "</rss>\n"; return $feed; }