3 * GForge Forums Facility
5 * Copyright 2002 GForge, LLC
14 By Tim Perdue, Sourceforge, 11/99
16 Massive rewrite by Tim Perdue 7/2000 (nested/views/save)
18 Complete OO rewrite by Tim Perdue 12/2002
21 require_once('pre.php');
22 require_once('note.php');
23 require_once('www/news/news_utils.php');
24 require_once('www/forum/admin/ForumAdmin.class');
25 require_once('www/forum/include/AttachManager.class');
27 function forum_header($params) {
28 global $HTML,$group_id,$forum_name,$forum_id,$sys_datefmt,$sys_news_group,$Language,$f,$sys_use_forum,$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 $sql="SELECT submitted_by, post_date, group_id, forum_id, summary, details FROM news_bytes WHERE forum_id='$forum_id'";
49 $result=db_query($sql);
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($sys_datefmt,db_result($result,0,'post_date')).'<br />
69 <strong>'._('Summary').':</strong> <a href="'.$GLOBALS['sys_urlprefix'].'/forum/forum.php?forum_id='.db_result($result,0,'forum_id').'&group_id='.$group_id.'">'. db_result($result,0,'summary').'</a><br/>
70 <strong>'._('Project').':</strong> <a href="'.$GLOBALS['sys_urlprefix'].'/projects/'.$group->getUnixName().'">'.$group->getPublicName().'</a> <br />
72 '. (util_make_links(nl2br(db_result($result,0,'details'))));
76 echo '</td><td valign="top" width="35%">';
77 echo $HTML->boxTop(_('Latest News'));
78 echo news_show_latest($params['group'],5,false);
79 echo $HTML->boxBottom();
80 echo '</td></tr></table>';
82 site_project_header($params);
85 site_project_header($params);
90 if ($f && $forum_id) {
91 $menu_text[]=_('Discussion Forums:') .' '. $f->getName();
92 $menu_links[]='/forum/forum.php?forum_id='.$forum_id;
94 if ($f && $f->userIsAdmin()) {
95 $menu_text[]=_('Admin');
96 $menu_links[]='/forum/admin/?group_id='.$group_id;
98 if (count($menu_text) > 0) {
105 if (session_loggedin() ) {
107 if ($f->isMonitoring()) {
108 echo '<a href="'.$GLOBALS['sys_urlprefix'].'/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&stop=1">' .
109 html_image('ic/xmail16w.png','20','20',array()).' '._('Stop Monitoring').'</a> | ';
111 echo '<a href="'.$GLOBALS['sys_urlprefix'].'/forum/monitor.php?forum_id='.$forum_id.'&group_id='.$group_id.'&start=1">' .
112 html_image('ic/mail16w.png','20','20',array()).' '._('Monitor Forum').'</a> | ';
114 echo '<a href="'.$GLOBALS['sys_urlprefix'].'/forum/save.php?forum_id='.$forum_id.'&group_id='.$group_id.'">' .
115 html_image('ic/save.png','24','24',array()) .' '._('Save Place').'</a> | ';
119 if ($f && $forum_id) {
120 echo '<a href="'.$GLOBALS['sys_urlprefix'].'/forum/new.php?forum_id='.$forum_id.'&group_id='.$group_id.'">' .
121 html_image('ic/write16w.png','20','20',array('alt'=>_('Start New Thread'))) .' '.
122 _('Start New Thread').'</a>';
126 function forum_footer($params) {
127 site_project_footer($params);
133 Wrap many forum functions in this class
136 class ForumHTML extends Error {
144 function ForumHTML(&$Forum) {
146 if (!$Forum || !is_object($Forum)) {
147 $this->setError('ForumMessage:: No Valid Forum Object');
150 if ($Forum->isError()) {
151 $this->setError('ForumMessage:: '.$Forum->getErrorMessage());
154 $this->Forum =& $Forum;
160 * Function showPendingMessage
162 * @param object The message.
164 * @return returns the html output
166 function showPendingMessage ( &$msg) {
167 global $sys_datefmt,$Language,$HTML,$group_id;
169 $am = new AttachManager();
170 $ret_val = $am->PrintHelperFunctions();
171 html_feedback_top(_('This is the content of the pending message'));
175 <td class="tablecontent" nowrap="nowrap">'._('By:').
176 $msg->getPosterRealName().
179 $msgforum =& $msg->getForum();
180 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
183 html_image('ic/msg.png',"10","12",array("border"=>"0")) .
184 $bold_begin. $msg->getSubject() . $bold_end .' '.
185 '<br />'. date($sys_datefmt,$msg->getPostDate()) .'
190 '. $msg->getBody() .'
198 function showNestedMessage ( &$msg ) {
201 accepts a database result handle to display a single message
202 in the format appropriate for the nested messages
205 global $sys_datefmt,$Language,$HTML,$group_id;
207 See if this message is new or not
208 If so, highlite it in bold
210 if ($this->Forum->getSavedDate() < $msg->getPostDate()) {
211 $bold_begin='<strong>';
212 $bold_end='</strong>';
214 $am = new AttachManager();
215 $fa = new ForumAdmin();
216 $msgforum =& $msg->getForum();
221 <td class="tablecontent" nowrap="nowrap">'; if ($msgforum->userIsAdmin()) {$ret_val .= $fa->PrintAdminMessageOptions($msg->getID(),$group_id,$msg->getThreadID(),$msgforum->getID());} $ret_val .= _('By:').' <a href="'.$GLOBALS['sys_urlprefix'].'/users/'.
222 $msg->getPosterName() .'/">'.
223 $msg->getPosterRealName() .'</a>'.
226 $ret_val .= $am->PrintAttachLink($msg,$group_id,$msgforum->getID()) . '
228 <a href="'.$GLOBALS['sys_urlprefix'].'/forum/message.php?msg_id='.
229 $msg->getID() .'&group_id='.$group_id.'">'.
230 html_image('ic/msg.png',"10","12",array("border"=>"0")) .
231 $bold_begin. $msg->getSubject() .' [ '._('reply').' ]'. $bold_end .'</a> '.
232 '<br />'. date($sys_datefmt,$msg->getPostDate()) .'
238 if (!strstr($msg->getBody(),'<')) {
239 $ret_val .= nl2br($msg->getBody()); //backwards compatibility for non html messages
241 $ret_val .= $msg->getBody();
251 * LinkAttachEditForm - Returns the link to the attach form for editing
253 * @param string Filename
254 * @param int group id
255 * @param int forum id
256 * @param int attach id
259 * @return The HTML output
262 function LinkAttachEditForm($filename,$group_id,$forum_id,$attachid,$msg_id) {
267 <form action="' . getStringFromServer('PHP_SELF') . '" method="post" enctype="multipart/form-data">
270 <td>' . _('Current File') . ": <span class=\"selected\">" . $filename . '</span></td>
274 <fieldset class=\"fieldset\">
278 <td>' . _('Use the "Browse" button to find the file you want to attach') . '</td>
281 <td>' . _('File to upload') . ': <input type="file" name="attachment1"/></td>
284 <td class="warning">' . _('Warning : Current file will be deleted permanently') . '</td>
287 <input type="submit" name="go" value="'._('Update').'">
288 <input type="hidden" name="doedit" value="1"/>
289 <input type="hidden" name="edit" value="yes"/>
290 <input type="hidden" name="forum_id" value="'.$forum_id.'"/>
291 <input type="hidden" name="group_id" value="'.$group_id.'"/>
292 <input type="hidden" name="attachid" value="'.$attachid.'"/>
293 <input type="hidden" name="msg_id" value="'.$msg_id.'"/>
294 </fieldset></form><p>';
299 * LinkAttachForm - echoes the link to the attach form
301 * @return The HTML output echoed
304 function LinkAttachForm() {
307 $poststarttime = time();
308 $posthash = md5($poststarttime . user_getid() );
310 <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>
325 function showNestedMessages ( &$msg_arr, $msg_id ) {
326 global $total_rows,$sys_datefmt;
328 $rows=count($msg_arr["$msg_id"]);
331 if ($msg_arr["$msg_id"] && $rows > 0) {
333 <ul><li style="list-style: none">';
337 iterate and show the messages in this result
339 for each message, recurse to show any submessages
342 $am = new AttachManager();
343 for ($i=($rows-1); $i >= 0; $i--) {
344 // increment the global total count
347 // show the actual nested message
348 $ret_val .= $this->showNestedMessage ($msg_arr["$msg_id"][$i]).'<p />';
350 if ($msg_arr["$msg_id"][$i]->hasFollowups()) {
351 // Call yourself if there are followups
352 $ret_val .= $this->showNestedMessages ( $msg_arr,$msg_arr["$msg_id"][$i]->getID() );
358 //$ret_val .= "<p><strong>no messages actually follow up to $msg_id</strong>";
364 function showSubmessages(&$msg_arr, $msg_id, $level) {
366 Recursive. Selects this message's id in this thread,
367 then checks if any messages are nested underneath it.
368 If there are, it calls itself, incrementing $level
369 $level is used for indentation of the threads.
371 global $total_rows,$sys_datefmt,$forum_id,$current_message,$group_id;
373 $rows=count($msg_arr["$msg_id"]);
375 //echo "<p>ShowSubmessages() $msg_id | $rows";
377 for ($i=($rows-1); $i >= 0; $i--) {
379 Is this row's background shaded or not?
384 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($total_rows) .'><td nowrap="nowrap">';
386 How far should it indent?
388 for ($i2=0; $i2<$level; $i2++) {
389 $ret_val .= ' ';
393 If it this is the message being displayed, don't show a link to it
395 if ($current_message != $msg_arr["$msg_id"][$i]->getID()) {
396 $ah_begin='<a href="'.$GLOBALS['sys_urlprefix'].'/forum/message.php?msg_id='. $msg_arr["$msg_id"][$i]->getID() .
397 '&group_id='.$group_id.'">';
404 $ret_val .= $ah_begin .
405 html_image('ic/msg.png',"10","12",array("border"=>"0"));
407 See if this message is new or not
409 if ($this->Forum->getSavedDate() < $msg_arr["$msg_id"][$i]->getPostDate()) {
410 $bold_begin='<strong>';
411 $bold_end='</strong>';
417 $ret_val .= $bold_begin.$msg_arr["$msg_id"][$i]->getSubject() .$bold_end.$ah_end.'</td>'.
418 '<td><a href="'.$GLOBALS['sys_urlprefix'].'/users/'.$msg_arr["$msg_id"][$i]->getPosterName().'/">'. $msg_arr["$msg_id"][$i]->getPosterRealName() .'</a></td>'.
419 '<td>'.date($sys_datefmt, $msg_arr["$msg_id"][$i]->getPostDate() ).'</td></tr>';
421 if ($msg_arr["$msg_id"][$i]->hasFollowups() > 0) {
423 Call yourself, incrementing the level
425 $ret_val .= $this->showSubmessages($msg_arr,$msg_arr["$msg_id"][$i]->getID(),($level+1));
433 * showEditForm - Prints the form to edit a message
435 * @param int The Message
436 * @return The HTML output echoed
439 function showEditForm(&$msg) {
440 global $Language,$sys_default_domain;
442 $thread_id = $msg->getThreadID();
443 $msg_id = $msg->getID();
444 $posted_by = $msg->getPosterID();
445 $subject = $msg->getSubject();
446 $body = $msg->getBody();
447 $post_date = $msg->getPostDate();
448 $is_followup_to = $msg->getParentID();
449 $has_followups = $msg->hasFollowups();
450 $most_recent_date = $msg->getMostRecentDate();
451 $g =& $this->Forum->getGroup();
452 $group_id = $g->getID();
454 if (strtoupper(getStringFromServer('HTTPS')) == 'ON') {
460 if ($this->Forum->userCanPost()) { // minor control, but anyways it should be an admin at this point
464 <form "enctype="multipart/form-data" action="/forum/admin/index.php" method="post">
465 <?php $objid = $this->Forum->getID();?>
466 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
467 <input type="hidden" name="forum_id" value="<?php echo $objid; ?>" />
468 <input type="hidden" name="editmsg" value="<?php echo $msg_id; ?>" />
469 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
470 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
471 <input type="hidden" name="posted_by" value="<?php echo $posted_by;?>">
472 <input type="hidden" name="post_date" value="<?php echo $post_date;?>">
473 <input type="hidden" name="has_followups" value="<?php echo $has_followups;?>">
474 <input type="hidden" name="most_recent_date" value="<?php echo $most_recent_date;?>">
475 <input type="hidden" name="group_id" value="<?php echo $group_id;?>">
476 <fieldset class="fieldset"><table><tr><td valign="top">
477 </td><td valign="top">
479 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
480 <input type="text" name="subject" value="<?php echo $subject; ?>" size="45" maxlength="45" />
482 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms[1].body') ?><?php echo utils_requiredField(); ?><br />
484 $params['body'] = $body;
485 $params['width'] = "800";
486 $params['height'] = "500";
487 $params['group'] = $group_id;
488 plugin_hook("text_editor",$params);
489 if (!$GLOBALS['editor_was_set_up']) {
490 //if we don�t have any plugin for text editor, display a simple textarea edit box
491 echo '<textarea name="body" rows="10" cols="50" wrap="soft">' . $body . '</textarea>';
493 unset($GLOBALS['editor_was_set_up']);
498 <?php //$this->LinkAttachForm();?>
505 <center><input type="submit" name="ok" value="<?php echo _('Update'); ?>" />
506 <input type="submit" name="cancel" value="<?php echo _('Cancel'); ?>" />
509 </td></tr></table></fieldset>
516 function showPostForm($thread_id=0, $is_followup_to=0, $subject="") {
517 global $Language,$sys_default_domain,$group_id;
519 if (strtoupper(getStringFromServer('HTTPS')) == 'ON') {
525 if ($this->Forum->userCanPost()) {
527 //if this is a followup, put a RE: before it if needed
528 if (!eregi('RE:',$subject,$test)) {
529 $subject ='RE: '.$subject;
535 <form "enctype="multipart/form-data" action="/forum/forum.php?forum_id=<?php echo $this->Forum->getID(); ?>&group_id=<?php echo $group_id; ?>" method="post">
536 <?php $objid = $this->Forum->getID();?>
537 <input type="hidden" name="post_message" value="y" />
538 <input type="hidden" name="thread_id" value="<?php echo $thread_id; ?>" />
539 <input type="hidden" name="msg_id" value="<?php echo $is_followup_to; ?>" />
540 <input type="hidden" name="is_followup_to" value="<?php echo $is_followup_to; ?>" />
541 <input type="hidden" name="form_key" value="<?php echo form_generate_key();?>">
542 <fieldset class="fieldset"><table><tr><td valign="top">
543 </td><td valign="top">
545 <strong><?php echo _('Subject:'); ?></strong><?php echo utils_requiredField(); ?><br />
546 <input type="text" name="subject" value="<?php echo $subject; ?>" size="45" maxlength="45" />
548 <strong><?php echo _('Message:'); ?></strong><?php echo notepad_button('document.forms[1].body') ?><?php echo utils_requiredField(); ?><br />
551 $params['body'] = $body;
552 $params['width'] = "800";
553 $params['height'] = "500";
554 $params['group'] = $group_id;
555 plugin_hook("text_editor",$params);
556 if (!$GLOBALS['editor_was_set_up']) {
557 //if we don�t have any plugin for text editor, display a simple textarea edit box
558 echo '<textarea name="body" rows="10" cols="50" wrap="soft">' . $body . '</textarea>';
560 unset($GLOBALS['editor_was_set_up']);
562 <?php //$text_support->displayTextField('body'); ?>
564 <!-- <span class="selected"><?php echo _('HTML tags will display in your post as text'); ?></span> -->
566 <?php $this->LinkAttachForm();?>
571 if (!session_loggedin()) {
572 echo '<span class="highlight">'._('You are posting anonymously because you are not').' <a href="'.$GLOBALS['sys_urlprefix'].'/account/login.php?return_to='. urlencode(getStringFromServer('REQUEST_URI')) .'">['._('logged in').']</a></span>';
576 <input type="submit" name="submit" value="<?php echo _('Post Comment'); echo ((!session_loggedin())?' '._('Anonymously'):''); ?>" /><?php
577 echo ((session_loggedin()) ? ' <input type="checkbox" value="1" name="monitor" /> '._('Receive followups via email').'.' : ''); ?>
579 </td></tr></table></fieldset>
584 } elseif ($this->Forum->allowAnonymous()) {
585 echo '<span class="error">';
586 printf(_('You could post if you were %1$s logged in %2$s'), '<a href="'.$GLOBALS['sys_urlprefix'].'/account/login.php?return_to='.urlencode(getStringFromServer('REQUEST_URI')).' ">', '</a>');
588 } elseif (!session_loggedin()) {
590 <span class="error">'.sprintf(_('Please %1$s login %2$s'), '<a href="'.$GLOBALS['sys_urlprefix'].'/account/login.php?return_to='.urlencode($REQUEST_URI).'">', '</a>').'</span><br/></p>';
599 $messagelink='http://'.$GLOBALS[sys_default_domain].'/forum/message.php?msg_id='.$msg_id;
600 $messagesender=db_result($result,0, 'user_name');
601 $messagebody=util_line_wrap(util_unconvert_htmlspecialchars(db_result($result,0, 'body')));
602 $messagesys=$GLOBALS['sys_name'];
603 $messagemonitor='http://'.$GLOBALS[sys_default_domain].'/forum/monitor.php?forum_id='.$forum_id;
604 $body = stripcslashes(sprintf(_('
605 Read and respond to this message at:
611 ______________________________________________________________________
612 You are receiving this email because you elected to monitor this forum.
613 To stop monitoring this forum, login to %4$s
614 and visit: %5$s'), $messagelink, $messagesender, $messagebody, $messagesys, $messagemonitor));
616 $body = "\nRead and respond to this message at: ".
617 "\nhttp://$GLOBALS[sys_default_domain]/forum/message.php?msg_id=".$msg_id.
618 "\nBy: " . db_result($result,0, 'user_name') .
619 "\n\n" . util_line_wrap(util_unconvert_htmlspecialchars(db_result($result,0, 'body'))).
620 "\n\n______________________________________________________________________".
621 "\nYou are receiving this email because you elected to monitor this forum.".
622 "\nTo stop monitoring this forum, login to ".$GLOBALS['sys_name']." and visit: ".
623 "\nhttp://$GLOBALS[sys_default_domain]/forum/monitor.php?forum_id=$forum_id";
626 $subject="[" .db_result($result,0,'unix_group_name'). " - " . db_result($result,0,'forum_name')."] ".util_unconvert_htmlspecialchars(db_result($result,0,'subject'));
627 util_handle_message(array_unique($tolist),$subject,$body,$send_all_posts_to);
632 // c-file-style: "bsd"