imsg_edt.inc.t

来自「eGroupWare is a multi-user, web-based gr」· T 代码 · 共 712 行 · 第 1/2 页

T
712
字号
		if (!db_locked()) {			db_lock('{SQL_TABLE_PREFIX}thread_view WRITE, {SQL_TABLE_PREFIX}level WRITE, {SQL_TABLE_PREFIX}users WRITE, {SQL_TABLE_PREFIX}forum WRITE, {SQL_TABLE_PREFIX}thread WRITE, {SQL_TABLE_PREFIX}msg WRITE');			$ll = 1;		}		q("UPDATE {SQL_TABLE_PREFIX}msg SET apr=1 WHERE id=".$mtf->id);		if ($mtf->poster_id) {			user_set_post_count($mtf->poster_id);		}		$last_post_id = $mtf->post_stamp > $mtf->frm_last_post_date ? $mtf->id : 0;		if ($mtf->root_msg_id == $mtf->id) {	/* new thread */			rebuild_forum_view($mtf->forum_id);			$threads = 1;		} else {				/* reply to thread */			if ($mtf->post_stamp > $mtf->last_post_date) {				th_inc_post_count($mtf->thread_id, 1, $mtf->id, $mtf->post_stamp);			} else {				th_inc_post_count($mtf->thread_id, 1);			}			rebuild_forum_view($mtf->forum_id, q_singleval('SELECT page FROM {SQL_TABLE_PREFIX}thread_view WHERE forum_id='.$mtf->forum_id.' AND thread_id='.$mtf->thread_id));			$threads = 0;		}		/* update forum thread & post count as well as last_post_id field */		frm_updt_counts($mtf->forum_id, 1, $threads, $last_post_id);		if ($unlock_safe || isset($ll)) {			db_unlock();		}		if ($mtf->poll_id) {			poll_activate($mtf->poll_id, $mtf->forum_id);		}		$mtf->body = read_msg_body($mtf->foff, $mtf->length, $mtf->file_id);		if ($GLOBALS['FUD_OPT_1'] & 16777216) {			index_text((preg_match('!Re: !i', $mtf->subject) ? '': $mtf->subject), $mtf->body, $mtf->id);		}		/* handle notifications */		if ($mtf->root_msg_id == $mtf->id) {			if (empty($mtf->frm_last_post_date)) {				$mtf->frm_last_post_date = 0;			}			/* send new thread notifications to forum subscribers */			$c = uq('SELECT u.email, u.icq, u.users_opt					FROM {SQL_TABLE_PREFIX}forum_notify fn					INNER JOIN {SQL_TABLE_PREFIX}users u ON fn.user_id=u.id					LEFT JOIN {SQL_TABLE_PREFIX}forum_read r ON r.forum_id=fn.forum_id AND r.user_id=fn.user_id					INNER JOIN {SQL_TABLE_PREFIX}group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id='.$mtf->forum_id.'					LEFT JOIN {SQL_TABLE_PREFIX}group_cache g2 ON g2.user_id=fn.user_id AND g2.resource_id='.$mtf->forum_id.'				WHERE					fn.forum_id='.$mtf->forum_id.' AND fn.user_id!='.(int)$mtf->poster_id.'					AND (CASE WHEN (r.last_view IS NULL AND (u.last_read=0 OR u.last_read >= '.$mtf->frm_last_post_date.')) OR r.last_view > '.$mtf->frm_last_post_date.' THEN 1 ELSE 0 END)=1					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');			$notify_type = 'frm';		} else {			/* send new reply notifications to thread subscribers */			$c = uq('SELECT u.email, u.icq, u.users_opt, r.msg_id, u.id					FROM {SQL_TABLE_PREFIX}thread_notify tn					INNER JOIN {SQL_TABLE_PREFIX}users u ON tn.user_id=u.id					LEFT JOIN {SQL_TABLE_PREFIX}read r ON r.thread_id=tn.thread_id AND r.user_id=tn.user_id					INNER JOIN {SQL_TABLE_PREFIX}group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id='.$mtf->forum_id.'					LEFT JOIN {SQL_TABLE_PREFIX}group_cache g2 ON g2.user_id=tn.user_id AND g2.resource_id='.$mtf->forum_id.'				WHERE					tn.thread_id='.$mtf->thread_id.' AND tn.user_id!='.(int)$mtf->poster_id.'					AND (r.msg_id='.$mtf->last_post_id.' OR (r.msg_id IS NULL AND '.$mtf->post_stamp.' > u.last_read))					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');			$notify_type = 'thr';		}		while ($r = db_rowarr($c)) {			if ($r[2] & 16) {				$to['EMAIL'] = $r[0];			} else {				$to['ICQ'] = $r[1].'@pager.icq.com';			}			if (isset($r[4]) && is_null($r[3])) {				$tl[] = $r[4];			}		}		unset($c);		if (isset($tl)) {			/* this allows us to mark the message we are sending notification about as read, so that we do not re-notify the user			 * until this message is read.			 */			q('INSERT INTO {SQL_TABLE_PREFIX}read (thread_id, msg_id, last_view, user_id) SELECT '.$mtf->thread_id.', 0, 0, id FROM {SQL_TABLE_PREFIX}users WHERE id IN('.implode(',', $tl).')');		}		if (isset($to)) {			send_notifications($to, $mtf->id, $mtf->subject, $mtf->alias, $notify_type, ($notify_type == 'thr' ? $mtf->thread_id : $mtf->forum_id), $mtf->frm_name, $mtf->forum_id);		}		// Handle Mailing List and/or Newsgroup syncronization.		if (($mtf->nntp_id || $mtf->mlist_id) && !$mtf->mlist_msg_id) {			fud_use('email_msg_format.inc', true);			reverse_fmt($mtf->alias);			$from = $mtf->poster_id ? $mtf->alias.' <'.$mtf->email.'>' : $GLOBALS['ANON_NICK'].' <'.$GLOBALS['NOTIFY_FROM'].'>';			$body = $mtf->body . (($mtf->msg_opt & 1 && $mtf->sig) ? "\n--\n" . $mtf->sig : '');			plain_text($body);			plain_text($subject);			if ($mtf->reply_to) {				$replyto_id = q_singleval('SELECT mlist_msg_id FROM {SQL_TABLE_PREFIX}msg WHERE id='.$mtf->reply_to);			} else {				$replyto_id = 0;			}			if ($mtf->attach_cnt) {				$r = uq("SELECT a.id, a.original_name,						CASE WHEN m.mime_hdr IS NULL THEN 'application/octet-stream' ELSE m.mime_hdr END						FROM {SQL_TABLE_PREFIX}attach a						LEFT JOIN {SQL_TABLE_PREFIX}mime m ON a.mime_type=m.id						WHERE a.message_id=".$mtf->id." AND a.attach_opt=0");				while ($ent = db_rowarr($r)) {					$attach[$ent[1]] = file_get_contents($GLOBALS['FILE_STORE'].$ent[0].'.atch');					if ($mtf->mlist_id) {						$attach_mime[$ent[1]] = $ent[2];					}				}			} else {				$attach_mime = $attach = null;			}			if ($mtf->nntp_id) {				fud_use('nntp.inc', true);				$nntp_adm = db_sab('SELECT * FROM {SQL_TABLE_PREFIX}nntp WHERE id='.$mtf->nntp_id);				$nntp = new fud_nntp;				$nntp->server = $nntp_adm->server;				$nntp->newsgroup = $nntp_adm->newsgroup;				$nntp->port = $nntp_adm->port;				$nntp->timeout = $nntp_adm->timeout;				$nntp->nntp_opt = $nntp_adm->nntp_opt;				$nntp->login = $nntp_adm->login;				$nntp->pass = $nntp_adm->pass;				define('sql_p', '{SQL_TABLE_PREFIX}');				$lock = $nntp->get_lock();				$nntp->post_message($mtf->subject, $body, $from, $mtf->id, $replyto_id, $attach);				$nntp->close_connection();				$nntp->release_lock($lock);			} else {				fud_use('mlist_post.inc', true);				$GLOBALS['CHARSET'] = '{TEMPLATE: imsg_CHARSET}';				$r = db_saq('SELECT name, additional_headers FROM {SQL_TABLE_PREFIX}mlist WHERE id='.$mtf->mlist_id);				mail_list_post($r[0], $from, $mtf->subject, $body, $mtf->id, $replyto_id, $attach, $attach_mime, $r[1]);			}		}	}}function write_body($data, &$len, &$offset){	$MAX_FILE_SIZE = 2147483647;	$len = strlen($data);	$i = 1;	while ($i < 100) {		$fp = fopen($GLOBALS['MSG_STORE_DIR'].'msg_'.$i, 'ab');		fseek($fp, 0, SEEK_END);		if (!($off = ftell($fp))) {			$off = __ffilesize($fp);		}		if (!$off || ($off + $len) < $MAX_FILE_SIZE) {			break;		}		fclose($fp);		$i++;	}	if (fwrite($fp, $data) !== $len) {		exit("FATAL ERROR: system has ran out of disk space<br>\n");	}	fclose($fp);	if (!$off) {		@chmod('msg_'.$i, ($GLOBALS['FUD_OPT_2'] & 8388608 ? 0600 : 0666));	}	$offset = $off;	return $i;}function trim_html($str, $maxlen){	$n = strlen($str);	$ln = 0;	for ($i = 0; $i < $n; $i++) {		if ($str[$i] != '<') {			$ln++;			if ($ln > $maxlen) {				break;			}			continue;		}		if (($p = strpos($str, '>', $i)) === false) {			break;		}		for ($k = $i; $k < $p; $k++) {			switch ($str[$k]) {				case ' ':				case "\r":				case "\n":				case "\t":				case ">":					break 2;			}		}		if ($str[$i+1] == '/') {			$tagname = strtolower(substr($str, $i+2, $k-$i-2));			if (@end($tagindex[$tagname])) {				$k = key($tagindex[$tagname]);				unset($tagindex[$tagname][$k], $tree[$k]);			}		} else {			$tagname = strtolower(substr($str, $i+1, $k-$i-1));			switch ($tagname) {				case 'br':				case 'img':				case 'meta':					break;				default:					$tree[] = $tagname;					end($tree);					$tagindex[$tagname][key($tree)] = 1;			}		}		$i = $p;	}	$data = substr($str, 0, $i);	if (isset($tree) && is_array($tree)) {		$tree = array_reverse($tree);		foreach ($tree as $v) {			$data .= '</'.$v.'>';		}	}	return $data;}function make_email_message(&$body, &$obj, $iemail_unsub){	$TITLE_EXTRA = $iemail_poll = $iemail_attach = '';	if ($obj->poll_cache) {		$pl = @unserialize($obj->poll_cache);		if (is_array($pl) && count($pl)) {			foreach ($pl as $k => $v) {				$length = ($v[1] && $obj->total_votes) ? round($v[1] / $obj->total_votes * 100) : 0;				$iemail_poll .= '{TEMPLATE: iemail_poll_result}';			}			$iemail_poll = '{TEMPLATE: iemail_poll_tbl}';		}	}	if ($obj->attach_cnt && $obj->attach_cache) {		$atch = @unserialize($obj->attach_cache);		if (is_array($atch) && count($atch)) {			foreach ($atch as $v) {				$sz = $v[2] / 1024;				$sz = $sz < 1000 ? number_format($sz, 2).'KB' : number_format($sz/1024, 2).'MB';				$iemail_attach .= '{TEMPLATE: iemail_attach_entry}';			}			$iemail_attach = '{TEMPLATE: iemail_attach}';		}	}	return '{TEMPLATE: iemail_body}';}function send_notifications($to, $msg_id, $thr_subject, $poster_login, $id_type, $id, $frm_name, $frm_id){	if (isset($to['EMAIL']) && (is_string($to['EMAIL']) || (is_array($to['EMAIL']) && count($to['EMAIL'])))) {		$do_email = 1;		$goto_url['email'] = '{ROOT}?t=rview&goto='.$msg_id;		if ($GLOBALS['FUD_OPT_2'] & 64) {			$obj = db_sab("SELECT p.total_votes, p.name AS poll_name, m.reply_to, m.subject, m.id, m.post_stamp, m.poster_id, m.foff, m.length, m.file_id, u.alias, m.attach_cnt, m.attach_cache, m.poll_cache FROM {SQL_TABLE_PREFIX}msg m LEFT JOIN {SQL_TABLE_PREFIX}users u ON m.poster_id=u.id LEFT JOIN {SQL_TABLE_PREFIX}poll p ON m.poll_id=p.id WHERE m.id=".$msg_id." AND m.apr=1");			$headers  = "MIME-Version: 1.0\r\n";			if ($obj->reply_to) {				$headers .= "In-Reply-To: ".$obj->reply_to."\r\n";			}			$headers .= "List-Id: ".$frm_id.".".$_SERVER['SERVER_NAME']."\r\n";			$split = get_random_value(128)                                                                            ;			$headers .= "Content-Type: multipart/alternative; boundary=\"------------" . $split . "\"\r\n";			$boundry = "\r\n--------------" . $split . "\r\n";			$CHARSET = '{TEMPLATE: CHARSET}';			$pfx = '';			$plain_text = read_msg_body($obj->foff, $obj->length, $obj->file_id);			$iemail_unsub = $id_type == 'thr' ? '{TEMPLATE: iemail_thread_unsub}' : '{TEMPLATE: iemail_forum_unsub}';			$body_email = $boundry . "Content-Type: text/plain; charset=" . $CHARSET . "; format=flowed\r\nContent-Transfer-Encoding: 7bit\r\n\r\n" . strip_tags($plain_text) . "\r\n\r\n" . '{TEMPLATE: iemail_participate}' . ' ' . '{ROOT}?t=rview&th=' . $id . "&notify=1&opt=off\r\n" .			$boundry . "Content-Type: text/html; charset=" . $CHARSET . "\r\nContent-Transfer-Encoding: 7bit\r\n\r\n" . make_email_message($plain_text, $obj, $iemail_unsub) . "\r\n" . substr($boundry, 0, -2) . "--\r\n";		}	}	if (isset($to['ICQ']) && (is_string($to['ICQ']) || (is_array($to['ICQ']) && count($to['ICQ'])))) {		$do_icq = 1;		$icq = str_replace('http://', "http'+'://'+'", $GLOBALS['WWW_ROOT']);		$icq = str_replace('www.', "www'+'.", $icq);		$goto_url['icq'] = "javascript:window.location='".$icq."{ROOT}?t=rview&goto=".$msg_id."';";	} else if (!isset($do_email)) {		/* nothing to do */		return;	}	reverse_fmt($thr_subject);	reverse_fmt($poster_login);	if ($id_type == 'thr') {		$subj = '{TEMPLATE: iemail_thr_subject}';		if (!isset($body_email) && isset($do_email)) {			$unsub_url['email'] = '{ROOT}?t=rview&th='.$id.'&notify=1&opt=off';			$body_email = '{TEMPLATE: iemail_thr_bodyemail}';		}		if (isset($do_icq)) {			$unsub_url['icq'] = "javascript:window.location='".$icq."{ROOT}?t=rview&th=".$id."&notify=1&opt=off';";			$body_icq = '{TEMPLATE: iemail_thr_bodyicq}';		}	} else if ($id_type == 'frm') {		reverse_fmt($frm_name);		$subj = '{TEMPLATE: iemail_frm_subject}';		if (isset($do_icq)) {			$unsub_url['icq'] = "javascript:window.location='".$icq."{ROOT}?t=rview&unsub=1&frm_id=".$id."';";			$body_icq = '{TEMPLATE: iemail_frm_bodyicq}';		}		if (!isset($body_email) && isset($do_email)) {			$unsub_url['email'] = '{ROOT}?t=rview&unsub=1&frm_id='.$id;			$body_email = '{TEMPLATE: iemail_frm_bodyemail}';		}	}	if (isset($do_email)) {		send_email($GLOBALS['NOTIFY_FROM'], $to['EMAIL'], $subj, $body_email, (isset($headers) ? $headers : ''));	}	if (isset($do_icq)) {		send_email($GLOBALS['NOTIFY_FROM'], $to['ICQ'], $subj, $body_icq);	}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?