Support for showing a threaded comment reply inline using ajax. Falls back to default if javascript is disabled.

This commit is contained in:
Adam Lewis
2008-05-29 08:23:25 -04:00
committed by Chris Morgan
parent 2503d2ba21
commit be6a19f95e
5 changed files with 4316 additions and 6 deletions

9
comment_body.php Normal file
View File

@@ -0,0 +1,9 @@
<?php
require("path.php");
require(BASE."include/incl.php");
require_once(BASE."include/comment.php");
Comment::view_comment_body($aClean['iCommentId']);
?>

View File

@@ -223,6 +223,20 @@ class Comment {
$this->sDateCreated = date("l F jS Y, H:i");
}
/**
* Displays the body of one comment.
*/
function view_comment_body($iCommentId)
{
$hResult = Comment::grab_comment($iCommentId);
if ($hResult)
{
$oRow = query_fetch_object($hResult);
Comment::view_app_comment($oRow);
}
}
/**
* display a single comment (in $oRow)
*/
@@ -276,6 +290,27 @@ class Comment {
echo html_frame_end();
}
/**
* grab single comment for commentId
*/
function grab_comment($iCommentId)
{
$iCommentId = query_escape_string($iCommentId);
if($iCommentId)
{
$sQuery = "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.commentId = '$iCommentId'";
$hResult = query_appdb($sQuery);
return $hResult;
}
return null;
}
/**
* grab comments for appId / versionId
* if parentId is not -1 only comments for that thread are returned
@@ -343,6 +378,25 @@ class Comment {
Comment::do_display_comments_nested($hResult);
}
/**
* Generates the link to show the comment.
*/
function comment_link($oRow)
{
$sLink = "commentview.php?iAppId={$oRow->appId}&iVersionId=".
"{$oRow->versionId}&iThreadId={$oRow->parentId}";
$sOnClick = "showComment('{$oRow->commentId}');";
/**
* The return false line in the onClick is used to handle javascript
* being disabled so we can fail gracefully to the old style.
*/
return "<li><a href=\"$sLink\" onclick=\"$sOnClick return false;\">$oRow->subject</a>".
' by '.forum_lookup_user($oRow->userId)." on
{$oRow->time}<div id=\"{$oRow->commentId}\"></div></li>\n";
}
/**
* display threaded comments
* handle is a db result set
@@ -359,10 +413,8 @@ class Comment {
Comment::view_app_comment($oRow);
} else
{
echo "<li><a href=\"commentview.php?iAppId={$oRow->appId}&amp;iVersionId=".
"{$oRow->versionId}&amp;iThreadId={$oRow->parentId}\" ".
"name=\"Comment-{$oRow->commentId}\"> ".
$oRow->subject.' </a> by '.forum_lookup_user($oRow->userId).' on '.$oRow->time.' </li>'."\n";
$link = Comment::comment_link($oRow);
echo "$link";
}
$hResult2 = Comment::grab_comments($oRow->versionId, $oRow->commentId);

View File

@@ -12,6 +12,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="<?php echo BASE; ?>apidb.css" type="text/css">
<link rel="stylesheet" href="<?php echo BASE; ?>application.css" type="text/css">
<script src="<?php echo BASE; ?>prototype-1.6.0.2.js" type="text/javascript"></script>
<script src="<?php echo BASE; ?>scripts.js" type="text/javascript"></script>
</head>

4221
prototype-1.6.0.2.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -40,3 +40,30 @@ function DoNav(sUrl)
{
document.location.href = sUrl;
}
/**
* commentId is the uniquely identifying comment id from the database.
* It is also used as the div id for the comment body.
*/
function showComment(commentid)
{
elem = $(commentid);
if(elem.visible() && !elem.empty())
{
elem.hide();
}
else
{
// Cache the contents of the comment body so we don't need to hit db again.
if(elem.empty())
{
new Ajax.Updater(commentid, 'comment_body.php', {
method: 'get',
parameters: {
iCommentId: commentid
}
});
}
elem.show();
}
}