| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
class WP_Query { |
|---|
| 4 |
var $query; |
|---|
| 5 |
var $query_vars; |
|---|
| 6 |
var $queried_object; |
|---|
| 7 |
var $queried_object_id; |
|---|
| 8 |
var $request; |
|---|
| 9 |
|
|---|
| 10 |
var $posts; |
|---|
| 11 |
var $post_count = 0; |
|---|
| 12 |
var $current_post = -1; |
|---|
| 13 |
var $in_the_loop = false; |
|---|
| 14 |
var $post; |
|---|
| 15 |
|
|---|
| 16 |
var $is_single = false; |
|---|
| 17 |
var $is_preview = false; |
|---|
| 18 |
var $is_page = false; |
|---|
| 19 |
var $is_archive = false; |
|---|
| 20 |
var $is_date = false; |
|---|
| 21 |
var $is_year = false; |
|---|
| 22 |
var $is_month = false; |
|---|
| 23 |
var $is_day = false; |
|---|
| 24 |
var $is_time = false; |
|---|
| 25 |
var $is_author = false; |
|---|
| 26 |
var $is_category = false; |
|---|
| 27 |
var $is_search = false; |
|---|
| 28 |
var $is_feed = false; |
|---|
| 29 |
var $is_trackback = false; |
|---|
| 30 |
var $is_home = false; |
|---|
| 31 |
var $is_404 = false; |
|---|
| 32 |
var $is_comments_popup = false; |
|---|
| 33 |
var $is_admin = false; |
|---|
| 34 |
var $is_attachment = false; |
|---|
| 35 |
|
|---|
| 36 |
function init_query_flags() { |
|---|
| 37 |
$this->is_single = false; |
|---|
| 38 |
$this->is_page = false; |
|---|
| 39 |
$this->is_archive = false; |
|---|
| 40 |
$this->is_date = false; |
|---|
| 41 |
$this->is_year = false; |
|---|
| 42 |
$this->is_month = false; |
|---|
| 43 |
$this->is_day = false; |
|---|
| 44 |
$this->is_time = false; |
|---|
| 45 |
$this->is_author = false; |
|---|
| 46 |
$this->is_category = false; |
|---|
| 47 |
$this->is_search = false; |
|---|
| 48 |
$this->is_feed = false; |
|---|
| 49 |
$this->is_trackback = false; |
|---|
| 50 |
$this->is_home = false; |
|---|
| 51 |
$this->is_404 = false; |
|---|
| 52 |
$this->is_paged = false; |
|---|
| 53 |
$this->is_admin = false; |
|---|
| 54 |
$this->is_attachment = false; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
function init () { |
|---|
| 58 |
unset($this->posts); |
|---|
| 59 |
unset($this->query); |
|---|
| 60 |
unset($this->query_vars); |
|---|
| 61 |
unset($this->queried_object); |
|---|
| 62 |
unset($this->queried_object_id); |
|---|
| 63 |
$this->post_count = 0; |
|---|
| 64 |
$this->current_post = -1; |
|---|
| 65 |
$this->in_the_loop = false; |
|---|
| 66 |
|
|---|
| 67 |
$this->init_query_flags(); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
function parse_query_vars() { |
|---|
| 72 |
$this->parse_query(''); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
function parse_query ($query) { |
|---|
| 77 |
if ( !empty($query) || !isset($this->query) ) { |
|---|
| 78 |
$this->init(); |
|---|
| 79 |
parse_str($query, $qv); |
|---|
| 80 |
$this->query = $query; |
|---|
| 81 |
$this->query_vars = $qv; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
if ('404' == $qv['error']) { |
|---|
| 85 |
$this->is_404 = true; |
|---|
| 86 |
if ( !empty($query) ) { |
|---|
| 87 |
do_action('parse_query', array(&$this)); |
|---|
| 88 |
} |
|---|
| 89 |
return; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
$qv['m'] = (int) $qv['m']; |
|---|
| 93 |
$qv['p'] = (int) $qv['p']; |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
if ( '' != $qv['subpost'] ) |
|---|
| 97 |
$qv['attachment'] = $qv['subpost']; |
|---|
| 98 |
if ( '' != $qv['subpost_id'] ) |
|---|
| 99 |
$qv['attachment_id'] = $qv['subpost_id']; |
|---|
| 100 |
|
|---|
| 101 |
if ( ('' != $qv['attachment']) || (int) $qv['attachment_id'] ) { |
|---|
| 102 |
$this->is_single = true; |
|---|
| 103 |
$this->is_attachment = true; |
|---|
| 104 |
} elseif ('' != $qv['name']) { |
|---|
| 105 |
$this->is_single = true; |
|---|
| 106 |
} elseif ( $qv['p'] ) { |
|---|
| 107 |
$this->is_single = true; |
|---|
| 108 |
} elseif (('' != $qv['hour']) && ('' != $qv['minute']) &&('' != $qv['second']) && ('' != $qv['year']) && ('' != $qv['monthnum']) && ('' != $qv['day'])) { |
|---|
| 109 |
|
|---|
| 110 |
// post is being queried. |
|---|
| 111 |
$this->is_single = true; |
|---|
| 112 |
} elseif ('' != $qv['static'] || '' != $qv['pagename'] || (int) $qv['page_id']) { |
|---|
| 113 |
$this->is_page = true; |
|---|
| 114 |
$this->is_single = false; |
|---|
| 115 |
} elseif (!empty($qv['s'])) { |
|---|
| 116 |
$this->is_search = true; |
|---|
| 117 |
switch ($qv['show_post_type']) { |
|---|
| 118 |
case 'page' : |
|---|
| 119 |
$this->is_page = true; |
|---|
| 120 |
break; |
|---|
| 121 |
case 'attachment' : |
|---|
| 122 |
$this->is_attachment = true; |
|---|
| 123 |
break; |
|---|
| 124 |
} |
|---|
| 125 |
} else { |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
if ( (int) $qv['second']) { |
|---|
| 129 |
$this->is_time = true; |
|---|
| 130 |
$this->is_date = true; |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
if ( (int) $qv['minute']) { |
|---|
| 134 |
$this->is_time = true; |
|---|
| 135 |
$this->is_date = true; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
if ( (int) $qv['hour']) { |
|---|
| 139 |
$this->is_time = true; |
|---|
| 140 |
$this->is_date = true; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
if ( (int) $qv['day']) { |
|---|
| 144 |
if (! $this->is_date) { |
|---|
| 145 |
$this->is_day = true; |
|---|
| 146 |
$this->is_date = true; |
|---|
| 147 |
} |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
if ( (int) $qv['monthnum']) { |
|---|
| 151 |
if (! $this->is_date) { |
|---|
| 152 |
$this->is_month = true; |
|---|
| 153 |
$this->is_date = true; |
|---|
| 154 |
} |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
if ( (int) $qv['year']) { |
|---|
| 158 |
if (! $this->is_date) { |
|---|
| 159 |
$this->is_year = true; |
|---|
| 160 |
$this->is_date = true; |
|---|
| 161 |
} |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
if ( (int) $qv['m']) { |
|---|
| 165 |
$this->is_date = true; |
|---|
| 166 |
if (strlen($qv['m']) > 9) { |
|---|
| 167 |
$this->is_time = true; |
|---|
| 168 |
} else if (strlen($qv['m']) > 7) { |
|---|
| 169 |
$this->is_day = true; |
|---|
| 170 |
} else if (strlen($qv['m']) > 5) { |
|---|
| 171 |
$this->is_month = true; |
|---|
| 172 |
} else { |
|---|
| 173 |
$this->is_year = true; |
|---|
| 174 |
} |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
if ('' != $qv['w']) { |
|---|
| 178 |
$this->is_date = true; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
if (empty($qv['cat']) || ($qv['cat'] == '0')) { |
|---|
| 182 |
$this->is_category = false; |
|---|
| 183 |
} else { |
|---|
| 184 |
if (stristr($qv['cat'],'-')) { |
|---|
| 185 |
$this->is_category = false; |
|---|
| 186 |
} else { |
|---|
| 187 |
$this->is_category = true; |
|---|
| 188 |
} |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
if ('' != $qv['category_name']) { |
|---|
| 192 |
$this->is_category = true; |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
if ((empty($qv['author'])) || ($qv['author'] == '0')) { |
|---|
| 196 |
$this->is_author = false; |
|---|
| 197 |
} else { |
|---|
| 198 |
$this->is_author = true; |
|---|
| 199 |
} |
|---|
| 200 |
|
|---|
| 201 |
if ('' != $qv['author_name']) { |
|---|
| 202 |
$this->is_author = true; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
if ( ($this->is_date || $this->is_author || $this->is_category)) { |
|---|
| 206 |
$this->is_archive = true; |
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
if ( 'attachment' == $qv['show_post_type'] ) { |
|---|
| 210 |
$this->is_attachment = true; |
|---|
| 211 |
} |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
if ('' != $qv['feed']) { |
|---|
| 215 |
$this->is_feed = true; |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
if ('' != $qv['tb']) { |
|---|
| 219 |
$this->is_trackback = true; |
|---|
| 220 |
} |
|---|
| 221 |
|
|---|
| 222 |
if ('' != $qv['paged']) { |
|---|
| 223 |
$this->is_paged = true; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
if ('' != $qv['comments_popup']) { |
|---|
| 227 |
$this->is_comments_popup = true; |
|---|
| 228 |
} |
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
if ('' != $qv['preview']) { |
|---|
| 232 |
$this->is_preview = true; |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
if (strstr($_SERVER['PHP_SELF'], 'wp-admin/')) { |
|---|
| 236 |
$this->is_admin = true; |
|---|
| 237 |
} |
|---|
| 238 |
|
|---|
| 239 |
if ( ! ($this->is_attachment || $this->is_archive || $this->is_single || $this->is_page || $this->is_search || $this->is_feed || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_comments_popup)) { |
|---|
| 240 |
$this->is_home = true; |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
if ( !empty($query) ) { |
|---|
| 244 |
do_action('parse_query', array(&$this)); |
|---|
| 245 |
} |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|
| 248 |
function set_404() { |
|---|
| 249 |
$is_feed = $this->is_feed; |
|---|
| 250 |
|
|---|
| 251 |
$this->init_query_flags(); |
|---|
| 252 |
$this->is_404 = true; |
|---|
| 253 |
|
|---|
| 254 |
$this->is_feed = $is_feed; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
function get($query_var) { |
|---|
| 258 |
if (isset($this->query_vars[$query_var])) { |
|---|
| 259 |
return $this->query_vars[$query_var]; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
return ''; |
|---|
| 263 |
} |
|---|
| 264 |
|
|---|
| 265 |
function set($query_var, $value) { |
|---|
| 266 |
$this->query_vars[$query_var] = $value; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
function &get_posts() { |
|---|
| 270 |
global $wpdb, $pagenow, $user_ID; |
|---|
| 271 |
|
|---|
| 272 |
do_action('pre_get_posts', array(&$this)); |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
$q = $this->query_vars; |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
$whichcat = ''; |
|---|
| 279 |
$whichauthor = ''; |
|---|
| 280 |
$whichpage = ''; |
|---|
| 281 |
$result = ''; |
|---|
| 282 |
$where = ''; |
|---|
| 283 |
$limits = ''; |
|---|
| 284 |
$distinct = ''; |
|---|
| 285 |
$join = ''; |
|---|
| 286 |
|
|---|
| 287 |
if ( !isset($q['posts_per_page']) || $q['posts_per_page'] == 0 ) |
|---|
| 288 |
$q['posts_per_page'] = get_settings('posts_per_page'); |
|---|
| 289 |
if ( !isset($q['what_to_show']) ) |
|---|
| 290 |
$q['what_to_show'] = get_settings('what_to_show'); |
|---|
| 291 |
if ( isset($q['showposts']) && $q['showposts'] ) { |
|---|
| 292 |
$q['showposts'] = (int) $q['showposts']; |
|---|
| 293 |
$q['posts_per_page'] = $q['showposts']; |
|---|
| 294 |
} |
|---|
| 295 |
if ( (isset($q['posts_per_archive_page']) && $q['posts_per_archive_page'] != 0) && ($this->is_archive || $this->is_search) ) |
|---|
| 296 |
$q['posts_per_page'] = $q['posts_per_archive_page']; |
|---|
| 297 |
if ( !isset($q['nopaging']) ) { |
|---|
| 298 |
if ($q['posts_per_page'] == -1) { |
|---|
| 299 |
$q['nopaging'] = true; |
|---|
| 300 |
} else { |
|---|
| 301 |
$q['nopaging'] = false; |
|---|
| 302 |
} |
|---|
| 303 |
} |
|---|
| 304 |
if ( $this->is_feed ) { |
|---|
| 305 |
$q['posts_per_page'] = get_settings('posts_per_rss'); |
|---|
| 306 |
$q['what_to_show'] = 'posts'; |
|---|
| 307 |
} |
|---|
| 308 |
|
|---|
| 309 |
if (isset($q['page'])) { |
|---|
| 310 |
$q['page'] = trim($q['page'], '/'); |
|---|
| 311 |
$q['page'] = (int) $q['page']; |
|---|
| 312 |
$q['page'] = abs($q['page']); |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
$add_hours = intval(get_settings('gmt_offset')); |
|---|
| 316 |
$add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours)); |
|---|
| 317 |
$wp_posts_post_date_field = "post_date"; |
|---|
| 318 |
|
|---|
| 319 |
// If a month is specified in the querystring, load that month |
|---|
| 320 |
if ( (int) $q['m'] ) { |
|---|
| 321 |
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); |
|---|
| 322 |
$where .= ' AND YEAR(post_date)=' . substr($q['m'], 0, 4); |
|---|
| 323 |
if (strlen($q['m'])>5) |
|---|
| 324 |
$where .= ' AND MONTH(post_date)=' . substr($q['m'], 4, 2); |
|---|
| 325 |
if (strlen($q['m'])>7) |
|---|
| 326 |
$where .= ' AND DAYOFMONTH(post_date)=' . substr($q['m'], 6, 2); |
|---|
| 327 |
if (strlen($q['m'])>9) |
|---|
| 328 |
$where .= ' AND HOUR(post_date)=' . substr($q['m'], 8, 2); |
|---|
| 329 |
if (strlen($q['m'])>11) |
|---|
| 330 |
$where .= ' AND MINUTE(post_date)=' . substr($q['m'], 10, 2); |
|---|
| 331 |
if (strlen($q['m'])>13) |
|---|
| 332 |
$where .= ' AND SECOND(post_date)=' . substr($q['m'], 12, 2); |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
if ( (int) $q['hour'] ) { |
|---|
| 336 |
$q['hour'] = '' . intval($q['hour']); |
|---|
| 337 |
$where .= " AND HOUR(post_date)='" . $q['hour'] . "'"; |
|---|
| 338 |
} |
|---|
| 339 |
|
|---|
| 340 |
if ( (int) $q['minute'] ) { |
|---|
| 341 |
$q['minute'] = '' . intval($q['minute']); |
|---|
| 342 |
$where .= " AND MINUTE(post_date)='" . $q['minute'] . "'"; |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
if ( (int) $q['second'] ) { |
|---|
| 346 |
$q['second'] = '' . intval($q['second']); |
|---|
| 347 |
$where .= " AND SECOND(post_date)='" . $q['second'] . "'"; |
|---|
| 348 |
} |
|---|
| 349 |
|
|---|
| 350 |
if ( (int) $q['year'] ) { |
|---|
| 351 |
$q['year'] = '' . intval($q['year']); |
|---|
| 352 |
$where .= " AND YEAR(post_date)='" . $q['year'] . "'"; |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
if ( (int) $q['monthnum'] ) { |
|---|
| 356 |
$q['monthnum'] = '' . intval($q['monthnum']); |
|---|
| 357 |
$where .= " AND MONTH(post_date)='" . $q['monthnum'] . "'"; |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
if ( (int) $q['day'] ) { |
|---|
| 361 |
$q['day'] = '' . intval($q['day']); |
|---|
| 362 |
$where .= " AND DAYOFMONTH(post_date)='" . $q['day'] . "'"; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
if ( '' != $q['subpost'] ) |
|---|
| 367 |
$q['attachment'] = $q['subpost']; |
|---|
| 368 |
if ( '' != $q['subpost_id'] ) |
|---|
| 369 |
$q['attachment_id'] = $q['subpost_id']; |
|---|
| 370 |
|
|---|
| 371 |
if ('' != $q['name']) { |
|---|
| 372 |
$q['name'] = sanitize_title($q['name']); |
|---|
| 373 |
$where .= " AND post_name = '" . $q['name'] . "'"; |
|---|
| 374 |
} else if ('' != $q['pagename']) { |
|---|
| 375 |
$q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); |
|---|
| 376 |
$page_paths = '/' . trim($q['pagename'], '/'); |
|---|
| 377 |
$q['pagename'] = sanitize_title(basename($page_paths)); |
|---|
| 378 |
$q['name'] = $q['pagename']; |
|---|
| 379 |
$page_paths = explode('/', $page_paths); |
|---|
| 380 |
foreach($page_paths as $pathdir) |
|---|
| 381 |
$page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); |
|---|
| 382 |
|
|---|
| 383 |
$all_page_ids = get_all_page_ids(); |
|---|
| 384 |
$reqpage = 0; |
|---|
| 385 |
if (is_array($all_page_ids)) { foreach ( $all_page_ids as $page_id ) { |
|---|
| 386 |
$page = get_page($page_id); |
|---|
| 387 |
if ( $page->fullpath == $page_path ) { |
|---|
| 388 |
$reqpage = $page_id; |
|---|
| 389 |
break; |
|---|
| 390 |
} |
|---|
| 391 |
} } |
|---|
| 392 |
|
|---|
| 393 |
$where .= " AND (ID = '$reqpage')"; |
|---|
| 394 |
} elseif ('' != $q['attachment']) { |
|---|
| 395 |
$q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); |
|---|
| 396 |
$attach_paths = '/' . trim($q['attachment'], '/'); |
|---|
| 397 |
$q['attachment'] = sanitize_title(basename($attach_paths)); |
|---|
| 398 |
$q['name'] = $q['attachment']; |
|---|
| 399 |
$where .= " AND post_name = '" . $q['attachment'] . "'"; |
|---|
| 400 |
} |
|---|
| 401 |
|
|---|
| 402 |
if ( (int) $q['w'] ) { |
|---|
| 403 |
$q['w'] = ''.intval($q['w']); |
|---|
| 404 |
$where .= " AND WEEK(post_date, 1)='" . $q['w'] . "'"; |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
if ( intval($q['comments_popup']) ) |
|---|
| 408 |
$q['p'] = intval($q['comments_popup']); |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
if ( ($q['attachment_id'] != '') && (intval($q['attachment_id']) != 0) ) |
|---|
| 412 |
$q['p'] = (int) $q['attachment_id']; |
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
if (($q['p'] != '') && intval($q['p']) != 0) { |
|---|
| 416 |
$q['p'] = (int) $q['p']; |
|---|
| 417 |
$where = ' AND ID = ' . $q['p']; |
|---|
| 418 |
} |
|---|
| 419 |
|
|---|
| 420 |
if (($q['page_id'] != '') && (intval( |
|---|