From 7a4f578118c21f5bfddb5c7125be591a88b04aef Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 13 Dec 2004 13:22:58 +0000 Subject: [PATCH] new BlogArchives plugin for the new blog theme. enable default box method for all plugins. Minor search improvement. git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4269 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/WikiDB.php | 10 ++- lib/WikiPlugin.php | 19 +++-- lib/plugin/BlogArchives.php | 159 ++++++++++++++++++++++++++++++++++++ lib/plugin/WikiBlog.php | 11 ++- 4 files changed, 187 insertions(+), 12 deletions(-) create mode 100644 lib/plugin/BlogArchives.php diff --git a/lib/WikiDB.php b/lib/WikiDB.php index a37af73c7..f81a0bac6 100644 --- a/lib/WikiDB.php +++ b/lib/WikiDB.php @@ -1,5 +1,5 @@ getPackedContent()); } - /** + /** * Get the pagename of the revision. * * @access public @@ -1493,6 +1493,9 @@ class WikiDB_PageRevision function getPageName() { return $this->_pagename; } + function getName() { + return $this->_pagename; + } /** * Determine whether revision is the latest. @@ -2141,6 +2144,9 @@ function _sql_debuglog_shutdown_function() { } // $Log: not supported by cvs2svn $ +// Revision 1.117 2004/12/13 08:15:09 rurban +// false is wrong. null might be better but lets play safe. +// // Revision 1.116 2004/12/10 22:15:00 rurban // fix $page->get('_cached_html) // refactor upgrade db helper _convert_cached_html() to be able to call them from WikiAdminUtils also. diff --git a/lib/WikiPlugin.php b/lib/WikiPlugin.php index a1e1226d6..578793449 100644 --- a/lib/WikiPlugin.php +++ b/lib/WikiPlugin.php @@ -1,5 +1,5 @@ _getName(); + // box is used to display a fixed-width, narrow version with common header + function box($args=false, $request=false, $basepage=false) { + if (!$request) $request =& $GLOBALS['request']; + $dbi = $request->getDbh(); + return $this->makeBox('', $this->run($dbi, $args, $request, $basepage)); + } + + function makeBox($title, $body) { + if (!$title) $title = $this->getName(); return HTML::div(array('class'=>'box'), - HTML::div(array('class'=>'box-title'),$title), - HTML::div(array('class'=>'box-data'),$body)); + HTML::div(array('class'=>'box-title'), $title), + HTML::div(array('class'=>'box-data'), $body)); } function error ($message) { diff --git a/lib/plugin/BlogArchives.php b/lib/plugin/BlogArchives.php new file mode 100644 index 000000000..da2db2a41 --- /dev/null +++ b/lib/plugin/BlogArchives.php @@ -0,0 +1,159 @@ + false, + 'order' => 'reverse', // latest first + 'info' => 'month,numpages', // ignored + 'month' => false, + 'noheader' => 0 + )); + } + + // "2004-12" => "December 2004" + function _monthTitle($month){ + //list($year,$mon) = explode("-",$month); + return strftime("%B %Y", strtotime($month."-01")); + } + + // "User/Blog/2004-12-13/12:28:50+01:00" => array('month' => "2004-12", ...) + 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; + 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); + } + + function _nonDefaultArgs($args) { + return array_diff_assoc($args, $this->getDefaultArguments()); + } + + function run($dbi, $argstr, &$request, $basepage) { + if (is_array($argstr)) + $args =& $argstr; + else + $args = $this->getArgs($argstr, $request); + $user = $request->getUser(); + if ($user->isAuthenticated()) + $args['user'] = $user->UserName(); + else + $args['user'] = ADMIN_USER; + $info = explode(',', $args['info']); + //$pagelist = new PageList($args['info'], $args['exclude'], $args); + //if (!is_array('pagename'), explode(',', $info)) + // unset($pagelist->_columns['pagename']); + + //$prefix = $args['user'].SUBPAGE_SEPARATOR."Blog"; + if ($args['month']) { + $prefix = $args['user'].SUBPAGE_SEPARATOR."Blog".SUBPAGE_SEPARATOR.$args['month'].'-'; + $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix')); + $html = HTML::ul(); + while ($page = $pages->next()) { + $rev = $page->getCurrentRevision(false); + if ($rev->get('pagetype') != 'wikiblog') continue; + $blog = $this->_blog($rev); + $html->pushContent(WikiLink($page, 'known', $rev->get('summary'))); + } + if (!$args['noheader']) + return HTML(HTML::h3(sprintf(_("Blog Entries for %s:"), $this->_monthTitle($args['month']))), + $html); + else + return $html; + } + + $blogs = $this->findBlogs ($dbi, $args['user'], 'wikiblog'); + if ($blogs) { + if (!$basepage) $basepage = _("BlogArchives"); + $html = HTML::ul(); + usort($blogs, array("WikiPlugin_WikiBlog", "cmp")); + if ($args['order'] == 'reverse') + $blogs = array_reverse($blogs); + // collapse pagenames by month + $months = array(); + foreach ($blogs as $rev) { + $blog = $this->_blog($rev); + $mon = $blog['month']; + if (empty($months[$mon])) + $months[$mon] = + array('title' => $this->_monthTitle($mon), + 'num' => 1, + 'month' => $mon, + 'link' => WikiURL($basepage, + $this->_nonDefaultArgs(array('month' => $mon)))); + + else + $months[$mon]['num']++; + } + foreach ($months as $m) { + $html->pushContent(HTML::a(array('href'=>$m['link'], + 'class' => 'named-wiki'), + $m['title'] . " (".$m['num'].")")); + } + if (!$args['noheader']) + return HTML(HTML::h3(_("Blog Archives:")), $html); + else + return $html; + } else + return ''; + } + + // box is used to display a fixed-width, narrow version with common header + function box($args=false, $request=false, $basepage=false) { + if (!$request) $request =& $GLOBALS['request']; + if (!$args or empty($args['limit'])) $args['limit'] = 10; + if (!$args or empty($args['noheader'])) $args['noheader'] = 1; + return $this->makeBox('', $this->run($request->_dbi, $args, $request, $basepage)); + } +}; + +// $Log: not supported by cvs2svn $ + +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: +?> \ No newline at end of file diff --git a/lib/plugin/WikiBlog.php b/lib/plugin/WikiBlog.php index 374e6f364..27307a00e 100644 --- a/lib/plugin/WikiBlog.php +++ b/lib/plugin/WikiBlog.php @@ -1,5 +1,5 @@ titleSearch(new TextSearchQuery($prefix, true)); + //require_once('lib/TextSearchQuery.php'); + $pages = $dbi->titleSearch(new TextSearchQuery("^".$prefix, true, 'posix')); $blogs = array(); while ($page = $pages->next()) { @@ -350,6 +350,9 @@ extends WikiPlugin }; // $Log: not supported by cvs2svn $ +// Revision 1.19 2004/11/26 18:39:02 rurban +// new regex search parser and SQL backends (90% complete, glob and pcre backends missing) +// // Revision 1.18 2004/05/14 20:55:04 rurban // simplified RecentComments // -- 2.45.0