Ejemplo n.º 1
0
 /**
  * Simple log now text in param to DB table, also record in table time and other data
  * @param string text
  */
 public static function logerr($text)
 {
     if (rad_config::getParam('logger.loginDB', false)) {
         $flush = rad_input::getFlushInput();
         //die(rad_config::getParam('loader_class'));
         $flush['input'] = call_user_func(array(rad_config::getParam('loader_class'), 'getFlushData'));
         $flush = serialize($flush);
         $flush = str_replace('"', '\\"', $flush);
         rad_dbpdo::exec('insert into ' . RAD . 'logger(dt,flush,`text`)values(now(),"' . $flush . '","' . $text . '")');
     }
 }
Ejemplo n.º 2
0
 /**
  * Get URL using URL alias
  * @static
  * @param string $alias
  * @return false|string
  */
 public static function getUrlByAlias($alias)
 {
     $result = rad_dbpdo::query('SELECT item_type, item_id, lang_id FROM ' . RAD . 'url_aliases WHERE alias=:alias', array('alias' => $alias));
     if (empty($result['item_type'])) {
         return false;
     }
     $lng = rad_lang::getLangByID($result['lang_id']);
     rad_lang::changeLanguage($lng->lng_code);
     switch ($result['item_type']) {
         //List all supported item types here (if they don't need some special processing)
         case 'product':
             return rad_input::makeURL('alias=' . $result['item_type'] . '&p=' . $result['item_id'], false);
         default:
             return false;
             //For not supported item types
     }
 }
Ejemplo n.º 3
0
 /**
  * Main function to init the loader
  * @access public
  */
 public static function init()
 {
     self::$alias = rad_input::request('alias');
     if (!self::$alias) {
         self::$alias = rad_config::getParam('defaultAlias');
         self::$template = rad_config::getParam('defaultTemplate');
     }
     self::$_alias = self::getAliasByName(self::$alias);
     if (is_null(self::$_alias)) {
         throw new rad_exception('Aliases not found! Even the default aliases and alias for the 404 error! Insert those aliases into database please and try again!');
     }
     if (strlen(self::$_alias->input_class)) {
         rad_input::reparseGetWithPlug(self::$_alias->input_class);
     }
     self::parseIncludes(self::$_alias->includes);
     self::$_langContainer = new rad_lang_container();
     self::parseController();
     if (!rad_breadcrumbs::initandmake(self::$_alias)) {
         rad_dblogger::logerr('Can\'t create and init breadcrumbs! file: ' . __FILE__ . ' and line: ' . __LINE__);
     }
 }
Ejemplo n.º 4
0
 function manage()
 {
     $this->setVar('alias_loginform', $this->config('alias.loginform'));
     if (!$this->request('logout') and $this->request('alias') == 'login' and $this->getCurrentUser() and $this->getCurrentUser()->u_id) {
         if ($this->getCurrentUser()->is_admin) {
             $this->redirect($this->makeURL('alias=admin'));
         } else {
             $this->redirect($this->makeURL('alias=' . $this->config('mainAlias')));
         }
         return;
     }
     if ($this->request('login') and $this->request('pass')) {
         if ($user = rad_session::login(rad_input::request('login'), rad_input::request('pass'))) {
             rad_instances::get('model_corecatalog_bin')->mergeCart();
             if (!$user->u_active) {
                 $this->setVar('message_error', $this->lang('usernotacitve.session.error'));
                 rad_session::logout();
             } else {
                 $this->setVar('message', 'Login sucersfull!');
                 if ($this->request('referer')) {
                     $this->redirect($this->request('referer'));
                 } elseif ($_SERVER['HTTP_REFERER']) {
                     $this->redirect($_SERVER['HTTP_REFERER']);
                 } else {
                     $this->redirect($this->makeURL('alias=admin'));
                 }
             }
             //there is needs to set up some variables lica $this->setVar($key,$value)
         } else {
             $this->setVar('message_error', $this->lang('loginpassincorrect.session.message'));
         }
     } elseif ($this->request('logout')) {
         $logout_url = $this->makeURL('alias=' . $this->config('alias.siteloginform'));
         rad_session::logout();
         $this->redirect($logout_url);
     } else {
         //$this->setVar('message','Not enouph actual parametets!');
     }
 }
Ejemplo n.º 5
0
 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));
 }
Ejemplo n.º 6
0
 /**
  * Register new user
  * @param struct_core_users $item
  */
 public function register($item, $encode_password = true)
 {
     $item->u_active = 1;
     $item->u_subscribe_active = 1;
     $item->u_subscribe_langid = $this->getCurrentLangID();
     $clearpass = empty($item->u_pass) ? rad_session::genereCode(6) : $item->u_pass;
     $item->u_pass = $encode_password ? rad_session::encodePassword($clearpass) : $clearpass;
     $this->insertItem($item);
     $item->u_id = $this->inserted_id();
     rad_instances::get('model_coremail_subscribes')->removeExpired();
     $item_url = new struct_coremail_subscribers_activationurl();
     $item_url->sac_url = md5(rad_session::genereCode(31) . now() . $item->u_id);
     $item_url->sac_scrid = $item->u_id;
     $item_url->sac_type = 2;
     $item_url->email = $item->u_email;
     $item_url->date_created = time();
     $item_url->save();
     rad_mailtemplate::send($item->u_email, $this->config('registration.template'), array('user' => $item, 'link' => rad_input::makeURL('alias=register&c=' . urlencode($item_url->sac_url)), 'clearpass' => $clearpass), $this->config('mail_format', 'html'));
 }
Ejemplo n.º 7
0
 /**
  * Reparse all GET with some plugin
  * @param string $classname
  */
 public static function reparseGetWithPlug($classname = '')
 {
     if (file_exists(LIBPATH . 'ext/' . $classname . '.php')) {
         $cl = rad_instances::get($classname);
         $cl->parse_string(self::$_request_parts, self::$_query_parts, self::$GET);
         self::$GET = $cl->get;
         self::setRequest();
     }
 }
Ejemplo n.º 8
0
 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 : ''));
 }
Ejemplo n.º 9
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);
 }
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
}
$mem = memory_get_usage();
require 'config.php';
foreach ($config['db_delimiters'] as $id => $value) {
    define($id, $value);
}
foreach ($config['folders'] as $id => $value) {
    define($id, $value);
}
define('SITE_URL', $config['url']);
require LIBPATH . 'simplefunctions.php';
$time_start = microtime_float();
foreach ($config as $id => $value) {
    if (!is_array($value)) {
        rad_config::setParam($id, $value);
    }
}
rad_config::loadConfig();
rad_exception::setHandlers();
rad_input::init_all();
rad_session::start();
define('SITE_ALIAS', rad_input::get('alias', rad_config::getParam('defaultAlias', 'index.html')));
rad_lang::init();
call_user_func(array(rad_config::getParam('loader_class'), 'init'));
if (rad_config::getParam('lang.caching')) {
    call_user_func(array(rad_config::getParam('loader_class'), 'saveLangCache'));
}
/*
$time_end = microtime_float();
$time = $time_end - $time_start;
*/
Ejemplo n.º 12
0
 function editRecord()
 {
     $model = rad_instances::get('model_core_aliases');
     $model->setState('join_description', true);
     $model->setState('join.aliasgroup', true);
     $theme = trim($this->request('theme'));
     if (strlen($theme)) {
         $model->setState('theme', $theme);
     }
     $item = $model->getItem((int) $this->request('id'));
     for ($i = 0; $i < count($item->includes); $i++) {
         $item->includes[$i]->hasOptions = rad_xmlparams::checkXMLFor($item->includes[$i]->m_name, $item->includes[$i]->inc_filename);
         if ($item->includes[$i]->hasOptions) {
             $item->includes[$i]->controllers = rad_xmlparams::getControllerList($item->includes[$i]->m_name, $item->includes[$i]->inc_filename);
         }
         //if
     }
     //for
     //DO NOT REMEMBER WHERE I CREATED BEFORE CONTROLLERS PARAM!
     $this->setVar('item', $item);
     $this->addBC('aliasname', $item->alias);
     $model = new model_core_table('templates');
     $model->setState('order by', 'filename');
     $templates = $model->getItems();
     $this->setVar('templates', $templates);
     $this->setVar('inclasses', rad_input::getPluginsFGet());
     $this->setVar('langs', $this->getAllLanguages());
     $this->setVar('curr_lng', $this->getCurrentLangID());
 }