Revision [1108]
This is an old revision of RichardTerry made by RichardTerry on 2004-09-03 02:39:34.
Richard Terry
I created a very simple Blog Action for my personal website.
Here is actions/blog.php:
<?php
if (!isset($name))
{
print "<span class='error'>You need to include \"name=\" when using the blog action.</span>";
}
else if ($pages = $this->LoadBlogEntries($name))
{
$curday = "";
if ($user = $this->GetUser()) {
$max = $user["changescount"];
} else {
$max = 50;
}
foreach ($pages as $i => $page)
{
if (($i < $max) || !$max)
{
// day header
list($day, $time) = explode(" ", $page["firsttime"]);
if ($day != $curday)
{
if ($curday) print("</span><br />\n");
print("<strong>$day:</strong><br />\n<span class=\"recentchanges\">");
$curday = $day;
}
// Begin entry
$pagetag = $page["tag"];
// Print Title. Strip "Blog" from page tag and add spaces.
print "<h1>".$this->BeautifyTitle($pagetag)."</h1><br />\n";
// I used Dreck Fehler's include action code here.
$pagename = strtolower($pagetag);
if (!$this->config["includes"]) $this->config["includes"][] = strtolower($this->tag);
if (!in_array($pagename, $this->config["includes"]) && $pagename != $this->tag) {
if ($this->HasAccess("read", $pagename)) {
$this->config["includes"][] = $pagename;
$blogpage = $this->LoadPage($pagename);
print $this->Format($blogpage["body"]);
}
} else print "<span class='error'>Circular reference detected</span>";
}
print "<br /><br />\n";
}
}
?>
if (!isset($name))
{
print "<span class='error'>You need to include \"name=\" when using the blog action.</span>";
}
else if ($pages = $this->LoadBlogEntries($name))
{
$curday = "";
if ($user = $this->GetUser()) {
$max = $user["changescount"];
} else {
$max = 50;
}
foreach ($pages as $i => $page)
{
if (($i < $max) || !$max)
{
// day header
list($day, $time) = explode(" ", $page["firsttime"]);
if ($day != $curday)
{
if ($curday) print("</span><br />\n");
print("<strong>$day:</strong><br />\n<span class=\"recentchanges\">");
$curday = $day;
}
// Begin entry
$pagetag = $page["tag"];
// Print Title. Strip "Blog" from page tag and add spaces.
print "<h1>".$this->BeautifyTitle($pagetag)."</h1><br />\n";
// I used Dreck Fehler's include action code here.
$pagename = strtolower($pagetag);
if (!$this->config["includes"]) $this->config["includes"][] = strtolower($this->tag);
if (!in_array($pagename, $this->config["includes"]) && $pagename != $this->tag) {
if ($this->HasAccess("read", $pagename)) {
$this->config["includes"][] = $pagename;
$blogpage = $this->LoadPage($pagename);
print $this->Format($blogpage["body"]);
}
} else print "<span class='error'>Circular reference detected</span>";
}
print "<br /><br />\n";
}
}
?>
Here are the changes I made to wikka.php:
function LoadPagesLinkingFrom($tag) { return $this->LoadAll("select to_tag as tag from ".$this->config["table_prefix"]."links where from_tag = '".mysql_real_escape_string($tag)."' order by tag"); } function LoadBlogEntries($tag) { //Get pages linking to Blog entry list page and form part of query string $blogPages = $this->LoadPagesLinkingFrom($tag); if (count($blogPages) == 0) { return false; } $i = 0; $queryString = ""; foreach ($blogPages as $blogPage) { $i++; if ($i < count($blogPages)) { $queryString .= "\"".$blogPage["tag"]."\", "; } else { $queryString .= "\"".$blogPage["tag"]."\""; } } if ($pages = $this->LoadAll("select min(entry2.id) as firstid, min(entry2.time) as firsttime, entry1.* from ".$this->config["table_prefix"]."pages entry1, ".$this->config["table_prefix"]."pages entry2 where entry1.tag = entry2.tag and entry1.tag in (".$queryString.") and entry1.latest ='Y' group by entry1.tag order by firstid desc")) { foreach ($pages as $page) { $this->CachePage($page); } return $pages; } } function BeautifyTitle($title) { /* * I scarfed this function from John Greenway's JSPWiki page * http://www.jspwiki.org/Wiki.jsp?page=JohnGreenaway */ $result = ""; for($i = 0; $i <= strlen($title); $i++) { if(ctype_upper($title[$i]) && ($i > 0)) { if (($i < (strlen($title) - 1) && ctype_lower($title[$i+1])) || ctype_lower($title[$i-1])) { $result.=' '; } } $result.= $title[$i]; } return $result; }