First commit

This commit is contained in:
2025-06-18 10:24:27 +08:00
commit ebc39cd5dd
3873 changed files with 412712 additions and 0 deletions

36
uc_client/model/app.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: app.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
class appmodel {
var $db;
var $base;
function __construct(&$base) {
$this->appmodel($base);
}
function appmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function get_apps($col = '*', $where = '') {
$arr = $this->db->fetch_all("SELECT $col FROM ".UC_DBTABLEPRE."applications".($where ? ' WHERE '.$where : ''), 'appid');
foreach($arr as $k => $v) {
isset($v['extra']) && !empty($v['extra']) && $v['extra'] = unserialize($v['extra']);
unset($v['authkey']);
$arr[$k] = $v;
}
return $arr;
}
}
?>

295
uc_client/model/base.php Normal file
View File

@@ -0,0 +1,295 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: base.php 1167 2014-11-03 03:06:21Z hypowang $
*/
!defined('IN_UC') && exit('Access Denied');
if(!function_exists('getgpc')) {
function getgpc($k, $var='G') {
switch($var) {
case 'G': $var = &$_GET; break;
case 'P': $var = &$_POST; break;
case 'C': $var = &$_COOKIE; break;
case 'R': $var = &$_REQUEST; break;
}
return isset($var[$k]) ? $var[$k] : NULL;
}
}
class base {
var $sid;
var $time;
var $onlineip;
var $db;
var $key;
var $settings;
var $cache;
var $_CACHE;
var $app;
var $user = array();
var $input = array();
function __construct() {
$this->base();
}
function base() {
require_once UC_ROOT.'./model/var.php';
base_var::bind($this);
if(empty($this->time)) {
$this->init_var();
$this->init_db();
$this->init_cache();
$this->init_note();
$this->init_mail();
}
}
function init_var() {
$this->time = time();
$this->onlineip = $_SERVER['REMOTE_ADDR'];
if (!defined('UC_ONLYREMOTEADDR') || (defined('UC_ONLYREMOTEADDR') && !constant('UC_ONLYREMOTEADDR'))) {
require_once UC_ROOT.'./lib/ucip.class.php';
if(defined('UC_IPGETTER') && !empty(constant('UC_IPGETTER'))) {
$s = defined('UC_IPGETTER_'.strtoupper(constant('UC_IPGETTER'))) ? (is_string(constant('UC_IPGETTER_'.strtoupper(constant('UC_IPGETTER')))) ? unserialize(constant('UC_IPGETTER_'.strtoupper(constant('UC_IPGETTER')))) : constant('UC_IPGETTER_'.strtoupper(constant('UC_IPGETTER')))) : array();
$c = 'ucip_getter_'.strtolower(constant('UC_IPGETTER'));
require_once UC_ROOT.'./lib/'.$c.'.class.php';
$r = $c::get($s);
$this->onlineip = ucip::validate_ip($r) ? $r : $this->onlineip;
} else if (isset($_SERVER['HTTP_CLIENT_IP']) && ucip::validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
$this->onlineip = $_SERVER['HTTP_CLIENT_IP'];
} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ",") > 0) {
$exp = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$this->onlineip = ucip::validate_ip(trim($exp[0])) ? $exp[0] : $this->onlineip;
} else {
$this->onlineip = ucip::validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $this->onlineip;
}
}
}
$this->app['appid'] = UC_APPID;
}
function init_input($getagent = '') {
}
function init_db() {
require_once UC_ROOT.'lib/dbi.class.php';
$this->db = new ucclient_db();
$this->db->connect(UC_DBHOST, UC_DBUSER, UC_DBPW, '', UC_DBCHARSET, UC_DBCONNECT, UC_DBTABLEPRE);
}
function load($model, $base = NULL, $release = '') {
$base = $base ? $base : $this;
if(empty($_ENV[$model])) {
require_once UC_ROOT."./model/$model.php";
$modelname = $model.'model';
$_ENV[$model] = new $modelname($base);
}
return $_ENV[$model];
}
function date($time, $type = 3) {
if(!$this->settings) {
$this->settings = $this->cache('settings');
}
$format[] = $type & 2 ? (!empty($this->settings['dateformat']) ? $this->settings['dateformat'] : 'Y-n-j') : '';
$format[] = $type & 1 ? (!empty($this->settings['timeformat']) ? $this->settings['timeformat'] : 'H:i') : '';
return gmdate(implode(' ', $format), $time + $this->settings['timeoffset']);
}
function page_get_start($page, $ppp, $totalnum) {
$totalpage = ceil($totalnum / $ppp);
$page = max(1, min($totalpage,intval($page)));
return ($page - 1) * $ppp;
}
function implode($arr) {
return "'".implode("','", (array)$arr)."'";
}
function set_home($uid, $dir = '.') {
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
!is_dir($dir.'/'.$dir1) && mkdir($dir.'/'.$dir1, 0777) && @touch($dir.'/'.$dir1.'/index.htm');
!is_dir($dir.'/'.$dir1.'/'.$dir2) && mkdir($dir.'/'.$dir1.'/'.$dir2, 0777) && @touch($dir.'/'.$dir1.'/'.$dir2.'/index.htm');
!is_dir($dir.'/'.$dir1.'/'.$dir2.'/'.$dir3) && mkdir($dir.'/'.$dir1.'/'.$dir2.'/'.$dir3, 0777) && @touch($dir.'/'.$dir1.'/'.$dir2.'/'.$dir3.'/index.htm');
}
function get_home($uid) {
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
return $dir1.'/'.$dir2.'/'.$dir3;
}
function get_avatar($uid, $size = 'big', $type = '') {
$size = in_array($size, array('big', 'middle', 'small')) ? $size : 'big';
$uid = abs(intval($uid));
$uid = sprintf("%09d", $uid);
$dir1 = substr($uid, 0, 3);
$dir2 = substr($uid, 3, 2);
$dir3 = substr($uid, 5, 2);
$typeadd = $type == 'real' ? '_real' : '';
return $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($uid, -2).$typeadd."_avatar_$size.jpg";
}
function &cache($cachefile) {
if(!isset($this->_CACHE[$cachefile])) {
$cachepath = UC_DATADIR.'./cache/'.$cachefile.'.php';
if(!file_exists($cachepath)) {
$this->load('cache');
$_ENV['cache']->updatedata($cachefile);
} else {
include_once $cachepath;
$this->_CACHE[$cachefile] = $_CACHE[$cachefile];
}
}
return $this->_CACHE[$cachefile];
}
function get_setting($k = array(), $decode = FALSE) {
$return = array();
$sqladd = $k ? "WHERE k IN (".$this->implode($k).")" : '';
$settings = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."settings $sqladd");
if(is_array($settings)) {
foreach($settings as $arr) {
$return[$arr['k']] = $decode ? unserialize($arr['v']) : $arr['v'];
}
}
return $return;
}
function init_cache() {
$this->settings = $this->cache('settings');
$this->cache['apps'] = $this->cache('apps');
if(PHP_VERSION > '5.1') {
$timeoffset = intval($this->settings['timeoffset'] / 3600);
@date_default_timezone_set('Etc/GMT'.($timeoffset > 0 ? '-' : '+').(abs($timeoffset)));
}
}
function cutstr($string, $length, $dot = ' ...') {
if(strlen($string) <= $length) {
return $string;
}
$string = str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'), $string);
$strcut = '';
if(strtolower(UC_CHARSET) == 'utf-8') {
$n = $tn = $noc = 0;
while($n < strlen($string)) {
$t = ord($string[$n]);
if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
$tn = 1; $n++; $noc++;
} elseif(194 <= $t && $t <= 223) {
$tn = 2; $n += 2; $noc += 2;
} elseif(224 <= $t && $t < 239) {
$tn = 3; $n += 3; $noc += 2;
} elseif(240 <= $t && $t <= 247) {
$tn = 4; $n += 4; $noc += 2;
} elseif(248 <= $t && $t <= 251) {
$tn = 5; $n += 5; $noc += 2;
} elseif($t == 252 || $t == 253) {
$tn = 6; $n += 6; $noc += 2;
} else {
$n++;
}
if($noc >= $length) {
break;
}
}
if($noc > $length) {
$n -= $tn;
}
$strcut = substr($string, 0, $n);
} else {
for($i = 0; $i < $length; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
}
$strcut = str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $strcut);
return $strcut.$dot;
}
function init_note() {
if($this->note_exists()) {
$this->load('note');
$_ENV['note']->send();
}
}
function note_exists() {
if(!is_numeric(constant("UC_APPID"))) {
return NULL;
}
$noteexists = $this->db->result_first("SELECT value FROM ".UC_DBTABLEPRE."vars WHERE name='noteexists".UC_APPID."'");
if(empty($noteexists)) {
return FALSE;
} else {
return TRUE;
}
}
function init_mail() {
if($this->mail_exists() && !getgpc('inajax')) {
$this->load('mail');
$_ENV['mail']->send();
}
}
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
return uc_authcode($string, $operation, $key, $expiry);
}
function unserialize($s) {
return uc_unserialize($s);
}
function input($k) {
return isset($this->input[$k]) ? (is_array($this->input[$k]) ? $this->input[$k] : trim($this->input[$k])) : NULL;
}
function mail_exists() {
$mailexists = $this->db->result_first("SELECT value FROM ".UC_DBTABLEPRE."vars WHERE name='mailexists'");
if(empty($mailexists)) {
return FALSE;
} else {
return TRUE;
}
}
function dstripslashes($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = $this->dstripslashes($val);
}
} else {
$string = stripslashes($string);
}
return $string;
}
}
?>

93
uc_client/model/cache.php Normal file
View File

