* Copyright 1999-2000, Tim Perdue/Sourceforge
* Copyright 2002, Tim Perdue/GForge, LLC
* Copyright 2009, Roland Mas
- * Copyright 2013, Franck Villaume - TrivialDev
+ * Copyright 2013,2021-2022, Franck Villaume - TrivialDev
* Copyright 2013, French Ministry of National Education
+ * Copyright 2021, Guy Morin - French Ministry of Finances, DGFiP
*
* This file is part of FusionForge. FusionForge is free software;
* you can redistribute it and/or modify it under the terms of the
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-require_once $gfcommon.'include/Error.class.php';
+require_once $gfcommon.'include/FFError.class.php';
include_once $gfcommon.'include/TextSanitizer.class.php'; // for parsing the mail body
include_once $gfcommon.'include/User.class.php';
+include_once $gfcommon.'forum/ForumHTML.class.php';
-class ForumMessage extends Error {
+class ForumMessage extends FFError {
var $awaits_moderation;//boolean -> true if the message was inserted for approval (pending), false if not
/**
var $Forum;
/**
- * Constructor.
- *
* @param object $Forum The Forum object to which this ForumMessage is associated.
* @param bool|int $msg_id The message_id.
* @param array $arr The associative array of data.
* @param bool $pending Whether the message is a pending one.
- * @return bool success.
*/
- function ForumMessage(&$Forum, $msg_id=false, $arr=array(), $pending=false) {
- $this->Error();
+ function __construct(&$Forum, $msg_id=false, $arr=array(), $pending=false) {
+ parent::__construct();
if (!$Forum || !is_object($Forum)) {
$this->setError(_('Invalid Forum Object'));
- return false;
+ return;
}
if ($Forum->isError()) {
$this->setError('ForumMessage: '.$Forum->getErrorMessage());
- return false;
+ return;
}
$this->Forum =& $Forum;
if ($pending) {
//we are going to create the pending message to show it to the admin for moderation
if (!$this->fetchModeratedData($msg_id)) {
- return false;
+ return;
}
$this->awaits_moderation = true;
} else {
$this->awaits_moderation = false;
if (!$arr || !is_array($arr)) {
- if (!$this->fetchData($msg_id)) {
- return false;
- }
+ $this->fetchData($msg_id);
} else {
$this->data_array =& $arr;
//
if ($this->data_array['group_forum_id'] != $this->Forum->getID()) {
$this->setError(_('Group_forum_id in db result does not match Forum Object'));
$this->data_array=null;
- return false;
}
}
}
}
- return true;
}
/**
* insertmoderated - inserts the message into the table for moderation (forum_pending_messages)
*
- * @param string $subject The subject of the message.
- * @param string $body The body of the message.
- * @param int $thread_id The thread_id of the message, if known.
- * @param int $is_followup_to The message_id of the parent message, if any.
- * @param int $user_id The id of the user that is posting the message
- * @return boolean success.
+ * @param string $subject The subject of the message.
+ * @param string $body The body of the message.
+ * @param int $thread_id The thread_id of the message, if known.
+ * @param int $is_followup_to The message_id of the parent message, if any.
+ * @param int $user_id The id of the user that is posting the message
+ * @return bool success.
*/
- function insertmoderated($subject, $body, $thread_id=0, $is_followup_to=0,$user_id) {
+ function insertmoderated($subject, $body, $thread_id, $is_followup_to, $user_id) {
if (!$thread_id) {
$thread_id=$this->Forum->getNextThreadID();
$is_followup_to=0;
/**
* insertreleasedmsg - inserts the released message into the main table (forum)
*
- * @param string $group_forum_id The Forum id
+ * @param string $group_forum_id The Forum id
* @param string $subject The subject of the message.
* @param string $body The body of the message.
* @param string $post_date The post date
- * @param int $thread_id The thread_id of the message
- * @param int $is_followup_to The message_id of the parent message, if any.
- * @param int $posted_by The id of the user that is posting the message
- * @param int $has_followups has followups?
- * @param int $most_recent_date most recent date
+ * @param int $thread_id The thread_id of the message
+ * @param int $is_followup_to The message_id of the parent message, if any.
+ * @param int $posted_by The id of the user that is posting the message
+ * @param int $most_recent_date most recent date
* @return bool success.
*/
- function insertreleasedmsg($group_forum_id, $subject, $body, $post_date, $thread_id,
- $is_followup_to, $posted_by, $has_followups, $most_recent_date) {
+ function insertreleasedmsg($group_forum_id, $subject, $body, $post_date, $thread_id, $is_followup_to, $posted_by, $most_recent_date) {
if ($is_followup_to != 0) {
//was posted in reply to another thread
db_begin();
- $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)) ;
+ $is_pinned = 'f';
+ if (ForumHTML::getIsPinned($thread_id)) {
+ $is_pinned = 't';
+ }
+ $result = db_query_params('INSERT INTO forum (group_forum_id,posted_by,subject,body,post_date,is_followup_to,thread_id,most_recent_date,is_pinned) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)',
+ array($group_forum_id,
+ $posted_by,
+ htmlspecialchars($subject),
+ $body,
+ $post_date,
+ $is_followup_to,
+ $thread_id,
+ $most_recent_date,
+ $is_pinned));
if (!$result || db_affected_rows($result) < 1) {
$this->setError(_('Posting Failed').' '.db_error());
/**
* insertmsg - inserts the message into the main table (forum)
*
- * @param string $subject The subject of the message.
- * @param string $body The body of the message.
- * @param int $thread_id The thread_id of the message, if known.
- * @param int $is_followup_to The message_id of the parent message, if any.
- * @param int $user_id The id of the user that is posting the message
- * @param bool $has_attach Whether the message has an attach associated. Defaults to false
- * @param int $timestamp The timestamp of the message to insert, defaults to 0.
- * @return boolean success.
+ * @param string $subject The subject of the message.
+ * @param string $body The body of the message.
+ * @param int $thread_id The thread_id of the message, if known.
+ * @param int $is_followup_to The message_id of the parent message, if any.
+ * @param int $user_id The id of the user that is posting the message
+ * @param bool $has_attach Whether the message has an attach associated. Defaults to false
+ * @param int $timestamp The timestamp of the message to insert, defaults to 0.
+ * @return bool success.
*/
- function insertmsg($subject, $body, $thread_id=0, $is_followup_to=0,
- $user_id, $has_attach=false, $timestamp=0) {
+ function insertmsg($subject, $body, $thread_id, $is_followup_to, $user_id, $has_attach = false, $timestamp = 0) {
if ($timestamp == 0){
$timestamp = time();
}
}
}
- $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,
- $timestamp,
- $is_followup_to,
- $thread_id,
- $timestamp)) ;
+ $is_pinned = 'f';
+ if(ForumHTML::getIsPinned($thread_id)) {
+ $is_pinned = 't';
+ }
+ $result = db_query_params('INSERT INTO forum (group_forum_id,posted_by,subject,body,post_date,is_followup_to,thread_id,most_recent_date, is_pinned) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)',
+ array($this->Forum->getID(),
+ $user_id,
+ htmlspecialchars($subject),
+ $body,
+ $timestamp,
+ $is_followup_to,
+ $thread_id,
+ $timestamp,
+ $is_pinned));
if (!$result || db_affected_rows($result) < 1) {
$this->setError(_('Posting Failed').' '.db_error());
db_rollback();
db_rollback();
return false;
}
-//echo "Committing";
db_commit();
-//echo "db_error()".db_error();
$this->awaits_moderation = false;
return true;
}
/**
* create - use this function to create a new message in the database.
*
- * @param string $subject The subject of the message.
- * @param string $body The body of the message.
- * @param int $thread_id The thread_id of the message, if known.
- * @param int $is_followup_to The message_id of the parent message, if any.
- * @param bool $has_attach Whether the message has an attach associated. Defaults to false
- * @param int $timestamp The timestamp of the message to create. Defaults to 0, meaning the timestamp used for this message will be "time()"
- * @return boolean success.
+ * @param string $subject The subject of the message.
+ * @param string $body The body of the message.
+ * @param int $thread_id The thread_id of the message, if known.
+ * @param int $is_followup_to The message_id of the parent message, if any.
+ * @param bool $has_attach Whether the message has an attach associated. Defaults to false
+ * @param int $timestamp The timestamp of the message to create. Defaults to 0, meaning the timestamp used for this message will be "time()"
+ * @return bool success.
*/
function create($subject, $body, $thread_id=0, $is_followup_to=0, $has_attach=false, $timestamp = 0) {
if (!strlen(trim($body)) || !strlen(trim($subject))) {
/**
* fetchData - re-fetch the data for this forum_message from the database.
*
- * @param int $msg_id The message ID.
- * @return boolean success.
+ * @param int $msg_id The message ID.
+ * @return bool success.
*/
function fetchData($msg_id) {
$res = db_query_params ('SELECT * FROM forum_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
/**
* fetchModeratedData - re-fetch the data for this forum_message from the database, for pending messages
*
- * @param int The message ID.
- * @return boolean success.
+ * @param int The message ID.
+ * @return bool success.
*/
function fetchModeratedData($msg_id) {
$res = db_query_params ('SELECT * FROM forum_pending_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
/**
* hasFollowups - whether this message has any followups.
*
- * @return boolean has_followups.
+ * @return bool has_followups.
*/
function hasFollowups() {
return $this->data_array['has_followups'];
/**
* hasAttach - whether this message has an attachment.
*
- * @return boolean has_attach.
+ * @return bool has_attach.
*/
function hasAttach() {
if ($this->isPending()) {
$msg = new ForumMessage($this->Forum,db_result($result,$i,'msg_id'));
$count += $msg->delete();
}
- $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));
+ $res_pa = db_query_params('SELECT attachmentid FROM forum_attachment WHERE msg_id=$1',
+ array($msg_id));
+ while ($pa = db_fetch_array($res_pa)) {
+ ForumStorage::instance()->delete($pa['attachmentid']);
+ db_query_params('DELETE FROM forum_attachment WHERE attachmentid=$1',
+ array($pa['attachmentid']));
+ }
+ ForumStorage::instance()->commit();
+
+ db_query_params('DELETE FROM forum WHERE msg_id=$1 AND group_forum_id=$2',
+ array ($msg_id, $this->Forum->getID()));
return $count;
}
* @return string converted text
*/
function removebbcode($text) {
- //$replaced = preg_replace("/\[[_a-zA-Z]:.+\](.+)\[\/[_a-zA-Z]:.*\]/","$1",$text);
- $replaced = preg_replace("/\[.+\](.+)\[\/.+\]/","$1",$text);
- return $replaced;
+ return preg_replace("/\[.+\](.+)\[\/.+\]/","$1",$text);
}
/**
* sendNotice - contains the logic to send out email followups when a message is posted.
*
- * @param boolean $has_attach Whether the message has an attach associated. Defaults to false
- * @return boolean success.
+ * @param bool $has_attach Whether the message has an attach associated. Defaults to false
+ * @return bool success.
*/
function sendNotice($has_attach=false) {
$ids = $this->Forum->getMonitoringIDs();
}
}
- if (count ($recipients) == 0) {
+ if (empty($recipients)) {
return true ;
}
foreach ($recipients as $recipient) {
- if ($recipient instanceof GFUser) {
+ if ($recipient instanceof FFUser) {
setup_gettext_for_user ($recipient) ;
$dest_email = $recipient->getEmail ();
} else {
$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();
+ ."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').">";
+ ."References: <forumpost".$this->getParentID()."@".forge_get_config('web_host').">";
}
$subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
/**
* sendNewModeratedMsgNotice - contains the logic to send out email notifications to the forum admins when a new moderated message is posted
*
- * @return boolean success.
+ * @return bool success.
*/
function sendNewModeratedMsgNotice() {
$ids = array();
$text = $this->getBody();
$sanitizer = new TextSanitizer();
$text = $sanitizer->convertNeededTagsForEmail($text);
- $text= strip_tags($this->removebbcode(util_line_wrap($text)));
+ $text = strip_tags($this->removebbcode(util_line_wrap($text)));
$text = $sanitizer->convertExtendedCharsForEmail($text);
$body .= $text .
"\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().'@'.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()."@".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();
+ ."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').">";
+ ."References: <forumpost".$this->getParentID()."@".forge_get_config('web_host').">";
}
$subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
- if (count($ids) != 0) {
+ if (!empty($ids)) {
$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);
+ $BCC = implode(',', util_result_column_to_array($bccres)).','.$this->Forum->getSendAllPostsTo();
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;
}
* @param string $post_date The post date
* @param int $is_followup_to The message_id of the parent message, if any.
* @param int $thread_id The thread_id of the message, if known.
- * @param int $has_followups has followups?
* @param string $most_recent_date The most recent date.
- * @return boolean success.
+ * @return bool success.
*/
- function updatemsg($group_forum_id, $posted_by, $subject, $body,
- $post_date, $is_followup_to, $thread_id, $has_followups, $most_recent_date) {
+ function updatemsg($group_forum_id, $posted_by, $subject, $body, $post_date, $is_followup_to, $thread_id, $most_recent_date) {
if (!strlen(trim($body)) || !strlen(trim($subject))) {
- $this->setError(_('Error: a forum message must include a message body and a subject.'));
+ $this->setError(_('Error')._(': ')._('a forum message must include a message body and a subject.'));
return false;
}
$subject = htmlspecialchars($subject);
* 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
- * @return boolean success.
+ * @return bool success.
*/
function sendAttachNotice($attach_id) {
if ($attach_id) {
$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();
+ ."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').">";
+ ."References: <forumpost".$this->getParentID()."@".forge_get_config('web_host').">";
}
$subject="[" . $this->Forum->getUnixName() ."][".$this->getID()."] ".util_unconvert_htmlspecialchars($this->getSubject());
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());
+ $BCC = implode(',', util_result_column_to_array($bccres)).','.$this->Forum->getSendAllPostsTo();
util_send_message('',$subject,$body,"noreply@".forge_get_config('web_host'),$BCC,'Forum',$extra_headers);
return true;
}
return false;
}
}
-
-// Local Variables:
-// mode: php
-// c-file-style: "bsd"
-// End: