/**
  * 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;
         }
     }
 }
Example #2
0
 /**
  * Method to build and return a full request URL for the request.  This method will
  * add appropriate pagination details if necessary and also prepend the API url
  * to have a complete URL for the request.
  *
  * @param   string   $path    URL to inflect.
  * @param   integer  $limit   The number of objects per page.
  * @param   integer  $offset  The object's number on the page.
  * @param   string   $until   A unix timestamp or any date accepted by strtotime.
  * @param   string   $since   A unix timestamp or any date accepted by strtotime.
  *
  * @return  string  The request URL.
  *
  * @since   1.0
  */
 protected function fetchUrl($path, $limit = 0, $offset = 0, $until = null, $since = null)
 {
     // Get a new Uri object fousing the api url and given path.
     $apiUrl = isset($this->options['api.url']) ? $this->options['api.url'] : null;
     $uri = new Uri($apiUrl . $path);
     if ($limit > 0) {
         $uri->setVar('limit', (int) $limit);
     }
     if ($offset > 0) {
         $uri->setVar('offset', (int) $offset);
     }
     if ($until != null) {
         $uri->setVar('until', $until);
     }
     if ($since != null) {
         $uri->setVar('since', $since);
     }
     return (string) $uri;
 }
 /**
  * Build by resource.
  *
  * @param   string   $resource The resource key to find our route.
  * @param   array    $data     The url query data.
  * @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  string Route url.
  */
 public static function _($resource, $data = array(), $xhtml = true, $ssl = null)
 {
     // Replace all '.' and ':' to '@' to make it B/C
     $resource = str_replace(array('.', ':'), '@', $resource);
     if (static::$defaultOption && strpos($resource, '@') === false) {
         $resource = static::$defaultOption . '@' . $resource;
     }
     $resource = explode('@', $resource, 2);
     if (count($resource) == 2) {
         $data['option'] = $resource[0];
         $data['_resource'] = $resource[1];
     } elseif (count($resource) == 1) {
         $data['option'] = $resource[0];
         $data['_resource'] = null;
     }
     $url = new Uri();
     $url->setQuery($data);
     $url->setPath('index.php');
     return static::jroute((string) $url, $xhtml, $ssl);
 }
 /**
  * Method to build and return a full request URL for the request.  This method will
  * add appropriate pagination details if necessary and also prepend the API url
  * to have a complete URL for the request.
  *
  * @param   string   $path   URL to inflect
  * @param   integer  $page   Page to request
  * @param   integer  $limit  Number of results to return per page
  *
  * @return  string   The request URL.
  *
  * @since   11.3
  */
 protected function fetchUrl($path, $page = 0, $limit = 0)
 {
     // Get a new JUri object fousing the api url and given path.
     $uri = new Uri($this->options->get('api.url') . $path);
     if ($this->options->get('api.username', false)) {
         $uri->setUser($this->options->get('api.username'));
     }
     if ($this->options->get('api.password', false)) {
         $uri->setPass($this->options->get('api.password'));
     }
     // If we have a defined page number add it to the JUri object.
     if ($page > 0) {
         $uri->setVar('page', (int) $page);
     }
     // If we have a defined items per page add it to the JUri object.
     if ($limit > 0) {
         $uri->setVar('per_page', (int) $limit);
     }
     return (string) $uri;
 }
 /**
  * Method to build and return a full request URL for the request.  This method will
  * add appropriate pagination details if necessary and also prepend the API url
  * to have a complete URL for the request.
  *
  * @param   string   $path   URL to inflect
  * @param   integer  $page   Page to request
  * @param   integer  $limit  Number of results to return per page
  *
  * @return  string   The request URL.
  *
  * @since   1.0
  */
 protected function fetchUrl($path, $page = 0, $limit = 0)
 {
     // Get a new Uri object fousing the api url and given path.
     $uri = new Uri($this->options->get('api.url') . $path);
     if ($this->options->get('gh.token', false)) {
         // Use oAuth authentication - @todo set in request header ?
         $uri->setVar('access_token', $this->options->get('gh.token'));
     } else {
         // Use basic authentication
         if ($this->options->get('api.username', false)) {
             $uri->setUser($this->options->get('api.username'));
         }
         if ($this->options->get('api.password', false)) {
             $uri->setPass($this->options->get('api.password'));
         }
     }
     // If we have a defined page number add it to the JUri object.
     if ($page > 0) {
         $uri->setVar('page', (int) $page);
     }
     // If we have a defined items per page add it to the JUri object.
     if ($limit > 0) {
         $uri->setVar('per_page', (int) $limit);
     }
     return (string) $uri;
 }
 /**
  * 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;
 }
 /**
  * Render the document
  *
  * @param   boolean  $cache   If true, cache the output
  * @param   array    $params  Associative array of attributes
  *
  * @return  string   The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     // If no error object is set return null
     if (!isset($this->_error)) {
         return;
     }
     // Set the status header
     Response::setHeader('status', $this->_error->getCode() . ' ' . str_replace("\n", ' ', $this->_error->getMessage()));
     $file = 'error.php';
     // Check template
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $template = isset($params['template']) ? FilterInput::getInstance()->clean($params['template'], 'cmd') : 'system';
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     // Set variables
     $this->baseurl = Uri::base(true);
     $this->template = $template;
     $this->debug = isset($params['debug']) ? $params['debug'] : false;
     $this->error = $this->_error;
     // Load
     $data = $this->_loadTemplate($directory . '/' . $template, $file);
     parent::render();
     return $data;
 }
 /**
  * Method to connect to a server and get the resource.
  *
  * @param   Uri      $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(Uri $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];
 }
 /**
  * Give a relative path, return path with host.
  *
  * @param   string $path A system path.
  *
  * @return  string  Path with host added.
  */
 public static function pathAddHost($path)
 {
     if (!$path) {
         return '';
     }
     // Build path
     $uri = new Uri($path);
     if ($uri->getHost()) {
         return $path;
     }
     $uri = new Uri(\JUri::root());
     $root_path = $uri->getPath();
     if (strpos($path, $root_path) === 0) {
         $num = Utf8String::strlen($root_path);
         $path = Utf8String::substr($path, $num);
     }
     $uri->setPath($uri->getPath() . $path);
     $uri->setScheme('http');
     $uri->setQuery(null);
     return $uri->toString();
 }