@@ -0,0 +1,93 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: cache.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
class cachemodel {
var $db;
var $base;
var $map;
function __construct(&$base) {
$this->cachemodel($base);
}
function cachemodel(&$base) {
$this->base = $base;
$this->db = $base->db;
$this->map = array(
'settings' => array('settings'),
'badwords' => array('badwords'),
'apps' => array('apps'),
);
}
function updatedata($cachefile = '') {
if($cachefile) {
foreach((array)$this->map[$cachefile] as $modules) {
$s = "<?php\r\n";
foreach((array)$modules as $m) {
$method = "_get_$m";
$s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
}
$s .= "\r\n?>";
file_put_contents(UC_DATADIR."./cache/$cachefile.php", $s, LOCK_EX);
}
} else {
foreach((array)$this->map as $file => $modules) {
$s = "<?php\r\n";
foreach($modules as $m) {
$method = "_get_$m";
$s .= '$_CACHE[\''.$m.'\'] = '.var_export($this->$method(), TRUE).";\r\n";
}
$s .= "\r\n?>";
file_put_contents(UC_DATADIR."./cache/$file.php", $s, LOCK_EX);
}
}
}
function updatetpl() {
}
function _get_badwords() {
$data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."badwords");
$return = array();
if(is_array($data)) {
foreach($data as $k => $v) {
$return['findpattern'][$k] = $v['findpattern'];
$return['replace'][$k] = $v['replacement'];
}
}
return $return;
}
function _get_apps() {
$this->base->load('app');
$apps = $_ENV['app']->get_apps();
$apps2 = array();
if(is_array($apps)) {
foreach($apps as $v) {
if(!empty($v['extra'])) {
$v['extra'] = is_array($v['extra']) ? $v['extra'] : unserialize($v['extra']);
}
$apps2[$v['appid']] = $v;
}
}
return $apps2;
}
function _get_settings() {
return $this->base->get_setting();
}
}
?>

View File

@@ -0,0 +1,56 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: domain.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
class domainmodel {
var $db;
var $base;
function __construct(&$base) {
$this->domainmodel($base);
}
function domainmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function add_domain($domain, $ip) {
if($domain) {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."domains SET domain='$domain', ip='$ip'");
}
return $this->db->insert_id();
}
function get_total_num() {
$data = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."domains");
return $data;
}
function get_list($page, $ppp, $totalnum) {
$start = $this->base->page_get_start($page, $ppp, $totalnum);
$data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."domains LIMIT $start, $ppp");
return $data;
}
function delete_domain($arr) {
$domainids = $this->base->implode($arr);
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."domains WHERE id IN ($domainids)");
return $this->db->affected_rows();
}
function update_domain($domain, $ip, $id) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."domains SET domain='$domain', ip='$ip' WHERE id='$id'");
return $this->db->affected_rows();
}
}
?>

107
uc_client/model/friend.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: friend.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
class friendmodel {
var $db;
var $base;
function __construct(&$base) {
$this->friendmodel($base);
}
function friendmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function add($uid, $friendid, $comment='') {
$direction = $this->db->result_first("SELECT direction FROM ".UC_DBTABLEPRE."friends WHERE uid='$friendid' AND friendid='$uid' LIMIT 1");
if($direction == 1) {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."friends SET uid='$uid', friendid='$friendid', comment='$comment', direction='3'", 'SILENT');
$this->db->query("UPDATE ".UC_DBTABLEPRE."friends SET direction='3' WHERE uid='$friendid' AND friendid='$uid'");
return 1;
} elseif($direction == 2) {
return 1;
} elseif($direction == 3) {
return -1;
} else {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."friends SET uid='$uid', friendid='$friendid', comment='$comment', direction='1'", 'SILENT');
return $this->db->insert_id();
}
}
function delete($uid, $friendids) {
$friendids = $this->base->implode($friendids);
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."friends WHERE uid='$uid' AND friendid IN ($friendids)");
$affectedrows = $this->db->affected_rows();
if($affectedrows > 0) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."friends SET direction=1 WHERE uid IN ($friendids) AND friendid='$uid' AND direction='3'");
}
return $affectedrows;
}
function get_totalnum_by_uid($uid, $direction = 0) {
$sqladd = '';
if($direction == 0) {
$sqladd = "uid='$uid'";
} elseif($direction == 1) {
$sqladd = "uid='$uid' AND direction='1'";
} elseif($direction == 2) {
$sqladd = "friendid='$uid' AND direction='1'";
} elseif($direction == 3) {
$sqladd = "uid='$uid' AND direction='3'";
}
$totalnum = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."friends WHERE $sqladd");
return $totalnum;
}
function get_list($uid, $page, $pagesize, $totalnum, $direction = 0) {
$start = $this->base->page_get_start($page, $pagesize, $totalnum);
$sqladd = '';
if($direction == 0) {
$sqladd = "f.uid='$uid'";
} elseif($direction == 1) {
$sqladd = "f.uid='$uid' AND f.direction='1'";
} elseif($direction == 2) {
$sqladd = "f.friendid='$uid' AND f.direction='1'";
} elseif($direction == 3) {
$sqladd = "f.uid='$uid' AND f.direction='3'";
}
if($sqladd) {
$data = $this->db->fetch_all("SELECT f.*, m.username FROM ".UC_DBTABLEPRE."friends f LEFT JOIN ".UC_DBTABLEPRE."members m ON f.friendid=m.uid WHERE $sqladd LIMIT $start, $pagesize");
return $data;
} else {
return array();
}
}
function is_friend($uid, $friendids, $direction = 0) {
$friendid_str = implode("', '", $friendids);
$sqladd = '';
if($direction == 0) {
$sqladd = "uid='$uid'";
} elseif($direction == 1) {
$sqladd = "uid='$uid' AND friendid IN ('$friendid_str') AND direction='1'";
} elseif($direction == 2) {
$sqladd = "friendid='$uid' AND uid IN ('$friendid_str') AND direction='1'";
} elseif($direction == 3) {
$sqladd = "uid='$uid' AND friendid IN ('$friendid_str') AND direction='3'";
}
if($this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."friends WHERE $sqladd") == count($friendids)) {
return true;
} else {
return false;
}
}
}
?>

View File

@@ -0,0 +1 @@

150
uc_client/model/mail.php Normal file
View File

@@ -0,0 +1,150 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: mail.php 1139 2012-05-08 09:02:11Z liulanbo $
*/
!defined('IN_UC') && exit('Access Denied');
define('UC_MAIL_REPEAT', 5);
class mailmodel {
var $db;
var $base;
var $apps;
function __construct(&$base) {
$this->mailmodel($base);
}
function mailmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
$this->apps = &$this->base->cache['apps'];
}
function get_total_num() {
$data = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."mailqueue");
return $data;
}
function get_list($page, $ppp, $totalnum) {
$start = $this->base->page_get_start($page, $ppp, $totalnum);
$data = $this->db->fetch_all("SELECT m.*, u.username, u.email FROM ".UC_DBTABLEPRE."mailqueue m LEFT JOIN ".UC_DBTABLEPRE."members u ON m.touid=u.uid ORDER BY dateline DESC LIMIT $start, $ppp");
foreach((array)$data as $k => $v) {
$data[$k]['subject'] = dhtmlspecialchars($v['subject']);
$data[$k]['tomail'] = empty($v['tomail']) ? $v['email'] : $v['tomail'];
$data[$k]['dateline'] = $v['dateline'] ? $this->base->date($data[$k]['dateline']) : '';
$data[$k]['appname'] = $this->base->cache['apps'][$v['appid']]['name'];
}
return $data;
}
function delete_mail($ids) {
$ids = $this->base->implode($ids);
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."mailqueue WHERE mailid IN ($ids)");
return $this->db->affected_rows();
}
function add($mail) {
if($mail['level']) {
$sql = "INSERT INTO ".UC_DBTABLEPRE."mailqueue (touid, tomail, subject, message, frommail, charset, htmlon, level, dateline, failures, appid) VALUES ";
$values_arr = array();
foreach($mail['uids'] as $uid) {
if(empty($uid)) continue;
$uid = intval($uid);
$values_arr[] = "('$uid', '', '{$mail['subject']}', '{$mail['message']}', '{$mail['frommail']}', '{$mail['charset']}', '{$mail['htmlon']}', '{$mail['level']}', '{$mail['dateline']}', '0', '{$mail['appid']}')";
}
foreach($mail['emails'] as $email) {
if(empty($email)) continue;
$values_arr[] = "('', '$email', '{$mail['subject']}', '{$mail['message']}', '{$mail['frommail']}', '{$mail['charset']}', '{$mail['htmlon']}', '{$mail['level']}', '{$mail['dateline']}', '0', '{$mail['appid']}')";
}
$sql .= implode(',', $values_arr);
$this->db->query($sql);
$insert_id = $this->db->insert_id();
$insert_id && $this->db->query("REPLACE INTO ".UC_DBTABLEPRE."vars SET name='mailexists', value='1'");
return $insert_id;
} else {
$mail['email_to'] = array();
$uids = 0;
foreach($mail['uids'] as $uid) {
if(empty($uid)) continue;
$uids .= ','.intval($uid);
}
$users = $this->db->fetch_all("SELECT uid, username, email FROM ".UC_DBTABLEPRE."members WHERE uid IN ($uids)");
foreach($users as $v) {
$mail['email_to'][] = $v['username'].'<'.$v['email'].'>';
}
foreach($mail['emails'] as $email) {
if(empty($email)) continue;
$mail['email_to'][] = $email;
}
$mail['message'] = str_replace('\"', '"', $mail['message']);
$mail['email_to'] = implode(',', $mail['email_to']);
return $this->send_one_mail($mail);
}
}
function send() {
register_shutdown_function(array($this, '_send'));
}
function _send() {
$mail = $this->_get_mail();
if(empty($mail)) {
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."vars SET name='mailexists', value='0'");
return NULL;
} else {
$mail['email_to'] = $mail['tomail'] ? $mail['tomail'] : $mail['username'].'<'.$mail['email'].'>';
if($this->send_one_mail($mail)) {
$this->_delete_one_mail($mail['mailid']);
return true;
} else {
$this->_update_failures($mail['mailid']);
return false;
}
}
}
function send_by_id($mailid) {
if ($this->send_one_mail($this->_get_mail_by_id($mailid))) {
$this->_delete_one_mail($mailid);
return true;
}
}
function send_one_mail($mail) {
if(empty($mail)) return;
$mail['email_to'] = $mail['email_to'] ? $mail['email_to'] : $mail['username'].'<'.$mail['email'].'>';
$mail_setting = $this->base->settings;
return include UC_ROOT.'lib/sendmail.inc.php';
}
function _get_mail() {
$data = $this->db->fetch_first("SELECT m.*, u.username, u.email FROM ".UC_DBTABLEPRE."mailqueue m LEFT JOIN ".UC_DBTABLEPRE."members u ON m.touid=u.uid WHERE failures<'".UC_MAIL_REPEAT."' ORDER BY level DESC, mailid ASC LIMIT 1");
return $data;
}
function _get_mail_by_id($mailid) {
$data = $this->db->fetch_first("SELECT m.*, u.username, u.email FROM ".UC_DBTABLEPRE."mailqueue m LEFT JOIN ".UC_DBTABLEPRE."members u ON m.touid=u.uid WHERE mailid='$mailid'");
return $data;
}
function _delete_one_mail($mailid) {
$mailid = intval($mailid);
return $this->db->query("DELETE FROM ".UC_DBTABLEPRE."mailqueue WHERE mailid='$mailid'");
}
function _update_failures($mailid) {
$mailid = intval($mailid);
return $this->db->query("UPDATE ".UC_DBTABLEPRE."mailqueue SET failures=failures+1 WHERE mailid='$mailid'");
}
}
?>

221
uc_client/model/misc.php Normal file
View File

@@ -0,0 +1,221 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: misc.php 1127 2011-12-14 04:24:58Z svn_project_zhangjie $
*/
!defined('IN_UC') && exit('Access Denied');
define('UC_ARRAY_SEP_1', 'UC_ARRAY_SEP_1');
define('UC_ARRAY_SEP_2', 'UC_ARRAY_SEP_2');
class miscmodel {
var $db;
var $base;
function __construct(&$base) {
$this->miscmodel($base);
}
function miscmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function get_apps($col = '*', $where = '') {
$arr = $this->db->fetch_all("SELECT $col FROM ".UC_DBTABLEPRE."applications".($where ? ' WHERE '.$where : ''));
return $arr;
}
function delete_apps($appids) {
}
function update_app($appid, $name, $url, $authkey, $charset, $dbcharset) {
}
function alter_app_table($appid, $operation = 'ADD') {
}
function get_host_by_url($url) {
}
function check_url($url) {
}
function check_ip($ip) {
}
function test_api($url, $ip = '') {
}
function dfopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) {
$__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
if($__times__ > 2) {
return '';
}
$url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__";
return $this->dfopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype, $allowcurl);
}
function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE', $allowcurl = TRUE) {
$return = '';
$matches = parse_url($url);
$scheme = strtolower($matches['scheme']);
$host = $matches['host'];
$path = !empty($matches['path']) ? $matches['path'].(!empty($matches['query']) ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : ($scheme == 'https' ? 443 : 80);
if(function_exists('curl_init') && function_exists('curl_exec') && $allowcurl) {
$ch = curl_init();
$ip && curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: ".$host));
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if(!empty($ip) && filter_var($ip, FILTER_VALIDATE_IP) && !filter_var($host, FILTER_VALIDATE_IP) && version_compare(PHP_VERSION, '5.5.0', 'ge')) {
curl_setopt($ch, CURLOPT_RESOLVE, array("$host:$port:$ip"));
curl_setopt($ch, CURLOPT_URL, $scheme.'://'.$host.':'.$port.$path);
} else {
curl_setopt($ch, CURLOPT_URL, $scheme.'://'.($ip ? $ip : $host).':'.$port.$path);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if($post) {
curl_setopt($ch, CURLOPT_POST, 1);
if($encodetype == 'URLENCODE') {
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
} else {
parse_str($post, $postarray);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray);
}
}
if($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
$status = curl_getinfo($ch);
$errno = curl_errno($ch);
curl_close($ch);
if($errno || $status['http_code'] != 200) {
return;
} else {
return !$limit ? $data : substr($data, 0, $limit);
}
}
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$header = "Accept: */*\r\n";
$header .= "Accept-Language: zh-cn\r\n";
if($allowcurl) {
$encodetype = 'URLENCODE';
}
$boundary = $encodetype == 'URLENCODE' ? '' : '; boundary='.trim(substr(trim($post), 2, strpos(trim($post), "\n") - 2));
$header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
$header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
$header .= "Host: $host:$port\r\n";
$header .= 'Content-Length: '.strlen($post)."\r\n";
$header .= "Connection: Close\r\n";
$header .= "Cache-Control: no-cache\r\n";
$header .= "Cookie: $cookie\r\n\r\n";
$out .= $header.$post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$header = "Accept: */*\r\n";
$header .= "Accept-Language: zh-cn\r\n";
$header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n";
$header .= "Host: $host:$port\r\n";
$header .= "Connection: Close\r\n";
$header .= "Cookie: $cookie\r\n\r\n";
$out .= $header;
}
$fpflag = 0;
$context = array();
if($scheme == 'https') {
$context['ssl'] = array(
'verify_peer' => false,
'verify_peer_name' => false,
'peer_name' => $host
);
if(version_compare(PHP_VERSION, '5.6.0', '<')) {
$context['ssl']['SNI_enabled'] = true;
$context['ssl']['SNI_server_name'] = $host;
}
}
if(ini_get('allow_url_fopen')) {
$context['http'] = array(
'method' => $post ? 'POST' : 'GET',
'header' => $header,
'timeout' => $timeout
);
if($post) {
$context['http']['content'] = $post;
}
$context = stream_context_create($context);
$fp = @fopen($scheme.'://'.($ip ? $ip : $host).':'.$port.$path, 'b', false, $context);
$fpflag = 1;
} elseif(function_exists('stream_socket_client')) {
$context = stream_context_create($context);
$fp = @stream_socket_client(($scheme == 'https' ? 'ssl://' : '').($ip ? $ip : $host).':'.$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
} else {
$fp = @fsocketopen(($scheme == 'https' ? 'ssl://' : '').($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout);
}
if(!$fp) {
return '';
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
if(!$fpflag) {
@fwrite($fp, $out);
}
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp) && !$fpflag) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
function array2string($arr) {
$s = $sep = '';
if($arr && is_array($arr)) {
foreach($arr as $k => $v) {
$s .= $sep.addslashes($k).UC_ARRAY_SEP_1.$v;
$sep = UC_ARRAY_SEP_2;
}
}
return $s;
}
function string2array($s) {
$arr = explode(UC_ARRAY_SEP_2, $s);
$arr2 = array();
foreach($arr as $k => $v) {
list($key, $val) = explode(UC_ARRAY_SEP_1, $v);
$arr2[$key] = $val;
}
return $arr2;
}
}
?>

199
uc_client/model/note.php Normal file
View File

@@ -0,0 +1,199 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: note.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
define('UC_NOTE_REPEAT', 5);
define('UC_NOTE_TIMEOUT', 15);
define('UC_NOTE_GC', 10000);
define('API_RETURN_FAILED', '-1');
class notemodel {
var $db;
var $base;
var $apps;
var $operations = array();
var $notetype = 'HTTP';
function __construct(&$base) {
$this->notemodel($base);
}
function notemodel(&$base) {
$this->base = $base;
$this->db = $base->db;
$this->apps = $this->base->cache('apps');
$this->operations = array(
'test'=>array('', 'action=test'),
'deleteuser'=>array('', 'action=deleteuser'),
'renameuser'=>array('', 'action=renameuser'),
'deletefriend'=>array('', 'action=deletefriend'),
'gettag'=>array('', 'action=gettag', 'tag', 'updatedata'),
'getcreditsettings'=>array('', 'action=getcreditsettings'),
'getcredit'=>array('', 'action=getcredit'),
'updatecreditsettings'=>array('', 'action=updatecreditsettings'),
'updateclient'=>array('', 'action=updateclient'),
'updatepw'=>array('', 'action=updatepw'),
'updatebadwords'=>array('', 'action=updatebadwords'),
'updatehosts'=>array('', 'action=updatehosts'),
'updateapps'=>array('', 'action=updateapps'),
'updatecredit'=>array('', 'action=updatecredit'),
);
}
function get_total_num($all = TRUE) {
}
function get_list($page, $ppp, $totalnum, $all = TRUE) {
}
function delete_note($ids) {
}
function add($operation, $getdata='', $postdata='', $appids=array(), $pri = 0) {
$extra = $varextra = '';
$appadd = $varadd = array();
foreach((array)$this->apps as $appid => $app) {
$appid = $app['appid'];
if($appid == intval($appid)) {
if($appids && !in_array($appid, $appids)) {
$appadd[] = 'app'.$appid."='1'";
} else {
$varadd[] = "('noteexists{$appid}', '1')";
}
}
}
if($appadd) {
$extra = implode(',', $appadd);
$extra = $extra ? ', '.$extra : '';
}
if($varadd) {
$varextra = implode(', ', $varadd);
$varextra = $varextra ? ', '.$varextra : '';
}
$getdata = addslashes($getdata);
$postdata = addslashes($postdata);
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."notelist SET getdata='$getdata', operation='$operation', pri='$pri', postdata='$postdata'$extra");
$insert_id = $this->db->insert_id();
$insert_id && $this->db->query("REPLACE INTO ".UC_DBTABLEPRE."vars (name, value) VALUES ('noteexists', '1')$varextra");
return $insert_id;
}
function send() {
register_shutdown_function(array($this, '_send'));
}
function _send() {
if(!is_numeric(constant("UC_APPID"))) {
return NULL;
}
$note = $this->_get_note();
if(empty($note)) {
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."vars SET name='noteexists".UC_APPID."', value='0'");
return NULL;
}
$this->sendone(UC_APPID, 0, $note);
$this->_gc();
}
function sendone($appid, $noteid = 0, $note = '') {
require_once UC_ROOT.'./lib/xml.class.php';
$return = FALSE;
$app = $this->apps[$appid];
if($noteid) {
$note = $this->_get_note_by_id($noteid);
}
$this->base->load('misc');
$apifilename = isset($app['apifilename']) && $app['apifilename'] ? $app['apifilename'] : 'uc.php';
if(((defined('UC_STANDALONE') && !empty(constant('UC_STANDALONE'))) || (defined('IN_DISCUZ') && in_array($note['operation'], array('deleteuser', 'renameuser', 'updatepw')))) && @include UC_ROOT.'./extend_client.php') {
$uc_note = new uc_note_handler();
$method = $note['operation'];
if(is_string($method) && !empty($method)) {
parse_str($note['getdata'], $note['getdata']);
$note['postdata'] = xml_unserialize($note['postdata']);
$response = $uc_note->$method($note['getdata'], $note['postdata']);
}
unset($uc_note);
} else {
$url = $this->get_url_code($note['operation'], $note['getdata'], $appid);
$note['postdata'] = str_replace(array("\n", "\r"), '', $note['postdata']);
$response = trim($_ENV['misc']->dfopen2($url, 0, $note['postdata'], '', 1, $app['ip'], UC_NOTE_TIMEOUT, TRUE));
}
$returnsucceed = $response != '' && ($response == 1 || is_array(xml_unserialize($response)));
$closedsqladd = $this->_close_note($note, $this->apps, $returnsucceed, $appid) ? ",closed='1'" : '';
if($returnsucceed) {
if($this->operations[$note['operation']][2]) {
$this->base->load($this->operations[$note['operation']][2]);
$func = $this->operations[$note['operation']][3];
$_ENV[$this->operations[$note['operation']][2]]->$func($appid, $response);
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."notelist SET app$appid='1', totalnum=totalnum+1, succeednum=succeednum+1, dateline='{$this->base->time}' $closedsqladd WHERE noteid='{$note['noteid']}'", 'SILENT');
$return = TRUE;
} else {
$this->db->query("UPDATE ".UC_DBTABLEPRE."notelist SET app$appid = app$appid-'1', totalnum=totalnum+1, dateline='{$this->base->time}' $closedsqladd WHERE noteid='{$note['noteid']}'", 'SILENT');
$return = FALSE;
}
return $return;
}
function _get_note() {
if(!is_numeric(constant("UC_APPID"))) {
return NULL;
}
$app_field = 'app'.UC_APPID;
$data = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."notelist WHERE closed='0' AND $app_field<'1' AND $app_field>'-".UC_NOTE_REPEAT."' LIMIT 1");
return $data;
}
function _gc() {
rand(0, UC_NOTE_GC) == 0 && $this->db->query("DELETE FROM ".UC_DBTABLEPRE."notelist WHERE closed='1'");
}
function _close_note($note, $apps, $returnsucceed, $appid) {
$note['app'.$appid] = $returnsucceed ? 1 : $note['app'.$appid] - 1;
$appcount = count($apps);
foreach($apps as $key => $app) {
$appstatus = $note['app'.$app['appid']];
if(!$app['recvnote'] || $appstatus == 1 || $appstatus <= -UC_NOTE_REPEAT) {
$appcount--;
}
}
if($appcount < 1) {
return TRUE;
}
}
function _get_note_by_id($noteid) {
$data = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."notelist WHERE noteid='$noteid'");
return $data;
}
function get_url_code($operation, $getdata, $appid) {
$app = $this->apps[$appid];
$authkey = UC_KEY;
$url = $app['url'];
$apifilename = isset($app['apifilename']) && $app['apifilename'] ? $app['apifilename'] : 'uc.php';
$action = $this->operations[$operation][1];
$code = urlencode($this->base->authcode("$action&".($getdata ? "$getdata&" : '')."time=".$this->base->time, 'ENCODE', $authkey));
return $url."/api/$apifilename?code=$code";
}
}
?>

