Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
- /**
- *
- * @param mixed $var
- * @param string $userclass
- * @param mixed $peer
- * @param boolean $debug
- * @return boolean
- */
- function check_class($var, $userclass = USERCLASS, $peer = FALSE, $debug = FALSE)
- {
- global $tp,$pref;
- if($var == e_LANGUAGE){
- return TRUE;
- }
- if (is_numeric($var) && !$var) return TRUE; // Accept numeric class zero - 'PUBLIC'
- if (!$var || $var == '')
- { // ....but an empty string or NULL variable is not valid
- return FALSE;
- }
- if(strpos($var, ',') !== FALSE)
- {
- $lans = explode(',', e_LANLIST);
- $varList = explode(',', $var);
- rsort($varList); // check the language first.(ie. numbers come last)
- foreach($varList as $v)
- {
- if (in_array($v,$lans) && strpos($v, e_LANGUAGE) === FALSE) {
- return FALSE;
- }
- if(check_class($v, $userclass, $debug)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- //if peer is array, assume it's a user record
- if(is_array($peer)) {
- $_adminperms = ($peer['user_admin'] === 1 ? $peer['user_perms'] : '');
- $_user = true;
- $_admin = $peer['user_admin'] === 1;
- $peer = false;
- $_userjoined = $peer['user_joined'];
- } else {
- $_adminperms = defined('ADMINPERMS') ? ADMINPERMS : '';
- $_user = USER;
- $_admin = ADMIN;
- $_userjoined = USERJOINED;
- }
- //Test 'special' userclass numbers
- if (preg_match("/^([0-9]+)$/", $var) && !$peer)
- {
- if ($var == e_UC_MAINADMIN && getperms('0', $_adminperms))
- {
- return TRUE;
- }
- //&& $_admin == FALSE
- if ($var == e_UC_NEWUSER && (time() < ($_userjoined + (varset($pref['user_new_period'],0)*86400))))
- {
- return TRUE;
- }
- if ($var == e_UC_MEMBER && $_user == TRUE)
- {
- return TRUE;
- }
- if ($var == e_UC_GUEST && $_user == FALSE) {
- return TRUE;
- }
- if ($var == e_UC_PUBLIC) {
- return TRUE;
- }
- if ($var == e_UC_NOBODY) {
- return FALSE;
- }
- if ($var == e_UC_ADMIN && $_admin) {
- return TRUE;
- }
- if ($var == e_UC_READONLY) {
- return TRUE;
- }
- }
- if ($debug) {
- echo "USERCLASS: ".$userclass.", \$var = $var : ";
- }
- if (!defined("USERCLASS") || $userclass == "") {
- if ($debug) {
- echo "FALSE<br />";
- }
- return FALSE;
- }
- // user has classes set - continue
- if (preg_match("/^([0-9]+)$/", $var)) {
- $tmp=explode(',', $userclass);
- if (is_numeric(array_search($var, $tmp))) {
- if ($debug) {
- echo "TRUE<br />";
- }
- return TRUE;
- }
- } else {
- // var is name of class ...
- $sql=new db;
- if ($sql->db_Select("userclass_classes", "*", "userclass_name='".$tp -> toDB($var)."' ")) {
- $row=$sql->db_Fetch();
- $tmp=explode(',', $userclass);
- if (is_numeric(array_search($row['userclass_id'], $tmp))) {
- if ($debug) {
- echo "TRUE<br />";
- }
- return TRUE;
- }
- }
- }
- if ($debug) {
- echo "NOTNUM! FALSE<br />";
- }
- return FALSE;
- }
- function getperms($arg, $ap = ADMINPERMS)
- {
- global $PLUGINS_DIRECTORY;
- if(!ADMIN)
- {
- return FALSE;
- }
- if ($ap == "0")
- {
- return TRUE;
- }
- if ($ap == "")
- {
- return FALSE;
- }
- $ap='.'.$ap;
- if ($arg == 'P' && preg_match("#(.*?)/".$PLUGINS_DIRECTORY."(.*?)/(.*?)#", e_SELF, $matches))
- {
- $psql=new db;
- if ($psql->db_Select('plugin', 'plugin_id', "plugin_path = '".$matches[2]."' "))
- {
- $row=$psql->db_Fetch();
- $arg='P'.$row[0];
- }
- }
- if (strpos($ap, ".".$arg.".") !== FALSE)
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- /**
- * Get the user data from user and user_extended tables
- *
- * @return array
- */
- function get_user_data($uid, $extra = "")
- {
- global $pref, $sql;
- $uid = intval($uid);
- $var = array();
- if($uid == 0) { return $var; }
- if($ret = getcachedvars("userdata_{$uid}"))
- {
- return $ret;
- }
- $qry = "
- SELECT u.*, ue.* FROM #user AS u
- LEFT JOIN #user_extended AS ue ON ue.user_extended_id = u.user_id
- WHERE u.user_id = {$uid} {$extra}
- ";
- if (!$sql->db_Select_gen($qry))
- {
- $qry = "SELECT * FROM #user AS u WHERE u.user_id = {$uid} {$extra}";
- if(!$sql->db_Select_gen($qry))
- {
- return FALSE;
- }
- }
- $var = $sql->db_Fetch(MYSQL_ASSOC);
- $extended_struct = getcachedvars("extended_struct");
- if(!$extended_struct)
- {
- unset($extended_struct);
- $qry = "SHOW COLUMNS FROM #user_extended ";
- if($sql->db_Select_gen($qry))
- {
- while($row = $sql->db_Fetch(MYSQL_ASSOC))
- {
- if($row['Default'] != "")
- {
- $extended_struct[] = $row;
- }
- }
- if(isset($extended_struct))
- {
- cachevars("extended_struct", $extended_struct);
- }
- }
- }
- if(isset($extended_struct))
- {
- foreach($extended_struct as $row)
- {
- if($row['Default'] != "" && ($var[$row['Field']] == NULL || $var[$row['Field']] == "" ))
- {
- $var[$row['Field']] = $row['Default'];
- }
- }
- }
- if ($var['user_perms'] == '0.') $var['user_perms'] = '0'; // Handle some legacy situations
- cachevars("userdata_{$uid}", $var);
- return $var;
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
- function save_prefs($table = 'core', $uid = USERID, $row_val = '')
- {
- global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage;
- if ($table == 'core')
- {
- if ($row_val == '')
- { // Save old version as a backup first
- $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs_Backup', '".addslashes($PrefCache)."') ");
- // Now save the updated values
- // traverse the pref array, with toDB on everything
- $_pref = $tp -> toDB($pref, true, true, 'pReFs');
- // Create the data to be stored
- $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs', '".$eArrayStorage->WriteArray($_pref)."') ");
- ecache::clear('SitePrefs');
- }
- }
- else
- {
- $_user_pref = $tp -> toDB($user_pref);
- $tmp=addslashes(serialize($_user_pref));
- $sql->db_Update("user", "user_prefs='$tmp' WHERE user_id=".intval($uid));
- return $tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement