3 * GForge Forums Facility
5 * Copyright 2002 GForge, LLC
13 By Tim Perdue, Sourceforge, 11/99
15 Massive rewrite by Tim Perdue 7/2000 (nested/views/save)
17 Complete OO rewrite by Tim Perdue 12/2002
20 require_once $gfwww.'include/pre.php';
21 require_once $gfwww.'include/note.php';
22 require_once $gfwww.'include/trove.php';
23 require_once $gfwww.'news/news_utils.php';
24 require_once $gfwww.'forum/admin/ForumAdmin.class.php';
25 require_once $gfwww.'forum/include/AttachManager.class.php';
27 function forum_header($params) {
28 global $HTML,$group_id,$forum_name,$forum_id,$f,$group_forum_id;
30 if ($group_forum_id) {
31 $forum_id=$group_forum_id;
33 if (!forge_get_config('use_forum')) {
37 $params['group']=$group_id;
38 $params['toptab']='forums';
41 bastardization for news
42 Show icon bar unless it's a news forum
44 if ($group_id == forge_get_config('news_group')) {
45 //this is a news item, not a regular forum
47 // Show this news item 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 // checks which group the news item belongs to
52 $params['group']=db_result($result,0,'group_id');
53 $params['toptab']='news';
54 $HTML->header($params);
57 echo '<table><tr><td valign="top">';
58 if (!$result || db_numrows($result) < 1) {
59 echo '<div class="error">'._('Error - this news item was not found').'</div>';
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> '. date(_('Y-m-d H:i'),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 />
76 $body = db_result($result,0,'details');
77 $sanitizer = new TextSanitizer();
78 $body = $sanitizer->purify($body);
79 if (!strstr($body,'<')) {
80 //backwards compatibility for non html messages
81 echo util_make_links(nl2br($body));
83 echo util_make_links($body);
88 // display classification
89 if ($params['group'] == forge_get_config('news_group')) {
90 print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
91 } elseif (forge_get_config('use_trove')) {
92 print stripslashes(trove_getcatlisting($params['group'],0,1));
95 echo '</td><td valign="top" width="35%">';
96 echo $HTML->boxTop(_('Latest News'));
97 echo news_show_latest($params['group'],5,false);
98 echo $HTML->boxBottom();
99 echo '</td></tr></table>';
101 site_project_header($params);
104 site_project_header($params);
112 $menu_text[]=_('Discussion Forums:') .' '. $f->getName();
113 $menu_links[]='/forum/forum.php?forum_id='.$forum_id;
115 if (forge_check_perm ('forum_admin', $f->Group->getID())) {
116 $menu_text[]=_('Admin');
117 $menu_links[]='/forum/admin/?group_id='.$group_id;
120 $gg=&group_get_object($group_id);
121 if (forge_check_perm ('forum_admin', $group_id)) {
122 $menu_text[]=_('Admin');
123 $menu_links[]='/forum/admin/?group_id='.$group_id;
126 if (count($menu_text) > 0) {
133 $pluginManager = plugin_manager_get_object();
134 if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
137 if (session_loggedin() ) {
139 if ($f->isMonitoring()) {
140 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
141 html_image('ic/xmail16w.png','20','20',array()).' '._('Stop Monitoring')).' | ';
143 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
144 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum')).' | ';
146 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
147 html_image('ic/save.png','24','24',array()) .' '._('Save Place')).' | ';
150 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
151 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum').'</a> | ';
154 if ($f && $forum_id) {
155 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
156 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
157 _('Start New Thread'));
161 function forum_footer($params) {
162 site_project_footer($params);
168 Wrap many forum functions in this class
171 class ForumHTML extends Error {
179 function ForumHTML(&$Forum) {
181 if (!$Forum || !is_object($Forum)) {
182 $this->setError('ForumMessage:: No Valid Forum Object');
185 if ($Forum->isError()) {
186 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
189 $this->Forum =& $Forum;
195 * Function showPendingMessage
197 * @param object The message.
199 * @return returns the html output
201 function showPendingMessage ( &$msg) {
202 global $HTML,$group_id;
204 $am = new AttachManager();
205 $ret_val = $am->PrintHelperFunctions();
206 html_feedback_top(_('This is the content of the pending message'));
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',"10","12",array("border"=>"0")) .
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_url('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
257 '<table border="0" width="100%" cellspacing="0">
259 <td class="tablecontent" style="white-space: nowrap;" valign="top">';
260 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
261 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
262 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
263 $ret_val .= '</td><td class="tablecontent" align="right">';
264 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
265 if (forge_check_perm ('forum_admin', $msgforum->Group->getID())) {
266 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
268 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
275 if (strpos($msg->getBody(),'<') === false) {
276 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
278 $ret_val .= $msg->getBody();
288 * LinkAttachEditForm - Returns the link to the attach form for editing
290 * @param string Filename
291 * @param int group id
292 * @param int forum id
293 * @param int attach id
296 * @return The HTML output
299 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
302 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
305 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
309 <fieldset class=\"fieldset\">
313 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
316 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
319 <td class="warning">' . _('Warning: Current file will be deleted permanently') . '</td>
322 <input type="submit" name="go" value="'._('Update').'">
323 <input type="hidden" name="doedit" value="1"/>
324 <input type="hidden" name="edit" value="yes"/>
325 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
326 <input type="hidden" name="group_id" value="'.$group_id.'"/>
327 <input type="hidden" name="attachid" value="'.$attachid.'"/>
328 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
329 </fieldset></form><p>';
334 * LinkAttachForm - echoes the link to the attach form
336 * @return The HTML output echoed
339 function LinkAttachForm() {
340 $poststarttime = time();
341 $posthash = md5($poststarttime . user_getid() );
343 <fieldset class=\"fieldset\">
346 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
349 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
358 function showNestedMessages ( &$msg_arr, $msg_id ) {
361 $rows=count($msg_arr["$msg_id"]);
364 if ($msg_arr["$msg_id"] && $rows > 0) {
366 <ul><li style="list-style: none">';
370 iterate and show the messages in this result
372 for each message, recurse to show any submessages
375 $am = new AttachManager();
376 for ($i=($rows-1); $i >= 0; $i--) {
377 // increment the global total count
380 // show the actual nested message
381 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
383 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
384 // Call yourself if there are followups
385 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
391 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
397 function showSubmessages(&$msg_arr, $msg_id, $level) {
399 Recursive. Selects this message's id in this thread,
400 then checks if any messages are nested underneath it.
401 If there are, it calls itself, incrementing $level
402 $level is used for indentation of the threads.
404 global $total_rows,$forum_id,$current_message,$group_id;
406 $rows=count($msg_arr["$msg_id"]);
408 //echo "<p>ShowSubmessages() $msg_id | $rows";
410 for ($i=($rows-1); $i >= 0; $i--) {
412 Is this row's background shaded or not?
417 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
419 How far should it indent?
421 for ($i2=0; $i2<$level; $i2++) {
422 $ret_val .= ' ';
426 If it this is the message being displayed, don't show a link to it
428 if ($current_message != $msg_arr["$msg_id"][$i]->getID()) {
429 $ah_begin='<a href="'.util_make_url ('/forum/message.php?msg_id='. $msg_arr["$msg_id"][$i]->getID() .'&group_id='.$group_id).'">';
436 $ret_val .= $ah_begin .
437 html_image('ic/msg.png',"10","12",array("border"=>"0")).' ';
439 See if this message is new or not
441 if ($this->Forum->getSavedDate() < $msg_arr["$msg_id"][$i]->getPostDate()) {
442 $bold_begin='<strong>';
443 $bold_end='</strong>';
449 $ret_val .= $bold_begin.$msg_arr["$msg_id"][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
450 '<td>'.util_make_link_u ($msg_arr["$msg_id"][$i]->getPosterName(),$msg_arr["$msg_id"][$i]->getPosterID(),$msg_arr["$msg_id"][$i]->getPosterRealName()) .'</td>'.
451 '<td>'.date(_('Y-m-d H:i'), $msg_arr["$msg_id"][$i]->getPostDate() ).'</td></tr>';
453 if ($msg_arr["$msg_id"][$i]->hasFollowups() > 0) {
455 Call yourself, incrementing the level
457 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr["$msg_id"][$i]->getID(),($level+1));
465 * showEditForm - Prints the form to edit a message
467 * @param int The Message
468 * @return The HTML output echoed
471 function showEditForm(&$msg) {
472 $thread_id = $msg->getThreadID();
473 $msg_id = $msg->getID();
474 $posted_by = $msg->getPosterID();
475 $subject = $msg->getSubject();
476 $body = $msg->getBody();
477 $post_date = $msg->getPostDate();
478 $is_followup_to = $msg->getParentID();
479 $has_followups = $msg->hasFollowups();
480 $most_recent_date = $msg->getMostRecentDate();
481 $g =& $this->Forum->getGroup();
482 $group_id = $g->getID();
484 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) { // minor control, but anyways it should be an admin at this point
488 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
489 <?php $objid = $this->Forum->getID();?>
490 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
491 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
492 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
493 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
494 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
495 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
496 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
497 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
498 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
499 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
500 <fieldset class="fieldset">
501 <table><tr><td valign="top">
502 </td><td valign="top">
504 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
505 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
507 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
509 $GLOBALS['editor_was_set_up']=false;
511 $params['body'] = $body;
512 $params['width'] = "800";
513 $params['height'] = "500";
514 $params['group'] = $group_id;
515 plugin_hook("text_editor",$params);
516 if (!$GLOBALS['editor_was_set_up']) {
517 //if we don't have any plugin for text editor, display a simple textarea edit box
518 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
520 unset($GLOBALS['editor_was_set_up']);
525 <?php //$this->LinkAttachForm();?>
532 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
533 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
536 </td></tr></table></fieldset>
543 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
548 if (forge_check_perm ('forum', $this->Forum->getID(), 'post')) {
550 //if this is a followup, put a RE: before it if needed
551 if (!eregi('RE:',$subject,$test)) {
552 $subject ='RE: '.$subject;
558 <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">
559 <?php $objid = $this->Forum->getID();?>
560 <input type="hidden" name="post_message" value="y" />
561 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
562 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
563 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
564 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
565 <fieldset class="fieldset"><table><tr><td valign="top">
566 </td><td valign="top">
568 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
569 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
571 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
574 $GLOBALS['editor_was_set_up']=false;
576 $params['body'] = $body;
577 $params['width'] = "800";
578 $params['height'] = "500";
579 $params['group'] = $group_id;
580 plugin_hook("text_editor",$params);
581 if (!$GLOBALS['editor_was_set_up']) {
582 //if we don't have any plugin for text editor, display a simple textarea edit box
583 echo '<textarea name="body" rows="10" cols="70" wrap="soft">' . $body . '</textarea>';
585 unset($GLOBALS['editor_was_set_up']);
586 ?> <?php //$text_support->displayTextField('body'); ?> <br>
588 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
589 <p><?php $this->LinkAttachForm();?>
593 if (!session_loggedin()) {
594 echo '<span class="highlight">';
595 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>';
598 <input type="submit" name="submit"
599 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
600 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
610 } elseif ($this->Forum->allowAnonymous()) {
611 echo '<span class="error">';
612 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'))));
614 } elseif (!session_loggedin()) {
615 echo '<span class="error">';
616 printf(_('Please <a href="%1$s">log in</a>'), util_make_url('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
617 echo '</span><br/></p>';
627 // c-file-style: "bsd"