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 * http://fusionforge.org
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 require_once $gfwww.'include/note.php';
29 require_once $gfwww.'include/trove.php';
30 require_once $gfwww.'news/news_utils.php';
31 require_once $gfcommon.'forum/ForumAdmin.class.php';
32 require_once $gfcommon.'forum/AttachManager.class.php';
34 function forum_header($params) {
35 global $HTML, $group_id, $forum_name, $forum_id, $f, $group_forum_id;
37 if ($group_forum_id) {
38 $forum_id = $group_forum_id;
40 if (!forge_get_config('use_forum')) {
44 $params['group'] = $group_id;
45 $params['toptab'] = 'forums';
48 // Check if this is a news item, to display it at the top of the page
49 $result = db_query_params('SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id=$1',
52 if (db_numrows($result) == 1) {
54 // checks which group the news item belongs to
55 $params['group'] = db_result($result, 0, 'group_id');
56 $params['toptab'] = 'news';
57 $params['title'] = _('Forum: ') . db_result($result,0,'summary');
58 $HTML->header($params);
60 echo '<table><tr><td class="top">';
61 $user = user_get_object(db_result($result,0,'submitted_by'));
62 $group = group_get_object($params['group']);
63 if (!$group || !is_object($group) || $group->isError()) {
67 <strong>'._('Posted by:').'</strong> '.$user->getRealName().'<br />
68 <strong>'._('Date').':</strong> '. relative_date(db_result($result,0,'post_date')).'<br />
69 <strong>'._('Summary').':</strong>'.
70 util_make_link('/forum/forum.php?forum_id='.db_result($result, 0, 'forum_id').'&group_id='.$group_id,
71 db_result($result, 0, 'summary')).'<br/>
72 <strong>'._('Project')._(': ').'</strong>'.
73 util_make_link_g($group->getUnixName(),db_result($result, 0, 'group_id'),$group->getPublicName()).'<br />
77 // display classification
78 if ($params['group'] == forge_get_config('news_group')) {
79 print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
80 } elseif (forge_get_config('use_trove')) {
81 print stripslashes(trove_getcatlisting($params['group'],0,1));
84 echo '<p><strong>'._('Content:').'</strong></p>';
85 $body = db_result($result,0,'details');
86 $body = TextSanitizer::purify($body);
87 if (!strstr($body,'<')) {
88 //backwards compatibility for non html messages
89 echo util_make_links(nl2br($body));
91 echo util_make_links($body);
93 echo '</td><td valign="top" width="35%">';
94 echo $HTML->boxTop(_('Latest News'));
95 echo news_show_latest($params['group'],5,false);
96 echo $HTML->boxBottom();
97 echo '</td></tr></table>';
99 $HTML->header($params);
102 $menu_text = array();
103 $menu_links = array();
105 $menu_text[] = _('View Forums');
106 $menu_links[] = '/forum/?group_id='.$group_id;
110 $menu_text[]=_('Discussion Forums:') .' '. $f->getName();
111 $menu_links[]='/forum/forum.php?forum_id='.$forum_id;
113 if (forge_check_perm ('forum_admin', $f->Group->getID())) {
114 $menu_text[]=_('Administration');
115 $menu_links[]='/forum/admin/?group_id='.$group_id;
118 $gg=group_get_object($group_id);
119 if (forge_check_perm ('forum_admin', $group_id)) {
120 $menu_text[]=_('Administration');
121 $menu_links[]='/forum/admin/?group_id='.$group_id;
124 if (count($menu_text) > 0) {
125 $params['submenu'] =$HTML->subMenu($menu_text,$menu_links);
128 site_project_header($params);
131 $pluginManager = plugin_manager_get_object();
132 if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
135 if (session_loggedin() ) {
137 if ($f->isMonitoring()) {
138 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
139 html_image('ic/xmail16w.png').' '._('Stop Monitoring')).' | ';
141 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
142 html_image('ic/mail16w.png').' '._('Monitor Forum')).' | ';
144 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
145 html_image('ic/save.png') .' '._('Save Place')).' | ';
148 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
149 html_image('ic/mail16w.png').' '._('Monitor Forum').'</a> | ';
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) {
160 site_project_footer($params);
166 Wrap many forum functions in this class
169 class ForumHTML extends Error {
177 function ForumHTML(&$Forum) {
179 if (!$Forum || !is_object($Forum)) {
180 $this->setError('ForumMessage:: No Valid Forum Object');
183 if ($Forum->isError()) {
184 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
187 $this->Forum =& $Forum;
193 * Function showPendingMessage
195 * @param object The message.
197 * @return returns the html output
199 function showPendingMessage ( &$msg) {
200 global $HTML,$group_id;
202 $am = new AttachManager();
203 $ret_val = $am->PrintHelperFunctions();
204 html_feedback_top(_('This is the content of the pending message'));
205 $bold_begin='<strong>';
206 $bold_end='</strong>';
210 <td class="tablecontent" style="white-space: nowrap;">'._('By:').
211 $msg->getPosterRealName().
214 $msgforum =& $msg->getForum();
215 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
218 html_image('ic/msg.png') .
219 $bold_begin. $msg->getSubject() . $bold_end .
220 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
225 '. $msg->getBody() .'
233 function showNestedMessage ( &$msg ) {
236 accepts a database result handle to display a single message
237 in the format appropriate for the nested messages
240 global $HTML,$group_id;
242 See if this message is new or not
243 If so, highlite it in bold
245 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
246 $bold_begin='<strong>';
247 $bold_end='</strong>';
252 $am = new AttachManager();
253 $msgforum =& $msg->getForum();
254 $fa = new ForumAdmin($msgforum->Group->getID());
255 $url = util_make_uri('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
257 '<table class="fullwidth">
259 <td class="tablecontent top" style="white-space: nowrap;">';
261 $params = array('user_id' => $msg->getPosterID(), 'size' => 's', 'content' => '');
262 plugin_hook_by_reference("user_logo", $params);
263 if ($params['content']) {
264 $ret_val .= $params['content'];
267 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
268 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
269 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
270 $ret_val .= '</td><td class="tablecontent align-right">';
271 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
272 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
273 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
275 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
282 if (strpos($msg->getBody(),'<') === false) {
283 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
285 $ret_val .= $msg->getBody();
295 * LinkAttachEditForm - Returns the link to the attach form for editing
297 * @param string Filename
298 * @param int group id
299 * @param int forum id
300 * @param int attach id
303 * @return The HTML output
306 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
309 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
312 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
316 <fieldset class=\"fieldset\">
320 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
323 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
326 <td class="warning">' . _('Warning: Uploaded file will replace current file') . '</td>
329 <input type="submit" name="go" value="'._('Update').'" />
330 <input type="hidden" name="doedit" value="1"/>
331 <input type="hidden" name="edit" value="yes"/>
332 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
333 <input type="hidden" name="group_id" value="'.$group_id.'"/>
334 <input type="hidden" name="attachid" value="'.$attachid.'"/>
335 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
343 * LinkAttachForm - echoes the link to the attach form
345 * @return The HTML output echoed
348 function LinkAttachForm() {
349 $poststarttime = time();
350 $posthash = md5($poststarttime . user_getid() );
352 <fieldset class=\"fieldset\">
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 function showNestedMessages ( &$msg_arr, $msg_id ) {
370 $rows=count($msg_arr["$msg_id"]);
373 if ($msg_arr["$msg_id"] && $rows > 0) {
375 <ul><li style="list-style: none">';
379 iterate and show the messages in this result
381 for each message, recurse to show any submessages
384 $am = new AttachManager();
385 for ($i=($rows-1); $i >= 0; $i--) {
386 // increment the global total count
389 // show the actual nested message
390 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
392 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
393 // Call yourself if there are followups
394 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
400 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
406 function showSubmessages(&$msg_arr, $msg_id, $level) {
408 Recursive. Selects this message's id in this thread,
409 then checks if any messages are nested underneath it.
410 If there are, it calls itself, incrementing $level
411 $level is used for indentation of the threads.
413 global $total_rows,$forum_id,$current_message,$group_id;
415 if (!isset($msg_arr["$msg_id"]))
418 $rows=count($msg_arr["$msg_id"]);
420 //echo "<p>ShowSubmessages() $msg_id | $rows";
422 for ($i=($rows-1); $i >= 0; $i--) {
424 Is this row's background shaded or not?
429 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
431 How far should it indent?
433 for ($i2=0; $i2<$level; $i2++) {
434 $ret_val .= ' ';
438 If it this is the message being displayed, don't show a link to it
440 if ($current_message != $msg_arr[$msg_id][$i]->getID()) {
441 $ah_begin='<a href="'.util_make_uri('/forum/message.php?msg_id='. $msg_arr[$msg_id][$i]->getID() .'&group_id='.$group_id).'">';
448 $ret_val .= $ah_begin .
449 html_image('ic/msg.png').' ';
451 See if this message is new or not
453 if ($this->Forum->getSavedDate() < $msg_arr[$msg_id][$i]->getPostDate()) {
454 $bold_begin='<strong>';
455 $bold_end='</strong>';
461 $ret_val .= $bold_begin.$msg_arr[$msg_id][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
462 '<td>'.util_display_user($msg_arr[$msg_id][$i]->getPosterName(),$msg_arr[$msg_id][$i]->getPosterID(),$msg_arr[$msg_id][$i]->getPosterRealName()) .'</td>'.
463 '<td>'.relative_date($msg_arr[$msg_id][$i]->getPostDate()).'</td></tr>';
465 if ($msg_arr[$msg_id][$i]->hasFollowups() > 0) {
467 Call yourself, incrementing the level
469 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr[$msg_id][$i]->getID(),($level+1));
477 * showEditForm - Prints the form to edit a message
479 * @param int The Message
480 * @return The HTML output echoed
483 function showEditForm(&$msg) {
484 $thread_id = $msg->getThreadID();
485 $msg_id = $msg->getID();
486 $posted_by = $msg->getPosterID();
487 $subject = $msg->getSubject();
488 $body = $msg->getBody();
489 $post_date = $msg->getPostDate();
490 $is_followup_to = $msg->getParentID();
491 $has_followups = $msg->hasFollowups();
492 $most_recent_date = $msg->getMostRecentDate();
493 $g =& $this->Forum->getGroup();
494 $group_id = $g->getID();
496 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
500 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
501 <?php $objid = $this->Forum->getID();?>
502 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
503 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
504 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
505 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
506 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
507 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
508 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
509 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
510 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
511 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
512 <fieldset class="fieldset">
513 <table><tr><td valign="top">
514 </td><td valign="top">
516 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
517 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
519 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
521 $GLOBALS['editor_was_set_up']=false;
523 $params['body'] = $body;
524 $params['width'] = "800";
525 $params['height'] = "500";
526 $params['group'] = $group_id;
527 plugin_hook("text_editor",$params);
528 if (!$GLOBALS['editor_was_set_up']) {
529 //if we don't have any plugin for text editor, display a simple textarea edit box
530 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
532 unset($GLOBALS['editor_was_set_up']);
537 <?php //$this->LinkAttachForm();?>
544 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
545 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
548 </td></tr></table></fieldset>
555 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
560 $rl = RoleLoggedIn::getInstance() ;
561 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
563 //if this is a followup, put a RE: before it if needed
564 if (!preg_match('/RE:/i',$subject,$test)) {
565 $subject ='RE: '.$subject;
571 <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">
572 <?php $objid = $this->Forum->getID();?>
573 <input type="hidden" name="post_message" value="y" />
574 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
575 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
576 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
577 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
578 <fieldset class="fieldset"><table><tr><td valign="top">
579 </td><td valign="top">
581 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
582 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
584 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
587 $GLOBALS['editor_was_set_up']=false;
589 $params['body'] = $body;
590 $params['width'] = "800";
591 $params['height'] = "500";
592 $params['group'] = $group_id;
593 plugin_hook("text_editor",$params);
594 if (!$GLOBALS['editor_was_set_up']) {
595 //if we don't have any plugin for text editor, display a simple textarea edit box
596 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
598 unset($GLOBALS['editor_was_set_up']);
599 ?> <?php //$text_support->displayTextField('body'); ?> <br>
601 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
602 <p><?php $this->LinkAttachForm();?>
606 if (!session_loggedin()) {
607 echo '<span class="highlight">';
608 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>';
611 <input type="submit" name="submit"
612 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
613 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
623 } elseif ($rl->hasPermission('forum', $this->Forum->getID(), 'post')) {
624 echo '<span class="error">';
625 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'))));
627 } elseif (!session_loggedin()) {
628 echo '<span class="error">';
629 printf(_('Please <a href="%1$s">log in</a>'), util_make_uri('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
630 echo '</span><br/></p>';
638 // c-file-style: "bsd"