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-2014, 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_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_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 class="top" style="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 util_make_link('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1', html_image('ic/mail16w.png').' '._('Monitor Forum')).' | ';
152 if ($f && $forum_id) {
153 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
154 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
155 _('Start New Thread'));
159 function forum_footer($params = array()) {
160 site_project_footer($params);
165 * Wrap many forum functions in this class
168 class ForumHTML extends FFError {
176 function ForumHTML(&$Forum) {
177 parent::__construct();
178 if (!$Forum || !is_object($Forum)) {
179 $this->setError(_('Invalid Forum Object'));
182 if ($Forum->isError()) {
183 $this->setError('ForumMessage: '.$Forum->getErrorMessage());
186 $this->Forum =& $Forum;
191 * showPendingMessage - get the HTML code of a pending message
193 * @param object $msg The message.
194 * @return string return the html output
196 function showPendingMessage(&$msg) {
197 global $HTML,$group_id;
199 $am = new AttachManager();
200 $ret_val = $am->PrintHelperFunctions();
201 html_feedback_top(_('This is the content of the pending message'));
202 $bold_begin='<strong>';
203 $bold_end='</strong>';
207 <td class="tablecontent" style="white-space: nowrap;">'._('By')._(': ').
208 $msg->getPosterRealName().
211 $msgforum =& $msg->getForum();
212 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
215 html_image('ic/msg.png') .
216 $bold_begin. $msg->getSubject() . $bold_end .
217 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
222 '. $msg->getBody() .'
230 function showNestedMessage(&$msg) {
233 accepts a database result handle to display a single message
234 in the format appropriate for the nested messages
237 global $HTML,$group_id;
239 See if this message is new or not
240 If so, highlight it in bold
242 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
243 $bold_begin='<strong>';
244 $bold_end='</strong>';
249 $am = new AttachManager();
250 $msgforum =& $msg->getForum();
251 $fa = new ForumAdmin($msgforum->Group->getID());
252 $url = util_make_uri('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
254 '<table class="fullwidth">
256 <td class="tablecontent top" style="white-space: nowrap;">';
258 $params = array('user_id' => $msg->getPosterID(), 'size' => 's', 'content' => '');
259 plugin_hook_by_reference("user_logo", $params);
260 if ($params['content']) {
261 $ret_val .= $params['content'];
264 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("Reply").' ]</a>'. $bold_end;
265 $ret_val .= '<br/>'._('By')._(': ').util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
266 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
267 $ret_val .= '</td><td class="tablecontent align-right">';
268 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
269 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
270 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
272 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
279 if (strpos($msg->getBody(),'<') === false) {
280 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
282 $ret_val .= $msg->getBody();
292 * LinkAttachEditForm - Returns the link to the attach form for editing
294 * @param string $filename Filename
295 * @param int $group_id group id
296 * @param int $forum_id forum id
297 * @param int $attachid attach id
298 * @param int $msg_id msg id
299 * @return string The HTML output
301 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
305 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
308 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
312 <fieldset class=\"fieldset\">
316 <td>' . _('Use the “Browse” button to find the file you want to attach') . '</td>
319 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
322 <td>'.$HTML->warning_msg(_('Warning: Uploaded file will replace current file')).'</td>
325 <input type="submit" name="go" value="'._('Update').'" />
326 <input type="hidden" name="doedit" value="1" />
327 <input type="hidden" name="edit" value="yes" />
328 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
329 <input type="hidden" name="group_id" value="'.$group_id.'" />
330 <input type="hidden" name="attachid" value="'.$attachid.'" />
331 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
339 * LinkAttachForm - echoes the link to the attach form
341 function LinkAttachForm() {
342 $poststarttime = time();
343 $posthash = md5($poststarttime . user_getid() );
345 <fieldset class="fieldset">
346 <legend>' . _('Attachments') . "</legend>
349 <td>" . _('Use the “Browse” button to find the file you want to attach') . "</td>
352 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
360 * @param string $msg_arr
361 * @param string $msg_id
364 function showNestedMessages ( &$msg_arr, $msg_id ) {
367 $rows=count($msg_arr["$msg_id"]);
370 if ($msg_arr["$msg_id"] && $rows > 0) {
372 <ul><li style="list-style: none">';
376 iterate and show the messages in this result
378 for each message, recurse to show any submessages
381 $am = new AttachManager();
382 for ($i=($rows-1); $i >= 0; $i--) {
383 // increment the global total count
386 // show the actual nested message
387 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
389 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
390 // Call yourself if there are followups
391 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
397 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
409 function showSubmessages(&$msg_arr, $msg_id, $level) {
411 Recursive. Selects this message's id in this thread,
412 then checks if any messages are nested underneath it.
413 If there are, it calls itself, incrementing $level
414 $level is used for indentation of the threads.
416 global $total_rows,$forum_id,$current_message,$group_id;
418 if (!isset($msg_arr["$msg_id"]))
421 $rows=count($msg_arr["$msg_id"]);
423 //echo "<p>ShowSubmessages() $msg_id | $rows";
425 for ($i=($rows-1); $i >= 0; $i--) {
427 Is this row's background shaded or not?
432 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
434 How far should it indent?
436 for ($i2=0; $i2<$level; $i2++) {
437 $ret_val .= ' ';
441 If it this is the message being displayed, don't show a link to it
443 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
444 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
451 $ret_val .= $ah_begin .
452 html_image('ic/msg.png').' ';
454 See if this message is new or not
456 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
457 $bold_begin='<strong>';
458 $bold_end='</strong>';
464 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
465 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
466 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
468 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
470 Call yourself, incrementing the level
472 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
480 * showEditForm - Prints the form to edit a message
482 * @param int $msg The Message
483 * @return The HTML output echoed
485 function showEditForm(&$msg) {
486 $thread_id = $msg->getThreadID();
487 $msg_id = $msg->getID();
488 $posted_by = $msg->getPosterID();
489 $subject = $msg->getSubject();
490 $body = $msg->getBody();
491 $post_date = $msg->getPostDate();
492 $is_followup_to = $msg->getParentID();
493 $has_followups = $msg->hasFollowups();
494 $most_recent_date = $msg->getMostRecentDate();
495 $g = $this->Forum->getGroup();
496 $group_id = $g->getID();
498 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
501 <div style="margin-left: auto; margin-right: auto;">
502 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
503 <?php $objid = $this->Forum->getID();?>
504 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
505 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
506 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
507 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
508 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
509 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
510 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
511 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
512 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
513 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
514 <fieldset class="fieldset">
515 <legend><?php echo _('Edit Message'); ?></legend>
516 <table><tr><td class="top">
517 </td><td class="top">
519 <strong><?php echo _('Subject').utils_requiredField()._(':'); ?></strong><br />
520 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
523 <strong><?php echo _('Message').utils_requiredField()._(': '); ?></strong>
524 <?php echo notepad_button('document.forms.ForumEditForm.body'); ?>
527 $GLOBALS['editor_was_set_up']=false;
529 $params['body'] = $body;
530 $params['width'] = "800";
531 $params['height'] = "500";
532 $params['group'] = $group_id;
533 plugin_hook("text_editor",$params);
534 if (!$GLOBALS['editor_was_set_up']) {
535 //if we don't have any plugin for text editor, display a simple textarea edit box
536 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
538 unset($GLOBALS['editor_was_set_up']);
541 <p style="text-align: center">
542 <input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
543 <input type="submit" name="cancel" formnovalidate="formnovalidate" value="<?php echo _('Cancel'); ?>" />
545 </td></tr></table></fieldset>
553 * @param int $thread_id
554 * @param int $is_followup_to
555 * @param string $subject
557 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
562 $rl = RoleLoggedIn::getInstance() ;
563 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
565 //if this is a followup, put a RE: before it if needed
566 if (!preg_match('/RE:/i',$subject,$test)) {
567 $subject ='RE: '.$subject;
572 <div class="align-center">
573 <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">
574 <?php $objid = $this->Forum->getID();?>
575 <input type="hidden" name="post_message" value="y" />
576 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
577 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
578 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
579 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
580 <fieldset class="fieldset"><table><tr>
584 <strong><?php echo _('Subject').utils_requiredField()._(': '); ?></strong><br />
585 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
587 <strong><?php echo _('Message').utils_requiredField()._(': '); ?></strong>
588 <?php echo notepad_button('document.forms.ForumPostForm.body') ?><br />
591 $GLOBALS['editor_was_set_up']=false;
593 $params['body'] = $body;
594 $params['width'] = "800";
595 $params['height'] = "500";
596 $params['group'] = $group_id;
597 plugin_hook("text_editor",$params);
598 if (!$GLOBALS['editor_was_set_up']) {
599 //if we don't have any plugin for text editor, display a simple textarea edit box
600 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
602 unset($GLOBALS['editor_was_set_up']);
603 //$text_support->displayTextField('body'); ?>
605 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
607 <?php $this->LinkAttachForm();?>
610 if (!session_loggedin()) {
611 echo '<span class="highlight">';
612 printf (_('You are posting anonymously because you are not <a href="%s">logged in</a>'),util_make_url ('/account/login.php?return_to='. urlencode(getStringFromServer('REQUEST_URI'))));
616 <input type="submit" name="submit"
617 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
618 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive comments via email').'.' : ''); ?>
628 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
629 echo $HTML->error_msg(_('You could post if you were <a href="%s">logged in</a>.'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
630 } elseif (!session_loggedin()) {
631 echo $HTML->error_msg(_('Please <a href="%s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
639 // c-file-style: "bsd"