Advertisement
Guest User

Previous

a guest
Nov 6th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.13 KB | None | 0 0
  1. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
  2.  
  3. /**
  4.  *
  5.  * @param mixed $var
  6.  * @param string $userclass
  7.  * @param mixed $peer
  8.  * @param boolean $debug
  9.  * @return boolean
  10.  */
  11. function check_class($var, $userclass = USERCLASS, $peer = FALSE, $debug = FALSE)
  12. {
  13.     global $tp,$pref;
  14.     if($var == e_LANGUAGE){
  15.         return TRUE;
  16.     }
  17.  
  18.     if (is_numeric($var) && !$var) return TRUE;     // Accept numeric class zero - 'PUBLIC'
  19.  
  20.     if (!$var || $var == '')
  21.     {   // ....but an empty string or NULL variable is not valid
  22.         return FALSE;
  23.     }
  24.  
  25.     if(strpos($var, ',') !== FALSE)
  26.     {
  27.         $lans = explode(',', e_LANLIST);
  28.         $varList = explode(',', $var);
  29.         rsort($varList); // check the language first.(ie. numbers come last)
  30.         foreach($varList as $v)
  31.         {
  32.             if (in_array($v,$lans) && strpos($v, e_LANGUAGE) === FALSE) {
  33.                 return FALSE;
  34.             }
  35.  
  36.             if(check_class($v, $userclass, $debug)) {
  37.                 return TRUE;
  38.             }
  39.         }
  40.         return FALSE;
  41.     }
  42.    
  43.     //if peer is array, assume it's a user record
  44.     if(is_array($peer)) {
  45.         $_adminperms = ($peer['user_admin'] === 1 ? $peer['user_perms'] : '');
  46.         $_user = true;
  47.         $_admin = $peer['user_admin'] === 1;
  48.         $peer = false;
  49.         $_userjoined = $peer['user_joined'];
  50.     } else {
  51.         $_adminperms = defined('ADMINPERMS') ? ADMINPERMS : '';
  52.         $_user = USER;
  53.         $_admin = ADMIN;
  54.         $_userjoined = USERJOINED;
  55.     }
  56.  
  57.     //Test 'special' userclass numbers
  58.     if (preg_match("/^([0-9]+)$/", $var) && !$peer)
  59.     {
  60.         if ($var == e_UC_MAINADMIN && getperms('0', $_adminperms))
  61.         {
  62.             return TRUE;
  63.         }
  64.         //&& $_admin == FALSE
  65.         if ($var == e_UC_NEWUSER  && (time() < ($_userjoined + (varset($pref['user_new_period'],0)*86400))))
  66.         {
  67.             return TRUE;
  68.         }
  69.  
  70.         if ($var == e_UC_MEMBER && $_user == TRUE)
  71.         {
  72.             return TRUE;
  73.         }
  74.  
  75.         if ($var == e_UC_GUEST && $_user == FALSE) {
  76.             return TRUE;
  77.         }
  78.  
  79.         if ($var == e_UC_PUBLIC) {
  80.             return TRUE;
  81.         }
  82.  
  83.         if ($var == e_UC_NOBODY) {
  84.             return FALSE;
  85.         }
  86.  
  87.         if ($var == e_UC_ADMIN && $_admin) {
  88.             return TRUE;
  89.         }
  90.         if ($var == e_UC_READONLY) {
  91.             return TRUE;
  92.         }
  93.     }
  94.  
  95.     if ($debug) {
  96.         echo "USERCLASS: ".$userclass.", \$var = $var : ";
  97.     }
  98.  
  99.     if (!defined("USERCLASS") || $userclass == "") {
  100.         if ($debug) {
  101.             echo "FALSE<br />";
  102.         }
  103.         return FALSE;
  104.     }
  105.  
  106.     // user has classes set - continue
  107.     if (preg_match("/^([0-9]+)$/", $var)) {
  108.         $tmp=explode(',', $userclass);
  109.         if (is_numeric(array_search($var, $tmp))) {
  110.             if ($debug) {
  111.                 echo "TRUE<br />";
  112.             }
  113.             return TRUE;
  114.         }
  115.     } else {
  116.         // var is name of class ...
  117.         $sql=new db;
  118.         if ($sql->db_Select("userclass_classes", "*", "userclass_name='".$tp -> toDB($var)."' ")) {
  119.             $row=$sql->db_Fetch();
  120.             $tmp=explode(',', $userclass);
  121.             if (is_numeric(array_search($row['userclass_id'], $tmp))) {
  122.                 if ($debug) {
  123.                     echo "TRUE<br />";
  124.                 }
  125.                 return TRUE;
  126.             }
  127.         }
  128.     }
  129.  
  130.     if ($debug) {
  131.         echo "NOTNUM! FALSE<br />";
  132.     }
  133.  
  134.     return FALSE;
  135. }
  136.  
  137. function getperms($arg, $ap = ADMINPERMS)
  138. {
  139.     global $PLUGINS_DIRECTORY;
  140.    
  141.     if(!ADMIN)
  142.     {
  143.         return FALSE;
  144.     }
  145.     if ($ap == "0")
  146.     {
  147.         return TRUE;
  148.     }
  149.     if ($ap == "")
  150.     {
  151.         return FALSE;
  152.     }
  153.     $ap='.'.$ap;
  154.     if ($arg == 'P' && preg_match("#(.*?)/".$PLUGINS_DIRECTORY."(.*?)/(.*?)#", e_SELF, $matches))
  155.     {
  156.         $psql=new db;
  157.         if ($psql->db_Select('plugin', 'plugin_id', "plugin_path = '".$matches[2]."' "))
  158.         {
  159.             $row=$psql->db_Fetch();
  160.             $arg='P'.$row[0];
  161.         }
  162.     }
  163.     if (strpos($ap, ".".$arg.".") !== FALSE)
  164.     {
  165.         return TRUE;
  166.     }
  167.     else
  168.     {
  169.         return FALSE;
  170.     }
  171. }
  172.  
  173. /**
  174.  * Get the user data from user and user_extended tables
  175.  *
  176.  * @return array
  177.  */
  178. function get_user_data($uid, $extra = "")
  179. {
  180.     global $pref, $sql;
  181.     $uid = intval($uid);
  182.     $var = array();
  183.     if($uid == 0) { return $var; }
  184.     if($ret = getcachedvars("userdata_{$uid}"))
  185.     {
  186.         return $ret;
  187.     }
  188.  
  189.     $qry = "
  190.     SELECT u.*, ue.* FROM #user AS u
  191.     LEFT JOIN #user_extended AS ue ON ue.user_extended_id = u.user_id
  192.     WHERE u.user_id = {$uid} {$extra}
  193.     ";
  194.     if (!$sql->db_Select_gen($qry))
  195.     {
  196.         $qry = "SELECT * FROM #user AS u WHERE u.user_id = {$uid} {$extra}";
  197.         if(!$sql->db_Select_gen($qry))
  198.         {
  199.             return FALSE;
  200.         }
  201.     }
  202.  
  203.     $var = $sql->db_Fetch(MYSQL_ASSOC);
  204.     $extended_struct = getcachedvars("extended_struct");
  205.     if(!$extended_struct)
  206.     {
  207.         unset($extended_struct);
  208.         $qry = "SHOW COLUMNS FROM #user_extended ";
  209.         if($sql->db_Select_gen($qry))
  210.         {
  211.             while($row = $sql->db_Fetch(MYSQL_ASSOC))
  212.             {
  213.                 if($row['Default'] != "")
  214.                 {
  215.                     $extended_struct[] = $row;
  216.                 }
  217.             }
  218.             if(isset($extended_struct))
  219.             {
  220.                 cachevars("extended_struct", $extended_struct);
  221.             }
  222.         }
  223.     }
  224.  
  225.     if(isset($extended_struct))
  226.     {
  227.         foreach($extended_struct as $row)
  228.         {
  229.             if($row['Default'] != "" && ($var[$row['Field']] == NULL || $var[$row['Field']] == "" ))
  230.             {
  231.                 $var[$row['Field']] = $row['Default'];
  232.             }
  233.         }
  234.     }
  235.     if ($var['user_perms'] == '0.') $var['user_perms'] = '0';       // Handle some legacy situations
  236.     cachevars("userdata_{$uid}", $var);
  237.     return $var;
  238. }
  239.  
  240. //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
  241.  
  242. function save_prefs($table = 'core', $uid = USERID, $row_val = '')
  243. {
  244.   global $pref, $user_pref, $tp, $PrefCache, $sql, $eArrayStorage;
  245.   if ($table == 'core')
  246.   {
  247.     if ($row_val == '')
  248.     {       // Save old version as a backup first
  249.       $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs_Backup', '".addslashes($PrefCache)."') ");
  250.  
  251.       // Now save the updated values
  252.       // traverse the pref array, with toDB on everything
  253.       $_pref = $tp -> toDB($pref, true, true, 'pReFs');
  254.       // Create the data to be stored
  255.       $sql->db_Select_gen("REPLACE INTO `#core` (e107_name,e107_value) values ('SitePrefs', '".$eArrayStorage->WriteArray($_pref)."') ");
  256.       ecache::clear('SitePrefs');
  257.     }
  258.   }
  259.   else
  260.   {
  261.     $_user_pref = $tp -> toDB($user_pref);
  262.     $tmp=addslashes(serialize($_user_pref));
  263.     $sql->db_Update("user", "user_prefs='$tmp' WHERE user_id=".intval($uid));
  264.     return $tmp;
  265.   }
  266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement