📄 post.func.php
字号:
if(strlen($subject) > 80) {
return 'post_subject_toolong';
}
if(!$disablepostctrl) {
if($maxpostsize && strlen($message) > $maxpostsize) {
return 'post_message_toolong';
} elseif($minpostsize && strlen(preg_replace("/\[quote\].+?\[\/quote\]/is", '', $message)) < $minpostsize) {
return 'post_message_tooshort';
}
}
return FALSE;
}
function checkbbcodes($message, $bbcodeoff) {
return !$bbcodeoff && !preg_match("/\[.+\]/s", $message) ? -1 : $bbcodeoff;
}
function checksmilies($message, $smileyoff) {
if($smileyoff) {
return 1;
} else {
if(!empty($GLOBALS['_DCACHE']['smilies_display']) && is_array($GLOBALS['_DCACHE']['smilies_display'])) {
$message = stripslashes($message);
foreach($GLOBALS['_DCACHE']['smilies_display'] AS $stypeid => $smilies) {
foreach($smilies AS $key => $smiley) {
if(strpos($message, $smiley['code']) !== FALSE) {
return 0;
}
}
}
}
return -1;
}
}
function updatepostcredits($operator, $uidarray, $creditsarray) {
global $db, $tablepre, $discuz_uid, $timestamp;
$membersarray = $postsarray = array();
foreach((is_array($uidarray) ? $uidarray : array($uidarray)) as $id) {
$membersarray[intval(trim($id))]++;
}
foreach($membersarray as $uid => $posts) {
$postsarray[$posts][] = $uid;
}
$lastpostadd = $uidarray == $discuz_uid ? ", lastpost='$timestamp'" : '';
$creditsadd1 = '';
if(is_array($creditsarray)) {
foreach($creditsarray as $id => $addcredits) {
$creditsadd1 .= ", extcredits$id=extcredits$id$operator$addcredits*\$posts";
}
}
foreach($postsarray as $posts => $uidarray) {
$uids = implode(',', $uidarray);
eval("\$creditsadd2 = \"$creditsadd1\";");
$db->query("UPDATE {$tablepre}members SET posts=posts+('$operator$posts') $lastpostadd $creditsadd2 WHERE uid IN ($uids)", 'UNBUFFERED');
}
}
function updateattachcredits($operator, $uidarray, $creditsarray) {
global $db, $tablepre, $discuz_uid;
$creditsadd1 = '';
if(is_array($creditsarray)) {
foreach($creditsarray as $id => $addcredits) {
$creditsadd1[] = "extcredits$id=extcredits$id$operator$addcredits*\$attachs";
}
}
if(is_array($creditsadd1)) {
$creditsadd1 = implode(', ', $creditsadd1);
foreach($uidarray as $uid => $attachs) {
eval("\$creditsadd2 = \"$creditsadd1\";");
$db->query("UPDATE {$tablepre}members SET $creditsadd2 WHERE uid = $uid", 'UNBUFFERED');
}
}
}
function updateforumcount($fid) {
global $db, $tablepre, $lang;
extract($db->fetch_first("SELECT COUNT(*) AS threadcount, SUM(t.replies)+COUNT(*) AS replycount
FROM {$tablepre}threads t, {$tablepre}forums f
WHERE f.fid='$fid' AND t.fid=f.fid AND t.displayorder>='0'"));
$thread = $db->fetch_first("SELECT tid, subject, author, lastpost, lastposter FROM {$tablepre}threads
WHERE fid='$fid' AND displayorder>='0' ORDER BY lastpost DESC LIMIT 1");
$thread['subject'] = addslashes($thread['subject']);
$thread['lastposter'] = $thread['author'] ? addslashes($thread['lastposter']) : $lang['anonymous'];
$db->query("UPDATE {$tablepre}forums SET posts='$replycount', threads='$threadcount', lastpost='$thread[tid]\t$thread[subject]\t$thread[lastpost]\t$thread[lastposter]' WHERE fid='$fid'", 'UNBUFFERED');
}
function updatethreadcount($tid, $updateattach = 0) {
global $db, $tablepre, $lang;
$replycount = $db->result_first("SELECT COUNT(*) FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0'") - 1;
$lastpost = $db->fetch_first("SELECT author, anonymous, dateline FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline DESC LIMIT 1");
$lastpost['author'] = $lastpost['anonymous'] ? $lang['anonymous'] : addslashes($lastpost['author']);
if($updateattach) {
$query = $db->query("SELECT attachment FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' AND attachment>0 LIMIT 1");
$attachadd = ', attachment=\''.($db->num_rows($query)).'\'';
} else {
$attachadd = '';
}
$db->query("UPDATE {$tablepre}threads SET replies='$replycount', lastposter='$lastpost[author]', lastpost='$lastpost[dateline]' $attachadd WHERE tid='$tid'", 'UNBUFFERED');
}
function updatemodlog($tids, $action, $expiration = 0, $iscron = 0) {
global $db, $tablepre, $timestamp;
$uid = empty($iscron) ? $GLOBALS['discuz_uid'] : 0;
$username = empty($iscron) ? $GLOBALS['discuz_user'] : 0;
$expiration = empty($expiration) ? 0 : intval($expiration);
$data = $comma = '';
foreach(explode(',', str_replace(array('\'', ' '), array('', ''), $tids)) as $tid) {
if($tid) {
$data .= "{$comma} ('$tid', '$uid', '$username', '$timestamp', '$action', '$expiration', '1')";
$comma = ',';
}
}
!empty($data) && $db->query("INSERT INTO {$tablepre}threadsmod (tid, uid, username, dateline, action, expiration, status) VALUES $data", 'UNBUFFERED');
}
function isopera() {
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($useragent, 'opera') !== false) {
preg_match('/opera(\/| )([0-9\.]+)/', $useragent, $regs);
return $regs[2];
}
return FALSE;
}
function deletethreadcaches($tids) {
global $cachethreadon;
if(!$cachethreadon) {
return FALSE;
}
include_once DISCUZ_ROOT.'./include/forum.func.php';
if(!empty($tids)) {
foreach(explode(',', $tids) as $tid) {
$fileinfo = getcacheinfo($tid);
@unlink($fileinfo['filename']);
}
}
return TRUE;
}
function arrayslice($array, $offset, $length) {
if(PHP_VERSION >= '5.0.2') {
return array_slice($array, $offset, $length, TRUE);
} else {
$array = array_chunk($array, $length, TRUE);
return $array[$offset / $length];
}
}
function threadtype_checkoption($unchangeable = 1, $trade = 0) {
global $selecttypeid, $optionlist, $trade_create, $tradetypeid, $typeid, $_DTYPE, $checkoption, $forum, $action;
if($trade) {
$selecttypeid = $tradetypeid ? intval($tradetypeid) : '';
} else {
$selecttypeid = $typeid ? intval($typeid) : '';
}
@include_once DISCUZ_ROOT.'./forumdata/cache/threadtype_'.$selecttypeid.'.php';
$optionlist = $_DTYPE;
foreach($_DTYPE as $optionid => $option) {
$checkoption[$option['identifier']]['optionid'] = $optionid;
$checkoption[$option['identifier']]['title'] = $option['title'];
$checkoption[$option['identifier']]['type'] = $option['type'];
$checkoption[$option['identifier']]['required'] = $option['required'] ? 1 : 0;
$checkoption[$option['identifier']]['unchangeable'] = $action == 'edit' && $unchangeable && $option['unchangeable'] ? 1 : 0;
$checkoption[$option['identifier']]['maxnum'] = $option['maxnum'] ? intval($option['maxnum']) : '';
$checkoption[$option['identifier']]['minnum'] = $option['minnum'] ? intval($option['minnum']) : '';
$checkoption[$option['identifier']]['maxlength'] = $option['maxlength'] ? intval($option['maxlength']) : '';
}
}
function threadtype_optiondata() {
global $db, $tablepre, $tid, $pid, $tradetype, $_DTYPE, $_DTYPEDESC, $optiondata, $optionlist, $thread;
$optiondata = array();
if(!$tradetype) {
$id = $tid;
$field = 'tid';
$table = 'typeoptionvars';
} else {
$id = $pid;
$field = 'pid';
$table = 'tradeoptionvars';
}
if($id) {
$query = $db->query("SELECT optionid, value FROM {$tablepre}$table WHERE $field='$id'");
while($option = $db->fetch_array($query)) {
$optiondata[$option['optionid']] = $option['value'];
}
foreach($_DTYPE as $optionid => $option) {
$optionlist[$optionid]['unchangeable'] = $_DTYPE[$optionid]['unchangeable'] ? 'readonly' : '';
if($_DTYPE[$optionid]['type'] == 'radio') {
$optionlist[$optionid]['value'] = array($optiondata[$optionid] => 'checked="checked"');
} elseif($_DTYPE[$optionid]['type'] == 'select') {
$optionlist[$optionid]['value'] = array($optiondata[$optionid] => 'selected="selected"');
} elseif($_DTYPE[$optionid]['type'] == 'checkbox') {
foreach(explode("\t", $optiondata[$optionid]) as $value) {
$optionlist[$optionid]['value'][$value] = array($value => 'checked="checked"');
}
} else {
$optionlist[$optionid]['value'] = $optiondata[$optionid];
}
if(!isset($optiondata[$optionid])) {
$db->query("INSERT INTO {$tablepre}$table (typeid, $field, optionid)
VALUES ('$thread[typeid]', '$id', '$optionid')");
}
}
}
}
function threadtype_validator($typeoption) {
global $checkoption, $var, $selecttypeid, $fid, $tid, $pid;
$postaction = $tid && $pid ? "edit&tid=$tid&pid=$pid" : 'newthread';
$optiondata = array();
foreach($checkoption as $var => $option) {
if($checkoption[$var]['required'] && !$typeoption[$var]) {
showmessage('threadtype_required_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
} elseif($typeoption[$var] && ($checkoption[$var]['type'] == 'number' && !is_numeric($typeoption[$var]) || $checkoption[$var]['type'] == 'email' && !isemail($typeoption[$var]))){
showmessage('threadtype_format_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
} elseif($typeoption[$var] && $checkoption[$var]['maxlength'] && strlen($typeoption[$var]) > $checkoption[$var]['maxlength']) {
showmessage('threadtype_toolong_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
} elseif($typeoption[$var] && (($checkoption[$var]['maxnum'] && $typeoption[$var] >= $checkoption[$var]['maxnum']) || ($checkoption[$var]['minnum'] && $typeoption[$var] < $checkoption[$var]['minnum']))) {
showmessage('threadtype_num_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
} elseif($typeoption[$var] && $checkoption[$var]['unchangeable'] && !($tid && $pid)) {
showmessage('threadtype_unchangeable_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
}
$typeoption[$var] = $checkoption[$var]['type'] == 'checkbox' ? ($typeoption[$var] ? implode("\t", dhtmlspecialchars($typeoption[$var])) : '') : dhtmlspecialchars(censor(trim($typeoption[$var])));
$optiondata[$checkoption[$var]['optionid']] = $typeoption[$var];
}
return $optiondata;
}
function videodelete($ids, $writelog = FALSE) {
global $db, $tablepre, $vsiteid, $vkey;
$ids = implode("','", (array)$ids);
$query = $db->query("SELECT t.tid, v.vid FROM {$tablepre}threads t LEFT JOIN {$tablepre}videos v ON t.tid=v.tid WHERE t.tid IN('$ids') AND t.special='6'");
$data = $datas = array();
while($data = $db->fetch_array($query)) {
$datas[] = $data['vid'];
}
$ids = implode("','", (array)$datas);
$vids = implode(",", (array)$datas);
$db->query("DELETE FROM {$tablepre}videos WHERE tid IN ('$ids')");
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -