Пример #1
0
 function __construct()
 {
     if ($this->request('lang')) {
         $previous_lang = rad_lang::getCurrentLanguage();
         if (rad_lang::changeLanguage($this->request('lang'))) {
             //all is ok - redirecting
             if ($this->request('fromsite')) {
                 $this->redirect($this->makeURL('alias=' . $this->config('mainAlias')));
             } elseif (!empty($_SERVER['HTTP_REFERER'])) {
                 $ref = $_SERVER['HTTP_REFERER'];
                 if (mb_substr($ref, 0, mb_strlen(SITE_URL)) == SITE_URL and $this->getParamsObject() and $this->getParamsObject()->_get('returntorefferer', false)) {
                     $this->redirect(str_replace(SITE_URL . $previous_lang . '/', SITE_URL . rad_lang::getCurrentLanguage() . '/', $ref));
                 } else {
                     $this->redirect($this->makeURL('alias=' . $this->config('mainAlias')));
                 }
             } else {
                 $this->redirect($this->makeURL('alias=' . $this->config('mainAlias')));
             }
         } else {
             $this->redirect($this->makeURL('alias=' . $this->config('defaultAlias')), 'Error changing language!');
             die('can\'t change language');
         }
     } elseif ($this->request('action')) {
         $this->setVar('action', strtolower($this->request('action')));
         switch (strtolower($this->request('action'))) {
             case 'adminlng':
                 $this->changeAdminLanguage();
                 break;
             case 'contentlng':
                 $this->changeContentLanguage();
                 break;
             case 'getjs':
                 $this->getJS();
                 break;
             default:
                 $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName());
                 break;
         }
         //switch
     } else {
         $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName());
     }
 }
Пример #2
0
/**
* Модификатор date: unix_timestamp, date, datetime => дата на человеческом языке
*
* @param string $string
* @param string $format — 'date', 'time', 'datetime'
* @return string
*/
function smarty_modifier_date($string, $format = 'datetime')
{
    if (!isset($GLOBALS['config']['smarty.' . $format . '_format'][rad_lang::getCurrentLanguage()])) {
        trigger_error('Modifier date: invalid format specified in config!');
        return '';
    }
    $format = $GLOBALS['config']['smarty.' . $format . '_format'][rad_lang::getCurrentLanguage()];
    if (!is_numeric($string)) {
        // try to read date and datetime
        $timestamp = strtotime($string);
        if ($timestamp !== FALSE) {
            $string = $timestamp;
        }
    }
    // is this like unix_timestamp?
    if (is_numeric($string)) {
        // Month on human language
        $format = str_replace('%B', rad_lang::lang('-' . date('F', $string)), $format);
        return strftime($format, $string);
    }
    // we are still here? Something wrong...
    trigger_error('Invalid data for date modifier!');
    return '';
}
Пример #3
0
 /**
  * Makes the url from standart params
  * @param string $context
  * @param bool $url_aliases_enabled
  * @return string
  * @example makeURL('alias=index.html&page=2&itemsperpage=10&category=754')
  */
 public static function makeURL($context, $url_aliases_enabled = false)
 {
     static $alias_plugins = null;
     static $search = null;
     static $replace = null;
     if (!$alias_plugins) {
         $alias_plugins = rad_loader::getAliasInputClasses();
     }
     if (!$search) {
         $search = array('SITE_URL');
         $replace = array(SITE_URL);
         if (defined('SITE_ALIAS')) {
             $search[] = 'SITE_ALIAS';
             $replace[] = SITE_ALIAS;
         }
     }
     $c = str_replace($search, $replace, $context);
     if (is_link_external($c)) {
         return $c;
     }
     $r = strstr($c, '?');
     if ($r) {
         $c = substr($r, 1);
     }
     $r = explode('&', $c);
     $get = array();
     foreach ($r as $id) {
         $r1 = explode('=', $id);
         if (count($r1) >= 2) {
             $get[$r1[0]] = $r1[1];
         } else {
             $get[$r1[0]] = '';
         }
     }
     if (!isset($get['alias'])) {
         $get['alias'] = SITE_ALIAS;
     }
     if ($url_aliases_enabled && rad_config::getParam('cleanurl.on')) {
         if ($alias = rad_cleanurl::getAliasByParams($get)) {
             return SITE_URL . $alias;
         }
     }
     if (isset($alias_plugins[$get['alias']])) {
         $model = rad_instances::get($alias_plugins[$get['alias']]);
         $string = $model->makeurl($get);
     } else {
         if ((!count($get) or count($get) == 1 and isset($get['alias'])) and trim($get['alias']) == rad_config::getParam('defaultAlias')) {
             $string = SITE_URL;
         } else {
             if (rad_config::getParam('lang.location_show')) {
                 $string = SITE_URL . rad_lang::getCurrentLanguage() . '/' . $get['alias'] . '/';
             } else {
                 $string = SITE_URL . $get['alias'] . '/';
             }
             if (strlen($context)) {
                 foreach ($get as $prmname => $prmvalue) {
                     if ($prmname != 'alias') {
                         $string .= $prmname . '/' . $prmvalue . '/';
                     }
                 }
                 if (strpos($prmvalue, '.')) {
                     if ($string[strlen($string) - 1] == '/') {
                         $string = substr($string, 0, -1);
                     }
                 }
             }
         }
     }
     return $string;
 }