868
uc_client/model/pm.php Normal file
View File

@@ -0,0 +1,868 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: pm.php 1160 2013-10-24 08:04:45Z jeffjzhang $
*/
!defined('IN_UC') && exit('Access Denied');
define('PMINBALCKLIST_ERROR', -6);
define('PMSENDSELF_ERROR', -8);
define('PMSENDNONE_ERROR', -9);
define('PMSENDCHATNUM_ERROR', -10);
define('PMTHREADNONE_ERROR', -11);
define('PMPRIVILEGENONE_ERROR', -12);
define('PMCHATTYPE_ERROR', -13);
define('PMUIDTYPE_ERROR', -14);
define('PMDATA_ERROR', -15);
class pmmodel {
var $db;
var $base;
function __construct(&$base) {
$this->pmmodel($base);
}
function pmmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function pmintval($pmid) {
return @is_numeric($pmid) ? $pmid : 0;
}
function getpmbypmid($uid, $pmid) {
if(!$pmid) {
return array();
}
$arr = array();
$pm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_indexes i LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON t.plid=i.plid WHERE i.pmid='$pmid'");
if($this->isprivilege($pm['plid'], $uid)) {
$pms = $this->db->fetch_all("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM ".UC_DBTABLEPRE.$this->getposttablename($pm['plid'])." p LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON t.plid=p.plid WHERE p.pmid='{$pm['pmid']}'");
$arr = $this->getpostlist($pms);
}
return $arr;
}
function isprivilege($plid, $uid) {
if(!$plid || !$uid) {
return true;
}
$query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid' AND uid='$uid'");
if($this->db->fetch_array($query)) {
return true;
} else {
return false;
}
}
function getpmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp, $type = 0) {
if(!$type) {
$pm = $this->getprivatepmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp);
} else {
$pm = $this->getchatpmbyplid($uid, $plid, $starttime, $endtime, $start, $ppp);
}
return $this->getpostlist($pm);
}
function getpostlist($list) {
if(empty($list)) {
return array();
}
$authoridarr = $authorarr = array();
foreach($list as $key => $value) {
$authoridarr[$value['authorid']] = $value['authorid'];
}
if($authoridarr) {
$this->base->load('user');
$authorarr = $_ENV['user']->id2name($authoridarr);
}
foreach($list as $key => $value) {
if($value['pmtype'] == 1) {
$users = explode('_', $value['min_max']);
if($value['authorid'] == $users[0]) {
$value['touid'] = $users[1];
} else {
$value['touid'] = $users[0];
}
} else {
$value['touid'] = 0;
}
$value['author'] = $authorarr[$value['authorid']];
$value['msgfromid'] = $value['authorid'];
$value['msgfrom'] = $value['author'];
$value['msgtoid'] = $value['touid'];
unset($value['min_max']);
unset($value['delstatus']);
unset($value['lastmessage']);
$list[$key] = $value;
}
return $list;
}
function setpmstatus($uid, $touids, $plids, $status = 0) {
if(!$uid) {
return false;
}
if(!$status) {
$oldstatus = 1;
$newstatus = 0;
} else {
$oldstatus = 0;
$newstatus = 1;
}
if($touids) {
foreach($touids as $key => $value) {
if($uid == $value || !$value || !preg_match("/^[0-9]+$/", $value)) {
return false;
}
$relastionship[] = $this->relationship($uid, $value);
}
$plid = $plidpostarr = array();
$query = $this->db->query("SELECT plid FROM ".UC_DBTABLEPRE."pm_lists WHERE min_max IN (".$this->base->implode($relationship).")");
while($thread = $this->db->fetch_array($query)) {
$plidarr[] = $thread['plid'];
}
if($plidarr) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew='$newstatus' WHERE plid IN (".$this->base->implode($plidarr).") AND uid='$uid' AND isnew='$oldstatus'");
}
}
if($plids) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew='$newstatus' WHERE plid IN (".$this->base->implode($plids).") AND uid='$uid' AND isnew='$oldstatus'");
}
return true;
}
function set_ignore($uid) {
return $this->db->query("DELETE FROM ".UC_DBTABLEPRE."newpm WHERE uid='$uid'");
}
function isnewpm($uid) {
return $this->db->result_first("SELECT uid FROM ".UC_DBTABLEPRE."newpm WHERE uid='$uid'");
}
function lastpm($uid) {
$lastpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT 1");
$lastmessage = unserialize($lastpm['lastmessage']);
if($lastmessage['lastauthorid']) {
$lastpm['lastauthorid'] = $lastmessage['lastauthorid'];
$lastpm['lastauthor'] = $lastmessage['lastauthor'];
$lastpm['lastsummary'] = $lastmessage['lastsummary'];
} else {
$lastpm['lastauthorid'] = $lastmessage['firstauthorid'];
$lastpm['lastauthor'] = $lastmessage['firstauthor'];
$lastpm['lastsummary'] = $lastmessage['firstsummary'];
}
return $lastpm;
}
function getpmnum($uid, $type = 0, $isnew = 0) {
$newsql = '';
$newnum = 0;
if($isnew) {
$newsql = 'AND m.isnew=1';
}
if(!$type) {
$newnum = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_members m WHERE m.uid='$uid' $newsql");
} else {
$newnum = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON t.plid=m.plid WHERE m.uid='$uid' $newsql AND t.pmtype='$type'");
}
return $newnum;
}
function getpmnumbyplid($uid, $plid) {
return $this->db->result_first("SELECT pmnum FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid' AND uid='$uid'");
}
function sendpm($fromuid, $fromusername, $touids, $subject, $message, $type = 0) {
if(!$fromuid || !$fromusername || !$touids || !$message) {
return 0;
}
$touids = array_unique($touids);
$relationship = $existplid = $pm_member_insertsql = array();
$this->base->load('user');
$tmptouidarr = $touids;
$blackls = $this->get_blackls($fromuid, $touids);
foreach($tmptouidarr as $key => $value) {
if($fromuid == $value || !$value) {
return PMSENDSELF_ERROR;
}
if(in_array('{ALL}', $blackls[$value])) {
unset($touids[$key]);
continue;
}
$blackls[$value] = $_ENV['user']->name2id($blackls[$value]);
if(!(isset($blackls[$value]) && !in_array($fromuid, $blackls[$value]))) {
unset($touids[$key]);
} else {
$relationship[$value] = $this->relationship($fromuid, $value);
}
}
if(empty($touids)) {
return PMSENDNONE_ERROR;
}
if($type == 1 && count($touids) < 2) {
return PMSENDCHATNUM_ERROR;
}
$_CACHE['badwords'] = $this->base->cache('badwords');
if($_CACHE['badwords']['findpattern']) {
$subject = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $subject);
$message = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $message);
}
if(!$subject) {
$subject = $this->removecode(trim($message), 80);
} else {
$subject = dhtmlspecialchars($subject);
}
$lastsummary = addslashes($this->removecode(trim(stripslashes($message)), 150));
$subject = addslashes($subject);
if(!$type) {
$query = $this->db->query("SELECT plid, min_max FROM ".UC_DBTABLEPRE."pm_lists WHERE min_max IN (".$this->base->implode($relationship).")");
while($thread = $this->db->fetch_array($query)) {
$existplid[$thread['min_max']] = $thread['plid'];
}
$lastmessage = array('lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
$lastmessage = addslashes(serialize($lastmessage));
foreach($relationship as $key => $value) {
if(!isset($existplid[$value])) {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_lists(authorid, pmtype, subject, members, min_max, dateline, lastmessage) VALUES('$fromuid', '1', '$subject', 2, '$value', '".$this->base->time."', '$lastmessage')");
$plid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_indexes(plid) VALUES('$plid')");
$pmid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE.$this->getposttablename($plid)."(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '".$this->base->time."', 0)");
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$key', '1', '1', '0', '".$this->base->time."')");
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$fromuid', '0', '1', '".$this->base->time."', '".$this->base->time."')");
} else {
$plid = $existplid[$value];
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_indexes(plid) VALUES('$plid')");
$pmid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE.$this->getposttablename($plid)."(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '".$this->base->time."', 0)");
$result = $this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$key', '1', '1', '0', '".$this->base->time."')", 'SILENT');
if(!$result) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='".$this->base->time."' WHERE plid='$plid' AND uid='$key'");
}
$result = $this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$fromuid', '0', '1', '".$this->base->time."', '".$this->base->time."')", 'SILENT');
if(!$result) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=0, pmnum=pmnum+1, lastupdate='".$this->base->time."', lastdateline='".$this->base->time."' WHERE plid='$plid' AND uid='$fromuid'");
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_lists SET lastmessage='$lastmessage' WHERE plid='$plid'");
}
}
} else {
$lastmessage = array('firstauthorid' => $fromuid, 'firstauthor' => $fromusername, 'firstsummary' => $lastsummary);
$lastmessage = addslashes(serialize($lastmessage));
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_lists(authorid, pmtype, subject, members, min_max, dateline, lastmessage) VALUES('$fromuid', '2', '$subject', '".(count($touids)+1)."', '', '".$this->base->time."', '$lastmessage')");
$plid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_indexes(plid) VALUES('$plid')");
$pmid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE.$this->getposttablename($plid)."(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '".$this->base->time."', 0)");
$pm_member_insertsql[] = "('$plid', '$fromuid', '0', '1', '".$this->base->time."', '".$this->base->time."')";
foreach($touids as $key => $value) {
$pm_member_insertsql[] = "('$plid', '$value', '1', '1', '0', '".$this->base->time."')";
}
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES ".implode(',', $pm_member_insertsql));
}
$newpm = array();
foreach($touids as $key => $value) {
$newpm[] = "('$value')";
}
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."newpm(uid) VALUES ".implode(',', $newpm));
return $pmid;
}
function replypm($plid, $fromuid, $fromusername, $message) {
if(!$plid || !$fromuid || !$fromusername || !$message) {
return 0;
}
$threadpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'");
if(empty($threadpm)) {
return PMTHREADNONE_ERROR;
}
if($threadpm['pmtype'] == 1) {
$users = explode('_', $threadpm['min_max']);
if($users[0] == $fromuid) {
$touid = $users[1];
} elseif($users[1] == $fromuid) {
$touid = $users[0];
} else {
return PMPRIVILEGENONE_ERROR;
}
$blackls = $this->get_blackls($fromuid, $touid);
if(in_array('{ALL}', $blackls[$touid])) {
return PMINBALCKLIST_ERROR;
}
$this->base->load('user');
$blackls[$touid] = $_ENV['user']->name2id($blackls[$touid]);
if(!(isset($blackls[$touid]) && !in_array($fromuid, $blackls[$touid]))) {
return PMINBALCKLIST_ERROR;
}
}
$memberuid = array();
$query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid'");
while($member = $this->db->fetch_array($query)) {
$memberuid[$member['uid']] = "('{$member['uid']}')";
}
if(!isset($memberuid[$fromuid])) {
return PMPRIVILEGENONE_ERROR;
}
$_CACHE['badwords'] = $this->base->cache('badwords');
if($_CACHE['badwords']['findpattern']) {
$message = @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $message);
}
$lastsummary = addslashes($this->removecode(trim(stripslashes($message)), 150));
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_indexes(plid) VALUES('$plid')");
$pmid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE.$this->getposttablename($plid)."(pmid, plid, authorid, message, dateline, delstatus) VALUES('$pmid', '$plid', '$fromuid', '$message', '".$this->base->time."', 0)");
if($threadpm['pmtype'] == 1) {
$lastmessage = array('lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
$lastmessage = addslashes(serialize($lastmessage));
$result = $this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$touid', '1', '1', '0', '".$this->base->time."')", 'SILENT');
if(!$result) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='".$this->base->time."' WHERE plid='$plid' AND uid='$touid'");
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=0, pmnum=pmnum+1, lastupdate='".$this->base->time."', lastdateline='".$this->base->time."' WHERE plid='$plid' AND uid='$fromuid'");
} else {
$lastmessage = unserialize($threadpm['lastmessage']);
$lastmessage = array('firstauthorid' => $lastmessage['firstauthorid'], 'firstauthor' => $lastmessage['firstauthor'], 'firstsummary' => $lastmessage['firstsummary'], 'lastauthorid' => $fromuid, 'lastauthor' => $fromusername, 'lastsummary' => $lastsummary);
$lastmessage = addslashes(serialize($lastmessage));
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=1, pmnum=pmnum+1, lastdateline='".$this->base->time."' WHERE plid='$plid'");
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=0, lastupdate='".$this->base->time."' WHERE plid='$plid' AND uid='$fromuid'");
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_lists SET lastmessage='$lastmessage' WHERE plid='$plid'");
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."newpm(uid) VALUES ".implode(',', $memberuid)."");
return $pmid;
}
function appendchatpm($plid, $uid, $touid) {
if(!$plid || !$uid || !$touid) {
return 0;
}
$threadpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'");
if(empty($threadpm)) {
return PMTHREADNONE_ERROR;
}
if($threadpm['pmtype'] != 2) {
return PMCHATTYPE_ERROR;
}
if($threadpm['authorid'] != $uid) {
return PMPRIVILEGENONE_ERROR;
}
$blackls = $this->get_blackls($uid, $touid);
if(in_array('{ALL}', $blackls[$touid])) {
return PMINBALCKLIST_ERROR;
}
$this->base->load('user');
$blackls[$touid] = $_ENV['user']->name2id($blackls[$touid]);
if(!(isset($blackls[$touid]) && !in_array($uid, $blackls[$touid]))) {
return PMINBALCKLIST_ERROR;
}
$pmnum = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE.$this->getposttablename($plid)." WHERE plid='$plid'");
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."pm_members(plid, uid, isnew, pmnum, lastupdate, lastdateline) VALUES('$plid', '$touid', '1', '$pmnum', '0', '0')", 'SILENT');
$num = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid'");
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_lists SET members='$num' WHERE plid='$plid'");
return 1;
}
function kickchatpm($plid, $uid, $touid) {
if(!$uid || !$touid || !$plid || $uid == $touid) {
return 0;
}
$threadpm = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'");
if($threadpm['pmtype'] != 2) {
return PMCHATTYPE_ERROR;
}
if($threadpm['authorid'] != $uid) {
return PMPRIVILEGENONE_ERROR;
}
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid' AND uid='$touid'");
$num = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid'");
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_lists SET members='$num' WHERE plid='$plid'");
return 1;
}
function quitchatpm($uid, $plids) {
if(!$uid || !$plids) {
return 0;
}
$list = array();
$query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE m.plid IN (".$this->base->implode($plids).") AND m.uid='$uid'");
while($threadpm = $this->db->fetch_array($query)) {
if($threadpm['pmtype'] != 2) {
return PMCHATTYPE_ERROR;
}
if($threadpm['authorid'] == $uid) {
return PMPRIVILEGENONE_ERROR;
}
$list[] = $threadpm['plid'];
}
if($list) {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid IN (".$this->base->implode($list).") AND uid='$uid'");
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_lists SET members=members-1 WHERE plid IN (".$this->base->implode($list).")");
}
return 1;
}
function deletepmbypmid($uid, $pmid) {
if(!$uid || !$pmid) {
return 0;
}
$index = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_indexes i LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON i.plid=t.plid WHERE i.pmid='$pmid'");
if($index['pmtype'] != 1) {
return PMUIDTYPE_ERROR;
}
$users = explode('_', $index['min_max']);
if(!in_array($uid, $users)) {
return PMPRIVILEGENONE_ERROR;
}
if($index['authorid'] != $uid) {
$this->db->query("UPDATE ".UC_DBTABLEPRE.$this->getposttablename($index['plid'])." SET delstatus=2 WHERE pmid='$pmid' AND delstatus=0");
$updatenum = $this->db->affected_rows();
$this->db->query("DELETE FROM ".UC_DBTABLEPRE.$this->getposttablename($index['plid'])." WHERE pmid='$pmid' AND delstatus=1");
$deletenum = $this->db->affected_rows();
} else {
$this->db->query("UPDATE ".UC_DBTABLEPRE.$this->getposttablename($index['plid'])." SET delstatus=1 WHERE pmid='$pmid' AND delstatus=0");
$updatenum = $this->db->affected_rows();
$this->db->query("DELETE FROM ".UC_DBTABLEPRE.$this->getposttablename($index['plid'])." WHERE pmid='$pmid' AND delstatus=2");
$deletenum = $this->db->affected_rows();
}
if(!$this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE.$this->getposttablename($index['plid'])." WHERE plid='{$index['plid']}'")) {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='{$index['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid='{$index['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid='{$index['plid']}'");
} else {
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET pmnum=pmnum-".($updatenum + $deletenum)." WHERE plid='".$index['plid']."' AND uid='$uid'");
}
return 1;
}
function deletepmbypmids($uid, $pmids) {
if($pmids) {
foreach($pmids as $key => $pmid) {
$this->deletepmbypmid($uid, $pmid);
}
}
return 1;
}
function deletepmbyplid($uid, $plid, $isuser = 0) {
if(!$uid || !$plid) {
return 0;
}
if($isuser) {
$relationship = $this->relationship($uid, $plid);
$sql = "SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE min_max='$relationship'";
} else {
$sql = "SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'";
}
$query = $this->db->query($sql);
if($list = $this->db->fetch_array($query)) {
if($list['pmtype'] == 1) {
$user = explode('_', $list['min_max']);
if(!in_array($uid, $user)) {
return PMPRIVILEGENONE_ERROR;
}
} else {
if($uid != $list['authorid']) {
return PMPRIVILEGENONE_ERROR;
}
}
} else {
return PMTHREADNONE_ERROR;
}
if($list['pmtype'] == 1) {
if($uid == $list['authorid']) {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." WHERE plid='{$list['plid']}' AND delstatus=2");
$this->db->query("UPDATE ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." SET delstatus=1 WHERE plid='{$list['plid']}' AND delstatus=0");
} else {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." WHERE plid='{$list['plid']}' AND delstatus=1");
$this->db->query("UPDATE ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." SET delstatus=2 WHERE plid='{$list['plid']}' AND delstatus=0");
}
$count = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." WHERE plid='{$list['plid']}'");
if(!$count) {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='{$list['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid='{$list['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid='{$list['plid']}'");
} else {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid='{$list['plid']}' AND uid='$uid'");
}
} else {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE.$this->getposttablename($list['plid'])." WHERE plid='{$list['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='{$list['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_members WHERE plid='{$list['plid']}'");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."pm_indexes WHERE plid='{$list['plid']}'");
}
return 1;
}
function deletepmbyplids($uid, $plids, $isuser = 0) {
if($plids) {
foreach($plids as $key => $plid) {
$this->deletepmbyplid($uid, $plid, $isuser);
}
}
return 1;
}
function getprivatepmbyplid($uid, $plid, $starttime = 0, $endtime = 0, $start = 0, $ppp = 0) {
if(!$uid || !$plid) {
return 0;
}
if(!$this->isprivilege($plid, $uid)) {
return 0;
}
$thread = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'");
if($thread['pmtype'] != 1) {
return 0;
}
$pms = $addsql = array();
$addsql[] = "p.plid='$plid'";
if($thread['authorid'] == $uid) {
$addsql[] = 'p.delstatus IN (0,2)';
} else {
$addsql[] = 'p.delstatus IN (0,1)';
}
if($starttime) {
$addsql[]= "p.dateline>'$starttime'";
}
if($endtime) {
$addsql[] = "p.dateline<'$endtime'";
}
if($addsql) {
$addsql = implode(' AND ', $addsql);
} else {
$addsql = '';
}
if($ppp) {
$limitsql = 'LIMIT '.intval($start).', '.intval($ppp);
} else {
$limitsql = '';
}
$pms = $this->db->fetch_all("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM ".UC_DBTABLEPRE.$this->getposttablename($plid)." p LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON p.plid=t.plid WHERE $addsql ORDER BY p.dateline DESC $limitsql");
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=0 WHERE plid='$plid' AND uid='$uid' AND isnew=1");
return array_reverse($pms);
}
function getchatpmbyplid($uid, $plid, $starttime = 0, $endtime = 0, $start = 0, $ppp = 0) {
if(!$uid || !$plid) {
return 0;
}
if(!$this->isprivilege($plid, $uid)) {
return 0;
}
$pms = $addsql = array();
$addsql[] = "p.plid='$plid'";
if($starttime) {
$addsql[]= "p.dateline>'$starttime'";
}
if($endtime) {
$addsql[] = "p.dateline<'$endtime'";
}
if($addsql) {
$addsql = implode(' AND ', $addsql);
} else {
$addsql = '';
}
if($ppp) {
$limitsql = 'LIMIT '.intval($start).', '.intval($ppp);
} else {
$limitsql = '';
}
$query = $this->db->query("SELECT t.*, p.*, t.authorid as founderuid, t.dateline as founddateline FROM ".UC_DBTABLEPRE.$this->getposttablename($plid)." p LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON p.plid=t.plid WHERE $addsql ORDER BY p.dateline DESC $limitsql");
while($pm = $this->db->fetch_array($query)) {
if($pm['pmtype'] != 2) {
return 0;
}
$pms[] = $pm;
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."pm_members SET isnew=0 WHERE plid='$plid' AND uid='$uid' AND isnew=1");
return array_reverse($pms);
}
function getpmlist($uid, $filter, $start, $ppp = 10) {
if(!$uid) {
return 0;
}
$members = $touidarr = $tousernamearr = array();
if($filter == 'newpm') {
$addsql = 'm.isnew=1 AND ';
} else {
$addsql = '';
}
$query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON t.plid=m.plid WHERE $addsql m.uid='$uid' ORDER BY m.lastdateline DESC LIMIT $start, $ppp");
while($member = $this->db->fetch_array($query)) {
if($member['pmtype'] == 1) {
$users = explode('_', $member['min_max']);
$member['touid'] = $users[0] == $uid ? $users[1] : $users[0];
} else {
$member['touid'] = 0;
}
$touidarr[$member['touid']] = $member['touid'];
$members[] = $member;
}
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."newpm WHERE uid='$uid'");
$array = array();
if($members) {
$today = $this->base->time - $this->base->time % 86400;
$this->base->load('user');
$tousernamearr = $_ENV['user']->id2name($touidarr);
foreach($members as $key => $data) {
$daterange = 5;
$data['founddateline'] = $data['dateline'];
$data['dateline'] = $data['lastdateline'];
$data['pmid'] = $data['plid'];
$lastmessage = unserialize($data['lastmessage']);
if($lastmessage['firstauthorid']) {
$data['firstauthorid'] = $lastmessage['firstauthorid'];
$data['firstauthor'] = $lastmessage['firstauthor'];
$data['firstsummary'] = $lastmessage['firstsummary'];
}
if($lastmessage['lastauthorid']) {
$data['lastauthorid'] = $lastmessage['lastauthorid'];
$data['lastauthor'] = $lastmessage['lastauthor'];
$data['lastsummary'] = $lastmessage['lastsummary'];
}
$data['msgfromid'] = $lastmessage['lastauthorid'];
$data['msgfrom'] = $lastmessage['lastauthor'];
$data['message'] = $lastmessage['lastsummary'];
$data['new'] = $data['isnew'];
$data['msgtoid'] = $data['touid'];
if($data['lastdateline'] >= $today) {
$daterange = 1;
} elseif($data['lastdateline'] >= $today - 86400) {
$daterange = 2;
} elseif($data['lastdateline'] >= $today - 172800) {
$daterange = 3;
} elseif($data['lastdateline'] >= $today - 604800) {
$daterange = 4;
}
$data['daterange'] = $daterange;
$data['tousername'] = $tousernamearr[$data['touid']];
unset($data['min_max']);
$array[] = $data;
}
}
return $array;
}
function getplidbypmid($pmid) {
if(!$pmid) {
return false;
}
return $this->db->result_first("SELECT plid FROM ".UC_DBTABLEPRE."pm_indexes WHERE pmid='$pmid'");
}
function getplidbytouid($uid, $touid) {
if(!$uid || !$touid) {
return 0;
}
return $this->db->result_first("SELECT plid FROM ".UC_DBTABLEPRE."pm_lists WHERE min_max='".$this->relationship($uid, $touid)."'");
}
function getuidbyplid($plid) {
if(!$plid) {
return array();
}
$uidarr = array();
$query = $this->db->query("SELECT uid FROM ".UC_DBTABLEPRE."pm_members WHERE plid='$plid'");
while($uid = $this->db->fetch_array($query)) {
$uidarr[$uid['uid']] = $uid['uid'];
}
return $uidarr;
}
function chatpmmemberlist($uid, $plid) {
if(!$uid || !$plid) {
return 0;
}
$uidarr = $this->getuidbyplid($plid);
if(empty($uidarr)) {
return 0;
}
if(!isset($uidarr[$uid])) {
return 0;
}
$authorid = $this->db->result_first("SELECT authorid FROM ".UC_DBTABLEPRE."pm_lists WHERE plid='$plid'");
return array('author' => $authorid, 'member' => $uidarr);
}
function relationship($fromuid, $touid) {
if($fromuid < $touid) {
return $fromuid.'_'.$touid;
} elseif($fromuid > $touid) {
return $touid.'_'.$fromuid;
} else {
return '';
}
}
function getposttablename($plid) {
$id = substr((string)$plid, -1, 1);
return 'pm_messages_'.intval($id);
}
function get_blackls($uid, $uids = array()) {
if(!$uids) {
$blackls = $this->db->result_first("SELECT blacklist FROM ".UC_DBTABLEPRE."memberfields WHERE uid='$uid'");
} else {
$blackls = array();
$uids = is_array($uids) ? $uids : array($uids);
foreach($uids as $uid) {
$blackls[$uid] = array();
}
$uids = $this->base->implode($uids);
$query = $this->db->query("SELECT uid, blacklist FROM ".UC_DBTABLEPRE."memberfields WHERE uid IN ($uids)");
while($data = $this->db->fetch_array($query)) {
$blackls[$data['uid']] = explode(',', $data['blacklist']);
}
}
return $blackls;
}
function set_blackls($uid, $blackls) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."memberfields SET blacklist='$blackls' WHERE uid='$uid'");
return $this->db->affected_rows();
}
function update_blackls($uid, $username, $action = 1) {
$username = !is_array($username) ? array($username) : $username;
if($action == 1) {
if(!in_array('{ALL}', $username)) {
$usernames = $this->base->implode($username);
$query = $this->db->query("SELECT username FROM ".UC_DBTABLEPRE."members WHERE username IN ($usernames)");
$usernames = array();
while($data = $this->db->fetch_array($query)) {
$usernames[addslashes($data['username'])] = addslashes($data['username']);
}
if(!$usernames) {
return 0;
}
$blackls = addslashes($this->db->result_first("SELECT blacklist FROM ".UC_DBTABLEPRE."memberfields WHERE uid='$uid'"));
if($blackls) {
$list = explode(',', $blackls);
foreach($list as $k => $v) {
if(in_array($v, $usernames)) {
unset($usernames[$v]);
}
}
}
if(!$usernames) {
return 1;
}
$listnew = implode(',', $usernames);
$blackls .= $blackls !== '' ? ','.$listnew : $listnew;
} else {
$blackls = addslashes($this->db->result_first("SELECT blacklist FROM ".UC_DBTABLEPRE."memberfields WHERE uid='$uid'"));
$blackls .= ',{ALL}';
}
} else {
$blackls = addslashes($this->db->result_first("SELECT blacklist FROM ".UC_DBTABLEPRE."memberfields WHERE uid='$uid'"));
$list = $blackls = explode(',', $blackls);
foreach($list as $k => $v) {
if(in_array($v, $username)) {
unset($blackls[$k]);
}
}
$blackls = implode(',', $blackls);
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."memberfields SET blacklist='$blackls' WHERE uid='$uid'");
return 1;
}
function removecode($str, $length) {
static $uccode = null;
if($uccode === null) {
require_once UC_ROOT.'lib/uccode.class.php';
$uccode = new uccode();
}
$str = $uccode->complie($str);
return trim($this->base->cutstr(strip_tags($str), $length));
}
function ispminterval($uid, $interval = 0) {
if(!$uid) {
return 0;
}
$interval = intval($interval);
if(!$interval) {
return 1;
}
$lastupdate = $this->db->result_first("SELECT lastupdate FROM ".UC_DBTABLEPRE."pm_members WHERE uid='$uid' ORDER BY lastupdate DESC LIMIT 1");
if(($this->base->time - $lastupdate) > $interval) {
return 1;
} else {
return 0;
}
}
function isprivatepmthreadlimit($uid, $maxnum = 0) {
if(!$uid) {
return 0;
}
$maxnum = intval($maxnum);
if(!$maxnum) {
return 1;
}
$num = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_members m LEFT JOIN ".UC_DBTABLEPRE."pm_lists t ON m.plid=t.plid WHERE uid='$uid' AND lastupdate>'".($this->base->time-86400)."' AND t.pmtype=1");
if($maxnum - $num < 0) {
return 0;
} else {
return 1;
}
}
function ischatpmthreadlimit($uid, $maxnum = 0) {
if(!$uid) {
return 0;
}
$maxnum = intval($maxnum);
if(!$maxnum) {
return 1;
}
$num = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."pm_lists WHERE authorid='$uid' AND dateline>'".($this->base->time-86400)."'");
if($maxnum - $num < 0) {
return 0;
} else {
return 1;
}
}
}
?>