Example #10
0
 /**
  * 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;
 }
Example #11
0
 /**
  * Method to list issues.
  *
  * @param   string   $user       The name of the owner of the GitHub repository.
  * @param   string   $repo       The name of the GitHub repository.
  * @param   string   $milestone  The milestone number, 'none', or *.
  * @param   string   $state      The optional state to filter requests by. [open, closed]
  * @param   string   $assignee   The assignee name, 'none', or *.
  * @param   string   $mentioned  The GitHub user name.
  * @param   string   $labels     The list of comma separated Label names. Example: bug,ui,@high.
  * @param   string   $sort       The sort order: created, updated, comments, default: created.
  * @param   string   $direction  The list direction: asc or desc, default: desc.
  * @param   Date     $since      The date/time since when issues should be returned.
  * @param   integer  $page       The page number from which to get items.
  * @param   integer  $limit      The number of items on a page.
  *
  * @return  object
  *
  * @since   1.0
  * @throws  \DomainException
  */
 public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, Date $since = null, $page = 0, $limit = 0)
 {
     // Build the request path.
     $path = '/repos/' . $user . '/' . $repo . '/issues';
     $uri = new Uri($this->fetchUrl($path, $page, $limit));
     if ($milestone) {
         $uri->setVar('milestone', $milestone);
     }
     if ($state) {
         $uri->setVar('state', $state);
     }
     if ($assignee) {
         $uri->setVar('assignee', $assignee);
     }
     if ($mentioned) {
         $uri->setVar('mentioned', $mentioned);
     }
     if ($labels) {
         $uri->setVar('labels', $labels);
     }
     if ($sort) {
         $uri->setVar('sort', $sort);
     }
     if ($direction) {
         $uri->setVar('direction', $direction);
     }
     if ($since) {
         $uri->setVar('since', $since->toISO8601());
     }
     // Send the request.
     $response = $this->client->get((string) $uri);
     // Validate the response code.
     if ($response->code != 200) {
         // Decode the error response and throw an exception.
         $error = json_decode($response->body);
         throw new \DomainException($error->message, $response->code);
     }
     return json_decode($response->body);
 }
