1 | <?php |
---|
2 | |
---|
3 | $use_cache = 1; |
---|
4 | $use_gzipcompression = 1; |
---|
5 | |
---|
6 | /* Including config and functions files */ |
---|
7 | require_once (dirname(__FILE__).'/b2config.php'); |
---|
8 | $b2blah = dirname(__FILE__).'/'; |
---|
9 | if ( (substr($b2inc,0,1)=='/') || (substr($b2inc,1,1)==':') ) { |
---|
10 | $b2blah='./'; |
---|
11 | } |
---|
12 | require_once ($b2blah.$b2inc.'/b2template.functions.php'); |
---|
13 | require_once ($b2blah.$b2inc.'/b2vars.php'); |
---|
14 | require_once ($b2blah.$b2inc.'/b2functions.php'); |
---|
15 | require_once ($b2blah.$b2inc.'/xmlrpc.inc'); |
---|
16 | require_once ($b2blah.$b2inc.'/xmlrpcs.inc'); |
---|
17 | |
---|
18 | $b2varstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby'); |
---|
19 | |
---|
20 | for ($i=0; $i<count($b2varstoreset); $i += 1) { |
---|
21 | $b2var = $b2varstoreset[$i]; |
---|
22 | if (!isset($$b2var)) { |
---|
23 | if (empty($HTTP_POST_VARS[$b2var])) { |
---|
24 | if (empty($HTTP_GET_VARS[$b2var])) { |
---|
25 | $$b2var = ''; |
---|
26 | } else { |
---|
27 | $$b2var = $HTTP_GET_VARS[$b2var]; |
---|
28 | } |
---|
29 | } else { |
---|
30 | $$b2var = $HTTP_POST_VARS[$b2var]; |
---|
31 | } |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | /* Connecting to the db */ |
---|
36 | dbconnect(); |
---|
37 | |
---|
38 | /* Sending HTTP headers */ |
---|
39 | $last_modified_header = mysql2date('D, d M Y H:i:s', get_lastpostdate()); |
---|
40 | @header ("X-Pingback: $pathserver/xmlrpc.php"); |
---|
41 | if (!$is_winIE) { |
---|
42 | @header ("Last-Modified: $last_modified_header"); |
---|
43 | @header ('ETag: "'.md5($last_modified_header.$pagenow).'"'); |
---|
44 | } |
---|
45 | |
---|
46 | /* Getting settings from db */ |
---|
47 | $posts_per_page = get_settings('posts_per_page'); |
---|
48 | $what_to_show = get_settings('what_to_show'); |
---|
49 | $archive_mode = get_settings('archive_mode'); |
---|
50 | $dateformat = stripslashes(get_settings('date_format')); |
---|
51 | $timeformat = stripslashes(get_settings('time_format')); |
---|
52 | $autobr = get_settings('AutoBR'); |
---|
53 | $time_difference = get_settings('time_difference'); |
---|
54 | |
---|
55 | /* First let's clear some variables */ |
---|
56 | $whichcat = ''; |
---|
57 | $whichauthor = ''; |
---|
58 | $result = ''; |
---|
59 | $where = ''; |
---|
60 | $limits = ''; |
---|
61 | $distinct = ''; |
---|
62 | |
---|
63 | if ($pagenow != 'b2edit.php') { timer_start(); } |
---|
64 | |
---|
65 | if ($posts) |
---|
66 | $posts_per_page=$posts; |
---|
67 | |
---|
68 | // if a month is specified in the querystring, load that month |
---|
69 | if ($m != '') { |
---|
70 | $m = ''.intval($m); |
---|
71 | $where .= ' AND YEAR(post_date)='.substr($m,0,4); |
---|
72 | if (strlen($m)>5) |
---|
73 | $where .= ' AND MONTH(post_date)='.substr($m,4,2); |
---|
74 | if (strlen($m)>7) |
---|
75 | $where .= ' AND DAYOFMONTH(post_date)='.substr($m,6,2); |
---|
76 | if (strlen($m)>9) |
---|
77 | $where .= ' AND HOUR(post_date)='.substr($m,8,2); |
---|
78 | if (strlen($m)>11) |
---|
79 | $where .= ' AND MINUTE(post_date)='.substr($m,10,2); |
---|
80 | if (strlen($m)>13) |
---|
81 | $where .= ' AND SECOND(post_date)='.substr($m,12,2); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | if ($w != '') { |
---|
86 | $w = ''.intval($w); |
---|
87 | $where .= ' AND WEEK(post_date,1)='.$w; |
---|
88 | } |
---|
89 | |
---|
90 | // if a post number is specified, load that post |
---|
91 | if (($p != '') && ($p != 'all')) { |
---|
92 | $p = intval($p); |
---|
93 | $where = ' AND ID = '.$p; |
---|
94 | } |
---|
95 | |
---|
96 | // if a search pattern is specified, load the posts that match |
---|
97 | if (!empty($s)) { |
---|
98 | $s = addslashes_gpc($s); |
---|
99 | $search = ' AND ('; |
---|
100 | // puts spaces instead of commas |
---|
101 | $s = preg_replace('/, +/', '', $s); |
---|
102 | $s = str_replace(',', ' ', $s); |
---|
103 | $s = str_replace('"', ' ', $s); |
---|
104 | $s = trim($s); |
---|
105 | if ($exact) { |
---|
106 | $n = ''; |
---|
107 | } else { |
---|
108 | $n = '%'; |
---|
109 | } |
---|
110 | if (!$sentence) { |
---|
111 | $s_array = explode(' ',$s); |
---|
112 | $search .= '(post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$s_array[0].'\')'; |
---|
113 | for ( $i = 1; $i < count($s_array); $i = $i + 1) { |
---|
114 | $search .= ' OR (post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\')'; |
---|
115 | } |
---|
116 | $search .= ' OR (post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\')'; |
---|
117 | $search .= ')'; |
---|
118 | } else { |
---|
119 | $search = ' AND ((post_title LIKE \''.$n.$s.$n.'\') OR (post_content LIKE \''.$n.$s.$n.'\'))'; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | // category stuff |
---|
124 | if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) { |
---|
125 | $whichcat=''; |
---|
126 | } else { |
---|
127 | $cat = ''.urldecode($cat).''; |
---|
128 | $cat = addslashes_gpc($cat); |
---|
129 | if (stristr($cat,'-')) { |
---|
130 | $eq = '!='; |
---|
131 | $andor = 'AND'; |
---|
132 | $cat = explode('-',$cat); |
---|
133 | $cat = $cat[1]; |
---|
134 | } else { |
---|
135 | $eq = '='; |
---|
136 | $andor = 'OR'; |
---|
137 | } |
---|
138 | $cat_array = explode(' ',$cat); |
---|
139 | $whichcat .= ' AND (post_category '.$eq.' '.$cat_array[0]; |
---|
140 | for ($i = 1; $i < (count($cat_array)); $i = $i + 1) { |
---|
141 | $whichcat .= ' '.$andor.' post_category '.$eq.' '.$cat_array[$i]; |
---|
142 | } |
---|
143 | $whichcat .= ')'; |
---|
144 | } |
---|
145 | // author stuff |
---|
146 | if ((empty($author)) || ($author == 'all') || ($cat == '0')) { |
---|
147 | $whichauthor=''; |
---|
148 | } elseif (intval($author)) { |
---|
149 | $author = intval($author); |
---|
150 | if (stristr($author, '-')) { |
---|
151 | $eq = '!='; |
---|
152 | $andor = 'AND'; |
---|
153 | $author = explode('-', $author); |
---|
154 | $author = $author[1]; |
---|
155 | } else { |
---|
156 | $eq = '='; |
---|
157 | $andor = 'OR'; |
---|
158 | } |
---|
159 | $author_array = explode(' ', $author); |
---|
160 | $whichauthor .= ' AND post_author '.$eq.' '.$author_array[0]; |
---|
161 | for ($i = 1; $i < (count($author_array)); $i = $i + 1) { |
---|
162 | $whichauthor .= ' '.$andor.' post_author '.$eq.' '.$author_array[$i]; |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | $where .= $search.$whichcat.$whichauthor; |
---|
167 | |
---|
168 | if ((empty($order)) || ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) { |
---|
169 | $order='DESC'; |
---|
170 | } |
---|
171 | |
---|
172 | // order by stuff |
---|
173 | if (empty($orderby)) { |
---|
174 | $orderby='date '.$order; |
---|
175 | } else { |
---|
176 | $orderby = urldecode($orderby); |
---|
177 | $orderby = addslashes_gpc($orderby); |
---|
178 | $orderby_array = explode(' ',$orderby); |
---|
179 | $orderby = $orderby_array[0].' '.$order; |
---|
180 | if (count($orderby_array)>1) { |
---|
181 | for ($i = 1; $i < (count($orderby_array)); $i = $i + 1) { |
---|
182 | $orderby .= ',post_'.$orderby_array[$i].' '.$order; |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | if ((!$whichcat) && (!$m) && (!$p) && (!$w) && (!$s) && empty($poststart) && empty($postend)) { |
---|
188 | if ($what_to_show == 'posts') { |
---|
189 | $limits = ' LIMIT '.$posts_per_page; |
---|
190 | } elseif ($what_to_show == 'days') { |
---|
191 | $lastpostdate = get_lastpostdate(); |
---|
192 | $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate); |
---|
193 | $lastpostdate = mysql2date('U',$lastpostdate); |
---|
194 | $otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($posts_per_page-1) * 86400))); |
---|
195 | $where .= ' AND post_date > \''.$otherdate.'\''; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | if ( !empty($postend) && ($postend > $poststart) && (!$m) &&(!$w) && (!$whichcat) && (!$s) && (!$p)) { |
---|
200 | if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) { |
---|
201 | $poststart = intval($poststart); |
---|
202 | $postend = intval($postend); |
---|
203 | $posts = $postend - $poststart; |
---|
204 | $limits = ' LIMIT '.$poststart.','.$posts; |
---|
205 | } elseif ($what_to_show == 'days') { |
---|
206 | $poststart = intval($poststart); |
---|
207 | $postend = intval($postend); |
---|
208 | $posts = $postend - $poststart; |
---|
209 | $lastpostdate = get_lastpostdate(); |
---|
210 | $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate); |
---|
211 | $lastpostdate = mysql2date('U',$lastpostdate); |
---|
212 | $startdate = date('Y-m-d H:i:s', ($lastpostdate - (($poststart -1) * 86400))); |
---|
213 | $otherdate = date('Y-m-d H:i:s', ($lastpostdate - (($postend -1) * 86400))); |
---|
214 | $where .= ' AND post_date > \''.$otherdate.'\' AND post_date < \''.$startdate.'\''; |
---|
215 | } |
---|
216 | } else { |
---|
217 | if (($what_to_show == 'paged') && (!$p) && (!$more)) { |
---|
218 | if ($pagenow != 'b2edit.php') { |
---|
219 | $pgstrt = ''; |
---|
220 | if ($paged) { |
---|
221 | $pgstrt = (intval($paged) -1) * $posts_per_page . ', '; |
---|
222 | } |
---|
223 | $limits = 'LIMIT '.$pgstrt.$posts_per_page; |
---|
224 | } else { |
---|
225 | if (($m) || ($p) || ($w) || ($s) || ($whichcat)) { |
---|
226 | $limits = ''; |
---|
227 | } else { |
---|
228 | $pgstrt = ''; |
---|
229 | if ($paged) { |
---|
230 | $pgstrt = (intval($paged) -1) * $posts_per_page . ', '; |
---|
231 | } |
---|
232 | $limits = 'LIMIT '.$pgstrt.$posts_per_page; |
---|
233 | } |
---|
234 | } |
---|
235 | } |
---|
236 | elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author)) { |
---|
237 | $limits = ''; |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | if ($p == 'all') { |
---|
242 | $where = ''; |
---|
243 | } |
---|
244 | |
---|
245 | $now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600))); |
---|
246 | |
---|
247 | if ($pagenow != 'b2edit.php') { |
---|
248 | if ((empty($poststart)) || (empty($postend)) || !($postend > $poststart)) { |
---|
249 | $where .= ' AND post_date <= \''.$now.'\''; |
---|
250 | } |
---|
251 | $where .= ' AND post_category > 0'; |
---|
252 | $distinct = 'DISTINCT'; |
---|
253 | if ($use_gzipcompression) { |
---|
254 | // gzipping the output of the script |
---|
255 | gzip_compression(); |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | $request = " SELECT $distinct * FROM $tableposts WHERE 1=1".$where." ORDER BY post_$orderby $limits"; |
---|
260 | |
---|
261 | if ($preview) { |
---|
262 | $request = 'SELECT 1-1'; // dummy mysql query for the preview |
---|
263 | // little funky fix for IEwin, rawk on that code |
---|
264 | $is_winIE = ((preg_match('/MSIE/',$HTTP_USER_AGENT)) && (preg_match('/Win/',$HTTP_USER_AGENT))); |
---|
265 | if (($is_winIE) && (!isset($IEWin_bookmarklet_fix))) { |
---|
266 | $preview_content = preg_replace('/\%u([0-9A-F]{4,4})/e', "'&#'.base_convert('\\1',16,10).';'", $preview_content); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | //echo $request; |
---|
271 | $result = mysql_query($request); |
---|
272 | ?> |
---|