Revision history for PagedComments


Revision [20002]

Last edited on 2008-06-04 04:21:40 by MasinAlDujaili [working versions]
Additions:
>>Working for 1.1.6.0 to 1.1.6.4 (latest)
Slight changes in the code in the vicinity of this modification, nothing serious.>>{{lastedit show="3"}}
<?php echo $this->FormOpen("addcomment"); ?>
</label>
Deletions:
{{lastedit show="3"}}
<?php echo $this->FormOpen("addcomment"); ?>
</label>


Revision [19202]

Edited on 2008-01-28 00:14:43 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [16978]

Edited on 2007-05-31 23:27:32 by JavaWoman [Reverted]
Additions:
$prev = " <a href=\"" .$this->Href("","","l=".$l."&s=".($s-$l))."#comments\">«</a> ";
// show "next" link if needed
if($n > ($s + $l)) {
$next = " <a href=\"".$this->Href("","","l=".$l."&s=".($s+$l))."#comments\">»</a> ";
// create pager links
$pager = ($prev || $next)? $prev.($s+1)."-".($s+$l).$next : "";
*/
// 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("","","l=".$l."&s=".($i))."#comments\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
// create switcher link
switch($showall) {
case "0":
// FLAVOUR A)
// $switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $l)? " <a href=\"".$this->Href("","","showall=1")."#comments\">all</a> " : "";
break;
case "1":
// FLAVOUR A)
// $switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $d)? " <a href=\"".$this->Href("","","showall=0")."#comments\">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!
if ($_SESSION["show_comments"][$tag])
{
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>[<a href="<?php echo $this->href("", "", "show_comments=0") ?>">Hide comments/form</a>]
</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");
else
{
?>
<div class="commentsheader">
<?php
switch ($n)
{
case 0:
print("<p>There are no comments on this page. ");
$showcomments_text = "Add comment";
break;
case 1:
print("<p>There is one comment on this page. ");
$showcomments_text = "Display comment";
break;
default:
print("<p>There are ".$n." comments on this page. ");
$showcomments_text = "Display comments";
}
?>
[<a href="<?php echo $this->href("", "", "show_comments=1#comments")."\">$showcomments_text"; ?></a>]</p>
</div>
<?php
== 3. Update ##actions/recentlycommented.php##==
Replace the two occurrences of
%%"show_comments=1"%%
with
%%"show_comments=1&showall=1"%%
== 4. Update ##actions/usersettings.php##==
These modifications allow users to store their preferred //number of comments per page// in a session parameter.
Modify the two following code blocks:
==A)==
**original**
$this->SetUser($this->LoadUser($user["name"]));

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
**modified**
$this->SetUser($this->LoadUser($user["name"]));
$_SESSION["limit_comments"] = ($_REQUEST["limit_comments"])? $_REQUEST["limit_comments"] : "10";

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
==B)==
**original**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
**modified**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td align="right">Comments per page:</td>
<?php
$limit_comments = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
?>
<td><input name="limit_comments" value="<?php echo $limit_comments ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
CategoryDevelopmentHandlers
Deletions:
$prev = " <a href=\"" .$this->Href("","","l=".$l."


Revision [16777]

Edited on 2007-05-31 10:47:30 by KopLow [Reverted]
Additions:
$prev = " <a href=\"" .$this->Href("","","l=".$l."
Deletions:
$prev = " <a href=\"" .$this->Href("","","l=".$l."&s=".($s-$l))."#comments\">«</a> ";
// show "next" link if needed
if($n > ($s + $l)) {
$next = " <a href=\"".$this->Href("","","l=".$l."&s=".($s+$l))."#comments\">»</a> ";
// create pager links
$pager = ($prev || $next)? $prev.($s+1)."-".($s+$l).$next : "";
*/
// 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("","","l=".$l."&s=".($i))."#comments\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
// create switcher link
switch($showall) {
case "0":
// FLAVOUR A)
// $switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $l)? " <a href=\"".$this->Href("","","showall=1")."#comments\">all</a> " : "";
break;
case "1":
// FLAVOUR A)
// $switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $d)? " <a href=\"".$this->Href("","","showall=0")."#comments\">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!
if ($_SESSION["show_comments"][$tag])
{
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>[<a href="<?php echo $this->href("", "", "show_comments=0") ?>">Hide comments/form</a>]
</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");
else
{
?>
<div class="commentsheader">
<?php
switch ($n)
{
case 0:
print("<p>There are no comments on this page. ");
$showcomments_text = "Add comment";
break;
case 1:
print("<p>There is one comment on this page. ");
$showcomments_text = "Display comment";
break;
default:
print("<p>There are ".$n." comments on this page. ");
$showcomments_text = "Display comments";
}
?>
[<a href="<?php echo $this->href("", "", "show_comments=1#comments")."\">$showcomments_text"; ?></a>]</p>
</div>
<?php
== 3. Update ##actions/recentlycommented.php##==
Replace the two occurrences of
%%"show_comments=1"%%
with
%%"show_comments=1&showall=1"%%
== 4. Update ##actions/usersettings.php##==
These modifications allow users to store their preferred //number of comments per page// in a session parameter.
Modify the two following code blocks:
==A)==
**original**
$this->SetUser($this->LoadUser($user["name"]));

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
**modified**
$this->SetUser($this->LoadUser($user["name"]));
$_SESSION["limit_comments"] = ($_REQUEST["limit_comments"])? $_REQUEST["limit_comments"] : "10";

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
==B)==
**original**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
**modified**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td align="right">Comments per page:</td>
<?php
$limit_comments = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
?>
<td><input name="limit_comments" value="<?php echo $limit_comments ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
CategoryDevelopmentHandlers


Revision [8705]

Edited on 2005-05-29 14:29:27 by JavaWoman [new category]
Additions:
===== Paged Comments =====
{{lastedit show="3"}}

When the number of comments at the bottom of a page is too large (there is virtually no limit to their number), the comments block becomes user-unfriendly:
~-the page can take too long to load (especially for users with 56k dial-up connections)
~- navigation between comments becomes difficult.

I've written a configurable **comments pager** to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by a **$limit_comments** session parameter, that can be changed in UserSettings.
Paged comments come in two "flavours".

----
==Screenshots:==

**Flavour A) - previous/next links**
http://wikka.jsnx.com/images/pagedcomments.jpg

**Flavour B) - pagelist**
http://wikka.jsnx.com/images/pagedcomments2.jpg

----

Here's the code.

==1. Create function ##""LoadCommentPage()""## in ##wikka.php##==

%%(php)
function LoadCommentPage($tag, $start, $limit) {
return $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."comments WHERE page_tag = '".mysql_real_escape_string($tag)."' ORDER BY time LIMIT ".$start.",".$limit);
}
%%

==2. Modify the comments block in ##handlers/page/show.php##==

%%(php)
if ($this->GetConfigValue("hide_comments") != 1)
{
// 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 A) - next/previous links

// show "previous" link if needed
if($s > 0) {
$prev = " <a href=\"" .$this->Href("","","l=".$l."&s=".($s-$l))."#comments\">«</a> ";
}

// show "next" link if needed
if($n > ($s + $l)) {
$next = " <a href=\"".$this->Href("","","l=".$l."&s=".($s+$l))."#comments\">»</a> ";
}

// create pager links
$pager = ($prev || $next)? $prev.($s+1)."-".($s+$l).$next : "";

*/


// 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("","","l=".$l."&s=".($i))."#comments\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
}


// create switcher link
switch($showall) {

case "0":
// FLAVOUR A)
// $switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $l)? " <a href=\"".$this->Href("","","showall=1")."#comments\">all</a> " : "";
break;

case "1":
// FLAVOUR A)
// $switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $d)? " <a href=\"".$this->Href("","","showall=0")."#comments\">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!
if ($_SESSION["show_comments"][$tag])
{
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>[<a href="<?php echo $this->href("", "", "show_comments=0") ?>">Hide comments/form</a>]
</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");
}
else
{
?>
<div class="commentsheader">
<?php
switch ($n)
{
case 0:
print("<p>There are no comments on this page. ");
$showcomments_text = "Add comment";
break;
case 1:
print("<p>There is one comment on this page. ");
$showcomments_text = "Display comment";
break;
default:
print("<p>There are ".$n." comments on this page. ");
$showcomments_text = "Display comments";
}
?>
[<a href="<?php echo $this->href("", "", "show_comments=1#comments")."\">$showcomments_text"; ?></a>]</p>
</div>
<?php
}
}
%%

== 3. Update ##actions/recentlycommented.php##==

Replace the two occurrences of

%%"show_comments=1"%%

with

%%"show_comments=1&showall=1"%%


== 4. Update ##actions/usersettings.php##==

These modifications allow users to store their preferred //number of comments per page// in a session parameter.
Modify the two following code blocks:

==A)==
**original**
%%(php)
$this->SetUser($this->LoadUser($user["name"]));

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
%%

**modified**
%%(php)
$this->SetUser($this->LoadUser($user["name"]));
$_SESSION["limit_comments"] = ($_REQUEST["limit_comments"])? $_REQUEST["limit_comments"] : "10";

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
%%

==B)==

**original**
%%(php)
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
%%

**modified**
%%(php)
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td align="right">Comments per page:</td>
<?php
$limit_comments = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
?>
<td><input name="limit_comments" value="<?php echo $limit_comments ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
%%

----
CategoryDevelopmentHandlers
Deletions:
===== Paged Comments =====
{{lastedit show="3"}}

When the number of comments at the bottom of a page is too large (there is virtually no limit to their number), the comments block becomes user-unfriendly:
~-the page can take too long to load (especially for users with 56k dial-up connections)
~- navigation between comments becomes difficult.

I've written a configurable **comments pager** to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by a **$limit_comments** session parameter, that can be changed in UserSettings.
Paged comments come in two "flavours".

----
==Screenshots:==

**Flavour A) - previous/next links**
http://wikka.jsnx.com/images/pagedcomments.jpg

**Flavour B) - pagelist**
http://wikka.jsnx.com/images/pagedcomments2.jpg

----

Here's the code.

==1. Create function ##""LoadCommentPage()""## in ##wikka.php##==

%%(php)
function LoadCommentPage($tag, $start, $limit) {
return $this->LoadAll("SELECT * FROM ".$this->config["table_prefix"]."comments WHERE page_tag = '".mysql_real_escape_string($tag)."' ORDER BY time LIMIT ".$start.",".$limit);
}
%%

==2. Modify the comments block in ##handlers/page/show.php##==

%%(php)
if ($this->GetConfigValue("hide_comments") != 1)
{
// 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 A) - next/previous links

// show "previous" link if needed
if($s > 0) {
$prev = " <a href=\"" .$this->Href("","","l=".$l."&s=".($s-$l))."#comments\">«</a> ";
}

// show "next" link if needed
if($n > ($s + $l)) {
$next = " <a href=\"".$this->Href("","","l=".$l."&s=".($s+$l))."#comments\">»</a> ";
}

// create pager links
$pager = ($prev || $next)? $prev.($s+1)."-".($s+$l).$next : "";

*/


// 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("","","l=".$l."&s=".($i))."#comments\">".($i+1)."-".($i + $l)."</a> | \n";
}
$i = $i + $l;
}
}


