Support for showing a threaded comment reply inline using ajax. Falls back to default if javascript is disabled.
This commit is contained in:
9
comment_body.php
Normal file
9
comment_body.php
Normal 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']);
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -223,6 +223,20 @@ class Comment {
|
|||||||
$this->sDateCreated = date("l F jS Y, H:i");
|
$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)
|
* display a single comment (in $oRow)
|
||||||
*/
|
*/
|
||||||
@@ -276,6 +290,27 @@ class Comment {
|
|||||||
echo html_frame_end();
|
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
|
* grab comments for appId / versionId
|
||||||
* if parentId is not -1 only comments for that thread are returned
|
* if parentId is not -1 only comments for that thread are returned
|
||||||
@@ -343,6 +378,25 @@ class Comment {
|
|||||||
Comment::do_display_comments_nested($hResult);
|
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
|
* display threaded comments
|
||||||
* handle is a db result set
|
* handle is a db result set
|
||||||
@@ -351,7 +405,7 @@ class Comment {
|
|||||||
{
|
{
|
||||||
if (!$is_main)
|
if (!$is_main)
|
||||||
echo "<ul>\n";
|
echo "<ul>\n";
|
||||||
|
|
||||||
while ($oRow = query_fetch_object($hResult))
|
while ($oRow = query_fetch_object($hResult))
|
||||||
{
|
{
|
||||||
if ($is_main)
|
if ($is_main)
|
||||||
@@ -359,15 +413,13 @@ class Comment {
|
|||||||
Comment::view_app_comment($oRow);
|
Comment::view_app_comment($oRow);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
echo "<li><a href=\"commentview.php?iAppId={$oRow->appId}&iVersionId=".
|
$link = Comment::comment_link($oRow);
|
||||||
"{$oRow->versionId}&iThreadId={$oRow->parentId}\" ".
|
echo "$link";
|
||||||
"name=\"Comment-{$oRow->commentId}\"> ".
|
|
||||||
$oRow->subject.' </a> by '.forum_lookup_user($oRow->userId).' on '.$oRow->time.' </li>'."\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hResult2 = Comment::grab_comments($oRow->versionId, $oRow->commentId);
|
$hResult2 = Comment::grab_comments($oRow->versionId, $oRow->commentId);
|
||||||
if ($hResult2 && query_num_rows($hResult2))
|
if ($hResult2 && query_num_rows($hResult2))
|
||||||
{
|
{
|
||||||
echo "<blockquote>\n";
|
echo "<blockquote>\n";
|
||||||
Comment::do_display_comments_threaded($hResult2, 0);
|
Comment::do_display_comments_threaded($hResult2, 0);
|
||||||
echo "</blockquote>\n";
|
echo "</blockquote>\n";
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
<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; ?>apidb.css" type="text/css">
|
||||||
<link rel="stylesheet" href="<?php echo BASE; ?>application.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>
|
<script src="<?php echo BASE; ?>scripts.js" type="text/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
4221
prototype-1.6.0.2.js
vendored
Normal file
4221
prototype-1.6.0.2.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
27
scripts.js
27
scripts.js
@@ -40,3 +40,30 @@ function DoNav(sUrl)
|
|||||||
{
|
{
|
||||||
document.location.href = 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user