From 03c0c145c55b2e73c1c81239d517ba4835579ec9 Mon Sep 17 00:00:00 2001 From: Jonathan Ernst Date: Wed, 2 Feb 2005 03:01:29 +0000 Subject: [PATCH] - 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 --- addcomment.php | 56 +---- admin/adminCommentView.php | 4 +- appview.php | 118 +++++----- bugs.php | 2 +- commentview.php | 4 +- deletecomment.php | 74 +------ include/comment.php | 436 +++++++++++++++++++++++++++++++++++++ include/comments.php | 263 ---------------------- tables/appdb_tables.sql | 4 +- vendorview.php | 6 +- 10 files changed, 510 insertions(+), 457 deletions(-) create mode 100644 include/comment.php delete mode 100644 include/comments.php diff --git a/addcomment.php b/addcomment.php index 30bf5a0..7c78f17 100644 --- a/addcomment.php +++ b/addcomment.php @@ -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 ""; } -?> -

 

- - diff --git a/admin/adminCommentView.php b/admin/adminCommentView.php index 776ab7a..e43c092 100644 --- a/admin/adminCommentView.php +++ b/admin/adminCommentView.php @@ -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"); diff --git a/appview.php b/appview.php index 218c286..5f38237 100644 --- a/appview.php +++ b/appview.php @@ -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 "\n"; - echo " ".$ver->versionName."\n"; + echo " ".$ver->versionName."\n"; echo " $desc  \n"; echo " $ver->maintainer_rating\n"; echo " $ver->maintainer_release\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 ""; echo "\n"; echo " \n"; echo " \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 " \n"; echo "
\n"; @@ -237,7 +228,7 @@ if($appId && !$versionId) echo "
URL".$appLinkURL."
Links\n"; @@ -249,7 +240,7 @@ if($appId && !$versionId) } // image - $img = get_screenshot_img($appId); + $img = get_screenshot_img($_REQUEST['appId']); echo "
$img
\n"; /* close of name/vendor/bugs/url table */ @@ -260,7 +251,7 @@ if($appId && !$versionId) // Display all supermaintainers maintainers of this application echo " \n"; echo " \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 ' '; } else /* nope */ @@ -287,14 +278,13 @@ if($appId && !$versionId) echo ' '; } - echo " "; - echo " "; - echo " "; /* set superMaintainer to 1 because we are at the appFamily level */ + echo " "; + echo " "; /* set superMaintainer to 1 because we are at the appFamily level */ echo " "; - if($_SESSION['current']->isSuperMaintainer($appId) || $_SESSION['current']->hasPriv("admin")) + if($_SESSION['current']->isSuperMaintainer($_REQUEST['appId']) || $_SESSION['current']->hasPriv("admin")) { - echo ' '; + echo ' '; echo ''; echo ''; echo ''; @@ -303,7 +293,7 @@ if($appId && !$versionId) { $url = BASE."admin/deleteAny.php?what=appFamily&appId=".$_REQUEST['appId']."&confirmed=yes"; echo " "; - echo ' '; + echo ' '; } } else { @@ -320,29 +310,33 @@ if($appId && !$versionId) // description echo "
Super maintainers:
\n"; - echo "
Description
\n"; - echo add_br(stripslashes($data->description)); - + echo "
Description\n"; + echo $data->description; echo "
\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) ? "".substr(stripslashes($ver->webPage),0,30)."": " "; // start version display echo html_frame_start("","98%","",0); - + echo ""; echo '
',"\n"; echo '',"\n"; echo "\n"; echo "\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 " \n"; // image - $img = get_screenshot_img($appId, $versionId); + $img = get_screenshot_img($appId, $_REQUEST['versionId']); echo "\n"; // display all maintainers of this application echo "
Name".stripslashes($data->appName)."
Version".stripslashes($ver->versionName)."
Links\n"; @@ -393,13 +387,13 @@ else if($appId && $versionId) echo "
Maintainers Version".stripslashes($ver->maintainer_release)."
$img
Maintainers of this application:\n"; echo ""; - $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 ''; echo ""; @@ -438,8 +432,8 @@ else if($appId && $versionId) } } - echo ""; - echo ""; + echo ""; + echo ""; echo ""; } else { @@ -450,26 +444,26 @@ else if($appId && $versionId) echo ""; - 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 "
"; - echo '
'; + echo ''; echo ''; echo '
'; $url = BASE."admin/deleteAny.php?what=appVersion&appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."&confirmed=yes"; echo "
"; echo ''; echo '
'; - echo '
'; + echo ''; echo ''; echo '
'; echo ''; - echo '
'; + echo ''; echo ''; echo ''; echo '
'; echo ''; - echo '
'; + echo ''; echo ''; echo ''; echo '
'; @@ -478,9 +472,9 @@ else if($appId && $versionId) echo "
\n"; - //Desc Image + // description echo ""; /* 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; } -?> -

 

- - diff --git a/bugs.php b/bugs.php index a4a1939..7a5afbb 100644 --- a/bugs.php +++ b/bugs.php @@ -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"); diff --git a/commentview.php b/commentview.php index 5b1cf47..2ccd186 100644 --- a/commentview.php +++ b/commentview.php @@ -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"); diff --git a/deletecomment.php b/deletecomment.php index 94c1441..5d04f50 100644 --- a/deletecomment.php +++ b/deletecomment.php @@ -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 = "Please state why you are deleting the following comment"; echo "\n"; echo html_frame_start($mesTitle,500,"",0); echo "
"; - echo html_frame_start($ob->subject,500); - echo htmlify_urls($ob->body), "

\n"; + echo html_frame_start($oComment->sSubject,500); + echo htmlify_urls($oComment->sBody), "

\n"; echo html_frame_end(); echo '
Description
\n"; - echo add_br(stripslashes($ver->description)); + echo $ver->description; echo "
',"\n"; echo "\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'])); } ?> diff --git a/include/comment.php b/include/comment.php new file mode 100644 index 0000000..2a9ca34 --- /dev/null +++ b/include/comment.php @@ -0,0 +1,436 @@ +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 = '' . $oUser->sRealname . ''; + } + if (!$iUserId || !$oUser->isLoggedIn()) + { + $sMailto = 'Anonymous'; + } + return $sMailto; +} + +/** + * display a single comment (in $ob) + */ +function view_app_comment($ob) +{ + + echo html_frame_start('','98%'); + echo '
',"\n"; + + $ob->subject = stripslashes($ob->subject); + $ob->body = stripslashes($ob->body); + + // message header + echo "\n"; + + // delete message button, for admins + if ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($ob->appId,$ob->versionId) )) + { + echo ""; + echo "","\n"; + echo ""; + } + + echo "
\n"; + echo " ".$ob->subject."
\n"; + echo " by ".forum_lookup_user($ob->userId)." on ".$ob->time."
\n"; + echo "
\n"; + + // body + echo htmlify_urls($ob->body), "

\n"; + + // only add RE: once + if(eregi("RE:", $ob->subject)) + $subject = $ob->subject; + else + $subject = "RE: ".$ob->subject; + + // reply post buttons + echo " [post new] \n"; + echo " [reply to this] \n"; + + echo "
\n"; + echo "commentId\" />"; + echo "appId\" />"; + echo "versionId\" />
\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 "
\n"; + do_display_comments_nested($result); + echo "
\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 "
    \n"; + + while ($ob = mysql_fetch_object($handle)) + { + if ($is_main) + { + view_app_comment($ob); + } else + { + echo '
  • '. + $ob->subject.' by '.forum_lookup_user($ob->userId).' on '.$ob->time.'
  • '."\n"; + } + + $result = grab_comments($ob->versionId, $ob->commentId); + if ($result && mysql_num_rows($result)) + { + echo "
    \n"; + do_display_comments_threaded($result, 0); + echo "
    \n"; + } + } + + if (!$is_main) + echo "
\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 '',"\n"; + + echo '',"\n"; + echo '
',"\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 '',"\n"; + } + + // blank space + echo '',"\n"; + + // post new message button + echo '',"\n"; + + //end comment format table + echo '
',"\n"; + echo "Application Comments $messageCount total comments "; + echo 'Mode ',"\n"; + echo '
 
',"\n"; + echo '
',"\n"; + echo html_frame_end(); + + if( $messageCount > 0 ) + { + echo '

The following comments are owned by whoever posted them. WineHQ is not responsible for what they say.

'."\n"; + } + + //start comments + echo '
',"\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 '
',"\n"; +} +?> diff --git a/include/comments.php b/include/comments.php deleted file mode 100644 index f46c7f1..0000000 --- a/include/comments.php +++ /dev/null @@ -1,263 +0,0 @@ - 0) - { - $oUser = new User($iUserId); - $sMailto = '' . $oUser->sRealname . ''; - } - else - { - $sMailto = 'Anonymous'; - } - return $sMailto; -} - -/** - * display a single comment (in $ob) - */ -function view_app_comment($ob) -{ - - echo html_frame_start('','98%'); - echo '',"\n"; - - $ob->subject = stripslashes($ob->subject); - $ob->body = stripslashes($ob->body); - - // message header - echo "\n"; - - // delete message button, for admins - if ($_SESSION['current']->isLoggedIn() && ($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($ob->appId,$ob->versionId) )) - { - echo ""; - echo "","\n"; - echo ""; - } - - echo "
\n"; - echo " ".$ob->subject."
\n"; - echo " by ".forum_lookup_user($ob->userId)." on ".$ob->time."
\n"; - echo "
\n"; - - // body - echo htmlify_urls($ob->body), "

\n"; - - // only add RE: once - if(eregi("RE:", $ob->subject)) - $subject = $ob->subject; - else - $subject = "RE: ".$ob->subject; - - // reply post buttons - echo " [post new] \n"; - echo " [reply to this] \n"; - - echo "
\n"; - echo "commentId\" />"; - echo "appId\" />"; - echo "versionId\" />
\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 "
\n"; - do_display_comments_nested($result); - echo "
\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 "
    \n"; - - while ($ob = mysql_fetch_object($handle)) - { - if ($is_main) - { - view_app_comment($ob); - } else - { - echo '
  • '. - $ob->subject.' by '.forum_lookup_user($ob->userId).' on '.$ob->time.'
  • '."\n"; - } - - $result = grab_comments($ob->appId, $ob->versionId, $ob->commentId); - if ($result && mysql_num_rows($result)) - { - echo "
    \n"; - do_display_comments_threaded($result, 0); - echo "
    \n"; - } - } - - if (!$is_main) - echo "
\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 '',"\n"; - - echo '',"\n"; - echo '
',"\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 '',"\n"; - } - - // blank space - echo '',"\n"; - - // post new message button - echo '',"\n"; - - //end comment format table - echo '
',"\n"; - echo "Application Comments $messageCount total comments "; - echo 'Mode ',"\n"; - echo '
 
',"\n"; - echo '
',"\n"; - echo html_frame_end(); - - if( $messageCount > 0 ) - { - echo '

The following comments are owned by whoever posted them. WineHQ is not responsible for what they say.

'."\n"; - } - - //start comments - echo '
',"\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 '
',"\n"; -} - - -?> diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql index c894e3f..b3562de 100644 --- a/tables/appdb_tables.sql +++ b/tables/appdb_tables.sql @@ -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) diff --git a/vendorview.php b/vendorview.php index 123591d..2caf302 100644 --- a/vendorview.php +++ b/vendorview.php @@ -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'];