Example #12
0
 /**
  * Parse rule hook.
  *
  * @param \JRouter $router The router object.
  * @param Uri      $uri    The uri object.
  *
  * @return  array
  *
  * @throws \InvalidArgumentException
  */
 public function parseRule(\JRouter $router, Uri $uri)
 {
     $path = $uri->getPath();
     // No path & method, return 404.
     if ($this->isRoot($uri)) {
         throw new \InvalidArgumentException('No method.', 404);
     }
     // Direct our URI to component
     $path = 'component/' . $this->component . '/' . $path;
     $uri->setPath($path);
     $uri->setVar('format', 'json');
     return array();
 }
 /**
  * A method to do Google translate.
  *
  * @param   string $text      String to translate.
  * @param   string $SourceLan Translate from this language, eg: 'zh-tw'. Empty will auto detect.
  * @param   string $ResultLan Translate to this language, eg: 'en'. Empty will auto detect.
  *
  * @return  string|bool Translated text.
  */
 public static function gTranslate($text, $SourceLan, $ResultLan)
 {
     $url = new Uri();
     // For Google APIv2
     $url->setHost('https://www.googleapis.com/');
     $url->setPath('language/translate/v2');
     $query['key'] = self::APT_KEY;
     $query['q'] = urlencode($text);
     $query['source'] = $SourceLan;
     $query['target'] = $ResultLan;
     if (!$text) {
         return false;
     }
     $url->setQuery($query);
     $url->toString();
     $response = CurlHelper::get((string) $url);
     if (empty($response->body)) {
         return '';
     }
     $json = new \JRegistry();
     $json->loadString($response->body, 'json');
     $r = $json->get('data.translations');
     return $r[0]->translatedText;
 }
 /**
  * Fetch the template, and initialise the params
  *
  * @param   array  $params  Parameters to determine the template
  *
  * @return  JDocumentHTML instance of $this to allow chaining
  *
  * @since   11.1
  */
 protected function _fetchTemplate($params = array())
 {
     // Check
     $directory = isset($params['directory']) ? $params['directory'] : 'templates';
     $filter = FilterInput::getInstance();
     $template = $filter->clean($params['template'], 'cmd');
     $file = $filter->clean($params['file'], 'cmd');
     if (!file_exists($directory . '/' . $template . '/' . $file)) {
         $template = 'system';
     }
     // Load the language file for the template
     $lang = JFactory::getLanguage();
     // 1.5 or core then 1.6
     $lang->load('tpl_' . $template, JPATH_BASE, null, false, false) || $lang->load('tpl_' . $template, $directory . '/' . $template, null, false, false) || $lang->load('tpl_' . $template, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template, $directory . '/' . $template, $lang->getDefault(), false, false);
     // Assign the variables
     $this->template = $template;
     $this->baseurl = Uri::base(true);
     $this->params = isset($params['params']) ? $params['params'] : new JRegistry();
     // Load
     $this->_template = $this->_loadTemplate($directory . '/' . $template, $file);
     return $this;
 }
 /**
  * Convert links in a text from relative to absolute
  *
  * @param   string  $text  The text processed
  *
  * @return  string   Text with converted links
  *
  * @since   11.1
  */
 public function _relToAbs($text)
 {
     $base = Uri::base();
     $text = preg_replace("/(href|src)=\"(?!http|ftp|https|mailto|data)([^\"]*)\"/", "\$1=\"{$base}\$2\"", $text);
     return $text;
 }
