This repository has been archived on 2025-05-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
qemudb/include/comments.php

267 lines
8.1 KiB
PHP
Raw Normal View History

<?php
/***************************/
/* get user info for posts */
/***************************/
2004-03-15 16:22:00 +00:00
function forum_lookup_user($iUserId)
2004-03-24 19:30:36 +00:00
{
$mailto = '';
if ($iUserId > 0)
2004-03-15 16:22:00 +00:00
{
$sQuery = "SELECT email,realname FROM user_list WHERE userId = '".$iUserId."' LIMIT 1";
$hResult = query_appdb($sQuery);
$oUsr = mysql_fetch_object($hResult);
$sMailto = '<a href="mailto:' . $oUsr->email . '">' . $oUsr->realname . '</a>';
2004-03-15 16:22:00 +00:00
}
else
{
$sMailto = '<font color="#999999">Anonymous</font>';
2004-03-15 16:22:00 +00:00
}
return $sMailto;
2004-03-24 19:30:36 +00:00
}
2004-03-15 16:22:00 +00:00
/**
2004-03-24 19:30:36 +00:00
* display a single comment (in $ob)
*/
function view_app_comment($ob)
{
2004-03-15 16:22:00 +00:00
echo html_frame_start('','98%');
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1">',"\n";
$ob->subject = stripslashes($ob->subject);
$ob->body = stripslashes($ob->body);
// message header
echo "<tr bgcolor=#E0E0E0><td>\n";
2004-03-24 19:30:36 +00:00
echo " <b>".$ob->subject."</b><br>\n";
echo " by ".forum_lookup_user($ob->userId)." on ".$ob->time."<br>\n";
2004-03-15 16:22:00 +00:00
echo "</td></tr><tr><td>\n";
// body
echo htmlify_urls($ob->body), "<br><br>\n";
// only add RE: once
if(eregi("RE:", $ob->subject))
$subject = $ob->subject;
else
2004-03-24 19:30:36 +00:00
$subject = "RE: ".$ob->subject;
2004-03-15 16:22:00 +00:00
// reply post buttons
echo " [<a href='addcomment.php?appId=$ob->appId&versionId=$ob->versionId'><small>post new</small></a>] \n";
echo " [<a href='addcomment.php?appId=$ob->appId&versionId=$ob->versionId&subject=".
urlencode("$subject")."&thread=$ob->commentId'><small>reply to this</small></a>] \n";
echo "</td></tr>\n";
// delete message button, for admins
if (loggedin() && (havepriv("admin") || $_SESSION['current']->is_maintainer($ob->appId,$ob->versionId) ))
{
echo "<tr>";
echo "<td><form method=\"post\" name=\"message\" action=\"".BASE."deletecomment.php\"><input type=submit value='Delete' class=button>\n";
echo "<input type=\"hidden\" name=\"commentId\" value=\"$ob->commentId\" />";
echo "<input type=\"hidden\" name=\"appId\" value=\"$ob->appId\" />";
echo "<input type=\"hidden\" name=\"versionId\" value=\"$ob->versionId\" /></form></td>","\n";
echo "</td></tr>";
}
echo "</table>\n";
2004-03-15 16:22:00 +00:00
echo html_frame_end();
}
/**
2004-03-15 16:22:00 +00:00
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
*/
function grab_comments($appId, $versionId, $parentId = -1)
{
$extra = "";
if($parentId != -1)
$extra = "AND parentId = $parentId ";
2004-03-15 16:22:00 +00:00
$qstring = "SELECT from_unixtime(unix_timestamp(time), \"%W %M %D %Y, %k:%i\") as time, ".
"commentId, parentId, appId, versionId, userId, subject, body ".
2004-03-24 19:30:36 +00:00
"FROM appComments WHERE appId = '$appId' AND versionId = '$versionId' ".
$extra.
"ORDER BY appComments.time ASC";
2004-03-15 16:22:00 +00:00
$result = mysql_query($qstring);
return $result;
}
/**
2004-03-15 16:22:00 +00:00
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
*/
function count_comments($appId, $versionId)
{
$qstring = "SELECT count(commentId) as hits FROM appComments WHERE appId = $appId AND versionId = $versionId";
$result = mysql_query($qstring);
$ob = mysql_fetch_object($result);
return $ob->hits;
}
/**
2004-03-15 16:22:00 +00:00
* display nested comments
* handle is a db result set
*/
function do_display_comments_nested($handle)
{
while($ob = mysql_fetch_object($handle))
{
view_app_comment($ob);
$result = grab_comments($ob->appId, $ob->versionId, $ob->commentId);
if($result && mysql_num_rows($result))
2004-03-15 16:22:00 +00:00
{
echo "<blockquote>\n";
do_display_comments_nested($result);
echo "</blockquote>\n";
}
2004-03-15 16:22:00 +00:00
}
}
function display_comments_nested($appId, $versionId, $threadId)
{
$result = grab_comments($appId, $versionId, $threadId);
do_display_comments_nested($result);
}
/**
2004-03-15 16:22:00 +00:00
* display threaded comments
* handle is a db result set
*/
function do_display_comments_threaded($handle, $is_main)
{
2004-03-24 19:30:36 +00:00
if (!$is_main)
echo "<ul>\n";
2004-03-15 16:22:00 +00:00
2004-03-24 19:30:36 +00:00
while ($ob = mysql_fetch_object($handle))
{
if ($is_main)
2004-03-15 16:22:00 +00:00
{
2004-03-24 19:30:36 +00:00
view_app_comment($ob);
} else
2004-03-24 19:30:36 +00:00
{
echo '<li><a href="commentview.php?appId='.$ob->appId.'&versionId='.$ob->versionId.'&threadId='.$ob->parentId.'"> '.
$ob->subject.' </a> by '.forum_lookup_user($ob->userId).' on '.$ob->time.' </li>'."\n";
2004-03-24 19:30:36 +00:00
}
$result = grab_comments($ob->appId, $ob->versionId, $ob->commentId);
if ($result && mysql_num_rows($result))
{
echo "<blockquote>\n";
do_display_comments_threaded($result, 0);
echo "</blockquote>\n";
}
}
if (!$is_main)
echo "</ul>\n";
2004-03-15 16:22:00 +00:00
}
2004-03-15 16:22:00 +00:00
function display_comments_threaded($appId, $versionId, $threadId = 0)
{
$result = grab_comments($appId, $versionId, $threadId);
do_display_comments_threaded($result, 1);
}
/**
2004-03-15 16:22:00 +00:00
* display flat comments
*/
function display_comments_flat($appId, $versionId)
{
$result = grab_comments($appId, $versionId);
2004-03-24 19:30:36 +00:00
if ($result)
{
while($ob = mysql_fetch_object($result))
{
view_app_comment($ob);
}
}
2004-03-15 16:22:00 +00:00
}
2004-03-15 16:22:00 +00:00
function view_app_comments($appId, $versionId, $threadId = 0)
{
2004-03-24 19:30:36 +00:00
// count posts
2004-03-15 16:22:00 +00:00
$result = mysql_query("SELECT commentId FROM appComments WHERE appId = $appId AND versionId = $versionId");
$messageCount = mysql_num_rows($result);
//start comment format table
echo html_frame_start("","98%",'',0);
echo '<table width="100%" border=0 cellpadding=1 cellspacing=0">',"\n";
echo '<tr><td bgcolor=#C0C0C0 align=center><table border=0 cellpadding=0 cellspacing=0><tr bgcolor=#C0C0C0>',"\n";
// message display mode changer
if (loggedin())
{
// FIXME we need to change this so not logged in users can change current view as well
if (isset($_REQUEST['cmode']))
$_SESSION['current']->setpref("comments:mode", $_REQUEST['cmode']);
$sel[$_SESSION['current']->getpref("comments:mode")] = 'selected';
echo '<td><form method=get name=smode action="appview.php">',"\n";
echo "<b>Application Comments</b> $messageCount total comments ";
echo '<b>Mode</b> <select name="cmode" onchange="document.smode.submit();">',"\n";
echo ' <option value=flat '.$sel['flat'].'>Flat</option>',"\n";
echo ' <option value=threaded '.$sel['threaded'].'>Threaded</option>',"\n";
echo ' <option value=nested '.$sel['nested'].'>Nested</option>',"\n";
echo ' <option value=off '.$sel['off'].'>No Comments</option>',"\n";
echo '</select><input type=hidden name="appId" value="'.$appId.'">',"\n";
echo '<input type=hidden name="versionId" value="'.$versionId.'"></form></td>',"\n";
2004-03-15 16:22:00 +00:00
}
// blank space
echo '<td> &nbsp; </td>',"\n";
// post new message button
echo '<td><form method=get name=message action="addcomment.php"><input type=submit value=" post new comment " class=button> ',"\n";
echo '<input type=hidden name="appId" value="'.$appId.'"><input type=hidden name="versionId" value="'.$versionId.'"></form></td>',"\n";
2004-03-24 19:30:36 +00:00
2004-03-15 16:22:00 +00:00
//end comment format table
echo '</tr></table></td></tr>',"\n";
echo '</table>',"\n";
2004-03-24 19:30:36 +00:00
echo html_frame_end();
if( $messageCount > 0 )
{
echo '<p align="center">The following comments are owned by whoever posted them. WineHQ is not responsible for what they say.</p>'."\n";
}
2004-03-15 16:22:00 +00:00
//start comments
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1"><tr><td>',"\n";
//hide or display depending on pref
if (loggedin())
$mode = $_SESSION['current']->getpref("comments:mode");
2004-03-15 16:22:00 +00:00
else
$mode = "flat";
2004-03-15 16:22:00 +00:00
switch ($mode)
{
case "flat":
display_comments_flat($appId, $versionId);
break;
2004-03-15 16:22:00 +00:00
case "nested":
display_comments_nested($appId, $versionId, $threadId);
break;
2004-03-15 16:22:00 +00:00
case "threaded":
display_comments_threaded($appId, $versionId, $threadId);
break;
2004-03-15 16:22:00 +00:00
}
echo '</td></tr></table>',"\n";
}
?>