-
Notifications
You must be signed in to change notification settings - Fork 0
/
news_months_menu.php
154 lines (128 loc) · 3.83 KB
/
news_months_menu.php
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
<?php
/**
* Copyright (C) 2008-2011 e107 Inc (e107.org), Licensed under GNU GPL (http://www.gnu.org/licenses/gpl.txt)
* $Id$
*
* News by month menu
*/
if (!defined('e107_INIT')) { exit; }
$cString = 'nq_news_months_menu_'.md5(serialize($parm).USERCLASS_LIST.e_LANGUAGE);
$cached = e107::getCache()->retrieve($cString);
if(!empty($parm))
{
if(is_string($parm))
{
parse_str($parm, $parms);
}
else
{
$parms = $parm;
}
}
if(false === $cached)
{
if(!function_exists('newsFormatDate'))
{
function newsFormatDate($year, $month, $day = "") {
$date = $year;
$date .= (strlen($month) < 2)?"0".$month:
$month;
$date .= (strlen($day) < 2 && $day != "")?"0".$day:
$day;
return $date;
}
}
if(!isset($parms['showarchive']))
{
$parms['showarchive'] = 0;
}
// e107::lan('blogcalendar_menu', e_LANGUAGE); // FIXME decide on language file structure (#743)
e107::includeLan(e_PLUGIN.'blogcalendar_menu/languages/'.e_LANGUAGE.'.php');
$tp = e107::getParser();
$sql = e107::getDb();
$marray = e107::getDate()->terms('month');
//$parms['year'] = "2011 0";
if(vartrue($parms['year']))
{
$date = $parms['year'];
list($cur_year, $cur_month) = explode(" ", date($date));
$start = mktime(0, 0, 0, 1, 1, $cur_year);
$end = mktime(23, 59, 59, 12, 31, $cur_year);
}
else
{
$date = "Y n";
list($cur_year, $cur_month) = explode(" ", date($date));
$start = mktime(0, 0, 0, 1, 1, $cur_year);
$end = time();
}
$req_year = $cur_year;
if(e_PAGE == 'news.php' && strpos(e_QUERY, "month") !== false)
{
$tmp = explode('.', e_QUERY);
$item = $tmp[1];
$req_month = intval(substr($item, 4, 2));
$req = 'month';
}
else
{
$req_month = $cur_month;
}
$xmonth_cnt = array();
$month_links = array();
e107::getDebug()->logTime('News months menu');
if(!$sql->select("news", "news_id, news_datestamp", "news_class IN (".USERCLASS_LIST.") AND (FIND_IN_SET('0', news_render_type) OR FIND_IN_SET(1, news_render_type)) AND news_datestamp > ".intval($start)." AND news_datestamp < ".intval($end)." ORDER BY news_datestamp DESC"))
{
e107::getCache()->set($cString, '');
return '';
}
while ($news = $sql->fetch())
{
$xmonth = date("n", $news['news_datestamp']);
if ((!isset($month_links[$xmonth]) || !$month_links[$xmonth]))
{
$xmonth_cnt[$xmonth] = 0;
$month_links[$xmonth] = e107::getUrl()->create('news/list/month', 'id='.newsFormatDate($req_year, $xmonth));
}
$xmonth_cnt[$xmonth]++;
}
e107::getDebug()->log($month_links);
// go over the link array and create the option fields
$menu_text = array();
$template = e107::getTemplate('news', 'news_menu', 'months', true, true);
$bullet = defined('BULLET') ? THEME_ABS.'images/'.BULLET : THEME_ABS.'images/bullet2.gif';
$vars = new e_vars(array('bullet' => $bullet));
foreach($month_links as $index => $val)
{
$vars->addData(array(
'active' => $index == $req_month ? " active" : '',
'url' => $val,
'month' => $marray[$index],
'count' => $xmonth_cnt[$index],
));
$menu_text[] = $tp->simpleParse($template['item'], $vars);
}
$cached = $template['start'].implode(varset($template['separator'],''), $menu_text).$template['end'];
$ns->setContent('text', $cached);
if($cached)
{
if(!$parms['showarchive'])
{
if(isset($template['footer']))
{
$footer = $tp->replaceConstants($template['footer'],'abs');
$footer = $tp->parseTemplate($footer,true);
$ns->setUniqueId('news-months-menu')->setContent('footer', $footer);
}
else
{
$footer = '<div class="e-menu-link news-menu-archive"><a class="btn btn-default btn-secondary btn-sm" href="'.e_PLUGIN_ABS.'blogcalendar_menu/archive.php">'.BLOGCAL_L2.'</a></div>';
$cached .= $footer;
}
}
$cached = $ns->tablerender(BLOGCAL_L1." ".$req_year, $cached, 'news_months_menu', true);
$ns->setUniqueId(null);
}
e107::getCache()->set($cString, $cached);
}
echo $cached;