- new Comment class

- improved performances (much less duplicated mysql queries)
- less code and better error handling
- informs the whole thread when posting new comment
- fix various bugs
This commit is contained in:
Jonathan Ernst
2005-02-02 03:01:29 +00:00
committed by WineHQ
parent 64d8f93b15
commit 03c0c145c5
10 changed files with 510 additions and 457 deletions

View File

@@ -10,6 +10,7 @@ include("path.php");
require(BASE."include/incl.php");
require(BASE."include/application.php");
require(BASE."include/mail.php");
require(BASE."include/comment.php");
// you must be logged in to submit comments
if(!$_SESSION['current']->isLoggedIn())
@@ -19,17 +20,12 @@ if(!$_SESSION['current']->isLoggedIn())
exit;
}
if(!is_numeric($_REQUEST['appId']))
if(!is_numeric($_REQUEST['versionId']))
{
errorpage('Internal Database Access Error');
exit;
}
if(!is_numeric($_REQUEST['versionId']))
{
$_REQUEST['versionId'] = 0;
}
if(!is_numeric($_REQUEST['thread']))
{
$_REQUEST['thread'] = 0;
@@ -40,47 +36,9 @@ if(!is_numeric($_REQUEST['thread']))
############################
if(isset($_REQUEST['body']))
{
$hostname = get_remote();
// get current userid
$userId = $_SESSION['current']->userid;
$aInsert = compile_insert_string(array( 'parentId' => $_REQUEST['thread'],
'appId' => $_REQUEST['appId'],
'versionId' => $_REQUEST['versionId'],
'userId' => $userId,
'hostname' => $hostname,
'subject' => $_REQUEST['subject'],
'body' => $_REQUEST['body']));
$result = query_appdb("INSERT INTO appComments (`time`, {$aInsert['FIELDS']}) VALUES (NOW(), {$aInsert['VALUES']})");
if ($result)
{
$sEmail = $oOriginator->sEmail;
$sFullAppName = "Comment added to ".lookupAppName($_REQUEST['appId'])." ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
$sMsg = APPDB_ROOT."appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId'].".\n";
$sMsg .= "\n";
$sMsg .= $_SESSION['current']->sRealname." added comment to ".$sFullAppName."\n";
$sMsg .= "\n";
$sMsg .= "Subject: ".$_REQUEST['subject']."\n";
$sMsg .= $_REQUEST['body']."\n";
$oOriginator = new User($_REQUEST['originator']);
if ($oOriginator->wantsEmail())
{
mail_appdb($sEmail, $sFullAppName ,$sMsg);
addmsg("Comment message sent to original poster", "green");
}
$sEmail = get_notify_email_address_list($_REQUEST['appId'], $_REQUEST['versionId']);
if($sEmail)
{
mail_appdb($sEmail, $sFullAppName ,$sMsg);
}
addmsg("New comment posted.", "green");
}
redirect(apidb_fullurl("appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
$oComment = new Comment();
$oComment->create($_REQUEST['subject'], $_REQUEST['body'], $_REQUEST['thread'], $_REQUEST['versionId']);
redirect(apidb_fullurl("appview.php?versionId=".$oComment->iVersionId));
}
################################
@@ -133,10 +91,6 @@ else
}
echo "</form>";
}
?>
<p>&nbsp;</p>
<?
apidb_footer();
?>

View File

@@ -5,8 +5,8 @@
/************************************************************/
include("path.php");
include(BASE."include/"."incl.php");
require(BASE."include/"."comments.php");
include(BASE."include/incl.php");
require(BASE."include/comment.php");
apidb_header("Comments");

View File

@@ -9,7 +9,7 @@
include("path.php");
require(BASE."include/incl.php");
require(BASE."include/application.php");
require(BASE."include/comments.php");
require(BASE."include/comment.php");
require(BASE."include/appdb.php");
require(BASE."include/vote.php");
require(BASE."include/category.php");
@@ -142,8 +142,8 @@ function display_versions($appId, $versions)
//set row color
$bgcolor = ($c % 2 == 0) ? "color0" : "color1";
//format desc
$desc = substr(stripslashes($ver->description),0,75);
// Description
$desc = trim_description($ver->description);
if(strlen($desc) == 75)
$desc .= " ...";
@@ -152,7 +152,7 @@ function display_versions($appId, $versions)
//display row
echo "<tr class=$bgcolor>\n";
echo " <td><a href='appview.php?appId=$appId&versionId=$ver->versionId'>".$ver->versionName."</a></td>\n";
echo " <td><a href='appview.php?versionId=$ver->versionId'>".$ver->versionName."</a></td>\n";
echo " <td>$desc &nbsp;</td>\n";
echo " <td align=center>$ver->maintainer_rating</td>\n";
echo " <td align=center>$ver->maintainer_release</td>\n";
@@ -172,25 +172,16 @@ function display_versions($appId, $versions)
/**
* We want to see an application family (=no version)
*/
if(!is_numeric($_REQUEST['appId']))
if(!is_numeric($_REQUEST['appId']) && !is_numeric($_REQUEST['versionId']))
{
errorpage("Something went wrong with the application ID");
errorpage("Something went wrong with the application or version id");
exit;
}
$appId = $_REQUEST['appId'];
if(!empty($_REQUEST['versionId']) AND !is_numeric($_REQUEST['versionId']))
if($_REQUEST['appId'])
{
errorpage("Something went wrong with the version ID");
exit;
}
$versionId = $_REQUEST['versionId'];
if($appId && !$versionId)
{
$app = new Application($appId);
$app = new Application($_REQUEST['appId']);
$data = $app->data;
if(!$data)
{
@@ -207,7 +198,7 @@ if($appId && !$versionId)
apidb_header("Viewing App - ".$data->appName);
// cat display
display_catpath($app->data->catId, $appId);
display_catpath($app->data->catId, $_REQUEST['appId']);
// set Vendor
$vendor = $app->getVendor();
@@ -217,7 +208,7 @@ if($appId && !$versionId)
// start display application
echo html_frame_start("","98%","",0);
echo "<link rel=\"stylesheet\" href=\"./application.css\" type=\"text/css\">";
echo "<tr><td class=color4 valign=top>\n";
echo " <table>\n";
echo " <tr><td>\n";
@@ -237,7 +228,7 @@ if($appId && !$versionId)
echo " <tr class=\"color1\"><td><b>URL</b></td><td>".$appLinkURL."</td></tr>\n";
// optional links
$result = query_appdb("SELECT * FROM appData WHERE appId = $appId AND versionID = 0 AND type = 'url'");
$result = query_appdb("SELECT * FROM appData WHERE appId = ".$_REQUEST['appId']." AND versionID = 0 AND type = 'url'");
if($result && mysql_num_rows($result) > 0)
{
echo " <tr class=\"color1\"><td> <b>Links</b></td><td>\n";
@@ -249,7 +240,7 @@ if($appId && !$versionId)
}
// image
$img = get_screenshot_img($appId);
$img = get_screenshot_img($_REQUEST['appId']);
echo "<tr><td align=center colspan=2>$img</td></tr>\n";
echo " </table>\n"; /* close of name/vendor/bugs/url table */
@@ -260,7 +251,7 @@ if($appId && !$versionId)
// Display all supermaintainers maintainers of this application
echo " <table class=color4 width=250 border=1>\n";
echo " <tr><td align=left><b>Super maintainers:</b></td></tr>\n";
$other_maintainers = getSuperMaintainersUserIdsFromAppId($appId);
$other_maintainers = getSuperMaintainersUserIdsFromAppId($_REQUEST['appId']);
if($other_maintainers)
{
while(list($index, list($userIdValue)) = each($other_maintainers))
@@ -279,7 +270,7 @@ if($appId && !$versionId)
if($_SESSION['current']->isLoggedIn())
{
/* are we already a maintainer? */
if($_SESSION['current']->isSuperMaintainer($appId)) /* yep */
if($_SESSION['current']->isSuperMaintainer($_REQUEST['appId'])) /* yep */
{
echo ' <form method=post name=message action="maintainerdelete.php"><input type=submit value="Remove yourself as a super maintainer" class=button>';
} else /* nope */
@@ -287,14 +278,13 @@ if($appId && !$versionId)
echo ' <form method=post name=message action="maintainersubmit.php"><input type=submit value="Be a super maintainer of this app" class=button>';
}
echo " <input type=hidden name='appId' value=$appId>";
echo " <input type=hidden name='versionId' value=$versionId>";
echo " <input type=hidden name='superMaintainer' value=1>"; /* set superMaintainer to 1 because we are at the appFamily level */
echo " <input type=\"hidden\" name=\"appId\" value=\"".$_REQUEST['appId']."\">";
echo " <input type=\"hidden\" name=\"superMaintainer\" value=\"1\">"; /* set superMaintainer to 1 because we are at the appFamily level */
echo " </form>";
if($_SESSION['current']->isSuperMaintainer($appId) || $_SESSION['current']->hasPriv("admin"))
if($_SESSION['current']->isSuperMaintainer($_REQUEST['appId']) || $_SESSION['current']->hasPriv("admin"))
{
echo ' <form method="post" name="edit" action="admin/editAppFamily.php"><input type="hidden" name="appId" value="'.$appId.'"><input type="submit" value="Edit App" class="button"></form>';
echo ' <form method="post" name="edit" action="admin/editAppFamily.php"><input type="hidden" name="appId" value="'.$_REQUEST['appId'].'"><input type="submit" value="Edit App" class="button"></form>';
echo '<form method="post" name="message" action="appsubmit.php?appId='.$_REQUEST['appId'].'&apptype=2">';
echo '<input type=submit value="Add Version" class="button">';
echo '</form>';
@@ -303,7 +293,7 @@ if($appId && !$versionId)
{
$url = BASE."admin/deleteAny.php?what=appFamily&appId=".$_REQUEST['appId']."&confirmed=yes";
echo " <form method=\"post\" name=\"edit\" action=\"javascript:deleteURL(\"Are you sure?\", \"".$url."\")\"><input type=\"submit\" value=\"Delete App\" class=\"button\"></form>";
echo ' <form method="post" name="edit" action="admin/editBundle.php"><input type="hidden" name="bundleId" value="'.$appId.'"><input type="submit" value="Edit Bundle" class="button"></form>';
echo ' <form method="post" name="edit" action="admin/editBundle.php"><input type="hidden" name="bundleId" value="'.$_REQUEST['appId'].'"><input type="submit" value="Edit Bundle" class="button"></form>';
}
} else
{
@@ -320,29 +310,33 @@ if($appId && !$versionId)
// description
echo " <td class=color2 valign=top width='100%'>\n";
echo " <table width='100%' border=0><tr><td width='100%' valign=top><b>Description</b><br />\n";
echo add_br(stripslashes($data->description));
echo " <table width='100%' border=0><tr><td width='100%' valign=top><span class=\"title\">Description</span>\n";
echo $data->description;
echo " </td></tr></table>\n";
echo html_frame_end("For more details and user comments, view the versions of this application.");
// display versions
display_versions($appId,$app->getAppVersionList());
display_versions($_REQUEST['appId'],$app->getAppVersionList());
// display bundle
display_bundle($appId);
display_bundle($_REQUEST['appId']);
// disabled for now
//log_application_visit($appId);
//log_application_visit($_REQUEST['appId']);
}
#######################################
# We want to see a particular version #
#######################################
else if($appId && $versionId)
else if($_REQUEST['versionId'])
{
$app = new Application($appId);
//FIXME: get rid of appId references everywhere, as version is enough.
$sQuery = "SELECT appId FROM appVersion WHERE versionId = '".$_REQUEST['versionId']."'";
$hResult = query_appdb($sQuery);
$oRow = mysql_fetch_object($hResult);
$appId = $oRow->appId;
$app = new Application($oRow->appId);
$data = $app->data;
if(!$data)
{
@@ -351,7 +345,7 @@ else if($appId && $versionId)
exit;
}
$ver = $app->getAppVersion($versionId);
$ver = $app->getAppVersion($_REQUEST['versionId']);
if(!$ver)
{
// Oops! Version not found or other error. do something
@@ -360,24 +354,24 @@ else if($appId && $versionId)
}
// header
apidb_header("Viewing App Version - ".$data->appName);
apidb_header("Viewing App Version - ".$data->appName);
// cat
display_catpath($app->data->catId, $appId, $versionId);
display_catpath($app->data->catId, $appId, $_REQUEST['versionId']);
// set URL
$appLinkURL = ($ver->webPage) ? "<a href='$ver->webPage'>".substr(stripslashes($ver->webPage),0,30)."</a>": "&nbsp;";
// start version display
echo html_frame_start("","98%","",0);
echo "<link rel=\"stylesheet\" href=\"./application.css\" type=\"text/css\">";
echo '<tr><td class=color4 valign=top>',"\n";
echo '<table width="250" border=0 cellpadding=3 cellspacing=1">',"\n";
echo "<tr class=color0 valign=top><td width=100> <b>Name</b></td><td width='100%'>".stripslashes($data->appName)."</td>\n";
echo "<tr class=color1 valign=top><td> <b>Version</b></td><td>".stripslashes($ver->versionName)."</td></tr>\n";
// links
$result = query_appdb("SELECT * FROM appData WHERE appId = $appId AND versionID = $versionId AND type = 'url'");
$result = query_appdb("SELECT * FROM appData WHERE appId = $appId AND versionID = ".$_REQUEST['versionId']." AND type = 'url'");
if($result && mysql_num_rows($result) > 0)
{
echo " <tr class=\"color1\"><td><b>Links</b></td><td>\n";
@@ -393,13 +387,13 @@ else if($appId && $versionId)
echo "<tr class=\"color0\" valign=\"top\"><td> <b>Maintainers Version</b></td><td>".stripslashes($ver->maintainer_release)."</td></tr>\n";
// image
$img = get_screenshot_img($appId, $versionId);
$img = get_screenshot_img($appId, $_REQUEST['versionId']);
echo "<tr><td align=center colspan=2>$img</td></tr>\n";
// display all maintainers of this application
echo "<tr class=color0><td align=left colspan=2><b>Maintainers of this application:</b>\n";
echo "<table width=250 border=0>";
$other_maintainers = getMaintainersUserIdsFromAppIdVersionId($appId, $versionId);
$other_maintainers = getMaintainersUserIdsFromAppIdVersionId($appId, $_REQUEST['versionId']);
if($other_maintainers)
{
while(list($index, list($userIdValue)) = each($other_maintainers))
@@ -428,7 +422,7 @@ else if($appId && $versionId)
} else
{
/* are we already a maintainer? */
if($_SESSION['current']->isMaintainer($appId, $versionId)) /* yep */
if($_SESSION['current']->isMaintainer($appId, $_REQUEST['versionId'])) /* yep */
{
echo '<form method=post name=message action="maintainerdelete.php"><input type=submit value="Remove yourself as a maintainer" class=button>';
echo "<input type=hidden name='superMaintainer' value=0>";
@@ -438,8 +432,8 @@ else if($appId && $versionId)
}
}
echo "<input type=hidden name='appId' value=$appId>";
echo "<input type=hidden name='versionId' value=$versionId>";
echo "<input type=hidden name=\"appId\" value=\"".$appId."\">";
echo "<input type=hidden name=\"versionId\" value=\"".$_REQUEST['versionId']."\">";
echo "</form>";
} else
{
@@ -450,26 +444,26 @@ else if($appId && $versionId)
echo "</center></td></tr>";
if ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($appId, $versionId)))
if ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($appId, $_REQUEST['versionId'])))
{
echo "<tr><td colspan = 2><center>";
echo '<form method=post name=message action=admin/editAppVersion.php?appId='.$appId.'&versionId='.$versionId.'>';
echo '<form method=post name=message action=admin/editAppVersion.php?appId='.$appId.'&versionId='.$_REQUEST['versionId'].'>';
echo '<input type=submit value="Edit Version Info" class=button>';
echo '</form>';
$url = BASE."admin/deleteAny.php?what=appVersion&appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."&confirmed=yes";
echo "<form method=\"post\" name=\"delete\" action=\"javascript:deleteURL('Are you sure?', '".$url."')\">";
echo '<input type=submit value="Delete Version" class="button">';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?appId='.$appId.'&versionId='.$versionId.'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$_REQUEST['versionId'].'>';
echo '<input type=submit value="Add Note" class=button>';
echo '</form>';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?appId='.$appId.'&versionId='.$versionId.'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$_REQUEST['versionId'].'>';
echo '<input type=hidden name="noteTitle" value="HOWTO">';
echo '<input type=submit value="Add How To" class=button>';
echo '</form>';
echo '</form>';
echo '<form method=post name=message action=admin/addAppNote.php?appId='.$appId.'&versionId='.$versionId.'>';
echo '<form method=post name=message action=admin/addAppNote.php?versionId='.$versionId.'>';
echo '<input type=hidden name="noteTitle" value="WARNING">';
echo '<input type=submit value="Add Warning" class=button>';
echo '</form>';
@@ -478,9 +472,9 @@ else if($appId && $versionId)
echo "</table><td class=color2 valign=top width='100%'>\n";
//Desc Image
// description
echo "<table width='100%' border=0><tr><td width='100%' valign=top> <b>Description</b><br />\n";
echo add_br(stripslashes($ver->description));
echo $ver->description;
echo "</td></tr>";
/* close the table */
@@ -488,21 +482,15 @@ else if($appId && $versionId)
echo html_frame_end();
$rNotes = query_appdb("SELECT * FROM appNotes WHERE appId = $appId and versionId = $versionId");
$rNotes = query_appdb("SELECT * FROM appNotes WHERE versionId = ".$_REQUEST['versionId']);
while( $oNote = mysql_fetch_object($rNotes) )
{
echo show_note($oNote->noteTitle,$oNote);
}
//TODO: code to view/add user experience record
// if(!$versionId)
// {
// $versionId = 0;
// }
// Comments Section
view_app_comments($appId, $versionId);
view_app_comments($_REQUEST['versionId']);
} else
{
@@ -510,10 +498,6 @@ else if($appId && $versionId)
errorpage('Page Called with No Params!');
exit;
}
?>
<p>&nbsp;</p>
<?php
apidb_footer();
?>

View File

@@ -9,7 +9,7 @@
include("path.php");
require(BASE."include/incl.php");
require(BASE."include/application.php");
require(BASE."include/comments.php");
require(BASE."include/comment.php");
require(BASE."include/appdb.php");
require(BASE."include/screenshot.php");
require(BASE."include/category.php");

View File

@@ -9,8 +9,8 @@
* application environment
*/
include("path.php");
include(BASE."include/"."incl.php");
require(BASE."include/"."comments.php");
include(BASE."include/incl.php");
require(BASE."include/comment.php");
apidb_header("Comments");

View File

@@ -10,6 +10,7 @@ include("path.php");
require(BASE."include/incl.php");
require(BASE."include/application.php");
require(BASE."include/mail.php");
require(BASE."include/comment.php");
$_REQUEST['appId'] = strip_tags($_REQUEST['appId']);
@@ -26,42 +27,24 @@ if(!$_SESSION['current']->isLoggedIn())
/* if we aren't an admin or the maintainer of this app we shouldn't be */
/* allowed to delete any comments */
if(!$_SESSION['current']->hasPriv("admin") &&
!$_SESSION['current']->isMaintainer($_REQUEST['appId'],
$_REQUEST['versionId']))
!$_SESSION['current']->isMaintainer($_REQUEST['appId'], $_REQUEST['versionId']))
{
errorpage('You don\'t have admin privileges');
errorpage('You don\'t have sufficient privileges to delete this comment.');
exit;
}
/* retrieve the parentID of the comment we are deleting */
/* so we can fix up the parentIds of this comments children */
$result = query_appdb("SELECT parentId FROM appComments WHERE commentId = '".$_REQUEST['commentId']."'");
if (!$result)
{
errorpage('Internal error retrieving parent of commentId');
exit;
}
$oComment = new Comment($_REQUEST['commentId']);
$ob = mysql_fetch_object($result);
$deletedParentId = $ob->parentId;
/* get the subject and body from the comment */
$result = query_appdb("select * FROM appComments WHERE commentId = '".$_REQUEST['commentId']."'");
if (!$result) redirect(apidb_fullurl("appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
$ob = mysql_fetch_object($result);
$body = $ob->body;
$subject = $ob->subject;
if($_SESSION['current']->getpref("confirm_comment_deletion") != "no" &&
!isset($_REQUEST['int_delete_it']))
if($_SESSION['current']->getPref("confirm_comment_deletion") != "no" && !isset($_REQUEST['int_delete_it']))
{
apidb_header("Delete Comment");
$mesTitle = "<b>Please state why you are deleting the following comment</b>";
echo "<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo html_frame_start($mesTitle,500,"",0);
echo "<br />";
echo html_frame_start($ob->subject,500);
echo htmlify_urls($ob->body), "<br /><br />\n";
echo html_frame_start($oComment->sSubject,500);
echo htmlify_urls($oComment->sBody), "<br /><br />\n";
echo html_frame_end();
echo '<table width="100%" border=0 cellpadding=0 cellspacing=1>',"\n";
echo "<tr class=color1><td colspan=2><textarea name=\"str_why\" cols=\"70\" rows=\"15\" wrap=\"virtual\"></textarea></td></tr>\n";
@@ -84,46 +67,7 @@ if($_SESSION['current']->getpref("confirm_comment_deletion") != "no" &&
apidb_footer();
} else
{
/* delete the comment from the database */
$result = query_appdb("DELETE FROM appComments WHERE commentId = '".$_REQUEST['commentId']."'");
if ($result)
{
/* fixup the child comments so the parentId points to a valid parent comment */
$result = query_appdb("UPDATE appComments set parentId = '$deletedParentId' WHERE parentId = '".$_REQUEST['commentId']."'");
if(!$result)
{
errorpage('Internal database error fixing up the parentId of child comments');
exit;
} else
{
$sEmail = get_notify_email_address_list($_REQUEST['appId'], $_REQUEST['versionId']);
$oUser = new User($ob->userId);
$notify_user_email=$oUser->sEmail;
$notify_user_realname=$oUser->sRealname;
$sEmail .= $notify_user_email;
if($sEmail)
{
$sFullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
$sMsg = APPDB_ROOT."appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\r\n";
$sMsg .= "\r\n";
$sMsg .= $_SESSION['current']->realname." deleted comment from ".$sFullAppName."\r\n";
$sMsg .= "\n";
$sMsg .= "This comment was made on ".substr($ob->time,0,10)." by $notify_user_realname \r\n";
$sMsg .= "\r\n";
$sMsg .= "Subject: ".$subject."\r\n";
$sMsg .= "\r\n";
$sMsg .= $body."\r\n";
$sMsg .= "\r\n";
$sMsg .= "Because:\r\n";
if($_REQUEST['str_why'])
$sMsg .= stripslashes($_REQUEST['str_why'])."\r\n";
else
$sMsg .= "No reason given.\r\n";
mail_appdb($sEmail, $sFullAppName ,$sMsg);
}
addmsg("Comment deleted", "green");
redirect(apidb_fullurl("appview.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
}
}
$oComment->delete($_REQUEST['str_why']);
redirect(apidb_fullurl("appview.php?versionId=".$_REQUEST['versionId']));
}
?>

436
include/comment.php Normal file
View File

@@ -0,0 +1,436 @@
<?php
/***************************************/
/* comment class and related functions */
/***************************************/
/**
* Comment class for handling comments
*/
class Comment {
var $iCommentId;
var $iParentId;
var $iAppId;
var $iVersionId;
var $sSubject;
var $sBody;
var $sDateCreated;
var $sHostname;
var $oOwner;
/**
* Constructor.
* If $iCommentId is provided, fetches comment.
*/
function Comment($iCommentId="")
{
if($iCommentId)
{
$sQuery = "SELECT appComments.*, appVersion.appId AS appId
FROM appComments, appVersion
WHERE appComments.versionId = appVersion.versionId
AND commentId = '".$iCommentId."'";
$hResult = query_appdb($sQuery);
$oRow = mysql_fetch_object($hResult);
$this->iCommentId = $oRow->commentId;
$this->iParentId = $oRow->parentId;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sSubject = $oRow->subject;
$this->sBody = $oRow->body;
$this->sDateCreated = $oRow->time;
$this->sHostname = $oRow->hostname;
$this->oOwner = new User($oRow->userId);
}
}
/*
* Creates a new comment.
* Informs interested people about the creation.
* Returns true on success, false on failure
*/
function create($sSubject, $sBody, $iParentId=null, $iVersionId)
{
$aInsert = compile_insert_string(array( 'parentId' => $iParentId,
'versionId' => $iVersionId,
'subject' => $sSubject,
'body' => $sBody ));
$sFields = "({$aInsert['FIELDS']}, `userId`, `time`, `hostname`)";
$sValues = "({$aInsert['VALUES']}, ".$_SESSION['current']->iUserId.", NOW(), '".get_remote()."')";
if(query_appdb("INSERT INTO appComments $sFields VALUES $sValues", "Error while creating a new comment."))
{
$this->comment(mysql_insert_id());
$sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail." ";
// fetches e-mails from parent comments
while($iParentId)
{
$oParent = new Comment($iParentId);
$sEmail .= $oParent->oOwner->sEmail." ";
$iParentId = $oParent->iParentId;
}
if($sEmail)
{
$sSubject = "Comment for ".lookupAppName($this->iAppId)." ".lookupVersionName($this->iVersionId)." added by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?appId=".$this->iAppId."&versionId=".$this->iVersionId."\n";
$sMsg .= "\n";
$sMsg .= "Subject: ".$this->sSubject."\r\n";
$sMsg .= "\n";
$sMsg .= $this->sBody."\r\n";
mail_appdb($sEmail, $sSubject ,$sMsg);
}
addmsg("Comment created.", "green");
return true;
}
else
return false;
}
/**
* Update comment.
* FIXME: Informs interested people about the modification.
* Returns true on success and false on failure.
*/
function update($sSubject=null, $sBody=null, $iParentId=null, $iVersionId=null)
{
if ($iParentId)
{
if (!query_appdb("UPDATE appComments SET parentId = '".$iParentId."' WHERE commentId = ".$this->iCommentId))
return false;
$this->iParentId = $iParentId;
}
if ($iVersionId)
{
if (!query_appdb("UPDATE appComments SET versionId = '".$iVersionId."' WHERE commentId = ".$this->iCommentId))
return false;
$this->iVersionId = $iVersionId;
// FIXME: we need to refetch $this->iAppId.
}
if ($sSubject)
{
if (!query_appdb("UPDATE appComments SET subject = '".$sSubject."' WHERE commentId = ".$this->iCommentId))
return false;
$this->sSubject = $sSubject;
}
if ($sBody)
{
if (!query_appdb("UPDATE appComments SET body = '".$sBody."' WHERE commentId = ".$this->iCommentId))
return false;
$this->sBody = $sBody;
}
return true;
}
/**
* Removes the current comment from the database.
* Informs interested people about the deletion.
* Returns true on success and false on failure.
*/
function delete($sReason=null)
{
$hResult = query_appdb("DELETE FROM appComments WHERE commentId = '".$this->iCommentId."'");
if ($hResult)
{
/* fixup the child comments so the parentId points to a valid parent comment */
$hResult = query_appdb("UPDATE appComments set parentId = '".$this->iParentId."' WHERE parentId = '".$this->iCommentId."'");
$sEmail = get_notify_email_address_list($this->iAppId, $this->iVersionId);
$sEmail .= $this->oOwner->sEmail;
if($sEmail)
{
$sSubject = "Comment for ".lookupAppName($this->iAppId)." ".lookupVersionName($this->iVersionId)." deleted by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?appId=".$this->iAppId."&versionId=".$this->iVersionId."\n";
$sMsg .= "\n";
$sMsg .= "This comment was made on ".substr($this->sDateCreated,0,10)." by ".$this->oOwner->sRealname."\n";
$sMsg .= "\n";
$sMsg .= "Subject: ".$this->sSubject."\r\n";
$sMsg .= "\n";
$sMsg .= $this->sBody."\r\n";
$sMsg .= "\n";
$sMsg .= "Because:\n";
if($sReason)
$sMsg .= $sReason."\n";
else
$sMsg .= "No reason given.\n";
mail_appdb($sEmail, $sSubject ,$sMsg);
}
addmsg("Comment deleted.", "green");
return true;
}
return false;
}
}
/*
* Comment functions that are not part of the class
*/
function forum_lookup_user($iUserId)
{
if ($iUserId > 0)
{
$oUser = new User($iUserId);
$sMailto = '<a href="mailto:' . $oUser->sEmail . '">' . $oUser->sRealname . '</a>';
}
if (!$iUserId || !$oUser->isLoggedIn())
{
$sMailto = '<font color="#999999">Anonymous</font>';
}
return $sMailto;
}
/**
* display a single comment (in $ob)
*/
function view_app_comment($ob)
{
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";
echo " <b>".$ob->subject."</b><br>\n";
echo " by ".forum_lookup_user($ob->userId)." on ".$ob->time."<br>\n";
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
$subject = "RE: ".$ob->subject;
// 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 ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($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";
echo html_frame_end();
}
/**
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
*/
function grab_comments($versionId, $parentId = -1)
{
$extra = "";
if($parentId != -1)
$extra = "AND parentId = $parentId ";
$qstring = "SELECT from_unixtime(unix_timestamp(appComments.time), \"%W %M %D %Y, %k:%i\") as time, ".
"appComments.commentId, appComments.parentId, appComments.versionId, appComments.userId, appComments.subject, appComments.body, appVersion.appId ".
"FROM appComments, appVersion WHERE appComments.versionId = appVersion.versionId AND appComments.versionId = '$versionId' ".
$extra.
"ORDER BY appComments.time ASC";
$result = query_appdb($qstring);
return $result;
}
/**
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
*/
function count_comments($versionId)
{
$qstring = "SELECT count(commentId) as hits FROM appComments WHERE versionId = $versionId";
$result = query_appdb($qstring);
$ob = mysql_fetch_object($result);
return $ob->hits;
}
/**
* 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->versionId, $ob->commentId);
if($result && mysql_num_rows($result))
{
echo "<blockquote>\n";
do_display_comments_nested($result);
echo "</blockquote>\n";
}
}
}
function display_comments_nested($versionId, $threadId)
{
$result = grab_comments($versionId, $threadId);
do_display_comments_nested($result);
}
/**
* display threaded comments
* handle is a db result set
*/
function do_display_comments_threaded($handle, $is_main)
{
if (!$is_main)
echo "<ul>\n";
while ($ob = mysql_fetch_object($handle))
{
if ($is_main)
{
view_app_comment($ob);
} else
{
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";
}
$result = grab_comments($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";
}
function display_comments_threaded($versionId, $threadId = 0)
{
$result = grab_comments($versionId, $threadId);
do_display_comments_threaded($result, 1);
}
/**
* display flat comments
*/
function display_comments_flat($versionId)
{
$result = grab_comments($versionId);
if ($result)
{
while($ob = mysql_fetch_object($result))
{
view_app_comment($ob);
}
}
}
function view_app_comments($versionId, $threadId = 0)
{
// count posts
$result = query_appdb("SELECT commentId FROM appComments WHERE 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 ($_SESSION['current']->isLoggedIn())
{
// 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>',"\n";
echo '<input type=hidden name="versionId" value="'.$versionId.'"></form></td>',"\n";
}
// 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="versionId" value="'.$versionId.'"></form></td>',"\n";
//end comment format table
echo '</tr></table></td></tr>',"\n";
echo '</table>',"\n";
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";
}
//start comments
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1"><tr><td>',"\n";
//hide or display depending on pref
if ($_SESSION['current']->isLoggedIn())
$mode = $_SESSION['current']->getPref("comments:mode");
else
$mode = "flat";
switch ($mode)
{
case "flat":
display_comments_flat($versionId);
break;
case "nested":
display_comments_nested($versionId, $threadId);
break;
case "threaded":
display_comments_threaded($versionId, $threadId);
break;
}
echo '</td></tr></table>',"\n";
}
?>

View File

@@ -1,263 +0,0 @@
<?php
/***************************/
/* get user info for posts */
/***************************/
function forum_lookup_user($iUserId)
{
if ($iUserId > 0)
{
$oUser = new User($iUserId);
$sMailto = '<a href="mailto:' . $oUser->sEmail . '">' . $oUser->sRealname . '</a>';
}
else
{
$sMailto = '<font color="#999999">Anonymous</font>';
}
return $sMailto;
}
/**
* display a single comment (in $ob)
*/
function view_app_comment($ob)
{
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";
echo " <b>".$ob->subject."</b><br>\n";
echo " by ".forum_lookup_user($ob->userId)." on ".$ob->time."<br>\n";
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
$subject = "RE: ".$ob->subject;
// 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 ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($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";
echo html_frame_end();
}
/**
* 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 ";
$qstring = "SELECT from_unixtime(unix_timestamp(time), \"%W %M %D %Y, %k:%i\") as time, ".
"commentId, parentId, appId, versionId, userId, subject, body ".
"FROM appComments WHERE appId = '$appId' AND versionId = '$versionId' ".
$extra.
"ORDER BY appComments.time ASC";
$result = query_appdb($qstring);
return $result;
}
/**
* 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 = query_appdb($qstring);
$ob = mysql_fetch_object($result);
return $ob->hits;
}
/**
* 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))
{
echo "<blockquote>\n";
do_display_comments_nested($result);
echo "</blockquote>\n";
}
}
}
function display_comments_nested($appId, $versionId, $threadId)
{
$result = grab_comments($appId, $versionId, $threadId);
do_display_comments_nested($result);
}
/**
* display threaded comments
* handle is a db result set
*/
function do_display_comments_threaded($handle, $is_main)
{
if (!$is_main)
echo "<ul>\n";
while ($ob = mysql_fetch_object($handle))
{
if ($is_main)
{
view_app_comment($ob);
} else
{
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";
}
$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";
}
function display_comments_threaded($appId, $versionId, $threadId = 0)
{
$result = grab_comments($appId, $versionId, $threadId);
do_display_comments_threaded($result, 1);
}
/**
* display flat comments
*/
function display_comments_flat($appId, $versionId)
{
$result = grab_comments($appId, $versionId);
if ($result)
{
while($ob = mysql_fetch_object($result))
{
view_app_comment($ob);
}
}
}
function view_app_comments($appId, $versionId, $threadId = 0)
{
// count posts
$result = query_appdb("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 ($_SESSION['current']->isLoggedIn())
{
// 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";
}
// 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";
//end comment format table
echo '</tr></table></td></tr>',"\n";
echo '</table>',"\n";
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";
}
//start comments
echo '<table width="100%" border=0 cellpadding=2 cellspacing=1"><tr><td>',"\n";
//hide or display depending on pref
if ($_SESSION['current']->isLoggedIn())
$mode = $_SESSION['current']->getpref("comments:mode");
else
$mode = "flat";
switch ($mode)
{
case "flat":
display_comments_flat($appId, $versionId);
break;
case "nested":
display_comments_nested($appId, $versionId, $threadId);
break;
case "threaded":
display_comments_threaded($appId, $versionId, $threadId);
break;
}
echo '</td></tr></table>',"\n";
}
?>

View File

@@ -137,13 +137,11 @@ create table appComments (
time datetime,
commentId int not null auto_increment,
parentId int default 0,
appId int not null,
versionId int default 0,
versionId int not null,
userId int,
hostname varchar(80),
subject varchar(128),
body text,
score int,
key(commentId),
index(appId),
index(versionId)

View File

@@ -7,9 +7,9 @@
* application environment
*/
include("path.php");
require(BASE."include/"."incl.php");
require(BASE."include/"."application.php");
require(BASE."include/"."comments.php");
require(BASE."include/incl.php");
require(BASE."include/application.php");
require(BASE."include/comment.php");
$vendorId = $_REQUEST['vendorId'];