Revision [1257]
This is an old revision of UserCommentsAction made by DarTar on 2004-09-16 09:27:41.
UserComments Action
This action displays a list of pages commented by the current user or by any other registered user specified via a user GET variable
(This action is meant as a module for the UserAdmin tool).
Save the following code as actions/usercomments.php.
-- DarTar
actions/usercomments.php
<?php
// Shows pages commented by $_GET["user"] or, if this is not provided, by the current user.
// Adapted from actions/mychanges.php written by Carlo Zottmann
$page = $this->GetPageTag();
$user = (($_GET["user"])? $_GET["user"] : $this->GetUserName());
if ($user)
{
$user_comments_count = 0;
if ($_GET["alpha"] == 1)
{
echo $this->Format("== Pages commented by [[".$user."]] == --- --- ");
print("<strong>This is a list of pages commented by ".$this->Link($user).", along with the time of the comment (<a href=\"".$page."?user=".$user."&date=1&action=comments\">order by date</a>).</strong><br /><br />\n");
if ($comments = $this->LoadAll("SELECT id, page_tag, time FROM ".$this->config["table_prefix"]."comments WHERE user =
'".mysql_real_escape_string($user)."' ORDER BY page_tag ASC, time DESC"))
{
foreach ($comments as $comment)
{
if ($last_tag != $comment["page_tag"]) {
$last_tag = $comment["page_tag"];
$firstChar = strtoupper($comment["page_tag"][0]);
if (!preg_match("/[A-Z,a-z]/", $firstChar)) {
$firstChar = "#";
}
if ($firstChar != $curChar) {
if ($curChar) print("<br />\n");
print("<strong>$firstChar</strong><br />\n");
$curChar = $firstChar;
}
// print entry
print(" (".$comment["time"].") <a href=\"".$this->href("", $comment["page_tag"], "show_comments=1")."#".$comment["id"]."\">".$comment["page_tag"]."</a><br />\n");
$user_comments_count++;
}
}
if ($user_comments_count == 0)
{
print("<em>User has not commented any pages yet.</em>");
}
}
else
{
print("<em>No comments found.</em>");
}
}
else
{
echo $this->Format("== Pages commented by [[".$user."]] == --- --- ");
print("<strong>This is a list of pages commented by ".$this->Link($user).", ordered by the time of the comment (<a href=\"".$page."?user=".$user."&alpha=1&action=comments\">order alphabetically</a>).</strong><br /><br />\n");
if ($comments = $this->LoadAll("SELECT id, page_tag, time FROM ".$this->config["table_prefix"]."comments WHERE user =
'".mysql_real_escape_string($user)."' ORDER BY time ASC, page_tag ASC"))
{
foreach ($comments as $comment)
{
$commented_pages[$comment["page_tag"]] = $comment["time"];
}
$commented_pages = array_reverse($commented_pages);
foreach ($commented_pages as $comment["page_tag"] => $comment["time"])
{
// day header
list($day, $time) = explode(" ", $comment["time"]);
if ($day != $curday)
{
if ($curday) print("<br />\n");
print("<strong>$day:</strong><br />\n");
$curday = $day;
}
// print entry
print(" (".$time.") <a href=\"".$this->href("", $comment["page_tag"], "show_comments=1")."#".$comment["id"]."\">".$comment["page_tag"]."</a><br />\n");
$user_comments_count++;
}
if ($user_comments_count == 0)
{
print("<em>User has not commented any pages yet.</em>");
}
}
else
{
print("<em>No comments found.</em>");
}
}
}
else
{
print("<em>No user specified</em>");
}
?>
// Shows pages commented by $_GET["user"] or, if this is not provided, by the current user.
// Adapted from actions/mychanges.php written by Carlo Zottmann
$page = $this->GetPageTag();
$user = (($_GET["user"])? $_GET["user"] : $this->GetUserName());
if ($user)
{
$user_comments_count = 0;
if ($_GET["alpha"] == 1)
{
echo $this->Format("== Pages commented by [[".$user."]] == --- --- ");
print("<strong>This is a list of pages commented by ".$this->Link($user).", along with the time of the comment (<a href=\"".$page."?user=".$user."&date=1&action=comments\">order by date</a>).</strong><br /><br />\n");
if ($comments = $this->LoadAll("SELECT id, page_tag, time FROM ".$this->config["table_prefix"]."comments WHERE user =
'".mysql_real_escape_string($user)."' ORDER BY page_tag ASC, time DESC"))
{
foreach ($comments as $comment)
{
if ($last_tag != $comment["page_tag"]) {
$last_tag = $comment["page_tag"];
$firstChar = strtoupper($comment["page_tag"][0]);
if (!preg_match("/[A-Z,a-z]/", $firstChar)) {
$firstChar = "#";
}
if ($firstChar != $curChar) {
if ($curChar) print("<br />\n");
print("<strong>$firstChar</strong><br />\n");
$curChar = $firstChar;
}
// print entry
print(" (".$comment["time"].") <a href=\"".$this->href("", $comment["page_tag"], "show_comments=1")."#".$comment["id"]."\">".$comment["page_tag"]."</a><br />\n");
$user_comments_count++;
}
}
if ($user_comments_count == 0)
{
print("<em>User has not commented any pages yet.</em>");
}
}
else
{
print("<em>No comments found.</em>");
}
}
else
{
echo $this->Format("== Pages commented by [[".$user."]] == --- --- ");
print("<strong>This is a list of pages commented by ".$this->Link($user).", ordered by the time of the comment (<a href=\"".$page."?user=".$user."&alpha=1&action=comments\">order alphabetically</a>).</strong><br /><br />\n");
if ($comments = $this->LoadAll("SELECT id, page_tag, time FROM ".$this->config["table_prefix"]."comments WHERE user =
'".mysql_real_escape_string($user)."' ORDER BY time ASC, page_tag ASC"))
{
foreach ($comments as $comment)
{
$commented_pages[$comment["page_tag"]] = $comment["time"];
}
$commented_pages = array_reverse($commented_pages);
foreach ($commented_pages as $comment["page_tag"] => $comment["time"])
{
// day header
list($day, $time) = explode(" ", $comment["time"]);
if ($day != $curday)
{
if ($curday) print("<br />\n");
print("<strong>$day:</strong><br />\n");
$curday = $day;
}
// print entry
print(" (".$time.") <a href=\"".$this->href("", $comment["page_tag"], "show_comments=1")."#".$comment["id"]."\">".$comment["page_tag"]."</a><br />\n");
$user_comments_count++;
}
if ($user_comments_count == 0)
{
print("<em>User has not commented any pages yet.</em>");
}
}
else
{
print("<em>No comments found.</em>");
}
}
}
else
{
print("<em>No user specified</em>");
}
?>