/**
  * Iterates the redirects array returning the uri to redirect to if a match is found
  * @uses htmlspecialchars_decode()
  * 
  * @access public
  * @return mixed - bool false / string redirection url 
  */
 public function needsRedirect()
 {
     if (!empty(self::$redirects)) {
         foreach (self::$redirects as $target => $uri_data) {
             if (Usu_Main::i()->getVar('request_uri') == $target) {
                 return htmlspecialchars_decode(tep_href_link($uri_data[0], $uri_data[1]));
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Cache garbage clearance
  * 
  * @param bool $file_info
  * 
  * @access public
  * @return void
  */
 public function gc($file_info = false)
 {
     $this->insert = true;
     Usu_Main::i()->query('TRUNCATE `usu_cache`');
 }
Exemplo n.º 3
0
 /**
  * Parse the path into superglobal _GET and long array HTTP_GET_VARS
  * @uses substr()
  * @uses strpos()
  * @uses explode()
  * @uses str_replace()
  * @uses http_build_query()
  * 
  * @access public
  * @return mixed - bool false / string key=value
  */
 public function parsePath()
 {
     global $HTTP_GET_VARS;
     Usu_Main::i()->setVar('parsing_module', __CLASS__);
     if (false !== strpos(Usu_Main::i()->getVar('request_uri'), 'ext/modules')) {
         return false;
     }
     $dependencies = Usu_Main::i()->getVar('page_modules', substr(Usu_Main::i()->getVar('filename'), 0, -4))->retrieveDependencies();
     foreach ($dependencies as $get_key => $detail) {
         if (false !== strpos(Usu_Main::i()->getVar('request_uri'), $detail['marker'])) {
             // Found an seo marker so explode into two component parts
             $tmp = explode($detail['marker'], Usu_Main::i()->getVar('request_uri'));
             // assign the key=>value pair to _GET
             $value = false !== strpos($tmp[1], '.html') ? usu_cleanse(str_replace('.html', '', $tmp[1])) : usu_cleanse($tmp[1]);
             $_GET[$get_key] = $value;
             $HTTP_GET_VARS[$get_key] = $value;
             Usu_Main::i()->setVar('request_querystring', http_build_query($_GET));
             return $get_key . '=' . $value;
         }
     }
     return false;
 }
 /**
  * The main method of this class that receives input needed to build a link
  * then finally returns a fully built seo link if it has not previousluy returned false.
  * 
  * @see Usu_Main::getVar()
  * @see Usu_Main::setVar()
  * @see aPage_Modules::stripPathToLastNumber()
  * @see aPage_Modules::setQuery()
  * @see aPage_Modules::unsetProperties()
  * @see aPage_Modules::getDependencyKey()
  * @see aPage_Modules::setAllParams()
  * @see aPage_Modules::validRequest()
  * @see aPage_Modules::returnFinalLink()
  * @param string $page - valid osCommerce page name
  * @param string $parameters - querystring parameters
  * @param bool $add_session_id - true / false
  * @param string $connection - NONSSL / SSL
  * @param array $extract - array of _GET keys to remove from the querystring or bool false to do nothing
  * @uses trigger_error()
  * @throws - triggers an error of type E_USER_WARNING for an incorrect or inexistant dependency key
  * @access public
  * @return bool false - forces the system to return the standard osCommerce link wrapper
  * @return string - fully built seo url
  */
 public function buildLink($page, $parameters, $add_session_id, $connection)
 {
     $this->setAllParams($page, $parameters, $add_session_id, $connection, $extract = false);
     if (false === $this->validRequest()) {
         $this->unsetProperties();
         return false;
     }
     $this->key = $this->getDependencyKey();
     /**
      * If the shop has issues it may pass in null values, in this case return false to force the standard osCommerce link wrapper
      */
     if (!array_key_exists($this->key, $this->keys_index) || !tep_not_null($this->keys_index[$this->key])) {
         return false;
     }
     // Switch statement where the correct query and query marker replacements to use are selected via the _GET key detected
     switch (true) {
         case $this->key == 'products_id':
             // xxx = _GET key ( e.g. cPath )
             // This array contains replacements for the to_replace array ( see the $dependencies array )
             $this->setQuery(array(TABLE_PRODUCTS_DESCRIPTION, TABLE_PRODUCTS, $this->stripPathToLastNumber($this->keys_index[$this->key]), Usu_Main::i()->getVar('languages_id')));
             break;
         default:
             trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' Incorrect or inexistant dependency key.', E_USER_WARNING);
             break;
     }
     // end switch
     $link_text = $this->acquireLinkText();
     // If the query returned false then we return nothing and set $page_not_found to true forcing a 404 page
     Usu_Main::i()->setVar('page_not_found', false);
     if (false === $link_text) {
         Usu_Main::i()->setVar('page_not_found', true);
         $this->unsetProperties();
         return;
     }
     // Return a fully built seo url
     return $this->returnFinalLink(Usu_Main::i()->getVar('uri_modules', USU5_URLS_TYPE)->createLinkString($this->page, Usu_Main::i()->getVar('uri_modules', USU5_URLS_TYPE)->separateUriText($this->linktext($link_text)), $this->dependencies[$this->key]['marker'], $this->keys_index[$this->key]));
 }
Exemplo n.º 5
0
 /**
  * The page does not exist so we will show our custom 404 error page and header
  * 
  * @see Usu_Main::getVar()
  * @see Uri_Redirects::needsRedirect()
  * @see Usu_Validator::redirect()
  * @uses session_write_close()
  * @uses header()
  * @uses exit()
  * 
  * @access private
  * @return void
  */
 private function pageNotFound()
 {
     include_once Usu_Main::i()->getVar('includes_path') . 'uri_redirects_class.php';
     if (false !== ($url = Uri_Redirects::i()->needsRedirect())) {
         $this->redirect($url);
     }
     session_write_close();
     header("HTTP/1.0 404 Not Found");
     include_once Usu_Main::i()->getVar('includes_path') . 'notfound_404.php';
     exit;
 }
Exemplo n.º 6
0
 /**
  * Remove the language from the request uri if present
  * 
  * @uses preg_match()
  * @uses array_key_exists()
  * @uses str_replace()
  * 
  * @access protected
  * @return string - uri with language removed
  * 
  */
 protected function withoutLanguage()
 {
     preg_match('@^[a-z]{2}/@', Usu_Main::i()->getVar('request_uri'), $matches);
     if (array_key_exists(0, $matches)) {
         return str_replace($matches[0], '', Usu_Main::i()->getVar('request_uri'));
     }
     return Usu_Main::i()->getVar('request_uri');
 }
Exemplo n.º 7
0
 /**
  * Retrieve the cached data
  * 
  * If $insert becomes bool true then we insert data when storing, bool false we don't save as the cache already exists
  * 
  * @see Usu_Main::extractCacheData()
  * 
  * @access public
  * @return void
  */
 public function retrieve()
 {
     if (false !== self::$cache_on) {
         $this->insert = Usu_Main::i()->extractCacheData(self::$cache_name, 'sqlite', $this);
     }
 }
Exemplo n.º 8
0
 /**
  * The main method of this class that receives input needed to build a link
  * then finally returns a fully built seo link if it has not previousluy returned false.
  * 
  * @see Usu_Main::getVar()
  * @see Usu_Main::setVar()
  * @see aPage_Modules::stripPathToLastNumber()
  * @see aPage_Modules::setQuery()
  * @see aPage_Modules::unsetProperties()
  * @see aPage_Modules::getDependencyKey()
  * @see aPage_Modules::setAllParams()
  * @see aPage_Modules::validRequest()
  * @see aPage_Modules::returnFinalLink()
  * @param string $page - valid osCommerce page name
  * @param string $parameters - querystring parameters
  * @param bool $add_session_id - true / false
  * @param string $connection - NONSSL / SSL
  * @param array $extract - array of _GET keys to remove from the querystring or bool false to do nothing
  * @uses trigger_error()
  * @throws - triggers an error of type E_USER_WARNING for an incorrect or inexistant dependency key
  * @access public
  * @return bool false - forces the system to return the standard osCommerce link wrapper
  * @return string - fully built seo url
  */
 public function buildLink($page, $parameters, $add_session_id, $connection)
 {
     $extract = defined('USU5_ADD_CPATH_TO_PRODUCT_URLS') && USU5_ADD_CPATH_TO_PRODUCT_URLS == 'false' ? array('cPath', 'manufacturers_id') : array('manufacturers_id');
     $this->setAllParams($page, $parameters, $add_session_id, $connection, $extract);
     if (false === $this->validRequest()) {
         return false;
     }
     $this->key = $this->getDependencyKey();
     /**
      * If the shop has issues it may pass in null values, in this case return false to force the standard osCommerce link wrapper
      */
     if (!array_key_exists($this->key, $this->keys_index) || !tep_not_null($this->keys_index[$this->key])) {
         return false;
     }
     // Switch statement where the correct query and query marker replacements to use are selected via the _GET key detected
     switch (true) {
         case $this->key == 'products_id':
             // This array contains replacements for the to_replace array
             $this->setQuery(array(TABLE_PRODUCTS_DESCRIPTION, TABLE_PRODUCTS_TO_CATEGORIES, TABLE_PRODUCTS, TABLE_MANUFACTURERS, TABLE_CATEGORIES_DESCRIPTION, Usu_Main::i()->getVar('languages_id'), $this->keys_index[$this->key]));
             break;
         default:
             trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' Incorrect or inexistant dependency key.', E_USER_WARNING);
             break;
     }
     // end switch
     $link_text = $this->acquireLinkText();
     // If the query returned no results then we return false forcing the use of the standard osCommerce link wrapper
     Usu_Main::i()->setVar('page_not_found', false);
     if (false === $link_text) {
         Usu_Main::i()->setVar('page_not_found', true);
         $this->unsetProperties();
         return;
     }
     return $this->returnFinalLink(Usu_Main::i()->getVar('uri_modules', USU5_URLS_TYPE)->createLinkString($this->page, Usu_Main::i()->getVar('uri_modules', USU5_URLS_TYPE)->separateUriText($this->linktext($this->linkTextOrder($link_text))), $this->dependencies[$this->key]['marker'], $this->keys_index[$this->key]));
 }
 /**
  * Break up an osC experimental seo url into an _GET query
  * Add the key => value pairs to _GET and $HTTP_GET_VARS
  * @uses explode()
  * @uses count()
  * @uses http_build_query(
  * @see Usu_Main::setVar()
  * @see Usu_Main::getVar()
  * @see includes/usu_general_functions.php usu_cleanse()
  * 
  * @access public
  * @return string - querystring
  */
 public function parsePath()
 {
     global $HTTP_GET_VARS;
     Usu_Main::i()->setVar('parsing_module', __CLASS__);
     $tmp = explode('/', Usu_Main::i()->getVar('request_uri'));
     $count = count($tmp);
     for ($i = 0; $i < $count; $i = $i + 2) {
         $newget[usu_cleanse($tmp[$i])] = usu_cleanse($tmp[$i + 1]);
         // assign cleansed key=>value pair to _GET
         $_GET[usu_cleanse($tmp[$i])] = usu_cleanse($tmp[$i + 1]);
         $HTTP_GET_VARS[usu_cleanse($tmp[$i])] = usu_cleanse($tmp[$i + 1]);
     }
     Usu_Main::i()->setVar('request_querystring', http_build_query($_GET));
     // Newly created _GET array added to the querystring and converted to _GET string
     return http_build_query($newget);
 }
/**
 * Adds language code to a uri
 * @uses defined()
 * 
 * @param string $separator
 * @return string 2 letter language code with a / added if required
 */
function usu5_multi_language($separator = false)
{
    if (!defined('USU5_ENABLED') || USU5_ENABLED != 'true' || !defined('USU5_MULTI_LANGUAGE_SEO_SUPPORT') || USU5_MULTI_LANGUAGE_SEO_SUPPORT != 'true' || false === Usu_Main::i()->getVar('current_language', 'code') || DEFAULT_LANGUAGE == Usu_Main::i()->getVar('current_language', 'code')) {
        return false;
    }
    switch (true) {
        case $separator == 'left':
            return '/' . Usu_Main::i()->getVar('current_language', 'code');
            break;
        case $separator == 'right':
            return Usu_Main::i()->getVar('current_language', 'code') . '/';
            break;
        case $separator == 'both':
            return '/' . Usu_Main::i()->getVar('current_language', 'code') . '/';
            break;
        default:
            return Usu_Main::i()->getVar('current_language', 'code');
            break;
    }
}
Exemplo n.º 11
0
 /**
  * Initiate the registry and retrieve the cached data
  * 
  * @access private
  * @return void
  */
 private function setRegistry()
 {
     Usu_Main::i()->setVar('registry', Data_Registry::i());
     Usu_Main::i()->getVar('cache')->retrieve();
 }
Exemplo n.º 12
0
        tep_session_register('languages_id');
    }
    include DIR_WS_CLASSES . 'language.php';
    $lng = new language();
    if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {
        $lng->set_language($HTTP_GET_VARS['language']);
    } else {
        $lng->get_browser_language();
    }
    $language = $lng->language['directory'];
    $languages_id = $lng->language['id'];
}
/**
 * ULTIMATE Seo Urls 5 PRO by FWR Media
 */
Usu_Main::i()->setVar('languages_id', $languages_id)->setVar('request_type', $request_type)->setVar('session_started', $session_started)->setVar('sid', $SID)->setVar('language', $language)->setVar('filename', $PHP_SELF)->initiate(isset($lng) && $lng instanceof language ? $lng : array(), $languages_id, $language);
// include the language translations
$_system_locale_numeric = setlocale(LC_NUMERIC, 0);
require DIR_WS_LANGUAGES . $language . '.php';
setlocale(LC_NUMERIC, $_system_locale_numeric);
// Prevent LC_ALL from setting LC_NUMERIC to a locale with 1,0 float/decimal values instead of 1.0 (see bug #634)
// currency
if (!tep_session_is_registered('currency') || isset($HTTP_GET_VARS['currency']) || USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && LANGUAGE_CURRENCY != $currency) {
    if (!tep_session_is_registered('currency')) {
        tep_session_register('currency');
    }
    if (isset($HTTP_GET_VARS['currency']) && $currencies->is_set($HTTP_GET_VARS['currency'])) {
        $currency = $HTTP_GET_VARS['currency'];
    } else {
        $currency = USE_DEFAULT_LANGUAGE_CURRENCY == 'true' && $currencies->is_set(LANGUAGE_CURRENCY) ? LANGUAGE_CURRENCY : DEFAULT_CURRENCY;
    }
Exemplo n.º 13
0
 /**
  * Return a singleton instance of the class
  * 
  * @access public
  * @return Usu_Main
  */
 public static function i()
 {
     if (!self::$_singleton instanceof Usu_Main) {
         self::$_singleton = new self();
     }
     return self::$_singleton;
 }
Exemplo n.º 14
0
 /**
  * Formatter for URI text
  * 
  * Takes a text string and formats it based on existing settings
  * @uses is_array()
  * @uses strtr()
  * @uses str_replace()
  * @uses defined()
  * @uses preg_replace()
  * @uses strtolower()
  * @uses version_compare()
  * @uses is_numeric()
  * @uses explode()
  * @uses strlen()
  * @uses implode()
  * @param string $string - The raw URI string to be converted
  * 
  * @access protected
  * @return string - the final formated URI string
  */
 protected function linkTextParts($string)
 {
     // Action character conversions
     if (is_array(Usu_Main::i()->getVar('character_conversion'))) {
         $string = strtr($string, Usu_Main::i()->getVar('character_conversion'));
     }
     $string = str_replace('-', ' ', $string);
     // some strings will already have -(hyphen) so we convert them to spaces
     // Remove special characters
     $pattern = defined('SEO_REMOVE_ALL_SPEC_CHARS') && SEO_REMOVE_ALL_SPEC_CHARS == 'true' ? "@[^\\sa-z0-9]@i" : "@[!#\$%&'\"()\\*\\+,\\-\\./:;<=>\\?\\@\\[\\]\\^_`\\{|\\}~]+@";
     $link_text = preg_replace($pattern, '', strtolower($string));
     if (version_compare(PHP_VERSION, '5.2.4' == -1)) {
         $link_text = preg_replace("@[\\s]+@", '-', $link_text);
     } else {
         $link_text = preg_replace("@[\\s\v]+@", '-', $link_text);
     }
     // No short words so return the base text
     if (false === strpos($link_text, '-')) {
         return $link_text;
     }
     // Remove any words less than or equal in legnth the our filter
     if (defined('USU5_FILTER_SHORT_WORDS') && is_numeric(USU5_FILTER_SHORT_WORDS)) {
         $to_array = @explode('-', $link_text);
         $parts = array();
         foreach ($to_array as $index => $value) {
             if (strlen($value) > USU5_FILTER_SHORT_WORDS) {
                 $parts[] = $value;
             }
         }
         // end foreach
         return implode('-', $parts);
     }
     return $link_text;
 }
Exemplo n.º 15
0
 /**
  * Check that the cache directory is writeable
  * @uses trigger_error()
  * 
  * @access private
  * @throws - triggers an error of type E_USER_WARNING if the cache directory is not writeable
  * @return bool
  */
 private static function checkCacheWriteable()
 {
     $cache_file = Usu_Main::i()->getVar('cache_system_path') . 'cache/';
     if (false === usu5_make_writeable($cache_file)) {
         trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' could not make the cache directory writeable, you will need to do this manually.<br />' . $cache_file, E_USER_WARNING);
         return false;
     }
     return true;
 }
Exemplo n.º 16
0
function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true)
{
    return Usu_Main::i()->hrefLink($page, $parameters, $connection, $add_session_id, $search_engine_safe);
}