Example #16
0
 /**
  * Method to retrieve the correct URI for login via GitHub
  *
  * @return  string  The login URI
  *
  * @since   1.0
  */
 public function getLoginUri()
 {
     if (!$this->clientId) {
         // No clientId set - Throw some fatal error...
         return '';
     }
     /* @type \JTracker\Application $application */
     $application = $this->container->get('app');
     $redirect = $application->get('uri.base.full') . 'login';
     $uri = new Uri($redirect);
     $usrRedirect = base64_encode((string) new Uri($application->get('uri.request')));
     $uri->setVar('usr_redirect', $usrRedirect);
     $redirect = (string) $uri;
     // Use "raw URI" here to partial encode the url.
     return 'https://github.com/login/oauth/authorize?scope=' . $application->get('github.auth_scope', 'public_repo') . '&client_id=' . $this->clientId . '&redirect_uri=' . urlencode($redirect);
 }
 /**
  * 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);
 }
 /**
  * Create a uri based on a full or partial url string
  *
  * @param   string  $url  The URI
  *
  * @return  JURI
  *
  * @since   11.1
  */
 protected function _createURI($url)
 {
     // Create full URL if we are only appending variables to it
     if (substr($url, 0, 1) == '&') {
         $vars = array();
         if (strpos($url, '&amp;') !== false) {
             $url = str_replace('&amp;', '&', $url);
         }
         parse_str($url, $vars);
         $vars = array_merge($this->getVars(), $vars);
         foreach ($vars as $key => $var) {
             if ($var == "") {
                 unset($vars[$key]);
             }
         }
         $url = 'index.php?' . Uri::buildQuery($vars);
     }
     // Decompose link into url component parts
     return new Uri($url);
 }
Example #19
0
 /**
  * Build route by resource setting.
  *
  * @param string $name       The route name.
  * @param array  $queries    The queries.
  * @param bool   $rootSlash  Add root slash or not.
  *
  * @return  array|string  Segments, can be string or array.
  */
 public function build($name, $queries = array(), $rootSlash = false)
 {
     $segments = parent::build($name, $queries, $rootSlash);
     $uri = new Uri($segments);
     $segments = $uri->getPath();
     $this->queries = $uri->getQuery(true);
     return explode('/', $segments);
 }
Example #20
0
 /**
  * Method to list issues.
  *
  * @param   string   $user       The name of the owner of the GitHub repository.
  * @param   string   $repo       The name of the GitHub repository.
  * @param   string   $milestone  The milestone number, 'none', or *.
  * @param   string   $state      The optional state to filter requests by. [open, closed]
  * @param   string   $assignee   The assignee name, 'none', or *.
  * @param   string   $mentioned  The GitHub user name.
  * @param   string   $labels     The list of comma separated Label names. Example: bug,ui,@high.
  * @param   string   $sort       The sort order: created, updated, comments, default: created.
  * @param   string   $direction  The list direction: asc or desc, default: desc.
  * @param   Date     $since      The date/time since when issues should be returned.
  * @param   integer  $page       The page number from which to get items.
  * @param   integer  $limit      The number of items on a page.
  *
  * @return  object
  *
  * @since   1.0
  * @throws  \DomainException
  */
 public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, Date $since = null, $page = 0, $limit = 0)
 {
     // Build the request path.
     $path = '/repos/' . $user . '/' . $repo . '/issues';
     $uri = new Uri($this->fetchUrl($path, $page, $limit));
     if ($milestone) {
         $uri->setVar('milestone', $milestone);
     }
     if ($state) {
         $uri->setVar('state', $state);
     }
     if ($assignee) {
         $uri->setVar('assignee', $assignee);
     }
     if ($mentioned) {
         $uri->setVar('mentioned', $mentioned);
     }
     if ($labels) {
         $uri->setVar('labels', $labels);
     }
     if ($sort) {
         $uri->setVar('sort', $sort);
     }
     if ($direction) {
         $uri->setVar('direction', $direction);
     }
     if ($since) {
         $uri->setVar('since', $since->toISO8601());
     }
     // Send the request.
     return $this->processResponse($this->client->get((string) $uri));
 }
 /**
  * Add unobtrusive javascript support for a color picker.
  *
  * @return  void
  *
  * @since   11.2
  */
 public static function colorpicker()
 {
     // Only load once
     if (isset(self::$loaded[__METHOD__])) {
         return;
     }
     // Include MooTools framework
     self::framework(true);
     Html::_('stylesheet', 'system/mooRainbow.css', array('media' => 'all'), true);
     Html::_('script', 'system/mooRainbow.js', false, true);
     Factory::getDocument()->addScriptDeclaration("window.addEvent('domready', function(){\n\t\t\t\tvar nativeColorUi = false;\n\t\t\t\tif (Browser.opera && (Browser.version >= 11.5)) {\n\t\t\t\t\tnativeColorUi = true;\n\t\t\t\t}\n\t\t\t\t\$\$('.input-colorpicker').each(function(item){\n\t\t\t\t\tif (nativeColorUi) {\n\t\t\t\t\t\titem.type = 'color';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnew MooRainbow(item, {\n\t\t\t\t\t\t\tid: item.id,\n\t\t\t\t\t\t\timgPath: '" . Uri::root(true) . "/media/system/images/mooRainbow/',\n\t\t\t\t\t\t\tonComplete: function(color) {\n\t\t\t\t\t\t\t\tthis.element.value = color.hex;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tstartColor: item.value.hexToRgb(true) ? item.value.hexToRgb(true) : [0, 0, 0]\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t");
     self::$loaded[__METHOD__] = true;
 }
