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('ForumMessage:: No Valid Forum Object');
184 if ($Forum->isError()) {
185 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
188 $this->Forum =& $Forum;
194 * Function showPendingMessage
196 * @param object The message.
198 * @return returns 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, highlite 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
299 * @param int group id
300 * @param int forum id
301 * @param int attach id
304 * @return 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
346 * @return The HTML output echoed
349 function LinkAttachForm() {
350 $poststarttime = time();
351 $posthash = md5($poststarttime . user_getid() );
353 <fieldset class=\"fieldset\">
356 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
359 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
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>";
407 function showSubmessages(&$msg_arr, $msg_id, $level) {
409 Recursive. Selects this message's id in this thread,
410 then checks if any messages are nested underneath it.
411 If there are, it calls itself, incrementing $level
412 $level is used for indentation of the threads.
414 global $total_rows,$forum_id,$current_message,$group_id;
416 if (!isset($msg_arr["$msg_id"]))
419 $rows=count($msg_arr["$msg_id"]);
421 //echo "<p>ShowSubmessages() $msg_id | $rows";
423 for ($i=($rows-1); $i >= 0; $i--) {
425 Is this row's background shaded or not?
430 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
432 How far should it indent?
434 for ($i2=0; $i2<$level; $i2++) {
435 $ret_val .= ' ';
439 If it this is the message being displayed, don't show a link to it
441 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
442 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
449 $ret_val .= $ah_begin .
450 html_image('ic/msg.png').' ';
452 See if this message is new or not
454 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
455 $bold_begin='<strong>';
456 $bold_end='</strong>';
462 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
463 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
464 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
466 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
468 Call yourself, incrementing the level
470 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
478 * showEditForm - Prints the form to edit a message
480 * @param int The Message
481 * @return The HTML output echoed
484 function showEditForm(&$msg) {
485 $thread_id = $msg->getThreadID();
486 $msg_id = $msg->getID();
487 $posted_by = $msg->getPosterID();
488 $subject = $msg->getSubject();
489 $body = $msg->getBody();
490 $post_date = $msg->getPostDate();
491 $is_followup_to = $msg->getParentID();
492 $has_followups = $msg->hasFollowups();
493 $most_recent_date = $msg->getMostRecentDate();
494 $g =& $this->Forum->getGroup();
495 $group_id = $g->getID();
497 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
501 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
502 <?php $objid = $this->Forum->getID();?>
503 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
504 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
505 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
506 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
507 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
508 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
509 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
510 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
511 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
512 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
513 <fieldset class="fieldset">
514 <table><tr><td valign="top">
515 </td><td valign="top">
517 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
518 <input type="text" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
520 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
522 $GLOBALS['editor_was_set_up']=false;
524 $params['body'] = $body;
525 $params['width'] = "800";
526 $params['height'] = "500";
527 $params['group'] = $group_id;
528 plugin_hook("text_editor",$params);
529 if (!$GLOBALS['editor_was_set_up']) {
530 //if we don't have any plugin for text editor, display a simple textarea edit box
531 echo '<textarea name="body" required="required" rows="10" cols="70">' . $body . '</textarea>';
533 unset($GLOBALS['editor_was_set_up']);
538 <?php //$this->LinkAttachForm();?>
545 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
546 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
549 </td></tr></table></fieldset>
556 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
561 $rl = RoleLoggedIn::getInstance() ;
562 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
564 //if this is a followup, put a RE: before it if needed
565 if (!preg_match('/RE:/i',$subject,$test)) {
566 $subject ='RE: '.$subject;
572 <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">
573 <?php $objid = $this->Forum->getID();?>
574 <input type="hidden" name="post_message" value="y" />
575 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
576 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
577 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
578 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
579 <fieldset class="fieldset"><table><tr><td valign="top">
580 </td><td valign="top">
582 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
583 <input type="text" required="required" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
585 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
588 $GLOBALS['editor_was_set_up']=false;
590 $params['body'] = $body;
591 $params['width'] = "800";
592 $params['height'] = "500";
593 $params['group'] = $group_id;
594 plugin_hook("text_editor",$params);
595 if (!$GLOBALS['editor_was_set_up']) {
596 //if we don't have any plugin for text editor, display a simple textarea edit box
597 echo '<textarea name="body" required="required" rows="10" cols="70">' . $body . '</textarea>';
599 unset($GLOBALS['editor_was_set_up']);
600 ?> <?php //$text_support->displayTextField('body'); ?> <br>
602 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
603 <p><?php $this->LinkAttachForm();?>
607 if (!session_loggedin()) {
608 echo '<span class="highlight">';
609 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>';
612 <input type="submit" name="submit"
613 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
614 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
624 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
625 echo '<span class="error">';
626 printf(_('You could post if you were <a href="%1$s">logged in</a>.'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
628 } elseif (!session_loggedin()) {
629 echo '<span class="error">';
630 printf(_('Please <a href="%1$s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
631 echo '</span><br/></p>';
639 // c-file-style: "bsd"