// create switcher link
switch($showall) {

case "0":
// FLAVOUR A)
// $switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $l)? " <a href=\"".$this->Href("","","showall=1")."#comments\">all</a> " : "";
break;

case "1":
// FLAVOUR A)
// $switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $d)? " <a href=\"".$this->Href("","","showall=0")."#comments\">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!
if ($_SESSION["show_comments"][$tag])
{
// display comments header
?>
<div class="commentsheader">
<span id="comments"> </span>Comments <?php echo "(".$n.") ".$pager.$switcher; ?>[<a href="<?php echo $this->href("", "", "show_comments=0") ?>">Hide comments/form</a>]
</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");
}
else
{
?>
<div class="commentsheader">
<?php
switch ($n)
{
case 0:
print("<p>There are no comments on this page. ");
$showcomments_text = "Add comment";
break;
case 1:
print("<p>There is one comment on this page. ");
$showcomments_text = "Display comment";
break;
default:
print("<p>There are ".$n." comments on this page. ");
$showcomments_text = "Display comments";
}
?>
[<a href="<?php echo $this->href("", "", "show_comments=1#comments")."\">$showcomments_text"; ?></a>]</p>
</div>
<?php
}
}
%%

== 3. Update ##actions/recentlycommented.php##==

Replace the two occurrences of

%%"show_comments=1"%%

with

%%"show_comments=1&showall=1"%%


== 4. Update ##actions/usersettings.php##==

These modifications allow users to store their preferred //number of comments per page// in a session parameter.
Modify the two following code blocks:

==A)==
**original**
%%(php)
$this->SetUser($this->LoadUser($user["name"]));

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
%%

**modified**
%%(php)
$this->SetUser($this->LoadUser($user["name"]));
$_SESSION["limit_comments"] = ($_REQUEST["limit_comments"])? $_REQUEST["limit_comments"] : "10";

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
%%

==B)==

**original**
%%(php)
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
%%

**modified**
%%(php)
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td align="right">Comments per page:</td>
<?php
$limit_comments = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
?>
<td><input name="limit_comments" value="<?php echo $limit_comments ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
%%

----
CategoryUserContributions


Revision [4733]

Edited on 2005-01-17 14:31:58 by NilsLindenberg [cat. changed]
Additions:
CategoryUserContributions
Deletions:
CategoryDevelopment


Revision [3110]

Edited on 2004-12-12 10:18:06 by DarTar [Number of comments per page can now be set from UserSettings]
Additions:
{{lastedit show="3"}}
I've written a configurable **comments pager** to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by a **$limit_comments** session parameter, that can be changed in UserSettings.
$d = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
== 4. Update ##actions/usersettings.php##==
These modifications allow users to store their preferred //number of comments per page// in a session parameter.
Modify the two following code blocks:
==A)==
**original**
$this->SetUser($this->LoadUser($user["name"]));

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
**modified**
$this->SetUser($this->LoadUser($user["name"]));
$_SESSION["limit_comments"] = ($_REQUEST["limit_comments"])? $_REQUEST["limit_comments"] : "10";