Пример #4
0
 /**
  * Gets the current language code string like en,us,ru,uk ...
  *
  * @return string
  */
 public function getCurrentLang()
 {
     return rad_lang::getCurrentLanguage();
 }
Пример #5
0
 /**
  * Makes the correct url from string to work with the access
  * It is not recommended overriding the function. Override protected _makeUrl*() instead.
  * @param array $get Parsed $GET array
  * @return string Full URI generated
  */
 public final function makeurl($get = array())
 {
     $string = SITE_URL;
     if (rad_config::getParam('lang.location_show')) {
         $string .= rad_lang::getCurrentLanguage() . '/';
     }
     $string .= $get['alias'] . '/';
     unset($get['alias']);
     $string .= $this->_makeUrlMiddle($get);
     $string .= $this->_makeUrlEnd($get);
     if (substr($string, -1) == '/') {
         $string .= 'index' . $this->_ending;
     } else {
         $string .= $this->_ending;
     }
     return $string;
 }
Пример #6
0
 /**
  * Makes the url from standart params
  * @param string $context
  * @param boolean $canonicad | false
  * @return string
  * @example makeURL('alias=index.html&page=2&itemsperpage=10&category=754')
  */
 function makeURL($string, $canonical = false)
 {
     if ($canonical) {
         return SITE_URL . 'index.php?lang=' . rad_lang::getCurrentLanguage() . (empty($string) ? '' : '&' . $string);
     }
     return rad_input::makeURL($string);
 }
Пример #7
0
/**
 * @example
 * {url type="js" module="core" file="..." load="sync|defer|async|inplace" tag="0"}
 *
 * Parameter "tag" is used only with type="js|css|image":
 * tag="0" - return only link
 * tag="1" - return html code
 * for type="image" default value is "0", for type="js|css" default value is "1"
 *
 * Parameter "load" is used only with type="js":
 * load="defer" - the script will not run until after the page has loaded (default value)
 * load="async" - the script will be run asynchronously
 * load="inplace" - the script will be insert into template where {url} tag was placed
 * load="sync" - the script will be run in order during the page rendering
 *
 * Parameter "attr" contains a list of additional attributes, that will be inserted into the tag
 * @example
 * {url type="css" module="core" file="..." attr="media=screen"}
 * {url type="image" module="core" file="..." attr="border=0&class=preview"}
 */