Example #22
0
 /**
  * Resolves //, ../ and ./ from a path and returns
  * the result. Eg:
  *
  * /foo/bar/../boo.php    => /foo/boo.php
  * /foo/bar/../../boo.php => /boo.php
  * /foo/bar/.././/boo.php => /foo/boo.php
  *
  * @param   string  $path  The URI path to clean.
  *
  * @return  string  Cleaned and resolved URI path.
  *
  * @since       11.1
  * @deprecated  4.0   Use {@link \Joomla\Uri\Uri::cleanPath()} instead
  */
 protected function _cleanPath($path)
 {
     return parent::cleanPath($path);
 }
 /**
  * 1. Request authorization on GitHub.
  *
  * @param   string  $client_id     The client ID you received from GitHub when you registered.
  * @param   string  $redirect_uri  URL in your app where users will be sent after authorization.
  * @param   string  $scope         Comma separated list of scopes.
  * @param   string  $state         An unguessable random string. It is used to protect against
  *                                 cross-site request forgery attacks.
  *
  * @return  string
  *
  * @since   1.0
  */
 public function getAuthorizationLink($client_id, $redirect_uri = '', $scope = '', $state = '')
 {
     $uri = new Uri('https://github.com/login/oauth/authorize');
     $uri->setVar('client_id', $client_id);
     if ($redirect_uri) {
         $uri->setVar('redirect_uri', urlencode($redirect_uri));
     }
     if ($scope) {
         $uri->setVar('scope', $scope);
     }
     if ($state) {
         $uri->setVar('state', $state);
     }
     return (string) $uri;
 }
Example #24
0
 /**
  * Build by resource.
  *
  * @param   string   $resource The resource key to find our route.
  * @param   array    $data     The url query data.
  * @param   boolean  $xhtml    Replace & by &amp; 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  string Route url.
  */
 public static function _($resource, $data = array(), $xhtml = true, $ssl = null)
 {
     $resource = explode('.', $resource, 2);
     if (count($resource) == 2) {
         $data['option'] = $resource[0];
         $data['_resource'] = $resource[1];
     } elseif (count($resource) == 1) {
         $data['option'] = $resource[0];
         $data['_resource'] = null;
     }
     $url = new Uri();
     $url->setQuery($data);
     $url->setPath('index.php');
     return \JRoute::_((string) $url, $xhtml, $ssl);
 }
