function getItem($id = NULL) { $id = $id ? $id : $this->getState('id'); $this->setState('id', $id); $limit = $this->getState('limit') ? ' LIMIT ' . $this->getState('limit') : ''; $q = $this->getListQuery($this->getStates()); $item = new struct_core_alias($this->query($q->toString(), $q->getValues())); $theme_id = $item->themeid ? $item->themeid : 0; $theme2_id = $theme_id; if ($item->group_id) { $theme2_id = rad_dbpdo::query('SELECT theme_id FROM ' . RAD . 'themes WHERE theme_aliasid=? AND theme_folder=?', array($item->group_id, $item->themefolder)); $theme2_id = !empty($theme2_id['theme_id']) ? (int) $theme2_id['theme_id'] : $theme_id; } if ($this->getState('join.aliasgroup')) { $table = new model_core_table('aliases'); $ali_item = $table->getItem($id); } if (!$this->getState('without_joins')) { foreach ($this->queryAll('select params_presonal,inc_id,inc_name,inc_filename,controller,order_sort,rp_name,rp_id,id_module,m_name,ia.id as incinal_id, ia.params_hash as params_hash, 0 as is_ga ' . ($this->getState('join.original_params', false) ? ', ip_params AS original_params ' : '') . 'from ' . RAD . 'includes_in_aliases ia ' . '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 ' . ($this->getState('join.original_params', false) ? ' left join ' . RAD . 'includes_params ip ON ip.ip_incid=ia.include_id ' : '') . 'where alias_id=' . $id . ' and ia.theme_id=' . $theme_id . (($this->getState('join.aliasgroup') and isset($ali_item) and $ali_item->group_id) ? ' UNION (' . 'select params_presonal,inc_id,inc_name,inc_filename,controller,order_sort,rp_name,rp_id,id_module,m_name,ia.id as incinal_id, ia.params_hash as params_hash, 1 as is_ga ' . ($this->getState('join.original_params', false) ? ', ip_params AS original_params ' : '') . 'from ' . RAD . 'includes_in_aliases ia ' . '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 ' . ($this->getState('join.original_params', false) ? ' left join ' . RAD . 'includes_params ip ON ip.ip_incid=ia.include_id ' : '') . 'where alias_id=' . $ali_item->group_id . ' and ia.theme_id=' . $theme2_id . ')' : '') . ' order by rp_name, order_sort') as $idi) { $item->includes[] = new struct_core_include($idi); $item->includes[count($item->includes) - 1]->is_ga = (bool) $idi['is_ga']; } } if ($this->getState('join_description')) { $wlangid = $this->getState('ald_langid'); $wlangid = $wlangid ? ' AND ald_langid=' . $wlangid : ''; foreach ($this->queryAll('SELECT * FROM ' . RAD . 'aliases_description where ald_aliasid=' . $id . $wlangid) as $idd) { $item->description[$idd['ald_langid']] = new struct_core_aliases_description($idd); } } return $item; }
/** * 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 } }
/** * Query an a element and return the rad_struct * @param string $result_struct * @return rad_struct */ function getItem($result_struct) { $result = null; $res = rad_dbpdo::query($this->toString(), $this->getValues()); if ($res) { $result = new $result_struct($res); } return $result; }
/** * Check user by its username and password * * @var string login * @var string password * * @return struct_core_users */ public static function checkUser(&$login = '', &$password = '') { $res = rad_dbpdo::query('select * from ' . RAD . 'users where u_login=:login and u_pass=:pass and u_active=1 limit 1', array('login' => $login, 'pass' => md5($password))); if (count($res)) { return new struct_core_users($res); } else { return null; } }
/** * Alias for rad_dbpdo::query($sql,$fetchMode) * * @param string $sql * @param array $params * * @return mixed assoc array * * @access public */ function query($sql = null, $params = null) { return rad_dbpdo::query($sql, $params); }
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; }
/** * * @param string $social_id identifire from social site * @param string $provider social site name * @return id user or false */ public static function social_login($social_id, $provider, $sessionTime = NULL) { //$sessionTime =($sessionTime)?$sessionTime:rad_config::getParam('CookieExpireTime'); $provider_row = 'u_' . $provider . '_id'; $id = rad_dbpdo::query('SELECT u_id, u_email, u_pass, is_admin FROM ' . RAD . 'users WHERE `' . $provider_row . '`=:' . $provider_row, array($provider_row => $social_id)); if (!empty($id['u_id'])) { self::$error_code = 0; self::$is_admin = $id['is_admin']; self::$user = rad_user::getUserByID($id['u_id']); rad_user::setUser(self::$user); $_SESSION['user_dump'] = self::$user; $_SESSION['user'] = $id['u_email']; $_SESSION['pass'] = md5($id['u_pass']); return self::$user; } self::$error_code = self::ERROR_WRONG_PASSWORD; return false; }
/** * Load item by it primary key */ public function load() { $pk = $this->getPrimaryKey(); $this->CopyToStruct(rad_dbpdo::query('SELECT ' . implode(',', $this->getKeys('`', true)) . ' FROM ' . $this->_getTableName() . ' WHERE `' . $pk . '`=?', array($this->{$pk}))); return $this; }
/** * Returns language value by it langcode * * @param string $code * @param string $langcode (en.ru e.t.c.) * @param boolean $ucfirst * @return string * @example lang('submit.system.button'); * * @access public */ public static function lang($code = '', $langcode = null, $container = NULL, $ucfirst = false) { $langcode = $langcode ? $langcode : self::$currentLanguage; $langID = ($langcode and isset(self::$allLanguages[$langcode])) ? self::$allLanguages[$langcode]->lng_id : self::$langID; if (isset(self::$cacheLngValues[$langID][$code])) { return self::$cacheLngValues[$langID][$code]; } $row = rad_dbpdo::query('SELECT `lnv_value` FROM ' . RAD . 'langvalues where `lnv_code`=? and `lnv_lang`=?', array($code, $langID)); if (is_null($row['lnv_value'])) { self::$cacheLngValues[$langID][$code] = $code; if (!empty($container)) { self::addNotFoundCache($container->getTemplate(), $code, $langcode); } } else { self::$cacheLngValues[$langID][$code] = $row['lnv_value']; } return $ucfirst ? mb_ucfirst(self::$cacheLngValues[$langID][$code]) : self::$cacheLngValues[$langID][$code]; }