Source of trunk/postcalendar.php at revision HEAD (06/16/2010 12:06:43, 4292 bytes, 117 lines, language: php) [download]:

1
<?php
2
3
/*
4
** Posting Calendar Functions
5
** for CodewiseBlog Multi-User
6
**
7
** by William R. Fraser <wrf@codewise.org>
8
** Copyright (c) 2005-2008 Codewise.org
9
*/
10
11
/*
12
** This file is part of CodewiseBlog
13
**
14
** CodewiseBlog is free software; you can redistribute it and/or modify
15
** it under the terms of the GNU General Public License as published by
16
** the Free Software Foundation; either version 2 of the License, or
17
** (at your option) any later version.
18
**
19
** CodewiseBlog is distributed in the hope that it will be useful,
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
** GNU General Public License for more details.
23
**
24
** You should have received a copy of the GNU General Public License
25
** along with CodewiseBlog; if not, write to the Free Software
26
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27
*/
28
29
function postcalendar()
30
{
31
    global $db;
32
33
    $q $db->issue_query("SELECT DISTINCT FROM_UNIXTIME(timestamp, '%Y') AS year, FROM_UNIXTIME(timestamp, '%m') AS month, FROM_UNIXTIME(timestamp, '%M') AS name FROM topics WHERE blogid = '" BLOGID "' ORDER BY timestamp DESC");
34
    $data $db->fetch_all($qL1SQL_ASSOC);
35
36
    if(count($data) == 0)
37
        return(skinvoodoo("postcalendar""", array("contents" => "<i>Nothing to show.</i>")));
38
39
    $latestmonth true;
40
    foreach($data as $row)
41
    {
42
        $year $row['year'];
43
        $month $row['month'];
44
        $name $row['name'];
45
46
        $out .= skinvoodoo("postcalendar""monthrow", array(
47
            "url" => INDEX_URL "?year=$year&amp;month=$month",
48
            "url2" => INDEX_URL "archive/$year/$month/",
49
            "monthname" => $name,
50
            "year" => $year
51
        ));
52
53
        /*
54
        ** For the most recent month, display a list of the 5 most recent titles as
55
        ** links. If a month and year were set in the query, however, show the 5
56
        ** most recent titles in that month instead.
57
        **                                                            | <- if the month and year were set in the query ----> | otherwise, just the first
58
        */
59
        if( (is_numeric($_GET['month']) && is_numeric($_GET['year'])) ? ($_GET['month'] == $month && $_GET['year'] == $year) : $latestmonth)
60
        {
61
            $time1 mktime(0,0,0$month1$year);
62
            $day date("t"$time1);
63
            $time2 mktime(23,59,59$month$day$year);
64
65
            $q $db->issue_query("SELECT title,tid,extra FROM topics WHERE timestamp >= " $db->prepare_value($time1) . " AND timestamp <= " $db->prepare_value($time2) . " AND blogid = '" BLOGID "' ORDER BY timestamp DESC");
66
            $rows $db->fetch_all($q);
67
68
            if($_GET['page'] > 1)
69
            {
70
                for($i=0$iTOPICS_PER_PAGE * ($_GET['page'] - 1); $i++)
71
                {
72
                    array_shift($rows);
73
                }
74
            }
75
76
            while(count($rows) > TOPICS_PER_PAGE)
77
                array_pop($rows);
78
79
            $currentmonth "";
80
81
            foreach($rows as $row)
82
            {
83
                $tid $row['tid'];
84
                $title $row['title'];
85
                $urltitle string_to_url_goodness($title);
86
87
                if($row['extra'] == "HIDE")
88
                    continue;
89
90
                if(strlen($title) > 50)
91
                    $title substr($title047) . "...";
92
93
                $currentmonth .= skinvoodoo("postcalendar""topiclink", array(
94
                    "url" => INDEX_URL "?tid=$tid",
95
                    "url2" => INDEX_URL "article/$urltitle",
96
                    "title" => $title
97
                ));
98
            }
99
100
            if($db->num_rows[$q] - (($_GET['page'] - 1) * TOPICS_PER_PAGE) > TOPICS_PER_PAGE)
101
                $currentmonth .= skinvoodoo("postcalendar""nextpage", array(
102
                    "url" => INDEX_URL "?year=$year&amp;month=$month&amp;page=2",
103
                    "url2" => INDEX_URL "archive/$year/$month/?page=2",
104
                ));
105
106
            $out .= skinvoodoo("postcalendar""latestmonth", array("contents" => $currentmonth));
107
        }
108
109
        $latestmonth false;
110
111
    }
112
113
    return(skinvoodoo("postcalendar""", array("contents" => $out)));
114
}
115
116
?>
117

powered by Codewise Manager v0.1-DEV :: 41.75ms, 6 ops, 3 queries