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-2011 Alain Peyrat - Alcatel-Lucent
9 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 require_once $gfwww.'include/note.php';
28 require_once $gfwww.'include/trove.php';
29 require_once $gfwww.'news/news_utils.php';
30 require_once $gfcommon.'forum/ForumAdmin.class.php';
31 require_once $gfcommon.'forum/AttachManager.class.php';
33 function forum_header($params) {
34 global $HTML, $group_id, $forum_name, $forum_id, $f, $group_forum_id;
36 if ($group_forum_id) {
37 $forum_id = $group_forum_id;
39 if (!forge_get_config('use_forum')) {
43 $params['group'] = $group_id;
44 $params['toptab'] = 'forums';
47 // Check if this is a news item, to display it at the top of the page
48 $result = db_query_params('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
51 if (db_numrows($result) == 1) {
53 // checks which group the news item belongs to
54 $params['group'] = db_result($result, 0, 'group_id');
55 $params['toptab'] = 'news';
56 $params['title'] = _('Forum: ') . db_result($result,0,'summary');
57 $HTML->header($params);
59 echo '<table><tr><td valign="top">';
60 $user = user_get_object(db_result($result,0,'submitted_by'));
61 $group = group_get_object($params['group']);
62 if (!$group || !is_object($group) || $group->isError()) {
66 <strong>'._('Posted by').':</strong> '.$user->getRealName().'<br />
67 <strong>'._('Date').':</strong> '. date(_('Y-m-d H:i'),db_result($result,0,'post_date')).'<br />
68 <strong>'._('Summary').':</strong>'.
69 util_make_link('/forum/forum.php?forum_id='.db_result($result, 0, 'forum_id').'&group_id='.$group_id,
70 db_result($result, 0, 'summary')).'<br/>
71 <strong>'._('Project').':</strong>'.
72 util_make_link_g($group->getUnixName(),db_result($result, 0, 'group_id'),$group->getPublicName()).'<br />
75 $body = db_result($result,0,'details');
76 $body = TextSanitizer::purify($body);
77 if (!strstr($body,'<')) {
78 //backwards compatibility for non html messages
79 echo util_make_links(nl2br($body));
81 echo util_make_links($body);
84 // display classification
85 if ($params['group'] == forge_get_config('news_group')) {
86 print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
87 } elseif (forge_get_config('use_trove')) {
88 print stripslashes(trove_getcatlisting($params['group'],0,1));
90 echo '</td><td valign="top" width="35%">';
91 echo $HTML->boxTop(_('Latest News'));
92 echo news_show_latest($params['group'],5,false);
93 echo $HTML->boxBottom();
94 echo '</td></tr></table>';
96 $HTML->header($params);
100 $menu_links = array();
102 $menu_text[] = _('View Forums');
103 $menu_links[] = '/forum/?group_id='.$group_id;
107 $menu_text[]=_('Discussion Forums:') .' '. $f->getName();
108 $menu_links[]='/forum/forum.php?forum_id='.$forum_id;
110 if (forge_check_perm ('forum_admin', $f->Group->getID())) {
111 $menu_text[]=_('Administration');
112 $menu_links[]='/forum/admin/?group_id='.$group_id;
115 $gg=group_get_object($group_id);
116 if (forge_check_perm ('forum_admin', $group_id)) {
117 $menu_text[]=_('Administration');
118 $menu_links[]='/forum/admin/?group_id='.$group_id;
121 if (count($menu_text) > 0) {
122 $params['submenu'] =$HTML->subMenu($menu_text,$menu_links);
125 site_project_header($params);
128 $pluginManager = plugin_manager_get_object();
129 if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
132 if (session_loggedin() ) {
134 if ($f->isMonitoring()) {
135 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
136 html_image('ic/xmail16w.png').' '._('Stop Monitoring')).' | ';
138 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
139 html_image('ic/mail16w.png').' '._('Monitor Forum')).' | ';
141 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
142 html_image('ic/save.png') .' '._('Save Place')).' | ';
145 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
146 html_image('ic/mail16w.png').' '._('Monitor Forum').'</a> | ';
149 if ($f && $forum_id) {
150 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
151 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
152 _('Start New Thread'));
156 function forum_footer($params) {
157 site_project_footer($params);
163 Wrap many forum functions in this class
166 class ForumHTML extends Error {
174 function ForumHTML(&$Forum) {
176 if (!$Forum || !is_object($Forum)) {
177 $this->setError('ForumMessage:: No Valid Forum Object');
180 if ($Forum->isError()) {
181 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
184 $this->Forum =& $Forum;
190 * Function showPendingMessage
192 * @param object The message.
194 * @return returns 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'));
205 <td class="tablecontent" style="white-space: nowrap;">'._('By:').
206 $msg->getPosterRealName().
209 $msgforum =& $msg->getForum();
210 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
213 html_image('ic/msg.png') .
214 $bold_begin. $msg->getSubject() . $bold_end .' '.
215 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
220 '. $msg->getBody() .'
228 function showNestedMessage ( &$msg ) {
231 accepts a database result handle to display a single message
232 in the format appropriate for the nested messages
235 global $HTML,$group_id;
237 See if this message is new or not
238 If so, highlite it in bold
240 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
241 $bold_begin='<strong>';
242 $bold_end='</strong>';
247 $am = new AttachManager();
248 $msgforum =& $msg->getForum();
249 $fa = new ForumAdmin($msgforum->Group->getID());
250 $url = util_make_uri('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
252 '<table border="0" width="100%" cellspacing="0">
254 <td class="tablecontent" style="white-space: nowrap;" valign="top">';
256 $params = array('user_id' => $msg->getPosterID(), 'size' => 's', 'content' => '');
257 plugin_hook_by_reference("user_logo", $params);
258 if ($params['content']) {
259 $ret_val .= $params['content'];
262 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
263 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
264 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
265 $ret_val .= '</td><td class="tablecontent" align="right">';
266 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
267 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
268 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
270 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
277 if (strpos($msg->getBody(),'<') === false) {
278 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
280 $ret_val .= $msg->getBody();
290 * LinkAttachEditForm - Returns the link to the attach form for editing
292 * @param string Filename
293 * @param int group id
294 * @param int forum id
295 * @param int attach id
298 * @return The HTML output
301 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
304 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
307 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
311 <fieldset class=\"fieldset\">
315 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
318 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
321 <td class="warning">' . _('Warning: Uploaded file will replace current file') . '</td>
324 <input type="submit" name="go" value="'._('Update').'" />
325 <input type="hidden" name="doedit" value="1"/>
326 <input type="hidden" name="edit" value="yes"/>
327 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
328 <input type="hidden" name="group_id" value="'.$group_id.'"/>
329 <input type="hidden" name="attachid" value="'.$attachid.'"/>
330 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
338 * LinkAttachForm - echoes the link to the attach form
340 * @return The HTML output echoed
343 function LinkAttachForm() {
344 $poststarttime = time();
345 $posthash = md5($poststarttime . user_getid() );
347 <fieldset class=\"fieldset\">
350 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
353 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
362 function showNestedMessages ( &$msg_arr, $msg_id ) {
365 $rows=count($msg_arr["$msg_id"]);
368 if ($msg_arr["$msg_id"] && $rows > 0) {
370 <ul><li style="list-style: none">';
374 iterate and show the messages in this result
376 for each message, recurse to show any submessages
379 $am = new AttachManager();
380 for ($i=($rows-1); $i >= 0; $i--) {
381 // increment the global total count
384 // show the actual nested message
385 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
387 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
388 // Call yourself if there are followups
389 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
395 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
401 function showSubmessages(&$msg_arr, $msg_id, $level) {
403 Recursive. Selects this message's id in this thread,
404 then checks if any messages are nested underneath it.
405 If there are, it calls itself, incrementing $level
406 $level is used for indentation of the threads.
408 global $total_rows,$forum_id,$current_message,$group_id;
410 if (!isset($msg_arr["$msg_id"]))
413 $rows=count($msg_arr["$msg_id"]);
415 //echo "<p>ShowSubmessages() $msg_id | $rows";
417 for ($i=($rows-1); $i >= 0; $i--) {
419 Is this row's background shaded or not?
424 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
426 How far should it indent?
428 for ($i2=0; $i2<$level; $i2++) {
429 $ret_val .= ' ';
433 If it this is the message being displayed, don't show a link to it
435 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
436 $ah_begin='<a href="'.util_make_url ('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
443 $ret_val .= $ah_begin .
444 html_image('ic/msg.png').' ';
446 See if this message is new or not
448 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
449 $bold_begin='<strong>';
450 $bold_end='</strong>';
456 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
457 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
458 '<td>'.date(_('Y-m-d H:i'), $msg_arr[$msg_id][$i]->getPostDate() ).'</td></tr>';
460 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
462 Call yourself, incrementing the level
464 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
472 * showEditForm - Prints the form to edit a message
474 * @param int The Message
475 * @return The HTML output echoed
478 function showEditForm(&$msg) {
479 $thread_id = $msg->getThreadID();
480 $msg_id = $msg->getID();
481 $posted_by = $msg->getPosterID();
482 $subject = $msg->getSubject();
483 $body = $msg->getBody();
484 $post_date = $msg->getPostDate();
485 $is_followup_to = $msg->getParentID();
486 $has_followups = $msg->hasFollowups();
487 $most_recent_date = $msg->getMostRecentDate();
488 $g =& $this->Forum->getGroup();
489 $group_id = $g->getID();
491 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
495 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
496 <?php $objid = $this->Forum->getID();?>
497 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
498 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
499 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
500 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
501 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
502 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
503 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
504 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
505 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
506 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
507 <fieldset class="fieldset">
508 <table><tr><td valign="top">
509 </td><td valign="top">
511 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
512 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
514 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
516 $GLOBALS['editor_was_set_up']=false;
518 $params['body'] = $body;
519 $params['width'] = "800";
520 $params['height'] = "500";
521 $params['group'] = $group_id;
522 plugin_hook("text_editor",$params);
523 if (!$GLOBALS['editor_was_set_up']) {
524 //if we don't have any plugin for text editor, display a simple textarea edit box
525 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
527 unset($GLOBALS['editor_was_set_up']);
532 <?php //$this->LinkAttachForm();?>
539 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
540 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
543 </td></tr></table></fieldset>
550 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
555 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
557 //if this is a followup, put a RE: before it if needed
558 if (!preg_match('/RE:/i',$subject,$test)) {
559 $subject ='RE: '.$subject;
565 <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">
566 <?php $objid = $this->Forum->getID();?>
567 <input type="hidden" name="post_message" value="y" />
568 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
569 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
570 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
571 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
572 <fieldset class="fieldset"><table><tr><td valign="top">
573 </td><td valign="top">
575 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
576 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
578 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
581 $GLOBALS['editor_was_set_up']=false;
583 $params['body'] = $body;
584 $params['width'] = "800";
585 $params['height'] = "500";
586 $params['group'] = $group_id;
587 plugin_hook("text_editor",$params);
588 if (!$GLOBALS['editor_was_set_up']) {
589 //if we don't have any plugin for text editor, display a simple textarea edit box
590 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
592 unset($GLOBALS['editor_was_set_up']);
593 ?> <?php //$text_support->displayTextField('body'); ?> <br>
595 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
596 <p><?php $this->LinkAttachForm();?>
600 if (!session_loggedin()) {
601 echo '<span class="highlight">';
602 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>';
605 <input type="submit" name="submit"
606 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
607 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
617 } elseif ($this->Forum->allowAnonymous()) {
618 echo '<span class="error">';
619 printf(_('You could post if you were <a href="%1$s">logged in</a>.'), util_make_url ('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
621 } elseif (!session_loggedin()) {
622 echo '<span class="error">';
623 printf(_('Please <a href="%1$s">log in</a>'), util_make_url('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
624 echo '</span><br/></p>';
632 // c-file-style: "bsd"