Example #25
0
 /**
  * Test the isSsl method.
  *
  * @return  void
  *
  * @since   1.0
  * @covers  Joomla\Uri\Uri::isSsl
  */
 public function testisSsl()
 {
     $object = new Uri('https://*****:*****@www.example.com:80/path/file.html?var=value#fragment');
     $this->assertThat($object->isSsl(), $this->equalTo(true));
     $object = new Uri('http://*****:*****@www.example.com:80/path/file.html?var=value#fragment');
     $this->assertThat($object->isSsl(), $this->equalTo(false));
 }
 /**
  * Get the Uri object for a given page.
  *
  * @param   integer  $page  The page number.
  *
  * @return  Uri
  *
  * @since   1.0
  */
 private function uri($page)
 {
     $this->uri->setVar('page', $page);
     return $this->uri;
 }
 /**
  * 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   1.0
  */
 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 = new Uri($siteUri);
         $path = $uri->toString(array('path'));
     } else {
         // Start with the requested URI.
         $uri = new Uri($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.
             $path = dirname($_SERVER['PHP_SELF']);
         } else {
             $path = dirname($_SERVER['SCRIPT_NAME']);
         }
     }
     // Get the host from the URI.
     $host = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
     // 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.
     if (stripos($this->get('uri.request'), $this->get('uri.base.full')) === 0) {
         $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/');
     }
 }
