Revision history for ShowCommentsHandler
Revision [18528]
Last edited on 2008-01-28 00:11:43 by SamuelDr [Modified links pointing to docs server]No Differences
Additions:
=====""ShowComments"" Handler=====
Documentation: ShowCommentsHandlerInfo.>>This is the development page for the ""ShowComments"" handler.::c::
""ShowComments"" handler let you to see a page containing only the comments.
Documentation: ShowCommentsHandlerInfo.>>This is the development page for the ""ShowComments"" handler.::c::
""ShowComments"" handler let you to see a page containing only the comments.
Deletions:
Documentation: ShowCommentsHandlerInfo.>>This is the development page for the ShowComments handler.::c::
ShowComments handler let you to see a page containing only the comments.
Additions:
=====ShowComments Handler=====
>>==See also:==
Documentation: ShowCommentsHandlerInfo.>>This is the development page for the ShowComments handler.::c::
ShowComments handler let you to see a page containing only the comments.
It is useful if, as example, a page is really long and is long to load, too many content or too slow connection. If you want to see the comments, you don't want to wait the page to load, especially when there are many comments page (paged comments).
I'm sure of this : **This handler can be improved**.
Now, the code :
%%(php)
<?php
// set default number of comments per page
$d = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
// set default visualization to "paged"
$showall = ($_REQUEST["showall"])? $_REQUEST["showall"] : "0";
// get total number of comments for current page
$n = count($this->LoadComments($this->tag));
// calculate starting item of last page
$lastcomments = ceil($n/$d)*$d;
$start = ($n > $d)? ($lastcomments-$d) : "0";
// set starting item and limit
$s = (isset($_REQUEST["s"]))? $_REQUEST["s"] : $start;
$l = (isset($_REQUEST["l"]))? $_REQUEST["l"] : $d;
// set no limits for showall visualization
if ($showall == 1) {
$s = "0";
$l = "999";
}
// Build pager links:
// FLAVOUR B) - pagelist
if ($showall == 0 && $n > $l) {
$i = 0;
while ($i < $n) {
if ($i == $s) {
$pager .= ($i+1)."-".($i+$l)." | \n";
} else {
$pager .= "<a href=\"".$this->Href("showcomments","","l=".$l."&s=".($i))."\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
}
// create switcher link
switch($showall) {
case "0":
$switcher = ($n > $l)? " <a href=\"".$this->Href("showcomments","","showall=1")."\">all</a> " : "";
break;
case "1":
$switcher = ($n > $d)? " <a href=\"".$this->Href("showcomments","","showall=0")."\">show paged</a> " : "";
}
// load comments for this page with limits
$comments = $this->LoadCommentPage($this->tag, $s, $l);
// store comments display in session
$tag = $this->GetPageTag();
if (!isset($_SESSION["show_comments"][$tag]))
$_SESSION["show_comments"][$tag] = ($this->UserWantsComments() ? "1" : "0");
if (isset($_REQUEST["show_comments"])){
switch($_REQUEST["show_comments"])
{
case "0":
$_SESSION["show_comments"][$tag] = 0;
break;
case "1":
$_SESSION["show_comments"][$tag] = 1;
break;
}
}
// display comments!
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>
</div>
<?php
// display comments themselves
if ($comments)
{
$current_user = $this->GetUserName();
foreach ($comments as $comment)
{
print("<div class=\"comment\">\n");
print("<span id=\"comment_".$comment["id"]."\"></span>".$comment["comment"]."\n");
print("\t<div class=\"commentinfo\">\n-- ".$this->Format($comment["user"])." (".$comment["time"].")\n");
$current_user = $this->GetUserName();
if ($this->UserIsOwner() || $current_user == $comment["user"] || ($this->config['anony_delete_own_comments'] && $current_user == $comment["user"]) )
{
?>
<?php echo $this->FormOpen("delcomment"); ?>
<input type="hidden" name="comment_id" value="<?php echo $comment["id"] ?>" />
<input type="submit" value="Delete Comment" accesskey="d" />
<?php echo $this->FormClose(); ?>
<?php
}
print("\n\t</div>\n");
print("</div>\n");
}
// Show bottom pager link
if ($showall == 0 && $n > $l) {
print "<div class=\"commentsheader\">".$pager.$switcher."</div>\n";
}
}
// display comment form
print("<div class=\"commentform\">\n");
if ($this->HasAccess("comment"))
{?>
<?php echo $this->FormOpen("addcomment"); ?>
<label for="commentbox">Add a comment to this page:<br />
<textarea id="commentbox" name="body" rows="6" cols="78"></textarea><br />
<input type="submit" value="Add Comment" accesskey="s" />
</label>
<?php echo $this->FormClose(); ?>
<?php
}
print("</div>\n");
?>
%%
And finally, to make it redirect back on the handler's page, when posting a new comment :
modify pages/addcomment.php
FIND :
%%(php)
// redirect to page
$this->redirect($this->Href(), $redirectmessage);
%%
Replace with :
%%(php)
if ($_POST['from'] == 'showcomments') {
$href = $this->Href().'/showcomments';
}
else {
$href = $this->Href();
}
// redirect to page
$this->redirect($href, $redirectmessage);
%%
If there is any issue or bug, comment and correct it.
As usual.
----
>>==See also:==
Documentation: ShowCommentsHandlerInfo.>>This is the development page for the ShowComments handler.::c::
ShowComments handler let you to see a page containing only the comments.
It is useful if, as example, a page is really long and is long to load, too many content or too slow connection. If you want to see the comments, you don't want to wait the page to load, especially when there are many comments page (paged comments).
I'm sure of this : **This handler can be improved**.
Now, the code :
%%(php)
<?php
// set default number of comments per page
$d = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
// set default visualization to "paged"
$showall = ($_REQUEST["showall"])? $_REQUEST["showall"] : "0";
// get total number of comments for current page
$n = count($this->LoadComments($this->tag));
// calculate starting item of last page
$lastcomments = ceil($n/$d)*$d;
$start = ($n > $d)? ($lastcomments-$d) : "0";
// set starting item and limit
$s = (isset($_REQUEST["s"]))? $_REQUEST["s"] : $start;
$l = (isset($_REQUEST["l"]))? $_REQUEST["l"] : $d;
// set no limits for showall visualization
if ($showall == 1) {
$s = "0";
$l = "999";
}
// Build pager links:
// FLAVOUR B) - pagelist
if ($showall == 0 && $n > $l) {
$i = 0;
while ($i < $n) {
if ($i == $s) {
$pager .= ($i+1)."-".($i+$l)." | \n";
} else {
$pager .= "<a href=\"".$this->Href("showcomments","","l=".$l."&s=".($i))."\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
}
// create switcher link
switch($showall) {
case "0":
$switcher = ($n > $l)? " <a href=\"".$this->Href("showcomments","","showall=1")."\">all</a> " : "";
break;
case "1":
$switcher = ($n > $d)? " <a href=\"".$this->Href("showcomments","","showall=0")."\">show paged</a> " : "";
}
// load comments for this page with limits
$comments = $this->LoadCommentPage($this->tag, $s, $l);
// store comments display in session
$tag = $this->GetPageTag();
if (!isset($_SESSION["show_comments"][$tag]))
$_SESSION["show_comments"][$tag] = ($this->UserWantsComments() ? "1" : "0");
if (isset($_REQUEST["show_comments"])){
switch($_REQUEST["show_comments"])
{
case "0":
$_SESSION["show_comments"][$tag] = 0;
break;
case "1":
$_SESSION["show_comments"][$tag] = 1;
break;
}
}
// display comments!
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>
</div>
<?php
// display comments themselves
if ($comments)
{
$current_user = $this->GetUserName();
foreach ($comments as $comment)
{
print("<div class=\"comment\">\n");
print("<span id=\"comment_".$comment["id"]."\"></span>".$comment["comment"]."\n");
print("\t<div class=\"commentinfo\">\n-- ".$this->Format($comment["user"])." (".$comment["time"].")\n");
$current_user = $this->GetUserName();
if ($this->UserIsOwner() || $current_user == $comment["user"] || ($this->config['anony_delete_own_comments'] && $current_user == $comment["user"]) )
{
?>
<?php echo $this->FormOpen("delcomment"); ?>
<input type="hidden" name="comment_id" value="<?php echo $comment["id"] ?>" />
<input type="submit" value="Delete Comment" accesskey="d" />
<?php echo $this->FormClose(); ?>
<?php
}
print("\n\t</div>\n");
print("</div>\n");
}
// Show bottom pager link
if ($showall == 0 && $n > $l) {
print "<div class=\"commentsheader\">".$pager.$switcher."</div>\n";
}
}
// display comment form
print("<div class=\"commentform\">\n");
if ($this->HasAccess("comment"))
{?>
<?php echo $this->FormOpen("addcomment"); ?>
<label for="commentbox">Add a comment to this page:<br />
<textarea id="commentbox" name="body" rows="6" cols="78"></textarea><br />
<input type="submit" value="Add Comment" accesskey="s" />
</label>
<?php echo $this->FormClose(); ?>
<?php
}
print("</div>\n");
?>
%%
And finally, to make it redirect back on the handler's page, when posting a new comment :
modify pages/addcomment.php
FIND :
%%(php)
// redirect to page
$this->redirect($this->Href(), $redirectmessage);
%%
Replace with :
%%(php)
if ($_POST['from'] == 'showcomments') {
$href = $this->Href().'/showcomments';
}
else {
$href = $this->Href();
}
// redirect to page
$this->redirect($href, $redirectmessage);
%%
If there is any issue or bug, comment and correct it.
As usual.
----
Deletions:
>>==See also:==
Documentation: xxxxxHandlerInfo.>>This is the development page for the xxxxx handler.::c::
//This page is a **template**. It belongs to CategoryTemplate (which contains more handy templates). To create a handler development page, [[http://wikka.jsnx.com/HandlerTemplate/clone clone this page]] to a page called **xxxxxHandler** (where xxxxx is the (capitalized) name of the handler), replace all occurrences of 'xxxxx' with the name of the handler and replace this paragraph with the actual content.//
----