71
uc_client/model/tag.php Normal file
View File

@@ -0,0 +1,71 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: tag.php 1059 2011-03-01 07:25:09Z monkey $
*/
!defined('IN_UC') && exit('Access Denied');
class tagmodel {
var $db;
var $base;
function __construct(&$base) {
$this->tagmodel($base);
}
function tagmodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function get_tag_by_name($tagname) {
$arr = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."tags WHERE tagname='$tagname'");
return $arr;
}
function get_template($appid) {
$result = $this->db->result_first("SELECT tagtemplates FROM ".UC_DBTABLEPRE."applications WHERE appid='$appid'");
return $result;
}
function updatedata($appid, $data) {
$appid = intval($appid);
include_once UC_ROOT.'lib/xml.class.php';
$data = xml_unserialize($data);
$this->base->load('app');
$data[0] = addslashes($data[0]);
$datanew = array();
if(is_array($data[1])) {
foreach($data[1] as $r) {
$datanew[] = $_ENV['misc']->array2string($r);
}
}
$tmp = $_ENV['app']->get_apps('type', "appid='$appid'");
$datanew = addslashes($tmp[0]['type']."\t".implode("\t", $datanew));
if(!empty($data[0])) {
$return = $this->db->result_first("SELECT count(*) FROM ".UC_DBTABLEPRE."tags WHERE tagname='$data[0]' AND appid='$appid'");
if($return) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."tags SET data='$datanew', expiration='".$this->base->time."' WHERE tagname='$data[0]' AND appid='$appid'");
} else {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."tags (tagname, appid, data, expiration) VALUES ('$data[0]', '$appid', '$datanew', '".$this->base->time."')");
}
}
}
function formatcache($appid, $tagname) {
$return = $this->db->result_first("SELECT count(*) FROM ".UC_DBTABLEPRE."tags WHERE tagname='$tagname' AND appid='$appid'");
if($return) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."tags SET expiration='0' WHERE tagname='$tagname' AND appid='$appid'");
} else {
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."tags (tagname, appid, expiration) VALUES ('$tagname', '$appid', '0')");
}
}
}
?>

