File: BlogArchives.php

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (163 lines) | stat: -rw-r--r-- 5,932 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php // -*-php-*-
rcs_id('$Id: BlogArchives.php,v 1.5 2005/10/29 09:06:37 rurban Exp $');
/*
 * Copyright 2004 $ThePhpWikiProgrammingTeam
 */

//require_once('lib/PageList.php');
require_once('lib/plugin/WikiBlog.php');

/**
 * BlogArchives - List monthly links for the current users blog if signed, 
 * or the ADMIN_USER's Blog if not.
 * On month=... list the blog titles per month.
 *
 * TODO: year=
 *       support PageList (paging, limit, info filters: title, num, month, year, ...)
 *       leave off time subpage? Blogs just per day with one summary title only?
 * @author: Reini Urban
 */
class WikiPlugin_BlogArchives
extends WikiPlugin_WikiBlog
{
    function getName() {
        return _("Archives");
    }

    function getDescription() {
        return _("List blog months links for the current or ADMIN user");
    }

    function getVersion() {
        return preg_replace("/[Revision: $]/", '',
                            "\$Revision: 1.5 $");
    }

    function getDefaultArguments() {
        return //array_merge
               //(
               //PageList::supportedArgs(), 
             array('user'     => '',
                   'order'    => 'reverse',        // latest first
                   'info'     => 'month,numpages', // ignored
                   'month'    => false,
                   'noheader' => 0
                   );
    }

    function run($dbi, $argstr, &$request, $basepage) {
        if (is_array($argstr)) { // can do with array also.
            $args =& $argstr;
            if (!isset($args['order'])) $args['order'] = 'reverse';
        } else {
            $args = $this->getArgs($argstr, $request);
        }
        if (empty($args['user'])) {
            $user = $request->getUser();
            if ($user->isAuthenticated()) {
                $args['user'] = $user->UserName();
            } else {
                $args['user'] = '';
            }
        }
        if (!$args['user'] or $args['user'] == ADMIN_USER) {
            if (BLOG_EMPTY_DEFAULT_PREFIX)
                $args['user'] = ''; 	    // "Blogs/day" pages 
            else
                $args['user'] = ADMIN_USER; // "Admin/Blogs/day" pages 
        }
        $parent = (empty($args['user']) ? '' : $args['user'] . SUBPAGE_SEPARATOR);

        //$info = explode(',', $args['info']);
        //$pagelist = new PageList($args['info'], $args['exclude'], $args);
        //if (!is_array('pagename'), explode(',', $info))
        //    unset($pagelist->_columns['pagename']);
        
        $sp = HTML::Raw('&middot; ');
        if (!empty($args['month'])) {
            $prefix = $parent . $this->_blogPrefix('wikiblog') . 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(HTML::li(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::li(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;
        $args['noheader'] = 1;
        return $this->makeBox(_("Archives"), $this->run($request->_dbi, $args, $request, $basepage));
    }
};

// $Log: BlogArchives.php,v $
// Revision 1.5  2005/10/29 09:06:37  rurban
// move common blog methods to WikiBlog
//
// Revision 1.4  2004/12/16 18:29:00  rurban
// allow empty Blog prefix
//
// Revision 1.3  2004/12/15 17:45:08  rurban
// fix box method
//
// Revision 1.2  2004/12/14 21:35:15  rurban
// support new BLOG_EMPTY_DEFAULT_PREFIX
//
// Revision 1.1  2004/12/13 13:22:57  rurban
// new BlogArchives plugin for the new blog theme. enable default box method
// for all plugins. Minor search improvement.
//

// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>