*
* Copyright 1999-2000, Tim Perdue/Sourceforge
* Copyright 2002, Tim Perdue/GForge, LLC
+ * Copyright 2009, Roland Mas
*
* This file is part of FusionForge.
*
}
}
- $sql="INSERT INTO forum_pending_messages (group_forum_id,posted_by,subject,
- body,post_date,is_followup_to,thread_id,most_recent_date)
- VALUES ('". $this->Forum->getID() ."', '$user_id', '". htmlspecialchars($subject) ."',
- '". $body ."', '". time() ."','$is_followup_to','$thread_id','". time() ."')";
-
- $result=db_query($sql);
+ $result = db_query_params ('INSERT INTO forum_pending_messages (group_forum_id,posted_by,subject,
+ body,post_date,is_followup_to,thread_id,most_recent_date) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
+ array ($this->Forum->getID(),
+ $user_id,
+ htmlspecialchars($subject),
+ $body,
+ time(),
+ $is_followup_to,
+ $thread_id,
+ time ())) ;
if (!$result || db_affected_rows($result) < 1) {
$this->setError(_('ForumMessage::create() Posting Failed').' '.db_error());
db_rollback();
// increment the parent's followup count if necessary
//
db_begin();
- $res4=db_query("UPDATE forum SET most_recent_date='". time() ."'
- WHERE thread_id='$thread_id' AND is_followup_to='0'");
+ $res4 = db_query_params ('UPDATE forum SET most_recent_date=$1 WHERE thread_id=$2 AND is_followup_to=0',
+ array (time(),
+ $thread_id)) ;
if (!$res4 || db_affected_rows($res4) < 1) {
$this->setError(_('Couldn\'t Update Master Thread parent with current time'));
db_rollback();
//
// mark the parent with followups as an optimization later
//
- $res3=db_query("UPDATE forum SET has_followups='1',most_recent_date='". time() ."'
- WHERE msg_id='$is_followup_to'");
+ $res3 = db_query_params ('UPDATE forum SET has_followups=1,most_recent_date=$1 WHERE msg_id=$2',
+ array (time(),
+ $is_followup_to)) ;
if (!$res3) {
$this->setError(_('Could Not Update Parent'));
db_rollback();
db_begin();
- $sql="INSERT INTO forum (group_forum_id,posted_by,subject,
- body,post_date,is_followup_to,thread_id,most_recent_date)
- VALUES ('". $group_forum_id ."', '$posted_by', '". htmlspecialchars($subject) ."',
- '". $body ."', '". $post_date ."','$is_followup_to','$thread_id','". $most_recent_date ."')";
+ $result = db_query_params ('INSERT INTO forum (group_forum_id,posted_by,subject,body,post_date,is_followup_to,thread_id,most_recent_date) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
+ array ($group_forum_id,
+ $posted_by,
+ htmlspecialchars($subject),
+ $body,
+ $post_date,
+ $is_followup_to,
+ $thread_id,
+ $most_recent_date)) ;
- $result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$this->setError(_('ForumMessage::create() Posting Failed').' '.db_error());
db_rollback();
//
// increment the parent's followup count if necessary
//
- $res4=db_query("UPDATE forum SET most_recent_date='". time() ."'
- WHERE thread_id='$thread_id' AND is_followup_to='0'");
+ $res4 = db_query_params ('UPDATE forum SET most_recent_date=$1 WHERE thread_id=$2 AND is_followup_to=0',
+ array (time(),
+ $thread_id)) ;
if (!$res4 || db_affected_rows($res4) < 1) {
$this->setError(_('Couldn\'t Update Master Thread parent with current time'));
db_rollback();
//
// mark the parent with followups as an optimization later
//
- $res3=db_query("UPDATE forum SET has_followups='1',most_recent_date='". time() ."'
- WHERE msg_id='$is_followup_to'");
+ $res3 = db_query_params ('UPDATE forum SET has_followups=1,most_recent_date=$1 WHERE msg_id=$2',
+ array (time(),
+ $is_followup_to)) ;
if (!$res3) {
$this->setError(_('Could Not Update Parent'));
db_rollback();
}
}
- $sql="INSERT INTO forum (group_forum_id,posted_by,subject,
- body,post_date,is_followup_to,thread_id,most_recent_date)
- VALUES ('". $this->Forum->getID() ."', '$user_id', '". htmlspecialchars($subject) ."',
- '". $body ."', '". time() ."','$is_followup_to','$thread_id','". time() ."')";
-
- $result=db_query($sql);
+ $result = db_query_params ('INSERT INTO forum (group_forum_id,posted_by,subject,body,post_date,is_followup_to,thread_id,most_recent_date) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
+ array ($this->Forum->getID(),
+ $user_id,
+ htmlspecialchars($subject),
+ $body,
+ time(),
+ $is_followup_to,
+ $thread_id,
+ time())) ;
if (!$result || db_affected_rows($result) < 1) {
$this->setError(_('ForumMessage::create() Posting Failed').' '.db_error());
db_rollback();
$is_followup_to=0;
}
- //see if that message has been posted already for all the idiots that double-post
- //we shouldn't need this, the double post checker functions solve this issue now
- /*$res3=db_query("SELECT * FROM forum
- WHERE is_followup_to='$is_followup_to'
- AND body='". htmlspecialchars($body) ."'
- AND subject='". htmlspecialchars($subject) ."'
- AND group_forum_id='". $this->Forum->getId() ."'
- AND posted_by='$user_id'");
-
- if (db_numrows($res3) > 0) {
- //already posted this message
- $this->setError(_('You appear to be double-posting this message, since it has the same subject and followup information as a prior post.'));
- return false;
- } else {
- echo db_error();
- }*/
-
db_begin();
//now we check the moderation status of the forum and act accordingly
* @return boolean success.
*/
function fetchData($msg_id) {
- $res=db_query("SELECT * FROM forum_user_vw
- WHERE msg_id='$msg_id'
- AND group_forum_id='". $this->Forum->getID() ."'");
+ $res = db_query_params ('SELECT * FROM forum_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
+ array ($msg_id,
+ $this->Forum->getID())) ;
if (!$res || db_numrows($res) < 1) {
$this->setError(_('ForumMessage::fetchData() Invalid MessageID').db_error());
return false;
* @return boolean success.
*/
function fetchModeratedData($msg_id) {
- $res=db_query("SELECT * FROM forum_pending_user_vw
- WHERE msg_id='$msg_id'
- AND group_forum_id='". $this->Forum->getID() ."'");
+ $res = db_query_params ('SELECT * FROM forum_pending_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
+ array ($msg_id,
+ $this->Forum->getID())) ;
if (!$res || db_numrows($res) < 1) {
$this->setError(_('ForumMessage::fetchData() Invalid MessageID').db_error());
return false;
function hasAttach() {
if ($this->isPending()) {
- $sql = "SELECT attachmentid FROM forum_pending_attachment WHERE msg_id='$this->getID()'";
+ $res = db_query_params ('SELECT attachmentid FROM forum_pending_attachment WHERE msg_id=$1',
+ array ($this->getID())) ;
} else {
- $sql = "SELECT attachmentid FROM forum_attachment WHERE msg_id='$this->getID()'";
+ $res = db_query_params ('SELECT attachmentid FROM forum_attachment WHERE msg_id=$1',
+ array ($this->getID())) ;
}
- if ((db_numrows(db_query($sql)) > 0 )) {
+ if (db_numrows($res) > 0) {
return true;
}
return false;
$this->setPermissionDeniedError();
return false;
}*/
-
- $sql="SELECT msg_id FROM forum
- WHERE is_followup_to='$msg_id'
- AND group_forum_id='".$this->Forum->getID()."'";
- $result=db_query($sql);
+ $result = db_query_params ('SELECT msg_id FROM forum
+ WHERE is_followup_to=$1
+ AND group_forum_id=$2',
+ array ($msg_id,
+ $this->Forum->getID())) ;
$rows=db_numrows($result);
$count=1;
-
for ($i=0;$i<$rows;$i++) {
$msg = new ForumMessage($this->Forum,db_result($result,$i,'msg_id'));
$count += $msg->delete();
}
- $sql="DELETE FROM forum
- WHERE msg_id='$msg_id'
- AND group_forum_id='".$this->Forum->getID()."'";
- $toss=db_query($sql);
- $sql = "DELETE FROM forum_attachment where msg_id='$msg_id'";
- $res = db_query($res);
+ $toss = db_query_params ('DELETE FROM forum
+ WHERE msg_id=$1
+ AND group_forum_id=$2',
+ array ($msg_id,
+ $this->Forum->getID())) ;
+ $res = db_query_params ('DELETE FROM forum_attachment where msg_id=$1',
+ array ($msg_id));
return $count;
function sendNotice($has_attach=false) {
$ids =& $this->Forum->getMonitoringIDs();
- //
- // See if there is anyone to send messages to
- //
- if (!count($ids) > 0 && !$this->Forum->getSendAllPostsTo()) {
- return true;
+ $recipients = array ();
+ foreach ($ids as $id) {
+ $recipient = user_get_object ($id) ;
+ if ($recipient->isActive()) {
+ $recipients[] = $recipient ;
+ }
}
-
- $body = "\nRead and respond to this message at: ".
- "\n".util_make_url ('/forum/message.php?msg_id='.$this->getID()).
- "\nOr by replying to this e-mail entering your response between the following markers: ".
- "\n".FORUM_MAIL_MARKER.
- "\n(enter your response here)".
- "\n".FORUM_MAIL_MARKER.
- "\n\n".
- "\nBy: " . $this->getPosterRealName() . "\n";
-
- if ($has_attach) {
- //if there's an attachment for the message, make it note.
- //Note: We can't give a link for the attachment here because it hasn't been created yet (first the message needs to be created
- $body .= "A file has been uploaded with this message\n\n";
- } else {
- $body .= "\n";
+ if ($this->Forum->getSendAllPostsTo()) {
+ $sapt = explode (',', $this->Forum->getSendAllPostsTo()) ;
+ foreach ($sapt as $r) {
+ $recipients[] = $r;
+ }
}
- $sanitizer = new TextSanitizer();
- $text = $this->getBody();
- $text = $sanitizer->convertNeededTagsForEmail($text);
- $text= strip_tags($this->removebbcode(util_line_wrap($text)));
- $text = $sanitizer->convertExtendedCharsForEmail($text);
- $body .= $text .
- "\n\n______________________________________________________________________".
- "\nYou are receiving this email because you elected to monitor this forum.".
- "\nTo stop monitoring this forum, login to ".$GLOBALS['sys_name']." and visit: ".
- "\n".util_make_url('/forum/monitor.php?forum_id='.$this->Forum->getID().'&group_id='.$this->Forum->Group->getID().'&stop=1');
-
- //$extra_headers = 'Reply-to: '.$this->Forum->getUnixName().'@'.$GLOBALS['sys_default_domain'];
- $extra_headers = "Return-Path: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Errors-To: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Sender: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Reply-To: ".$this->Forum->getReturnEmailAddress()."\n";
- $extra_headers .= "Precedence: Bulk\n"
- ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".$GLOBALS['sys_default_domain'].">\n"
- ."List-Help: ".util_make_url ('/forum/forum.php?id='.$this->Forum->getId())."\n"
- ."Message-Id: <forumpost".$this->getId()."@".$GLOBALS['sys_default_domain'].">";
- $parentid = $this->getParentId();
- if (!empty($parentid)) {
- $extra_headers .= "\nIn-Reply-To: ".$this->Forum->getReturnEmailAddress()."\n"
- ."References: <forumpost".$this->getParentId()."@".$GLOBALS['sys_default_domain'].">";
+
+ if (count ($recipients) == 0) {
+ return true ;
}
- $subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
- if (count($ids) != 0) {
- // maybe we have no monitoring ids. this was causing a transaction to be aborted because of being called everytime
- $sql="SELECT email FROM users WHERE status='A' AND user_id IN ('".implode($ids,'\',\'')."')";
- $bccres = db_query($sql);
+ foreach ($recipients as $recipient) {
+ if (is_a ($recipient, 'GFUser')) {
+ setup_gettext_for_user ($recipient) ;
+ $dest_email = $recipient->getEmail ();
+ } else {
+ setup_gettext_from_sys_lang ();
+ $dest_email = $recipient ;
+ }
+
+ $body = sprintf(_("\nRead and respond to this message at: \n%s"), util_make_url ('/forum/message.php?msg_id='.$this->getID()));
+ if ($GLOBALS['sys_use_mail']) {
+ $body .= stripcslashes(sprintf(_('
+Or reply to this e-mail entering your response between the following markers:
+%1$s
+(enter your response here)
+%1$s'), FORUM_MAIL_MARKER));
+ }
+ $body .= sprintf(_("\n\n\nBy: %s\n"), $this->getPosterRealName());
+
+ if ($has_attach) {
+ //if there's an attachment for the message, make it note.
+ //Note: We can't give a link for the attachment here because it hasn't been created yet (first the message needs to be created
+ $body .= _("A file has been uploaded with this message.")."\n\n";
+ } else {
+ $body .= "\n";
+ }
+ $sanitizer = new TextSanitizer();
+ $text = $this->getBody();
+ $text = $sanitizer->convertNeededTagsForEmail($text);
+ $text= strip_tags($this->removebbcode(util_line_wrap($text)));
+ $text = $sanitizer->convertExtendedCharsForEmail($text);
+ $body .= sprintf(
+ "%s\n\n______________________________________________________________________\n".
+ _("You are receiving this email because you elected to monitor this forum.".
+ "\nTo stop monitoring this forum, login to %s and visit: \n%s\n"),
+ $text,
+ forge_get_config ('forge_name'),
+ util_make_url('/forum/monitor.php?forum_id='.$this->Forum->getID().
+ '&group_id='.$this->Forum->Group->getID().'&stop=1')
+ );
+
+ $extra_headers = "Return-Path: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Errors-To: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Sender: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Reply-To: ".$this->Forum->getReturnEmailAddress()."\n";
+ $extra_headers .= "Precedence: Bulk\n"
+ ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".forge_get_config('web_host').">\n"
+ ."List-Help: ".util_make_url ('/forum/forum.php?id='.$this->Forum->getId())."\n"
+ ."Message-Id: <forumpost".$this->getId()."@".forge_get_config('web_host').">";
+ $parentid = $this->getParentId();
+ if (!empty($parentid)) {
+ $extra_headers .= "\nIn-Reply-To: ".$this->Forum->getReturnEmailAddress()."\n"
+ ."References: <forumpost".$this->getParentId()."@".forge_get_config('web_host').">";
+ }
+
+ $subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
+
+ util_send_message($dest_email,$subject,$body,"noreply@".forge_get_config('web_host'),'','Forum',$extra_headers);
}
- $BCC =& implode(util_result_column_to_array($bccres),',').','.$this->Forum->getSendAllPostsTo();
-//echo $BCC;
- $User = user_get_object($this->getPosterID());
- util_send_message('',$subject,$body,"noreply@".$GLOBALS['sys_default_domain'],$BCC,'Forum',$extra_headers);
- //util_send_message('',$subject,$body,$User->getEmail(),$BCC,$this->getPosterRealName(),$extra_headers);
-// util_handle_message(array_unique($ids),$subject,$body,$this->Forum->getSendAllPostsTo(),'','forumgateway@'.$GLOBALS[sys_default_domain]);
+
+ // Switch back to the user language settings
+ setup_gettext_from_context();
return true;
}
"\n\n______________________________________________________________________".
"\nYou are receiving this email because the forum you administrate has a new moderated message awaiting your approval.";
- //$extra_headers = 'Reply-to: '.$this->Forum->getUnixName().'@'.$GLOBALS['sys_default_domain'];
- $extra_headers = "Return-Path: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Errors-To: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Sender: <noreply@".$GLOBALS['sys_default_domain'].">\n";
+ //$extra_headers = 'Reply-to: '.$this->Forum->getUnixName().'@'.forge_get_config('web_host');
+ $extra_headers = "Return-Path: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Errors-To: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Sender: <noreply@".forge_get_config('web_host').">\n";
$extra_headers .= "Reply-To: ".$this->Forum->getReturnEmailAddress()."\n";
$extra_headers .= "Precedence: Bulk\n"
- ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".$GLOBALS['sys_default_domain'].">\n"
+ ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".forge_get_config('web_host').">\n"
."List-Help: ".util_make_url('/forum/forum.php?id='.$this->Forum->getId())."\n"
- ."Message-Id: <forumpost".$this->getId()."@".$GLOBALS['sys_default_domain'].">";
+ ."Message-Id: <forumpost".$this->getId()."@".forge_get_config('web_host').">";
$parentid = $this->getParentId();
if (!empty($parentid)) {
$extra_headers .= "\nIn-Reply-To: ".$this->Forum->getReturnEmailAddress()."\n"
- ."References: <forumpost".$this->getParentId()."@".$GLOBALS['sys_default_domain'].">";
+ ."References: <forumpost".$this->getParentId()."@".forge_get_config('web_host').">";
}
$subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
if (count($ids) != 0) {
- $sql="SELECT email FROM users WHERE status='A' AND user_id IN ('".implode($ids,'\',\'')."')";
- $bccres = db_query($sql);
+ $bccres = db_query_params ('SELECT email FROM users WHERE status=$1 AND user_id = ANY ($2)',
+ array ('A',
+ db_int_array_to_any_clause ($ids))) ;
}
$BCC =& implode(util_result_column_to_array($bccres),',').','.$this->Forum->getSendAllPostsTo();
$User = user_get_object($this->getPosterID());
//util_send_message('',$subject,$body,$User->getEmail(),$BCC,$this->getPosterRealName(),$extra_headers);
- util_send_message('',$subject,$body,"noreply@".$GLOBALS['sys_default_domain'],$BCC,'Forum',$extra_headers);
-// util_handle_message(array_unique($ids),$subject,$body,$this->Forum->getSendAllPostsTo(),'','forumgateway@'.$GLOBALS[sys_default_domain]);
+ util_send_message('',$subject,$body,"noreply@".forge_get_config('web_host'),$BCC,'Forum',$extra_headers);
+// util_handle_message(array_unique($ids),$subject,$body,$this->Forum->getSendAllPostsTo(),'','forumgateway@'.forge_get_config('web_host'));
return true;
}
$subject = htmlspecialchars($subject);
$body = $body;
$msg_id = $this->getID();
- $sql="UPDATE forum
- SET group_forum_id='$group_forum_id' , posted_by='$posted_by' , subject='$subject',
- body='$body', post_date='$post_date' , is_followup_to='$is_followup_to' ,
- thread_id='$thread_id',most_recent_date='$most_recent_date'
- WHERE msg_id='$msg_id'";
- $res = db_query($sql);
+ $res = db_query_params ('UPDATE forum
+ SET group_forum_id=$1, posted_by=$2, subject=$3,
+ body=$4, post_date=$5, is_followup_to=$6,
+ thread_id=$7, most_recent_date=$8
+ WHERE msg_id=$9',
+ array ($group_forum_id,
+ $posted_by,
+ $subject,
+ $body,
+ $post_date,
+ $is_followup_to,
+ $thread_id,
+ $most_recent_date,
+ $msg_id)) ;
if (!$res) {
$this->setError(db_error());
return false;
}
}
- /**
+ /**
* sendAttachNotice - contains the logic to send out email attachement followups when a message is posted.
*
* @param int attach_id - The id of the file that has been attached
$body .=
"\n\n______________________________________________________________________".
"\nYou are receiving this email because you elected to monitor this forum.".
- "\nTo stop monitoring this forum, login to ".$GLOBALS['sys_name']." and visit: ".
+ "\nTo stop monitoring this forum, login to ".forge_get_config ('forge_name')." and visit: ".
"\n".util_make_url ('/forum/monitor.php?forum_id='.$this->Forum->getID() .'&group_id='.$this->Forum->Group->getID().'&stop=1');
- $extra_headers = "Return-Path: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Errors-To: <noreply@".$GLOBALS['sys_default_domain'].">\n";
- $extra_headers .= "Sender: <noreply@".$GLOBALS['sys_default_domain'].">\n";
+ $extra_headers = "Return-Path: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Errors-To: <noreply@".forge_get_config('web_host').">\n";
+ $extra_headers .= "Sender: <noreply@".forge_get_config('web_host').">\n";
$extra_headers .= "Reply-To: ".$this->Forum->getReturnEmailAddress()."\n";
$extra_headers .= "Precedence: Bulk\n"
- ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".$GLOBALS['sys_default_domain'].">\n"
+ ."List-Id: ".$this->Forum->getName()." <forum".$this->Forum->getId()."@".forge_get_config('web_host').">\n"
."List-Help: ".util_make_url('/forum/forum.php?id='.$this->Forum->getId())."\n"
- ."Message-Id: <forumpost".$this->getId()."@".$GLOBALS['sys_default_domain'].">";
+ ."Message-Id: <forumpost".$this->getId()."@".forge_get_config('web_host').">";
$parentid = $this->getParentId();
if (!empty($parentid)) {
$extra_headers .= "\nIn-Reply-To: ".$this->Forum->getReturnEmailAddress()."\n"
- ."References: <forumpost".$this->getParentId()."@".$GLOBALS['sys_default_domain'].">";
+ ."References: <forumpost".$this->getParentId()."@".forge_get_config('web_host').">";
}
$subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
if (count($ids) != 0) {
- $sql="SELECT email FROM users WHERE status='A' AND user_id IN ('".implode($ids,'\',\'')."')";
- $bccres = db_query($sql);
+ $bccres = db_query_params ('SELECT email FROM users WHERE status=$1 AND user_id = ANY ($2)',
+ array ('A',
+ db_int_array_to_any_clause ($ids))) ;
}
$BCC =& implode(util_result_column_to_array($bccres),',').','.$this->Forum->getSendAllPostsTo();
$User = user_get_object($this->getPosterID());
- util_send_message('',$subject,$body,"noreply@".$GLOBALS['sys_default_domain'],$BCC,'Forum',$extra_headers);
+ util_send_message('',$subject,$body,"noreply@".forge_get_config('web_host'),$BCC,'Forum',$extra_headers);
return true;
}