function smarty_function_url($params, $smarty)
{
    $valid_attributes = array('css' => array('media'), 'image' => array('class', 'border'));
    $params += array('load' => false, 'type' => '', 'tag' => isset($params['type']) && $params['type'] == 'image' ? 0 : 1, 'priority' => 0);
    if (isset($params['href']) != empty($params['file'])) {
        //Either both params are set or both ain't.
        if (rad_config::getParam('debug.showErrors')) {
            throw new rad_exception('url file=[EMPTY]!');
        } else {
            return '';
        }
    }
    if (isset($params['href'])) {
        $url = $params['href'];
        if (!is_link_absolute($url)) {
            if (!empty($params['canonical'])) {
                if (empty($url)) {
                    $url = SITE_URL . 'index.php?lang=' . rad_lang::getCurrentLanguage();
                } else {
                    $url = SITE_URL . 'index.php?lang=' . rad_lang::getCurrentLanguage() . '&' . $url;
                }
            } else {
                $url = rad_input::makeURL($url, true);
            }
        }
    } else {
        if (!empty($params['type'])) {
            if (!isset($params['module'])) {
                if (rad_config::getParam('debug.showErrors')) {
                    throw new RuntimeException("Module is required in {url type='{$params['type']}' TAG");
                } else {
                    return '';
                }
            }
            try {
                switch ($params['type']) {
                    case 'js':
                        $url = rad_jscss::getLinkToJS($params['module'], $params['file']);
                        break;
                    case 'css':
                        $url = rad_jscss::getLinkToCSS($params['module'], $params['file']);
                        break;
                    case 'dfile':
                        //TODO: implement per-component dfiles folders and dfiles caching.
                        return DOWNLOAD_FILES . $params['module'] . '/' . $params['file'];
                    case 'image':
                        $url = rad_gd_image::getLinkToImage($params['module'], $params['file'], $params['preset']);
                        break;
                    default:
                        throw new rad_exception("Wrong parameter type in {url type='{$params['type']}'}");
                }
            } catch (Exception $e) {
                if (rad_config::getParam('debug.showErrors')) {
                    throw $e;
                } else {
                    return '';
                }
            }
            /* TODO: some draft for future #850 implementation
               } elseif(get_class($params['file'])=='struct_core_files') {
                   if(!isset($params['module'])) {
                       $smarty->_syntax_error("url: missing 'module' parameter for struct_core_files class when genere url", E_USER_ERROR);
                   }
                   $module = $params['module'];
                   if( rad_input::getDefine( strtoupper($module.'PATH') ) != strtoupper($module.'PATH') ) {
                       return SITE_URL.str_replace( rad_input::getDefine('rootPath') ,'', rad_input::getDefine( strtoupper($module.'PATH') ));
                   } elseif(rad_input::getDefine('DOWNLOAD_FILES')!='DOWNLOAD_FILES') {
                       return DOWNLOAD_FILES.$params['file']->rfl_filename.'/'.$module.'/'.$params['file']->rfl_name;
                   } else {
                       throw new rad_exception('DOWNLOAD_FILES_DIR or '.strtoupper($module.'PATH').' not defined in config!');
                   }
               */
        } elseif (get_class($params['file']) == 'struct_corecatalog_cat_files') {
            return DOWNLOAD_FILES . $params['file']->rcf_filename . '/' . $params['file']->rcf_name;
        } else {
            if (rad_config::getParam('debug.showErrors')) {
                throw new rad_exception('Unknown class in url function "' . get_class($params['file']) . '" ', __LINE__);
            } else {
                return '';
            }
        }
    }
    if (!empty($params['type']) && $params['tag']) {
        $attributes = '';
        if (!empty($params['attr']) && !empty($valid_attributes[$params['type']])) {
            parse_str($params['attr'], $attr_array);
            $attributes_array = array_intersect_key($attr_array, array_flip($valid_attributes[$params['type']]));
            foreach ($attributes_array as $k => $v) {
                $v = htmlspecialchars($v);
                $attributes .= " {$k}='{$v}'";
            }
        }
        switch ($params['type']) {
            case 'js':
                switch ($params['load']) {
                    case 'async':
                        $attributes .= " async='true'";
                    case 'defer':
                        //NB: also for "async" mode for IE compatibility
                        $attributes .= " defer='true'";
                }
                $html = "<script type='text/javascript' src='{$url}'{$attributes}></script>";
                if ($params['load'] == 'inplace') {
                    return $html;
                }
                if (isset($params['href'])) {
                    rad_jscss::addFile('--EXTERNAL--', $params['href'], $html, (int) $params['priority']);
                } else {
                    rad_jscss::addFile($params['module'], $params['file'], $html, (int) $params['priority']);
                }
                return '';
            case 'css':
                $html = "<link rel='stylesheet' type='text/css' href='{$url}'{$attributes} />";
                if (isset($params['href'])) {
                    rad_jscss::addFile('--EXTERNAL--', $params['href'], $html, (int) $params['priority']);
                } else {
                    rad_jscss::addFile($params['module'], $params['file'], $html, (int) $params['priority']);
                }
                return '';
            case 'image':
                return "<img src='{$url}'{$attributes} />";
        }
    }
    return $url;
}
Пример #8
0
 /**
  * Function that is called to show all variables and all the page!
  */
 public static function show()
 {
     $o = rad_rsmarty::getSmartyObject();
     //TODO: optimize memory
     if (count(self::$_html)) {
         foreach (self::$_html as $key => $value) {
             $o->assign($key, $value);
         }
     }
     $o->assign('_CURR_LANG_', rad_lang::getCurrentLanguage());
     if (isset(self::$sendedParams[self::$_alias->filename])) {
         foreach (self::$sendedParams[self::$_alias->filename] as $pkey => $pval) {
             $o->assign($pkey, $pval);
         }
     }
     $file = rad_themer::getFilePath(null, 'templates', 'core', 'maintemplates' . DS . self::$_alias->filename . '.tpl');
     rad_instances::setCurrentTemplate($file, true);
     $o->display($file);
 }