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,$sys_news_group,$f,$sys_use_forum,$sys_use_trove,$group_forum_id;
30 if ($group_forum_id) {
31 $forum_id=$group_forum_id;
33 if (!$sys_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 == $sys_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 '<h3>'._('Error - this news item was not found').'</h3>';
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'] == $sys_news_group) {
90 print stripslashes(trove_news_getcatlisting(db_result($result,0,'forum_id'),0,1));
91 } elseif ($sys_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 ($f->userIsAdmin()) {
116 $menu_text[]=_('Admin');
117 $menu_links[]='/forum/admin/?group_id='.$group_id;
120 $gg=&group_get_object($group_id);
121 $perm =& $gg->getPermission( session_get_user() );
122 if ($perm->isForumAdmin()) {
123 $menu_text[]=_('Admin');
124 $menu_links[]='/forum/admin/?group_id='.$group_id;
127 if (count($menu_text) > 0) {
134 if (session_loggedin() ) {
136 if ($f->isMonitoring()) {
137 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
138 html_image('ic/xmail16w.png','20','20',array()).' '._('Stop Monitoring')).' | ';
140 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
141 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum')).' | ';
143 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
144 html_image('ic/save.png','24','24',array()) .' '._('Save Place')).' | ';
147 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
148 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum').'</a> | ';
151 if ($f && $forum_id) {
152 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
153 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
154 _('Start New Thread'));
158 function forum_footer($params) {
159 site_project_footer($params);
165 Wrap many forum functions in this class
168 class ForumHTML extends Error {
176 function ForumHTML(&$Forum) {
178 if (!$Forum || !is_object($Forum)) {
179 $this->setError('ForumMessage:: No Valid Forum Object');
182 if ($Forum->isError()) {
183 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
186 $this->Forum =& $Forum;
192 * Function showPendingMessage
194 * @param object The message.
196 * @return returns the html output
198 function showPendingMessage ( &$msg) {
199 global $HTML,$group_id;
201 $am = new AttachManager();
202 $ret_val = $am->PrintHelperFunctions();
203 html_feedback_top(_('This is the content of the pending message'));
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',"10","12",array("border"=>"0")) .
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 $fa = new ForumAdmin();
251 $msgforum =& $msg->getForum();
252 $url = util_make_url('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
254 '<table border="0" width="100%" cellspacing="0">
256 <td class="tablecontent" style="white-space: nowrap;" valign="top">';
257 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
258 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
259 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
260 $ret_val .= '</td><td class="tablecontent" align="right">';
261 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
262 if ($msgforum->userIsAdmin()) {
263 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
265 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
272 if (strpos($msg->getBody(),'<') === false) {
273 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
275 $ret_val .= $msg->getBody();
285 * LinkAttachEditForm - Returns the link to the attach form for editing
287 * @param string Filename
288 * @param int group id
289 * @param int forum id
290 * @param int attach id
293 * @return The HTML output
296 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
299 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
302 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
306 <fieldset class=\"fieldset\">
310 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
313 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
316 <td class="warning">' . _('Warning: Current file will be deleted permanently') . '</td>
319 <input type="submit" name="go" value="'._('Update').'">
320 <input type="hidden" name="doedit" value="1"/>
321 <input type="hidden" name="edit" value="yes"/>
322 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
323 <input type="hidden" name="group_id" value="'.$group_id.'"/>
324 <input type="hidden" name="attachid" value="'.$attachid.'"/>
325 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
326 </fieldset></form><p>';
331 * LinkAttachForm - echoes the link to the attach form
333 * @return The HTML output echoed
336 function LinkAttachForm() {
337 $poststarttime = time();
338 $posthash = md5($poststarttime . user_getid() );
340 <fieldset class=\"fieldset\">
343 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
346 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
355 function showNestedMessages ( &$msg_arr, $msg_id ) {
358 $rows=count($msg_arr["$msg_id"]);
361 if ($msg_arr["$msg_id"] && $rows > 0) {
363 <ul><li style="list-style: none">';
367 iterate and show the messages in this result
369 for each message, recurse to show any submessages
372 $am = new AttachManager();
373 for ($i=($rows-1); $i >= 0; $i--) {
374 // increment the global total count
377 // show the actual nested message
378 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
380 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
381 // Call yourself if there are followups
382 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
388 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
394 function showSubmessages(&$msg_arr, $msg_id, $level) {
396 Recursive. Selects this message's id in this thread,
397 then checks if any messages are nested underneath it.
398 If there are, it calls itself, incrementing $level
399 $level is used for indentation of the threads.
401 global $total_rows,$forum_id,$current_message,$group_id;
403 $rows=count($msg_arr["$msg_id"]);
405 //echo "<p>ShowSubmessages() $msg_id | $rows";
407 for ($i=($rows-1); $i >= 0; $i--) {
409 Is this row's background shaded or not?
414 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
416 How far should it indent?
418 for ($i2=0; $i2<$level; $i2++) {
419 $ret_val .= ' ';
423 If it this is the message being displayed, don't show a link to it
425 if ($current_message != $msg_arr["$msg_id"][$i]->getID()) {
426 $ah_begin='<a href="'.util_make_url ('/forum/message.php?msg_id='. $msg_arr["$msg_id"][$i]->getID() .'&group_id='.$group_id).'">';
433 $ret_val .= $ah_begin .
434 html_image('ic/msg.png',"10","12",array("border"=>"0")).' ';
436 See if this message is new or not
438 if ($this->Forum->getSavedDate() < $msg_arr["$msg_id"][$i]->getPostDate()) {
439 $bold_begin='<strong>';
440 $bold_end='</strong>';
446 $ret_val .= $bold_begin.$msg_arr["$msg_id"][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
447 '<td>'.util_make_link_u ($msg_arr["$msg_id"][$i]->getPosterName(),$msg_arr["$msg_id"][$i]->getPosterID(),$msg_arr["$msg_id"][$i]->getPosterRealName()) .'</td>'.
448 '<td>'.date(_('Y-m-d H:i'), $msg_arr["$msg_id"][$i]->getPostDate() ).'</td></tr>';
450 if ($msg_arr["$msg_id"][$i]->hasFollowups() > 0) {
452 Call yourself, incrementing the level
454 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr["$msg_id"][$i]->getID(),($level+1));
462 * showEditForm - Prints the form to edit a message
464 * @param int The Message
465 * @return The HTML output echoed
468 function showEditForm(&$msg) {
469 $thread_id = $msg->getThreadID();
470 $msg_id = $msg->getID();
471 $posted_by = $msg->getPosterID();
472 $subject = $msg->getSubject();
473 $body = $msg->getBody();
474 $post_date = $msg->getPostDate();
475 $is_followup_to = $msg->getParentID();
476 $has_followups = $msg->hasFollowups();
477 $most_recent_date = $msg->getMostRecentDate();
478 $g =& $this->Forum->getGroup();
479 $group_id = $g->getID();
481 if ($this->Forum->userCanPost()) { // minor control, but anyways it should be an admin at this point
485 <form enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
486 <?php $objid = $this->Forum->getID();?>
487 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
488 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
489 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
490 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
491 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
492 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
493 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
494 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
495 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
496 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
497 <fieldset class="fieldset">
498 <table><tr><td valign="top">
499 </td><td valign="top">
501 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
502 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
504 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms[2].body') ?><?php echo utils_requiredField(); ?><br />
506 $GLOBALS['editor_was_set_up']=false;
508 $params['body'] = $body;
509 $params['width'] = "800";
510 $params['height'] = "500";
511 $params['group'] = $group_id;
512 plugin_hook("text_editor",$params);
513 if (!$GLOBALS['editor_was_set_up']) {
514 //if we don't have any plugin for text editor, display a simple textarea edit box
515 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
517 unset($GLOBALS['editor_was_set_up']);
522 <?php //$this->LinkAttachForm();?>
529 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
530 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
533 </td></tr></table></fieldset>
540 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
545 if ($this->Forum->userCanPost()) {
547 //if this is a followup, put a RE: before it if needed
548 if (!eregi('RE:',$subject,$test)) {
549 $subject ='RE: '.$subject;
555 <form enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/forum.php?forum_id='.$this->Forum->getID().'&group_id='.$group_id); ?>" method="post">
556 <?php $objid = $this->Forum->getID();?>
557 <input type="hidden" name="post_message" value="y" />
558 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
559 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
560 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
561 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
562 <fieldset class="fieldset"><table><tr><td valign="top">
563 </td><td valign="top">
565 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
566 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
568 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms[2].body') ?><?php echo utils_requiredField(); ?><br />
571 $GLOBALS['editor_was_set_up']=false;
573 $params['body'] = $body;
574 $params['width'] = "800";
575 $params['height'] = "500";
576 $params['group'] = $group_id;
577 plugin_hook("text_editor",$params);
578 if (!$GLOBALS['editor_was_set_up']) {
579 //if we don't have any plugin for text editor, display a simple textarea edit box
580 echo '<textarea name="body" rows="10" cols="70" wrap="soft">' . $body . '</textarea>';
582 unset($GLOBALS['editor_was_set_up']);
583 ?> <?php //$text_support->displayTextField('body'); ?> <br>
585 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
586 <p><?php $this->LinkAttachForm();?>
590 if (!session_loggedin()) {
591 echo '<span class="highlight">';
592 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>';
595 <input type="submit" name="submit"
596 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
597 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
607 } elseif ($this->Forum->allowAnonymous()) {
608 echo '<span class="error">';
609 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'))));
611 } elseif (!session_loggedin()) {
612 echo '<span class="error">';
613 printf(_('Please <a href="%1$s">log in</a>'), util_make_url('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
614 echo '</span><br/></p>';
624 // c-file-style: "bsd"