public function compile() { $doc = JFactory::getDocument(); $headers = $doc->getHeadData(); $javascripts = JArrayHelper::getValue($headers, 'scripts'); $dest = JPath::clean($this->paths->get('js.compressed')); $compile = $this->params->get('minify_js', 1); $changed = (bool) $this->isJsUpdated(); JLog::add('Javascript cache changed: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger); $force = (bool) ($compile == 2); $changed = (bool) ($compile == 1 && $changed); JLog::add('Force Javascript minification: ' . ((bool) $force ? 'true' : 'false'), JLog::DEBUG, $this->logger); JLog::add('Minify Javascript: ' . ((bool) $changed ? 'true' : 'false'), JLog::DEBUG, $this->logger); $uncompressed = ''; foreach (array_keys($javascripts) as $script) { $url = new JUri($script); if (!$url->getScheme()) { $url = new JUri(JUri::base()); $url->setPath($script); } $key = str_replace(JUri::base(), JPATH_ROOT . '/', (string) $url); if (array_search($key, $this->paths->get('js.uncompressed')) !== false) { unset($headers['scripts'][$script]); if (!JFile::exists($dest) || $changed || $force) { JLog::add('Compressing: ' . $key . ' to ' . $dest, JLog::DEBUG, $this->logger); $stream = new JStream(); $stream->open($key); $response = $stream->read($stream->filesize()); $stream->close(); $uncompressed .= $response; } } } if ($uncompressed) { file_put_contents($dest, JSMinPlus::minify($uncompressed, $dest)); $this->updateCache(self::CACHEKEY . '.files.js', $this->paths->get('js.uncompressed')); } // workaround. There needs to be at least one script. if (count($headers['scripts']) == 0) { $url = str_replace(JPATH_ROOT . '/', JUri::base(), $dest); $headers['scripts'][$url] = array('mime' => 'text/javascript', 'defer' => false, 'async' => false); } $doc->setHeadData($headers); }
/** * Function to convert a route to an internal URI * * @param JUri $uri The uri. * * @return array */ public function parse($uri) { $vars = array(); // Get the application $app = JApplication::getInstance('site'); if ($app->getCfg('force_ssl') == 2 && strtolower($uri->getScheme()) != 'https') { // Forward to https $uri->setScheme('https'); $app->redirect((string) $uri); } // Get the path // Decode URL to convert punycode to unicode so that strings match when routing. $path = urldecode($uri->getPath()); // Remove the base URI path. $path = substr_replace($path, '', 0, strlen(JUri::base(true))); // Check to see if a request to a specific entry point has been made. if (preg_match("#.*?\\.php#u", $path, $matches)) { // Get the current entry point path relative to the site path. $scriptPath = realpath($_SERVER['SCRIPT_FILENAME'] ? $_SERVER['SCRIPT_FILENAME'] : str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED'])); $relativeScriptPath = str_replace('\\', '/', str_replace(JPATH_SITE, '', $scriptPath)); // If a php file has been found in the request path, check to see if it is a valid file. // Also verify that it represents the same file from the server variable for entry script. if (file_exists(JPATH_SITE . $matches[0]) && $matches[0] == $relativeScriptPath) { // Remove the entry point segments from the request path for proper routing. $path = str_replace($matches[0], '', $path); } } // Identify format if ($this->_mode == JROUTER_MODE_SEF) { if ($app->getCfg('sef_suffix') && !(substr($path, -9) == 'index.php' || substr($path, -1) == '/')) { if ($suffix = pathinfo($path, PATHINFO_EXTENSION)) { $vars['format'] = $suffix; } } } // Set the route $uri->setPath(trim($path, '/')); $vars += parent::parse($uri); return $vars; }
/** * Method to connect to a server and get the resource. * * @param JUri $uri The URI to connect with. * @param integer $timeout Read timeout in seconds. * * @return resource Socket connection resource. * * @since 11.3 * @throws RuntimeException */ protected function connect(JUri $uri, $timeout = null) { $errno = null; $err = null; // Get the host from the uri. $host = $uri->isSsl() ? 'ssl://' . $uri->getHost() : $uri->getHost(); // If the port is not explicitly set in the URI detect it. if (!$uri->getPort()) { $port = $uri->getScheme() == 'https' ? 443 : 80; } else { $port = $uri->getPort(); } // Build the connection key for resource memory caching. $key = md5($host . $port); // If the connection already exists, use it. if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) { // Connection reached EOF, cannot be used anymore $meta = stream_get_meta_data($this->connections[$key]); if ($meta['eof']) { if (!fclose($this->connections[$key])) { throw new RuntimeException('Cannot close connection'); } } elseif (!$meta['timed_out']) { return $this->connections[$key]; } } if (!is_numeric($timeout)) { $timeout = ini_get('default_socket_timeout'); } // Capture PHP errors $php_errormsg = ''; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); // PHP sends a warning if the uri does not exists; we silence it and throw an exception instead. // Attempt to connect to the server $connection = @fsockopen($host, $port, $errno, $err, $timeout); if (!$connection) { if (!$php_errormsg) { // Error but nothing from php? Create our own $php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno); } // Restore error tracking to give control to the exception handler ini_set('track_errors', $track_errors); throw new RuntimeException($php_errormsg); } // Restore error tracking to what it was before. ini_set('track_errors', $track_errors); // Since the connection was successful let's store it in case we need to use it later. $this->connections[$key] = $connection; // If an explicit timeout is set, set it. if (isset($timeout)) { stream_set_timeout($this->connections[$key], (int) $timeout); } return $this->connections[$key]; }
/** * Method to connect to a server and get the resource. * * @param JUri $uri The URI to connect with. * * @return mixed Connection resource on success or boolean false on failure. * * @since 11.1 */ protected function _connect(JUri $uri) { // Initialize variables. $errno = null; $err = null; // Get the host from the uri. $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost(); // If the port is not explicitly set in the URI detect it. if (!$uri->getPort()) { $port = $uri->getScheme() == 'https' ? 443 : 80; } else { $port = $uri->getPort(); } // Build the connection key for resource memory caching. $key = md5($host . $port); // If the connection already exists, use it. if (!empty($this->_connections[$key]) && is_resource($this->_connections[$key])) { // Make sure the connection has not timed out. $meta = stream_get_meta_data($this->_connections[$key]); if (!$meta['timed_out']) { return $this->_connections[$key]; } } // Attempt to connect to the server. if ($this->_connections[$key] = fsockopen($host, $port, $errno, $err, $this->_timeout)) { stream_set_timeout($this->_connections[$key], $this->_timeout); } return $this->_connections[$key]; }
/** * Method to connect to a server and get the resource. * * @param JUri $uri The URI to connect with. * @param integer $timeout Read timeout in seconds. * * @return resource Socket connection resource. * * @since 11.3 * @throws RuntimeException */ protected function connect(JUri $uri, $timeout = null) { // Initialize variables. $errno = null; $err = null; // Get the host from the uri. $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost(); // If the port is not explicitly set in the URI detect it. if (!$uri->getPort()) { $port = $uri->getScheme() == 'https' ? 443 : 80; } else { $port = $uri->getPort(); } // Build the connection key for resource memory caching. $key = md5($host . $port); // If the connection already exists, use it. if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) { // Connection reached EOF, cannot be used anymore $meta = stream_get_meta_data($this->connections[$key]); if ($meta['eof']) { if (!fclose($this->connections[$key])) { throw new RuntimeException('Cannot close connection'); } } elseif (!$meta['timed_out']) { return $this->connections[$key]; } } if (!is_numeric($timeout)) { $timeout = ini_get("default_socket_timeout"); } // Attempt to connect to the server. $connection = fsockopen($host, $port, $errno, $err, $timeout); if (!$connection) { throw new RuntimeException($err, $errno); } // Since the connection was successful let's store it in case we need to use it later. $this->connections[$key] = $connection; // If an explicit timeout is set, set it. if (isset($timeout)) { stream_set_timeout($this->connections[$key], (int) $timeout); } return $this->connections[$key]; }
/** * Send a request to the server and return a JHttpResponse object with the response. * * @param string $method The HTTP method for sending the request. * @param JUri $uri The URI to the resource to request. * @param mixed $data Either an associative array or a string to be sent with the request. * @param array $headers An array of request headers to send with the request. * @param integer $timeout Read timeout in seconds. * @param string $userAgent The optional user agent string to send with the request. * * @return JHttpResponse * * @since 11.3 * @throws RuntimeException */ public function request($method, JUri $uri, $data = null, array $headers = null, $timeout = null, $userAgent = null) { // Setup the cURL handle. $ch = curl_init(); $options = array(); // Set the request method. switch (strtoupper($method)) { case 'GET': $options[CURLOPT_HTTPGET] = true; break; case 'POST': $options[CURLOPT_POST] = true; break; case 'PUT': default: $options[CURLOPT_CUSTOMREQUEST] = strtoupper($method); break; } // Don't wait for body when $method is HEAD $options[CURLOPT_NOBODY] = $method === 'HEAD'; // Initialize the certificate store $options[CURLOPT_CAINFO] = $this->options->get('curl.certpath', __DIR__ . '/cacert.pem'); // If data exists let's encode it and make sure our Content-type header is set. if (isset($data)) { // If the data is a scalar value simply add it to the cURL post fields. if (is_scalar($data) || isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'multipart/form-data') === 0) { $options[CURLOPT_POSTFIELDS] = $data; } else { $options[CURLOPT_POSTFIELDS] = http_build_query($data); } if (!isset($headers['Content-Type'])) { $headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'; } // Add the relevant headers. if (is_scalar($options[CURLOPT_POSTFIELDS])) { $headers['Content-Length'] = strlen($options[CURLOPT_POSTFIELDS]); } } // Build the headers string for the request. $headerArray = array(); if (isset($headers)) { foreach ($headers as $key => $value) { $headerArray[] = $key . ': ' . $value; } // Add the headers string into the stream context options array. $options[CURLOPT_HTTPHEADER] = $headerArray; } // Curl needs the accepted encoding header as option if (isset($headers['Accept-Encoding'])) { $options[CURLOPT_ENCODING] = $headers['Accept-Encoding']; } // If an explicit timeout is given user it. if (isset($timeout)) { $options[CURLOPT_TIMEOUT] = (int) $timeout; $options[CURLOPT_CONNECTTIMEOUT] = (int) $timeout; } // If an explicit user agent is given use it. if (isset($userAgent)) { $options[CURLOPT_USERAGENT] = $userAgent; } // Set the request URL. $options[CURLOPT_URL] = (string) $uri; // We want our headers. :-) $options[CURLOPT_HEADER] = true; // Return it... echoing it would be tacky. $options[CURLOPT_RETURNTRANSFER] = true; // Override the Expect header to prevent cURL from confusing itself in its own stupidity. // Link: http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/ $options[CURLOPT_HTTPHEADER][] = 'Expect:'; // Follow redirects if server config allows if ($this->redirectsAllowed()) { $options[CURLOPT_FOLLOWLOCATION] = (bool) $this->options->get('follow_location', true); } // Proxy configuration $config = JFactory::getConfig(); if ($config->get('proxy_enable')) { $options[CURLOPT_PROXY] = $config->get('proxy_host') . ':' . $config->get('proxy_port'); if ($user = $config->get('proxy_user')) { $options[CURLOPT_PROXYUSERPWD] = $user . ':' . $config->get('proxy_pass'); } } // Set any custom transport options foreach ($this->options->get('transport.curl', array()) as $key => $value) { $options[$key] = $value; } // Authentification, if needed if ($this->options->get('userauth') && $this->options->get('passwordauth')) { $options[CURLOPT_USERPWD] = $this->options->get('userauth') . ':' . $this->options->get('passwordauth'); $options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; } // Set the cURL options. curl_setopt_array($ch, $options); // Execute the request and close the connection. $content = curl_exec($ch); // Check if the content is a string. If it is not, it must be an error. if (!is_string($content)) { $message = curl_error($ch); if (empty($message)) { // Error but nothing from cURL? Create our own $message = 'No HTTP response received'; } throw new RuntimeException($message); } // Get the request information. $info = curl_getinfo($ch); // Close the connection. curl_close($ch); $response = $this->getResponse($content, $info); // Manually follow redirects if server doesn't allow to follow location using curl if ($response->code >= 301 && $response->code < 400 && isset($response->headers['Location'])) { $redirect_uri = new JUri($response->headers['Location']); if (in_array($redirect_uri->getScheme(), array('file', 'scp'))) { throw new RuntimeException('Curl redirect cannot be used in file or scp requests.'); } $response = $this->request($method, $redirect_uri, $data, $headers, $timeout, $userAgent); } return $response; }
/** * Find the file we want in oaths. * * @param string $file File name to find. * @param string $type File type, css or js. * @param string $name The instance name. * * @return array|boolean Found file & sum information. */ protected function findFile($file, $type, $name = null) { $name = $name ?: $this->name; $foundpath = ''; $sum = ''; $uri = new \JUri($file); if ($uri->getScheme()) { return $file; } foreach (clone $this->paths as $path) { $path = str_replace(array('{name}', '{type}'), array($name, $type), $path); $path = trim($path, '/'); // Get compressed file if ($foundFile = $this->getMinFile(JPATH_ROOT . '/' . $path, $file)) { $file = $foundFile; $foundpath = $path; break; } $filepath = $path . '/' . $file; if (is_file(JPATH_ROOT . '/' . $filepath)) { $foundpath = $path; break; } } if (!$foundpath) { return false; } $foundpath = str_replace(array('/', '\\'), '/', $foundpath); // Get SUM if (!$this->debug) { $sumfile = JPATH_ROOT . '/' . $foundpath . '/' . $file . '.sum'; if (!is_file($sumfile)) { $sumfile = JPATH_ROOT . '/' . $foundpath . '/' . $this->sumName; } if (is_file($sumfile)) { $sum = file_get_contents($sumfile); } if ($sum) { $sum = str_replace(array("\n", "\r"), '', $sum); $sum = addslashes(htmlentities($sum)); } } else { $sum = null; } // Build path $file = $foundpath . '/' . $file; return array('file' => $file, 'sum' => $sum); }
/** * Test the setScheme method. * * @return void * * @since 11.1 * @covers JUri::setScheme */ public function testSetScheme() { $this->object->setScheme('ftp'); $this->assertThat($this->object->getScheme(), $this->equalTo('ftp')); }
function onAfterInitialise() { /** @var JSite $app */ $app = JFactory::getApplication(); if ($app->isAdmin()) { // don't use MobileJoomla in backend return; } $is_joomla15 = $this->isJoomla15(); //load MobileJoomla class require_once JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/classes/mobilejoomla.php'; //load config $MobileJoomla_Settings =& MobileJoomla::getConfig(); $MobileJoomla_Device =& MobileJoomla::getDevice(); // check for legacy redirect if (@$_GET['option'] == 'com_mobilejoomla' && @$_GET['task'] == 'setmarkup' && isset($_GET['markup']) && isset($_GET['return'])) { $desktop_uri = new JUri($MobileJoomla_Settings['desktop_url']); $uri = new JUri(base64_decode($_GET['return'])); if (!$uri->getScheme()) { $uri->setScheme('http'); } $uri->setHost($desktop_uri->getHost()); $uri->setPort($desktop_uri->getPort()); $app->redirect($uri->toString()); } JPluginHelper::importPlugin('mobile'); $cached_data = $app->getUserState('mobilejoomla.cache'); if ($cached_data !== null) { $cached_data = @gzinflate(@base64_decode($cached_data)); if ($cached_data !== false) { $cached_data = @unserialize($cached_data); } } if (is_array($cached_data)) { $MobileJoomla_Device = $cached_data['device']; } else { $app->triggerEvent('onDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device)); $gzlevel = 5; $cached_data = array('device' => $MobileJoomla_Device); $cached_data = base64_encode(gzdeflate(serialize($cached_data), $gzlevel)); $app->setUserState('mobilejoomla.cache', $cached_data); } $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']); $MobileJoomla_Device['real_markup'] = $MobileJoomla_Device['markup']; $app->triggerEvent('onAfterDeviceDetection', array(&$MobileJoomla_Settings, &$MobileJoomla_Device)); $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']); $markup = $MobileJoomla_Device['markup']; $MobileJoomla_Device['default_markup'] = $markup; //get user choice $user_markup = $this->getUserMarkup(); if ($user_markup !== false) { $markup = $user_markup; } // template preview $getTemplate = isset($_GET['template']) ? $_GET['template'] : null; if (version_compare(JVERSION, '1.7', '>=')) { if ($getTemplate === null && isset($_GET['templateStyle']) && is_int($_GET['templateStyle'])) { $db = JFactory::getDBO(); $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($_GET['templateStyle']) . ' AND client_id = 0'; $db->setQuery($query); $getTemplate = $db->loadResult(); } } elseif (version_compare(JVERSION, '1.6', '>=')) { if (is_int($getTemplate)) { $db = JFactory::getDBO(); $query = 'SELECT template FROM #__template_styles WHERE id = ' . intval($getTemplate) . ' AND client_id = 0'; $db->setQuery($query); $getTemplate = $db->loadResult(); } } if ($getTemplate) { switch ($getTemplate) { case $MobileJoomla_Settings['xhtml.template']: $markup = 'xhtml'; break; case $MobileJoomla_Settings['iphone.template']: $markup = 'iphone'; break; case $MobileJoomla_Settings['wml.template']: $markup = 'wml'; break; case $MobileJoomla_Settings['chtml.template']: $markup = 'chtml'; break; } } $MobileJoomla_Device['markup'] = $markup; if ($MobileJoomla_Device['screenwidth'] == 0 || $MobileJoomla_Device['screenheight'] == 0) { switch ($markup) { case 'wml': $MobileJoomla_Device['screenwidth'] = 64; $MobileJoomla_Device['screenheight'] = 96; break; case 'chtml': $MobileJoomla_Device['screenwidth'] = 120; $MobileJoomla_Device['screenheight'] = 128; break; case 'xhtml': $MobileJoomla_Device['screenwidth'] = 320; $MobileJoomla_Device['screenheight'] = 480; break; case 'iphone': $MobileJoomla_Device['screenwidth'] = 320; $MobileJoomla_Device['screenheight'] = 480; break; } } if ($MobileJoomla_Device['imageformats'] === null) { switch ($markup) { case 'wml': $MobileJoomla_Device['imageformats'] = array('wbmp'); break; case 'chtml': $MobileJoomla_Device['imageformats'] = array('gif'); break; case 'xhtml': case 'iphone': $MobileJoomla_Device['imageformats'] = array('png', 'gif', 'jpg'); break; } } if (count($MobileJoomla_Device['imageformats']) == 0) { $MobileJoomla_Settings['wml.img'] = 1; $MobileJoomla_Settings['chtml.img'] = 1; $MobileJoomla_Settings['xhtml.img'] = 1; $MobileJoomla_Settings['iphone.img'] = 1; } $app->triggerEvent('onBeforeMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device)); $MobileJoomla_Device['markup'] = self::CheckMarkup($MobileJoomla_Device['markup']); $this->updateUserMarkup(); $app->triggerEvent('onMobileMarkupInit', array(&$MobileJoomla_Settings, &$MobileJoomla_Device)); $markup = $MobileJoomla_Device['markup']; if (empty($markup)) { $MobileJoomla_Device['markup'] = false; return; } $MobileJoomla = MobileJoomla::getInstance($markup); // set headers here to be compatible with System-Cache $MobileJoomla->setHeader(); if ($MobileJoomla_Settings['mobile_sitename']) { $this->setConfig('sitename', $MobileJoomla_Settings['mobile_sitename']); } if (!$is_joomla15) { if (!$MobileJoomla_Settings['caching']) { $this->setConfig('caching', 0); } $cachekey = MobileJoomla::getCacheKey(); $registeredurlparams = isset($app->registeredurlparams) ? $app->registeredurlparams : null; if (empty($registeredurlparams)) { $registeredurlparams = new stdClass(); } $this->setRequestVar('mjcachekey', $cachekey); $registeredurlparams->mjcachekey = 'CMD'; $this->setRequestVar('mjurlkey', JRequest::getURI()); $registeredurlparams->mjurlkey = 'STRING'; $app->registeredurlparams = $registeredurlparams; //fix System-Cache plugin in J!3.0 if (JPluginHelper::isEnabled('system', 'cache') && version_compare(JVERSION, '3.0.0', '>=')) { $dispatcher = JEventDispatcher::getInstance(); $refObj = new ReflectionObject($dispatcher); $refProp = $refObj->getProperty('_observers'); $refProp->setAccessible(true); $observers = $refProp->getValue($dispatcher); foreach ($observers as $index => $object) { if (is_a($object, 'plgSystemCache')) { $object->_cache_key = '~' . $cachekey . '~' . $object->_cache_key; } } } } else { if ($MobileJoomla_Settings['caching']) { /** @var JRegistry $config */ $config = JFactory::getConfig(); $handler = $config->getValue('config.cache_handler', 'file'); $handler .= '_mj'; $config->setValue('config.cache_handler', $handler); $class = 'JCacheStorage' . ucfirst($handler); $path = JPATH_ADMINISTRATOR . '/components/com_mobilejoomla/override/cachestorage/' . $handler . '.php'; jimport('joomla.cache.storage'); JLoader::register($class, $path); } else { $this->setConfig('caching', 0); //disable System-Cache plugin $dispatcher = JDispatcher::getInstance(); foreach ($dispatcher->_observers as $index => $object) { if (is_a($object, 'plgSystemCache')) { $object->_cache = new _CacheStub(); unset($dispatcher->_observers[$index]); break; } } } } if (@$_SERVER['REQUEST_METHOD'] != 'POST') { $router = $app->getRouter(); $router->attachBuildRule(array($this, 'buildRule')); } if (!defined('SHMOBILE_MOBILE_TEMPLATE_SWITCHED')) { define('SHMOBILE_MOBILE_TEMPLATE_SWITCHED', 1); } }
/** * Recursively discovers the atom/rss OpenSearch url. * * @param string $sourceUrl The url to discover. * * @return JRegistry A OpenSearch description as a JRegistry or false if no description * can be found. */ private function discover($sourceUrl) { $discovered = false; $url = new JUri($sourceUrl); $http = JHttpFactory::getHttp(); $response = $http->get($url); if ((int) $response->code === 200) { $contentType = JArrayHelper::getValue($response->headers, 'Content-Type'); $contentType = $this->parseContentType($contentType); if ($contentType === 'text/html') { $dom = new DomDocument(); $dom->loadHTML($response->body); $xpath = new DOMXPath($dom); $opendocument = '//html/head/link[@type="application/opensearchdescription+xml"]'; $links = $xpath->query($opendocument); if (count($links)) { $link = $dom->importNode($links->item(0), true); $href = new JUri($link->getAttribute('href')); // sometimes the opensearch url is not complete so complete it. if (!$href->getScheme()) { $url->setQuery(array()); $url->setPath($href); $url->setQuery($href->getQuery()); } $url->setVar('source', $sourceUrl); $discovered = $this->discover((string) $url); } } else { if ($contentType === 'application/opensearchdescription+xml') { $originalUrl = $url->getVar('source'); $xml = new SimpleXMLElement($response->body); if (isset($xml->Url)) { $urls = $xml->Url; $i = 0; while (($url = $urls[$i]) && !$discovered) { $template = JArrayHelper::getValue($url, 'template', null, 'string'); $type = JArrayHelper::getValue($url, 'type', null, 'string'); $link = new JUri($template); $queries = $link->getQuery(true); //@todo a search/replace will probably suffice. foreach ($queries as $keyq => &$valueq) { if ($valueq === "{searchTerms}") { $queries[$keyq] = JUri::getInstance($originalUrl)->getVar($keyq); break; } } $link->setQuery($queries); // don't try and discover the html search. if (strpos($type, 'text/html') === false) { $discovered = $this->discover((string) $link); } $i++; } } } else { if (array_search($contentType, array('application/xml', 'text/xml', 'application/atom+xml', 'application/rss+xml')) !== false) { //@todo JUri not updating url via setVar. May need more testing. $discovered = new JRegistry(); $discovered->set('discovery.type', 'opensearch'); $discovered->set('discovery.url', (string) $sourceUrl); $discovered->set('discovery.plugin.type', (string) $contentType); } } } } return $discovered; }
/** * Method to connect to a server and get the resource. * * @param JUri $uri The URI to connect with. * @param integer $timeout Read timeout in seconds. * * @return resource Socket connection resource. * * @since 11.3 * @throws JMapExceptionRuntime */ protected function connect(JUri $uri, $timeout = null) { // Initialize variables. $errno = null; $err = null; // Get the host from the uri. $host = $uri->isSSL() ? 'ssl://' . $uri->getHost() : $uri->getHost(); // If the port is not explicitly set in the URI detect it. if (!$uri->getPort()) { $port = $uri->getScheme() == 'https' ? 443 : 80; } else { $port = $uri->getPort(); } // Build the connection key for resource memory caching. $key = md5($host . $port); // If the connection already exists, use it. if (!empty($this->connections[$key]) && is_resource($this->connections[$key])) { // Make sure the connection has not timed out. $meta = stream_get_meta_data($this->connections[$key]); if (!$meta['timed_out']) { return $this->connections[$key]; } } // Attempt to connect to the server. $connection = @fsockopen($host, $port, $errno, $err, $timeout); if (!$connection) { throw new JMapExceptionRuntime($err, 'error', $errno); } // Since the connection was successful let's store it in case we need to use it later. $this->connections[$key] = $connection; // If an explicit timeout is set, set it. if (isset($timeout)) { stream_set_timeout($this->connections[$key], (int) $timeout); } return $this->connections[$key]; }