protected function getMember($member, $realm, array $fields = array('items', 'achievements'))
 {
     $uri = new JUri();
     $uri->setPath('/wow/character/' . $realm . '/' . $member);
     $uri->setVar('fields', implode(',', $fields));
     return $this->getRemote($uri);
 }
Beispiel #2
0
 public function getBattleNetUrl()
 {
     $uri = new JUri();
     $uri->setScheme($this->params->get('scheme', 'http'));
     $uri->setHost($this->params->get('region') . '.battle.net');
     $uri->setPath('/wow/' . $this->params->get('locale') . '/guild/' . rawurlencode($this->params->get('realm')) . '/' . rawurlencode($this->params->get('guild')) . '/');
     return $uri->toString();
 }
 /**
  * @see https://www.warcraftlogs.com/v1/docs#!/Reports/
  * @throws RuntimeException
  *
  * @return stdClass
  */
 public function getData($api_key)
 {
     $uri = new JUri();
     $this->params->set('realm', str_replace("'", '', $this->params->get('realm')));
     $this->params->set('guild', str_replace(' ', '+', $this->params->get('guild')));
     $uri->setPath('/v1/reports/guild/' . $this->params->get('guild') . '/' . JApplicationHelper::stringURLSafe($this->params->get('realm')) . '/' . $this->params->get('region'));
     $uri->setVar('api_key', $api_key);
     return $this->getRemote($uri);
 }
Beispiel #4
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 & 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 \JUri();
     $url->setQuery($data);
     $url->setPath('index.php');
     return \JRoute::_((string) $url, $xhtml, $ssl);
 }
Beispiel #5
0
 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);
 }
 /**
  * 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 \JUri();
     // 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;
 }
 /**
  * Test the setPath method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::setPath
  */
 public function testSetPath()
 {
     $this->object->setPath('/this/is/a/path/to/a/file.htm');
     $this->assertThat($this->object->getPath(), $this->equalTo('/this/is/a/path/to/a/file.htm'));
 }
Beispiel #8
0
 /**
  * Function to build a sef route
  *
  * @param   JUri  $uri  The uri
  *
  * @return  void
  */
 protected function _buildSefRoute($uri)
 {
     // Get the route
     $route = $uri->getPath();
     // Get the query data
     $query = $uri->getQuery(true);
     if (!isset($query['option'])) {
         return;
     }
     $app = JApplication::getInstance('site');
     $menu = $app->getMenu();
     /*
      * Build the component route
      */
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $query['option']);
     $tmp = '';
     $itemID = !empty($query['Itemid']) ? $query['Itemid'] : null;
     // Use the component routing handler if it exists
     $path = JPATH_SITE . '/components/' . $component . '/router.php';
     // Use the custom routing handler if it exists
     if (file_exists($path) && !empty($query)) {
         require_once $path;
         $function = substr($component, 4) . 'BuildRoute';
         $function = str_replace(array("-", "."), "", $function);
         $parts = $function($query);
         // Encode the route segments
         if ($component != 'com_search') {
             // Cheep fix on searches
             $parts = $this->_encodeSegments($parts);
         } else {
             // Fix up search for URL
             $total = count($parts);
             for ($i = 0; $i < $total; $i++) {
                 // Urlencode twice because it is decoded once after redirect
                 $parts[$i] = urlencode(urlencode(stripcslashes($parts[$i])));
             }
         }
         $result = implode('/', $parts);
         $tmp = $result != "" ? $result : '';
     }
     /*
      * Build the application route
      */
     $built = false;
     if (!empty($query['Itemid'])) {
         $item = $menu->getItem($query['Itemid']);
         if (is_object($item) && $query['option'] == $item->component) {
             if (!$item->home || $item->language != '*') {
                 $tmp = !empty($tmp) ? $item->route . '/' . $tmp : $item->route;
             }
             $built = true;
         }
     }
     if (empty($query['Itemid']) && !empty($itemID)) {
         $query['Itemid'] = $itemID;
     }
     if (!$built) {
         $tmp = 'component/' . substr($query['option'], 4) . '/' . $tmp;
     }
     if ($tmp) {
         $route .= '/' . $tmp;
     } elseif ($route == 'index.php') {
         $route = '';
     }
     // Unset unneeded query information
     if (isset($item) && $query['option'] == $item->component) {
         unset($query['Itemid']);
     }
     unset($query['option']);
     // Set query again in the URI
     $uri->setQuery($query);
     $uri->setPath($route);
 }
 /**
  * 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 \JUri($path);
     if ($uri->getHost()) {
         return $path;
     }
     $uri->parse(\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();
 }