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);
167 Wrap many forum functions in this class
170 class ForumHTML extends Error {
178 function ForumHTML(&$Forum) {
180 if (!$Forum || !is_object($Forum)) {
181 $this->setError(_('Invalid Forum Object'));
184 if ($Forum->isError()) {
185 $this->setError('ForumMessage: '.$Forum->getErrorMessage());
188 $this->Forum =& $Forum;
194 * Function showPendingMessage
196 * @param object $msg The message.
198 * @return string return the html output
200 function showPendingMessage ( &$msg) {
201 global $HTML,$group_id;
203 $am = new AttachManager();
204 $ret_val = $am->PrintHelperFunctions();
205 html_feedback_top(_('This is the content of the pending message'));
206 $bold_begin='<strong>';
207 $bold_end='</strong>';
211 <td class="tablecontent" style="white-space: nowrap;">'._('By')._(': ').
212 $msg->getPosterRealName().
215 $msgforum =& $msg->getForum();
216 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
219 html_image('ic/msg.png') .
220 $bold_begin. $msg->getSubject() . $bold_end .
221 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
226 '. $msg->getBody() .'
234 function showNestedMessage ( &$msg ) {
237 accepts a database result handle to display a single message
238 in the format appropriate for the nested messages
241 global $HTML,$group_id;
243 See if this message is new or not
244 If so, highlight it in bold
246 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
247 $bold_begin='<strong>';
248 $bold_end='</strong>';
253 $am = new AttachManager();
254 $msgforum =& $msg->getForum();
255 $fa = new ForumAdmin($msgforum->Group->getID());
256 $url = util_make_uri('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
258 '<table class="fullwidth">
260 <td class="tablecontent top" style="white-space: nowrap;">';
262 $params = array('user_id' => $msg->getPosterID(), 'size' => 's', 'content' => '');
263 plugin_hook_by_reference("user_logo", $params);
264 if ($params['content']) {
265 $ret_val .= $params['content'];
268 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
269 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
270 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
271 $ret_val .= '</td><td class="tablecontent align-right">';
272 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
273 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
274 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
276 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
283 if (strpos($msg->getBody(),'<') === false) {
284 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
286 $ret_val .= $msg->getBody();
296 * LinkAttachEditForm - Returns the link to the attach form for editing
298 * @param string $filename Filename
299 * @param int $group_id group id
300 * @param int $forum_id forum id
301 * @param int $attachid attach id
302 * @param int $msg_id msg id
304 * @return string The HTML output
307 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
310 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
313 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
317 <fieldset class=\"fieldset\">
321 <td>' . _('Use the “Browse” button to find the file you want to attach') . '</td>
324 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
327 <td class="warning">' . _('Warning: Uploaded file will replace current file') . '</td>
330 <input type="submit" name="go" value="'._('Update').'" />
331 <input type="hidden" name="doedit" value="1" />
332 <input type="hidden" name="edit" value="yes" />
333 <input type="hidden" name="forum_id" value="'.$forum_id.'" />
334 <input type="hidden" name="group_id" value="'.$group_id.'" />
335 <input type="hidden" name="attachid" value="'.$attachid.'" />
336 <input type="hidden" name="msg_id" value="'.$msg_id.'" />
344 * LinkAttachForm - echoes the link to the attach form
347 function LinkAttachForm() {
348 $poststarttime = time();
349 $posthash = md5($poststarttime . user_getid() );
351 <fieldset class="fieldset">
352 <legend>' . _('Attachments') . "</legend>
355 <td>" . _('Use the “Browse” button to find the file you want to attach') . "</td>
358 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
367 * @param string $msg_arr
368 * @param string $msg_id
371 function showNestedMessages ( &$msg_arr, $msg_id ) {
374 $rows=count($msg_arr["$msg_id"]);
377 if ($msg_arr["$msg_id"] && $rows > 0) {
379 <ul><li style="list-style: none">';
383 iterate and show the messages in this result
385 for each message, recurse to show any submessages
388 $am = new AttachManager();
389 for ($i=($rows-1); $i >= 0; $i--) {
390 // increment the global total count
393 // show the actual nested message
394 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
396 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
397 // Call yourself if there are followups
398 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
404 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
416 function showSubmessages(&$msg_arr, $msg_id, $level) {
418 Recursive. Selects this message's id in this thread,
419 then checks if any messages are nested underneath it.
420 If there are, it calls itself, incrementing $level
421 $level is used for indentation of the threads.
423 global $total_rows,$forum_id,$current_message,$group_id;
425 if (!isset($msg_arr["$msg_id"]))
428 $rows=count($msg_arr["$msg_id"]);
430 //echo "<p>ShowSubmessages() $msg_id | $rows";
432 for ($i=($rows-1); $i >= 0; $i--) {
434 Is this row's background shaded or not?
439 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
441 How far should it indent?
443 for ($i2=0; $i2<$level; $i2++) {
444 $ret_val .= ' ';
448 If it this is the message being displayed, don't show a link to it
450 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
451 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
458 $ret_val .= $ah_begin .
459 html_image('ic/msg.png').' ';
461 See if this message is new or not
463 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
464 $bold_begin='<strong>';
465 $bold_end='</strong>';
471 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
472 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
473 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
475 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
477 Call yourself, incrementing the level
479 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
487 * showEditForm - Prints the form to edit a message
489 * @param int $msg The Message
490 * @return The HTML output echoed
493 function showEditForm(&$msg) {
494 $thread_id = $msg->getThreadID();
495 $msg_id = $msg->getID();
496 $posted_by = $msg->getPosterID();
497 $subject = $msg->getSubject();
498 $body = $msg->getBody();
499 $post_date = $msg->getPostDate();
500 $is_followup_to = $msg->getParentID();
501 $has_followups = $msg->hasFollowups();
502 $most_recent_date = $msg->getMostRecentDate();
503 $g = $this->Forum->getGroup();
504 $group_id = $g->getID();
506 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
509 <div style="margin-left: auto; margin-right: auto;">
510 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
511 <?php $objid = $this->Forum->getID();?>
512 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
513 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
514 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
515 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
516 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
517 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
518 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
519 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
520 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
521 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
522 <fieldset class="fieldset">
523 <legend><?php echo _('Edit Message'); ?></legend>
524 <table><tr><td class="top">
525 </td><td class="top">
527 <strong><?php echo _('Subject')._(': '); ?></strong><?php echo utils_requiredField(); ?><br />
528 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
531 <strong><?php echo _('Message')._(': '); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?>
534 $GLOBALS['editor_was_set_up']=false;
536 $params['body'] = $body;
537 $params['width'] = "800";
538 $params['height'] = "500";
539 $params['group'] = $group_id;
540 plugin_hook("text_editor",$params);
541 if (!$GLOBALS['editor_was_set_up']) {
542 //if we don't have any plugin for text editor, display a simple textarea edit box
543 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
545 unset($GLOBALS['editor_was_set_up']);
548 <p style="text-align: center">
549 <input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
550 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
552 </td></tr></table></fieldset>
560 * @param int $thread_id
561 * @param int $is_followup_to
562 * @param string $subject
564 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
569 $rl = RoleLoggedIn::getInstance() ;
570 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
572 //if this is a followup, put a RE: before it if needed
573 if (!preg_match('/RE:/i',$subject,$test)) {
574 $subject ='RE: '.$subject;
580 <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">
581 <?php $objid = $this->Forum->getID();?>
582 <input type="hidden" name="post_message" value="y" />
583 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
584 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
585 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
586 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
587 <fieldset class="fieldset"><table><tr>
591 <strong><?php echo _('Subject')._(': '); ?></strong><?php echo utils_requiredField(); ?><br />
592 <input type="text" autofocus="autofocus" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
594 <strong><?php echo _('Message')._(': '); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
597 $GLOBALS['editor_was_set_up']=false;
599 $params['body'] = $body;
600 $params['width'] = "800";
601 $params['height'] = "500";
602 $params['group'] = $group_id;
603 plugin_hook("text_editor",$params);
604 if (!$GLOBALS['editor_was_set_up']) {
605 //if we don't have any plugin for text editor, display a simple textarea edit box
606 echo '<textarea required="required" name="body" rows="10" cols="70">' . $body . '</textarea>';
608 unset($GLOBALS['editor_was_set_up']);
609 //$text_support->displayTextField('body'); ?>
611 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
613 <?php $this->LinkAttachForm();?>
616 if (!session_loggedin()) {
617 echo '<span class="highlight">';
618 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')))) .'</span>';
621 <input type="submit" name="submit"
622 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
623 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
633 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
634 echo '<span class="error">';
635 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'))));
637 } elseif (!session_loggedin()) {
638 echo '<span class="error">';
639 printf(_('Please <a href="%s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
640 echo '</span><br/></p>';
648 // c-file-style: "bsd"