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 '<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'] == $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 $pluginManager = plugin_manager_get_object();
135 if ($f && $pluginManager->PluginIsInstalled('blocks') && plugin_hook ("blocks", "forum_".$f->getName()))
138 if (session_loggedin() ) {
140 if ($f->isMonitoring()) {
141 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1',
142 html_image('ic/xmail16w.png','20','20',array()).' '._('Stop Monitoring')).' | ';
144 echo util_make_link ('/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1',
145 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum')).' | ';
147 echo util_make_link ('/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id,
148 html_image('ic/save.png','24','24',array()) .' '._('Save Place')).' | ';
151 echo '<a href="/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
152 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum').'</a> | ';
155 if ($f && $forum_id) {
156 echo util_make_link ('/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id,
157 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
158 _('Start New Thread'));
162 function forum_footer($params) {
163 site_project_footer($params);
169 Wrap many forum functions in this class
172 class ForumHTML extends Error {
180 function ForumHTML(&$Forum) {
182 if (!$Forum || !is_object($Forum)) {
183 $this->setError('ForumMessage:: No Valid Forum Object');
186 if ($Forum->isError()) {
187 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
190 $this->Forum =& $Forum;
196 * Function showPendingMessage
198 * @param object The message.
200 * @return returns the html output
202 function showPendingMessage ( &$msg) {
203 global $HTML,$group_id;
205 $am = new AttachManager();
206 $ret_val = $am->PrintHelperFunctions();
207 html_feedback_top(_('This is the content of the pending message'));
211 <td class="tablecontent" style="white-space: nowrap;">'._('By:').
212 $msg->getPosterRealName().
215 $msgforum =& $msg->getForum();
216 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
219 html_image('ic/msg.png',"10","12",array("border"=>"0")) .
220 $bold_begin. $msg->getSubject() . $bold_end .' '.
221 '<br />'. date(_('Y-m-d H:i'),$msg->getPostDate()) .'
226 '. $msg->getBody() .'
234 function showNestedMessage ( &$msg ) {
237 accepts a database result handle to display a single message
238 in the format appropriate for the nested messages
241 global $HTML,$group_id;
243 See if this message is new or not
244 If so, highlite it in bold
246 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
247 $bold_begin='<strong>';
248 $bold_end='</strong>';
253 $am = new AttachManager();
254 $fa = new ForumAdmin();
255 $msgforum =& $msg->getForum();
256 $url = util_make_url('/forum/message.php?msg_id='. $msg->getID() .'&group_id='.$group_id);
258 '<table border="0" width="100%" cellspacing="0">
260 <td class="tablecontent" style="white-space: nowrap;" valign="top">';
261 $ret_val .= $bold_begin. $msg->getSubject(). ' <a href="'.$url.'">[ '._("reply").' ]</a>'. $bold_end;
262 $ret_val .= '<br/>'._('By:').' '.util_make_link_u ($msg->getPosterName(),$msg->getPosterID(),$msg->getPosterRealName());
263 $ret_val .= ' on '.date('Y-m-d H:i',$msg->getPostDate());
264 $ret_val .= '</td><td class="tablecontent" align="right">';
265 $ret_val .= '<a href="'.$url.'">[forum:'.$msg->getID().']</a><br/>';
266 if ($msgforum->userIsAdmin()) {
267 $ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());
269 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID());
276 if (strpos($msg->getBody(),'<') === false) {
277 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
279 $ret_val .= $msg->getBody();
289 * LinkAttachEditForm - Returns the link to the attach form for editing
291 * @param string Filename
292 * @param int group id
293 * @param int forum id
294 * @param int attach id
297 * @return The HTML output
300 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
303 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
306 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
310 <fieldset class=\"fieldset\">
314 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
317 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
320 <td class="warning">' . _('Warning: Current file will be deleted permanently') . '</td>
323 <input type="submit" name="go" value="'._('Update').'">
324 <input type="hidden" name="doedit" value="1"/>
325 <input type="hidden" name="edit" value="yes"/>
326 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
327 <input type="hidden" name="group_id" value="'.$group_id.'"/>
328 <input type="hidden" name="attachid" value="'.$attachid.'"/>
329 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
330 </fieldset></form><p>';
335 * LinkAttachForm - echoes the link to the attach form
337 * @return The HTML output echoed
340 function LinkAttachForm() {
341 $poststarttime = time();
342 $posthash = md5($poststarttime . user_getid() );
344 <fieldset class=\"fieldset\">
347 <td>" . _('Use the "Browse" button to find the file you want to attach') . "</td>
350 <td>" . _('File to upload') . ": <input type=\"file\" name=\"attachment1\"/></td>
359 function showNestedMessages ( &$msg_arr, $msg_id ) {
362 $rows=count($msg_arr["$msg_id"]);
365 if ($msg_arr["$msg_id"] && $rows > 0) {
367 <ul><li style="list-style: none">';
371 iterate and show the messages in this result
373 for each message, recurse to show any submessages
376 $am = new AttachManager();
377 for ($i=($rows-1); $i >= 0; $i--) {
378 // increment the global total count
381 // show the actual nested message
382 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
384 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
385 // Call yourself if there are followups
386 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
392 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
398 function showSubmessages(&$msg_arr, $msg_id, $level) {
400 Recursive. Selects this message's id in this thread,
401 then checks if any messages are nested underneath it.
402 If there are, it calls itself, incrementing $level
403 $level is used for indentation of the threads.
405 global $total_rows,$forum_id,$current_message,$group_id;
407 $rows=count($msg_arr["$msg_id"]);
409 //echo "<p>ShowSubmessages() $msg_id | $rows";
411 for ($i=($rows-1); $i >= 0; $i--) {
413 Is this row's background shaded or not?
418 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td style="white-space: nowrap;">';
420 How far should it indent?
422 for ($i2=0; $i2<$level; $i2++) {
423 $ret_val .= ' ';
427 If it this is the message being displayed, don't show a link to it
429 if ($current_message != $msg_arr["$msg_id"][$i]->getID()) {
430 $ah_begin='<a href="'.util_make_url ('/forum/message.php?msg_id='. $msg_arr["$msg_id"][$i]->getID() .'&group_id='.$group_id).'">';
437 $ret_val .= $ah_begin .
438 html_image('ic/msg.png',"10","12",array("border"=>"0")).' ';
440 See if this message is new or not
442 if ($this->Forum->getSavedDate() < $msg_arr["$msg_id"][$i]->getPostDate()) {
443 $bold_begin='<strong>';
444 $bold_end='</strong>';
450 $ret_val .= $bold_begin.$msg_arr["$msg_id"][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
451 '<td>'.util_make_link_u ($msg_arr["$msg_id"][$i]->getPosterName(),$msg_arr["$msg_id"][$i]->getPosterID(),$msg_arr["$msg_id"][$i]->getPosterRealName()) .'</td>'.
452 '<td>'.date(_('Y-m-d H:i'), $msg_arr["$msg_id"][$i]->getPostDate() ).'</td></tr>';
454 if ($msg_arr["$msg_id"][$i]->hasFollowups() > 0) {
456 Call yourself, incrementing the level
458 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr["$msg_id"][$i]->getID(),($level+1));
466 * showEditForm - Prints the form to edit a message
468 * @param int The Message
469 * @return The HTML output echoed
472 function showEditForm(&$msg) {
473 $thread_id = $msg->getThreadID();
474 $msg_id = $msg->getID();
475 $posted_by = $msg->getPosterID();
476 $subject = $msg->getSubject();
477 $body = $msg->getBody();
478 $post_date = $msg->getPostDate();
479 $is_followup_to = $msg->getParentID();
480 $has_followups = $msg->hasFollowups();
481 $most_recent_date = $msg->getMostRecentDate();
482 $g =& $this->Forum->getGroup();
483 $group_id = $g->getID();
485 if ($this->Forum->userCanPost()) { // minor control, but anyways it should be an admin at this point
489 <form id="ForumEditForm" enctype="multipart/form-data" action="<?php echo util_make_url ('/forum/admin/index.php') ?>" method="post">
490 <?php $objid = $this->Forum->getID();?>
491 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
492 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
493 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
494 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
495 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
496 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
497 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
498 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
499 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
500 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
501 <fieldset class="fieldset">
502 <table><tr><td valign="top">
503 </td><td valign="top">
505 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
506 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
508 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumEditForm.body') ?><?php echo utils_requiredField(); ?><br />
510 $GLOBALS['editor_was_set_up']=false;
512 $params['body'] = $body;
513 $params['width'] = "800";
514 $params['height'] = "500";
515 $params['group'] = $group_id;
516 plugin_hook("text_editor",$params);
517 if (!$GLOBALS['editor_was_set_up']) {
518 //if we don't have any plugin for text editor, display a simple textarea edit box
519 echo '<textarea name="body" rows="10" cols="70">' . $body . '</textarea>';
521 unset($GLOBALS['editor_was_set_up']);
526 <?php //$this->LinkAttachForm();?>
533 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
534 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
537 </td></tr></table></fieldset>
544 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
549 if ($this->Forum->userCanPost()) {
551 //if this is a followup, put a RE: before it if needed
552 if (!eregi('RE:',$subject,$test)) {
553 $subject ='RE: '.$subject;
559 <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">
560 <?php $objid = $this->Forum->getID();?>
561 <input type="hidden" name="post_message" value="y" />
562 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
563 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
564 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
565 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>" />
566 <fieldset class="fieldset"><table><tr><td valign="top">
567 </td><td valign="top">
569 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
570 <input type="text" name="subject" value="<?php echo $subject; ?>" size="80" maxlength="80" />
572 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms.ForumPostForm.body') ?><?php echo utils_requiredField(); ?><br />
575 $GLOBALS['editor_was_set_up']=false;
577 $params['body'] = $body;
578 $params['width'] = "800";
579 $params['height'] = "500";
580 $params['group'] = $group_id;
581 plugin_hook("text_editor",$params);
582 if (!$GLOBALS['editor_was_set_up']) {
583 //if we don't have any plugin for text editor, display a simple textarea edit box
584 echo '<textarea name="body" rows="10" cols="70" wrap="soft">' . $body . '</textarea>';
586 unset($GLOBALS['editor_was_set_up']);
587 ?> <?php //$text_support->displayTextField('body'); ?> <br>
589 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
590 <p><?php $this->LinkAttachForm();?>
594 if (!session_loggedin()) {
595 echo '<span class="highlight">';
596 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>';
599 <input type="submit" name="submit"
600 value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
601 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
611 } elseif ($this->Forum->allowAnonymous()) {
612 echo '<span class="error">';
613 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'))));
615 } elseif (!session_loggedin()) {
616 echo '<span class="error">';
617 printf(_('Please <a href="%1$s">log in</a>'), util_make_url('/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI'))));
618 echo '</span><br/></p>';
628 // c-file-style: "bsd"