Example #28
0
 /**
  * Parse a given URI and populate the class fields.
  *
  * @param   string  $uri  The URI string to parse.
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  * @note    The parent method is protected, this exposes it as public for B/C
  */
 public function parse($uri)
 {
     return parent::parse($uri);
 }
 /**
  * Compute the files to be included
  *
  * @param   string   $folder          folder name to search into (images, css, js, ...)
  * @param   string   $file            path to file
  * @param   boolean  $relative        path to file is relative to /media folder
  * @param   boolean  $detect_browser  detect browser to include specific browser files
  * @param   boolean  $detect_debug    detect debug to include compressed files if debug is on
  *
  * @return  array    files to be included
  *
  * @see     JBrowser
  * @since   11.1
  */
 protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug)
 {
     // If http is present in filename
     if (strpos($file, 'http') === 0) {
         $includes = array($file);
     } else {
         // Extract extension and strip the file
         $strip = File::stripExt($file);
         $ext = File::getExt($file);
         // Prepare array of files
         $includes = array();
         // Detect browser and compute potential files
         if ($detect_browser) {
             $navigator = Browser::getInstance();
             $browser = $navigator->getBrowser();
             $major = $navigator->getMajor();
             $minor = $navigator->getMinor();
             // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext
             // where major and minor are the browser version names
             $potential = array($strip, $strip . '_' . $browser, $strip . '_' . $browser . '_' . $major, $strip . '_' . $browser . '_' . $major . '_' . $minor);
         } else {
             $potential = array($strip);
         }
         // If relative search in template directory or media directory
         if ($relative) {
             // Get the template
             $app = Factory::getApplication();
             $template = $app->getTemplate();
             // For each potential files
             foreach ($potential as $strip) {
                 $files = array();
                 // Detect debug mode
                 if ($detect_debug && Factory::getConfig()->get('debug')) {
                     /*
                      * Detect if we received a file in the format name.min.ext
                      * If so, strip the .min part out, otherwise append -uncompressed
                      */
                     if (strrpos($strip, '.min', '-4')) {
                         $position = strrpos($strip, '.min', '-4');
                         $filename = str_replace('.min', '.', $strip, $position);
                         $files[] = $filename . $ext;
                     } else {
                         $files[] = $strip . '-uncompressed.' . $ext;
                     }
                 }
                 $files[] = $strip . '.' . $ext;
                 /*
                  * Loop on 1 or 2 files and break on first found.
                  * Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh
                  * This MD5SUM file must represent the signature of the folder content
                  */
                 foreach ($files as $file) {
                     // If the file is in the template folder
                     $path = JPATH_THEMES . "/{$template}/{$folder}/{$file}";
                     if (file_exists($path)) {
                         $md5 = dirname($path) . '/MD5SUM';
                         $includes[] = Uri::base(true) . "/templates/{$template}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                         break;
                     } else {
                         // If the file contains any /: it can be in an media extension subfolder
                         if (strpos($file, '/')) {
                             // Divide the file extracting the extension as the first part before /
                             list($extension, $file) = explode('/', $file, 2);
                             // If the file yet contains any /: it can be a plugin
                             if (strpos($file, '/')) {
                                 // Divide the file extracting the element as the first part before /
                                 list($element, $file) = explode('/', $file, 2);
                                 // Try to deal with plugins group in the media folder
                                 $path = JPATH_ROOT . "/media/{$extension}/{$element}/{$folder}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/media/{$extension}/{$element}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                                 // Try to deal with classical file in a a media subfolder called element
                                 $path = JPATH_ROOT . "/media/{$extension}/{$folder}/{$element}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/media/{$extension}/{$folder}/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                                 // Try to deal with system files in the template folder
                                 $path = JPATH_THEMES . "/{$template}/{$folder}/system/{$element}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/templates/{$template}/{$folder}/system/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                                 // Try to deal with system files in the media folder
                                 $path = JPATH_ROOT . "/media/system/{$folder}/{$element}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/media/system/{$folder}/{$element}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                             } else {
                                 // Try to deals in the extension media folder
                                 $path = JPATH_ROOT . "/media/{$extension}/{$folder}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/media/{$extension}/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                                 // Try to deal with system files in the template folder
                                 $path = JPATH_THEMES . "/{$template}/{$folder}/system/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/templates/{$template}/{$folder}/system/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                                 // Try to deal with system files in the media folder
                                 $path = JPATH_ROOT . "/media/system/{$folder}/{$file}";
                                 if (file_exists($path)) {
                                     $md5 = dirname($path) . '/MD5SUM';
                                     $includes[] = Uri::root(true) . "/media/system/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                     break;
                                 }
                             }
                         } else {
                             $path = JPATH_ROOT . "/media/system/{$folder}/{$file}";
                             if (file_exists($path)) {
                                 $md5 = dirname($path) . '/MD5SUM';
                                 $includes[] = Uri::root(true) . "/media/system/{$folder}/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                                 break;
                             }
                         }
                     }
                 }
             }
         } else {
             foreach ($potential as $strip) {
                 $files = array();
                 // Detect debug mode
                 if ($detect_debug && Factory::getConfig()->get('debug')) {
                     $files[] = $strip . '-uncompressed.' . $ext;
                 }
                 $files[] = $strip . '.' . $ext;
                 /*
                  * Loop on 1 or 2 files and break on first found.
                  * Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh
                  * This MD5SUM file must represent the signature of the folder content
                  */
                 foreach ($files as $file) {
                     $path = JPATH_ROOT . "/{$file}";
                     if (file_exists($path)) {
                         $md5 = dirname($path) . '/MD5SUM';
                         $includes[] = Uri::root(true) . "/{$file}" . (file_exists($md5) ? '?' . file_get_contents($md5) : '');
                         break;
                     }
                 }
             }
         }
     }
     return $includes;
 }
Example #30
0
 /**
  * Tests the request method with credentials supplied
  *
  * @param   string  $transportClass  The transport class to test
  *
  * @return  void
  *
  * @since      1.0
  * @dataProvider  transportProvider
  */
 public function testRequestCredentials($transportClass)
 {
     $transport = new $transportClass($this->options);
     $uri = new Uri($this->stubUrl);
     $credentialedUri = new Uri($uri->toString(array('scheme')) . 'username:password@' . $uri->toString(array('host', 'port', 'path', 'query', 'fragment')));
     $response = $transport->request('get', $credentialedUri);
     $body = json_decode($response->body);
     $this->assertThat($response->code, $this->equalTo(200));
     $this->assertThat($body->username, $this->equalTo('username'));
     $this->assertThat($body->password, $this->equalTo('password'));
 }