-<?php // -*-php-*-
-// $Id: WikiBlog.php 8071 2011-05-18 14:56:14Z vargenau $
+<?php
+
/*
* Copyright 2002,2003,2007,2009 $ThePhpWikiProgrammingTeam
*
* This plugin shows 'blogs' (comments/news) associated with a
* particular page and provides an input form for adding a new blog.
*
- * USAGE:
- * Add <<WikiBlog >> at your PersonalPage and BlogArchive and
- * BlogJournal will find the Blog entries automatically.
- *
- * Now it is also the base class for all attachable pagetypes:
- * "wikiblog", "comment" and "wikiforum"
- *
- * HINTS/COMMENTS:
- *
- * To have the blog show up on a seperate page:
- * On TopPage, use
- * <<WikiBlog mode=add>>
- * Create TopPage/Blog with this page as actionpage:
- * <<WikiBlog pagename=TopPage mode=show>>
- *
- * To have the main ADMIN_USER Blog appear under Blog and not under WikiBlog/Blog
- * or UserName/Blog as for other users blogs,
- * define BLOG_DEFAULT_EMPTY_PREFIX=true
- * use the page Blog as basepage
- * and user="" (as default for ADMIN or current user) and pagename="Blog"
- * in the various blog plugins (BlogArchives, BlogJournal)
- *
* TODO:
*
* It also works as an action-page if you create a page called 'WikiBlog'
*/
class WikiPlugin_WikiBlog
-extends WikiPlugin
+ extends WikiPlugin
{
- function getName () {
- return _("WikiBlog");
- }
-
- function getDescription () {
- return sprintf(_("Show and add blogs for %s"),'[pagename]');
+ function getDescription()
+ {
+ return sprintf(_("Show and add blogs for %s."), '[pagename]');
}
// Arguments:
- // page - page which is blogged to (default current page)
- //
- // order - 'normal' - place in chronological order
- // - 'reverse' - place in reverse chronological order
- //
- // mode - 'show' - only show old blogs
- // 'add' - only show entry box for new blog
- // 'show,add' - show old blogs then entry box
- // 'add,show' - show entry box followed by old blogs
- //
// TODO:
//
// - arguments to allow selection of time range to display
// display as e.g. June 2002 archive, July 2002 archive, etc..
// - captions for 'show' and 'add' sections
-
- function getDefaultArguments() {
- return array('pagename' => '[pagename]',
- 'order' => 'normal',
- 'mode' => 'show,add',
- 'noheader' => false
- );
+ function getDefaultArguments()
+ {
+ return array('pagename' => '[pagename]',
+ 'order' => 'normal',
+ 'mode' => 'show,add',
+ 'noheader' => false
+ );
}
- function run($dbi, $argstr, &$request, $basepage) {
+ function run($dbi, $argstr, &$request, $basepage)
+ {
$args = $this->getArgs($argstr, $request);
// allow empty pagenames for ADMIN_USER style blogs: "Blog/day"
//if (!$args['pagename'])
$seen[$show] = 1;
switch ($show) {
- case 'show':
- $html->pushContent($this->showAll($request, $args));
- break;
- case 'add':
- $html->pushContent($this->showForm($request, $args));
- break;
- default:
- return $this->error(sprintf("Bad mode ('%s')", $show));
+ case 'show':
+ $html->pushContent($this->showAll($request, $args));
+ break;
+ case 'add':
+ $html->pushContent($this->showForm($request, $args));
+ break;
+ default:
+ return $this->error(sprintf("Bad mode (ā%sā)", $show));
}
}
return $html;
/**
* posted: required: pagename, content. optional: summary
*/
- function add (&$request, $posted, $type='wikiblog') {
+ function add(&$request, $posted, $type = 'wikiblog')
+ {
// This is similar to editpage. Shouldn't we use just this for preview?
$parent = $posted['pagename'];
if (empty($parent)) {
- $prefix = ""; // allow empty parent for default "Blog/day"
+ $prefix = ""; // allow empty parent for default "Blog/day"
$parent = HOME_PAGE;
- } elseif (($parent == 'Blog' or $parent == 'WikiBlog') and $type == 'wikiblog')
- { // avoid Blog/Blog/2003-01-11/14:03:02+00:00
+ } elseif (($parent == 'Blog' or $parent == 'WikiBlog') and $type == 'wikiblog') { // avoid Blog/Blog/2003-01-11/14:03:02+00:00
$prefix = "";
$parent = ''; // 'Blog';
- } elseif ($parent == 'Comment' and $type == "comment")
- {
+ } elseif ($parent == 'Comment' and $type == "comment") {
$prefix = "";
$parent = ''; // 'Comment';
- } elseif ($parent == 'Forum' and $type == "wikiforum")
- {
+ } elseif ($parent == 'Forum' and $type == "wikiforum") {
$prefix = "";
$parent = ''; // 'Forum';
} else {
* updates are atomic with the version creation.
*/
- $blog_meta = array('ctime' => $now,
- 'creator' => $user->getId(),
- 'creator_id' => $user->getAuthenticatedId(),
- );
-
+ $blog_meta = array('ctime' => $now,
+ 'creator' => $user->getId(),
+ 'creator_id' => $user->getAuthenticatedId(),
+ );
// Version meta-data
$summary = trim($posted['summary']);
// edit: private only
$perm = new PagePermission();
$perm->perm['edit'] = $perm->perm['remove'];
- $version_meta = array('author' => $blog_meta['creator'],
- 'author_id' => $blog_meta['creator_id'],
- 'markup' => 2.0, // assume new markup
- 'summary' => $summary ? $summary : _("New comment."),
- 'mtime' => $now,
- 'pagetype' => $type,
- $type => $blog_meta,
- 'perm' => $perm->perm,
- );
+ $version_meta = array('author' => $blog_meta['creator'],
+ 'author_id' => $blog_meta['creator_id'],
+ 'markup' => 2.0, // assume new markup
+ 'summary' => $summary ? $summary : _("New comment."),
+ 'mtime' => $now,
+ 'pagetype' => $type,
+ $type => $blog_meta,
+ 'perm' => $perm->perm,
+ );
if ($type == 'comment')
unset($version_meta['summary']);
$saved = false;
if ($type != 'wikiforum')
- $pagename = $this->_blogPrefix($type);
+ $pagename = $this->blogPrefix($type);
else {
- $pagename = substr($summary,0,12);
+ $pagename = substr($summary, 0, 12);
if (empty($pagename)) {
$saved = true;
trigger_error("Empty title", E_USER_WARNING);
// Maybe add the BlogArchives plugin instead for the new interim subpage.
$redirected = $prefix . $pagename;
if (!$dbi->isWikiPage($redirected)) {
- if (!$parent) $parent = HOME_PAGE;
+ if (!$parent) $parent = HOME_PAGE;
require_once 'lib/loadsave.php';
$pageinfo = array('pagename' => $redirected,
- 'content' => '<?plugin RedirectTo page="'.$parent.'" ?>',
- 'pagedata' => array(),
- 'versiondata' => array('author' => $blog_meta['creator'], 'is_minor_edit' => 1),
- );
+ 'content' => '<<RedirectTo page="' . $parent . '">>',
+ 'pagedata' => array(),
+ 'versiondata' => array('author' => $blog_meta['creator'], 'is_minor_edit' => 1),
+ );
SavePage($request, $pageinfo, '', '');
}
$redirected = $prefix . $pagename . SUBPAGE_SEPARATOR . preg_replace("/T.*/", "", "$time");
if (!$dbi->isWikiPage($redirected)) {
- if (!$parent) $parent = HOME_PAGE;
+ if (!$parent) $parent = HOME_PAGE;
require_once 'lib/loadsave.php';
$pageinfo = array('pagename' => $redirected,
- 'content' => '<?plugin RedirectTo page="'.$parent.'" ?>',
- 'pagedata' => array(),
- 'versiondata' => array('author' => $blog_meta['creator'], 'is_minor_edit' => 1),
- );
+ 'content' => '<<RedirectTo page="' . $parent . '">>',
+ 'pagedata' => array(),
+ 'versiondata' => array('author' => $blog_meta['creator'], 'is_minor_edit' => 1),
+ );
SavePage($request, $pageinfo, '', '');
}
$p = $dbi->getPage($prefix . $pagename . SUBPAGE_SEPARATOR
- . str_replace("T", SUBPAGE_SEPARATOR, "$time"));
+ . str_replace("T", SUBPAGE_SEPARATOR, "$time"));
$pr = $p->getCurrentRevision();
// Version should be zero. If not, page already exists
// Any way to jump back to preview mode???
}
- function showAll (&$request, $args, $type="wikiblog") {
+ function showAll(&$request, $args, $type = "wikiblog")
+ {
// FIXME: currently blogSearch uses WikiDB->titleSearch to
// get results, so results are in alphabetical order.
// When PageTypes fully implemented, could have smarter
if ($blogs) {
// First reorder
usort($blogs, array("WikiPlugin_WikiBlog",
- "cmp"));
+ "cmp"));
if ($args['order'] == 'reverse')
$blogs = array_reverse($blogs);
- $name = $this->_blogPrefix($type);
+ $name = $this->blogPrefix($type);
if (!$args['noheader'])
$html->pushContent(HTML::h4(array('class' => "$type-heading"),
- fmt("%s on %s:", $name, WikiLink($basepage))));
+ fmt("%s on %s:", $name, WikiLink($basepage))));
foreach ($blogs as $rev) {
if (!$rev->get($type)) {
// Ack! this is an old-style blog with data ctime in page meta-data.
- $content = $this->_transformOldFormatBlog($rev, $type);
- }
- else {
+ $content = $this->transformOldFormatBlog($rev, $type);
+ } else {
$content = $rev->getTransformedContent($type);
}
$html->pushContent($content);
// Subpage for the basepage. All Blogs/Forum/Comment entries are
// Subpages under this pagename, to find them faster.
- function _blogPrefix($type='wikiblog') {
+ protected function blogPrefix($type = 'wikiblog')
+ {
if ($type == 'wikiblog')
$basepage = "Blog";
elseif ($type == 'comment')
- $basepage = "Comment";
- elseif ($type == 'wikiforum')
- $basepage = substr($summary,0,12);
- //$basepage = _("Message"); // FIXME: we use now the first 12 chars of the summary
+ $basepage = "Comment"; elseif ($type == 'wikiforum')
+ $basepage = substr($summary, 0, 12);
+ //$basepage = _("Message"); // FIXME: we use now the first 12 chars of the summary
return $basepage;
}
- function _transformOldFormatBlog($rev, $type='wikiblog') {
+ private function transformOldFormatBlog($rev, $type = 'wikiblog')
+ {
$page = $rev->getPage();
$metadata = array();
foreach (array('ctime', 'creator', 'creator_id') as $key)
return new TransformedText($page, $rev->getPackedContent(), $meta, $type);
}
- function findBlogs (&$dbi, $basepage='', $type='wikiblog') {
+ function findBlogs(&$dbi, $basepage = '', $type = 'wikiblog')
+ {
$prefix = (empty($basepage)
- ? ""
- : $basepage . SUBPAGE_SEPARATOR) . $this->_blogPrefix($type);
- $pages = $dbi->titleSearch(new TextSearchQuery('"'.$prefix.'"', true, 'none'));
+ ? ""
+ : $basepage . SUBPAGE_SEPARATOR) . $this->blogPrefix($type);
+ $pages = $dbi->titleSearch(new TextSearchQuery('"' . $prefix . '"', true, 'none'));
$blogs = array();
while ($page = $pages->next()) {
return $blogs;
}
- function cmp($a, $b) {
- return(strcmp($a->get('mtime'),
- $b->get('mtime')));
+ function cmp($a, $b)
+ {
+ return (strcmp($a->get('mtime'),
+ $b->get('mtime')));
}
- function showForm (&$request, $args, $template='blogform') {
+ function showForm(&$request, $args, $template = 'blogform')
+ {
// Show blog-entry form.
$args = array('PAGENAME' => $args['pagename'],
- 'HIDDEN_INPUTS' =>
- HiddenInputs($request->getArgs()));
+ 'HIDDEN_INPUTS' =>
+ HiddenInputs($request->getArgs()));
if (ENABLE_EDIT_TOOLBAR and !ENABLE_WYSIWYG and ($template != 'addcomment')) {
include_once 'lib/EditToolbar.php';
$toolbar = new EditToolbar();
}
// "2004-12" => "December 2004"
- function _monthTitle($month){
- if (!$month) $month = strftime("%Y-%m");
+ protected function monthTitle($month)
+ {
+ if (!$month) $month = strftime("%Y-%m");
//list($year,$mon) = explode("-",$month);
- return strftime("%B %Y", strtotime($month."-01"));
+ return strftime("%B %Y", strtotime($month . "-01"));
}
// "UserName/Blog/2004-12-13/12:28:50+01:00" => array('month' => "2004-12", ...)
- function _blog($rev_or_page) {
- $pagename = $rev_or_page->getName();
+ protected function _blog($rev_or_page)
+ {
+ $pagename = $rev_or_page->getName();
if (preg_match("/^(.*Blog)\/(\d\d\d\d-\d\d)-(\d\d)\/(.*)/", $pagename, $m))
- list(,$prefix,$month,$day,$time) = $m;
+ list(, $prefix, $month, $day, $time) = $m;
return array('pagename' => $pagename,
- // page (list pages per month) or revision (list months)?
- //'title' => isa($rev_or_page,'WikiDB_PageRevision') ? $rev_or_page->get('summary') : '',
- //'monthtitle' => $this->_monthTitle($month),
- 'month' => $month,
- 'day' => $day,
- 'time' => $time,
- 'prefix' => $prefix);
+ // page (list pages per month) or revision (list months)?
+ //'title' => isa($rev_or_page,'WikiDB_PageRevision') ? $rev_or_page->get('summary') : '',
+ //'monthtitle' => $this->monthTitle($month),
+ 'month' => $month,
+ 'day' => $day,
+ 'time' => $time,
+ 'prefix' => $prefix);
}
- function _nonDefaultArgs($args) {
- return array_diff_assoc($args, $this->getDefaultArguments());
+ protected function nonDefaultArgs($args)
+ {
+ return array_diff_assoc($args, $this->getDefaultArguments());
}
-};
+}
// Local Variables:
// mode: php