raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Holds Most of the WordPress classes.
mp-wp_genesis 4 *
mp-wp_genesis 5 * Some of the other classes are contained in other files. For example, the
mp-wp_genesis 6 * WordPress cache is in cache.php and the WordPress roles API is in
mp-wp_genesis 7 * capabilities.php. The third party libraries are contained in their own
mp-wp_genesis 8 * separate files.
mp-wp_genesis 9 *
mp-wp_genesis 10 * @package WordPress
mp-wp_genesis 11 */
mp-wp_genesis 12
mp-wp_genesis 13 /**
mp-wp_genesis 14 * WordPress environment setup class.
mp-wp_genesis 15 *
mp-wp_genesis 16 * @package WordPress
mp-wp_genesis 17 * @since 2.0.0
mp-wp_genesis 18 */
mp-wp_genesis 19 class WP {
mp-wp_genesis 20 /**
mp-wp_genesis 21 * Public query variables.
mp-wp_genesis 22 *
mp-wp_genesis 23 * Long list of public query variables.
mp-wp_genesis 24 *
mp-wp_genesis 25 * @since 2.0.0
mp-wp_genesis 26 * @access public
mp-wp_genesis 27 * @var array
mp-wp_genesis 28 */
mp-wp_genesis 29 var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
mp-wp_genesis 30
mp-wp_genesis 31 /**
mp-wp_genesis 32 * Private query variables.
mp-wp_genesis 33 *
mp-wp_genesis 34 * Long list of private query variables.
mp-wp_genesis 35 *
mp-wp_genesis 36 * @since 2.0.0
mp-wp_genesis 37 * @var array
mp-wp_genesis 38 */
mp-wp_genesis 39 var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
mp-wp_genesis 40
mp-wp_genesis 41 /**
mp-wp_genesis 42 * Extra query variables set by the user.
mp-wp_genesis 43 *
mp-wp_genesis 44 * @since 2.1.0
mp-wp_genesis 45 * @var array
mp-wp_genesis 46 */
mp-wp_genesis 47 var $extra_query_vars = array();
mp-wp_genesis 48
mp-wp_genesis 49 /**
mp-wp_genesis 50 * Query variables for setting up the WordPress Query Loop.
mp-wp_genesis 51 *
mp-wp_genesis 52 * @since 2.0.0
mp-wp_genesis 53 * @var array
mp-wp_genesis 54 */
mp-wp_genesis 55 var $query_vars;
mp-wp_genesis 56
mp-wp_genesis 57 /**
mp-wp_genesis 58 * String parsed to set the query variables.
mp-wp_genesis 59 *
mp-wp_genesis 60 * @since 2.0.0
mp-wp_genesis 61 * @var string
mp-wp_genesis 62 */
mp-wp_genesis 63 var $query_string;
mp-wp_genesis 64
mp-wp_genesis 65 /**
mp-wp_genesis 66 * Permalink or requested URI.
mp-wp_genesis 67 *
mp-wp_genesis 68 * @since 2.0.0
mp-wp_genesis 69 * @var string
mp-wp_genesis 70 */
mp-wp_genesis 71 var $request;
mp-wp_genesis 72
mp-wp_genesis 73 /**
mp-wp_genesis 74 * Rewrite rule the request matched.
mp-wp_genesis 75 *
mp-wp_genesis 76 * @since 2.0.0
mp-wp_genesis 77 * @var string
mp-wp_genesis 78 */
mp-wp_genesis 79 var $matched_rule;
mp-wp_genesis 80
mp-wp_genesis 81 /**
mp-wp_genesis 82 * Rewrite query the request matched.
mp-wp_genesis 83 *
mp-wp_genesis 84 * @since 2.0.0
mp-wp_genesis 85 * @var string
mp-wp_genesis 86 */
mp-wp_genesis 87 var $matched_query;
mp-wp_genesis 88
mp-wp_genesis 89 /**
mp-wp_genesis 90 * Whether already did the permalink.
mp-wp_genesis 91 *
mp-wp_genesis 92 * @since 2.0.0
mp-wp_genesis 93 * @var bool
mp-wp_genesis 94 */
mp-wp_genesis 95 var $did_permalink = false;
mp-wp_genesis 96
mp-wp_genesis 97 /**
mp-wp_genesis 98 * Add name to list of public query variables.
mp-wp_genesis 99 *
mp-wp_genesis 100 * @since 2.1.0
mp-wp_genesis 101 *
mp-wp_genesis 102 * @param string $qv Query variable name.
mp-wp_genesis 103 */
mp-wp_genesis 104 function add_query_var($qv) {
mp-wp_genesis 105 if ( !in_array($qv, $this->public_query_vars) )
mp-wp_genesis 106 $this->public_query_vars[] = $qv;
mp-wp_genesis 107 }
mp-wp_genesis 108
mp-wp_genesis 109 /**
mp-wp_genesis 110 * Set the value of a query variable.
mp-wp_genesis 111 *
mp-wp_genesis 112 * @since 2.3.0
mp-wp_genesis 113 *
mp-wp_genesis 114 * @param string $key Query variable name.
mp-wp_genesis 115 * @param mixed $value Query variable value.
mp-wp_genesis 116 */
mp-wp_genesis 117 function set_query_var($key, $value) {
mp-wp_genesis 118 $this->query_vars[$key] = $value;
mp-wp_genesis 119 }
mp-wp_genesis 120
mp-wp_genesis 121 /**
mp-wp_genesis 122 * Parse request to find correct WordPress query.
mp-wp_genesis 123 *
mp-wp_genesis 124 * Sets up the query variables based on the request. There are also many
mp-wp_genesis 125 * filters and actions that can be used to further manipulate the result.
mp-wp_genesis 126 *
mp-wp_genesis 127 * @since 2.0.0
mp-wp_genesis 128 *
mp-wp_genesis 129 * @param array|string $extra_query_vars Set the extra query variables.
mp-wp_genesis 130 */
mp-wp_genesis 131 function parse_request($extra_query_vars = '') {
mp-wp_genesis 132 global $wp_rewrite;
mp-wp_genesis 133
mp-wp_genesis 134 $this->query_vars = array();
mp-wp_genesis 135 $taxonomy_query_vars = array();
mp-wp_genesis 136
mp-wp_genesis 137 if ( is_array($extra_query_vars) )
mp-wp_genesis 138 $this->extra_query_vars = & $extra_query_vars;
mp-wp_genesis 139 else if (! empty($extra_query_vars))
mp-wp_genesis 140 parse_str($extra_query_vars, $this->extra_query_vars);
mp-wp_genesis 141
mp-wp_genesis 142 // Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
mp-wp_genesis 143
mp-wp_genesis 144 // Fetch the rewrite rules.
mp-wp_genesis 145 $rewrite = $wp_rewrite->wp_rewrite_rules();
mp-wp_genesis 146
mp-wp_genesis 147 if (! empty($rewrite)) {
mp-wp_genesis 148 // If we match a rewrite rule, this will be cleared.
mp-wp_genesis 149 $error = '404';
mp-wp_genesis 150 $this->did_permalink = true;
mp-wp_genesis 151
mp-wp_genesis 152 if ( isset($_SERVER['PATH_INFO']) )
mp-wp_genesis 153 $pathinfo = $_SERVER['PATH_INFO'];
mp-wp_genesis 154 else
mp-wp_genesis 155 $pathinfo = '';
mp-wp_genesis 156 $pathinfo_array = explode('?', $pathinfo);
mp-wp_genesis 157 $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
mp-wp_genesis 158 $req_uri = $_SERVER['REQUEST_URI'];
mp-wp_genesis 159 $req_uri_array = explode('?', $req_uri);
mp-wp_genesis 160 $req_uri = $req_uri_array[0];
mp-wp_genesis 161 $self = $_SERVER['PHP_SELF'];
mp-wp_genesis 162 $home_path = parse_url(get_option('home'));
mp-wp_genesis 163 if ( isset($home_path['path']) )
mp-wp_genesis 164 $home_path = $home_path['path'];
mp-wp_genesis 165 else
mp-wp_genesis 166 $home_path = '';
mp-wp_genesis 167 $home_path = trim($home_path, '/');
mp-wp_genesis 168
mp-wp_genesis 169 // Trim path info from the end and the leading home path from the
mp-wp_genesis 170 // front. For path info requests, this leaves us with the requesting
mp-wp_genesis 171 // filename, if any. For 404 requests, this leaves us with the
mp-wp_genesis 172 // requested permalink.
mp-wp_genesis 173 $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
mp-wp_genesis 174 $req_uri = trim($req_uri, '/');
mp-wp_genesis 175 $req_uri = preg_replace("|^$home_path|", '', $req_uri);
mp-wp_genesis 176 $req_uri = trim($req_uri, '/');
mp-wp_genesis 177 $pathinfo = trim($pathinfo, '/');
mp-wp_genesis 178 $pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
mp-wp_genesis 179 $pathinfo = trim($pathinfo, '/');
mp-wp_genesis 180 $self = trim($self, '/');
mp-wp_genesis 181 $self = preg_replace("|^$home_path|", '', $self);
mp-wp_genesis 182 $self = trim($self, '/');
mp-wp_genesis 183
mp-wp_genesis 184 // The requested permalink is in $pathinfo for path info requests and
mp-wp_genesis 185 // $req_uri for other requests.
mp-wp_genesis 186 if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
mp-wp_genesis 187 $request = $pathinfo;
mp-wp_genesis 188 } else {
mp-wp_genesis 189 // If the request uri is the index, blank it out so that we don't try to match it against a rule.
mp-wp_genesis 190 if ( $req_uri == $wp_rewrite->index )
mp-wp_genesis 191 $req_uri = '';
mp-wp_genesis 192 $request = $req_uri;
mp-wp_genesis 193 }
mp-wp_genesis 194
mp-wp_genesis 195 $this->request = $request;
mp-wp_genesis 196
mp-wp_genesis 197 // Look for matches.
mp-wp_genesis 198 $request_match = $request;
mp-wp_genesis 199 foreach ( (array) $rewrite as $match => $query) {
mp-wp_genesis 200 // Don't try to match against AtomPub calls
mp-wp_genesis 201 if ( $req_uri == 'wp-app.php' )
mp-wp_genesis 202 break;
mp-wp_genesis 203
mp-wp_genesis 204 // If the requesting file is the anchor of the match, prepend it
mp-wp_genesis 205 // to the path info.
mp-wp_genesis 206 if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
mp-wp_genesis 207 $request_match = $req_uri . '/' . $request;
mp-wp_genesis 208 }
mp-wp_genesis 209
mp-wp_genesis 210 if (preg_match("!^$match!", $request_match, $matches) ||
mp-wp_genesis 211 preg_match("!^$match!", urldecode($request_match), $matches)) {
mp-wp_genesis 212 // Got a match.
mp-wp_genesis 213 $this->matched_rule = $match;
mp-wp_genesis 214
mp-wp_genesis 215 // Trim the query of everything up to the '?'.
mp-wp_genesis 216 $query = preg_replace("!^.+\?!", '', $query);
mp-wp_genesis 217
mp-wp_genesis 218 // Substitute the substring matches into the query.
mp-wp_genesis 219 eval("@\$query = \"" . addslashes($query) . "\";");
mp-wp_genesis 220
mp-wp_genesis 221 $this->matched_query = $query;
mp-wp_genesis 222
mp-wp_genesis 223 // Parse the query.
mp-wp_genesis 224 parse_str($query, $perma_query_vars);
mp-wp_genesis 225
mp-wp_genesis 226 // If we're processing a 404 request, clear the error var
mp-wp_genesis 227 // since we found something.
mp-wp_genesis 228 if (isset($_GET['error']))
mp-wp_genesis 229 unset($_GET['error']);
mp-wp_genesis 230
mp-wp_genesis 231 if (isset($error))
mp-wp_genesis 232 unset($error);
mp-wp_genesis 233
mp-wp_genesis 234 break;
mp-wp_genesis 235 }
mp-wp_genesis 236 }
mp-wp_genesis 237
mp-wp_genesis 238 // If req_uri is empty or if it is a request for ourself, unset error.
mp-wp_genesis 239 if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
mp-wp_genesis 240 if (isset($_GET['error']))
mp-wp_genesis 241 unset($_GET['error']);
mp-wp_genesis 242
mp-wp_genesis 243 if (isset($error))
mp-wp_genesis 244 unset($error);
mp-wp_genesis 245
mp-wp_genesis 246 if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false)
mp-wp_genesis 247 unset($perma_query_vars);
mp-wp_genesis 248
mp-wp_genesis 249 $this->did_permalink = false;
mp-wp_genesis 250 }
mp-wp_genesis 251 }
mp-wp_genesis 252
mp-wp_genesis 253 $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
mp-wp_genesis 254
mp-wp_genesis 255 foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t )
mp-wp_genesis 256 if ( isset($t->query_var) )
mp-wp_genesis 257 $taxonomy_query_vars[$t->query_var] = $taxonomy;
mp-wp_genesis 258
mp-wp_genesis 259 for ($i=0; $i<count($this->public_query_vars); $i += 1) {
mp-wp_genesis 260 $wpvar = $this->public_query_vars[$i];
mp-wp_genesis 261 if (isset($this->extra_query_vars[$wpvar]))
mp-wp_genesis 262 $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
mp-wp_genesis 263 elseif (isset($GLOBALS[$wpvar]))
mp-wp_genesis 264 $this->query_vars[$wpvar] = $GLOBALS[$wpvar];
mp-wp_genesis 265 elseif (!empty($_POST[$wpvar]))
mp-wp_genesis 266 $this->query_vars[$wpvar] = $_POST[$wpvar];
mp-wp_genesis 267 elseif (!empty($_GET[$wpvar]))
mp-wp_genesis 268 $this->query_vars[$wpvar] = $_GET[$wpvar];
mp-wp_genesis 269 elseif (!empty($perma_query_vars[$wpvar]))
mp-wp_genesis 270 $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
mp-wp_genesis 271
mp-wp_genesis 272 if ( !empty( $this->query_vars[$wpvar] ) ) {
mp-wp_genesis 273 $this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
mp-wp_genesis 274 if ( in_array( $wpvar, $taxonomy_query_vars ) ) {
mp-wp_genesis 275 $this->query_vars['taxonomy'] = $taxonomy_query_vars[$wpvar];
mp-wp_genesis 276 $this->query_vars['term'] = $this->query_vars[$wpvar];
mp-wp_genesis 277 }
mp-wp_genesis 278 }
mp-wp_genesis 279 }
mp-wp_genesis 280
mp-wp_genesis 281 foreach ( (array) $this->private_query_vars as $var) {
mp-wp_genesis 282 if (isset($this->extra_query_vars[$var]))
mp-wp_genesis 283 $this->query_vars[$var] = $this->extra_query_vars[$var];
mp-wp_genesis 284 elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
mp-wp_genesis 285 $this->query_vars[$var] = $GLOBALS[$var];
mp-wp_genesis 286 }
mp-wp_genesis 287
mp-wp_genesis 288 if ( isset($error) )
mp-wp_genesis 289 $this->query_vars['error'] = $error;
mp-wp_genesis 290
mp-wp_genesis 291 $this->query_vars = apply_filters('request', $this->query_vars);
mp-wp_genesis 292
mp-wp_genesis 293 do_action_ref_array('parse_request', array(&$this));
mp-wp_genesis 294 }
mp-wp_genesis 295
mp-wp_genesis 296 /**
mp-wp_genesis 297 * Send additional HTTP headers for caching, content type, etc.
mp-wp_genesis 298 *
mp-wp_genesis 299 * Sets the X-Pingback header, 404 status (if 404), Content-type. If showing
mp-wp_genesis 300 * a feed, it will also send last-modified, etag, and 304 status if needed.
mp-wp_genesis 301 *
mp-wp_genesis 302 * @since 2.0.0
mp-wp_genesis 303 */
mp-wp_genesis 304 function send_headers() {
mp-wp_genesis 305 @header('X-Pingback: '. get_bloginfo('pingback_url'));
mp-wp_genesis 306 if ( is_user_logged_in() )
mp-wp_genesis 307 nocache_headers();
mp-wp_genesis 308 if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
mp-wp_genesis 309 status_header( 404 );
mp-wp_genesis 310 if ( !is_user_logged_in() )
mp-wp_genesis 311 nocache_headers();
mp-wp_genesis 312 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
mp-wp_genesis 313 } else if ( empty($this->query_vars['feed']) ) {
mp-wp_genesis 314 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
mp-wp_genesis 315 } else {
mp-wp_genesis 316 // We're showing a feed, so WP is indeed the only thing that last changed
mp-wp_genesis 317 if ( !empty($this->query_vars['withcomments'])
mp-wp_genesis 318 || ( empty($this->query_vars['withoutcomments'])
mp-wp_genesis 319 && ( !empty($this->query_vars['p'])
mp-wp_genesis 320 || !empty($this->query_vars['name'])
mp-wp_genesis 321 || !empty($this->query_vars['page_id'])
mp-wp_genesis 322 || !empty($this->query_vars['pagename'])
mp-wp_genesis 323 || !empty($this->query_vars['attachment'])
mp-wp_genesis 324 || !empty($this->query_vars['attachment_id'])
mp-wp_genesis 325 )
mp-wp_genesis 326 )
mp-wp_genesis 327 )
mp-wp_genesis 328 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
mp-wp_genesis 329 else
mp-wp_genesis 330 $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
mp-wp_genesis 331 $wp_etag = '"' . md5($wp_last_modified) . '"';
mp-wp_genesis 332 @header("Last-Modified: $wp_last_modified");
mp-wp_genesis 333 @header("ETag: $wp_etag");
mp-wp_genesis 334
mp-wp_genesis 335 // Support for Conditional GET
mp-wp_genesis 336 if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
mp-wp_genesis 337 $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
mp-wp_genesis 338 else $client_etag = false;
mp-wp_genesis 339
mp-wp_genesis 340 $client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
mp-wp_genesis 341 // If string is empty, return 0. If not, attempt to parse into a timestamp
mp-wp_genesis 342 $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
mp-wp_genesis 343
mp-wp_genesis 344 // Make a timestamp for our most recent modification...
mp-wp_genesis 345 $wp_modified_timestamp = strtotime($wp_last_modified);
mp-wp_genesis 346
mp-wp_genesis 347 if ( ($client_last_modified && $client_etag) ?
mp-wp_genesis 348 (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
mp-wp_genesis 349 (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
mp-wp_genesis 350 status_header( 304 );
mp-wp_genesis 351 exit;
mp-wp_genesis 352 }
mp-wp_genesis 353 }
mp-wp_genesis 354
mp-wp_genesis 355 do_action_ref_array('send_headers', array(&$this));
mp-wp_genesis 356 }
mp-wp_genesis 357
mp-wp_genesis 358 /**
mp-wp_genesis 359 * Sets the query string property based off of the query variable property.
mp-wp_genesis 360 *
mp-wp_genesis 361 * The 'query_string' filter is deprecated, but still works. Plugins should
mp-wp_genesis 362 * use the 'request' filter instead.
mp-wp_genesis 363 *
mp-wp_genesis 364 * @since 2.0.0
mp-wp_genesis 365 */
mp-wp_genesis 366 function build_query_string() {
mp-wp_genesis 367 $this->query_string = '';
mp-wp_genesis 368 foreach ( (array) array_keys($this->query_vars) as $wpvar) {
mp-wp_genesis 369 if ( '' != $this->query_vars[$wpvar] ) {
mp-wp_genesis 370 $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
mp-wp_genesis 371 if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
mp-wp_genesis 372 continue;
mp-wp_genesis 373 $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
mp-wp_genesis 374 }
mp-wp_genesis 375 }
mp-wp_genesis 376
mp-wp_genesis 377 // query_string filter deprecated. Use request filter instead.
mp-wp_genesis 378 if ( has_filter('query_string') ) { // Don't bother filtering and parsing if no plugins are hooked in.
mp-wp_genesis 379 $this->query_string = apply_filters('query_string', $this->query_string);
mp-wp_genesis 380 parse_str($this->query_string, $this->query_vars);
mp-wp_genesis 381 }
mp-wp_genesis 382 }
mp-wp_genesis 383
mp-wp_genesis 384 /**
mp-wp_genesis 385 * Setup the WordPress Globals.
mp-wp_genesis 386 *
mp-wp_genesis 387 * The query_vars property will be extracted to the GLOBALS. So care should
mp-wp_genesis 388 * be taken when naming global variables that might interfere with the
mp-wp_genesis 389 * WordPress environment.
mp-wp_genesis 390 *
mp-wp_genesis 391 * @global string $query_string Query string for the loop.
mp-wp_genesis 392 * @global int $more Only set, if single page or post.
mp-wp_genesis 393 * @global int $single If single page or post. Only set, if single page or post.
mp-wp_genesis 394 *
mp-wp_genesis 395 * @since 2.0.0
mp-wp_genesis 396 */
mp-wp_genesis 397 function register_globals() {
mp-wp_genesis 398 global $wp_query;
mp-wp_genesis 399 // Extract updated query vars back into global namespace.
mp-wp_genesis 400 foreach ( (array) $wp_query->query_vars as $key => $value) {
mp-wp_genesis 401 $GLOBALS[$key] = $value;
mp-wp_genesis 402 }
mp-wp_genesis 403
mp-wp_genesis 404 $GLOBALS['query_string'] = & $this->query_string;
mp-wp_genesis 405 $GLOBALS['posts'] = & $wp_query->posts;
mp-wp_genesis 406 $GLOBALS['post'] = & $wp_query->post;
mp-wp_genesis 407 $GLOBALS['request'] = & $wp_query->request;
mp-wp_genesis 408
mp-wp_genesis 409 if ( is_single() || is_page() ) {
mp-wp_genesis 410 $GLOBALS['more'] = 1;
mp-wp_genesis 411 $GLOBALS['single'] = 1;
mp-wp_genesis 412 }
mp-wp_genesis 413 }
mp-wp_genesis 414
mp-wp_genesis 415 /**
mp-wp_genesis 416 * Setup the current user.
mp-wp_genesis 417 *
mp-wp_genesis 418 * @since 2.0.0
mp-wp_genesis 419 */
mp-wp_genesis 420 function init() {
mp-wp_genesis 421 wp_get_current_user();
mp-wp_genesis 422 }
mp-wp_genesis 423
mp-wp_genesis 424 /**
mp-wp_genesis 425 * Setup the Loop based on the query variables.
mp-wp_genesis 426 *
mp-wp_genesis 427 * @uses WP::$query_vars
mp-wp_genesis 428 * @since 2.0.0
mp-wp_genesis 429 */
mp-wp_genesis 430 function query_posts() {
mp-wp_genesis 431 global $wp_the_query;
mp-wp_genesis 432 $this->build_query_string();
mp-wp_genesis 433 $wp_the_query->query($this->query_vars);
mp-wp_genesis 434 }
mp-wp_genesis 435
mp-wp_genesis 436 /**
mp-wp_genesis 437 * Set the Headers for 404, if permalink is not found.
mp-wp_genesis 438 *
mp-wp_genesis 439 * Issue a 404 if a permalink request doesn't match any posts. Don't issue
mp-wp_genesis 440 * a 404 if one was already issued, if the request was a search, or if the
mp-wp_genesis 441 * request was a regular query string request rather than a permalink
mp-wp_genesis 442 * request. Issues a 200, if not 404.
mp-wp_genesis 443 *
mp-wp_genesis 444 * @since 2.0.0
mp-wp_genesis 445 */
mp-wp_genesis 446 function handle_404() {
mp-wp_genesis 447 global $wp_query;
mp-wp_genesis 448
mp-wp_genesis 449 if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
mp-wp_genesis 450 // Don't 404 for these queries if they matched an object.
mp-wp_genesis 451 if ( ( is_tag() || is_category() || is_author() ) && $wp_query->get_queried_object() ) {
mp-wp_genesis 452 if ( !is_404() )
mp-wp_genesis 453 status_header( 200 );
mp-wp_genesis 454 return;
mp-wp_genesis 455 }
mp-wp_genesis 456 $wp_query->set_404();
mp-wp_genesis 457 status_header( 404 );
mp-wp_genesis 458 nocache_headers();
mp-wp_genesis 459 } elseif ( !is_404() ) {
mp-wp_genesis 460 status_header( 200 );
mp-wp_genesis 461 }
mp-wp_genesis 462 }
mp-wp_genesis 463
mp-wp_genesis 464 /**
mp-wp_genesis 465 * Sets up all of the variables required by the WordPress environment.
mp-wp_genesis 466 *
mp-wp_genesis 467 * The action 'wp' has one parameter that references the WP object. It
mp-wp_genesis 468 * allows for accessing the properties and methods to further manipulate the
mp-wp_genesis 469 * object.
mp-wp_genesis 470 *
mp-wp_genesis 471 * @since 2.0.0
mp-wp_genesis 472 *
mp-wp_genesis 473 * @param string|array $query_args Passed to {@link parse_request()}
mp-wp_genesis 474 */
mp-wp_genesis 475 function main($query_args = '') {
mp-wp_genesis 476 $this->init();
mp-wp_genesis 477 $this->parse_request($query_args);
mp-wp_genesis 478 $this->send_headers();
mp-wp_genesis 479 $this->query_posts();
mp-wp_genesis 480 $this->handle_404();
mp-wp_genesis 481 $this->register_globals();
mp-wp_genesis 482 do_action_ref_array('wp', array(&$this));
mp-wp_genesis 483 }
mp-wp_genesis 484
mp-wp_genesis 485 /**
mp-wp_genesis 486 * PHP4 Constructor - Does nothing.
mp-wp_genesis 487 *
mp-wp_genesis 488 * Call main() method when ready to run setup.
mp-wp_genesis 489 *
mp-wp_genesis 490 * @since 2.0.0
mp-wp_genesis 491 *
mp-wp_genesis 492 * @return WP
mp-wp_genesis 493 */
mp-wp_genesis 494 function WP() {
mp-wp_genesis 495 // Empty.
mp-wp_genesis 496 }
mp-wp_genesis 497 }
mp-wp_genesis 498
mp-wp_genesis 499 /**
mp-wp_genesis 500 * WordPress Error class.
mp-wp_genesis 501 *
mp-wp_genesis 502 * Container for checking for WordPress errors and error messages. Return
mp-wp_genesis 503 * WP_Error and use {@link is_wp_error()} to check if this class is returned.
mp-wp_genesis 504 * Many core WordPress functions pass this class in the event of an error and
mp-wp_genesis 505 * if not handled properly will result in code errors.
mp-wp_genesis 506 *
mp-wp_genesis 507 * @package WordPress
mp-wp_genesis 508 * @since 2.1.0
mp-wp_genesis 509 */
mp-wp_genesis 510 class WP_Error {
mp-wp_genesis 511 /**
mp-wp_genesis 512 * Stores the list of errors.
mp-wp_genesis 513 *
mp-wp_genesis 514 * @since 2.1.0
mp-wp_genesis 515 * @var array
mp-wp_genesis 516 * @access private
mp-wp_genesis 517 */
mp-wp_genesis 518 var $errors = array();
mp-wp_genesis 519
mp-wp_genesis 520 /**
mp-wp_genesis 521 * Stores the list of data for error codes.
mp-wp_genesis 522 *
mp-wp_genesis 523 * @since 2.1.0
mp-wp_genesis 524 * @var array
mp-wp_genesis 525 * @access private
mp-wp_genesis 526 */
mp-wp_genesis 527 var $error_data = array();
mp-wp_genesis 528
mp-wp_genesis 529 /**
mp-wp_genesis 530 * PHP4 Constructor - Sets up error message.
mp-wp_genesis 531 *
mp-wp_genesis 532 * If code parameter is empty then nothing will be done. It is possible to
mp-wp_genesis 533 * add multiple messages to the same code, but with other methods in the
mp-wp_genesis 534 * class.
mp-wp_genesis 535 *
mp-wp_genesis 536 * All parameters are optional, but if the code parameter is set, then the
mp-wp_genesis 537 * data parameter is optional.
mp-wp_genesis 538 *
mp-wp_genesis 539 * @since 2.1.0
mp-wp_genesis 540 *
mp-wp_genesis 541 * @param string|int $code Error code
mp-wp_genesis 542 * @param string $message Error message
mp-wp_genesis 543 * @param mixed $data Optional. Error data.
mp-wp_genesis 544 * @return WP_Error
mp-wp_genesis 545 */
mp-wp_genesis 546 function WP_Error($code = '', $message = '', $data = '') {
mp-wp_genesis 547 if ( empty($code) )
mp-wp_genesis 548 return;
mp-wp_genesis 549
mp-wp_genesis 550 $this->errors[$code][] = $message;
mp-wp_genesis 551
mp-wp_genesis 552 if ( ! empty($data) )
mp-wp_genesis 553 $this->error_data[$code] = $data;
mp-wp_genesis 554 }
mp-wp_genesis 555
mp-wp_genesis 556 /**
mp-wp_genesis 557 * Retrieve all error codes.
mp-wp_genesis 558 *
mp-wp_genesis 559 * @since 2.1.0
mp-wp_genesis 560 * @access public
mp-wp_genesis 561 *
mp-wp_genesis 562 * @return array List of error codes, if avaiable.
mp-wp_genesis 563 */
mp-wp_genesis 564 function get_error_codes() {
mp-wp_genesis 565 if ( empty($this->errors) )
mp-wp_genesis 566 return array();
mp-wp_genesis 567
mp-wp_genesis 568 return array_keys($this->errors);
mp-wp_genesis 569 }
mp-wp_genesis 570
mp-wp_genesis 571 /**
mp-wp_genesis 572 * Retrieve first error code available.
mp-wp_genesis 573 *
mp-wp_genesis 574 * @since 2.1.0
mp-wp_genesis 575 * @access public
mp-wp_genesis 576 *
mp-wp_genesis 577 * @return string|int Empty string, if no error codes.
mp-wp_genesis 578 */
mp-wp_genesis 579 function get_error_code() {
mp-wp_genesis 580 $codes = $this->get_error_codes();
mp-wp_genesis 581
mp-wp_genesis 582 if ( empty($codes) )
mp-wp_genesis 583 return '';
mp-wp_genesis 584
mp-wp_genesis 585 return $codes[0];
mp-wp_genesis 586 }
mp-wp_genesis 587
mp-wp_genesis 588 /**
mp-wp_genesis 589 * Retrieve all error messages or error messages matching code.
mp-wp_genesis 590 *
mp-wp_genesis 591 * @since 2.1.0
mp-wp_genesis 592 *
mp-wp_genesis 593 * @param string|int $code Optional. Retrieve messages matching code, if exists.
mp-wp_genesis 594 * @return array Error strings on success, or empty array on failure (if using codee parameter).
mp-wp_genesis 595 */
mp-wp_genesis 596 function get_error_messages($code = '') {
mp-wp_genesis 597 // Return all messages if no code specified.
mp-wp_genesis 598 if ( empty($code) ) {
mp-wp_genesis 599 $all_messages = array();
mp-wp_genesis 600 foreach ( (array) $this->errors as $code => $messages )
mp-wp_genesis 601 $all_messages = array_merge($all_messages, $messages);
mp-wp_genesis 602
mp-wp_genesis 603 return $all_messages;
mp-wp_genesis 604 }
mp-wp_genesis 605
mp-wp_genesis 606 if ( isset($this->errors[$code]) )
mp-wp_genesis 607 return $this->errors[$code];
mp-wp_genesis 608 else
mp-wp_genesis 609 return array();
mp-wp_genesis 610 }
mp-wp_genesis 611
mp-wp_genesis 612 /**
mp-wp_genesis 613 * Get single error message.
mp-wp_genesis 614 *
mp-wp_genesis 615 * This will get the first message available for the code. If no code is
mp-wp_genesis 616 * given then the first code available will be used.
mp-wp_genesis 617 *
mp-wp_genesis 618 * @since 2.1.0
mp-wp_genesis 619 *
mp-wp_genesis 620 * @param string|int $code Optional. Error code to retrieve message.
mp-wp_genesis 621 * @return string
mp-wp_genesis 622 */
mp-wp_genesis 623 function get_error_message($code = '') {
mp-wp_genesis 624 if ( empty($code) )
mp-wp_genesis 625 $code = $this->get_error_code();
mp-wp_genesis 626 $messages = $this->get_error_messages($code);
mp-wp_genesis 627 if ( empty($messages) )
mp-wp_genesis 628 return '';
mp-wp_genesis 629 return $messages[0];
mp-wp_genesis 630 }
mp-wp_genesis 631
mp-wp_genesis 632 /**
mp-wp_genesis 633 * Retrieve error data for error code.
mp-wp_genesis 634 *
mp-wp_genesis 635 * @since 2.1.0
mp-wp_genesis 636 *
mp-wp_genesis 637 * @param string|int $code Optional. Error code.
mp-wp_genesis 638 * @return mixed Null, if no errors.
mp-wp_genesis 639 */
mp-wp_genesis 640 function get_error_data($code = '') {
mp-wp_genesis 641 if ( empty($code) )
mp-wp_genesis 642 $code = $this->get_error_code();
mp-wp_genesis 643
mp-wp_genesis 644 if ( isset($this->error_data[$code]) )
mp-wp_genesis 645 return $this->error_data[$code];
mp-wp_genesis 646 return null;
mp-wp_genesis 647 }
mp-wp_genesis 648
mp-wp_genesis 649 /**
mp-wp_genesis 650 * Append more error messages to list of error messages.
mp-wp_genesis 651 *
mp-wp_genesis 652 * @since 2.1.0
mp-wp_genesis 653 * @access public
mp-wp_genesis 654 *
mp-wp_genesis 655 * @param string|int $code Error code.
mp-wp_genesis 656 * @param string $message Error message.
mp-wp_genesis 657 * @param mixed $data Optional. Error data.
mp-wp_genesis 658 */
mp-wp_genesis 659 function add($code, $message, $data = '') {
mp-wp_genesis 660 $this->errors[$code][] = $message;
mp-wp_genesis 661 if ( ! empty($data) )
mp-wp_genesis 662 $this->error_data[$code] = $data;
mp-wp_genesis 663 }
mp-wp_genesis 664
mp-wp_genesis 665 /**
mp-wp_genesis 666 * Add data for error code.
mp-wp_genesis 667 *
mp-wp_genesis 668 * The error code can only contain one error data.
mp-wp_genesis 669 *
mp-wp_genesis 670 * @since 2.1.0
mp-wp_genesis 671 *
mp-wp_genesis 672 * @param mixed $data Error data.
mp-wp_genesis 673 * @param string|int $code Error code.
mp-wp_genesis 674 */
mp-wp_genesis 675 function add_data($data, $code = '') {
mp-wp_genesis 676 if ( empty($code) )
mp-wp_genesis 677 $code = $this->get_error_code();
mp-wp_genesis 678
mp-wp_genesis 679 $this->error_data[$code] = $data;
mp-wp_genesis 680 }
mp-wp_genesis 681 }
mp-wp_genesis 682
mp-wp_genesis 683 /**
mp-wp_genesis 684 * Check whether variable is a WordPress Error.
mp-wp_genesis 685 *
mp-wp_genesis 686 * Looks at the object and if a WP_Error class. Does not check to see if the
mp-wp_genesis 687 * parent is also WP_Error, so can't inherit WP_Error and still use this
mp-wp_genesis 688 * function.
mp-wp_genesis 689 *
mp-wp_genesis 690 * @since 2.1.0
mp-wp_genesis 691 *
mp-wp_genesis 692 * @param mixed $thing Check if unknown variable is WordPress Error object.
mp-wp_genesis 693 * @return bool True, if WP_Error. False, if not WP_Error.
mp-wp_genesis 694 */
mp-wp_genesis 695 function is_wp_error($thing) {
mp-wp_genesis 696 if ( is_object($thing) && is_a($thing, 'WP_Error') )
mp-wp_genesis 697 return true;
mp-wp_genesis 698 return false;
mp-wp_genesis 699 }
mp-wp_genesis 700
mp-wp_genesis 701 /**
mp-wp_genesis 702 * A class for displaying various tree-like structures.
mp-wp_genesis 703 *
mp-wp_genesis 704 * Extend the Walker class to use it, see examples at the below. Child classes
mp-wp_genesis 705 * do not need to implement all of the abstract methods in the class. The child
mp-wp_genesis 706 * only needs to implement the methods that are needed. Also, the methods are
mp-wp_genesis 707 * not strictly abstract in that the parameter definition needs to be followed.
mp-wp_genesis 708 * The child classes can have additional parameters.
mp-wp_genesis 709 *
mp-wp_genesis 710 * @package WordPress
mp-wp_genesis 711 * @since 2.1.0
mp-wp_genesis 712 * @abstract
mp-wp_genesis 713 */
mp-wp_genesis 714 class Walker {
mp-wp_genesis 715 /**
mp-wp_genesis 716 * What the class handles.
mp-wp_genesis 717 *
mp-wp_genesis 718 * @since 2.1.0
mp-wp_genesis 719 * @var string
mp-wp_genesis 720 * @access public
mp-wp_genesis 721 */
mp-wp_genesis 722 var $tree_type;
mp-wp_genesis 723
mp-wp_genesis 724 /**
mp-wp_genesis 725 * DB fields to use.
mp-wp_genesis 726 *
mp-wp_genesis 727 * @since 2.1.0
mp-wp_genesis 728 * @var array
mp-wp_genesis 729 * @access protected
mp-wp_genesis 730 */
mp-wp_genesis 731 var $db_fields;
mp-wp_genesis 732
mp-wp_genesis 733 /**
mp-wp_genesis 734 * Max number of pages walked by the paged walker
mp-wp_genesis 735 *
mp-wp_genesis 736 * @since 2.7.0
mp-wp_genesis 737 * @var int
mp-wp_genesis 738 * @access protected
mp-wp_genesis 739 */
mp-wp_genesis 740 var $max_pages = 1;
mp-wp_genesis 741
mp-wp_genesis 742 /**
mp-wp_genesis 743 * Starts the list before the elements are added.
mp-wp_genesis 744 *
mp-wp_genesis 745 * Additional parameters are used in child classes. The args parameter holds
mp-wp_genesis 746 * additional values that may be used with the child class methods. This
mp-wp_genesis 747 * method is called at the start of the output list.
mp-wp_genesis 748 *
mp-wp_genesis 749 * @since 2.1.0
mp-wp_genesis 750 * @abstract
mp-wp_genesis 751 *
mp-wp_genesis 752 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 753 */
mp-wp_genesis 754 # function start_lvl(&$output) {}
mp-wp_genesis 755
mp-wp_genesis 756 /**
mp-wp_genesis 757 * Ends the list of after the elements are added.
mp-wp_genesis 758 *
mp-wp_genesis 759 * Additional parameters are used in child classes. The args parameter holds
mp-wp_genesis 760 * additional values that may be used with the child class methods. This
mp-wp_genesis 761 * method finishes the list at the end of output of the elements.
mp-wp_genesis 762 *
mp-wp_genesis 763 * @since 2.1.0
mp-wp_genesis 764 * @abstract
mp-wp_genesis 765 *
mp-wp_genesis 766 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 767 */
mp-wp_genesis 768 # function end_lvl(&$output) {}
mp-wp_genesis 769
mp-wp_genesis 770 /**
mp-wp_genesis 771 * Start the element output.
mp-wp_genesis 772 *
mp-wp_genesis 773 * Additional parameters are used in child classes. The args parameter holds
mp-wp_genesis 774 * additional values that may be used with the child class methods. Includes
mp-wp_genesis 775 * the element output also.
mp-wp_genesis 776 *
mp-wp_genesis 777 * @since 2.1.0
mp-wp_genesis 778 * @abstract
mp-wp_genesis 779 *
mp-wp_genesis 780 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 781 */
mp-wp_genesis 782 # function start_el(&$output) {}
mp-wp_genesis 783
mp-wp_genesis 784 /**
mp-wp_genesis 785 * Ends the element output, if needed.
mp-wp_genesis 786 *
mp-wp_genesis 787 * Additional parameters are used in child classes. The args parameter holds
mp-wp_genesis 788 * additional values that may be used with the child class methods.
mp-wp_genesis 789 *
mp-wp_genesis 790 * @since 2.1.0
mp-wp_genesis 791 * @abstract
mp-wp_genesis 792 *
mp-wp_genesis 793 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 794 * @param object $thing object involved in walking
mp-wp_genesis 795 * @param int $depth Depth of object
mp-wp_genesis 796 * @param array $args additional arguments
mp-wp_genesis 797 */
mp-wp_genesis 798 function end_el(&$output, $thing, $depth, $args) {}
mp-wp_genesis 799
mp-wp_genesis 800 /**
mp-wp_genesis 801 * Traverse elements to create list from elements.
mp-wp_genesis 802 *
mp-wp_genesis 803 * Display one element if the element doesn't have any children otherwise,
mp-wp_genesis 804 * display the element and its children. Will only traverse up to the max
mp-wp_genesis 805 * depth and no ignore elements under that depth. It is possible to set the
mp-wp_genesis 806 * max depth to include all depths, see walk() method.
mp-wp_genesis 807 *
mp-wp_genesis 808 * This method shouldn't be called directly, use the walk() method instead.
mp-wp_genesis 809 *
mp-wp_genesis 810 * @since 2.5.0
mp-wp_genesis 811 *
mp-wp_genesis 812 * @param object $element Data object
mp-wp_genesis 813 * @param array $children_elements List of elements to continue traversing.
mp-wp_genesis 814 * @param int $max_depth Max depth to traverse.
mp-wp_genesis 815 * @param int $depth Depth of current element.
mp-wp_genesis 816 * @param array $args
mp-wp_genesis 817 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 818 * @return null Null on failure with no changes to parameters.
mp-wp_genesis 819 */
mp-wp_genesis 820 function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
mp-wp_genesis 821
mp-wp_genesis 822 if ( !$element )
mp-wp_genesis 823 return;
mp-wp_genesis 824
mp-wp_genesis 825 $id_field = $this->db_fields['id'];
mp-wp_genesis 826
mp-wp_genesis 827 //display this element
mp-wp_genesis 828 if ( is_array( $args[0] ) )
mp-wp_genesis 829 $args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
mp-wp_genesis 830 $cb_args = array_merge( array(&$output, $element, $depth), $args);
mp-wp_genesis 831 call_user_func_array(array(&$this, 'start_el'), $cb_args);
mp-wp_genesis 832
mp-wp_genesis 833 $id = $element->$id_field;
mp-wp_genesis 834
mp-wp_genesis 835 // descend only when the depth is right and there are childrens for this element
mp-wp_genesis 836 if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
mp-wp_genesis 837
mp-wp_genesis 838 foreach( $children_elements[ $id ] as $child ){
mp-wp_genesis 839
mp-wp_genesis 840 if ( !isset($newlevel) ) {
mp-wp_genesis 841 $newlevel = true;
mp-wp_genesis 842 //start the child delimiter
mp-wp_genesis 843 $cb_args = array_merge( array(&$output, $depth), $args);
mp-wp_genesis 844 call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
mp-wp_genesis 845 }
mp-wp_genesis 846 $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
mp-wp_genesis 847 }
mp-wp_genesis 848 unset( $children_elements[ $id ] );
mp-wp_genesis 849 }
mp-wp_genesis 850
mp-wp_genesis 851 if ( isset($newlevel) && $newlevel ){
mp-wp_genesis 852 //end the child delimiter
mp-wp_genesis 853 $cb_args = array_merge( array(&$output, $depth), $args);
mp-wp_genesis 854 call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
mp-wp_genesis 855 }
mp-wp_genesis 856
mp-wp_genesis 857 //end this element
mp-wp_genesis 858 $cb_args = array_merge( array(&$output, $element, $depth), $args);
mp-wp_genesis 859 call_user_func_array(array(&$this, 'end_el'), $cb_args);
mp-wp_genesis 860 }
mp-wp_genesis 861
mp-wp_genesis 862 /**
mp-wp_genesis 863 * Display array of elements hierarchically.
mp-wp_genesis 864 *
mp-wp_genesis 865 * It is a generic function which does not assume any existing order of
mp-wp_genesis 866 * elements. max_depth = -1 means flatly display every element. max_depth =
mp-wp_genesis 867 * 0 means display all levels. max_depth > 0 specifies the number of
mp-wp_genesis 868 * display levels.
mp-wp_genesis 869 *
mp-wp_genesis 870 * @since 2.1.0
mp-wp_genesis 871 *
mp-wp_genesis 872 * @param array $elements
mp-wp_genesis 873 * @param int $max_depth
mp-wp_genesis 874 * @return string
mp-wp_genesis 875 */
mp-wp_genesis 876 function walk( $elements, $max_depth) {
mp-wp_genesis 877
mp-wp_genesis 878 $args = array_slice(func_get_args(), 2);
mp-wp_genesis 879 $output = '';
mp-wp_genesis 880
mp-wp_genesis 881 if ($max_depth < -1) //invalid parameter
mp-wp_genesis 882 return $output;
mp-wp_genesis 883
mp-wp_genesis 884 if (empty($elements)) //nothing to walk
mp-wp_genesis 885 return $output;
mp-wp_genesis 886
mp-wp_genesis 887 $id_field = $this->db_fields['id'];
mp-wp_genesis 888 $parent_field = $this->db_fields['parent'];
mp-wp_genesis 889
mp-wp_genesis 890 // flat display
mp-wp_genesis 891 if ( -1 == $max_depth ) {
mp-wp_genesis 892 $empty_array = array();
mp-wp_genesis 893 foreach ( $elements as $e )
mp-wp_genesis 894 $this->display_element( $e, $empty_array, 1, 0, $args, $output );
mp-wp_genesis 895 return $output;
mp-wp_genesis 896 }
mp-wp_genesis 897
mp-wp_genesis 898 /*
mp-wp_genesis 899 * need to display in hierarchical order
mp-wp_genesis 900 * seperate elements into two buckets: top level and children elements
mp-wp_genesis 901 * children_elements is two dimensional array, eg.
mp-wp_genesis 902 * children_elements[10][] contains all sub-elements whose parent is 10.
mp-wp_genesis 903 */
mp-wp_genesis 904 $top_level_elements = array();
mp-wp_genesis 905 $children_elements = array();
mp-wp_genesis 906 foreach ( $elements as $e) {
mp-wp_genesis 907 if ( 0 == $e->$parent_field )
mp-wp_genesis 908 $top_level_elements[] = $e;
mp-wp_genesis 909 else
mp-wp_genesis 910 $children_elements[ $e->$parent_field ][] = $e;
mp-wp_genesis 911 }
mp-wp_genesis 912
mp-wp_genesis 913 /*
mp-wp_genesis 914 * when none of the elements is top level
mp-wp_genesis 915 * assume the first one must be root of the sub elements
mp-wp_genesis 916 */
mp-wp_genesis 917 if ( empty($top_level_elements) ) {
mp-wp_genesis 918
mp-wp_genesis 919 $first = array_slice( $elements, 0, 1 );
mp-wp_genesis 920 $root = $first[0];
mp-wp_genesis 921
mp-wp_genesis 922 $top_level_elements = array();
mp-wp_genesis 923 $children_elements = array();
mp-wp_genesis 924 foreach ( $elements as $e) {
mp-wp_genesis 925 if ( $root->$parent_field == $e->$parent_field )
mp-wp_genesis 926 $top_level_elements[] = $e;
mp-wp_genesis 927 else
mp-wp_genesis 928 $children_elements[ $e->$parent_field ][] = $e;
mp-wp_genesis 929 }
mp-wp_genesis 930 }
mp-wp_genesis 931
mp-wp_genesis 932 foreach ( $top_level_elements as $e )
mp-wp_genesis 933 $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
mp-wp_genesis 934
mp-wp_genesis 935 /*
mp-wp_genesis 936 * if we are displaying all levels, and remaining children_elements is not empty,
mp-wp_genesis 937 * then we got orphans, which should be displayed regardless
mp-wp_genesis 938 */
mp-wp_genesis 939 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
mp-wp_genesis 940 $empty_array = array();
mp-wp_genesis 941 foreach ( $children_elements as $orphans )
mp-wp_genesis 942 foreach( $orphans as $op )
mp-wp_genesis 943 $this->display_element( $op, $empty_array, 1, 0, $args, $output );
mp-wp_genesis 944 }
mp-wp_genesis 945
mp-wp_genesis 946 return $output;
mp-wp_genesis 947 }
mp-wp_genesis 948
mp-wp_genesis 949 /**
mp-wp_genesis 950 * paged_walk() - produce a page of nested elements
mp-wp_genesis 951 *
mp-wp_genesis 952 * Given an array of hierarchical elements, the maximum depth, a specific page number,
mp-wp_genesis 953 * and number of elements per page, this function first determines all top level root elements
mp-wp_genesis 954 * belonging to that page, then lists them and all of their children in hierarchical order.
mp-wp_genesis 955 *
mp-wp_genesis 956 * @package WordPress
mp-wp_genesis 957 * @since 2.7
mp-wp_genesis 958 * @param $max_depth = 0 means display all levels; $max_depth > 0 specifies the number of display levels.
mp-wp_genesis 959 * @param $page_num the specific page number, beginning with 1.
mp-wp_genesis 960 * @return XHTML of the specified page of elements
mp-wp_genesis 961 */
mp-wp_genesis 962 function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
mp-wp_genesis 963
mp-wp_genesis 964 /* sanity check */
mp-wp_genesis 965 if ( empty($elements) || $max_depth < -1 )
mp-wp_genesis 966 return '';
mp-wp_genesis 967
mp-wp_genesis 968 $args = array_slice( func_get_args(), 4 );
mp-wp_genesis 969 $output = '';
mp-wp_genesis 970
mp-wp_genesis 971 $id_field = $this->db_fields['id'];
mp-wp_genesis 972 $parent_field = $this->db_fields['parent'];
mp-wp_genesis 973
mp-wp_genesis 974 $count = -1;
mp-wp_genesis 975 if ( -1 == $max_depth )
mp-wp_genesis 976 $total_top = count( $elements );
mp-wp_genesis 977 if ( $page_num < 1 || $per_page < 0 ) {
mp-wp_genesis 978 // No paging
mp-wp_genesis 979 $paging = false;
mp-wp_genesis 980 $start = 0;
mp-wp_genesis 981 if ( -1 == $max_depth )
mp-wp_genesis 982 $end = $total_top;
mp-wp_genesis 983 $this->max_pages = 1;
mp-wp_genesis 984 } else {
mp-wp_genesis 985 $paging = true;
mp-wp_genesis 986 $start = ( (int)$page_num - 1 ) * (int)$per_page;
mp-wp_genesis 987 $end = $start + $per_page;
mp-wp_genesis 988 if ( -1 == $max_depth )
mp-wp_genesis 989 $this->max_pages = ceil($total_top / $per_page);
mp-wp_genesis 990 }
mp-wp_genesis 991
mp-wp_genesis 992 // flat display
mp-wp_genesis 993 if ( -1 == $max_depth ) {
mp-wp_genesis 994 if ( !empty($args[0]['reverse_top_level']) ) {
mp-wp_genesis 995 $elements = array_reverse( $elements );
mp-wp_genesis 996 $oldstart = $start;
mp-wp_genesis 997 $start = $total_top - $end;
mp-wp_genesis 998 $end = $total_top - $oldstart;
mp-wp_genesis 999 }
mp-wp_genesis 1000
mp-wp_genesis 1001 $empty_array = array();
mp-wp_genesis 1002 foreach ( $elements as $e ) {
mp-wp_genesis 1003 $count++;
mp-wp_genesis 1004 if ( $count < $start )
mp-wp_genesis 1005 continue;
mp-wp_genesis 1006 if ( $count >= $end )
mp-wp_genesis 1007 break;
mp-wp_genesis 1008 $this->display_element( $e, $empty_array, 1, 0, $args, $output );
mp-wp_genesis 1009 }
mp-wp_genesis 1010 return $output;
mp-wp_genesis 1011 }
mp-wp_genesis 1012
mp-wp_genesis 1013 /*
mp-wp_genesis 1014 * seperate elements into two buckets: top level and children elements
mp-wp_genesis 1015 * children_elements is two dimensional array, eg.
mp-wp_genesis 1016 * children_elements[10][] contains all sub-elements whose parent is 10.
mp-wp_genesis 1017 */
mp-wp_genesis 1018 $top_level_elements = array();
mp-wp_genesis 1019 $children_elements = array();
mp-wp_genesis 1020 foreach ( $elements as $e) {
mp-wp_genesis 1021 if ( 0 == $e->$parent_field )
mp-wp_genesis 1022 $top_level_elements[] = $e;
mp-wp_genesis 1023 else
mp-wp_genesis 1024 $children_elements[ $e->$parent_field ][] = $e;
mp-wp_genesis 1025 }
mp-wp_genesis 1026
mp-wp_genesis 1027 $total_top = count( $top_level_elements );
mp-wp_genesis 1028 if ( $paging )
mp-wp_genesis 1029 $this->max_pages = ceil($total_top / $per_page);
mp-wp_genesis 1030 else
mp-wp_genesis 1031 $end = $total_top;
mp-wp_genesis 1032
mp-wp_genesis 1033 if ( !empty($args[0]['reverse_top_level']) ) {
mp-wp_genesis 1034 $top_level_elements = array_reverse( $top_level_elements );
mp-wp_genesis 1035 $oldstart = $start;
mp-wp_genesis 1036 $start = $total_top - $end;
mp-wp_genesis 1037 $end = $total_top - $oldstart;
mp-wp_genesis 1038 }
mp-wp_genesis 1039 if ( !empty($args[0]['reverse_children']) ) {
mp-wp_genesis 1040 foreach ( $children_elements as $parent => $children )
mp-wp_genesis 1041 $children_elements[$parent] = array_reverse( $children );
mp-wp_genesis 1042 }
mp-wp_genesis 1043
mp-wp_genesis 1044 foreach ( $top_level_elements as $e ) {
mp-wp_genesis 1045 $count++;
mp-wp_genesis 1046
mp-wp_genesis 1047 //for the last page, need to unset earlier children in order to keep track of orphans
mp-wp_genesis 1048 if ( $end >= $total_top && $count < $start )
mp-wp_genesis 1049 $this->unset_children( $e, $children_elements );
mp-wp_genesis 1050
mp-wp_genesis 1051 if ( $count < $start )
mp-wp_genesis 1052 continue;
mp-wp_genesis 1053
mp-wp_genesis 1054 if ( $count >= $end )
mp-wp_genesis 1055 break;
mp-wp_genesis 1056
mp-wp_genesis 1057 $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
mp-wp_genesis 1058 }
mp-wp_genesis 1059
mp-wp_genesis 1060 if ( $end >= $total_top && count( $children_elements ) > 0 ) {
mp-wp_genesis 1061 $empty_array = array();
mp-wp_genesis 1062 foreach ( $children_elements as $orphans )
mp-wp_genesis 1063 foreach( $orphans as $op )
mp-wp_genesis 1064 $this->display_element( $op, $empty_array, 1, 0, $args, $output );
mp-wp_genesis 1065 }
mp-wp_genesis 1066
mp-wp_genesis 1067 return $output;
mp-wp_genesis 1068 }
mp-wp_genesis 1069
mp-wp_genesis 1070 function get_number_of_root_elements( $elements ){
mp-wp_genesis 1071
mp-wp_genesis 1072 $num = 0;
mp-wp_genesis 1073 $parent_field = $this->db_fields['parent'];
mp-wp_genesis 1074
mp-wp_genesis 1075 foreach ( $elements as $e) {
mp-wp_genesis 1076 if ( 0 == $e->$parent_field )
mp-wp_genesis 1077 $num++;
mp-wp_genesis 1078 }
mp-wp_genesis 1079 return $num;
mp-wp_genesis 1080 }
mp-wp_genesis 1081
mp-wp_genesis 1082 // unset all the children for a given top level element
mp-wp_genesis 1083 function unset_children( $e, &$children_elements ){
mp-wp_genesis 1084
mp-wp_genesis 1085 if ( !$e || !$children_elements )
mp-wp_genesis 1086 return;
mp-wp_genesis 1087
mp-wp_genesis 1088 $id_field = $this->db_fields['id'];
mp-wp_genesis 1089 $id = $e->$id_field;
mp-wp_genesis 1090
mp-wp_genesis 1091 if ( !empty($children_elements[$id]) && is_array($children_elements[$id]) )
mp-wp_genesis 1092 foreach ( (array) $children_elements[$id] as $child )
mp-wp_genesis 1093 $this->unset_children( $child, $children_elements );
mp-wp_genesis 1094
mp-wp_genesis 1095 if ( isset($children_elements[$id]) )
mp-wp_genesis 1096 unset( $children_elements[$id] );
mp-wp_genesis 1097
mp-wp_genesis 1098 }
mp-wp_genesis 1099 }
mp-wp_genesis 1100
mp-wp_genesis 1101 /**
mp-wp_genesis 1102 * Create HTML list of pages.
mp-wp_genesis 1103 *
mp-wp_genesis 1104 * @package WordPress
mp-wp_genesis 1105 * @since 2.1.0
mp-wp_genesis 1106 * @uses Walker
mp-wp_genesis 1107 */
mp-wp_genesis 1108 class Walker_Page extends Walker {
mp-wp_genesis 1109 /**
mp-wp_genesis 1110 * @see Walker::$tree_type
mp-wp_genesis 1111 * @since 2.1.0
mp-wp_genesis 1112 * @var string
mp-wp_genesis 1113 */
mp-wp_genesis 1114 var $tree_type = 'page';
mp-wp_genesis 1115
mp-wp_genesis 1116 /**
mp-wp_genesis 1117 * @see Walker::$db_fields
mp-wp_genesis 1118 * @since 2.1.0
mp-wp_genesis 1119 * @todo Decouple this.
mp-wp_genesis 1120 * @var array
mp-wp_genesis 1121 */
mp-wp_genesis 1122 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
mp-wp_genesis 1123
mp-wp_genesis 1124 /**
mp-wp_genesis 1125 * @see Walker::start_lvl()
mp-wp_genesis 1126 * @since 2.1.0
mp-wp_genesis 1127 *
mp-wp_genesis 1128 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1129 * @param int $depth Depth of page. Used for padding.
mp-wp_genesis 1130 */
mp-wp_genesis 1131 function start_lvl(&$output, $depth) {
mp-wp_genesis 1132 $indent = str_repeat("\t", $depth);
mp-wp_genesis 1133 $output .= "\n$indent<ul>\n";
mp-wp_genesis 1134 }
mp-wp_genesis 1135
mp-wp_genesis 1136 /**
mp-wp_genesis 1137 * @see Walker::end_lvl()
mp-wp_genesis 1138 * @since 2.1.0
mp-wp_genesis 1139 *
mp-wp_genesis 1140 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1141 * @param int $depth Depth of page. Used for padding.
mp-wp_genesis 1142 */
mp-wp_genesis 1143 function end_lvl(&$output, $depth) {
mp-wp_genesis 1144 $indent = str_repeat("\t", $depth);
mp-wp_genesis 1145 $output .= "$indent</ul>\n";
mp-wp_genesis 1146 }
mp-wp_genesis 1147
mp-wp_genesis 1148 /**
mp-wp_genesis 1149 * @see Walker::start_el()
mp-wp_genesis 1150 * @since 2.1.0
mp-wp_genesis 1151 *
mp-wp_genesis 1152 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1153 * @param object $page Page data object.
mp-wp_genesis 1154 * @param int $depth Depth of page. Used for padding.
mp-wp_genesis 1155 * @param int $current_page Page ID.
mp-wp_genesis 1156 * @param array $args
mp-wp_genesis 1157 */
mp-wp_genesis 1158 function start_el(&$output, $page, $depth, $args, $current_page) {
mp-wp_genesis 1159 if ( $depth )
mp-wp_genesis 1160 $indent = str_repeat("\t", $depth);
mp-wp_genesis 1161 else
mp-wp_genesis 1162 $indent = '';
mp-wp_genesis 1163
mp-wp_genesis 1164 extract($args, EXTR_SKIP);
mp-wp_genesis 1165 $css_class = 'page_item page-item-'.$page->ID;
mp-wp_genesis 1166 if ( !empty($current_page) ) {
mp-wp_genesis 1167 $_current_page = get_page( $current_page );
mp-wp_genesis 1168 if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
mp-wp_genesis 1169 $css_class .= ' current_page_ancestor';
mp-wp_genesis 1170 if ( $page->ID == $current_page )
mp-wp_genesis 1171 $css_class .= ' current_page_item';
mp-wp_genesis 1172 elseif ( $_current_page && $page->ID == $_current_page->post_parent )
mp-wp_genesis 1173 $css_class .= ' current_page_parent';
mp-wp_genesis 1174 } elseif ( $page->ID == get_option('page_for_posts') ) {
mp-wp_genesis 1175 $css_class .= ' current_page_parent';
mp-wp_genesis 1176 }
mp-wp_genesis 1177
mp-wp_genesis 1178 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . '</a>';
mp-wp_genesis 1179
mp-wp_genesis 1180 if ( !empty($show_date) ) {
mp-wp_genesis 1181 if ( 'modified' == $show_date )
mp-wp_genesis 1182 $time = $page->post_modified;
mp-wp_genesis 1183 else
mp-wp_genesis 1184 $time = $page->post_date;
mp-wp_genesis 1185
mp-wp_genesis 1186 $output .= " " . mysql2date($date_format, $time);
mp-wp_genesis 1187 }
mp-wp_genesis 1188 }
mp-wp_genesis 1189
mp-wp_genesis 1190 /**
mp-wp_genesis 1191 * @see Walker::end_el()
mp-wp_genesis 1192 * @since 2.1.0
mp-wp_genesis 1193 *
mp-wp_genesis 1194 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1195 * @param object $page Page data object. Not used.
mp-wp_genesis 1196 * @param int $depth Depth of page. Not Used.
mp-wp_genesis 1197 */
mp-wp_genesis 1198 function end_el(&$output, $page, $depth, $args) {
mp-wp_genesis 1199 $output .= "</li>\n";
mp-wp_genesis 1200 }
mp-wp_genesis 1201
mp-wp_genesis 1202 }
mp-wp_genesis 1203
mp-wp_genesis 1204 /**
mp-wp_genesis 1205 * Create HTML dropdown list of pages.
mp-wp_genesis 1206 *
mp-wp_genesis 1207 * @package WordPress
mp-wp_genesis 1208 * @since 2.1.0
mp-wp_genesis 1209 * @uses Walker
mp-wp_genesis 1210 */
mp-wp_genesis 1211 class Walker_PageDropdown extends Walker {
mp-wp_genesis 1212 /**
mp-wp_genesis 1213 * @see Walker::$tree_type
mp-wp_genesis 1214 * @since 2.1.0
mp-wp_genesis 1215 * @var string
mp-wp_genesis 1216 */
mp-wp_genesis 1217 var $tree_type = 'page';
mp-wp_genesis 1218
mp-wp_genesis 1219 /**
mp-wp_genesis 1220 * @see Walker::$db_fields
mp-wp_genesis 1221 * @since 2.1.0
mp-wp_genesis 1222 * @todo Decouple this
mp-wp_genesis 1223 * @var array
mp-wp_genesis 1224 */
mp-wp_genesis 1225 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
mp-wp_genesis 1226
mp-wp_genesis 1227 /**
mp-wp_genesis 1228 * @see Walker::start_el()
mp-wp_genesis 1229 * @since 2.1.0
mp-wp_genesis 1230 *
mp-wp_genesis 1231 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1232 * @param object $page Page data object.
mp-wp_genesis 1233 * @param int $depth Depth of page in reference to parent pages. Used for padding.
mp-wp_genesis 1234 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
mp-wp_genesis 1235 */
mp-wp_genesis 1236 function start_el(&$output, $page, $depth, $args) {
mp-wp_genesis 1237 $pad = str_repeat('&nbsp;', $depth * 3);
mp-wp_genesis 1238
mp-wp_genesis 1239 $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
mp-wp_genesis 1240 if ( $page->ID == $args['selected'] )
mp-wp_genesis 1241 $output .= ' selected="selected"';
mp-wp_genesis 1242 $output .= '>';
mp-wp_genesis 1243 $title = wp_specialchars($page->post_title);
mp-wp_genesis 1244 $output .= "$pad$title";
mp-wp_genesis 1245 $output .= "</option>\n";
mp-wp_genesis 1246 }
mp-wp_genesis 1247 }
mp-wp_genesis 1248
mp-wp_genesis 1249 /**
mp-wp_genesis 1250 * Create HTML list of categories.
mp-wp_genesis 1251 *
mp-wp_genesis 1252 * @package WordPress
mp-wp_genesis 1253 * @since 2.1.0
mp-wp_genesis 1254 * @uses Walker
mp-wp_genesis 1255 */
mp-wp_genesis 1256 class Walker_Category extends Walker {
mp-wp_genesis 1257 /**
mp-wp_genesis 1258 * @see Walker::$tree_type
mp-wp_genesis 1259 * @since 2.1.0
mp-wp_genesis 1260 * @var string
mp-wp_genesis 1261 */
mp-wp_genesis 1262 var $tree_type = 'category';
mp-wp_genesis 1263
mp-wp_genesis 1264 /**
mp-wp_genesis 1265 * @see Walker::$db_fields
mp-wp_genesis 1266 * @since 2.1.0
mp-wp_genesis 1267 * @todo Decouple this
mp-wp_genesis 1268 * @var array
mp-wp_genesis 1269 */
mp-wp_genesis 1270 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
mp-wp_genesis 1271
mp-wp_genesis 1272 /**
mp-wp_genesis 1273 * @see Walker::start_lvl()
mp-wp_genesis 1274 * @since 2.1.0
mp-wp_genesis 1275 *
mp-wp_genesis 1276 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1277 * @param int $depth Depth of category. Used for tab indentation.
mp-wp_genesis 1278 * @param array $args Will only append content if style argument value is 'list'.
mp-wp_genesis 1279 */
mp-wp_genesis 1280 function start_lvl(&$output, $depth, $args) {
mp-wp_genesis 1281 if ( 'list' != $args['style'] )
mp-wp_genesis 1282 return;
mp-wp_genesis 1283
mp-wp_genesis 1284 $indent = str_repeat("\t", $depth);
mp-wp_genesis 1285 $output .= "$indent<ul class='children'>\n";
mp-wp_genesis 1286 }
mp-wp_genesis 1287
mp-wp_genesis 1288 /**
mp-wp_genesis 1289 * @see Walker::end_lvl()
mp-wp_genesis 1290 * @since 2.1.0
mp-wp_genesis 1291 *
mp-wp_genesis 1292 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1293 * @param int $depth Depth of category. Used for tab indentation.
mp-wp_genesis 1294 * @param array $args Will only append content if style argument value is 'list'.
mp-wp_genesis 1295 */
mp-wp_genesis 1296 function end_lvl(&$output, $depth, $args) {
mp-wp_genesis 1297 if ( 'list' != $args['style'] )
mp-wp_genesis 1298 return;
mp-wp_genesis 1299
mp-wp_genesis 1300 $indent = str_repeat("\t", $depth);
mp-wp_genesis 1301 $output .= "$indent</ul>\n";
mp-wp_genesis 1302 }
mp-wp_genesis 1303
mp-wp_genesis 1304 /**
mp-wp_genesis 1305 * @see Walker::start_el()
mp-wp_genesis 1306 * @since 2.1.0
mp-wp_genesis 1307 *
mp-wp_genesis 1308 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1309 * @param object $category Category data object.
mp-wp_genesis 1310 * @param int $depth Depth of category in reference to parents.
mp-wp_genesis 1311 * @param array $args
mp-wp_genesis 1312 */
mp-wp_genesis 1313 function start_el(&$output, $category, $depth, $args) {
mp-wp_genesis 1314 extract($args);
mp-wp_genesis 1315
mp-wp_genesis 1316 $cat_name = attribute_escape( $category->name);
mp-wp_genesis 1317 $cat_name = apply_filters( 'list_cats', $cat_name, $category );
mp-wp_genesis 1318 $link = '<a href="' . get_category_link( $category->term_id ) . '" ';
mp-wp_genesis 1319 if ( $use_desc_for_title == 0 || empty($category->description) )
mp-wp_genesis 1320 $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
mp-wp_genesis 1321 else
mp-wp_genesis 1322 $link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->description, $category )) . '"';
mp-wp_genesis 1323 $link .= '>';
mp-wp_genesis 1324 $link .= $cat_name . '</a>';
mp-wp_genesis 1325
mp-wp_genesis 1326 if ( (! empty($feed_image)) || (! empty($feed)) ) {
mp-wp_genesis 1327 $link .= ' ';
mp-wp_genesis 1328
mp-wp_genesis 1329 if ( empty($feed_image) )
mp-wp_genesis 1330 $link .= '(';
mp-wp_genesis 1331
mp-wp_genesis 1332 $link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
mp-wp_genesis 1333
mp-wp_genesis 1334 if ( empty($feed) )
mp-wp_genesis 1335 $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
mp-wp_genesis 1336 else {
mp-wp_genesis 1337 $title = ' title="' . $feed . '"';
mp-wp_genesis 1338 $alt = ' alt="' . $feed . '"';
mp-wp_genesis 1339 $name = $feed;
mp-wp_genesis 1340 $link .= $title;
mp-wp_genesis 1341 }
mp-wp_genesis 1342
mp-wp_genesis 1343 $link .= '>';
mp-wp_genesis 1344
mp-wp_genesis 1345 if ( empty($feed_image) )
mp-wp_genesis 1346 $link .= $name;
mp-wp_genesis 1347 else
mp-wp_genesis 1348 $link .= "<img src='$feed_image'$alt$title" . ' />';
mp-wp_genesis 1349 $link .= '</a>';
mp-wp_genesis 1350 if ( empty($feed_image) )
mp-wp_genesis 1351 $link .= ')';
mp-wp_genesis 1352 }
mp-wp_genesis 1353
mp-wp_genesis 1354 if ( isset($show_count) && $show_count )
mp-wp_genesis 1355 $link .= ' (' . intval($category->count) . ')';
mp-wp_genesis 1356
mp-wp_genesis 1357 if ( isset($show_date) && $show_date ) {
mp-wp_genesis 1358 $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
mp-wp_genesis 1359 }
mp-wp_genesis 1360
mp-wp_genesis 1361 if ( isset($current_category) && $current_category )
mp-wp_genesis 1362 $_current_category = get_category( $current_category );
mp-wp_genesis 1363
mp-wp_genesis 1364 if ( 'list' == $args['style'] ) {
mp-wp_genesis 1365 $output .= "\t<li";
mp-wp_genesis 1366 $class = 'cat-item cat-item-'.$category->term_id;
mp-wp_genesis 1367 if ( isset($current_category) && $current_category && ($category->term_id == $current_category) )
mp-wp_genesis 1368 $class .= ' current-cat';
mp-wp_genesis 1369 elseif ( isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent) )
mp-wp_genesis 1370 $class .= ' current-cat-parent';
mp-wp_genesis 1371 $output .= ' class="'.$class.'"';
mp-wp_genesis 1372 $output .= ">$link\n";
mp-wp_genesis 1373 } else {
mp-wp_genesis 1374 $output .= "\t$link<br />\n";
mp-wp_genesis 1375 }
mp-wp_genesis 1376 }
mp-wp_genesis 1377
mp-wp_genesis 1378 /**
mp-wp_genesis 1379 * @see Walker::end_el()
mp-wp_genesis 1380 * @since 2.1.0
mp-wp_genesis 1381 *
mp-wp_genesis 1382 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1383 * @param object $page Not used.
mp-wp_genesis 1384 * @param int $depth Depth of category. Not used.
mp-wp_genesis 1385 * @param array $args Only uses 'list' for whether should append to output.
mp-wp_genesis 1386 */
mp-wp_genesis 1387 function end_el(&$output, $page, $depth, $args) {
mp-wp_genesis 1388 if ( 'list' != $args['style'] )
mp-wp_genesis 1389 return;
mp-wp_genesis 1390
mp-wp_genesis 1391 $output .= "</li>\n";
mp-wp_genesis 1392 }
mp-wp_genesis 1393
mp-wp_genesis 1394 }
mp-wp_genesis 1395
mp-wp_genesis 1396 /**
mp-wp_genesis 1397 * Create HTML dropdown list of Categories.
mp-wp_genesis 1398 *
mp-wp_genesis 1399 * @package WordPress
mp-wp_genesis 1400 * @since 2.1.0
mp-wp_genesis 1401 * @uses Walker
mp-wp_genesis 1402 */
mp-wp_genesis 1403 class Walker_CategoryDropdown extends Walker {
mp-wp_genesis 1404 /**
mp-wp_genesis 1405 * @see Walker::$tree_type
mp-wp_genesis 1406 * @since 2.1.0
mp-wp_genesis 1407 * @var string
mp-wp_genesis 1408 */
mp-wp_genesis 1409 var $tree_type = 'category';
mp-wp_genesis 1410
mp-wp_genesis 1411 /**
mp-wp_genesis 1412 * @see Walker::$db_fields
mp-wp_genesis 1413 * @since 2.1.0
mp-wp_genesis 1414 * @todo Decouple this
mp-wp_genesis 1415 * @var array
mp-wp_genesis 1416 */
mp-wp_genesis 1417 var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
mp-wp_genesis 1418
mp-wp_genesis 1419 /**
mp-wp_genesis 1420 * @see Walker::start_el()
mp-wp_genesis 1421 * @since 2.1.0
mp-wp_genesis 1422 *
mp-wp_genesis 1423 * @param string $output Passed by reference. Used to append additional content.
mp-wp_genesis 1424 * @param object $category Category data object.
mp-wp_genesis 1425 * @param int $depth Depth of category. Used for padding.
mp-wp_genesis 1426 * @param array $args Uses 'selected', 'show_count', and 'show_last_update' keys, if they exist.
mp-wp_genesis 1427 */
mp-wp_genesis 1428 function start_el(&$output, $category, $depth, $args) {
mp-wp_genesis 1429 $pad = str_repeat('&nbsp;', $depth * 3);
mp-wp_genesis 1430
mp-wp_genesis 1431 $cat_name = apply_filters('list_cats', $category->name, $category);
mp-wp_genesis 1432 $output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
mp-wp_genesis 1433 if ( $category->term_id == $args['selected'] )
mp-wp_genesis 1434 $output .= ' selected="selected"';
mp-wp_genesis 1435 $output .= '>';
mp-wp_genesis 1436 $output .= $pad.$cat_name;
mp-wp_genesis 1437 if ( $args['show_count'] )
mp-wp_genesis 1438 $output .= '&nbsp;&nbsp;('. $category->count .')';
mp-wp_genesis 1439 if ( $args['show_last_update'] ) {
mp-wp_genesis 1440 $format = 'Y-m-d';
mp-wp_genesis 1441 $output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);
mp-wp_genesis 1442 }
mp-wp_genesis 1443 $output .= "</option>\n";
mp-wp_genesis 1444 }
mp-wp_genesis 1445 }
mp-wp_genesis 1446
mp-wp_genesis 1447 ?>