My favorites | Sign in
Project Logo
                
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php

/**
* Frog CMS - Content Management Simplified. <http://www.madebyfrog.com>
* Copyright (C) 2008 Philippe Archambault <philippe.archambault@gmail.com>
*
* This file is part of Frog CMS.
*
* Frog CMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Frog CMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Frog CMS. If not, see <http://www.gnu.org/licenses/>.
*
* Frog CMS has made an exception to the GNU General Public License for plugins.
* See exception.txt for details and the full text.
*/

/**
* The Archive plugin provides an Archive pagetype behaving similar to a blog or news archive.
*
* @package frog
* @subpackage plugin.archive
*
* @author Philippe Archambault <philippe.archambault@gmail.com>
* @version 1.0
* @since Frog version 0.9.0
* @license http://www.gnu.org/licenses/gpl.html GPL License
* @copyright Philippe Archambault, 2008
*/

/**
* The Archive class...
*/
class Archive
{
public function __construct(&$page, $params)
{
$this->page =& $page;
$this->params = $params;

switch(count($params))
{
case 0: break;
case 1:
if (strlen((int) $params[0]) == 4)
$this->_archiveBy('year', $params);
else
$this->_displayPage($params[0]);
break;

case 2:
$this->_archiveBy('month', $params);
break;

case 3:
$this->_archiveBy('day', $params);
break;

case 4:
$this->_displayPage($params[3]);
break;

default:
page_not_found();
}
}

private function _archiveBy($interval, $params)
{
$this->interval = $interval;

global $__FROG_CONN__;

$page = $this->page->children(array(
'where' => "behavior_id = 'archive_{$interval}_index'",
'limit' => 1
), array(), true);

if ($page)
{
$this->page = $page;
$month = isset($params[1]) ? (int)$params[1]: 1;
$day = isset($params[2]) ? (int)$params[2]: 1;

$this->page->time = mktime(0, 0, 0, $month, $day, (int)$params[0]);
}
else
{
page_not_found();
}
}

private function _displayPage($slug)
{
if ( ! $this->page = find_page_by_slug($slug, $this->page))
page_not_found();
}

function get()
{
$date = join('-', $this->params);

$pages = $this->page->parent->children(array(
'where' => "page.created_on LIKE '{$date}%'",
'order' => 'page.created_on DESC'
));
return $pages;
}

function archivesByYear()
{
global $__FROG_CONN__;

$out = array();

$sql = "SELECT DISTINCT(DATE_FORMAT(created_on, '%Y')) FROM ".TABLE_PREFIX."page WHERE parent_id=? AND status_id != ".Page::STATUS_HIDDEN." ORDER BY created_on DESC";

$stmt = $__FROG_CONN__->prepare($sql);
$stmt->execute(array($this->page->id));

while ($date = $stmt->fetchColumn())
$out[] = $date;

return $out;
}

function archivesByMonth($year='all')
{
global $__FROG_CONN__;

$out = array();

$sql = "SELECT DISTINCT(DATE_FORMAT(created_on, '%Y/%m')) FROM ".TABLE_PREFIX."page WHERE parent_id=? AND status_id != ".Page::STATUS_HIDDEN." ORDER BY created_on DESC";

$stmt = $__FROG_CONN__->prepare($sql);
$stmt->execute(array($this->page->id));

while ($date = $stmt->fetchColumn())
$out[] = $date;

return $out;
}

function archivesByDay($year='all')
{
global $__FROG_CONN__;

$out = array();

if ($year == 'all') $year = '';

$sql = "SELECT DISTINCT(DATE_FORMAT(created_on, '%Y/%m/%d')) FROM ".TABLE_PREFIX."page WHERE parent_id=? AND status_id != ".Page::STATUS_HIDDEN." ORDER BY created_on DESC";

$stmt = $__FROG_CONN__->prepare($sql);
$stmt->execute(array($this->page->id));

while ($date = $stmt->fetchColumn())
$out[] = $date;

return $out;
}
}

class PageArchive extends Page
{
protected function setUrl()
{
$this->url = trim($this->parent->url . date('/Y/m/d/', strtotime($this->created_on)). $this->slug, '/');
}

public function title() { return isset($this->time) ? strftime($this->title, $this->time): $this->title; }

public function breadcrumb() { return isset($this->time) ? strftime($this->breadcrumb, $this->time): $this->breadcrumb; }
}
Show details Hide details

Change log

r431 by martijn.niji on Apr 26, 2009   Diff
Updated license statements to reflect
change to GNU GPLv3 with an exception.
Go to: 
Project members, sign in to write a code review

Older revisions

r411 by martijn.niji on Apr 06, 2009   Diff
General cleanup - removal of old and
commented out code
r295 by martijn.niji on Nov 14, 2008   Diff
Added commenting and documentation for
PHPDoc.
r163 by philippe.archambault on Aug 13, 2008   Diff
license change to AGPLv3
All revisions of this file

File info

Size: 5348 bytes, 182 lines
Hosted by Google Code