// forward
$this->SetMessage("User settings stored!");
$this->Redirect($this->href());
==B)==
**original**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
**modified**
<tr>
<td align="right">Page revisions list limit:</td>
<td><input name="revisioncount" value="<?php echo htmlspecialchars($user["revisioncount"]) ?>" size="40" /></td>
</tr>
<tr>
<td align="right">Comments per page:</td>
<?php
$limit_comments = ($_SESSION["limit_comments"])? $_SESSION["limit_comments"] : "10";
?>
<td><input name="limit_comments" value="<?php echo $limit_comments ?>" size="40" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Update Settings" /> <input type="button" value="Logout" onClick="document.location='<?php echo $this->href("", "", "action=logout"); ?>'" /></td>
</tr>
Deletions:
{{lastedit}}
I've written a configurable **comments pager** to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by the **$d** variable.
In the future, this value might be selected in the user settings and stored in a session.
$d = "10";


Revision [2633]

Edited on 2004-11-29 15:54:51 by DarTar [Comment pager - let me know if you want to test it on this server]
Additions:
I've written a configurable **comments pager** to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by the **$d** variable.
Deletions:
I've written a pager for comments to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by the **$d** variable.


Revision [2632]

Edited on 2004-11-29 15:53:26 by DarTar [Comment pager - let me know if you want to test it on this server]
Additions:
In the future, this value might be selected in the user settings and stored in a session.
Deletions:
In the future, this value might be selected in the user settings.


Revision [2631]

Edited on 2004-11-29 15:48:21 by DarTar [Comment pager - let me know if you want to test it on this server]
Additions:
In the future, this value might be selected in the user settings.
Paged comments come in two "flavours".
==Screenshots:==
**Flavour A) - previous/next links**
**Flavour B) - pagelist**
http://wikka.jsnx.com/images/pagedcomments2.jpg
/*
// FLAVOUR A) - next/previous 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("","","l=".$l."&s=".($i))."#comments\">".($i+1)."-".($i + $l)."</a> | \n";
$i = $i + $l;
// FLAVOUR A)
// $switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $l)? " <a href=\"".$this->Href("","","showall=1")."#comments\">all</a> " : "";
// FLAVOUR A)
// $switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
// FLAVOUR B)
$switcher = ($n > $d)? " <a href=\"".$this->Href("","","showall=0")."#comments\">show paged</a> " : "";
Deletions:
In the future, this value might be selected in the user settings.
**Screenshot:**
$switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
$switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";


Revision [2628]

Edited on 2004-11-29 14:01:47 by DarTar [Code for paged comments - let me know if you want to test it on this server]

No Differences

Revision [2626]

Edited on 2004-11-29 13:49:26 by DarTar [Code for paged comments - let me know if you want to test it on this server]
Additions:
**Screenshot:**
http://wikka.jsnx.com/images/pagedcomments.jpg
Deletions:
**Screenshot**
{{image alt="paged comments" title="Paged comments" url ="images/pagedcomments.jpg" link="PagedComments"}}


Revision [2625]

Edited on 2004-11-29 13:48:05 by DarTar [Code for paged comments - let me know if you want to test it on this server]
Additions:
{{image alt="paged comments" title="Paged comments" url ="images/pagedcomments.jpg" link="PagedComments"}}
Deletions:
{{image class="left" alt="paged comments" title="paged comments" url ="images/pagedcomments.jpg"}}


Revision [2624]

Edited on 2004-11-29 13:43:46 by DarTar [Code for paged comments - let me know if you want to test it on this server]
Additions:
**Screenshot**
{{image class="left" alt="paged comments" title="paged comments" url ="images/pagedcomments.jpg"}}


Revision [2618]

Edited on 2004-11-29 13:13:37 by DarTar [Adding code for paged comments - let me know if you want to test it on this server]
Additions:
I've written a pager for comments to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by the **$d** variable.
Deletions:
I've written a configurable pager for comments to address this issue. The pager allows to switch between a "paged" and a "showall" view. The default number of comments per page is set by the **$d** variable.


Revision [2615]

Edited on 2004-11-29 12:59:23 by DarTar [Adding code for paged comments]
Additions:
switch($showall) {
$switcher = ($n > $l)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : "";
break;
case "1":
$switcher = ($n > $d)? " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] " : "";
Deletions:
if ($n > $l) {
$switcher = ($showall == 0)? " [<a href=\"".$this->Href("","","showall=1")."#comments\">Show all</a>] " : " [<a href=\"".$this->Href("","","showall=0")."#comments\">Show paged</a>] ";


Revision [2614]

Edited on 2004-11-29 12:30:46 by DarTar [Adding code for paged comments]
Additions:
$s = (isset($_REQUEST["s"]))? $_REQUEST["s"] : $start;
$l = (isset($_REQUEST["l"]))? $_REQUEST["l"] : $d;
Deletions:
$s = (isset($_REQUEST["s"]))? $_REQUEST["s"] : $start; $l = (isset($_REQUEST["l"]))? $_REQUEST["l"] : $d;


Revision [2612]

The oldest known version of this page was created on 2004-11-29 12:30:11 by DarTar [Adding code for paged comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki