5 * Copyright 1999-2001, Tim Perdue - Sourceforge
6 * Copyright 2002, Tim Perdue - GForge, LLC
7 * Copyright 2010 (c) Franck Villaume - Capgemini
8 * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
9 * Copyright 2013, Franck Villaume - TrivialDev
10 * Copyright 2013, French Ministry of National Education
11 * http://fusionforge.org
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once $gfwww.'include/note.php';
30 require_once $gfwww.'include/trove.php';
31 require_once $gfwww.'news/news_utils.php';
32 require_once $gfcommon.'forum/ForumAdmin.class.php';
33 require_once $gfcommon.'forum/AttachManager.class.php';
35 function forum_header($params) {
36 global $HTML, $group_id, $forum_name, $forum_id, $f, $group_forum_id;
38 if ($group_forum_id) {
39 $forum_id = $group_forum_id;
41 if (!forge_get_config('use_forum')) {
45 $params['group'] = $group_id;
46 $params['toptab'] = 'forums';
49 // Check if this is a news item, to display it at the top of the page
50 $result = db_query_params('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
53 if (db_numrows($result) == 1) {
55 // checks which group the news item belongs to
56 $params['group'] = db_result($result, 0, 'group_id');
57 $params['toptab'] = 'news';
58 $params['title'] = _('Forum')._(': ').db_result($result,0,'summary');
59 $HTML->header($params);
61 echo '<table><tr><td class="top">';
62 $user = user_get_object(db_result($result,0,'submitted_by'));
63 $group = group_get_object($params['group']);
64 if (!$group || !is_object($group) || $group->isError()) {
68 <strong>'._('Posted by')._(': ').'</strong> '.$user->getRealName().'<br />
69 <strong>'._('Date')._(': ').'</strong> '. relative_date(db_result($result,0,'post_date')).'<br />
70 <strong>'._('Summary')._(': ').'</strong>'.
71 util_make_link('/forum/forum.php?forum_id='.db_result($result, 0, 'forum_id').'&group_id='.$group_id,
72 db_result($result, 0, 'summary')).'<br/>
73 <strong>'._('Project')._(': ').'</strong>'.
74 util_make_link_g($group->getUnixName(),db_result($result, 0, 'group_id'),$group->getPublicName()).'<br />
78 // display classification
79 if ($params['group'] == forge_get_config('news_group')) {
80 print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
81 } elseif (forge_get_config('use_trove')) {
82 print stripslashes(trove_getcatlisting($params['group'],0,1));
85 echo '<p><strong>'._('Content')._(':').'</strong></p>';
86 $body = db_result($result,0,'details');
87 $body = TextSanitizer::purify($body);
88 if (!strstr($body,'<')) {
89 //backwards compatibility for non html messages
90 echo util_make_links(nl2br($body));
92 echo util_make_links($body);
94 echo '</td><td valign="top" width="35%">';
95 echo $HTML->boxTop(_('Latest News'));
96 echo news_show_latest($params['group'],5,false);
97 echo $HTML->boxBottom();
98 echo '</td></tr></table>';
100 $HTML->header($params);
103 $menu_text = array();
104 $menu_links = array();
106 $menu_text[] = _('View Forums');
107 $menu_links[] = '/forum/?group_id='.$group_id;
111 $menu_text[]=_('Discussion Forums:') .' '. $f->getName();
112 $menu_links[]='/forum/forum.php?forum_id='.$forum_id;
114 if (forge_check_perm ('forum_admin', $f->Group->getID())) {
115 $menu_text[]=_('Administration');
116 $menu_links[]='/forum/admin/?group_id='.$group_id;
119 $gg = group_get_object($group_id);
120 if (forge_check_perm ('forum_admin', $group_id)) {
121 $menu_text[]=_('Administration');
122 $menu_links[]='/forum/admin/?group_id='.$group_id;
125 if (count($menu_text) > 0) {
126 $params['submenu'] =$HTML->subMenu($menu_text,$menu_links);
129 site_project_header($params);
132 $pluginManager = plugin_manager_get_object();
133 if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
136 if (session_loggedin() ) {
138 if ($f->isMonitoring()) {
139 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
140 html_image('ic/xmail16w.png').' '._('Stop Monitoring')).' | ';
142 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
143 html_image('ic/mail16w.png').' '._('Monitor Forum')).' | ';
145 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
146 html_image('ic/save.png') .' '._('Save Place')).' | ';
149 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
150 html_image('ic/mail16w.png').' '._('Monitor Forum').'</a> | ';
153 if ($f && $forum_id) {
154 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
155 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
156 _('Start New Thread'));
160 function forum_footer($params) {
161 site_project_footer($params);
166 Wrap many forum functions in this class
169 class ForumHTML extends Error {
177 function ForumHTML(&$Forum) {
179 if (!$Forum || !is_object($Forum)) {
180 $this->setError(_('Invalid Forum Object'));
183 if ($Forum->isError()) {
184 $this->setError('ForumMessage: '.$Forum->getErrorMessage());
187 $this->Forum =& $Forum;
192 * Function showPendingMessage
194 * @param object $msg The message.
196 * @return string return the html output
198 function showPendingMessage ( &$msg) {
199 global $HTML,$group_id;
201 $am = new AttachManager();
202 $ret_val = $am->PrintHelperFunctions();
203 html_feedback_top(_('This is the content of the pending message'));
204 $bold_begin='<strong>';
205 $bold_end='</strong>';
209 <td class="tablecontent" style="white-space: nowrap;">'._('By')._(': ').
210 $msg->getPosterRealName().
213 $msgforum =& $msg->getForum();
214 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
217 html_image('ic/msg.png') .
218 $bold_begin. $msg->getSubject() . $bold_end .
219 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
224 '. $msg->getBody() .'
232 function showNestedMessage ( &$msg ) {
235 accepts a database result handle to display a single message
236 in the format appropriate for the nested messages
239 global $HTML,$group_id;
241 See if this message is new or not
242 If so, highlight it in bold
244 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
245 $bold_begin='<strong>';
246 $bold_end='</strong>';
251 $am = new AttachManager();
252 $msgforum =& $msg->getForum();
253 $fa = new ForumAdmin($msgforum->Group->getID());
254 $url = util_make_uri('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
256 '<table class="fullwidth">
258 <td class="tablecontent top" style="white-space: nowrap;">';
260 $params = array('user_id' => $msg->getPosterID(), 'size' => 's', 'content' => '');
261 plugin_hook_by_reference("user_logo", $params);
262 if ($params['content']) {
263 $ret_val .= $params['content'];
266 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("Reply").' ]</a>'. $bold_end;
267 $ret_val .= '<br/>'._('By')._(': ').util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
268 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
269 $ret_val .= '</td><td class="tablecontent align-right">';
270 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
271 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
272 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
274 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
281 if (strpos($msg->getBody(),'<') === false) {
282 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
284 $ret_val .= $msg->getBody();
294 * LinkAttachEditForm - Returns the link to the attach form for editing
296 * @param string $filename Filename
297 * @param int $group_id group id
298 * @param int $forum_id forum id
299 * @param int $attachid attach id
300 * @param int $msg_id msg id
302 * @return string The HTML output
305 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
308 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
311 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
315 <fieldset class=\"fieldset\">
319 <td>' . _('Use the “Browse” button to find the file you want to attach') . '</td>
322 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
325 <td class="warning">' . _('Warning: Uploaded file will replace current file') . '</td>
328 <input type="submit" name="go" value="'._('Update').'" />
329 <input type="hidden" name="doedit" value="1" />
330 <input type="hidden" name="edit" value="yes" />
331 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
332 <input type="hidden" name="group_id" value="'.$group_id.'" />
333 <input type="hidden" name="attachid" value="'.$attachid.'" />
334 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
342 * LinkAttachForm - echoes the link to the attach form
345 function LinkAttachForm() {
346 $poststarttime = time();
347 $posthash = md5($poststarttime . user_getid() );
349 <fieldset class="fieldset">
350 <legend>' . _('Attachments') . "</legend>
353 <td>" . _('Use the “Browse” button to find the file you want to attach') . "</td>
356 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
364 * @param string $msg_arr
365 * @param string $msg_id
368 function showNestedMessages ( &$msg_arr, $msg_id ) {
371 $rows=count($msg_arr["$msg_id"]);
374 if ($msg_arr["$msg_id"] && $rows > 0) {
376 <ul><li style="list-style: none">';
380 iterate and show the messages in this result
382 for each message, recurse to show any submessages
385 $am = new AttachManager();
386 for ($i=($rows-1); $i >= 0; $i--) {
387 // increment the global total count
390 // show the actual nested message
391 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
393 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
394 // Call yourself if there are followups
395 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
401 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
413 function showSubmessages(&$msg_arr, $msg_id, $level) {
415 Recursive. Selects this message's id in this thread,
416 then checks if any messages are nested underneath it.
417 If there are, it calls itself, incrementing $level
418 $level is used for indentation of the threads.
420 global $total_rows,$forum_id,$current_message,$group_id;
422 if (!isset($msg_arr["$msg_id"]))
425 $rows=count($msg_arr["$msg_id"]);
427 //echo "<p>ShowSubmessages() $msg_id | $rows";
429 for ($i=($rows-1); $i >= 0; $i--) {
431 Is this row's background shaded or not?
436 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
438 How far should it indent?
440 for ($i2=0; $i2<$level; $i2++) {
441 $ret_val .= ' ';
445 If it this is the message being displayed, don't show a link to it
447 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
448 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
455 $ret_val .= $ah_begin .
456 html_image('ic/msg.png').' ';
458 See if this message is new or not
460 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
461 $bold_begin='<strong>';
462 $bold_end='</strong>';
468 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
469 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
470 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
472 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
474 Call yourself, incrementing the level
476 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
484 * showEditForm - Prints the form to edit a message
486 * @param int $msg The Message
487 * @return The HTML output echoed
490 function showEditForm(&$msg) {
491 $thread_id = $msg->getThreadID();
492 $msg_id = $msg->getID();
493 $posted_by = $msg->getPosterID();
494 $subject = $msg->getSubject();
495 $body = $msg->getBody();
496 $post_date = $msg->getPostDate();
497 $is_followup_to = $msg->getParentID();
498 $has_followups = $msg->hasFollowups();
499 $most_recent_date = $msg->getMostRecentDate();
500 $g = $this->Forum->getGroup();
501 $group_id = $g->getID();
503 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
506 <div style="margin-left: auto; margin-right: auto;">
507 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
508 <?php $objid = $this->Forum->getID();?>
509 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
510 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
511 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
512 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
513 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
514 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
515 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
516 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
517 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
518 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
519 <fieldset class="fieldset">
520 <legend><?php echo _('Edit Message'); ?></legend>
521 <table><tr><td class="top">
522 </td><td class="top">
524 <strong><?php echo _('Subject')._(': '); ?></strong><?php echo utils_requiredField(); ?><br />
525 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
528 <strong><?php echo _('Message')._(': '); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?>
531 $GLOBALS['editor_was_set_up']=false;
533 $params['body'] = $body;
534 $params['width'] = "800";
535 $params['height'] = "500";
536 $params['group'] = $group_id;
537 plugin_hook("text_editor",$params);
538 if (!$GLOBALS['editor_was_set_up']) {
539 //if we don't have any plugin for text editor, display a simple textarea edit box
540 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
542 unset($GLOBALS['editor_was_set_up']);
545 <p style="text-align: center">
546 <input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
547 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
549 </td></tr></table></fieldset>
557 * @param int $thread_id
558 * @param int $is_followup_to
559 * @param string $subject
561 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
566 $rl = RoleLoggedIn::getInstance() ;
567 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
569 //if this is a followup, put a RE: before it if needed
570 if (!preg_match('/RE:/i',$subject,$test)) {
571 $subject ='RE: '.$subject;
577 <form id="ForumPostForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/forum.php?forum_id='.$this->Forum->getID().'&group_id='.$group_id); ?>" method="post">
578 <?php $objid = $this->Forum->getID();?>
579 <input type="hidden" name="post_message" value="y" />
580 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
581 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
582 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
583 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
584 <fieldset class="fieldset"><table><tr>
588 <strong><?php echo _('Subject')._(': '); ?></strong><?php echo utils_requiredField(); ?><br />
589 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
591 <strong><?php echo _('Message')._(': '); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
594 $GLOBALS['editor_was_set_up']=false;
596 $params['body'] = $body;
597 $params['width'] = "800";
598 $params['height'] = "500";
599 $params['group'] = $group_id;
600 plugin_hook("text_editor",$params);
601 if (!$GLOBALS['editor_was_set_up']) {
602 //if we don't have any plugin for text editor, display a simple textarea edit box
603 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
605 unset($GLOBALS['editor_was_set_up']);
606 //$text_support->displayTextField('body'); ?>
608 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
610 <?php $this->LinkAttachForm();?>
613 if (!session_loggedin()) {
614 echo '<span class="highlight">';
615 printf (_('You are posting anonymously because you are not <a href="%1$s">logged in</a>'),util_make_url ('/account/login.php?return_to='. urlencode(getStringFromServer('REQUEST_URI'))));
619 <input type="submit" name="submit"
620 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
621 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
631 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
632 echo '<span class="error">';
633 printf(_('You could post if you were <a href="%s">logged in</a>.'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
635 } elseif (!session_loggedin()) {
636 echo '<span class="error">';
637 printf(_('Please <a href="%s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
638 echo '</span><br/></p>';
646 // c-file-style: "bsd"