388
uc_client/model/user.php Normal file
View File

@@ -0,0 +1,388 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: user.php 1179 2014-11-03 07:11:25Z hypowang $
*/
!defined('IN_UC') && exit('Access Denied');
class usermodel {
var $db;
var $base;
function __construct(&$base) {
$this->usermodel($base);
}
function usermodel(&$base) {
$this->base = $base;
$this->db = $base->db;
}
function get_user_by_uid($uid) {
$arr = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."members WHERE uid='$uid'");
return $arr;
}
function get_user_by_username($username) {
$arr = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."members WHERE username='$username'");
return $arr;
}
function get_user_by_email($email) {
$arr = $this->db->fetch_first("SELECT * FROM ".UC_DBTABLEPRE."members WHERE email='$email'");
return $arr;
}
function get_user_by_secmobile($secmobicc, $secmobile) {
return $this->db->fetch_first_stmt("SELECT * FROM ".UC_DBTABLEPRE."members WHERE secmobicc=? AND secmobile=?", array('d', 'd'), array($secmobicc, $secmobile));
}
function check_username($username) {
$charset = strtolower(UC_CHARSET);
if ($charset === 'utf-8') {
$guestexp = '\xE3\x80\x80|\xE6\xB8\xB8\xE5\xAE\xA2|\xE9\x81\x8A\xE5\xAE\xA2';
} elseif ($charset === 'gbk') {
$guestexp = '\xA1\xA1|\xD3\xCE\xBF\xCD';
} elseif ($charset === 'big5') {
$guestexp = '\xA1\x40|\xB9\x43\xAB\xC8';
} else {
return FALSE;
}
$guestexp .= '|^Guest';
$len = $this->dstrlen($username);
if($len > 15 || $len < 3 || preg_match("/\s+|^c:\\con\\con|[%,\*\"\s\<\>\&\(\)']|$guestexp/is", $username)) {
return FALSE;
} else {
return TRUE;
}
}
function dstrlen($str) {
if(strtolower(UC_CHARSET) != 'utf-8') {
return strlen($str);
}
$count = 0;
for($i = 0; $i < strlen($str); $i++){
$value = ord($str[$i]);
if($value > 127) {
$count++;
if($value >= 192 && $value <= 223) $i++;
elseif($value >= 224 && $value <= 239) $i = $i + 2;
elseif($value >= 240 && $value <= 247) $i = $i + 3;
}
$count++;
}
return $count;
}
function check_mergeuser($username) {
$data = $this->db->result_first("SELECT count(*) FROM ".UC_DBTABLEPRE."mergemembers WHERE appid='".$this->base->app['appid']."' AND username='$username'");
return $data;
}
function check_usernamecensor($username) {
$_CACHE['badwords'] = $this->base->cache('badwords');
$censorusername = $this->base->get_setting('censorusername');
$censorusername = $censorusername['censorusername'];
$censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($censorusername = trim($censorusername)), '/')).')$/i';
$usernamereplaced = isset($_CACHE['badwords']['findpattern']) && !empty($_CACHE['badwords']['findpattern']) ? @preg_replace($_CACHE['badwords']['findpattern'], $_CACHE['badwords']['replace'], $username) : $username;
if(($usernamereplaced != $username) || ($censorusername && preg_match($censorexp, $username))) {
return FALSE;
} else {
return TRUE;
}
}
function check_usernameexists($username) {
$data = $this->db->result_first("SELECT username FROM ".UC_DBTABLEPRE."members WHERE username='$username'");
return $data;
}
function check_emailformat($email) {
return strlen($email) > 6 && strlen($email) <= 255 && preg_match("/^([A-Za-z0-9\-_.+]+)@([A-Za-z0-9\-]+[.][A-Za-z0-9\-.]+)$/", $email);
}
function check_emailaccess($email) {
$setting = $this->base->get_setting(array('accessemail', 'censoremail'));
$accessemail = $setting['accessemail'];
$censoremail = $setting['censoremail'];
$accessexp = '/('.str_replace("\r\n", '|', preg_quote(trim($accessemail), '/')).')$/i';
$censorexp = '/('.str_replace("\r\n", '|', preg_quote(trim($censoremail), '/')).')$/i';
if($accessemail || $censoremail) {
if(($accessemail && !preg_match($accessexp, $email)) || ($censoremail && preg_match($censorexp, $email))) {
return FALSE;
} else {
return TRUE;
}
} else {
return TRUE;
}
}
function check_emailexists($email, $username = '') {
$sqladd = $username !== '' ? "AND username<>'$username'" : '';
$email = $this->db->result_first("SELECT email FROM ".UC_DBTABLEPRE."members WHERE email='$email' $sqladd");
return $email;
}
function check_secmobileexists($secmobicc, $secmobile, $username = '') {
$sqladd = $username !== '' ? "AND username<>'$username'" : '';
$secmobicc == 0 && $secmobicc = '';
$secmobile == 0 && $secmobile = '';
$secmobile = $this->db->result_first("SELECT secmobile FROM ".UC_DBTABLEPRE."members WHERE secmobicc='$secmobicc' AND secmobile='$secmobile' $sqladd");
return $secmobile;
}
function check_login($username, $password, &$user) {
$user = $this->get_user_by_username($username);
if(empty($user['username'])) {
return -1;
} elseif(!$this->verify_password($password, $user['password'], $user['salt'])) {
return -2;
}
$this->upgrade_password($username, $password, $user['password'], $user['salt']);
return $user['uid'];
}
function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $regip = '', $secmobicc = '', $secmobile = '') {
$regip = empty($regip) ? $this->base->onlineip : $regip;
$salt = '';
$password = $this->generate_password($password);
$sqladd = $uid ? "uid='".intval($uid)."'," : '';
$sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',";
$sqladd .= $secmobicc ? "secmobicc='".$secmobicc."'," : '';
$sqladd .= $secmobile ? "secmobile='".$secmobile."'," : '';
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', regip='$regip', regdate='".$this->base->time."', salt='$salt'");
$uid = $this->db->insert_id();
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'");
return $uid;
}
function edit_user($username, $oldpw, $newpw, $email, $ignoreoldpw = 0, $questionid = '', $answer = '', $secmobicc = '', $secmobile = '') {
$data = $this->db->fetch_first("SELECT username, uid, password, salt FROM ".UC_DBTABLEPRE."members WHERE username='$username'");
if($ignoreoldpw) {
$isprotected = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."protectedmembers WHERE uid = '{$data['uid']}'");
if($isprotected) {
return -8;
}
}
if(!$ignoreoldpw && !$this->verify_password($oldpw, $data['password'], $data['salt'])) {
return -1;
}
$sqladd = $newpw ? "password='".$this->generate_password($newpw)."', salt=''" : '';
$sqladd .= $email ? ($sqladd ? ',' : '')." email='$email'" : '';
$sqladd .= $secmobicc !== '' ? ($sqladd ? ',' : '').(!empty($secmobicc) ? " secmobicc='$secmobicc'" : " secmobicc=''") : '';
$sqladd .= $secmobile !== '' ? ($sqladd ? ',' : '').(!empty($secmobile) ? " secmobile='$secmobile'" : " secmobile=''") : '';
if($questionid !== '') {
if($questionid > 0) {
$sqladd .= ($sqladd ? ',' : '')." secques='".$this->quescrypt($questionid, $answer)."'";
} else {
$sqladd .= ($sqladd ? ',' : '')." secques=''";
}
}
if($sqladd || $emailadd) {
$this->db->query("UPDATE ".UC_DBTABLEPRE."members SET $sqladd WHERE username='$username'");
return $this->db->affected_rows();
} else {
return -7;
}
}
function delete_user($uidsarr) {
$uidsarr = (array)$uidsarr;
if(!$uidsarr) {
return 0;
}
$uids = $this->base->implode($uidsarr);
$arr = $this->db->fetch_all("SELECT uid FROM ".UC_DBTABLEPRE."protectedmembers WHERE uid IN ($uids)");
$puids = array();
foreach((array)$arr as $member) {
$puids[] = $member['uid'];
}
$uids = $this->base->implode(array_diff($uidsarr, $puids));
if($uids) {
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."members WHERE uid IN($uids)");
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."memberfields WHERE uid IN($uids)");
uc_user_deleteavatar($uidsarr);
$this->base->load('note');
$_ENV['note']->add('deleteuser', "ids=$uids");
return $this->db->affected_rows();
} else {
return 0;
}
}
function delete_useravatar($uidsarr) {
if(!defined('UC_DELAVTDIR')) {
define('UC_DELAVTDIR', UC_DATADIR.'./avatar/');
}
$uidsarr = (array)$uidsarr;
foreach((array)$uidsarr as $uid) {
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'big', 'real')) && unlink($avatar_file);
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'middle', 'real')) && unlink($avatar_file);
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'small', 'real')) && unlink($avatar_file);
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'big')) && unlink($avatar_file);
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'middle')) && unlink($avatar_file);
file_exists($avatar_file = UC_DELAVTDIR.$this->base->get_avatar($uid, 'small')) && unlink($avatar_file);
}
}
function chgusername($uid, $newusername) {
return $this->db->query_stmt("UPDATE ".UC_DBTABLEPRE."members SET username=? WHERE uid=?", array('s', 'i'), array($newusername, $uid));
}
function get_total_num($sqladd = '') {
$data = $this->db->result_first("SELECT COUNT(*) FROM ".UC_DBTABLEPRE."members $sqladd");
return $data;
}
function get_list($page, $ppp, $totalnum, $sqladd) {
$start = $this->base->page_get_start($page, $ppp, $totalnum);
$data = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."members $sqladd LIMIT $start, $ppp");
return $data;
}
function name2id($usernamesarr) {
$usernamesarr = uc_addslashes($usernamesarr, 1, TRUE);
$usernames = $this->base->implode($usernamesarr);
$query = $this->db->query("SELECT uid FROM ".UC_DBTABLEPRE."members WHERE username IN($usernames)");
$arr = array();
while($user = $this->db->fetch_array($query)) {
$arr[] = $user['uid'];
}
return $arr;
}
function id2name($uidarr) {
$arr = array();
$query = $this->db->query("SELECT uid, username FROM ".UC_DBTABLEPRE."members WHERE uid IN (".$this->base->implode($uidarr).")");
while($user = $this->db->fetch_array($query)) {
$arr[$user['uid']] = $user['username'];
}
return $arr;
}
function quescrypt($questionid, $answer) {
return $questionid > 0 && $answer != '' ? substr(md5($answer.md5($questionid)), 16, 8) : '';
}
function can_do_login($username, $ip = '') {
$check_times = $this->base->settings['login_failedtime'] > 0 ? $this->base->settings['login_failedtime'] : ($this->base->settings['login_failedtime'] < 0 ? 0 : 5);
if($check_times == 0) {
return -1;
}
$username = substr(md5($username), 8, 15);
$expire = 15 * 60;
if(!$ip) {
$ip = $this->base->onlineip;
}
$ip_check = $user_check = array();
$query = $this->db->query("SELECT * FROM ".UC_DBTABLEPRE."failedlogins WHERE ip='".$ip."' OR ip='$username'");
while($row = $this->db->fetch_array($query)) {
if($row['ip'] === $username) {
$user_check = $row;
} elseif($row['ip'] === $ip) {
$ip_check = $row;
}
}
if(empty($ip_check) || ($this->base->time - $ip_check['lastupdate'] > $expire)) {
$ip_check = array();
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."failedlogins (ip, count, lastupdate) VALUES ('{$ip}', '0', '{$this->base->time}')");
}
if(empty($user_check) || ($this->base->time - $user_check['lastupdate'] > $expire)) {
$user_check = array();
$this->db->query("REPLACE INTO ".UC_DBTABLEPRE."failedlogins (ip, count, lastupdate) VALUES ('{$username}', '0', '{$this->base->time}')");
}
if ($ip_check || $user_check) {
$time_left = min(($check_times - $ip_check['count']), ($check_times - $user_check['count']));
return $time_left;
}
$this->db->query("DELETE FROM ".UC_DBTABLEPRE."failedlogins WHERE lastupdate<".($this->base->time - ($expire + 1)), 'UNBUFFERED');
return $check_times;
}
function loginfailed($username, $ip = '') {
$username = substr(md5($username), 8, 15);
if(!$ip) {
$ip = $this->base->onlineip;
}
$this->db->query("UPDATE ".UC_DBTABLEPRE."failedlogins SET count=count+1, lastupdate='".$this->base->time."' WHERE ip='".$ip."' OR ip='$username'");
}
function user_log($uid, $action, $extra = '') {
$uid = intval($uid);
$action = addslashes($action);
$extra = addslashes($extra);
$this->db->query_stmt("INSERT INTO ".UC_DBTABLEPRE."memberlogs SET uid=?, action=?, extra=?", array('i', 's', 's'), array($uid, $action, $extra));
}
function get_passwordalgo() {
$algo = $this->base->settings['passwordalgo'];
if(empty($algo)) {
return constant('PASSWORD_BCRYPT');
} else {
return constant($algo) === null ? constant('PASSWORD_BCRYPT') : constant($algo);
}
}
function get_passwordoptions() {
$options = $this->base->settings['passwordoptions'];
if(empty($options)) {
return array();
} else {
$result = json_decode($options, true);
return is_array($result) ? $result : array();
}
}
function generate_password($password) {
$algo = $this->get_passwordalgo();
$options = $this->get_passwordoptions();
$hash = password_hash($password, $algo, $options);
return ($hash === false || $hash === null || !password_verify($password, $hash)) ? password_hash($password, PASSWORD_BCRYPT) : $hash;
}
function verify_password($password, $hash, $salt = '') {
if(empty($salt)) {
return password_verify($password, $hash);
} else if(strlen($salt) == 6) {
return hash_equals($hash, md5(md5($password).$salt));
} else if(strlen($salt) > 6 && strlen($salt) < 20 && file_exists(UC_ROOT . "lib/uc_password_$salt.class.php")) {
$classname = "uc_password_$salt";
include(UC_ROOT . "lib/uc_password_$salt.class.php");
return $classname::verify_password($password, $hash);
}
return false;
}
function upgrade_password($username, $password, $hash, $salt = '') {
$algo = $this->get_passwordalgo();
$options = $this->get_passwordoptions();
if (!empty($salt) || password_needs_rehash($hash, $algo, $options)) {
$password_new = $this->generate_password($password);
$sqladd = "password = '$password_new', salt = ''";
return $this->db->query("UPDATE ".UC_DBTABLEPRE."members SET $sqladd WHERE username='$username'");
}
return true;
}
}

37
uc_client/model/var.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
/*
[UCenter] (C)2001-2099 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id: base.php 1167 2014-11-03 03:06:21Z hypowang $
*/
!defined('IN_UC') && exit('Access Denied');
class base_var {
private static $instance;
var $time;
var $onlineip;
var $db;
var $settings = array();
var $cache = array();
var $_CACHE = array();
var $app = array();
public static function bind(&$class) {
if(empty(self::$instance)) {
self::$instance = new base_var();
}
$class->time =& self::$instance->time;
$class->onlineip =& self::$instance->onlineip;
$class->db =& self::$instance->db;
$class->settings =& self::$instance->settings;
$class->cache =& self::$instance->cache;
$class->_CACHE =& self::$instance->_CACHE;
$class->app =& self::$instance->app;
}
}
?>