mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
частичный перенос базовых классов на автозагрузку
This commit is contained in:
parent
b6054de287
commit
7a9dc820c3
6 changed files with 408 additions and 308 deletions
|
@ -1,40 +1,91 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
class upload_common
|
||||
if (!defined('BB_ROOT'))
|
||||
{
|
||||
var $cfg = array(
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class Upload
|
||||
{
|
||||
/**
|
||||
* @type array
|
||||
*/
|
||||
public $cfg = [
|
||||
'max_size' => 0,
|
||||
'max_width' => 0,
|
||||
'max_height' => 0,
|
||||
'allowed_ext' => array(),
|
||||
'allowed_ext' => [],
|
||||
'upload_path' => '',
|
||||
);
|
||||
var $file = array(
|
||||
];
|
||||
|
||||
/**
|
||||
* @type array
|
||||
*/
|
||||
public $file = [
|
||||
'name' => '',
|
||||
'type' => '',
|
||||
'size' => 0,
|
||||
'tmp_name' => '',
|
||||
'error' => UPLOAD_ERR_NO_FILE,
|
||||
);
|
||||
var $orig_name = '';
|
||||
var $file_path = ''; // Stored file path
|
||||
var $file_ext = '';
|
||||
var $file_ext_id = '';
|
||||
var $file_size = '';
|
||||
var $ext_ids = array(); // array_flip($bb_cfg['file_id_ext'])
|
||||
var $errors = array();
|
||||
var $img_types = array(
|
||||
];
|
||||
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
public $orig_name = '';
|
||||
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
public $file_path = '';
|
||||
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
public $file_ext = '';
|
||||
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
public $file_ext_id = '';
|
||||
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
public $file_size = '';
|
||||
|
||||
/**
|
||||
* array_flip($bb_cfg['file_id_ext'])
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
public $ext_ids = [];
|
||||
|
||||
/**
|
||||
* @type array
|
||||
*/
|
||||
public $errors = [];
|
||||
|
||||
/**
|
||||
* @type array
|
||||
*/
|
||||
public $img_types = [
|
||||
1 => 'gif',
|
||||
2 => 'jpg',
|
||||
3 => 'png',
|
||||
6 => 'bmp',
|
||||
7 => 'tiff',
|
||||
8 => 'tiff',
|
||||
);
|
||||
];
|
||||
|
||||
function init ($cfg = array(), $post_params = array(), $uploaded_only = true)
|
||||
/**
|
||||
* @param array $cfg
|
||||
* @param array $post_params
|
||||
* @param bool $uploaded_only
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function init ($cfg = [], $post_params = [], $uploaded_only = true)
|
||||
{
|
||||
global $bb_cfg, $lang;
|
||||
|
||||
|
@ -47,29 +98,34 @@ class upload_common
|
|||
$msg = $lang['UPLOAD_ERROR_COMMON'];
|
||||
$msg .= ($err_desc =& $lang['UPLOAD_ERRORS'][$this->file['error']]) ? " ($err_desc)" : '';
|
||||
$this->errors[] = $msg;
|
||||
|
||||
return false;
|
||||
}
|
||||
// file_exists
|
||||
if (!file_exists($this->file['tmp_name']))
|
||||
{
|
||||
$this->errors[] = "Uploaded file not exists: {$this->file['tmp_name']}";
|
||||
|
||||
return false;
|
||||
}
|
||||
// size
|
||||
if (!$this->file_size = filesize($this->file['tmp_name']))
|
||||
{
|
||||
$this->errors[] = "Uploaded file is empty: {$this->file['tmp_name']}";
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($this->cfg['max_size'] && $this->file_size > $this->cfg['max_size'])
|
||||
{
|
||||
$this->errors[] = sprintf($lang['UPLOAD_ERROR_SIZE'], humn_size($this->cfg['max_size']));
|
||||
|
||||
return false;
|
||||
}
|
||||
// is_uploaded_file
|
||||
if ($uploaded_only && !is_uploaded_file($this->file['tmp_name']))
|
||||
{
|
||||
$this->errors[] = "Not uploaded file: {$this->file['tmp_name']}";
|
||||
|
||||
return false;
|
||||
}
|
||||
// get ext
|
||||
|
@ -88,6 +144,7 @@ class upload_common
|
|||
if (!$width || !$height || !$type || !isset($this->img_types[$type]))
|
||||
{
|
||||
$this->errors[] = $lang['UPLOAD_ERROR_FORMAT'];
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->file_ext = $this->img_types[$type];
|
||||
|
@ -96,12 +153,14 @@ class upload_common
|
|||
if (($this->cfg['max_width'] && $width > $this->cfg['max_width']) || ($this->cfg['max_height'] && $height > $this->cfg['max_height']))
|
||||
{
|
||||
$this->errors[] = sprintf($lang['UPLOAD_ERROR_DIMENSIONS'], $this->cfg['max_width'], $this->cfg['max_height']);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errors[] = $lang['UPLOAD_ERROR_NOT_IMAGE'];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -109,24 +168,33 @@ class upload_common
|
|||
if ($uploaded_only && (!isset($this->ext_ids[$this->file_ext]) || !in_array($this->file_ext, $this->cfg['allowed_ext'], true)))
|
||||
{
|
||||
$this->errors[] = sprintf($lang['UPLOAD_ERROR_NOT_ALLOWED'], htmlCHR($this->file_ext));
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->file_ext_id = $this->ext_ids[$this->file_ext];
|
||||
$this->file_ext_id = @$this->ext_ids[$this->file_ext];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function store ($mode = '', $params = array())
|
||||
/**
|
||||
* @param string $mode
|
||||
* @param array $params
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function store ($mode = '', $params = [])
|
||||
{
|
||||
if ($mode == 'avatar')
|
||||
{
|
||||
delete_avatar($params['user_id'], $params['avatar_ext_id']);
|
||||
$file_path = get_avatar_path($params['user_id'], $this->file_ext_id);
|
||||
|
||||
return $this->_move($file_path);
|
||||
}
|
||||
else if ($mode == 'attach')
|
||||
{
|
||||
$file_path = get_attach_path($params['topic_id']);
|
||||
|
||||
return $this->_move($file_path);
|
||||
}
|
||||
else
|
||||
|
@ -135,7 +203,12 @@ class upload_common
|
|||
}
|
||||
}
|
||||
|
||||
function _move ($file_path)
|
||||
/**
|
||||
* @param $file_path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function _move ($file_path)
|
||||
{
|
||||
$dir = dirname($file_path);
|
||||
if (!file_exists($dir))
|
||||
|
@ -143,6 +216,7 @@ class upload_common
|
|||
if (!bb_mkdir($dir))
|
||||
{
|
||||
$this->errors[] = "Cannot create dir: $dir";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -151,6 +225,7 @@ class upload_common
|
|||
if (!@copy($this->file['tmp_name'], $file_path))
|
||||
{
|
||||
$this->errors[] = 'Cannot copy tmp file';
|
||||
|
||||
return false;
|
||||
}
|
||||
@unlink($this->file['tmp_name']);
|
|
@ -1,24 +1,22 @@
|
|||
<?php
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
define('ONLY_NEW_POSTS', 1);
|
||||
define('ONLY_NEW_TOPICS', 2);
|
||||
|
||||
class user_common
|
||||
class Sessions
|
||||
{
|
||||
/**
|
||||
* Config
|
||||
* @type array
|
||||
*/
|
||||
var $cfg = array(
|
||||
public $cfg = [
|
||||
'req_login' => false, // requires user to be logged in
|
||||
'req_session_admin' => false, // requires active admin session (for moderation or admin actions)
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* PHP-JS exchangeable options (JSON'ized as {USER_OPTIONS_JS} in TPL)
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
var $opt_js = array(
|
||||
public $opt_js = [
|
||||
'only_new' => 0, // show ony new posts or topics
|
||||
'h_av' => 0, // hide avatar
|
||||
'h_rnk_i' => 0, // hide rank images
|
||||
|
@ -31,49 +29,63 @@ class user_common
|
|||
'hl_tr' => 1, // show cursor in tracker.php
|
||||
'i_aft_l' => 0, // show images only after full loading
|
||||
'h_tsp' => 0, // show released title {...}
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Defaults options for guests
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
var $opt_js_guest = array(
|
||||
public $opt_js_guest = [
|
||||
'h_av' => 1, // hide avatar
|
||||
'h_rnk_i' => 1, // hide rank images
|
||||
'h_smile' => 1, // hide smilies
|
||||
'h_sig' => 1, // hide signatures
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Sessiondata
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
var $sessiondata = array(
|
||||
public $sessiondata = [
|
||||
'uk' => null,
|
||||
'uid' => null,
|
||||
'sid' => '',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Old $userdata
|
||||
*
|
||||
* @type array
|
||||
*/
|
||||
var $data = array();
|
||||
public $data = [];
|
||||
|
||||
/**
|
||||
* Shortcuts
|
||||
*
|
||||
* @type
|
||||
*/
|
||||
var $id = null;
|
||||
public $id;
|
||||
public $active;
|
||||
public $name;
|
||||
public $lastvisit;
|
||||
public $regdate;
|
||||
public $level;
|
||||
public $opt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function user_common ()
|
||||
|
||||
function __construct ()
|
||||
{
|
||||
$this->get_sessiondata();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start session (restore existent session or create new)
|
||||
* @param array $cfg
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
function session_start ($cfg = array())
|
||||
public function session_start ($cfg = [])
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
|
@ -157,7 +169,7 @@ class user_common
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->data = array();
|
||||
$this->data = [];
|
||||
}
|
||||
}
|
||||
// If we reach here then no (valid) session exists. So we'll create a new one,
|
||||
|
@ -207,9 +219,12 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Create new session for the given user
|
||||
* @param $userdata
|
||||
* @param bool $auto_created
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function session_create ($userdata, $auto_created = false)
|
||||
public function session_create ($userdata, $auto_created = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
|
@ -242,7 +257,7 @@ class user_common
|
|||
{
|
||||
$session_id = make_rand_str(SID_LENGTH);
|
||||
|
||||
$args = DB()->build_array('INSERT', array(
|
||||
$args = DB()->build_array('INSERT', [
|
||||
'session_id' => (string) $session_id,
|
||||
'session_user_id' => (int) $user_id,
|
||||
'session_start' => (int) TIMENOW,
|
||||
|
@ -250,7 +265,7 @@ class user_common
|
|||
'session_ip' => (string) USER_IP,
|
||||
'session_logged_in' => (int) $login,
|
||||
'session_admin' => (int) $mod_admin_session,
|
||||
));
|
||||
]);
|
||||
$sql = "INSERT INTO " . BB_SESSIONS . $args;
|
||||
|
||||
if (@DB()->query($sql))
|
||||
|
@ -326,9 +341,10 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Initialize sessiondata stored in cookies
|
||||
* @param bool $update_lastvisit
|
||||
* @param bool $set_cookie
|
||||
*/
|
||||
function session_end ($update_lastvisit = false, $set_cookie = true)
|
||||
public function session_end ($update_lastvisit = false, $set_cookie = true)
|
||||
{
|
||||
DB()->query("
|
||||
DELETE FROM " . BB_SESSIONS . "
|
||||
|
@ -368,9 +384,12 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Login
|
||||
* @param $args
|
||||
* @param bool $mod_admin_login
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function login ($args, $mod_admin_login = false)
|
||||
public function login ($args, $mod_admin_login = false)
|
||||
{
|
||||
$username = !empty($args['login_username']) ? clean_username($args['login_username']) : '';
|
||||
$password = !empty($args['login_password']) ? $args['login_password'] : '';
|
||||
|
@ -429,15 +448,12 @@ class user_common
|
|||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize sessiondata stored in cookies
|
||||
*/
|
||||
function get_sessiondata ()
|
||||
public function get_sessiondata ()
|
||||
{
|
||||
$sd_resv = !empty($_COOKIE[COOKIE_DATA]) ? @unserialize($_COOKIE[COOKIE_DATA]) : array();
|
||||
$sd_resv = !empty($_COOKIE[COOKIE_DATA]) ? @unserialize($_COOKIE[COOKIE_DATA]) : [];
|
||||
|
||||
// autologin_id
|
||||
if (!empty($sd_resv['uk']) && verify_id($sd_resv['uk'], LOGIN_KEY_LENGTH))
|
||||
|
@ -457,22 +473,22 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Store sessiondata in cookies
|
||||
* @param $user_id
|
||||
*/
|
||||
function set_session_cookies ($user_id)
|
||||
public function set_session_cookies ($user_id)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if ($user_id == GUEST_UID)
|
||||
{
|
||||
$delete_cookies = array(
|
||||
$delete_cookies = [
|
||||
COOKIE_DATA,
|
||||
COOKIE_DBG,
|
||||
'torhelp',
|
||||
'explain',
|
||||
'sql_log',
|
||||
'sql_log_full',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($delete_cookies as $cookie)
|
||||
{
|
||||
|
@ -499,9 +515,13 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Verify autologin_id
|
||||
* @param $userdata
|
||||
* @param bool $expire_check
|
||||
* @param bool $create_new
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
function verify_autologin_id ($userdata, $expire_check = false, $create_new = true)
|
||||
public function verify_autologin_id ($userdata, $expire_check = false, $create_new = true)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
|
@ -526,9 +546,12 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Create autologin_id
|
||||
* @param $userdata
|
||||
* @param bool $create_new
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function create_autologin_id ($userdata, $create_new = true)
|
||||
public function create_autologin_id ($userdata, $create_new = true)
|
||||
{
|
||||
$autologin_id = ($create_new) ? make_rand_str(LOGIN_KEY_LENGTH) : '';
|
||||
|
||||
|
@ -542,10 +565,8 @@ class user_common
|
|||
return $autologin_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shortcuts
|
||||
*/
|
||||
function set_shortcuts ()
|
||||
|
||||
public function set_shortcuts ()
|
||||
{
|
||||
$this->id =& $this->data['user_id'];
|
||||
$this->active =& $this->data['user_active'];
|
||||
|
@ -558,14 +579,15 @@ class user_common
|
|||
$this->ip = CLIENT_IP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise user settings
|
||||
*/
|
||||
function init_userprefs ()
|
||||
|
||||
public function init_userprefs ()
|
||||
{
|
||||
global $bb_cfg, $theme, $lang, $DeltaTime;
|
||||
|
||||
if (defined('LANG_DIR')) return; // prevent multiple calling
|
||||
if (defined('LANG_DIR'))
|
||||
{
|
||||
return;
|
||||
} // prevent multiple calling
|
||||
|
||||
define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . $bb_cfg['default_lang'] . '/');
|
||||
define('ENGLISH_LANG_DIR', LANG_ROOT_DIR . 'en/');
|
||||
|
@ -587,7 +609,10 @@ class user_common
|
|||
$this->data['user_lang'] = $bb_cfg['default_lang'];
|
||||
$this->data['user_timezone'] = $bb_cfg['board_timezone'];
|
||||
|
||||
if (!defined('LANG_DIR')) define('LANG_DIR', DEFAULT_LANG_DIR);
|
||||
if (!defined('LANG_DIR'))
|
||||
{
|
||||
define('LANG_DIR', DEFAULT_LANG_DIR);
|
||||
}
|
||||
|
||||
require(LANG_DIR . 'main.php');
|
||||
setlocale(LC_ALL, $bb_cfg['lang'][$this->data['user_lang']]['locale']);
|
||||
|
@ -605,9 +630,9 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Mark read
|
||||
* @param $type
|
||||
*/
|
||||
function mark_read ($type)
|
||||
public function mark_read ($type)
|
||||
{
|
||||
if ($type === 'all_forums')
|
||||
{
|
||||
|
@ -624,10 +649,10 @@ class user_common
|
|||
$this->data['user_lastvisit'] = TIMENOW;
|
||||
|
||||
// Update lastvisit
|
||||
db_update_userdata($this->data, array(
|
||||
db_update_userdata($this->data, [
|
||||
'user_session_time' => $this->data['session_time'],
|
||||
'user_lastvisit' => $this->data['user_lastvisit'],
|
||||
));
|
||||
]);
|
||||
|
||||
// Delete cookies
|
||||
bb_setcookie(COOKIE_TOPIC, '');
|
||||
|
@ -636,10 +661,7 @@ class user_common
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load misc options
|
||||
*/
|
||||
function load_opt_js ()
|
||||
public function load_opt_js ()
|
||||
{
|
||||
if (IS_GUEST)
|
||||
{
|
||||
|
@ -657,13 +679,18 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Get not auth forums
|
||||
* @param $auth_type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_not_auth_forums ($auth_type)
|
||||
public function get_not_auth_forums ($auth_type)
|
||||
{
|
||||
global $datastore;
|
||||
|
||||
if (IS_ADMIN) return '';
|
||||
if (IS_ADMIN)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$forums = $datastore->get('cat_forums'))
|
||||
{
|
||||
|
@ -686,7 +713,7 @@ class user_common
|
|||
}
|
||||
}
|
||||
|
||||
$auth_field_match = array(
|
||||
$auth_field_match = [
|
||||
AUTH_VIEW => 'auth_view',
|
||||
AUTH_READ => 'auth_read',
|
||||
AUTH_POST => 'auth_post',
|
||||
|
@ -699,9 +726,9 @@ class user_common
|
|||
AUTH_POLLCREATE => 'auth_pollcreate',
|
||||
AUTH_ATTACH => 'auth_attachments',
|
||||
AUTH_DOWNLOAD => 'auth_download',
|
||||
);
|
||||
];
|
||||
|
||||
$not_auth_forums = array();
|
||||
$not_auth_forums = [];
|
||||
$auth_field = $auth_field_match[$auth_type];
|
||||
$is_auth_ary = auth($auth_type, AUTH_LIST_ALL, $this->data);
|
||||
|
||||
|
@ -717,11 +744,14 @@ class user_common
|
|||
}
|
||||
|
||||
/**
|
||||
* Get excluded forums
|
||||
* @param $auth_type
|
||||
* @param string $return_as
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
function get_excluded_forums ($auth_type, $return_as = 'csv')
|
||||
public function get_excluded_forums ($auth_type, $return_as = 'csv')
|
||||
{
|
||||
$excluded = array();
|
||||
$excluded = [];
|
||||
|
||||
if ($not_auth = $this->get_not_auth_forums($auth_type))
|
||||
{
|
||||
|
@ -742,91 +772,22 @@ class user_common
|
|||
{
|
||||
foreach ($forums['forum'] as $key => $row)
|
||||
{
|
||||
if ($row['allow_porno_topic']) $excluded[] = $row['forum_id'];
|
||||
if ($row['allow_porno_topic'])
|
||||
{
|
||||
$excluded[] = $row['forum_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($return_as)
|
||||
{
|
||||
case 'csv': return join(',', $excluded);
|
||||
case 'array': return $excluded;
|
||||
case 'flip': return array_flip(explode(',', $excluded));
|
||||
case 'csv':
|
||||
return join(',', $excluded);
|
||||
case 'array':
|
||||
return $excluded;
|
||||
case 'flip':
|
||||
return array_flip(explode(',', $excluded));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// userdata cache
|
||||
//
|
||||
function ignore_cached_userdata ()
|
||||
{
|
||||
return (defined('IN_PM')) ? true : false;
|
||||
}
|
||||
|
||||
function cache_get_userdata ($id)
|
||||
{
|
||||
if (ignore_cached_userdata()) return false;
|
||||
|
||||
return CACHE('session_cache')->get($id);
|
||||
}
|
||||
|
||||
function cache_set_userdata ($userdata, $force = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if (!$userdata || (ignore_cached_userdata() && !$force)) return false;
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->set($id, $userdata, $bb_cfg['session_update_intrv']);
|
||||
}
|
||||
|
||||
function cache_rm_userdata ($userdata)
|
||||
{
|
||||
if (!$userdata) return false;
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->rm($id);
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function cache_rm_user_sessions ($user_id)
|
||||
{
|
||||
$user_id = get_id_csv($user_id);
|
||||
|
||||
$rowset = DB()->fetch_rowset("
|
||||
SELECT session_id FROM ". BB_SESSIONS ." WHERE session_user_id IN($user_id)
|
||||
");
|
||||
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
CACHE('session_cache')->rm($row['session_id']);
|
||||
}
|
||||
}
|
||||
|
||||
function cache_update_userdata ($userdata)
|
||||
{
|
||||
return cache_set_userdata($userdata, true);
|
||||
}
|
||||
|
||||
function db_update_userdata ($userdata, $sql_ary, $data_already_escaped = true)
|
||||
{
|
||||
if (!$userdata) return false;
|
||||
|
||||
$sql_args = DB()->build_array('UPDATE', $sql_ary, $data_already_escaped);
|
||||
DB()->query("UPDATE ". BB_USERS ." SET $sql_args WHERE user_id = {$userdata['user_id']}");
|
||||
|
||||
if (DB()->affected_rows())
|
||||
{
|
||||
cache_rm_userdata($userdata);
|
||||
}
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function delete_user_sessions ($user_id)
|
||||
{
|
||||
cache_rm_user_sessions($user_id);
|
||||
|
||||
$user_id = get_id_csv($user_id);
|
||||
DB()->query("DELETE FROM ". BB_SESSIONS ." WHERE session_user_id IN($user_id)");
|
||||
}
|
|
@ -1,28 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Reserved prefixes:
|
||||
*
|
||||
* "L_" - lang var, {L_VAR} is eq to $lang['VAR']
|
||||
* "$" - php var, {$VAR} is eq to $VAR (in $this->execute() scope!)
|
||||
* "#" - constant, {#CON} is eq to CON
|
||||
*
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) die(basename(__FILE__));
|
||||
|
||||
// Template system constants
|
||||
define('XS_TPL_PREFIX', 'tpl_');
|
||||
define('XS_USE_ISSET', '1');
|
||||
define('XS_TAG_NONE', 0);
|
||||
define('XS_TAG_BEGIN', 2);
|
||||
define('XS_TAG_END', 3);
|
||||
define('XS_TAG_INCLUDE', 4);
|
||||
define('XS_TAG_IF', 5);
|
||||
define('XS_TAG_ELSE', 6);
|
||||
define('XS_TAG_ELSEIF', 7);
|
||||
define('XS_TAG_ENDIF', 8);
|
||||
define('XS_TAG_BEGINELSE', 11);
|
||||
|
||||
class Template
|
||||
{
|
||||
|
@ -89,7 +66,7 @@ class Template
|
|||
/**
|
||||
* Constructor. Installs XS mod on first run or updates it and sets the root dir.
|
||||
*/
|
||||
function Template($root = '.')
|
||||
function __construct ($root = '.')
|
||||
{
|
||||
global $bb_cfg, $lang;
|
||||
|
|
@ -2611,3 +2611,76 @@ function bb_captcha ($mode, $callback = '')
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
## Sessions ##
|
||||
function ignore_cached_userdata ()
|
||||
{
|
||||
return (defined('IN_PM')) ? true : false;
|
||||
}
|
||||
|
||||
function cache_get_userdata ($id)
|
||||
{
|
||||
if (ignore_cached_userdata()) return false;
|
||||
|
||||
return CACHE('session_cache')->get($id);
|
||||
}
|
||||
|
||||
function cache_set_userdata ($userdata, $force = false)
|
||||
{
|
||||
global $bb_cfg;
|
||||
|
||||
if (!$userdata || (ignore_cached_userdata() && !$force)) return false;
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->set($id, $userdata, $bb_cfg['session_update_intrv']);
|
||||
}
|
||||
|
||||
function cache_rm_userdata ($userdata)
|
||||
{
|
||||
if (!$userdata) return false;
|
||||
|
||||
$id = ($userdata['user_id'] == GUEST_UID) ? $userdata['session_ip'] : $userdata['session_id'];
|
||||
return CACHE('session_cache')->rm($id);
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function cache_rm_user_sessions ($user_id)
|
||||
{
|
||||
$user_id = get_id_csv($user_id);
|
||||
|
||||
$rowset = DB()->fetch_rowset("
|
||||
SELECT session_id FROM ". BB_SESSIONS ." WHERE session_user_id IN($user_id)
|
||||
");
|
||||
|
||||
foreach ($rowset as $row)
|
||||
{
|
||||
CACHE('session_cache')->rm($row['session_id']);
|
||||
}
|
||||
}
|
||||
|
||||
function cache_update_userdata ($userdata)
|
||||
{
|
||||
return cache_set_userdata($userdata, true);
|
||||
}
|
||||
|
||||
function db_update_userdata ($userdata, $sql_ary, $data_already_escaped = true)
|
||||
{
|
||||
if (!$userdata) return false;
|
||||
|
||||
$sql_args = DB()->build_array('UPDATE', $sql_ary, $data_already_escaped);
|
||||
DB()->query("UPDATE ". BB_USERS ." SET $sql_args WHERE user_id = {$userdata['user_id']}");
|
||||
|
||||
if (DB()->affected_rows())
|
||||
{
|
||||
cache_rm_userdata($userdata);
|
||||
}
|
||||
}
|
||||
|
||||
// $user_id - array(id1,id2,..) or (string) id
|
||||
function delete_user_sessions ($user_id)
|
||||
{
|
||||
cache_rm_user_sessions($user_id);
|
||||
|
||||
$user_id = get_id_csv($user_id);
|
||||
DB()->query("DELETE FROM ". BB_SESSIONS ." WHERE session_user_id IN($user_id)");
|
||||
}
|
||||
|
|
|
@ -335,6 +335,23 @@ define('REQUEST', 4);
|
|||
define('CHBOX', 5);
|
||||
define('SELECT', 6);
|
||||
|
||||
define('ONLY_NEW_POSTS', 1);
|
||||
define('ONLY_NEW_TOPICS', 2);
|
||||
|
||||
// Template system constants
|
||||
define('XS_TPL_PREFIX', 'tpl_');
|
||||
define('XS_USE_ISSET', '1');
|
||||
define('XS_TAG_NONE', 0);
|
||||
define('XS_TAG_BEGIN', 2);
|
||||
define('XS_TAG_END', 3);
|
||||
define('XS_TAG_INCLUDE', 4);
|
||||
define('XS_TAG_IF', 5);
|
||||
define('XS_TAG_ELSE', 6);
|
||||
define('XS_TAG_ELSEIF', 7);
|
||||
define('XS_TAG_ENDIF', 8);
|
||||
define('XS_TAG_BEGINELSE', 11);
|
||||
|
||||
|
||||
if (!empty($banned_user_agents))
|
||||
{
|
||||
foreach ($banned_user_agents as $agent)
|
||||
|
@ -410,13 +427,11 @@ function make_url ($path = '')
|
|||
}
|
||||
|
||||
require(INC_DIR .'functions.php');
|
||||
require(INC_DIR .'sessions.php');
|
||||
require(INC_DIR .'template.php');
|
||||
require(CORE_DIR .'mysql.php');
|
||||
|
||||
$bb_cfg = array_merge(bb_get_config(BB_CONFIG), $bb_cfg);
|
||||
|
||||
$user = new user_common();
|
||||
$user = new Sessions();
|
||||
$userdata =& $user->data;
|
||||
|
||||
if (DBG_USER) require(INC_DIR .'functions_dev.php');
|
||||
|
|
|
@ -411,8 +411,7 @@ foreach ($profile_fields as $field => $can_edit)
|
|||
}
|
||||
else if (!empty($_FILES['avatar']['name']) && $bb_cfg['avatars']['up_allowed'])
|
||||
{
|
||||
require(INC_DIR .'functions_upload.php');
|
||||
$upload = new upload_common();
|
||||
$upload = new Upload();
|
||||
|
||||
if ($upload->init($bb_cfg['avatars'], $_FILES['avatar']) AND $upload->store('avatar', $pr_data))
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue