imsg_edt.inc.t
来自「eGroupWare is a multi-user, web-based gr」· T 代码 · 共 712 行 · 第 1/2 页
T
712 行
<?php/**************************************************************************** copyright : (C) 2001-2003 Advanced Internet Designs Inc.* email : forum@prohost.org* $Id: imsg_edt.inc.t,v 1.1.1.1 2003/10/17 21:11:28 ralfbecker Exp $** This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or * (at your option) any later version.***************************************************************************/class fud_msg{ var $id, $thread_id, $poster_id, $reply_to, $ip_addr, $host_name, $post_stamp, $subject, $attach_cnt, $poll_id, $update_stamp, $icon, $apr, $updated_by, $login, $length, $foff, $file_id, $msg_opt, $file_id_preview, $length_preview, $offset_preview, $body, $mlist_msg_id;}class fud_msg_edit extends fud_msg{ function add_reply($reply_to, $th_id=null, $perm, $autoapprove=true) { if ($reply_to) { $this->reply_to = $reply_to; $fd = db_saq('SELECT t.forum_id, f.message_threshold, f.forum_opt FROM {SQL_TABLE_PREFIX}msg m INNER JOIN {SQL_TABLE_PREFIX}thread t ON m.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}forum f ON f.id=t.forum_id WHERE m.id='.$reply_to); } else { $fd = db_saq('SELECT t.forum_id, f.message_threshold, f.forum_opt FROM {SQL_TABLE_PREFIX}thread t INNER JOIN {SQL_TABLE_PREFIX}forum f ON f.id=t.forum_id WHERE t.id='.$th_id); } return $this->add($fd[0], $fd[1], $fd[2], $perm, $autoapprove); } function add($forum_id, $message_threshold, $forum_opt, $perm, $autoapprove=true) { if (!$this->post_stamp) { $this->post_stamp = __request_timestamp__; } if (!isset($this->ip_addr)) { $this->ip_addr = get_ip(); } $this->host_name = $GLOBALS['FUD_OPT_1'] & 268435456 ? "'".addslashes(get_host($this->ip_addr))."'" : 'NULL'; $this->thread_id = isset($this->thread_id) ? $this->thread_id : 0; $this->reply_to = isset($this->reply_to) ? $this->reply_to : 0; $file_id = write_body($this->body, $length, $offset); /* determine if preview needs building */ if ($message_threshold && $message_threshold < strlen($this->body)) { $thres_body = trim_html($this->body, $message_threshold); $file_id_preview = write_body($thres_body, $length_preview, $offset_preview); } else { $file_id_preview = $offset_preview = $length_preview = 0; } poll_cache_rebuild($this->poll_id, $poll_cache); $poll_cache = ($poll_cache ? @serialize($poll_cache) : null); $this->id = db_qid("INSERT INTO {SQL_TABLE_PREFIX}msg ( thread_id, poster_id, reply_to, ip_addr, host_name, post_stamp, subject, attach_cnt, poll_id, icon, msg_opt, file_id, foff, length, file_id_preview, offset_preview, length_preview, mlist_msg_id, poll_cache ) VALUES( ".$this->thread_id.", ".$this->poster_id.", ".(int)$this->reply_to.", '".$this->ip_addr."', ".$this->host_name.", ".$this->post_stamp.", ".strnull(addslashes($this->subject)).", ".(int)$this->attach_cnt.", ".(int)$this->poll_id.", ".strnull(addslashes($this->icon)).", ".$this->msg_opt.", ".$file_id.", ".(int)$offset.", ".(int)$length.", ".$file_id_preview.", ".$offset_preview.", ".$length_preview.", ".strnull($this->mlist_msg_id).", ".strnull(addslashes($poll_cache))." )"); $thread_opt = (int) ($perm & 4096 && isset($_POST['thr_locked'])); if (!$this->thread_id) { /* new thread */ if ($perm & 64 && isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry'])) { if ((int)$_POST['thr_ordertype']) { $thread_opt |= (int) $_POST['thr_ordertype']; $thr_orderexpiry = (int) $_POST['thr_orderexpiry']; } } $this->thread_id = th_add($this->id, $forum_id, $this->post_stamp, $thread_opt, (isset($thr_orderexpiry) ? $thr_orderexpiry : 0)); q('UPDATE {SQL_TABLE_PREFIX}msg SET thread_id='.$this->thread_id.' WHERE id='.$this->id); } else { th_lock($this->thread_id, $thread_opt & 1); } if ($autoapprove && $forum_opt & 2) { $this->approve($this->id, true); } return $this->id; } function sync($id, $frm_id, $message_threshold, $perm) { if (!db_locked()) { db_lock('{SQL_TABLE_PREFIX}poll_opt WRITE, {SQL_TABLE_PREFIX}forum WRITE, {SQL_TABLE_PREFIX}msg WRITE, {SQL_TABLE_PREFIX}thread WRITE, {SQL_TABLE_PREFIX}thread_view WRITE'); $ll=1; } $file_id = write_body($this->body, $length, $offset); /* determine if preview needs building */ if ($message_threshold && $message_threshold < strlen($this->body)) { $thres_body = trim_html($this->body, $message_threshold); $file_id_preview = write_body($thres_body, $length_preview, $offset_preview); } else { $file_id_preview = $offset_preview = $length_preview = 0; } poll_cache_rebuild($this->poll_id, $poll_cache); $poll_cache = ($poll_cache ? @serialize($poll_cache) : null); q("UPDATE {SQL_TABLE_PREFIX}msg SET file_id=".$file_id.", foff=".(int)$offset.", length=".(int)$length.", mlist_msg_id=".strnull(addslashes($this->mlist_msg_id)).", file_id_preview=".$file_id_preview.", offset_preview=".$offset_preview.", length_preview=".$length_preview.", updated_by=".$id.", msg_opt=".$this->msg_opt.", attach_cnt=".(int)$this->attach_cnt.", poll_id=".(int)$this->poll_id.", update_stamp=".__request_timestamp__.", icon=".strnull(addslashes($this->icon))." , poll_cache=".strnull(addslashes($poll_cache)).", subject=".strnull(addslashes($this->subject))." WHERE id=".$this->id); /* determine wether or not we should deal with locked & sticky stuff * current approach may seem a little redundant, but for (most) users who * do not have access to locking & sticky this eliminated a query. */ $th_data = db_saq('SELECT orderexpiry, thread_opt, root_msg_id FROM {SQL_TABLE_PREFIX}thread WHERE id='.$this->thread_id); $locked = (int) isset($_POST['thr_locked']); if (isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) || (($th_data[1] ^ $locked) & 1)) { $thread_opt = (int) $th_data[1]; $orderexpiry = isset($_POST['thr_orderexpiry']) ? (int) $_POST['thr_orderexpiry'] : 0; /* confirm that user has ability to change lock status of the thread */ if ($perm & 4096) { if ($locked && !($thread_opt & $locked)) { $thread_opt |= 1; } else if (!$locked && $thread_opt & 1) { $thread_opt &= ~1; } } /* confirm that user has ability to change sticky status of the thread */ if ($th_data[2] == $this->id && isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) && $perm & 64) { if (!$_POST['thr_ordertype'] && $thread_opt>1) { $orderexpiry = 0; $thread_opt &= ~6; } else if ($thread_opt < 2 && (int) $_POST['thr_ordertype']) { $thread_opt |= $_POST['thr_ordertype']; } else if (!($thread_opt & (int) $_POST['thr_ordertype'])) { $thread_opt = $_POST['thr_ordertype'] | ($thread_opt & 1); } } /* Determine if any work needs to be done */ if ($thread_opt != $th_data[1] || $orderexpiry != $th_data[0]) { q("UPDATE {SQL_TABLE_PREFIX}thread SET thread_opt=".$thread_opt.", orderexpiry=".$orderexpiry." WHERE id=".$this->thread_id); /* Avoid rebuilding the forum view whenever possible, since it's a rather slow process * Only rebuild if expiry time has changed or message gained/lost sticky status */ $diff = $thread_opt ^ $th_data[1]; if (($diff > 1 && !($diff & 6)) || $orderexpiry != $th_data[0]) { rebuild_forum_view($frm_id); } } } if (isset($ll)) { db_unlock(); } if ($GLOBALS['FUD_OPT_1'] & 16777216) { delete_msg_index($this->id); index_text((preg_match('!^Re: !i', $this->subject) ? '': $this->subject), $this->body, $this->id); } } function delete($rebuild_view=true, $mid=0, $th_rm=0) { if (!$mid) { $mid = $this->id; } if (!db_locked()) { db_lock('{SQL_TABLE_PREFIX}thr_exchange WRITE, {SQL_TABLE_PREFIX}thread_view WRITE, {SQL_TABLE_PREFIX}level WRITE, {SQL_TABLE_PREFIX}forum WRITE, {SQL_TABLE_PREFIX}forum_read WRITE, {SQL_TABLE_PREFIX}thread WRITE, {SQL_TABLE_PREFIX}msg WRITE, {SQL_TABLE_PREFIX}attach WRITE, {SQL_TABLE_PREFIX}poll WRITE, {SQL_TABLE_PREFIX}poll_opt WRITE, {SQL_TABLE_PREFIX}poll_opt_track WRITE, {SQL_TABLE_PREFIX}users WRITE, {SQL_TABLE_PREFIX}thread_notify WRITE, {SQL_TABLE_PREFIX}msg_report WRITE, {SQL_TABLE_PREFIX}thread_rate_track WRITE'); $ll = 1; } if (!($del = db_sab('SELECT {SQL_TABLE_PREFIX}msg.id, {SQL_TABLE_PREFIX}msg.attach_cnt, {SQL_TABLE_PREFIX}msg.poll_id, {SQL_TABLE_PREFIX}msg.thread_id, {SQL_TABLE_PREFIX}msg.reply_to, {SQL_TABLE_PREFIX}msg.apr, {SQL_TABLE_PREFIX}msg.poster_id, {SQL_TABLE_PREFIX}thread.replies, {SQL_TABLE_PREFIX}thread.root_msg_id AS root_msg_id, {SQL_TABLE_PREFIX}thread.last_post_id AS thread_lip, {SQL_TABLE_PREFIX}thread.forum_id, {SQL_TABLE_PREFIX}forum.last_post_id AS forum_lip FROM {SQL_TABLE_PREFIX}msg LEFT JOIN {SQL_TABLE_PREFIX}thread ON {SQL_TABLE_PREFIX}msg.thread_id={SQL_TABLE_PREFIX}thread.id LEFT JOIN {SQL_TABLE_PREFIX}forum ON {SQL_TABLE_PREFIX}thread.forum_id={SQL_TABLE_PREFIX}forum.id WHERE {SQL_TABLE_PREFIX}msg.id='.$mid))) { if (isset($ll)) { db_unlock(); } return; } /* attachments */ if ($del->attach_cnt) { $res = q('SELECT location FROM {SQL_TABLE_PREFIX}attach WHERE message_id='.$mid." AND attach_opt=0"); while ($loc = db_rowarr($res)) { @unlink($loc[0]); } unset($res); q('DELETE FROM {SQL_TABLE_PREFIX}attach WHERE message_id='.$mid." AND attach_opt=0"); } q('DELETE FROM {SQL_TABLE_PREFIX}msg_report WHERE msg_id='.$mid); if ($del->poll_id) { poll_delete($del->poll_id); } /* check if thread */ if ($del->root_msg_id == $del->id) { $th_rm = 1; /* delete all messages in the thread if there is more then 1 message */ if ($del->replies) { $rmsg = q('SELECT id FROM {SQL_TABLE_PREFIX}msg WHERE thread_id='.$del->thread_id.' AND id != '.$del->id); while ($dim = db_rowarr($rmsg)) { fud_msg_edit::delete(false, $dim[0], 1); } unset($rmsg); } q('DELETE FROM {SQL_TABLE_PREFIX}thread_notify WHERE thread_id='.$del->thread_id); q('DELETE FROM {SQL_TABLE_PREFIX}thread WHERE id='.$del->thread_id); q('DELETE FROM {SQL_TABLE_PREFIX}thread_rate_track WHERE thread_id='.$del->thread_id); q('DELETE FROM {SQL_TABLE_PREFIX}thr_exchange WHERE th='.$del->thread_id); if ($del->apr) { /* we need to determine the last post id for the forum, it can be null */ $lpi = (int) q_singleval('SELECT {SQL_TABLE_PREFIX}thread.last_post_id FROM {SQL_TABLE_PREFIX}thread INNER JOIN {SQL_TABLE_PREFIX}msg ON {SQL_TABLE_PREFIX}thread.last_post_id={SQL_TABLE_PREFIX}msg.id AND {SQL_TABLE_PREFIX}msg.apr=1 WHERE forum_id='.$del->forum_id.' AND moved_to=0 ORDER BY {SQL_TABLE_PREFIX}msg.post_stamp DESC LIMIT 1'); q('UPDATE {SQL_TABLE_PREFIX}forum SET last_post_id='.$lpi.', thread_count=thread_count-1, post_count=post_count-'.$del->replies.'-1 WHERE id='.$del->forum_id); } } else if (!$th_rm && $del->apr) { q('UPDATE {SQL_TABLE_PREFIX}msg SET reply_to='.$del->reply_to.' WHERE thread_id='.$del->thread_id.' AND reply_to='.$mid); /* check if the message is the last in thread */ if ($del->thread_lip == $del->id) { list($lpi, $lpd) = db_saq('SELECT id, post_stamp FROM {SQL_TABLE_PREFIX}msg WHERE thread_id='.$del->thread_id.' AND apr=1 AND id!='.$del->id.' ORDER BY post_stamp DESC LIMIT 1'); q('UPDATE {SQL_TABLE_PREFIX}thread SET last_post_id='.$lpi.', last_post_date='.$lpd.', replies=replies-1 WHERE id='.$del->thread_id); } else { q('UPDATE {SQL_TABLE_PREFIX}thread SET replies=replies-1 WHERE id='.$del->thread_id); } /* check if the message is the last in the forum */ if ($del->forum_lip == $del->id) { $lp = db_saq('SELECT {SQL_TABLE_PREFIX}thread.last_post_id, {SQL_TABLE_PREFIX}thread.last_post_date FROM {SQL_TABLE_PREFIX}thread_view INNER JOIN {SQL_TABLE_PREFIX}thread ON {SQL_TABLE_PREFIX}thread_view.forum_id={SQL_TABLE_PREFIX}thread.forum_id AND {SQL_TABLE_PREFIX}thread_view.thread_id={SQL_TABLE_PREFIX}thread.id WHERE {SQL_TABLE_PREFIX}thread_view.forum_id='.$del->forum_id.' AND {SQL_TABLE_PREFIX}thread_view.page=1 AND {SQL_TABLE_PREFIX}thread.moved_to=0 ORDER BY {SQL_TABLE_PREFIX}thread.last_post_date DESC LIMIT 1'); if (!isset($lpd) || $lp[1] > $lpd) { $lpi = $lp[0]; } q('UPDATE {SQL_TABLE_PREFIX}forum SET post_count=post_count-1, last_post_id='.$lpi.' WHERE id='.$del->forum_id); } else { q('UPDATE {SQL_TABLE_PREFIX}forum SET post_count=post_count-1 WHERE id='.$del->forum_id); } } q('DELETE FROM {SQL_TABLE_PREFIX}msg WHERE id='.$mid); if ($del->apr) { if ($del->poster_id) { user_set_post_count($del->poster_id); } if ($rebuild_view) { rebuild_forum_view($del->forum_id); /* needed for moved thread pointers */ $r = q('SELECT forum_id, id FROM {SQL_TABLE_PREFIX}thread WHERE root_msg_id='.$del->root_msg_id); while (($res = db_rowarr($r))) { if ($th_rm) { q('DELETE FROM {SQL_TABLE_PREFIX}thread WHERE id='.$res[1]); } rebuild_forum_view($res[0]); } unset($r); } } if (isset($ll)) { db_unlock(); } } function approve($id, $unlock_safe=false) { /* fetch info about the message, poll (if one exists), thread & forum */ $mtf = db_sab('SELECT m.id, m.poster_id, m.apr, m.subject, m.foff, m.length, m.file_id, m.thread_id, m.poll_id, m.attach_cnt, m.post_stamp, m.reply_to, m.mlist_msg_id, t.forum_id, t.last_post_id, t.root_msg_id, t.last_post_date, m2.post_stamp AS frm_last_post_date, f.name AS frm_name, u.alias, u.email, u.sig, n.id AS nntp_id, ml.id AS mlist_id FROM {SQL_TABLE_PREFIX}msg m INNER JOIN {SQL_TABLE_PREFIX}thread t ON m.thread_id=t.id INNER JOIN {SQL_TABLE_PREFIX}forum f ON t.forum_id=f.id LEFT JOIN {SQL_TABLE_PREFIX}msg m2 ON f.last_post_id=m2.id LEFT JOIN {SQL_TABLE_PREFIX}users u ON m.poster_id=u.id LEFT JOIN {SQL_TABLE_PREFIX}mlist ml ON ml.forum_id=f.id LEFT JOIN {SQL_TABLE_PREFIX}nntp n ON n.forum_id=f.id WHERE m.id='.$id.' AND m.apr=0'); /* nothing to do or bad message id */ if (!$mtf) { return; } if ($mtf->alias) { reverse_fmt($mtf->alias); } else { $mtf->alias = $GLOBALS['ANON_NICK']; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?