Example #1
0
	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')
		);
	}
 /**
  * Method to parse the router
  *
  * @param   JRouter  $router  JRouter instance
  * @param   JURI     $uri     Current JURI instance
  *
  * @return array
  */
 public function parseRoute($router, $uri)
 {
     $path = $uri->getPath();
     $segments = explode('/', $path);
     $alias = end($segments);
     if (preg_match('/^([0-9])\\-/', $alias) == false) {
         $alias = preg_replace('/\\-$/', '', $alias);
         $slug = $this->getSlugByAlias($alias);
         if (!empty($slug)) {
             $path = str_replace($alias, $slug, $path);
             $uri->setPath($path);
         }
     }
     return array();
 }
Example #3
0
 /**
  * Returns the path generated by the Simple Custom Router when building the
  * given query.
  * The query should not contain the leading '?'; it must be just the query
  * itself.
  * 
  * @param string $query The query to build.
  * @return string The generated path, if any.
  */
 public function testQuery($query)
 {
     $simpleCustomRouter = new SimpleCustomRouter();
     $uri = new JURI();
     $uri->setPath('index.php');
     $uri->setQuery($query);
     $siteRouter = null;
     $simpleCustomRouter->build($siteRouter, $uri);
     if ($uri->getPath() == 'index.php') {
         return '';
     } else {
         if ($uri->getQuery() == '') {
             return $uri->getPath();
         } else {
             return $uri->getPath() . '?' . $uri->getQuery();
         }
     }
 }
Example #4
0
function gTranslate($text, $SourceLan, $ResultLan)
{
    $url = new JURI();
    // for APIv2
    $url->setHost('https://www.googleapis.com/');
    $url->setPath('language/translate/v2');
    $query['key'] = 'AIzaSyC04nF4KXjfR2VQ0jsFm5vEd9LbyiXqbKw';
    $query['q'] = urlencode($text);
    $query['source'] = $SourceLan;
    $query['target'] = $ResultLan;
    if (!$text) {
        return;
    }
    $url->setQuery($query);
    $url->toString();
    $response = AKHelper::_('curl.getPage', $url->toString());
    $json = new JRegistry($response);
    $r = $json->get('data.translations');
    return $r[0]->translatedText;
}
Example #5
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 = JString::strlen($root_path);
         $path = JString::substr($path, $num);
     }
     $uri->setPath($uri->getPath() . $path);
     $uri->setScheme('http');
     $uri->setQuery(null);
     return $uri->toString();
 }
Example #6
0
 /**
  * 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    Translated text.  
  */
 public static function gTranslate($text, $SourceLan, $ResultLan)
 {
     $url = new JURI();
     // for 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;
     }
     $url->setQuery($query);
     $url->toString();
     $response = AKHelper::_('curl.getPage', $url->toString());
     $json = new JRegistry();
     $json->loadString($response);
     $r = $json->get('data.translations');
     return $r[0]->translatedText;
 }
 function parse(&$uri)
 {
     $mainframe =& JFactory::getApplication();
     // test for the backlink plugin to work correctly
     if (JPluginHelper::isEnabled('system', 'backlink')) {
         // && $uri->getQuery() ) {    // commented out - causing problems
         $joomlaRequest = urldecode($_SERVER['REQUEST_URI']);
         $realRequest = $uri->toString(array('path', 'query'));
         if ($realRequest != $joomlaRequest) {
             $uri = new JURI($joomlaRequest);
         }
     }
     // store the old URI before we change it in case we will need it
     // for default Joomla SEF
     $oldUri = new JURI($uri->toString());
     if (!SEFTools::JoomFishInstalled()) {
         $url_query = $uri->getQuery();
         $host = explode(".", $uri->getHost());
         $subdomain = array_shift($host);
         $db = JFactory::getDBO();
         // Subdomain titlepage
         if ($uri->getPath() == '/' && empty($url_query) && empty($_POST)) {
             $query = "SELECT Itemid_titlepage FROM #__sef_subdomains WHERE subdomain = " . $db->quote($subdomain) . " LIMIT 1";
             $db->setQuery($query);
             $Itemid = $db->loadResult();
             if ($Itemid > 0) {
                 $uri->setVar('Itemid', $Itemid);
                 JoomSEF::set('real_domain', JFactory::getUri()->getHost());
                 JFactory::getUri()->setHost(implode(".", $host));
             }
         } else {
             $query = "SELECT COUNT(*) FROM #__sef_subdomains WHERE subdomain = " . $db->quote($subdomain);
             $db->setQuery($query);
             $cnt = $db->loadResult();
             if ($cnt) {
                 JoomSEF::set('real_domain', JFactory::getUri()->getHost());
                 JFactory::getUri()->setHost(implode(".", $host));
             }
         }
     }
     $sefConfig =& SEFConfig::getConfig();
     // load patches
     JPluginHelper::importPlugin('sefpatch');
     // trigger onSefLoad patches
     $mainframe->triggerEvent('onSefLoad');
     // get path
     $path = $uri->getPath();
     // remove basepath
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     // remove slashes
     $path = ltrim($path, '/');
     // Redirect URL with / on the end to URL without / on the end
     if ($sefConfig->redirectSlash) {
         $request = $_SERVER["REQUEST_URI"];
         $noBase = substr_replace($request, '', 0, strlen(JURI::base(true)));
         if ($request != "/" && $noBase != "/" && substr($request, -1) == '/') {
             $mainframe->redirect(rtrim($request, "/"), '', 'message');
             JFactory::getApplication()->close();
         }
     }
     // Redirect the index.php (need to check this before index.php removal)
     if ($sefConfig->fixIndexPhp && $path == 'index.php' && count($_POST) == 0) {
         $q = $uri->getQuery(true);
         if (count($q) == 0) {
             $newUrl = JURI::root();
             if (substr($newUrl, -1) != '/') {
                 $newUrl .= '/';
             }
             $mainframe->redirect($newUrl, '', 'message', true);
             exit;
         }
     }
     // Try the 301 Alias redirect
     if (count($_POST) == 0) {
         JoomSEF::_parseAlias($path, $uri->getQuery(true));
     }
     // Disable non-SEF redirect for index2.php links
     // EDIT: don't even parse index2.php links!
     if (substr($path, 0, 10) == 'index2.php') {
         //$sefConfig->nonSefRedirect = false;
         return $uri->getQuery(true);
     }
     // Redirect old /index.php/ links if set to
     if ($sefConfig->fixIndexPhp && substr($path, 0, 10) == 'index.php/' && count($_POST) == 0) {
         $newUrl = JURI::root();
         if (substr($newUrl, -1) != '/') {
             $newUrl .= '/';
         }
         $newUrl .= substr($path, 10);
         $mainframe->redirect($newUrl, '', 'message', true);
         exit;
     }
     // remove prefix (both index.php and index2.php)
     $path = preg_replace('/^index2?.php/i', '', $path);
     // remove slashes again to be sure there aren't any left
     $path = ltrim($path, '/');
     // replace spaces with our replacement character
     // (mainly for '+' handling, but may be useful in some other situations too)
     $path = str_replace(' ', $sefConfig->replacement, $path);
     // set the route
     $uri->setPath($path);
     // host name handling
     if (SEFTools::JoomFishInstalled() && $sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN && !JPluginHelper::isEnabled('system', 'jfrouter')) {
         // different domains for languages handling
         $host = $uri->toString(array('host'));
         $host = trim($host, '/');
         $code = null;
         foreach ($sefConfig->jfSubDomains as $langCode => $domain) {
             if ($host == $domain) {
                 // if main language is not selected, use the first corresponding domain
                 if ($sefConfig->mainLanguage == '0') {
                     $code = $langCode;
                     break;
                 } else {
                     if ($langCode == $sefConfig->mainLanguage) {
                         $code = $langCode;
                         break;
                     } else {
                         if (is_null($code)) {
                             $code = $langCode;
                         }
                     }
                 }
             }
         }
         // we found a matching domain
         if (!is_null($code)) {
             JRequest::setVar('lang', $code);
             $config =& JFactory::getConfig();
             $config->set('joomsef.domain_lang', $code);
         }
     }
     // parse the url
     $vars = JoomSEF::_parseSefUrl($uri, $oldUri);
     // handle custom site name for extensions
     if (isset($vars['option'])) {
         $params =& SEFTools::getExtParams($vars['option']);
         $useSitename = $params->get('useSitename', '1');
         $customSitename = trim($params->get('customSitename', ''));
         $config =& JFactory::getConfig();
         if ($useSitename == '0') {
             // don't use site name
             $config->setValue('sitename', '');
         } elseif (!empty($customSitename)) {
             // use custom site name
             $config->setValue('sitename', $customSitename);
         }
     }
     // trigger onSefUnload patches
     $mainframe->triggerEvent('onSefUnload');
     return $vars;
 }
Example #8
0
function shNormalizeNonSefUri(&$uri, $menu = null, $removeSlugs = true)
{
    // put back a J!1.5 non-sef url to J! 1.0.x format
    // Get the route
    $route = $uri->getPath();
    //Get the query vars
    $vars = $uri->getQuery(true);
    // fix some problems in incoming URLs
    if (!empty($vars['Itemid'])) {
        // sometimes we get doubles : ?Itemid=xx?Itemid=xx
        $vars['Itemid'] = intval($vars['Itemid']);
        $uri->setQuery($vars);
    }
    // fix urls obtained through a single Itemid, in menus : url is option=com_xxx&Itemid=yy
    if (count($vars) == 2 && $uri->getVar('Itemid')) {
        if (empty($menu)) {
            $menu =& shRouter::shGetMenu();
        }
        $shItem = $menu->getItem($vars['Itemid']);
        if (!empty($shItem)) {
            // we found the menu item
            $url = $shItem->link . '&Itemid=' . $shItem->id;
            $uri = new JURI($url);
            // rebuild $uri based on this new url
            $uri->setPath($route);
            $vars = $uri->getQuery(true);
        }
    }
    if ($removeSlugs !== false) {
        $vars = shRemoveSlugs($vars, $removeSlugs);
    }
    $uri->setQuery($vars);
}
Example #9
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 = '';
     // 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 (isset($query['Itemid']) && !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 (!$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);
 }
Example #10
0
} else {
    $checkout = '';
    JPluginHelper::importPlugin('redshop_payment');
    $dispatcher = JDispatcher::getInstance();
    $pluginButton = $dispatcher->trigger('onPaymentCheckoutButton', array($cart));
    $pluginButton = implode("<br>", $pluginButton);
    // Google checkout start Div
    if ($pluginButton) {
        $checkout .= '<div class="googlecheckout-button" style="float:left;">' . $pluginButton . '</div>';
    }
    if (SSL_ENABLE_IN_CHECKOUT) {
        $uri = JURI::getInstance();
        $c_link = new JURI();
        $c_link->setScheme('https');
        $c_link->setHost($uri->getHost());
        $c_link->setPath(JRoute::_('index.php?option=com_redshop&view=checkout&Itemid=' . $Itemid));
        $link = $c_link->toString();
    } else {
        $link = JRoute::_('index.php?option=com_redshop&view=checkout&Itemid=' . $Itemid);
    }
    $checkout .= '<div class="checkout_button"  style="float:right;">';
    $checkout .= '<input type=button class="greenbutton" value="' . JText::_('COM_REDSHOP_CART_CHECKOUT') . '" ';
    if (MINIMUM_ORDER_TOTAL > 0 && $cart['total'] < MINIMUM_ORDER_TOTAL) {
        $checkout .= ' onclick="alert(\'' . JText::_('COM_REDSHOP_MINIMUM_ORDER_TOTAL_HAS_TO_BE_MORE_THAN') . ' ' . MINIMUM_ORDER_TOTAL . '\');">';
    } else {
        $checkout .= ' onclick="javascript:document.location=\'' . $link . '\'">';
    }
    $checkout .= '</div>';
}
$cart_data = str_replace("{checkout}", $checkout, $cart_data);
$cart_data = str_replace("{checkout_button}", $checkout, $cart_data);
Example #11
0
 function parse(&$siteRouter, &$uri)
 {
     if ($this->parsing) {
         return array();
     }
     $this->parsing = true;
     $uri->setPath(JURI::base(true) . '/' . $uri->getPath());
     $mainframe = JFactory::getApplication();
     $router = $mainframe->get('mijosef.global.jrouter');
     $router->setMode(JROUTER_MODE_DONT_PARSE);
     // Fix the missing question mark
     if (count($_POST) == 0) {
         $url = $uri->toString();
         $new_url = preg_replace('/^([^?&]*)&([^?]+=[^?]*)$/', '$1?$2', $url);
         // Redirect if question mark fixed
         if ($new_url != $url) {
             $mainframe->redirect($new_url, '', 'message', true);
         }
     }
     // Check if URI is string
     if (is_string($uri)) {
         $uri = JURI::getInstance($uri);
     }
     // Backlink plugin compatibility
     if (JPluginHelper::isEnabled('system', 'backlink')) {
         $joomla_request = $_SERVER['REQUEST_URI'];
         $real_request = $uri->toString(array('path', 'query'));
         if ($real_request != $joomla_request) {
             $uri = new JURI($joomla_request);
         }
     }
     // We'll use it for Joomla! SEF to MijoSEF redirection
     $old_uri = clone $uri;
     // get path
     $path = $uri->getPath();
     // remove basepath
     $path = substr_replace($path, '', 0, strlen(JURI::base(true)));
     // remove slashes
     $path = ltrim($path, '/');
     // Check if the URL starts with index2.php
     if (substr($path, 0, 10) == 'index2.php') {
         return $uri->getQuery(true);
     }
     // remove prefix (both index.php and index2.php)
     $path = preg_replace('/^index2?.php/i', '', $path);
     // remove slashes again to be sure there aren't any left
     $path = ltrim($path, '/');
     // replace spaces with our replacement character
     $path = str_replace(' ', $this->MijosefConfig->replacement_character, $path);
     // set the route
     $uri->setPath($path);
     $vars = Mijosef::get('uri')->parseURI($uri, $old_uri);
     // Parsing done
     $this->parsing = false;
     // Fix the start variable
     if ($start = $uri->getVar('start')) {
         $uri->delVar('start');
         $vars['limitstart'] = $start;
     }
     $menu = Mijosef::get('utility')->getMenu();
     // Handle an empty URL (special case)
     if (empty($vars['Itemid']) && empty($vars['option'])) {
         $item = Mijosef::get('uri')->getDefaultMenuItem();
         if (!is_object($item)) {
             return $vars;
         }
         // set the information in the request
         $vars = $item->query;
         // get the itemid
         $vars['Itemid'] = $item->id;
         // set the active menu item
         $menu->setActive($vars['Itemid']);
         // set vars
         $this->setRequestVars($vars);
         return $vars;
     }
     // Get the item id, if it hasn't been set force it to null
     if (empty($vars['Itemid'])) {
         $vars['Itemid'] = JRequest::getInt('Itemid', null);
     }
     // Get the variables from the uri
     $this->setVars($vars);
     // No option? Get the full information from the itemid
     if (empty($vars['option'])) {
         $item = $menu->getItem($this->getVar('Itemid'));
         if (!is_object($item)) {
             return $vars;
         }
         // No default item set
         $vars = $vars + $item->query;
     }
     // Set the active menu item
     $menu->setActive($this->getVar('Itemid'));
     Mijosef::get('language')->parseLang($vars);
     // Set vars
     $this->setRequestVars($vars);
     return $vars;
 }
Example #12
0
 function _finalizeURI($uri, $route)
 {
     // Prepare non-SEF part
     if ($this->attributes->non_sef_part != '' && strstr($route, '?')) {
         $this->attributes->non_sef_part = str_replace('?', '&amp;', $this->attributes->non_sef_part);
     }
     // Get domain
     $url = self::getDomain();
     // Add non-SEF vars
     if ($this->MijosefConfig->append_non_sef == 1) {
         $url .= $route . $this->attributes->non_sef_part;
     } else {
         $url .= $route;
     }
     // Add fragment
     $fragment = $uri->getFragment();
     if (!empty($fragment)) {
         $url .= '#' . $fragment;
     }
     // Finally return new URI
     $uri = new JURI($url);
     $uri->setPath(JString::substr($uri->getPath(), JString::strlen(JURI::base(true))));
     return $uri;
 }