1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of shortArchives, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2009-10 - annso |
---|
6 | # contact@as-i-am.fr |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) {return;} |
---|
14 | |
---|
15 | require dirname(__FILE__).'/_widgets.php'; |
---|
16 | |
---|
17 | $core->addBehavior('publicHeadContent',array('publicShortArchives','publicHeadContent')); |
---|
18 | |
---|
19 | |
---|
20 | class publicShortArchives |
---|
21 | { |
---|
22 | |
---|
23 | public static function publicHeadContent($core) |
---|
24 | { |
---|
25 | $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__)); |
---|
26 | echo '<script type="text/javascript" src="'.$url.'/js/accordion.js"></script>'."\n"; |
---|
27 | echo '<style type="text/css">'."\n". |
---|
28 | '@import url('.$url.'/css/shortArchives.css);'."\n". |
---|
29 | '</style>'."\n"; |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | class tplShortArchives |
---|
34 | { |
---|
35 | public static function shortArchivesWidgets($w) |
---|
36 | { |
---|
37 | global $core; |
---|
38 | |
---|
39 | if (($w->homeonly == 1 && $core->url->type != 'default') || |
---|
40 | ($w->homeonly == 2 && $core->url->type == 'default')) { |
---|
41 | return; |
---|
42 | } |
---|
43 | |
---|
44 | $params = array(); |
---|
45 | $params['type'] = 'month'; |
---|
46 | $rs = $core->blog->getDates($params); |
---|
47 | unset($params); |
---|
48 | if ($rs->isEmpty()) { |
---|
49 | return; |
---|
50 | } |
---|
51 | |
---|
52 | $posts = array(); |
---|
53 | while ($rs->fetch()) { |
---|
54 | $posts[dt::dt2str(__('%Y'),$rs->dt)][] = array('url' => $rs->url($core), |
---|
55 | 'date' => html::escapeHTML(dt::dt2str(__('%B'),$rs->dt)), |
---|
56 | 'nbpost' => $rs->nb_post); |
---|
57 | } |
---|
58 | |
---|
59 | $res = |
---|
60 | '<div class="shortArchives">'. |
---|
61 | ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''). |
---|
62 | '<ul>'; |
---|
63 | foreach($posts as $annee=>$post) { |
---|
64 | $res .= '<li><span>'.$annee.'</span><ul>'; |
---|
65 | for($i=0; $i<sizeof($post); $i++) { |
---|
66 | $res .= |
---|
67 | '<li><a href="'.$post[$i]['url'].'">'.$post[$i]['date'].'</a>'. |
---|
68 | ($w->postcount ? ' ('.$post[$i]['nbpost'].')' : ''). |
---|
69 | '</li>'; |
---|
70 | } |
---|
71 | $res .= '</ul></li>'; |
---|
72 | } |
---|
73 | $res .= '</ul></div>'; |
---|
74 | |
---|
75 | return $res; |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|
79 | ?> |
---|