[Fusionforge-commits] FusionForge branch master updated. e16d9708ceeaf051c37d2db5f8bf51d5fda52ef5

Franck Villaume nerville at fusionforge.org
Thu Jul 10 17:52:27 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  e16d9708ceeaf051c37d2db5f8bf51d5fda52ef5 (commit)
      from  db0a68e8d05c8658a3620fc55be14dbbe630ee18 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e16d9708ceeaf051c37d2db5f8bf51d5fda52ef5
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Thu Jul 10 17:48:53 2014 +0200

    implement [#662] Forum: store the attached file on FS. And a lot of code style cleanup

diff --git a/src/CHANGES b/src/CHANGES
index f4a26ed..a93522a 100644
--- a/src/CHANGES
+++ b/src/CHANGES
@@ -9,6 +9,8 @@ Fusionforge-X.X:
 * [#669] General: feedback, error_msg, warning_msg are now store in cookie. (TrivialDev)
 * Plugin scmhook: Update git post-receive eMail hook (tarent solutions GmbH, Teckids e.V.)
 * [#684] Widget Public Area: display FRS link (TrivialDev)
+* [#655] Tracker: enable support for multi-select extrafield in roadmap (TrivialDev)
+* [#662] Forum: store the attached file on FS. (TrivialDev)
 
 Fusionforge-5.3.2:
 * Software map: fix "value too long for type character varying(255)" error in cron db_trove_maint.php (Inria)
diff --git a/src/common/forum/AttachManager.class.php b/src/common/forum/AttachManager.class.php
index aadc2b8..cbb9bd0 100644
--- a/src/common/forum/AttachManager.class.php
+++ b/src/common/forum/AttachManager.class.php
@@ -1,11 +1,12 @@
 <?php
-
 /**
  * FusionForge Attachment manager class
  *
  * Copyright 1999-2001 (c) VA Linux Systems
  * The rest Copyright 2002-2005 (c) GForge Team
+ * Copyright 2005, Daniel Perez
  * Copyright (C) 2010-2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2014, Franck Villaume - TrivialDev
  * http://fusionforge.org/
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -24,9 +25,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/*
-	by Daniel Perez - 2005
-*/
+require_once $gfcommon.'forum/ForumStorage.class.php';
 
 class AttachManager extends Error {
 
@@ -55,19 +54,19 @@ class AttachManager extends Error {
 	}
 
 	/**
-	* Function SetForumMsg
-	*
-	* Sets the forum message associated with the attachment
-	*/
+	 * Function SetForumMsg
+	 *
+	 * Sets the forum message associated with the attachment
+	 */
 	function SetForumMsg(&$ForumMsg) {
 		$this->ForumMsg =& $ForumMsg;
 	}
 
 	/**
-	* Function GetAttachId
-	*
-	* Returns the attach id for the message id passed as a parameter or false if error
-	*/
+	 * Function GetAttachId
+	 *
+	 * Returns the attach id for the message id passed as a parameter or false if error
+	 */
 	function GetAttachId($msg_id) {
 		$res = db_query_params ('SELECT attachmentid FROM forum_attachment WHERE msg_id=$1',
 			array ($msg_id));
@@ -79,11 +78,11 @@ class AttachManager extends Error {
 	}
 
 	/**
-	* Function PrintHelperFunctions
-	*
-	*
-	* @return 	string	returns the javascript helper functions
-	*/
+	 * Function PrintHelperFunctions
+	 *
+	 *
+	 * @return	string	returns the javascript helper functions
+	 */
 
 	function PrintHelperFunctions() {
 		return '<script type="text/javascript">/* <![CDATA[ */
@@ -104,25 +103,25 @@ class AttachManager extends Error {
 		/* ]]> */</script>';
 	}
 
-	 /**
-	 * Function PrintAttachLink
+	/**
+	 * PrintAttachLink - return the HTML code for attachment management
 	 *
-	 * @param 	object	$msg		The message.
-	 * @param 	int		$group_id	The group id.
-	 * @param 	int		$forum_id	The forum id.
+	 * @param	object	$msg		The message.
+	 * @param	int	$group_id	The group id.
+	 * @param	int	$forum_id	The forum id.
 	 *
-	 * @return 	string	returns link to attachment /delete if corresponding; else returns a message about no attachment found
+	 * @return	string	returns link to attachment /delete if corresponding; else returns a message about no attachment found
 	 */
-	function PrintAttachLink(&$msg,$group_id,$forum_id) {
+	function PrintAttachLink(&$msg, $group_id, $forum_id) {
 
 		//ask if the message has an attachment
 		$msg_id = $msg->getID();
 		if ($msg->isPending()) {
-			$res = db_query_params ('SELECT attachmentid,filename,userid,counter FROM forum_pending_attachment where msg_id=$1',
+			$res = db_query_params('SELECT attachmentid,filename,userid,counter FROM forum_pending_attachment where msg_id=$1',
 						array ($msg_id));
 			$pend = "&pending=yes";
 		} else {
-			$res = db_query_params ('SELECT attachmentid,filename,userid,counter FROM forum_attachment where msg_id=$1',
+			$res = db_query_params('SELECT attachmentid,filename,userid,counter FROM forum_attachment where msg_id=$1',
 						array ($msg_id));
 			$pend = "";
 		}
@@ -148,7 +147,7 @@ class AttachManager extends Error {
 					$attach .= "     <a href=\"javascript:manageattachments('/forum/attachment.php?attachid=$attachid&group_id=$group_id&forum_id=$forum_id&delete=yes','yes');\">" .  "<font size=\"-3\">" .  html_image('ic/forum_delete.gif','16','18',array('alt'=>_("Delete"))) . "</font></a>";
 				}
 			}
-		}	else {
+		} else {
 			//add attach for existing message
 			$f = $msg->getForum();
 			if (!$f || !is_object($f)) {
@@ -168,9 +167,17 @@ class AttachManager extends Error {
 	}
 
 	/**
-	 * Function AddToDBOnly : DB Query Only - used for releasing pending messages
-	 *
+	 * AddToDBOnly - DB Query Only - used for releasing pending messages
 	 *
+	 * @param	int	$userid
+	 * @param	string	$dateline	time format string
+	 * @param	string	$filename
+	 * @param	string	$filedata	path to the file
+	 * @param	int	$filesize
+	 * @param	int	$visible
+	 * @param	string	$filehash	md5 of the content of the file
+	 * @param	string	$mimetype	mimetype of the file
+	 * @return	bool	true / false on success
 	 */
 	function AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype) {
 		$result=db_query_params ('SELECT max(msg_id) AS id FROM forum',
@@ -178,22 +185,40 @@ class AttachManager extends Error {
 		if (!$result || db_numrows($result) < 1) {
 			$this->messages[] = _('Could not get message id');
 		} else {
-			$this->msg_id = db_result($result,0,0);
-			if (db_query_params ('INSERT INTO forum_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
-					VALUES
-					( $1 , $2, $3,
-					$4, $5, $6, $7,  $8, $9)',
-			array ($userid,
-				$dateline ,
-				$filename ,
-				$filedata ,
-				$filesize,
-				$visible,
-				$this->msg_id,
-				$filehash ,
-				$mimetype  ))) {
-				$this->messages[] = _('File uploaded');
-			}	else {
+			$this->msg_id = db_result($result, 0, 0);
+			$res = db_query_params('INSERT INTO forum_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
+						VALUES ($1 , $2, $3, $4, $5, $6, $7, $8, $9)',
+						array ($userid,
+							$dateline,
+							$filename,
+							0,
+							$filesize,
+							$visible,
+							$this->msg_id,
+							$filehash,
+							$mimetype));
+			if ($res) {
+				if ($filesize) {
+					if (is_file($filedata)) {
+						$id = db_insertid($res, 'forum_attachment', 'attachmentid');
+						if (ForumStorage::instance()->store($id, $filedata)) {
+							$this->messages[] = _('File uploaded');
+							return true;
+						} else {
+							ForumStorage::instance()->rollback();
+							db_rollback();
+							$this->setError(ForumStorage::instance()->getErrorMessage());
+							$this->messages[] = _('File not uploaded');
+							return false;
+						}
+					} else {
+						$this->setError(_('Error Adding Attachment')._(': ')._('Not a file').' '.$filename);
+						$this->messages[] = _('File not uploaded');
+						db_rollback();
+						return false;
+					}
+				}
+			} else {
 				$this->messages[] = _('File not uploaded');
 				$this->setError();
 			}
@@ -201,17 +226,17 @@ class AttachManager extends Error {
 	}
 
 	/**
-	 * Function attach : saves the file in the DB
+	 * attach - saves the file in the DB
 	 *
-	 * @param 	int		$attach		The file to attach
-	 * @param 	int		$group_id	The group.
-	 * @param 	int		$update		Whether we are updating an existing attach (attachid to update or zero for new message (inserts using the hights msg id from forum table)
-	 * @param 	int		$msg_id		msg id. if update is 0 and we pass a msg_id <> 0, then we are adding an attach for an existing msg
+	 * @param	int	$attach		The file to attach
+	 * @param	int	$group_id	The group.
+	 * @param	int	$update		Whether we are updating an existing attach (attachid to update or zero for new message (inserts using the hights msg id from forum table)
+	 * @param	int	$msg_id		msg id. if update is 0 and we pass a msg_id <> 0, then we are adding an attach for an existing msg
 	 *
-	 * @return	int	    Attach id on success, false otherwise
+	 * @return	int	Attach id on success, false otherwise
 	 *
 	 */
-	function attach($attach,$group_id,$update=0,$msg_id=0) {
+	function attach($attach, $group_id, $update = 0, $msg_id = 0) {
 		global $_FILES;
 
 		$attachment = trim($attach['tmp_name']);
@@ -219,16 +244,14 @@ class AttachManager extends Error {
 		$attachment_size = trim($attach['size']);
 		$attachment_type = trim($attach['type']);
 
-		if ($attachment == 'none' OR empty($attachment) OR empty($attachment_name))
-		{
+		if ($attachment == 'none' OR empty($attachment) OR empty($attachment_name)) {
 			return false; //no point in continuing if there's no file
 		}
 
 		$attachment_name2 = strtolower($attachment_name);
 		$extension = substr(strrchr($attachment_name2, '.'), 1);
 
-		if ($extension == 'exe')
-		{
+		if ($extension == 'exe') {
 			// invalid extension
 			$this->messages[] = _('Invalid Extension');
 
@@ -236,15 +259,14 @@ class AttachManager extends Error {
 			return false;
 		}
 
-		if (!is_uploaded_file($attachment) || !($filestuff = @file_get_contents($attachment)) )
-		{
+		if (!is_uploaded_file($attachment) || !($filestuff = @file_get_contents($attachment)) ) {
 			$this->messages[] = _('Error, problem with the attachment file uploaded into the server');
 			return false;
 		}
 
 		if (!session_loggedin()) {
 			$user_id = 100;
-		}	else {
+		} else {
 			$user_id = user_getid();
 		}
 
@@ -259,8 +281,8 @@ class AttachManager extends Error {
 				if ($msg_id!=0) {
 					$this->msg_id = $msg_id;
 				} else {
-					$result=db_query_params ('SELECT max(msg_id) AS id FROM forum_pending_messages',
-			array());
+					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_pending_messages',
+								array());
 					if (!$result || db_numrows($result) < 1) {
 						$this->messages[] = _('Could not get message id');
 						@unlink($attachment);
@@ -269,54 +291,90 @@ class AttachManager extends Error {
 						$this->msg_id = db_result($result,0,0);
 					}
 				}
-				$res = db_query_params ('INSERT INTO forum_pending_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
-					VALUES
-					( $1 , $2, $3,
-					$4, $5, 1, $6,  $7, $8)',
-			array ($user_id,
-				time() ,
-				$attachment_name,
-				base64_encode($filestuff) ,
-				$attachment_size,
-				$this->msg_id,
-				md5($filestuff),
-				$attachment_type));
+				db_begin();
+				$res = db_query_params('INSERT INTO forum_pending_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
+							VALUES ($1 , $2, $3, $4, $5, 1, $6,  $7, $8)',
+							array ($user_id,
+								time() ,
+								$attachment_name,
+								0,
+								$attachment_size,
+								$this->msg_id,
+								md5($filestuff),
+								$attachment_type));
 				if ($res) {
-					$this->messages[] = _('File uploaded');
-					$id = db_insertid($res,'forum_pending_attachment','attachmentid');
-				}	else {
+					if ($attachment_size) {
+						if (is_file($attachment)) {
+							$id = db_insertid($res,'forum_pending_attachment','attachmentid');
+							if (ForumStorage::instance()->store($this->$id, $attachment)) {
+								$this->messages[] = _('File uploaded');
+								db_commit();
+								return true;
+							} else {
+								ForumStorage::instance()->rollback();
+								db_rollback();
+								$this->setError(ForumStorage::instance()->getErrorMessage());
+								$this->messages[] = _('File not uploaded');
+								return false;
+							}
+						} else {
+							$this->setError(_('Error Adding Attachment')._(': ')._('Not a file').' '.$attachment_name);
+							$this->messages[] = _('File not uploaded');
+							db_rollback();
+							return false;
+						}
+					}
+					$this->messages[] = _('File not uploaded');
+				} else {
 					$this->messages[] = _('File not uploaded');
 				}
 			}
 		} else {
 			if ($update) {
 				//update the fileinfo
-				if (db_query_params ('UPDATE forum_attachment SET dateline = $1 , filedata = $2 ,
-				 filename = $3 ,
-				 filehash = $4 ,
-				 mimetype = $5 ,
-				 counter = 0 ,
-				 filesize = $6 where attachmentid=$7',
-			array (time() ,
-				base64_encode($filestuff) ,
-				$attachment_name,
-				md5($filestuff),
-				$attachment_type,
-				$attachment_size ,
-				$update))) {
+				db_begin();
+				if (db_query_params('UPDATE forum_attachment SET dateline = $1 , filedata = $2 ,
+							filename = $3 ,
+							filehash = $4 ,
+							mimetype = $5 ,
+							counter = 0 ,
+							filesize = $6 where attachmentid=$7',
+							array (time(),
+								0,
+								$attachment_name,
+								md5($filestuff),
+								$attachment_type,
+								$attachment_size ,
+								$update))) {
+					if ($attachment_size) {
+						if (is_file($attachment)) {
+							ForumStorage::instance()->delete($update)->commit();
+							ForumStorage::instance()->store($update, $attachment);
+							$this->messages[] = _('File uploaded');
+							$this->messages[] = _('File Updated Successfully');
+							db_commit();
+							return true;
+						} else {
+							$this->setError(_('Error Adding Attachment')._(': ')._('Not a file').' '.$attachment_name);
+							$this->messages[] = _('File not uploaded');
+							db_rollback();
+							return false;
+						}
+					}
 					$this->messages[] = _('File uploaded');
-					$this->messages[] = _('File Updated Successfully');
 					$id = $update;
-				}	else {
+					db_commit();
+				} else {
+					db_rollback();
 					$this->messages[] = _('File not uploaded');
 				}
 			} else {
 				// add to db
-				if ($msg_id!=0) {
+				if ($msg_id != 0) {
 					$this->msg_id = $msg_id;
 				} else {
-					$result=db_query_params ('SELECT max(msg_id) AS id FROM forum_pending_messages',
-			array());
+					$result = db_query_params('SELECT max(msg_id) AS id FROM forum_pending_messages',
+								array());
 					if (!$result || db_numrows($result) < 1) {
 						$this->messages[] = _('Could not get message id');
 						@unlink($attachment);
@@ -325,24 +383,42 @@ class AttachManager extends Error {
 						$this->msg_id = db_result($result,0,0);
 					}
 				}
-				$res = db_query_params ('INSERT INTO forum_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
-					VALUES
-					( $1 , $2, $3,
-					$4, $5, 1, $6,  $7, $8)',
-			array ($user_id,
-				time() ,
-				$attachment_name,
-				base64_encode($filestuff) ,
-				$attachment_size,
-				$this->msg_id,
-				md5($filestuff),
-				$attachment_type));
+				db_begin();
+				$res = db_query_params('INSERT INTO forum_attachment (userid, dateline, filename, filedata, filesize, visible, msg_id , filehash, mimetype)
+							VALUES ($1 , $2, $3, $4, $5, 1, $6,  $7, $8)',
+							array ($user_id,
+								time() ,
+								$attachment_name,
+								0,
+								$attachment_size,
+								$this->msg_id,
+								md5($filestuff),
+								$attachment_type));
 				if ($res) {
-					$this->messages[] = _('File uploaded');
-					$id = db_insertid($res,'forum_attachment','attachmentid');
-				}	else {
-					$this->messages[] = _('File not uploaded');
+					if ($attachment_size) {
+						if (is_file($attachment)) {
+							$id = db_insertid($res, 'forum_attachment', 'attachmentid');
+							if (ForumStorage::instance()->store($id, $attachment)) {
+								$this->messages[] = _('File uploaded');
+								db_commit();
+								return true;
+							} else {
+								ForumStorage::instance()->rollback();
+								db_rollback();
+								$this->setError(ForumStorage::instance()->getErrorMessage());
+								$this->messages[] = _('File not uploaded');
+								return false;
+							}
+						} else {
+							$this->setError(_('Error Adding Attachment')._(': ')._('Not a file').' '.$attachment_name);
+							$this->messages[] = _('File not uploaded');
+							db_rollback();
+							return false;
+						}
+					}
 				}
+				db_rollback();
+				$this->messages[] = _('File not uploaded');
 			}
 		}
 		@unlink($attachment);
diff --git a/src/common/forum/ForumAdmin.class.php b/src/common/forum/ForumAdmin.class.php
index 91e9248..fd92684 100644
--- a/src/common/forum/ForumAdmin.class.php
+++ b/src/common/forum/ForumAdmin.class.php
@@ -7,6 +7,7 @@
  * Copyright 2005 (c) Daniel Perez
  * Copyright 2010 (c) Franck Villaume - Capgemini
  * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2014, Franck Villaume - TrivialDev
  * http://fusionforge.org/
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -37,24 +38,22 @@ class ForumAdmin extends Error {
 			$this->g = group_get_object($group_id);
 			$this->p =& $this->g->getPermission();
 			if (!$this->g->usesForum()) {
-				$this->setError(sprintf(_('%s does not use the Forum tool.'),
-				    $this->g->getPublicName()));
+				$this->setError(sprintf(_('%s does not use the Forum tool.'), $this->g->getPublicName()));
 				return;
 			}
 		}
 	}
 
 	/**
-	 *  PrintAdminMessageOptions - prints the different administrator options for a message
+	 * PrintAdminMessageOptions - prints the different administrator options for a message
 	 *
-	 *	@param   int	$msg_id		The Message ID
-	 *	@param   int	$group_id	The Project ID
-	 *	@param   int	$thread_id	The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
-	 *	@param   int	$forum_id	The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
-	 *	@param	 int	$return_to_message
-	 *	@return  string	The HTML output
+	 * @param	int	$msg_id		The Message ID
+	 * @param	int	$group_id	The Project ID
+	 * @param	int	$thread_id	The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
+	 * @param	int	$forum_id	The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
+	 * @param	int	$return_to_message
+	 * @return	string	The HTML output
 	 */
-
 	function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
 
 		$return = util_make_link('/forum/admin/?movethread='.$thread_id.'&msg_id='.$msg_id.'&group_id='.$group_id.'&forum_id='.$forum_id.'&return_to_message='.$return_to_message, html_image('ic/forum_move.gif', '37', '15', array('alt' => _('Move Thread'))));
@@ -71,47 +70,44 @@ class ForumAdmin extends Error {
 	}
 
 	/**
-	 *  PrintAdminOptions - prints the different administrator option for the forums (heading).
+	 * PrintAdminOptions - prints the different administrator option for the forums (heading).
 	 *
 	 */
-
 	function PrintAdminOptions() {
 		global $group_id, $forum_id;
-
-		echo '<p>'.util_make_link('/forum/admin/?group_id='.$group_id.'&add_forum=1', _('Add Forum'));
-		echo ' | '.util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$group_id, _('Manage Pending Messages')).'<br /></p>';
+		echo html_e('p', array(), util_make_link('/forum/admin/?group_id='.$group_id.'&add_forum=1', _('Add Forum')).
+			' | '.util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$group_id, _('Manage Pending Messages')).'<br />');
 	}
 
 	/**
-	 *  PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
+	 * PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
 	 *
-	 *	@param 	int		$forum_id	The Forum ID.
+	 * @param	int	$forum_id	The Forum ID.
 	 */
-
 	function PrintAdminPendingOption($forum_id) {
-		echo '<p>'.util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$this->group_id.'&forum_id='.$forum_id, _('Manage Pending Messages')).'<br /></p>';
+		echo html_e('p', array(), util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$this->group_id.'&forum_id='.$forum_id, _('Manage Pending Messages')).'<br />');
 	}
 
 	/**
-	 *  GetPermission - Gets the permission for the user
+	 * GetPermission - Gets the permission for the user
 	 *
-	 *  @return  object	 The permission
+	 * @return	object	 The permission
 	 */
 	function &GetPermission() {
 		return $this->p;
 	}
 
 	/**
-	 *  GetGroupObject - Gets the group object of the forum
+	 * GetGroupObject - Gets the group object of the forum
 	 *
-	 *  @return  object	 The group obj
+	 * @return	object	 The group obj
 	 */
 	function &GetGroupObject() {
 		return $this->g;
 	}
 
 	/**
-	 *  isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
+	 * isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
 	 *
 	 */
 	function isGroupAdmin() {
@@ -119,12 +115,11 @@ class ForumAdmin extends Error {
 	}
 
 	/**
-	 *  Authorized - authorizes and returns true if the user is authorized for the group, or false.
+	 * Authorized - authorizes and returns true if the user is authorized for the group, or false.
 	 *
-	 *  @param  string	 $group_id	The group id.
-	 *	@return bool
+	 * @param	string	 $group_id	The group id.
+	 * @return	bool
 	 */
-
 	function Authorized($group_id) {
 		if (!$group_id) {
 			$this->setGroupIdError();
@@ -149,15 +144,15 @@ class ForumAdmin extends Error {
 	}
 
 	/**
-	 *  ExecuteAction - Executes the action passed as parameter
+	 * ExecuteAction - Executes the action passed as parameter
 	 *
-	 *  @param  string	 $action	action to execute.
-	 *	@return string
+	 * @param	string	 $action	action to execute.
+	 * @return	string
 	 */
-	function ExecuteAction ($action) {
+	function ExecuteAction($action) {
 		global $HTML;
 
-		$feedback='';
+		$feedback = '';
 		if ($action == "change_status") { //change a forum
 			$forum_name = getStringFromRequest('forum_name');
 			$description = getStringFromRequest('description');
@@ -166,14 +161,14 @@ class ForumAdmin extends Error {
 			/*
 				Change a forum
 			*/
-			$f=new Forum($this->g,$group_forum_id);
+			$f = new Forum($this->g, $group_forum_id);
 			if (!$f || !is_object($f)) {
-				exit_error(_('Error getting Forum'),'forums');
+				exit_error(_('Error getting Forum'), 'forums');
 			} elseif ($f->isError()) {
-				exit_error($f->getErrorMessage(),'forums');
+				exit_error($f->getErrorMessage(), 'forums');
 			}
 
-			session_require_perm ('forum_admin', $f->Group->getID()) ;
+			session_require_perm('forum_admin', $f->Group->getID());
 
 			if (!$f->update($forum_name,$description,$send_all_posts_to)) {
 				exit_error($f->getErrorMessage(),'forums');
@@ -298,13 +293,13 @@ class ForumAdmin extends Error {
 					return false;
 				}
 			}
-			/* ]]> */</script>
-			<form name="pending" action="'.util_make_uri('forum/admin/pending.php').'" method="post">
+			/* ]]> */</script>';
+			echo $HTML->openForm(array('name' => 'pending', 'action' => util_make_uri('forum/admin/pending.php'), 'method' => 'post'));
+			echo '
 			<input type="hidden" name="action" value="update_pending" />
 			<input type="hidden" name="form_key" value="' . form_generate_key() . '" />
 			<input type="hidden" name="group_id" value="' . getIntFromRequest("group_id") . '" />
 			<input type="hidden" name="forum_id" value="' . $forum_id . '" />
-
 			';
 
 			echo html_build_select_box_from_assoc($moderated_forums,'forum_id',$forum_id);
@@ -315,7 +310,7 @@ class ForumAdmin extends Error {
 			$title[] = _('Message');
 			$title[] = "Action";
 
-			$res = db_query_params ('SELECT msg_id,subject,pm.group_forum_id,gl.forum_name FROM forum_pending_messages pm, forum_group_list gl WHERE pm.group_forum_id=$1 AND pm.group_forum_id=gl.group_forum_id AND gl.group_forum_id=$2',
+			$res = db_query_params('SELECT msg_id,subject,pm.group_forum_id,gl.forum_name FROM forum_pending_messages pm, forum_group_list gl WHERE pm.group_forum_id=$1 AND pm.group_forum_id=gl.group_forum_id AND gl.group_forum_id=$2',
 			array ($forum_id,
 				$forum_id));
 			if (!$res) {
@@ -336,10 +331,6 @@ class ForumAdmin extends Error {
 			$i = 2;
 			echo $HTML->listTableTop($title);
 			while ($onemsg = db_fetch_array($res)) {
-
-				//$url = 'pendingmsgdetail.php?msg_id=' . $onemsg[msg_id];
-				//<a href=\"javascript:msgdetail('$url');\">$onemsg[subject]</a>
-				$url = "http://www.google.com";
 				echo "
 				<tr " . $HTML->boxGetAltRowStyle($i++). ">
 					<td>$onemsg[forum_name]</td>
@@ -352,8 +343,8 @@ class ForumAdmin extends Error {
 			echo '
 			<input type="hidden" name="msgids" value="' . $ids . '" />
 			<p class="align-right"><input type="submit" onclick="return confirmDel();" name="update" value="' . _('Update') . '" /></p>
-			</form>
 			';
+			echo $HTML->closeForm();
 		}
 		if ($action == "update_pending") {
 			$group_id = getIntFromRequest("group_id");
@@ -379,13 +370,13 @@ class ForumAdmin extends Error {
 						//delete
 						db_begin();
 						if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
-			array ($msgids[$i]))) {
+									array ($msgids[$i]))) {
 							$error_msg .= "DB Error: ". db_error();
 							db_rollback();
 							break;
 						}
-						if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
-			array ($msgids[$i]))) {
+						if (!db_query_params('DELETE FROM forum_pending_messages WHERE msg_id=$1',
+									array ($msgids[$i]))) {
 							$error_msg .= "DB Error: ". db_error();
 							db_rollback();
 							break;
@@ -397,13 +388,13 @@ class ForumAdmin extends Error {
 					case 3 : {
 						//release
 						$res1 = db_query_params ('SELECT * FROM forum_pending_messages WHERE msg_id=$1',
-			array ($msgids[$i]));
+									array ($msgids[$i]));
 						if (!$res1) {
 							$error_msg .= "DB Error " . db_error() . "<br />";
 							break;
 						}
 						$res2 = db_query_params ('SELECT * FROM forum_pending_attachment WHERE msg_id=$1',
-			array ($msgids[$i]));
+									array ($msgids[$i]));
 						if (!$res2) {
 							$error_msg .= "DB Error " . db_error() . "<br />";
 							break;
@@ -484,13 +475,13 @@ class ForumAdmin extends Error {
 							//delete the message and attach
 							db_begin();
 							if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
-			array ($msgids[$i]))) {
+										array ($msgids[$i]))) {
 								$error_msg .= "DB Error: ". db_error();
 								db_rollback();
 								break;
 							}
 							if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
-			array ($msgids[$i]))) {
+										array ($msgids[$i]))) {
 								$error_msg .= "DB Error: ". db_error();
 								db_rollback();
 								break;
diff --git a/src/common/forum/ForumFactory.class.php b/src/common/forum/ForumFactory.class.php
index dddba3c..469d6c2 100644
--- a/src/common/forum/ForumFactory.class.php
+++ b/src/common/forum/ForumFactory.class.php
@@ -76,12 +76,12 @@ class ForumFactory extends Error {
 	function &getAllForumIds() {
 		$result = array () ;
 		$res = db_query_params('SELECT group_forum_id FROM forum_group_list
-WHERE group_forum_id NOT IN (
-	SELECT group_forum_id FROM forum_group_list WHERE group_forum_id IN (
-		SELECT forum_id FROM news_bytes))
-AND group_id=$1
-ORDER BY group_forum_id',
-			array ($this->Group->getID()));
+					WHERE group_forum_id NOT IN (
+						SELECT group_forum_id FROM forum_group_list WHERE group_forum_id IN (
+							SELECT forum_id FROM news_bytes))
+					AND group_id=$1
+					ORDER BY group_forum_id',
+					array($this->Group->getID()));
 		if (!$res) {
 			return $result ;
 		}
@@ -94,7 +94,7 @@ ORDER BY group_forum_id',
 	function &getAllForumIdsWithNews() {
 		$result = array () ;
 		$res = db_query_params('SELECT group_forum_id FROM forum_group_list WHERE group_id=$1 ORDER BY group_forum_id',
-			array ($this->Group->getID()));
+					array($this->Group->getID()));
 		if (!$res) {
 			return $result ;
 		}
@@ -105,17 +105,17 @@ ORDER BY group_forum_id',
 	}
 
 	/**
-	 *	getForums - get an array of Forum objects for this Group.
+	 * getForums - get an array of Forum objects for this Group.
 	 *
-	 *	@return	array	The array of Forum objects.
+	 * @return	array	The array of Forum objects.
 	 */
 	function &getForums() {
 		if ($this->forums) {
 			return $this->forums;
 		}
 
-		$this->forums = array () ;
-		$ids = $this->getAllForumIds() ;
+		$this->forums = array();
+		$ids = $this->getAllForumIds();
 
 		if (!empty($ids) ) {
 			foreach ($ids as $id) {
@@ -128,9 +128,9 @@ ORDER BY group_forum_id',
 	}
 
 	/**
-	 *	getForumsAdmin - get an array of all (public, private and suspended) Forum objects for this Group.
+	 * getForumsAdmin - get an array of all (public, private and suspended) Forum objects for this Group.
 	 *
-	 *	@return	array	The array of Forum objects.
+	 * @return	array	The array of Forum objects.
 	 */
 	function &getForumsAdmin() {
 		if ($this->forums) {
@@ -142,10 +142,10 @@ ORDER BY group_forum_id',
 				$this->setError(_("You don't have a permission to access this page"));
 				$this->forums = false;
 			} else {
-				$result = db_query_params ('SELECT * FROM forum_group_list_vw
-WHERE group_id=$1
-ORDER BY group_forum_id',
-							   array ($this->Group->getID())) ;
+				$result = db_query_params('SELECT * FROM forum_group_list_vw
+							WHERE group_id=$1
+							ORDER BY group_forum_id',
+							array($this->Group->getID())) ;
 			}
 		} else {
 			$this->setError(_("You don't have a permission to access this page"));
@@ -165,24 +165,23 @@ ORDER BY group_forum_id',
 		return $this->forums;
 	}
 
-    /**
-     *    moveThread - move thread in another forum
-     *
-     * @param $group_forum_id
-     * @param $thread_id
-     * @param bool $old_forum_id
-     * @internal param \The $string forum ID
-     * @internal param \The $int thread_id of the tread to change.
-     * @internal param \The $string old forum ID
-     *
-     *    Note:
-     *   old forum ID is useless if forum_agg_msg_count table is no longer used
-     *
-     * @return boolean success.
-     */
+	/**
+	 * moveThread - move thread in another forum
+	 *
+	 * @param	$group_forum_id
+	 * @param	$thread_id
+	 * @param	bool $old_forum_id
+	 * @internal	param \The $string forum ID
+	 * @internal	param \The $int thread_id of the tread to change.
+	 * @internal	param \The $string old forum ID
+	 *
+	 * Note: old forum ID is useless if forum_agg_msg_count table is no longer used
+	 *
+	 * @return boolean success.
+	 */
 	function moveThread($group_forum_id,$thread_id,$old_forum_id = false) {
 		$res = db_query_params('UPDATE forum SET group_forum_id=$1 WHERE thread_id=$2',
-			array($group_forum_id, $thread_id));
+					array($group_forum_id, $thread_id));
 		if (!$res) {
 			$this->setError(db_error());
 			return false;
@@ -194,53 +193,48 @@ ORDER BY group_forum_id',
 			}
 		}
 
-		if ($old_forum_id !== false)
-		{
+		if ($old_forum_id !== false) {
 			// Update forum_agg_msg_count table
 			// Note: if error(s) are raised it's certainly because forum_agg_msg_count
 			//		is no longer used and updated. So, error(s) are not catched
 			// Update row of old forum id
 			$res = db_query_params('SELECT count FROM forum_agg_msg_count WHERE group_forum_id=$1',
-				array($old_forum_id));
+						array($old_forum_id));
 			if ($res && db_numrows($res)) {
 				// Update row
 				$count = db_result($res, 0, 'count');
 				$count -= $msg_count;
 				if ($count < 0) $count = 0;
 				$res = db_query_params('UPDATE forum_agg_msg_count SET count=$1 WHERE group_forum_id=$2',
-					array($count, $old_forum_id));
-			}
-			else {
+							array($count, $old_forum_id));
+			} else {
 				// Error because row doesn't exist... insert it
 				$res = db_query_params('SELECT COUNT(*) AS count FROM forum WHERE group_forum_id=$1',
-					array($old_forum_id));
+							array($old_forum_id));
 				if ($res && db_numrows($res)) {
 					$count = db_result($res, 0, 'count');
 					$res = db_query_params('INSERT INTO forum_agg_msg_count (group_forum_id, count) VALUES ($1,$2)',
-						array($old_forum_id, $count));
+								array($old_forum_id, $count));
 				}
 			}
 
 			// Update row of new forum id
 			$res = db_query_params('SELECT count FROM forum_agg_msg_count WHERE group_forum_id=$1',
-				array($group_forum_id));
+						array($group_forum_id));
 			if ($res && db_numrows($res)) {
 				// Update row
 				$count = db_result($res, 0, 'count');
 				$count += $msg_count;
 				$res = db_query_params('UPDATE forum_agg_msg_count SET count=$1 WHERE group_forum_id=$2',
-					array($count, $group_forum_id));
-			}
-			else {
+							array($count, $group_forum_id));
+			} else {
 				// Insert row
 				$res = db_query_params('INSERT INTO forum_agg_msg_count (group_forum_id, count) VALUES ($1,$2)',
-					array($group_forum_id, $msg_count));
+							array($group_forum_id, $msg_count));
 			}
 		}
-
 		return true;
 	}
-
 }
 
 // Local Variables:
diff --git a/src/common/forum/ForumHTML.class.php b/src/common/forum/ForumHTML.class.php
index 73e5aab..854dfc8 100644
--- a/src/common/forum/ForumHTML.class.php
+++ b/src/common/forum/ForumHTML.class.php
@@ -48,7 +48,7 @@ function forum_header($params) {
 	if ($forum_id) {
 		// Check if this is a news item, to display it at the top of the page
 		$result = db_query_params('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
-					   array ($forum_id));
+					   array($forum_id));
 
 		if (db_numrows($result) == 1) {
 
@@ -130,10 +130,10 @@ function forum_header($params) {
 	}
 
 	$pluginManager = plugin_manager_get_object();
-	if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
+	if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook("blocks", "forum_".$f->getName()))
 		echo '<br />';
 
-	if (session_loggedin() ) {
+	if (session_loggedin()) {
 		if ($f) {
 			if ($f->isMonitoring()) {
 				echo util_make_link('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
@@ -188,12 +188,12 @@ class ForumHTML extends Error {
 	}
 
 	/**
-	 * Function showPendingMessage
+	 * showPendingMessage - get the HTML code of a pending message
 	 *
 	 * @param	object	$msg	The message.
 	 * @return	string	return the html output
 	 */
-	function showPendingMessage ( &$msg) {
+	function showPendingMessage(&$msg) {
 		global $HTML,$group_id;
 
 		$am = new AttachManager();
@@ -227,7 +227,7 @@ class ForumHTML extends Error {
 
 	}
 
-	function showNestedMessage ( &$msg ) {
+	function showNestedMessage(&$msg) {
 		/*
 
 		accepts a database result handle to display a single message
@@ -289,7 +289,7 @@ class ForumHTML extends Error {
 	}
 
 	/**
-	 *  LinkAttachEditForm - Returns the link to the attach form for editing
+	 * LinkAttachEditForm - Returns the link to the attach form for editing
 	 *
 	 * @param	string	$filename	Filename
 	 * @param	int	$group_id	group id
@@ -298,7 +298,6 @@ class ForumHTML extends Error {
 	 * @param	int	$msg_id		msg id
 	 * @return	string The HTML output
 	 */
-
 	function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
 		global $HTML;
 		$return_val = '
@@ -478,12 +477,11 @@ class ForumHTML extends Error {
 	}
 
 	/**
-	 *  showEditForm - Prints the form to edit a message
+	 * showEditForm - Prints the form to edit a message
 	 *
-	 *	@param 	int	$msg The Message
-	 *	@return	The HTML output echoed
+	 * @param	int	$msg The Message
+	 * @return	The HTML output echoed
 	 */
-
 	function showEditForm(&$msg) {
 		$thread_id = $msg->getThreadID();
 		$msg_id = $msg->getID();
diff --git a/src/common/forum/ForumMessage.class.php b/src/common/forum/ForumMessage.class.php
index eab4570..4b9a821 100644
--- a/src/common/forum/ForumMessage.class.php
+++ b/src/common/forum/ForumMessage.class.php
@@ -46,7 +46,7 @@ class ForumMessage extends Error {
 	var $Forum;
 
 	/**
-	 *  Constructor.
+	 * Constructor.
 	 *
 	 * @param	object		$Forum		The Forum object to which this ForumMessage is associated.
 	 * @param	bool|int	$msg_id		The message_id.
@@ -95,16 +95,16 @@ class ForumMessage extends Error {
 		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.
-	*/
-
+	/**
+	 * 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.
+	 */
 	function insertmoderated($subject, $body, $thread_id=0, $is_followup_to=0,$user_id) {
 		if (!$thread_id) {
 			$thread_id=$this->Forum->getNextThreadID();
@@ -153,19 +153,19 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	*	insertreleasedmsg - inserts the released message into the main table (forum)
-	 *	@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
-	 *	@return	bool	success.
-	*/
-
+	 * insertreleasedmsg - inserts the released message into the main table (forum)
+	 *
+	 * @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
+	 * @return	bool	success.
+	 */
 	function insertreleasedmsg($group_forum_id, $subject, $body, $post_date, $thread_id,
 							   $is_followup_to, $posted_by, $has_followups, $most_recent_date) {
 		if ($is_followup_to != 0) {
@@ -238,19 +238,18 @@ class ForumMessage extends 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.
-	*/
+	 * 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.
+	 */
 	function insertmsg($subject, $body, $thread_id=0, $is_followup_to=0,
 					   $user_id, $has_attach=false, $timestamp=0) {
 		if ($timestamp == 0){
@@ -342,15 +341,15 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *	create - use this function to create a new message in the database.
+	 * 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	boolean success.
 	 */
 	function create($subject, $body, $thread_id=0, $is_followup_to=0, $has_attach=false, $timestamp = 0) {
 		if (!strlen(trim($body)) || !strlen(trim($subject))) {
@@ -394,10 +393,10 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *  fetchData - re-fetch the data for this forum_message from the database.
+	 * 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	boolean	success.
 	 */
 	function fetchData($msg_id) {
 		$res = db_query_params ('SELECT * FROM forum_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
@@ -412,10 +411,10 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *  fetchModeratedData - re-fetch the data for this forum_message from the database, for pending messages
+	 * 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	boolean	success.
 	 */
 	function fetchModeratedData($msg_id) {
 		$res = db_query_params ('SELECT * FROM forum_pending_user_vw WHERE msg_id=$1 AND group_forum_id=$2',
@@ -430,128 +429,127 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *	getForum - get the Forum object this ForumMessage is associated with.
+	 * getForum - get the Forum object this ForumMessage is associated with.
 	 *
-	 *	@return	object	The Forum object.
+	 * @return	object	The Forum object.
 	 */
 	function &getForum() {
 		return $this->Forum;
 	}
 
 	/**
-	 *	getID - get this message_id.
+	 * getID - get this message_id.
 	 *
-	 *	@return	int	The message_id.
+	 * @return	int	The message_id.
 	 */
 	function getID() {
 		return $this->data_array['msg_id'];
 	}
 
 	/**
-	 *	getPosterName - get the unix user_name of this message's poster.
+	 * getPosterName - get the unix user_name of this message's poster.
 	 *
-	 *	@return	string	The poster's unix name.
+	 * @return	string	The poster's unix name.
 	 */
 	function getPosterName() {
 		return $this->data_array['user_name'];
 	}
 
 	/**
-	 *	getPosterID - get this user_id of this message's poster.
+	 * getPosterID - get this user_id of this message's poster.
 	 *
-	 *	@return	int	The user_id.
+	 * @return	int	The user_id.
 	 */
 	function getPosterID() {
 		return $this->data_array['posted_by'];
 	}
 
 	/**
-	 *	getPosterRealName - get the real name of this message's poster.
+	 * getPosterRealName - get the real name of this message's poster.
 	 *
-	 *	@return	string	The real name.
+	 * @return	string	The real name.
 	 */
 	function getPosterRealName() {
 		return $this->data_array['realname'];
 	}
 
 	/**
-	 *	getSubject - get the subject of this message.
+	 * getSubject - get the subject of this message.
 	 *
-	 *	@return	string	The subject.
+	 * @return	string	The subject.
 	 */
 	function getSubject() {
 		return $this->data_array['subject'];
 	}
 
 	/**
-	 *	getBody - get the body of this message.
+	 * getBody - get the body of this message.
 	 *
-	 *	@return	String	The body.
+	 * @return	String	The body.
 	 */
 	function getBody() {
 		return $this->data_array['body'];
 	}
 
 	/**
-	 *	getPostDate - get the post date of this message.
+	 * getPostDate - get the post date of this message.
 	 *
-	 *	@return	int	The post date.
+	 * @return	int	The post date.
 	 */
 	function getPostDate() {
 		return $this->data_array['post_date'];
 	}
 
 	/**
-	 *	getParentID - get the id of the parent message, if this is a followup.
+	 * getParentID - get the id of the parent message, if this is a followup.
 	 *
-	 *	@return	int	The parent id.
+	 * @return	int	The parent id.
 	 */
 	function getParentID() {
 		return $this->data_array['is_followup_to'];
 	}
 
 	/**
-	 *	isPending - is the message pending, awaiting moderation?
+	 * isPending - is the message pending, awaiting moderation?
 	 *
-	 *	@return	int	awaits_moderation
+	 * @return	int	awaits_moderation
 	 */
 	function isPending() {
 		return $this->awaits_moderation;
 	}
 
 	/**
-	 *	getThreadID - get the thread_id of the message.
+	 * getThreadID - get the thread_id of the message.
 	 *
-	 *	@return	int	The thread_id.
+	 * @return	int	The thread_id.
 	 */
 	function getThreadID() {
 		return $this->data_array['thread_id'];
 	}
 
 	/**
-	 *	getMostRecentDate - get the date of the most recent followup.
+	 * getMostRecentDate - get the date of the most recent followup.
 	 *
-	 *	@return	int	The date of the most recent followup.
+	 * @return	int	The date of the most recent followup.
 	 */
 	function getMostRecentDate() {
 		return $this->data_array['most_recent_date'];
 	}
 
 	/**
-	 *	hasFollowups - whether this message has any followups.
+	 * hasFollowups - whether this message has any followups.
 	 *
-	 *	@return boolean has_followups.
+	 * @return boolean has_followups.
 	 */
 	function hasFollowups() {
 		return $this->data_array['has_followups'];
 	}
 
 	/**
-	 *	hasAttach - whether this message has an attachment.
+	 * hasAttach - whether this message has an attachment.
 	 *
-	 *	@return boolean has_attach.
+	 * @return boolean has_attach.
 	 */
-
 	function hasAttach() {
 		if ($this->isPending()) {
 			$res = db_query_params ('SELECT attachmentid FROM forum_pending_attachment WHERE msg_id=$1',
@@ -567,9 +565,9 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *	delete - Delete this message and its followups.
+	 * delete - Delete this message and its followups.
 	 *
-	 *	@return	int	The count of deleted messages.
+	 * @return	int	The count of deleted messages.
 	 */
 	function delete() {
 		$msg_id=$this->getID();
@@ -608,10 +606,10 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *	removebbcode - workaround to remove bbcode tags.
+	 * removebbcode - workaround to remove bbcode tags.
 	 *
-     * @param string $text
-	 * @return string	converted text
+	 * @param	string	$text
+	 * @return	string	converted text
 	 */
 	function removebbcode($text) {
 		//$replaced =  preg_replace("/\[[_a-zA-Z]:.+\](.+)\[\/[_a-zA-Z]:.*\]/","$1",$text);
@@ -620,11 +618,10 @@ class ForumMessage extends Error {
 	}
 
 	/**
-	 *	sendNotice - contains the logic to send out email followups when a message is posted.
+	 * 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	boolean	$has_attach	Whether the message has an attach associated. Defaults to false
+	 * @return	boolean	success.
 	 */
 	function sendNotice($has_attach=false) {
 		$ids = $this->Forum->getMonitoringIDs();
@@ -715,17 +712,17 @@ Or reply to this e-mail entering your response between the following markers:
 	}
 
 	/**
-	 *	sendNewModeratedMsgNotice - contains the logic to send out email notifications to the forum admins when a new moderated message is posted
+	 * sendNewModeratedMsgNotice - contains the logic to send out email notifications to the forum admins when a new moderated message is posted
 	 *
-	 *	@return boolean success.
+	 * @return	boolean	success.
 	 */
 	function sendNewModeratedMsgNotice() {
-		$ids = array () ;
-		$engine = RBACEngine::getInstance () ;
-		$moderators = $engine->getUsersByAllowedAction ('forum', $this->Forum->getID(), 'moderate') ;
+		$ids = array();
+		$engine = RBACEngine::getInstance();
+		$moderators = $engine->getUsersByAllowedAction('forum', $this->Forum->getID(), 'moderate');
 
 		foreach ($moderators as $m) {
-			$ids[] = $m->getID () ;
+			$ids[] = $m->getID();
 		}
 
 		//
@@ -782,19 +779,18 @@ Or reply to this e-mail entering your response between the following markers:
 	}
 
 	/**
-	 *	updatemsg - impacts in the DB the new content of the message
-	 *
-	 *	@param	string	$group_forum_id		The forum ID
-	 *	@param 	int		$posted_by			The id of the user that is posting the message
-	 *	@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		$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.
+	 * updatemsg - impacts in the DB the new content of the message
 	 *
-	 *	@return boolean success.
+	 * @param	string	$group_forum_id		The forum ID
+	 * @param 	int	$posted_by		The id of the user that is posting the message
+	 * @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	$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.
 	 */
 	function updatemsg($group_forum_id, $posted_by, $subject, $body,
 					   $post_date, $is_followup_to, $thread_id, $has_followups, $most_recent_date) {
@@ -831,11 +827,10 @@ Or reply to this e-mail entering your response between the following markers:
 	}
 
 	/**
-	 *	sendAttachNotice - contains the logic to send out email attachement followups when a message is posted.
+	 * 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.
+	 * @param	int	$attach_id	- The id of the file that has been attached
+	 * @return	boolean	success.
 	 */
 	function sendAttachNotice($attach_id) {
 		if ($attach_id) {
@@ -886,7 +881,6 @@ Or reply to this e-mail entering your response between the following markers:
 			util_send_message('',$subject,$body,"noreply@".forge_get_config('web_host'),$BCC,'Forum',$extra_headers);
 			return true;
 		}
-
 		return false;
 	}
 }
diff --git a/src/common/forum/ForumMessageFactory.class.php b/src/common/forum/ForumMessageFactory.class.php
index b6fe89a..08cf4e4 100644
--- a/src/common/forum/ForumMessageFactory.class.php
+++ b/src/common/forum/ForumMessageFactory.class.php
@@ -31,14 +31,14 @@ class ForumMessageFactory extends Error {
 	/**
 	 * The Forum object.
 	 *
-	 * @var	 object  $Forum.
+	 * @var	object  $Forum.
 	 */
 	var $Forum;
 
 	/**
 	 * The forum_messages array.
 	 *
-	 * @var  array  forum_messages.
+	 * @var	array  forum_messages.
 	 */
 	var $forum_messages;
 	var $style;
@@ -47,10 +47,10 @@ class ForumMessageFactory extends Error {
 	var $fetched_rows;
 
 	/**
-	 *  Constructor.
+	 * Constructor.
 	 *
-	 *	@param	object	$Forum	The Forum object to which this ForumMessageFactory is associated.
-	 *	@return	boolean	success.
+	 * @param	object	$Forum	The Forum object to which this ForumMessageFactory is associated.
+	 * @return	boolean	success.
 	 */
 	function ForumMessageFactory(&$Forum) {
 		$this->Error();
@@ -63,17 +63,16 @@ class ForumMessageFactory extends Error {
 			return false;
 		}
 		$this->Forum =& $Forum;
-
 		return true;
 	}
 
 	/**
-	 *	setup - call this function before getThreaded/nested/etc to set up the user preferences.
+	 * setup - call this function before getThreaded/nested/etc to set up the user preferences.
 	 *
-	 *	@param	int    $offset   The number of rows to skip.
-	 *	@param	string $style    The style of forum, whether it's nested, ultimate, etc.
-	 *	@param	int	   $max_rows The maximum number of rows to return.
-	 *	@param	int	   $set      Whether to set these prefs into the database - use "custom".
+	 * @param	int    $offset   The number of rows to skip.
+	 * @param	string $style    The style of forum, whether it's nested, ultimate, etc.
+	 * @param	int	   $max_rows The maximum number of rows to return.
+	 * @param	int	   $set      Whether to set these prefs into the database - use "custom".
 	 */
 	function setup($offset,$style,$max_rows,$set) {
 //echo "<br />offset: $offset| style: $style|max_rows: $max_rows|set: $set+";
@@ -127,9 +126,9 @@ class ForumMessageFactory extends Error {
 	}
 
 	/**
-	 *	getStyle - the style of forum this is - nested/ultimate/etc.
+	 * getStyle - the style of forum this is - nested/ultimate/etc.
 	 *
-	 *	@return	string	The style.
+	 * @return	string	The style.
 	 */
 	function getStyle() {
 		return $this->style;
@@ -147,7 +146,7 @@ class ForumMessageFactory extends Error {
 			if ($row[$i]) {
 				$msg_arr["".$row[$i]->getParentID().""][] =& $row[$i];
 			}
-	  	}
+		}
 		return $msg_arr;
 	}
 
@@ -163,17 +162,17 @@ class ForumMessageFactory extends Error {
 		}
 		if (isset ($thread_id) && is_numeric($thread_id)) {
 			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-                  AND thread_id=$2
-		ORDER BY most_recent_date DESC',
+							WHERE group_forum_id=$1
+							AND thread_id=$2
+							ORDER BY most_recent_date DESC',
 						   array ($this->Forum->getID(),
 							  $thread_id),
 						   $this->max_rows+25,
 						   $this->offset);
 		} else {
 			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-		ORDER BY most_recent_date DESC',
+							WHERE group_forum_id=$1
+							ORDER BY most_recent_date DESC',
 						   array ($this->Forum->getID()),
 						   $this->max_rows+25,
 						   $this->offset);
@@ -194,7 +193,7 @@ class ForumMessageFactory extends Error {
 	}
 
 	/**
-	 *    getThreaded - Return an array of ForumMessage objects arranged for threaded forum views.
+	 * getThreaded - Return an array of ForumMessage objects arranged for threaded forum views.
 	 *
 	 * @param	bool	$thread_id
 	 * @return	array	The array of ForumMessages.
@@ -205,17 +204,17 @@ class ForumMessageFactory extends Error {
 		}
 		if (isset ($thread_id) && is_numeric($thread_id)) {
 			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-                  AND thread_id=$2
-		ORDER BY most_recent_date DESC',
+							WHERE group_forum_id=$1
+							AND thread_id=$2
+							ORDER BY most_recent_date DESC',
 						   array ($this->Forum->getID(),
 							  $thread_id),
 						   $this->max_rows+25,
 						   $this->offset);
 		} else {
 			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-		ORDER BY most_recent_date DESC',
+							WHERE group_forum_id=$1
+							ORDER BY most_recent_date DESC',
 						   array ($this->Forum->getID()),
 						   $this->max_rows+25,
 						   $this->offset);
@@ -223,7 +222,7 @@ class ForumMessageFactory extends Error {
 		$rows = db_numrows($result);
 		$this->fetched_rows=$rows;
 		if (!$result) {
-			$this->setError('Error when fetching messages '.db_error());
+			$this->setError(_('Error when fetching messages ').db_error());
 			return false;
 		} elseif ($rows < 1) {
 			$this->forum_messages = array();
@@ -236,29 +235,29 @@ class ForumMessageFactory extends Error {
 	}
 
 	/**
-	 *	getFlat - Return an array of ForumMessage objects arranged for flat forum views.
+	 * getFlat - Return an array of ForumMessage objects arranged for flat forum views.
 	 *
-	 *	@param	int|bool	$thread_id
-	 *	@return	array		The array of ForumMessages.
+	 * @param	int|bool	$thread_id
+	 * @return	array		The array of ForumMessages.
 	 */
 	function &getFlat($thread_id=false) {
 		if ($this->forum_messages) {
 			return $this->forum_messages;
 		}
 		if (isset ($thread_id) && is_numeric($thread_id)) {
-			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-                  AND thread_id=$2
-		ORDER BY msg_id DESC',
-						   array ($this->Forum->getID(),
+			$result = db_query_params('SELECT * FROM forum_user_vw
+							WHERE group_forum_id=$1
+							AND thread_id=$2
+							ORDER BY msg_id DESC',
+						   array($this->Forum->getID(),
 							  $thread_id),
 						   $this->max_rows+25,
 						   $this->offset);
 		} else {
-			$result = db_query_params ('SELECT * FROM forum_user_vw
-		WHERE group_forum_id=$1
-		ORDER BY msg_id DESC',
-						   array ($this->Forum->getID()),
+			$result = db_query_params('SELECT * FROM forum_user_vw
+							WHERE group_forum_id=$1
+							ORDER BY msg_id DESC',
+						   array($this->Forum->getID()),
 						   $this->max_rows+25,
 						   $this->offset);
 		}
diff --git a/src/common/forum/ForumStorage.class.php b/src/common/forum/ForumStorage.class.php
new file mode 100644
index 0000000..67c67a7
--- /dev/null
+++ b/src/common/forum/ForumStorage.class.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * FusionForge Forum Storage Class
+ *
+ * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2014, Franck Villaume - TrivialDev
+ *
+ * This file is part of FusionForge. FusionForge 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 Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * Standard Alcatel-Lucent disclaimer for contributing to open source
+ *
+ * "The Artifact ("Contribution") has not been tested and/or
+ * validated for release as or in products, combinations with products or
+ * other commercial use. Any use of the Contribution is entirely made at
+ * the user's own responsibility and the user can not rely on any features,
+ * functionalities or performances Alcatel-Lucent has attributed to the
+ * Contribution.
+ *
+ * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
+ * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
+ * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
+ * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
+ * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
+ * ALONE BASIS."
+ */
+
+require_once $gfcommon.'include/Storage.class.php';
+
+class ForumStorage extends Storage {
+	public static function instance() {
+		if (!isset(self::$_instance)) {
+			$c = __CLASS__;
+			self::$_instance = new $c;
+		}
+		return self::$_instance;
+	}
+
+	function get_storage_path() {
+		return forge_get_config('data_path').'/forum';
+	}
+}
diff --git a/src/common/forum/ForumsForUser.class.php b/src/common/forum/ForumsForUser.class.php
index bc4d0bb..66df513 100644
--- a/src/common/forum/ForumsForUser.class.php
+++ b/src/common/forum/ForumsForUser.class.php
@@ -36,10 +36,10 @@ class ForumsForUser extends Error {
 	var $User;
 
 	/**
-	 *  Constructor.
+	 * Constructor.
 	 *
-	 *	@param	$user   object	The Group object to which this forum is associated.
-	 * @return bool
+	 * @param	$user   object	The Group object to which this forum is associated.
+	 * @return	bool
 	 */
 	function ForumsForUser(&$user) {
 		$this->User =& $user;
@@ -48,19 +48,19 @@ class ForumsForUser extends Error {
 	}
 
 	/**
-	*       getMonitoredForums
-	*
-	*       @return Forum[] The array of Forums
-	*
-	*/
+	 * getMonitoredForums
+	 *
+	 * @return	Forum[]	The array of Forums
+	 *
+	 */
 	function getMonitoredForums() {
 		$forums = array();
 		$result = db_query_params ('SELECT groups.group_name,groups.group_id,forum_group_list.group_forum_id,forum_group_list.forum_name
-		     FROM groups,forum_group_list,forum_monitored_forums
-		     WHERE groups.group_id=forum_group_list.group_id AND groups.status=$1
-		     AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id
-		     AND forum_monitored_forums.user_id=$2
-                     ORDER BY group_name DESC',
+						FROM groups,forum_group_list,forum_monitored_forums
+						WHERE groups.group_id=forum_group_list.group_id AND groups.status=$1
+						AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id
+						AND forum_monitored_forums.user_id=$2
+						ORDER BY group_name DESC',
 					   array ('A',
 						  $this->User->getID())) ;
 		$rows=db_numrows($result);
@@ -81,7 +81,6 @@ class ForumsForUser extends Error {
 		}
 		return $forums;
 	}
-
 }
 
 // Local Variables:
diff --git a/src/common/import/import_forums.php b/src/common/import/import_forums.php
index 26c20a5..1d46462 100644
--- a/src/common/import/import_forums.php
+++ b/src/common/import/import_forums.php
@@ -1,4 +1,25 @@
 <?php
+/**
+ * FusionForge
+ * Previous copyright : FusionForge Team
+ * Copyright 2014, Franck Villaume - TrivialDev
+ * http://fusionforge.org/
+ *
+ * This file is part of FusionForge. FusionForge 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 Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 require_once '../env.inc.php';
 require_once $gfwww.'include/pre.php';
@@ -57,7 +78,7 @@ class Forums {
 				}
 				$mimetype = $finfo->file($path);
 				$filehash = md5($filedata);
-				$am->AddToDBOnly($userid, $msg_time, $filename, base64_encode($filedata), $fs, 1, $filehash, $mimetype);
+				$am->AddToDBOnly($userid, $msg_time, $filename, $path, $fs, 1, $filehash, $mimetype);
 			}
 
 			if (count($message['children']) != 0){
@@ -91,9 +112,9 @@ class Forums {
 	 * deleteForums - Delete all existing default forums from a projet
 	 */
 	function deleteForums(){
-		$res = db_query_params ('SELECT group_forum_id FROM forum_group_list
-				WHERE group_id=$1',
-		array ($this->group_id));
+		$res = db_query_params('SELECT group_forum_id FROM forum_group_list
+					WHERE group_id=$1',
+					array ($this->group_id));
 		while($row=db_fetch_array($res)){
 			$f = new Forum($this->group, $row['group_forum_id']);
 			$f->delete(true,true);
diff --git a/src/db/20140710-forum-migrate-attachments-to-fs.php b/src/db/20140710-forum-migrate-attachments-to-fs.php
new file mode 100644
index 0000000..c2466ee
--- /dev/null
+++ b/src/db/20140710-forum-migrate-attachments-to-fs.php
@@ -0,0 +1,115 @@
+<?php
+/**
+ *
+ * Copyright 2012, Alain Peyrat
+ * Copyright 2014, Franck Villaume - TrivialDev
+ * http://fusionforge.org/
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge 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.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+require_once dirname(__FILE__).'/../common/include/env.inc.php';
+require_once $gfcommon.'include/pre.php';
+require_once $gfcommon.'forum/ForumStorage.class.php';
+
+ini_set('memory_limit', -1);
+ini_set('max_execution_time', 0);
+
+$data = forge_get_config('data_path');
+if (!is_dir($data)) {
+	system("mkdir -p $data");
+	system("chmod 0755 $data");
+}
+if (!is_dir("$data/forum")) {
+	system("mkdir $data/forum");
+	system("chmod 0700 $data/forum");
+}
+
+$fs = new ForumStorage();
+$tmp = tempnam('/tmp', 'docman');
+
+$res = db_query_params('SELECT attachmentid FROM forum_attachment where filedata != $1', array(0));
+if (!$res) {
+	echo 'UPGRADE ERROR: '.db_error();
+	exit(1);
+}
+
+while($row = db_fetch_array($res)) {
+	$res2 = db_query_params('SELECT filedata FROM forum_attachment WHERE attachmentid = $1',
+		array($row['attachmentid'])) ;
+	$row2 = db_fetch_array($res2);
+	$data = base64_decode($row2['filedata']);
+	// Not using column 'filesize', since we saw 2 installs where it was wrong
+	$size = strlen($data); // strlen == nb of bytes, not chars
+	$ret = file_put_contents($tmp, $data);
+	if ($ret === false) {
+		echo "UPGRADE ERROR: file_put_contents($tmp) error: returned false\n";
+		$fs->rollback();
+		exit(1);
+	}
+	if ($ret != $size) {
+		echo "UPGRADE ERROR: file_put_contents($tmp) size error: ($ret != ".$size.")\n";
+		$fs->rollback();
+		exit(1);
+	}
+	$ret = $fs->store($row['attachmentid'], $tmp);
+	if (!$ret) {
+		echo "UPGRADE ERROR: $ret: ".$fs->getErrorMessage()."\n";
+		$fs->rollback();
+		exit(1);
+	}
+	$fs->commit();
+	db_query_params('UPDATE forum_attachment set filedata = $1 where attachmentid = $2', array(0, $row['attachmentid']));
+}
+
+$res = db_query_params('SELECT attachmentid FROM forum_pending_attachment where filedata != $1', array(0));
+if (!$res) {
+	echo 'UPGRADE ERROR: '.db_error();
+	exit(1);
+}
+
+while($row = db_fetch_array($res)) {
+	$res2 = db_query_params('SELECT filedata FROM forum_pending_attachment WHERE attachmentid = $1',
+		array($row['attachmentid'])) ;
+	$row2 = db_fetch_array($res2);
+	$data = base64_decode($row2['filedata']);
+	// Not using column 'filesize', since we saw 2 installs where it was wrong
+	$size = strlen($data); // strlen == nb of bytes, not chars
+	$ret = file_put_contents($tmp, $data);
+	if ($ret === false) {
+		echo "UPGRADE ERROR: file_put_contents($tmp) error: returned false\n";
+		$fs->rollback();
+		exit(1);
+	}
+	if ($ret != $size) {
+		echo "UPGRADE ERROR: file_put_contents($tmp) size error: ($ret != ".$size.")\n";
+		$fs->rollback();
+		exit(1);
+	}
+	$ret = $fs->store($row['attachmentid'], $tmp);
+	if (!$ret) {
+		echo "UPGRADE ERROR: $ret: ".$fs->getErrorMessage()."\n";
+		$fs->rollback();
+		exit(1);
+	}
+	$fs->commit();
+	db_query_params('UPDATE forum_pending_attachment set filedata = $1 where attachmentid = $2', array(0, $row['attachmentid']));
+}
+
+system("chown -R ".forge_get_config('apache_user').':'.forge_get_config('apache_group')." $data/forum");
+
+echo "SUCCESS\n";
diff --git a/src/www/forum/attachment.php b/src/www/forum/attachment.php
index 7d8afa7..582ccbc 100644
--- a/src/www/forum/attachment.php
+++ b/src/www/forum/attachment.php
@@ -4,7 +4,9 @@
  *
  * Portions Copyright 1999-2001 (c) VA Linux Systems
  * The rest Copyright 2002-2004 (c) GForge Team
+ * Coyright 2005, Daniel Perez
  * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
+ * Copyright 2014, Franck Villaume - TrivialDev
  * http://fusionforge.org/
  *
  * This file is part of FusionForge. FusionForge is free software;
@@ -23,13 +25,10 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/* attachment download
-	by Daniel Perez - 2005
-*/
-
 require_once '../env.inc.php';
 require_once $gfcommon.'include/pre.php';
 require_once $gfcommon.'forum/ForumHTML.class.php';
+require_once $gfcommon.'forum/ForumStorage.class.php';
 
 /**
  *  goodbye - Just prints a message and a close button.
@@ -65,57 +64,58 @@ if (!$g || !is_object($g) || $g->isError()) {
 
 $f=new Forum($g,$forum_id);
 if (!$f || !is_object($f)) {
-	exit_error(_('Error getting Forum'),'forums');
+	exit_error(_('Error getting Forum'), 'forums');
 } elseif ($f->isError()) {
-	exit_error($f->getErrorMessage(),'forums');
+	exit_error($f->getErrorMessage(), 'forums');
 }
 
 if ($delete == "yes") {
-	session_require_perm ('forum', $f->getID(), 'post') ;
+	session_require_perm('forum', $f->getID(), 'post') ;
 
 	//only the user that created the attach  or forum admin can delete it (safecheck)
 	if (!$pending) { //pending messages aren't deleted from this page
-		$res = db_query_params ('SELECT userid FROM forum_attachment WHERE attachmentid=$1',
-			array ($attachid));
+		$res = db_query_params('SELECT userid FROM forum_attachment WHERE attachmentid=$1',
+					array($attachid));
 	} else {
-		$res = false ;
+		$res = false;
 	}
 	if ( (!$res) ) {
 		exit_error("Attachment Download error: ".db_error(),'forums');
 	}
 	if (! ((db_result($res,0,'userid') == user_getid()) || (forge_check_perm ('forum_admin', $f->Group->getID()))) ) {
 		goodbye(_('You cannot delete this attachment'));
-	}	else {
+	} else {
 		if (!$pending) {
-			if (db_query_params ('DELETE FROM forum_attachment WHERE attachmentid=$1',
-			array($attachid))) {
+			if (db_query_params('DELETE FROM forum_attachment WHERE attachmentid=$1',
+						array($attachid))) {
+				ForumStorage::instance()->delete($attachid)->commit();
 				goodbye(_('Attachment deleted'));
 			} else {
-				exit_error(db_error(),'forums');
+				exit_error(db_error(), 'forums');
 			}
 		}
 	}
 }
 
-if ($edit=="yes") {
-	session_require_perm ('forum', $f->getID(), 'post') ;
+if ($edit == "yes") {
+	session_require_perm('forum', $f->getID(), 'post') ;
 
 	//only the user that created the attach  or forum admin can edit it (safecheck)
 	if (!$pending) { //pending messages aren't deleted from this page
 		$res = db_query_params ('SELECT filename FROM forum_attachment WHERE attachmentid=$1',
-			array ($attachid));
-		$res2 = db_query_params ('SELECT posted_by FROM forum WHERE msg_id=$1',
-			array ($msg_id));
+					array($attachid));
+		$res2 = db_query_params('SELECT posted_by FROM forum WHERE msg_id=$1',
+					array($msg_id));
 	} else {
-		$res = false ;
-		$res2 = false ;
+		$res = false;
+		$res2 = false;
 	}
 	if ( (!$res) || (!$res2) ) {
-		exit_error("Attachment error:".db_error(),'forums');
+		exit_error("Attachment error:".db_error(), 'forums');
 	}
-	if (! ((db_result($res2,0,'posted_by') == user_getid()) || (forge_check_perm ('forum_admin', $f->Group->getID()))) ) {
+	if (! ((db_result($res2, 0, 'posted_by') == user_getid()) || (forge_check_perm('forum_admin', $f->Group->getID())))) {
 		goodbye(_('You cannot edit this attachment'));
-	}	else {
+	} else {
 		if ($doedit=="1") {
 			//actually edit the attach and save the info
 			forum_header(array('title'=>_('Attachments')));
@@ -141,24 +141,24 @@ if ($edit=="yes") {
 			foreach ($am->Getmessages() as $item) {
 				$feedback .= "<br />" . $item;
 			}
-			goodbye("Attachment saved");
+			goodbye(_('Attachment saved'));
 			forum_footer();
 			exit();
 		} else {
 			//show the form to edit the attach
-			forum_header(array('title'=>_('Attachments')));
+			forum_header(array('title' => _('Attachments')));
 			$fh = new ForumHTML($f);
 			if (!$fh || !is_object($fh)) {
-				exit_error(_('Error getting new ForumHTML'),'forums');
+				exit_error(_('Error getting new ForumHTML'), 'forums');
 			} elseif ($fh->isError()) {
-				exit_error($fh->getErrorMessage(),'forums');
+				exit_error($fh->getErrorMessage(), 'forums');
 			}
-			if (!db_result($res,0,'filename')) {
-				$filename = _("No attach found");
+			if (!db_result($res, 0, 'filename')) {
+				$filename = _('No attachment found');
 			} else {
-				$filename = db_result($res,0,'filename');
+				$filename = db_result($res, 0, 'filename');
 			}
-			echo $fh->LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id);
+			echo $fh->LinkAttachEditForm($filename, $group_id, $forum_id, $attachid, $msg_id);
 			forum_footer();
 			exit();
 		}
@@ -166,33 +166,34 @@ if ($edit=="yes") {
 	}
 }
 
-session_require_perm ('forum', $f->getID(), 'read') ;
+session_require_perm('forum', $f->getID(), 'read');
 
 if (!$attachid) {
 	exit_missing_param();
 }
 
-if ($pending=="yes") {
-	$res = db_query_params ('SELECT * FROM forum_pending_attachment WHERE attachmentid=$1',
-			array ($attachid));
+if ($pending == "yes") {
+	$res = db_query_params('SELECT * FROM forum_pending_attachment WHERE attachmentid=$1',
+			array($attachid));
 } else {
-	$res = db_query_params ('SELECT * FROM forum_attachment WHERE attachmentid=$1',
-			array ($attachid));
+	$res = db_query_params('SELECT * FROM forum_attachment WHERE attachmentid=$1',
+			array($attachid));
 }
 
 if (!$res || !db_numrows($res) ) {
 	exit_error("Attachment Download error: ".db_error(),'forums');
 }
-$extension = substr(strrchr(strtolower(db_result($res,0,'filename')), '.'), 1);
+
+$sysdebug_enable = false;
 
 $last = gmdate('D, d M Y H:i:s', db_result($res,0,'dateline'));
 header('Last-Modified: ' . $last . ' GMT');
 header('ETag: "' . db_result($res,0,'attachmentid').db_result($res,0,'filehash') . '"');
-
+$extension = substr(strrchr(strtolower(db_result($res,0,'filename')), '.'), 1);
 if ($extension != 'txt') {
 	header("Content-disposition: inline; filename=\"" . db_result($res,0,'filename') . "\"");
 	header('Content-transfer-encoding: binary');
-}	else {
+} else {
 	header("Content-disposition: attachment; filename=\"" . db_result($res,0,'filename') . "\"");
 }
 
@@ -205,16 +206,12 @@ if ($mimetype) {
 	header('Content-type: application/octet-stream');
 }
 
-$filedata = base64_decode(db_result($res,0,'filedata'));
-for ($i = 0; $i < strlen($filedata); $i = $i+100) {
-   $acum = substr($filedata, $i, 100);
-   echo $acum;
-}
-
+readfile_chunked(ForumStorage::instance()->get($attachid));
 flush();
+
 //increase the attach count
 if (!$pending) { //we don't care for the pending attach counter, it's just for administrative purposes
-	db_query_params ('UPDATE forum_attachment SET counter=counter+1 WHERE attachmentid=$1',
+	db_query_params('UPDATE forum_attachment SET counter=counter+1 WHERE attachmentid=$1',
 			array($attachid));
 }
 

-----------------------------------------------------------------------

Summary of changes:
 src/CHANGES                                        |    2 +
 src/common/forum/AttachManager.class.php           |  296 ++++++++++++--------
 src/common/forum/ForumAdmin.class.php              |   97 +++----
 src/common/forum/ForumFactory.class.php            |   90 +++---
 src/common/forum/ForumHTML.class.php               |   22 +-
 src/common/forum/ForumMessage.class.php            |  216 +++++++-------
 src/common/forum/ForumMessageFactory.class.php     |   75 +++--
 .../ForumStorage.class.php}                        |    8 +-
 src/common/forum/ForumsForUser.class.php           |   27 +-
 src/common/import/import_forums.php                |   29 +-
 .../20140710-forum-migrate-attachments-to-fs.php   |  115 ++++++++
 src/www/forum/attachment.php                       |   93 +++---
 12 files changed, 628 insertions(+), 442 deletions(-)
 copy src/common/{docman/DocumentStorage.class.php => forum/ForumStorage.class.php} (92%)
 create mode 100644 src/db/20140710-forum-migrate-attachments-to-fs.php


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list