Ejemplo n.º 1
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();
 }
 /**
  * @param JUri $uri
  *
  * @throws RuntimeException
  *
  * @return mixed
  */
 protected function getRemote($uri, $persistent = false)
 {
     $uri->setScheme('https');
     $uri->setHost('www.warcraftlogs.com');
     $this->url = $uri->toString();
     $result = parent::getRemote($this->url, $persistent);
     $result->body = json_decode($result->body);
     if ($result->code != 200) {
         // hide api key from normal users
         if (!JFactory::getUser()->get('isRoot')) {
             $uri->delVar('api_key');
             $this->url = $uri->toString();
         }
         $msg = JText::sprintf('Server Error: %s url: %s', $result->body->error, JHtml::_('link', $this->url, $result->code, array('target' => '_blank')));
         // TODO JText::_()
         throw new RuntimeException($msg);
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
 /**
  * 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'));
 }
Ejemplo n.º 5
0
 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);
     }
 }
Ejemplo n.º 6
0
 /**
  * getBackupZipFile
  *
  * @return  string
  */
 public static function getBackupZipFile()
 {
     $uri = new \JUri(\JUri::root());
     $uri->setScheme(null);
     return JPATH_ROOT . '/tmp/ezset/backup/ezset-backup-' . \JFilterOutput::stringURLSafe($uri) . '.zip';
 }
Ejemplo n.º 7
0
 /**
  * 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();
 }
 public function getExtensions()
 {
     // Get catid, search filter, order column, order direction
     $cache = JFactory::getCache();
     $cache->setCaching(1);
     $http = new JHttp();
     $http->setOption('timeout', 60);
     $componentParams = JComponentHelper::getParams('com_apps');
     $api_url = new JUri();
     $default_limit = $componentParams->get('default_limit', 8);
     $input = new JInput();
     $catid = $input->get('id', null, 'int');
     $order = $input->get('ordering', $this->getOrderBy());
     $orderCol = $this->state->get('list.ordering', $order);
     $orderDirn = $orderCol == 'core_title' ? 'ASC' : 'DESC';
     $release = preg_replace('/[^\\d]/', '', base64_decode($input->get('release', '', 'base64')));
     $limitstart = $input->get('limitstart', 0, 'int');
     $limit = $input->get('limit', $default_limit, 'int');
     $dashboard_limit = $componentParams->get('extensions_perrow') * 6;
     // 6 rows of extensions
     $search = str_replace('_', ' ', urldecode(trim($input->get('filter_search', null))));
     $release = intval($release / 5) * 5;
     $api_url->setScheme('http');
     $api_url->setHost('extensions.joomla.org/index.php');
     $api_url->setvar('option', 'com_jed');
     $api_url->setvar('controller', 'filter');
     $api_url->setvar('view', 'extension');
     $api_url->setvar('format', 'json');
     $api_url->setvar('limit', $limit);
     $api_url->setvar('limitstart', $limitstart);
     $api_url->setvar('filter[approved]', '1');
     $api_url->setvar('filter[published]', '1');
     $api_url->setvar('extend', '0');
     $api_url->setvar('order', $orderCol);
     $api_url->setvar('dir', $orderDirn);
     if ($search) {
         $api_url->setvar('searchall', urlencode($search));
     }
     $extensions_json = $cache->call(array($http, 'get'), $api_url);
     $items = json_decode($extensions_json->body);
     $items = $items->data;
     // Populate array
     $extensions = array(0 => array(), 1 => array());
     foreach ($items as $item) {
         $item->image = $this->getBaseModel()->getMainImageUrl($item);
         if ($search) {
             $extensions[1 - $item->foundintitle][] = $item;
         } else {
             $extensions[0][] = $item;
         }
     }
     return array_merge($extensions[0], $extensions[1]);
 }
 public function getExtension()
 {
     // Get extension id
     $cache = JFactory::getCache();
     $cache->setCaching(1);
     $http = new JHttp();
     $http->setOption('timeout', 60);
     $api_url = new JUri();
     $input = new JInput();
     $id = $input->get('id', null, 'int');
     $release = preg_replace('/[^\\d]/', '', base64_decode($input->get('release', '', 'base64')));
     $release = intval($release / 5) * 5;
     $api_url->setScheme('http');
     $api_url->setHost('extensions.joomla.org/index.php');
     $api_url->setvar('option', 'com_jed');
     $api_url->setvar('controller', 'filter');
     $api_url->setvar('view', 'extension');
     $api_url->setvar('format', 'json');
     $api_url->setvar('filter[approved]', '1');
     $api_url->setvar('filter[published]', '1');
     $api_url->setvar('extend', '0');
     $api_url->setvar('filter[id]', $id);
     $extension_json = $cache->call(array($http, 'get'), $api_url);
     // Create item
     $items = json_decode($extension_json->body);
     $item = $items->data[0];
     $this->_catid = $item->core_catid->value;
     $item->image = $this->getBaseModel()->getMainImageUrl($item);
     $item->downloadurl = $item->download_integration_url->value;
     if (preg_match('/\\.xml\\s*$/', $item->downloadurl)) {
         $app = JFactory::getApplication();
         $product = addslashes(base64_decode($app->input->get('product', '', 'base64')));
         $release = preg_replace('/[^\\d\\.]/', '', base64_decode($app->input->get('release', '', 'base64')));
         $dev_level = (int) base64_decode($app->input->get('dev_level', '', 'base64'));
         $updatefile = JPATH_ROOT . '/libraries/joomla/updater/update.php';
         $fh = fopen($updatefile, 'r');
         $theData = fread($fh, filesize($updatefile));
         fclose($fh);
         $theData = str_replace('<?php', '', $theData);
         $theData = str_replace('$ver->PRODUCT', "'" . $product . "'", $theData);
         $theData = str_replace('$ver->RELEASE', "'" . $release . "'", $theData);
         $theData = str_replace('$ver->DEV_LEVEL', "'" . $dev_level . "'", $theData);
         eval($theData);
         $update = new JUpdate();
         $update->loadFromXML($item->downloadurl);
         $package_url_node = $update->get('downloadurl', false);
         if (isset($package_url_node->_data)) {
             $item->downloadurl = $package_url_node->_data;
         }
     }
     $item->download_type = $this->getTypeEnum($item->download_integration_type->value);
     return array($item);
 }