* 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
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 FFError {
} else {
$this->awaits_moderation = false;
if (!$arr || !is_array($arr)) {
- if (!$this->fetchData($msg_id)) {
- return;
- }
+ $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;
}
}
}
/**
* 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()) {
* @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 ;
}
/**
* 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();
"\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";
}
$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();
+ $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) {
array ('A',
db_int_array_to_any_clause ($ids))) ;
}
- $BCC = implode(util_result_column_to_array($bccres),',').','.$this->Forum->getSendAllPostsTo();
+ $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: