function getUntranslated() { $result = array(); $files = glob(rad_config::getParam('lang.cacheDir') . "*.cachenf"); if (!empty($files)) { foreach ($files as $file) { if ($this->getState('lang', $this->getState('lang_id'))) { $res = json_decode(file_get_contents($file)); foreach ($res as $url => &$d1) { foreach ($d1 as $lngId => &$d2) { if ($this->getState('lang', $this->getState('lang_id')) != $lngId) { unset($res->{$url}->{$lngId}); } } if (empty($res->{$url})) { unset($res->{$url}); } } } else { $result[] = json_decode(file_get_contents($file)); } } } return $result; }
protected function __construct() { include SPHINXPATH . 'sphinxapi.php'; $this->_sphinx = new SphinxClient(); $this->_sphinx->SetServer(rad_config::getParam('sphinx.host'), rad_config::getParam('sphinx.port')); $this->_sphinx->SetMatchMode(SPH_MATCH_EXTENDED); }
public static function setHandlers() { self::setErrorHandler(); self::setExceptionHandler(); if (rad_config::getParam('debug.showErrors', true)) { ini_set('display_errors', 1); error_reporting(rad_config::getParam('debug.reportingLevel', E_ALL)); } else { ini_set('display_errors', 0); } }
function __construct() { if ($this->getParamsObject()) { $params = $this->getParamsObject(); $params->substring_checkbox = rad_config::getParam('sphinx.on') && rad_config::getParam('sphinx.substring_search') == 'allow'; $params->substring_checked = $params->substring_checkbox && $this->get('ss'); $this->setVar('search', $this->request('s', '')); $this->setVar('params', $params); if (rad_config::getParam('sphinx.on')) { $this->setVar('autocomplete_url', $this->makeURL('alias=searchxml&action=autocomplete') . 'term/'); } } }
function smarty_function_sendtotpl($params, $template) { if (!isset($params['var'])) { throw new Exception("currency: missing 'var' parameter", E_USER_WARNING); } if (!isset($params['value'])) { throw new Exception("currency: missing 'value' parameter", E_USER_WARNING); } if (!isset($params['template'])) { throw new Exception("currency: missing 'template' parameter", E_USER_WARNING); } call_user_func_array(array(rad_config::getParam('loader_class'), 'sendToTemplate'), array($params['template'], $params['var'], $params['value'])); //rad_ sloader::sendToTemplate($params['template'],$params['var'],$params['value']); return ''; }
function smarty_function_config($params, $smarty) { if (!isset($params['get'])) { throw new rad_exception('Not enouph actual parameters for tag {config', __LINE__); } $params['get'] = $params['get'][0] == '"' ? substr($params['get'], 1, -1) : $params['get']; $params['get'] = $params['get'][0] == '\'' ? substr($params['get'], 1, -1) : $params['get']; if (!empty($params['assign'])) { $params['assign'] = $params['assign'][0] == '"' ? substr($params['assign'], 1, -1) : $params['assign']; $params['assign'] = $params['assign'][0] == '\'' ? substr($params['assign'], 1, -1) : $params['assign']; $smarty->assign(trim($params['assign']), rad_config::getParam($params['get'])); return ''; } else { return rad_config::getParam($params['get']); } }
/** * Init and gets all the params and make the html strings! * @return Boolean - if all is good */ public static function initandmake(struct_core_alias $alias) { $o = rad_rsmarty::getSmartyObject(); $o->assign('lang', call_user_func(array(rad_config::getParam('loader_class'), 'getLangContainer'))); foreach (self::$_varvals as $classname => $vrnn) { foreach ($vrnn as $varname => $varvalue) { $o->assign('<%' . $classname . '.' . $varname . '%>', $varvalue); } $o->assign($classname, $vrnn); } $srcPrefix = SMARTYBCCACHE . 'alias_' . $alias->id . '_'; self::$_title = self::_fetchSrc($o, $srcPrefix . 'title.tpl', $alias->title_script); self::$_breadcrumbs = self::_fetchSrc($o, $srcPrefix . 'bc.tpl', $alias->navi_script); self::$_tags = self::_fetchSrc($o, $srcPrefix . 'meta.tpl', $alias->metatitle_script); self::$_description = self::_fetchSrc($o, $srcPrefix . 'descr.tpl', $alias->metadescription_script); $o->clearAllAssign(); return true; }
/** * parse templates from alias and assing variables from Controller To Templates * Also I think I can do that in function show() */ public static function parseTemplates() { $o = rad_rsmarty::getSmartyObject(); if (rad_config::getParam('lang.caching')) { $templates = array(); foreach (self::$_alias->includes as $id) { $templates[] = self::$_includes[$id->inc_name]; } self::loadLangCache($templates); } //No needed - fix to {lang code= in older modules rad_instances::setCurrentTemplate('BREADCRUMBS'); self::$_langContainer->setTemplate('BREADCRUMBS'); define(rad_config::getParam('bc.title'), rad_breadcrumbs::getTitle()); define(rad_config::getParam('bc.meta_description'), rad_breadcrumbs::getMetaDescription()); define(rad_config::getParam('bc.meta_tags'), rad_breadcrumbs::getMetaTags()); define(rad_config::getParam('bc.breadcrumbs'), rad_breadcrumbs::getBreadcrumbs()); foreach (self::$_alias->includes as $id) { if (isset(self::$_controllerResults[$id->incinal_id]) and self::$_controllerResults[$id->incinal_id]) { if (isset(self::$sendedParams[$id->inc_filename]) and count(self::$sendedParams[$id->inc_filename])) { foreach (self::$sendedParams[$id->inc_filename] as $pkey => $pval) { $o->assign($pkey, $pval); } } $data = self::$_controllerResults[$id->incinal_id]->getVars(); if ($data !== null) { foreach ($data as $key => $value) { $o->assign($key, $value); } } } if (!isset(self::$_html[$id->rp_name])) { self::$_html[$id->rp_name] = ''; } rad_instances::setCurrentTemplate(self::$_includes[$id->inc_name]); self::$_langContainer->setTemplate(self::$_includes[$id->inc_name]); $o->assign('_CURRENT_LOAD_PATH', dirname(self::$_includes[$id->inc_name])); $o->assign('_CURR_LANG_OBJ', rad_lang::getCurrentLanguage()); self::$_html[$id->rp_name] .= $o->fetch(self::$_includes[$id->inc_name]); $o->clearAllAssign(); } //foreach }
function smarty_function_lang($params, $smarty) { if (!isset($params['code'])) { throw new rad_exception("lang: missing 'code' parameter", E_USER_WARNING); } $params['code'] = trim($params['code'], " \t\"'"); if (isset($params['lang'])) { $val = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array($params['code'], $params['lang'])); } else { $val = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array($params['code'])); } if (isset($params['find']) && isset($params['replace'])) { if (!is_array($params['find'])) { $params['find'] = array($params['find']); } if (!is_array($params['replace'])) { $params['replace'] = array($params['replace']); } if (count($params['find']) != count($params['replace'])) { throw new rad_exception('lang: find/replace params should either be both scalar or be arrays of the same size'); } $find = reset($params['find']); $replace = reset($params['replace']); while ($find) { $val = mb_str_replace($val, $find, $replace); $find = next($params['find']); $replace = next($params['replace']); } } if (!empty($params['htmlchars'])) { $val = mb_str_replace($val, '"', '"'); } if (!empty($params['ucf'])) { $val = mb_ucfirst($val); } if (isset($params['assign'])) { $smarty->assign($params['assign'], $val); } else { return $val; } }
/** * Returns Smarty Object or null * @var Smarty * @return Smarty */ public static function getSmartyObject() { if (!self::$object) { if (!class_exists('Smarty', false)) { if (!file_exists(SMARTYPATH . 'Smarty.class.php')) { die(SMARTYPATH . 'Smarty.class.php does not exists!'); } include_once SMARTYPATH . 'Smarty.class.php'; } self::$object = new Smarty(); self::$object->compile_check = rad_config::getParam('smarty.compile_check', true); self::$object->debugging = rad_config::getParam('smarty.debugging;', false); self::$object->template_dir = rad_config::getParam('rootPath'); //NB: Looks like this parameter is never used since we use absolute adressing. self::$object->compile_dir = SMARTYCOMPILEPATH; self::$object->caching = rad_config::getParam('smarty.caching', false); self::$object->cache_dir = SMARTYCACHEPATH; self::$object->muteExpectedErrors(); self::$object->loadPlugin('smarty_compiler_switch'); } return self::$object; }
function __construct() { $this->setVar('hash', $this->hash()); if ($this->request('action')) { $this->setVar('action', $this->request('action')); switch ($this->request('action')) { case 'getjs': $this->getJS(); break; case 'save': $this->save(); break; } } $configParams = array(); foreach ($this->_allowedConfigFields as $field) { $configParams[$field] = rad_config::getParam($field); } $this->setVar('configParams', $configParams); $this->assignThemes(); $this->setVar('languages', rad_instances::get('model_core_lang')->getItems()); }
public static function getAliasByName(&$aliasname = '') { $result = self::getAliasRecord($aliasname); if (!$result->id || !$result->active) { rad_session::setVar('message', $aliasname); $aliasname = rad_config::getParam('alias.404'); $result = self::getAliasRecord(self::$alias); header(rad_config::getParam('header.404')); } if ($result->ali_admin && !rad_session::adminAccess()) { rad_session::setVar('message', $aliasname); rad_session::logout(); $aliasname = rad_config::getParam('alias.loginform'); $result = self::getAliasRecord(self::$alias); } if ($result->id) { $result->includes = array(); $themeId = $result->themeid ? $result->themeid : 0; $sqlParams = array('alias_1_id' => $result->id, 'theme_1_id' => $themeId); if ($result->group_id) { $sqlParams['alias_2_id'] = $result->group_id; $theme2Id = rad_dbpdo::query('SELECT theme_id FROM ' . RAD . 'themes WHERE theme_aliasid=? AND theme_folder=?', array($result->group_id, rad_themer::getCurrentTheme())); $theme2Id = !empty($theme2Id['theme_id']) ? (int) $theme2Id['theme_id'] : $themeId; $sqlParams['theme_2_id'] = $theme2Id; } $sql = 'SELECT inc_id,inc_name,inc_filename,controller,order_sort,rp_name,id_module,m_name,params_hash,ina.id as incinal_id,ina.params_presonal as params_presonal, ip.ip_params as original_params ' . 'FROM ' . RAD . 'includes_in_aliases ina ' . 'INNER JOIN ' . RAD . 'includes on include_id=inc_id ' . 'INNER JOIN ' . RAD . 'modules m on m.m_id=id_module ' . 'INNER JOIN ' . RAD . 'positions p on position_id=p.rp_id ' . 'LEFT JOIN ' . RAD . 'includes_params ip on ip.ip_incid=ina.include_id ' . 'WHERE alias_id=:alias_1_id' . ' AND ina.theme_id=:theme_1_id' . ($result->group_id ? ' UNION (SELECT inc_id,inc_name,inc_filename,controller,order_sort,rp_name,id_module,m_name,params_hash,ina.id as incinal_id,ina.params_presonal as params_presonal, ip.ip_params as original_params ' . 'FROM ' . RAD . 'includes_in_aliases ina ' . 'INNER JOIN ' . RAD . 'includes on include_id=inc_id ' . 'INNER JOIN ' . RAD . 'modules m on m.m_id=id_module ' . 'INNER JOIN ' . RAD . 'positions p on position_id=p.rp_id ' . 'LEFT JOIN ' . RAD . 'includes_params ip on ip.ip_incid=ina.include_id ' . 'WHERE alias_id=:alias_2_id' . ' AND ina.theme_id=:theme_2_id' . ')' : '') . ' ORDER BY order_sort, rp_name'; foreach (rad_dbpdo::queryAll($sql, $sqlParams) as $id) { $result->includes[] = new struct_core_include($id); } } else { $result = NULL; } return $result; }
final function config($paramname, $defaultValue = NULL) { return rad_config::getParam($paramname, $defaultValue); }
/** * Edit the product - shows the edit form * * @return html Full page edit form */ function editForm() { $cat_id = (int) $this->request('cat_id'); if ($cat_id) { $this->setVar('cat_id', $cat_id); $model = rad_instances::get('model_coremenus_tree'); $model->setState('pid', $this->request('pid', $this->_pid))->setState('lang', $this->getContentLangID()); $this->setVar('trees', $model->getItems(true)); $model->setState('pid', $this->_pid_types); $producttypes = $model->getItems(true); $firest_el = new struct_coremenus_tree(); $firest_el->tre_name = $this->lang('-pleaseselect'); array_unshift($producttypes, $firest_el); $this->setVar('producttypes', $producttypes); $this->setVar('currencys', rad_instances::get('model_corecatalog_currency')->getItems()); /** FOR MEASUREMENT IN RIGHT PANEL WHITCH NAMED "MAGAZINE" $model = new model_core_table('measurement','corecatalog'); $model->setState('order by','ms_position,ms_value'); $measurements = $model->getItems(); $this->setVar( 'measurements', $measurements ); */ $model_product = rad_instances::get('model_corecatalog_catalog'); if ($this->_have_downloads) { $model_product->setState('with_download_files', true); } if ($this->_have_tags) { $model_product->setState('with_tags', true); } $product = $model_product->getItem($cat_id); $this->addBC('product', $product->cat_name); $model->clearState(); $tree_link = $this->product ? $this->product->tree_link : $product->tree_catin_link; if (count($tree_link)) { $curr_cat = $model->getItem($tree_link[0]->cit_tre_id); $this->addBC('curr_cat', $curr_cat); $cat_path = $model->getCategoryPath($curr_cat, $this->_pid, 0); unset($cat_path[0]); $this->addBC('parents', $cat_path); $mas = array(); foreach ($tree_link as $id) { $mas[] = $id->cit_tre_id; } $this->setVar('selected_tree', $mas); } //if count catin_link $model = rad_instances::get('model_corecatalog_brands'); $this->setVar('brands', $model->getListBrands()); $this->setVar('product', $product); $this->setVar('cleanurl_enabled', rad_config::getParam('cleanurl.on')); if ($cat_id && rad_config::getParam('cleanurl.on')) { $this->setVar('url_alias', rad_cleanurl::getAlias('product', $cat_id)); } include_once 'helpers' . DS . 'fileuploader.php'; $uploader = new fileuploader($this); $imageWidgets = array($uploader->initWidget('images', array(), '', CORECATALOG_IMG_PATH, 'catalog', true)); $this->setVar('widgets', $imageWidgets); $this->get3DBinItems($cat_id); } else { //if $cat_id $this->securityHoleAlert(__FILE__, __LINE__, $this->getClassName()); } }
protected function makeUrl($page) { if ($page == 1 and SITE_ALIAS == rad_config::getParam('defaultAlias', 'index.html')) { return SITE_URL; } $current = $this->currentPage == $this->rightNeighbour ? true : false; $gp = strlen($this->getParams) ? '&' . $this->getParams : ''; $site_alias = SITE_ALIAS; if ($this->addAliasXML and substr($site_alias, -3) != 'XML') { $site_alias .= 'XML'; } return rad_input::makeURL('alias=' . $site_alias . $gp . ($page > 1 ? '&' . $this->getParam . '=' . $page : '')); }
/** * Download the code from the cache * node_id(int) */ function installCachedLang($node_id) { $controller_temp = rad_config::getParam('lang.cacheDir'); $pr = $this->allTemplate($controller_temp); $rs = array(); $no_code = array(); if (is_array($pr)) { foreach ($pr as $v) { $rs[] = $this->_readCachedLangueges($v); } if (is_array($rs)) { foreach ($rs as $k => $v) { if (is_array($v)) { foreach ($v as $vk) { if ($this->noCodeValue($vk, $node_id)) { $no_code[] = $this->noCodeValue($vk, $node_id); } } } } } } if (is_array($no_code)) { foreach ($no_code as $value) { if ($value) { $model = rad_instances::get('model_core_langvalues'); $rows = $model->insertItem($value); if ($rows) { //echo 'RADLangList.message("'.addslashes( $this->lang('deletedrows.lang.message') ).': '.$rows.'");'; } else { //echo 'RADLangList.message("'.addslashes( $this->lang('deleted.lang.error') ).': '.$rows.'");'; } } else { echo 'RADLangList.message("' . addslashes($this->lang('update.lang.error')) . '");'; } } } }
/** * Formats cost depending on the amount of entered in the admin settings * @param number $cost * @return float format */ public static function formatCost($cost, $curId = null) { self::init(); $currency = $curId ? self::$_currs[$curId] : self::$_curcours; $decimal_separator = $currency->cur_decimal_separator ?: rad_config::getParam('currency.decimal_separator', '.'); $group_separator = $currency->cur_group_separator ?: rad_config::getParam('currency.group_separator', ' '); return number_format($cost, (int) rad_config::getParam('currency.precision'), $decimal_separator, $group_separator); }
/** * @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; }
/** * 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; }
function smarty_function_paginator($params, $smarty) { /** * Default params */ $step = 1; $maxshow = 30; $showsteps = false; $showfirst = false; $showlast = false; $show_long_listing = false; $first_title_text = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array('-first')); $last_title_text = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array('-last')); $next_title_text = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array('-next')); $prev_title_text = call_user_func_array(array(rad_config::getParam('loader_class'), 'lang'), array('-prev')); $long_listing_text = '..'; $num_delimiter = ' '; $alias = SITE_ALIAS; $page_varname = 'p'; if (!isset($params['from'])) { throw new rad_exception("paginator: missing 'from' parameter", E_USER_ERROR); } $from = (int) $params['from']; if (!isset($params['to'])) { throw new rad_exception("paginator: missing 'to' parameter", E_USER_ERROR); } $to = (int) $params['to']; if (!isset($params['curpage'])) { throw new rad_exception("paginator: missing 'curpage' parameter", E_USER_ERROR); } $curpage = (int) $params['curpage']; if (isset($params['step'])) { $step = (int) $params['step']; } if (!$step or $step <= 0) { throw new rad_exception("paginator: default parameter 'step' can't be < or = 0 ", E_USER_ERROR); } if (isset($params['maxshow'])) { $maxshow = (int) $params['maxshow'] - 1; } if (!$maxshow or $maxshow <= 1) { throw new rad_exception("paginator: default parameter 'maxshow' can't be < or = 1 ", E_USER_ERROR); } if (isset($params['long_listing_text'])) { $long_listing_text = $params['long_listing_text']; } $showsteps = isset($params['showsteps']) ? (bool) $params['showsteps'] : $showsteps; $showfirst = isset($params['showfirst']) ? (bool) $params['showfirst'] : $showfirst; $showlast = isset($params['showlast']) ? (bool) $params['showlast'] : $showlast; $show_long_listing = isset($params['show_long_listing']) ? (bool) $params['show_long_listing'] : $show_long_listing; $first_title_text = isset($params['first_title_text']) ? (string) rad_sloader::lang($params['first_title_text']) : $first_title_text; $last_title_text = isset($params['last_title_text']) ? (string) rad_sloader::lang($params['last_title_text']) : $last_title_text; $next_title_text = isset($params['next_title_text']) ? (string) rad_sloader::lang($params['next_title_text']) : $next_title_text; $prev_title_text = isset($params['prev_title_text']) ? (string) rad_sloader::lang($params['prev_title_text']) : $prev_title_text; $num_delimiter = isset($params['num_delimiter']) ? (string) $params['num_delimiter'] : $num_delimiter; $alias = isset($params['alias']) ? (string) $params['alias'] : $alias; $page_varname = isset($params['page_varname']) ? (string) $params['page_varname'] : $page_varname; $bothldelimiter = isset($params['bothldelimiter']) ? (string) $params['bothldelimiter'] : ''; $bothrdelimiter = isset($params['bothrdelimiter']) ? (string) $params['bothrdelimiter'] : ''; /**** Calculate and return values ******/ $return = ''; /*** Parse GET params ******/ $get_params = array(); if (isset($params['GET']) and strlen($params['GET'])) { if ($params['GET'][0] == '&') { substr($params['GET'], 1); } $pt = explode('&', $params['GET']); if (count($pt)) { foreach ($pt as $ptID => $ptVL) { $pv = explode('=', $ptVL); if (count($pv) > 1) { $get_params[trim($pv[0])] = trim($pv[1]); } } } } $get_params['alias'] = $alias; //TODO Сделать чтобы при переходе на первую страницу или назад(если таже самая страница будет при клике назад) - небыло ссылки if ($showfirst) { $get_params[$page_varname] = $from; if ($get_params[$page_varname] == $from) { unset($get_params[$page_varname]); } $return .= $bothldelimiter . '<a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $first_title_text . '</a> ' . $bothrdelimiter; if (isset($get_params[$page_varname])) { unset($get_params[$page_varname]); } } if ($showsteps) { $get_params[$page_varname] = $curpage == $from ? $curpage : $curpage; if ($get_params[$page_varname] == $from) { unset($get_params[$page_varname]); } else { $get_params[$page_varname]--; $return .= $bothldelimiter . '<a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $prev_title_text . '</a> ' . $bothrdelimiter; } if (isset($get_params[$page_varname])) { unset($get_params[$page_varname]); } } if ($show_long_listing) { $get_params[$page_varname] = $curpage - $maxshow - 1 <= $from ? $from : $curpage - $maxshow - 1; if ($from + $maxshow >= $curpage) { unset($get_params[$page_varname]); } else { $return .= $bothldelimiter . '<a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $long_listing_text . '</a> ' . $bothrdelimiter; } if (isset($get_params[$page_varname])) { unset($get_params[$page_varname]); } } $return_pag = array(); //$maxshow if ($from == $to - 1) { $return_pag[] = $bothldelimiter . '<font class="pages_active last">1</font>' . $bothrdelimiter; } else { for ($i = $from; $i < $to - 1; $i = $i + $step) { if ($i >= $curpage - $maxshow and $i <= $curpage + $maxshow) { if ($curpage == $i) { $return_pag[] = $bothldelimiter . '<font class="pages_active' . ($i == $to - 2 ? ' last' : '') . '">' . (string) ($i + 1) . '</font>' . $bothrdelimiter; } else { $get_params[$page_varname] = $i; $return_pag[] = $bothldelimiter . '<font class="pages_active' . ($i == $to - 2 ? ' last' : '') . '"><a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">[' . ($i + 1) . ']</a></font>' . $bothrdelimiter; } } } } $return .= implode($num_delimiter, $return_pag); if ($show_long_listing) { $get_params[$page_varname] = $curpage + $maxshow + 1 >= $to - 2 ? $curpage : $curpage + $maxshow + 1; $get_params[$page_varname] = $get_params[$page_varname] == 0 ? $curpage + $maxshow + 1 : $get_params[$page_varname]; if ($curpage + $maxshow < $to - 2) { $return .= $bothldelimiter . ' <a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $long_listing_text . '</a> ' . $bothrdelimiter; } unset($get_params[$page_varname]); } if ($showsteps) { if ($curpage != $to - 2) { $get_params[$page_varname] = $curpage == $to - 2 ? $curpage : $curpage + 1; $return .= $bothldelimiter . ' <a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $next_title_text . '</a> ' . $bothrdelimiter; unset($get_params[$page_varname]); } } if ($showlast) { $get_params[$page_varname] = $to - 2; if ($get_params[$page_varname] != $to) { $return .= $bothldelimiter . '<a href="' . smarty_function_url(array('href' => smarty_function_paginator_make_get($get_params)), $smarty) . '">' . $last_title_text . '</a>' . $bothrdelimiter; } unset($get_params[$page_varname]); } if ($to > 2) { return $return; } return ''; }
private static function _renewCache($module, $file, $type) { $filename = fixPath($file); $cacheFile = CACHEPATH . $type . DS . self::$themeName . DS . $module . DS . $filename; $cachePath = dirname($cacheFile); if (!file_exists($cachePath)) { recursive_mkdir($cachePath); } if (file_exists($cacheFile) && time() - filemtime($cacheFile) < rad_config::getParam('cache.power.time')) { return true; } if ($fname = rad_themer::getFilePath(self::$themeName, 'jscss', $module, $filename)) { return self::copyToCache($fname, $cacheFile); } return false; }
/** * Assign theme folders * */ function assignThemes() { $this->setVar('theme_default', rad_config::getParam('theme.default')); $this->setVar('themes', rad_themer::getThemes()); $this->setVar('curr_theme', call_user_func(array(rad_config::getParam('loader_class'), 'getCurrentTheme'))); }
/** * Install the file * @param string $filename - specified filename with @CONSTANT@ without root start path to RADCMS * @param float $version */ public function installFile($filename, $version) { $fileContent = $this->_getURL($this->_url, array('action' => 'getfile', 'version' => $version, 'filename' => $filename)); if (strlen($fileContent)) { $search = array('@LIBPATH@', '@COMPONENTSPATH@', '@THEMESPATH@', '@SMARTYPATH@', '@ROOTPATH@'); $replace = array(LIBPATH, COMPONENTSPATH, THEMESPATH, SMARTYPATH, rad_config::getParam('rootPath')); $fullFileName = str_replace($search, $replace, $filename); $this->mkFile($fullFileName, $fileContent, 0777); } else { throw new rad_exception('File "' . $filename . '" with version "' . $version . '" is empty'); } }
/** * 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; }
public static function redirectUrl($params) { $string = 'alias='; switch ($params['type']) { case self::TYPE_INDEX: $string .= rad_config::getParam('defaultAlias'); break; case self::TYPE_ARTICLE: $string .= 'articles&a=' . (int) $params['item_id']; break; case self::TYPE_CATALOG: $string .= 'catalog&cat=' . (int) $params['item_id']; break; case self::TYPE_NEWS: $string .= 'news&nid=' . (int) $params['item_id']; break; case self::TYPE_PAGE: $string .= 'page&pgid=' . (int) $params['item_id']; break; case self::TYPE_PRODUCT: $string .= 'product&p=' . (int) $params['item_id']; break; } rad_input::redirect(rad_input::makeURL($string)); }
public static function prepareImages(array $files) { $theme = rad_themer::getCurrentTheme(); foreach ($files as $file) { $fileOriginal = rad_themer::getFilePath($theme, 'img', $file['module'], $file['file']); $fileCached = CACHEPATH . 'img' . DS . $theme . DS . $file['module'] . DS . 'original' . DS . fixPath($file['file']); if (file_exists($fileCached)) { if (time() - filemtime($fileCached) < rad_config::getParam('cache.power.time')) { continue; //File is already cached } } else { $cachePath = dirname($fileCached); if (!is_dir($cachePath) && !recursive_mkdir($cachePath)) { throw new RuntimeException('Could not create cache folder for image'); } } copy($fileOriginal, $fileCached); } }
public static function getCurrentTheme() { static $theme; if (isset($theme)) { return $theme; } if (($theme = @$_SESSION['theme']) && ($theme == 'default' || self::themeExists($theme))) { return $theme; } if (!empty($_SERVER['HTTP_REFERER']) && preg_match('~^' . preg_quote($GLOBALS['config']['url']) . 'cache/(?:js|css)/([a-z0-9]+)/~i', $_SERVER['HTTP_REFERER'], $matches)) { $theme = $matches[1]; if ($theme == 'default' || self::themeExists($theme)) { return $theme; } } if (!empty($_GET['th'])) { $theme = urldecode($_GET['th']); if ($theme == 'default' || self::themeExists($theme)) { return $theme; } } $theme = rad_config::getParam('theme.default'); if ($theme == 'default' || self::themeExists($theme)) { return $theme; } $theme = $GLOBALS['config']['theme.default']; if ($theme == 'default' || self::themeExists($theme)) { return $theme; } $theme = 'default'; return $theme; }
private function substringSearchChecked() { return rad_config::getParam('sphinx.on') && rad_config::getParam('sphinx.substring_search') == 'allow' && $this->request('ss'); }
/** * Gets the main javascript for the page */ function getJS() { $this->setVar('ROOT_PID', addslashes(str_replace(rad_config::getParam('rootPath'), '', TEMPLATESPATH))); $this->setVar('lang', $this->getCurrentLang()); $this->header('Content-type: text/javascript'); }
protected function getValValuesCache() { $file = self::getCacheFileName($this->_catIds, $this->_cat->tre_id); $result = NULL; if (is_file($file)) { $data = unserialize(file_get_contents($file)); if ($data['date'] >= time() - rad_config::getParam('cache.power.time')) { $result = $data['rows']; } } if (!$result) { $result = $this->getValValues(); $data = array('date' => time(), 'rows' => $result); safe_put_contents($file, serialize($data)); } return $result; }