llowinvite'] = $mtag['grade']>=0?1:0; if($mtag['joinperm'] && $mtag['grade'] < 8) { $mtag['allowinvite'] = 0; } if($mtag['close']) { $mtag['allowpost'] = $mtag['allowthread'] = 0; } return $mtag; } //取数组中的随机个 function sarray_rand($arr, $num=1) { $r_values = array(); if($arr && count($arr) > $num) { if($num > 1) { $r_keys = array_rand($arr, $num); foreach ($r_keys as $key) { $r_values[$key] = $arr[$key]; } } else { $r_key = array_rand($arr, 1); $r_values[$r_key] = $arr[$r_key]; } } else { $r_values = $arr; } return $r_values; } //获得用户唯一串 function space_key($space, $appid=0) { global $_SCONFIG; return substr(md5($_SCONFIG['sitekey'].'|'.$space['uid'].(empty($appid)?'':'|'.$appid)), 8, 16); } //获得用户URL function space_domain($space) { global $_SCONFIG; if($space['domain'] && $_SCONFIG['allowdomain'] && $_SCONFIG['domainroot']) { $space['domainurl'] = 'http://'.$space['domain'].'.'.$_SCONFIG['domainroot']; } else { if($_SCONFIG['allowrewrite']) { $space['domainurl'] = getsiteurl().$space[uid]; } else { $space['domainurl'] = getsiteurl()."?$space[uid]"; } } return $space['domainurl']; } //产生form防伪码 function formhash() { global $_SGLOBAL, $_SCONFIG; if(empty($_SGLOBAL['formhash'])) { $hashadd = defined('IN_ADMINCP') ? 'Only For UCenter Home AdminCP' : ''; $_SGLOBAL['formhash'] = substr(md5(substr($_SGLOBAL['timestamp'], 0, -7).'|'.$_SGLOBAL['supe_uid'].'|'.md5($_SCONFIG['sitekey']).'|'.$hashadd), 8, 8); } return $_SGLOBAL['formhash']; } //检查邮箱是否有效 function isemail($email) { return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email); } //验证提问 function question() { global $_SGLOBAL; include_once(S_ROOT.'./data/data_spam.php'); if($_SGLOBAL['spam']['question']) { $count = count($_SGLOBAL['spam']['question']); $key = $count>1?mt_rand(0, $count-1):0; ssetcookie('seccode', $key); echo $_SGLOBAL['spam']['question'][$key]; } } //输出MYOP升级信息脚本 function my_checkupdate() { global $_SGLOBAL, $_SCONFIG; if($_SCONFIG['my_status'] && empty($_SCONFIG['my_closecheckupdate']) && checkperm('admin')) { $sid = $_SCONFIG['my_siteid']; $ts = $_SGLOBAL['timestamp']; $key = md5($sid.$ts.$_SCONFIG['my_sitekey']); echo ''; } } //获得用户组图标 function g_icon($gid) { global $_SGLOBAL; include_once(S_ROOT.'./data/data_usergroup.php'); if(empty($_SGLOBAL['grouptitle'][$gid]['icon'])) { echo ''; } else { echo ' '; } } //获得用户颜色 function g_color($gid) { global $_SGLOBAL; include_once(S_ROOT.'./data/data_usergroup.php'); if(empty($_SGLOBAL['grouptitle'][$gid]['color'])) { echo ''; } else { echo ' style="color:'.$_SGLOBAL['grouptitle'][$gid]['color'].';"'; } } //检查是否操作创始人 function ckfounder($uid) { global $_SC; $founders = empty($_SC['founder'])?array():explode(',', $_SC['founder']); if($uid && $founders) { return in_array($uid, $founders); } else { return false; } } //获取目录 function sreaddir($dir, $extarr=array()) { $dirs = array(); if($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(!empty($extarr) && is_array($extarr)) { if(in_array(strtolower(fileext($file)), $extarr)) { $dirs[] = $file; } } else if($file != '.' && $file != '..') { $dirs[] = $file; } } closedir($dh); } return $dirs; } //获取指定动作能获得多少积分 function getreward($action, $update=1, $uid=0, $needle='', $setcookie = 1) { global $_SGLOBAL, $_SCOOKIE; $credit = 0; $reward = array( 'credit' => 0, 'experience' => 0 ); $creditlog = array(); @include_once(S_ROOT.'./data/data_creditrule.php'); $rule = $_SGLOBAL['creditrule'][$action]; if($rule['credit'] || $rule['experience']) { $uid = $uid ? intval($uid) : $_SGLOBAL['supe_uid']; if($rule['rewardtype']) { //增加积分 $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('creditlog')." WHERE uid='$uid' AND rid='$rule[rid]'"); $creditlog = $_SGLOBAL['db']->fetch_array($query); if(empty($creditlog)) { $reward['credit'] = $rule['credit']; $reward['experience'] = $rule['experience']; $setarr = array( 'uid' => $uid, 'rid' => $rule['rid'], 'total' => 1, 'cyclenum' => 1, 'credit' => $rule['credit'], 'experience' => $rule['experience'], 'dateline' => $_SGLOBAL['timestamp'] ); //判断是否需要去重 if($rule['norepeat']) { if($rule['norepeat'] == 1) { $setarr['info'] = $needle; } elseif($rule['norepeat'] == 2) { $setarr['user'] = $needle; } elseif($rule['norepeat'] == 3) { $setarr['app'] = $needle; } } if(in_array($rule['cycletype'], array(2,3))) { $setarr['starttime'] = $_SGLOBAL['timestamp']; } $clid = inserttable('creditlog', $setarr, 1); } else { $newcycle = false; $setarr = array(); $clid = $creditlog['clid']; switch($rule['cycletype']) { case 0: //一次性奖励 break; case 1: //每天限次数 case 4: //不限周期 $sql = 'cyclenum+1'; if($rule['cycletype'] == 1) { $today = sstrtotime(sgmdate('Y-m-d')); //判断是否为昨天 if($creditlog['dateline'] < $today && $rule['rewardnum']) { $creditlog['cyclenum'] = 0; $sql = 1; $newcycle = true; } } if(empty($rule['rewardnum']) || $creditlog['cyclenum'] < $rule['rewardnum']) { //验证是否为需要去重操作 if($rule['norepeat']) { $repeat = checkcheating($creditlog, $needle, $rule['norepeat']); if($repeat && !$newcycle) { return $reward; } } $reward['credit'] = $rule['credit']; $reward['experience'] = $rule['experience']; //更新次数 $setarr = array( 'cyclenum' => "cyclenum=$sql", 'total' => 'total=total+1', 'dateline' => "dateline='$_SGLOBAL[timestamp]'", 'credit' => "credit='$reward[credit]'", 'experience' => "experience='$reward[experience]'", ); } break; case 2: //整点 case 3: //间隔分钟 $nextcycle = 0; if($creditlog['starttime']) { if($rule['cycletype'] == 2) { //上一次执行时间 $start = sstrtotime(sgmdate('Y-m-d H:00:00', $creditlog['starttime'])); $nextcycle = $start+$rule['cycletime']*3600; } else { $nextcycle = $creditlog['starttime']+$rule['cycletime']*60; } } if($_SGLOBAL['timestamp'] <= $nextcycle && $creditlog['cyclenum'] < $rule['rewardnum']) { //验证是否为需要去重操作 if($rule['norepeat']) { $repeat = checkcheating($creditlog, $needle, $rule['norepeat']); if($repeat && !$newcycle) { return $reward; } } $reward['experience'] = $rule['experience']; $reward['credit'] = $rule['credit']; $setarr = array( 'cyclenum' => "cyclenum=cyclenum+1", 'total' => 'total=total+1', 'dateline' => "dateline='$_SGLOBAL[timestamp]'", 'credit' => "credit='$reward[credit]'", 'experience' => "experience='$reward[experience]'", ); } elseif($_SGLOBAL['timestamp'] >= $nextcycle) { $newcycle = true; $reward['experience'] = $rule['experience']; $reward['credit'] = $rule['credit']; $setarr = array( 'cyclenum' => "cyclenum=1", 'total' => 'total=total+1', 'dateline' => "dateline='$_SGLOBAL[timestamp]'", 'credit' => "credit='$reward[credit]'", 'starttime' => "starttime='$_SGLOBAL[timestamp]'", 'experience' => "experience='$reward[experience]'", ); } break; } //记录操作历史 if($rule['norepeat'] && $needle) { switch($rule['norepeat']) { case 0: break; case 1: //信息去重 $info = empty($creditlog['info'])||$newcycle ? $needle : $creditlog['info'].','.$needle; $setarr['info'] = "`info`='$info'"; break; case 2: //用户去重 $user = empty($creditlog['user'])||$newcycle ? $needle : $creditlog['user'].','.$needle; $setarr['user'] = "`user`='$user'"; break; case 3: //应用去重 $app = empty($creditlog['app'])||$newcycle ? $needle : $creditlog['app'].','.$needle; $setarr['app'] = "`app`='$app'"; break; } } if($setarr) { $_SGLOBAL['db']->query("UPDATE ".tname('creditlog')." SET ".implode(',', $setarr)." WHERE clid='$creditlog[clid]'"); } } if($setcookie && $uid = $_SGLOBAL['supe_uid']) { //其中有新值时才重写cookie值 if($reward['credit'] || $reward['experience']) { $logstr = $action.','.$clid; ssetcookie('reward_log', $logstr); $_SCOOKIE['reward_log'] = $logstr; } } } else { //扣除积分 $reward['credit'] = "-$rule[credit]"; $reward['experience'] = "-$rule[experience]"; } if($update && ($reward['credit'] || $reward['experience'])) { $setarr = array(); if($reward['credit']) { $setarr['credit'] = "credit=credit+$reward[credit]"; } if($reward['experience']) { $setarr['experience'] = "experience=experience+$reward[experience]"; } $_SGLOBAL['db']->query("UPDATE ".tname('space')." SET ".implode(',', $setarr)." WHERE uid='$uid'"); } } return array('credit'=>abs($reward['credit']), 'experience' => abs($reward['experience'])); } //防积分重复奖励同个人或同信息 function checkcheating($creditlog, $needle, $norepeat) { $repeat = false; switch($norepeat) { case 0: break; case 1: //信息去重 $infoarr = explode(',', $creditlog['info']); if(in_array($needle, $infoarr)) { $repeat = true; } break; case 2: //用户去重 $userarr = explode(',', $creditlog['user']); if(in_array($needle, $userarr)) { $repeat = true; } break; case 3: //应用去重 $apparr = explode(',', $creditlog['app']); if(in_array($needle, $apparr)) { $repeat = true; } break; } return $repeat; } //获得热点 function topic_get($topicid) { global $_SGLOBAL; $topic = array(); if($topicid) { $typearr = array('blog','pic','thread','poll','event','share'); $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('topic')." WHERE topicid='$topicid'"); if($topic = $_SGLOBAL['db']->fetch_array($query)) { $topic['pic'] = $topic['pic']?pic_get($topic['pic'], $topic['thumb'], $topic['remote'], 0):''; $topic['joingid'] = empty($topic['joingid'])?array():explode(',', $topic['joingid']); $topic['jointype'] = empty($topic['jointype'])? $typearr:explode(',', $topic['jointype']); $topic['lastpost'] = sgmdate('Y-m-d H:i', $topic['lastpost']); $topic['dateline'] = sgmdate('Y-m-d H:i', $topic['dateline']); $topic['allowjoin'] = $topic['endtime'] && $_SGLOBAL['timestamp']>$topic['endtime']?0:1; $topic['endtime'] = $topic['endtime']?sgmdate('Y-m-d H:i', $topic['endtime']):''; include_once(S_ROOT.'./source/function_bbcode.php'); $topic['message'] = bbcode($topic['message'], 1); $topic['joinurl'] = ''; foreach ($typearr as $value) { if(in_array($value, $topic['jointype'])) { if($value == 'pic') $value = 'upload'; $topic['joinurl'] = "cp.php?ac=$value&topicid=$topicid"; break; } } } } return $topic; } //自定义分页 function mob_perpage($perpage) { global $_SGLOBAL; $newperpage = isset($_GET['perpage'])?intval($_GET['perpage']):0; if($_SGLOBAL['mobile'] && $newperpage>0 && $newperpage<500) { $perpage = $newperpage; } return $perpage; } //检查用户的特殊身份 function ckspacelog() { global $_SGLOBAL; if(empty($_SGLOBAL['supe_uid'])) return false; $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('spacelog')." WHERE uid='$_SGLOBAL[supe_uid]'"); if($value = $_SGLOBAL['db']->fetch_array($query)) { if($value['expiration'] && $value['expiration'] <= $_SGLOBAL['timestamp']) {//到期 $_SGLOBAL['db']->query("DELETE FROM ".tname('spacelog')." WHERE uid='$_SGLOBAL[supe_uid]'"); } $expiration = sgmdate('Y-m-d H:i', $value['expiration']); showmessage('no_authority_expiration'.($value['expiration']?'_date':''), '', 1, array($expiration)); } } ?>
请教高手,先谢谢了! |