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> '. relative_date(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'));
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, highlite 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
295 * @param int group id
296 * @param int forum id
297 * @param int attach id
300 * @return The HTML output
303 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
306 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
309 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
313 <fieldset class=\"fieldset\">
317 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
320 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
323 <td class="warning">' . _('Warning: Uploaded file will replace current file') . '</td>
326 <input type="submit" name="go" value="'._('Update').'" />
327 <input type="hidden" name="doedit" value="1"/>
328 <input type="hidden" name="edit" value="yes"/>
329 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
330 <input type="hidden" name="group_id" value="'.$group_id.'"/>
331 <input type="hidden" name="attachid" value="'.$attachid.'"/>
332 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
340 * LinkAttachForm - echoes the link to the attach form
342 * @return The HTML output echoed
345 function LinkAttachForm() {
346 $poststarttime = time();
347 $posthash = md5($poststarttime . user_getid() );
349 <fieldset class=\"fieldset\">
352 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
355 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
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>";
403 function showSubmessages(&$msg_arr, $msg_id, $level) {
405 Recursive. Selects this message's id in this thread,
406 then checks if any messages are nested underneath it.
407 If there are, it calls itself, incrementing $level
408 $level is used for indentation of the threads.
410 global $total_rows,$forum_id,$current_message,$group_id;
412 if (!isset($msg_arr["$msg_id"]))
415 $rows=count($msg_arr["$msg_id"]);
417 //echo "<p>ShowSubmessages() $msg_id | $rows";
419 for ($i=($rows-1); $i >= 0; $i--) {
421 Is this row's background shaded or not?
426 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
428 How far should it indent?
430 for ($i2=0; $i2<$level; $i2++) {
431 $ret_val .= ' ';
435 If it this is the message being displayed, don't show a link to it
437 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
438 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
445 $ret_val .= $ah_begin .
446 html_image('ic/msg.png').' ';
448 See if this message is new or not
450 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
451 $bold_begin='<strong>';
452 $bold_end='</strong>';
458 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
459 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
460 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
462 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
464 Call yourself, incrementing the level
466 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
474 * showEditForm - Prints the form to edit a message
476 * @param int The Message
477 * @return The HTML output echoed
480 function showEditForm(&$msg) {
481 $thread_id = $msg->getThreadID();
482 $msg_id = $msg->getID();
483 $posted_by = $msg->getPosterID();
484 $subject = $msg->getSubject();
485 $body = $msg->getBody();
486 $post_date = $msg->getPostDate();
487 $is_followup_to = $msg->getParentID();
488 $has_followups = $msg->hasFollowups();
489 $most_recent_date = $msg->getMostRecentDate();
490 $g =& $this->Forum->getGroup();
491 $group_id = $g->getID();
493 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
497 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
498 <?php $objid = $this->Forum->getID();?>
499 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
500 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
501 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
502 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
503 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
504 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
505 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
506 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
507 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
508 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
509 <fieldset class="fieldset">
510 <table><tr><td valign="top">
511 </td><td valign="top">
513 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
514 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
516 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
518 $GLOBALS['editor_was_set_up']=false;
520 $params['body'] = $body;
521 $params['width'] = "800";
522 $params['height'] = "500";
523 $params['group'] = $group_id;
524 plugin_hook("text_editor",$params);
525 if (!$GLOBALS['editor_was_set_up']) {
526 //if we don't have any plugin for text editor, display a simple textarea edit box
527 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
529 unset($GLOBALS['editor_was_set_up']);
534 <?php //$this->LinkAttachForm();?>
541 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
542 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
545 </td></tr></table></fieldset>
552 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
557 $rl = RoleLoggedIn::getInstance() ;
558 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
560 //if this is a followup, put a RE: before it if needed
561 if (!preg_match('/RE:/i',$subject,$test)) {
562 $subject ='RE: '.$subject;
568 <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">
569 <?php $objid = $this->Forum->getID();?>
570 <input type="hidden" name="post_message" value="y" />
571 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
572 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
573 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
574 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
575 <fieldset class="fieldset"><table><tr><td valign="top">
576 </td><td valign="top">
578 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
579 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
581 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
584 $GLOBALS['editor_was_set_up']=false;
586 $params['body'] = $body;
587 $params['width'] = "800";
588 $params['height'] = "500";
589 $params['group'] = $group_id;
590 plugin_hook("text_editor",$params);
591 if (!$GLOBALS['editor_was_set_up']) {
592 //if we don't have any plugin for text editor, display a simple textarea edit box
593 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
595 unset($GLOBALS['editor_was_set_up']);
596 ?> <?php //$text_support->displayTextField('body'); ?> <br>
598 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
599 <p><?php $this->LinkAttachForm();?>
603 if (!session_loggedin()) {
604 echo '<span class="highlight">';
605 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>';
608 <input type="submit" name="submit"
609 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
610 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
620 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
621 echo '<span class="error">';
622 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'))));
624 } elseif (!session_loggedin()) {
625 echo '<span class="error">';
626 printf(_('Please <a href="%1$s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
627 echo '</span><br/></p>';
635 // c-file-style: "bsd"