2004-06-30 11:31:49 -04:00
|
|
|
<?php
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Holds Most of the WordPress classes.
|
|
|
|
*
|
|
|
|
* Some of the other classes are contained in other files. For example, the
|
|
|
|
* WordPress cache is in cache.php and the WordPress roles API is in
|
|
|
|
* capabilities.php. The third party libraries are contained in their own
|
|
|
|
* separate files.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
*/
|
2004-06-30 11:31:49 -04:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* WordPress environment setup class.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
class WP {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Public query variables.
|
|
|
|
*
|
|
|
|
* Long list of public query variables.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-02-01 18:12:26 -05:00
|
|
|
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', 'post_type');
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Private query variables.
|
|
|
|
*
|
|
|
|
* Long list of private query variables.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var array
|
|
|
|
*/
|
2009-05-13 18:28:56 -04:00
|
|
|
var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', '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');
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra query variables set by the user.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var array
|
|
|
|
*/
|
2006-02-21 03:39:58 -05:00
|
|
|
var $extra_query_vars = array();
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Query variables for setting up the WordPress Query Loop.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var array
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
var $query_vars;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* String parsed to set the query variables.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
var $query_string;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Permalink or requested URI.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2005-11-22 16:07:48 -05:00
|
|
|
var $request;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewrite rule the request matched.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2005-11-22 16:07:48 -05:00
|
|
|
var $matched_rule;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewrite query the request matched.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2005-11-22 16:07:48 -05:00
|
|
|
var $matched_query;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether already did the permalink.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
* @var bool
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
var $did_permalink = false;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Add name to list of public query variables.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $qv Query variable name.
|
|
|
|
*/
|
2006-03-12 17:57:00 -05:00
|
|
|
function add_query_var($qv) {
|
2008-03-26 02:37:19 -04:00
|
|
|
if ( !in_array($qv, $this->public_query_vars) )
|
|
|
|
$this->public_query_vars[] = $qv;
|
2006-03-12 17:57:00 -05:00
|
|
|
}
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Set the value of a query variable.
|
|
|
|
*
|
|
|
|
* @since 2.3.0
|
|
|
|
*
|
|
|
|
* @param string $key Query variable name.
|
|
|
|
* @param mixed $value Query variable value.
|
|
|
|
*/
|
2007-08-15 18:08:51 -04:00
|
|
|
function set_query_var($key, $value) {
|
|
|
|
$this->query_vars[$key] = $value;
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Parse request to find correct WordPress query.
|
|
|
|
*
|
|
|
|
* Sets up the query variables based on the request. There are also many
|
|
|
|
* filters and actions that can be used to further manipulate the result.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @param array|string $extra_query_vars Set the extra query variables.
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function parse_request($extra_query_vars = '') {
|
|
|
|
global $wp_rewrite;
|
|
|
|
|
|
|
|
$this->query_vars = array();
|
2008-05-16 12:33:11 -04:00
|
|
|
$taxonomy_query_vars = array();
|
2010-02-01 22:18:27 -05:00
|
|
|
$post_type_query_vars = array();
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2006-08-30 01:41:38 -04:00
|
|
|
if ( is_array($extra_query_vars) )
|
|
|
|
$this->extra_query_vars = & $extra_query_vars;
|
|
|
|
else if (! empty($extra_query_vars))
|
2006-02-21 03:39:58 -05:00
|
|
|
parse_str($extra_query_vars, $this->extra_query_vars);
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2005-06-12 22:09:24 -04:00
|
|
|
// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// Fetch the rewrite rules.
|
|
|
|
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( ! empty($rewrite) ) {
|
2005-06-10 19:15:13 -04:00
|
|
|
// If we match a rewrite rule, this will be cleared.
|
|
|
|
$error = '404';
|
2005-11-16 17:54:52 -05:00
|
|
|
$this->did_permalink = true;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2006-09-21 17:03:11 -04:00
|
|
|
if ( isset($_SERVER['PATH_INFO']) )
|
|
|
|
$pathinfo = $_SERVER['PATH_INFO'];
|
|
|
|
else
|
|
|
|
$pathinfo = '';
|
2005-11-16 17:54:52 -05:00
|
|
|
$pathinfo_array = explode('?', $pathinfo);
|
2006-09-18 23:05:08 -04:00
|
|
|
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
|
2005-11-16 17:54:52 -05:00
|
|
|
$req_uri = $_SERVER['REQUEST_URI'];
|
|
|
|
$req_uri_array = explode('?', $req_uri);
|
|
|
|
$req_uri = $req_uri_array[0];
|
|
|
|
$self = $_SERVER['PHP_SELF'];
|
2010-01-04 12:23:29 -05:00
|
|
|
$home_path = parse_url(home_url());
|
2006-09-21 17:03:11 -04:00
|
|
|
if ( isset($home_path['path']) )
|
|
|
|
$home_path = $home_path['path'];
|
|
|
|
else
|
|
|
|
$home_path = '';
|
2005-12-27 20:48:29 -05:00
|
|
|
$home_path = trim($home_path, '/');
|
2005-11-16 17:54:52 -05:00
|
|
|
|
|
|
|
// Trim path info from the end and the leading home path from the
|
|
|
|
// front. For path info requests, this leaves us with the requesting
|
|
|
|
// filename, if any. For 404 requests, this leaves us with the
|
2006-02-12 02:53:23 -05:00
|
|
|
// requested permalink.
|
2007-03-06 20:44:53 -05:00
|
|
|
$req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
|
2005-11-16 17:54:52 -05:00
|
|
|
$req_uri = trim($req_uri, '/');
|
2005-12-27 20:48:29 -05:00
|
|
|
$req_uri = preg_replace("|^$home_path|", '', $req_uri);
|
|
|
|
$req_uri = trim($req_uri, '/');
|
|
|
|
$pathinfo = trim($pathinfo, '/');
|
|
|
|
$pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
|
2005-11-16 17:54:52 -05:00
|
|
|
$pathinfo = trim($pathinfo, '/');
|
2005-12-27 20:48:29 -05:00
|
|
|
$self = trim($self, '/');
|
|
|
|
$self = preg_replace("|^$home_path|", '', $self);
|
2005-11-16 17:54:52 -05:00
|
|
|
$self = trim($self, '/');
|
|
|
|
|
|
|
|
// The requested permalink is in $pathinfo for path info requests and
|
|
|
|
// $req_uri for other requests.
|
2006-01-02 19:59:31 -05:00
|
|
|
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
|
2005-11-16 17:54:52 -05:00
|
|
|
$request = $pathinfo;
|
|
|
|
} else {
|
2005-11-30 20:34:29 -05:00
|
|
|
// If the request uri is the index, blank it out so that we don't try to match it against a rule.
|
|
|
|
if ( $req_uri == $wp_rewrite->index )
|
|
|
|
$req_uri = '';
|
2005-11-16 17:54:52 -05:00
|
|
|
$request = $req_uri;
|
|
|
|
}
|
2005-11-30 20:34:29 -05:00
|
|
|
|
2005-11-22 16:07:48 -05:00
|
|
|
$this->request = $request;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// Look for matches.
|
|
|
|
$request_match = $request;
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $rewrite as $match => $query) {
|
2008-07-06 13:33:39 -04:00
|
|
|
// Don't try to match against AtomPub calls
|
|
|
|
if ( $req_uri == 'wp-app.php' )
|
|
|
|
break;
|
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// If the requesting file is the anchor of the match, prepend it
|
|
|
|
// to the path info.
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( (! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request) )
|
2005-11-16 17:54:52 -05:00
|
|
|
$request_match = $req_uri . '/' . $request;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( preg_match("#^$match#", $request_match, $matches) ||
|
|
|
|
preg_match("#^$match#", urldecode($request_match), $matches) ) {
|
2005-11-16 17:54:52 -05:00
|
|
|
// Got a match.
|
2005-11-22 16:07:48 -05:00
|
|
|
$this->matched_rule = $match;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// Trim the query of everything up to the '?'.
|
|
|
|
$query = preg_replace("!^.+\?!", '', $query);
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// Substitute the substring matches into the query.
|
2009-08-20 16:09:36 -04:00
|
|
|
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
|
2008-09-15 20:37:05 -04:00
|
|
|
|
2005-11-22 16:07:48 -05:00
|
|
|
$this->matched_query = $query;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// Parse the query.
|
2006-02-21 03:39:58 -05:00
|
|
|
parse_str($query, $perma_query_vars);
|
2005-11-16 05:16:20 -05:00
|
|
|
|
2005-11-16 17:54:52 -05:00
|
|
|
// If we're processing a 404 request, clear the error var
|
|
|
|
// since we found something.
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($_GET['error']) )
|
2005-11-16 05:16:20 -05:00
|
|
|
unset($_GET['error']);
|
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($error) )
|
2005-11-16 05:16:20 -05:00
|
|
|
unset($error);
|
2005-11-16 17:54:52 -05:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If req_uri is empty or if it is a request for ourself, unset error.
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false ) {
|
|
|
|
if ( isset($_GET['error']) )
|
2005-11-16 17:54:52 -05:00
|
|
|
unset($_GET['error']);
|
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($error) )
|
2005-11-16 17:54:52 -05:00
|
|
|
unset($error);
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false )
|
2006-02-21 03:39:58 -05:00
|
|
|
unset($perma_query_vars);
|
2006-02-12 02:53:23 -05:00
|
|
|
|
2005-11-28 18:30:42 -05:00
|
|
|
$this->did_permalink = false;
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
|
|
|
|
|
2008-05-15 22:35:24 -04:00
|
|
|
foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t )
|
2009-04-30 15:05:32 -04:00
|
|
|
if ( $t->query_var )
|
2008-05-15 22:35:24 -04:00
|
|
|
$taxonomy_query_vars[$t->query_var] = $taxonomy;
|
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
foreach ( $GLOBALS['wp_post_types'] as $post_type => $t )
|
|
|
|
if ( $t->query_var )
|
|
|
|
$post_type_query_vars[$t->query_var] = $post_type;
|
|
|
|
|
|
|
|
for ( $i = 0; $i < count($this->public_query_vars); $i += 1 ) {
|
2005-06-10 19:15:13 -04:00
|
|
|
$wpvar = $this->public_query_vars[$i];
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($this->extra_query_vars[$wpvar]) )
|
2006-02-21 03:39:58 -05:00
|
|
|
$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
|
2010-02-01 18:12:26 -05:00
|
|
|
elseif ( isset($GLOBALS[$wpvar]) )
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_vars[$wpvar] = $GLOBALS[$wpvar];
|
2010-02-01 18:12:26 -05:00
|
|
|
elseif ( !empty($_POST[$wpvar]) )
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_vars[$wpvar] = $_POST[$wpvar];
|
2010-02-01 18:12:26 -05:00
|
|
|
elseif ( !empty($_GET[$wpvar]) )
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_vars[$wpvar] = $_GET[$wpvar];
|
2010-02-01 18:12:26 -05:00
|
|
|
elseif ( !empty($perma_query_vars[$wpvar]) )
|
2006-02-21 03:39:58 -05:00
|
|
|
$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
|
2007-03-04 13:08:33 -05:00
|
|
|
|
2008-05-15 22:35:24 -04:00
|
|
|
if ( !empty( $this->query_vars[$wpvar] ) ) {
|
2010-10-06 19:18:42 -04:00
|
|
|
if ( ! is_array( $this->query_vars[$wpvar] ) ) {
|
2010-10-07 22:27:22 -04:00
|
|
|
$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
|
2010-10-06 19:18:42 -04:00
|
|
|
} else {
|
|
|
|
foreach ( $this->query_vars[$wpvar] as $vkey => $v )
|
|
|
|
$this->query_vars[$wpvar][$vkey] = (string) $v;
|
|
|
|
}
|
|
|
|
|
2010-04-26 20:22:04 -04:00
|
|
|
if ( isset( $taxonomy_query_vars[$wpvar] ) ) {
|
2008-05-15 22:35:24 -04:00
|
|
|
$this->query_vars['taxonomy'] = $taxonomy_query_vars[$wpvar];
|
|
|
|
$this->query_vars['term'] = $this->query_vars[$wpvar];
|
2010-04-26 20:22:04 -04:00
|
|
|
} elseif ( isset($post_type_query_vars[$wpvar] ) ) {
|
2010-02-01 18:12:26 -05:00
|
|
|
$this->query_vars['post_type'] = $post_type_query_vars[$wpvar];
|
|
|
|
$this->query_vars['name'] = $this->query_vars[$wpvar];
|
2008-05-15 22:35:24 -04:00
|
|
|
}
|
|
|
|
}
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
2005-11-16 05:16:20 -05:00
|
|
|
|
2010-02-01 18:12:26 -05:00
|
|
|
// Limit publicly queried post_types to those that are publicly_queryable
|
|
|
|
if ( isset( $this->query_vars['post_type']) ) {
|
2010-10-06 19:18:42 -04:00
|
|
|
$queryable_post_types = get_post_types( array('publicly_queryable' => true) );
|
|
|
|
if ( ! is_array( $this->query_vars['post_type'] ) ) {
|
|
|
|
if ( ! in_array( $this->query_vars['post_type'], $queryable_post_types ) )
|
|
|
|
unset( $this->query_vars['post_type'] );
|
|
|
|
} else {
|
|
|
|
$this->query_vars['post_type'] = array_intersect( $this->query_vars['post_type'], $queryable_post_types );
|
|
|
|
}
|
2010-02-01 18:12:26 -05:00
|
|
|
}
|
|
|
|
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $this->private_query_vars as $var) {
|
2010-02-01 18:12:26 -05:00
|
|
|
if ( isset($this->extra_query_vars[$var]) )
|
2006-08-30 14:37:33 -04:00
|
|
|
$this->query_vars[$var] = $this->extra_query_vars[$var];
|
2010-02-01 18:12:26 -05:00
|
|
|
elseif ( isset($GLOBALS[$var]) && '' != $GLOBALS[$var] )
|
2006-08-30 01:41:38 -04:00
|
|
|
$this->query_vars[$var] = $GLOBALS[$var];
|
2006-02-21 03:39:58 -05:00
|
|
|
}
|
|
|
|
|
2005-11-16 05:16:20 -05:00
|
|
|
if ( isset($error) )
|
|
|
|
$this->query_vars['error'] = $error;
|
2006-05-22 15:23:46 -04:00
|
|
|
|
2006-08-30 01:41:38 -04:00
|
|
|
$this->query_vars = apply_filters('request', $this->query_vars);
|
|
|
|
|
2006-09-12 13:45:23 -04:00
|
|
|
do_action_ref_array('parse_request', array(&$this));
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Send additional HTTP headers for caching, content type, etc.
|
|
|
|
*
|
|
|
|
* Sets the X-Pingback header, 404 status (if 404), Content-type. If showing
|
|
|
|
* a feed, it will also send last-modified, etag, and 304 status if needed.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function send_headers() {
|
2009-02-21 16:39:06 -05:00
|
|
|
$headers = array('X-Pingback' => get_bloginfo('pingback_url'));
|
|
|
|
$status = null;
|
2009-02-28 04:30:46 -05:00
|
|
|
$exit_required = false;
|
|
|
|
|
2005-12-15 11:31:41 -05:00
|
|
|
if ( is_user_logged_in() )
|
2009-02-21 16:39:06 -05:00
|
|
|
$headers = array_merge($headers, wp_get_nocache_headers());
|
2005-06-10 19:15:13 -04:00
|
|
|
if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
|
2009-02-21 16:39:06 -05:00
|
|
|
$status = 404;
|
2006-10-03 23:54:10 -04:00
|
|
|
if ( !is_user_logged_in() )
|
2009-02-21 16:39:06 -05:00
|
|
|
$headers = array_merge($headers, wp_get_nocache_headers());
|
|
|
|
$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
|
2005-06-10 19:15:13 -04:00
|
|
|
} else if ( empty($this->query_vars['feed']) ) {
|
2009-02-21 16:39:06 -05:00
|
|
|
$headers['Content-Type'] = get_option('html_type') . '; charset=' . get_option('blog_charset');
|
2005-06-10 19:15:13 -04:00
|
|
|
} else {
|
|
|
|
// We're showing a feed, so WP is indeed the only thing that last changed
|
2008-02-02 13:42:09 -05:00
|
|
|
if ( !empty($this->query_vars['withcomments'])
|
|
|
|
|| ( empty($this->query_vars['withoutcomments'])
|
|
|
|
&& ( !empty($this->query_vars['p'])
|
|
|
|
|| !empty($this->query_vars['name'])
|
|
|
|
|| !empty($this->query_vars['page_id'])
|
|
|
|
|| !empty($this->query_vars['pagename'])
|
|
|
|
|| !empty($this->query_vars['attachment'])
|
|
|
|
|| !empty($this->query_vars['attachment_id'])
|
2006-11-18 15:46:43 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2005-06-10 19:15:13 -04:00
|
|
|
$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
|
2006-11-19 02:56:05 -05:00
|
|
|
else
|
2005-06-10 19:15:13 -04:00
|
|
|
$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
|
|
|
|
$wp_etag = '"' . md5($wp_last_modified) . '"';
|
2009-02-21 16:39:06 -05:00
|
|
|
$headers['Last-Modified'] = $wp_last_modified;
|
|
|
|
$headers['ETag'] = $wp_etag;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
|
|
|
// Support for Conditional GET
|
2006-11-19 02:56:05 -05:00
|
|
|
if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
|
2006-04-03 01:59:03 -04:00
|
|
|
$client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
|
2005-06-10 19:15:13 -04:00
|
|
|
else $client_etag = false;
|
|
|
|
|
2008-02-02 13:42:09 -05:00
|
|
|
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
2005-06-10 19:15:13 -04:00
|
|
|
// If string is empty, return 0. If not, attempt to parse into a timestamp
|
|
|
|
$client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
|
|
|
|
|
2006-02-12 02:53:23 -05:00
|
|
|
// Make a timestamp for our most recent modification...
|
2005-06-10 19:15:13 -04:00
|
|
|
$wp_modified_timestamp = strtotime($wp_last_modified);
|
|
|
|
|
|
|
|
if ( ($client_last_modified && $client_etag) ?
|
|
|
|
(($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
|
|
|
|
(($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
|
2009-02-21 16:39:06 -05:00
|
|
|
$status = 304;
|
2009-02-28 04:30:46 -05:00
|
|
|
$exit_required = true;
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
}
|
2006-05-22 15:23:46 -04:00
|
|
|
|
2009-03-17 22:43:45 -04:00
|
|
|
$headers = apply_filters('wp_headers', $headers, $this);
|
2009-02-21 16:39:06 -05:00
|
|
|
|
2009-03-17 22:43:45 -04:00
|
|
|
if ( ! empty( $status ) )
|
2009-02-21 16:39:06 -05:00
|
|
|
status_header( $status );
|
|
|
|
foreach( (array) $headers as $name => $field_value )
|
|
|
|
@header("{$name}: {$field_value}");
|
|
|
|
|
2009-02-28 04:30:46 -05:00
|
|
|
if ($exit_required)
|
|
|
|
exit();
|
|
|
|
|
2006-09-12 13:45:23 -04:00
|
|
|
do_action_ref_array('send_headers', array(&$this));
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Sets the query string property based off of the query variable property.
|
|
|
|
*
|
|
|
|
* The 'query_string' filter is deprecated, but still works. Plugins should
|
|
|
|
* use the 'request' filter instead.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function build_query_string() {
|
|
|
|
$this->query_string = '';
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) array_keys($this->query_vars) as $wpvar) {
|
2006-02-21 03:39:58 -05:00
|
|
|
if ( '' != $this->query_vars[$wpvar] ) {
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
|
2007-01-16 14:05:01 -05:00
|
|
|
if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
|
|
|
|
continue;
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 01:41:38 -04:00
|
|
|
// query_string filter deprecated. Use request filter instead.
|
2007-11-06 23:30:11 -05:00
|
|
|
if ( has_filter('query_string') ) { // Don't bother filtering and parsing if no plugins are hooked in.
|
2006-08-30 01:41:38 -04:00
|
|
|
$this->query_string = apply_filters('query_string', $this->query_string);
|
|
|
|
parse_str($this->query_string, $this->query_vars);
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
2010-03-17 00:39:50 -04:00
|
|
|
* Set up the WordPress Globals.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* The query_vars property will be extracted to the GLOBALS. So care should
|
|
|
|
* be taken when naming global variables that might interfere with the
|
|
|
|
* WordPress environment.
|
|
|
|
*
|
|
|
|
* @global string $query_string Query string for the loop.
|
|
|
|
* @global int $more Only set, if single page or post.
|
|
|
|
* @global int $single If single page or post. Only set, if single page or post.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function register_globals() {
|
|
|
|
global $wp_query;
|
|
|
|
// Extract updated query vars back into global namespace.
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $wp_query->query_vars as $key => $value) {
|
2005-06-10 19:15:13 -04:00
|
|
|
$GLOBALS[$key] = $value;
|
|
|
|
}
|
|
|
|
|
2009-05-20 12:05:23 -04:00
|
|
|
$GLOBALS['query_string'] = $this->query_string;
|
2005-06-10 19:15:13 -04:00
|
|
|
$GLOBALS['posts'] = & $wp_query->posts;
|
2010-10-07 17:23:50 -04:00
|
|
|
$GLOBALS['post'] = (isset($wp_query->post)) ? $wp_query->post : null;
|
2009-05-20 12:05:23 -04:00
|
|
|
$GLOBALS['request'] = $wp_query->request;
|
2005-06-10 19:15:13 -04:00
|
|
|
|
|
|
|
if ( is_single() || is_page() ) {
|
|
|
|
$GLOBALS['more'] = 1;
|
|
|
|
$GLOBALS['single'] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
2010-03-17 00:39:50 -04:00
|
|
|
* Set up the current user.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-12-18 17:08:01 -05:00
|
|
|
function init() {
|
2006-02-22 14:08:55 -05:00
|
|
|
wp_get_current_user();
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
2010-03-17 00:39:50 -04:00
|
|
|
* Set up the Loop based on the query variables.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* @uses WP::$query_vars
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function query_posts() {
|
2006-11-09 01:50:58 -05:00
|
|
|
global $wp_the_query;
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->build_query_string();
|
2006-11-09 01:50:58 -05:00
|
|
|
$wp_the_query->query($this->query_vars);
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
2010-02-22 17:54:21 -05:00
|
|
|
* Set the Headers for 404, if nothing is found for requested URL.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
2010-02-22 17:54:21 -05:00
|
|
|
* Issue a 404 if a request doesn't match any posts and doesn't match
|
|
|
|
* any object (e.g. an existing-but-empty category, tag, author) and a 404 was not already
|
|
|
|
* issued, and if the request was not a search or the homepage.
|
|
|
|
*
|
|
|
|
* Otherwise, issue a 200.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function handle_404() {
|
|
|
|
global $wp_query;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
2010-07-13 17:47:12 -04:00
|
|
|
if ( !is_admin() && ( 0 == count( $wp_query->posts ) ) && !is_404() && !is_robots() && !is_search() && !is_home() ) {
|
2008-08-28 15:58:57 -04:00
|
|
|
// Don't 404 for these queries if they matched an object.
|
2010-04-02 04:16:20 -04:00
|
|
|
if ( ( is_tag() || is_category() || is_tax() || is_author() ) && $wp_query->get_queried_object() && !is_paged() ) {
|
2008-08-28 15:58:57 -04:00
|
|
|
if ( !is_404() )
|
|
|
|
status_header( 200 );
|
|
|
|
return;
|
|
|
|
}
|
2005-09-15 23:16:12 -04:00
|
|
|
$wp_query->set_404();
|
2005-06-10 19:15:13 -04:00
|
|
|
status_header( 404 );
|
2006-10-03 23:54:10 -04:00
|
|
|
nocache_headers();
|
2008-08-28 15:58:57 -04:00
|
|
|
} elseif ( !is_404() ) {
|
2005-06-10 19:15:13 -04:00
|
|
|
status_header( 200 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Sets up all of the variables required by the WordPress environment.
|
|
|
|
*
|
|
|
|
* The action 'wp' has one parameter that references the WP object. It
|
|
|
|
* allows for accessing the properties and methods to further manipulate the
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @param string|array $query_args Passed to {@link parse_request()}
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function main($query_args = '') {
|
2005-12-18 17:08:01 -05:00
|
|
|
$this->init();
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->parse_request($query_args);
|
2005-11-10 20:44:41 -05:00
|
|
|
$this->send_headers();
|
2005-06-10 19:15:13 -04:00
|
|
|
$this->query_posts();
|
|
|
|
$this->handle_404();
|
|
|
|
$this->register_globals();
|
2006-09-12 13:45:23 -04:00
|
|
|
do_action_ref_array('wp', array(&$this));
|
2005-06-10 19:15:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* PHP4 Constructor - Does nothing.
|
|
|
|
*
|
2008-09-19 02:59:47 -04:00
|
|
|
* Call main() method when ready to run setup.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @return WP
|
|
|
|
*/
|
2005-06-10 19:15:13 -04:00
|
|
|
function WP() {
|
|
|
|
// Empty.
|
|
|
|
}
|
2004-12-02 21:38:11 -05:00
|
|
|
}
|
|
|
|
|
2010-10-04 14:57:13 -04:00
|
|
|
/**
|
|
|
|
* WordPress Query class.
|
|
|
|
*
|
|
|
|
* Abstract class for handling advanced queries
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 3.1.0
|
|
|
|
*/
|
|
|
|
class WP_Object_Query {
|
|
|
|
|
|
|
|
/**
|
2010-10-06 06:40:30 -04:00
|
|
|
* List of metadata queries
|
|
|
|
*
|
|
|
|
* A query is an associative array:
|
|
|
|
* - 'key' string The meta key
|
|
|
|
* - 'value' string|array The meta value
|
2010-10-07 22:27:22 -04:00
|
|
|
* - 'compare' (optional) string How to compare the key to the value.
|
|
|
|
* Possible values: '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN'.
|
2010-10-06 06:40:30 -04:00
|
|
|
* Default: '='
|
|
|
|
* - 'type' string (optional) The type of the value.
|
2010-10-07 22:27:22 -04:00
|
|
|
* Possible values: 'NUMERIC', 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED'.
|
2010-10-06 06:40:30 -04:00
|
|
|
* Default: 'CHAR'
|
2010-10-04 14:57:13 -04:00
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $meta_query = array();
|
|
|
|
|
2010-10-06 06:40:30 -04:00
|
|
|
/*
|
|
|
|
* List of taxonomy queries
|
|
|
|
*
|
|
|
|
* A query is an associative array:
|
|
|
|
* - 'taxonomy' string|array The taxonomy being queried
|
|
|
|
* - 'terms' string|array The list of terms
|
|
|
|
* - 'field' string (optional) Which term field is being used.
|
|
|
|
* Possible values: 'term_id', 'slug' or 'name'
|
|
|
|
* Default: 'slug'
|
|
|
|
* - 'operator' string (optional)
|
2010-10-07 22:27:22 -04:00
|
|
|
* Possible values: 'IN' and 'NOT IN'.
|
2010-10-06 06:40:30 -04:00
|
|
|
* Default: 'IN'
|
2010-10-07 22:35:06 -04:00
|
|
|
* - 'include_children' bool (optional) Whether to include child terms.
|
2010-10-06 06:40:30 -04:00
|
|
|
* Default: true
|
|
|
|
*
|
|
|
|
* @since 3.1.0
|
|
|
|
* @access public
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $tax_query = array();
|
|
|
|
|
2010-10-04 14:57:13 -04:00
|
|
|
/*
|
|
|
|
* Populates the $meta_query property
|
|
|
|
*
|
2010-10-04 17:05:31 -04:00
|
|
|
* @access protected
|
2010-10-04 14:57:13 -04:00
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @param array $qv The query variables
|
|
|
|
*/
|
|
|
|
function parse_meta_query( $qv ) {
|
2010-10-05 19:06:20 -04:00
|
|
|
if ( ! empty( $qv['meta_query'] ) && is_array( $qv['meta_query'] ) ) {
|
2010-10-04 14:57:13 -04:00
|
|
|
$this->meta_query = $qv['meta_query'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$meta_query = array();
|
2010-10-05 19:06:20 -04:00
|
|
|
foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
|
|
|
|
if ( ! empty( $qv[ "meta_$key" ] ) )
|
2010-10-04 14:57:13 -04:00
|
|
|
$meta_query[ $key ] = $qv[ "meta_$key" ];
|
|
|
|
}
|
|
|
|
|
2010-10-05 19:06:20 -04:00
|
|
|
if ( ! empty( $meta_query ) ) {
|
2010-10-04 16:19:21 -04:00
|
|
|
array_unshift( $this->meta_query, $meta_query );
|
2010-10-04 14:57:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used internally to generate an SQL string for searching across multiple meta key = value pairs
|
|
|
|
*
|
2010-10-04 17:05:31 -04:00
|
|
|
* @access protected
|
2010-10-04 14:57:13 -04:00
|
|
|
* @since 3.1.0
|
|
|
|
*
|
2010-10-06 06:40:30 -04:00
|
|
|
* @uses $this->meta_query
|
|
|
|
*
|
2010-10-04 14:57:13 -04:00
|
|
|
* @param string $primary_table
|
|
|
|
* @param string $primary_id_column
|
|
|
|
* @param string $meta_table
|
|
|
|
* @param string $meta_id_column
|
|
|
|
* @return array( $join_sql, $where_sql )
|
|
|
|
*/
|
|
|
|
function get_meta_sql( $primary_table, $primary_id_column, $meta_table, $meta_id_column ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$clauses = array();
|
|
|
|
|
|
|
|
$join = '';
|
|
|
|
$where = '';
|
|
|
|
$i = 0;
|
|
|
|
foreach ( $this->meta_query as $q ) {
|
|
|
|
$meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_value = isset( $q['value'] ) ? $q['value'] : '';
|
|
|
|
$meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
|
|
|
|
$meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
|
2010-10-04 14:57:13 -04:00
|
|
|
|
2010-10-07 22:27:22 -04:00
|
|
|
if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
|
2010-10-04 14:57:13 -04:00
|
|
|
$meta_compare = '=';
|
|
|
|
|
2010-10-05 19:06:20 -04:00
|
|
|
if ( 'NUMERIC' == $meta_type )
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_type = 'SIGNED';
|
2010-10-05 19:06:20 -04:00
|
|
|
elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_type = 'CHAR';
|
|
|
|
|
2010-10-04 14:57:13 -04:00
|
|
|
if ( empty( $meta_key ) && empty( $meta_value ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$alias = $i ? 'mt' . $i : $meta_table;
|
|
|
|
|
|
|
|
$join .= "\nINNER JOIN $meta_table";
|
|
|
|
$join .= $i ? " AS $alias" : '';
|
|
|
|
$join .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)";
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
|
|
if ( !empty( $meta_key ) )
|
|
|
|
$where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
|
|
|
|
|
2010-10-07 22:27:22 -04:00
|
|
|
if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
|
2010-10-05 19:06:20 -04:00
|
|
|
if ( ! is_array( $meta_value ) )
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_value = preg_split( '/[,\s]+/', $meta_value );
|
|
|
|
} else {
|
|
|
|
$meta_value = trim( $meta_value );
|
|
|
|
}
|
|
|
|
|
2010-10-04 14:57:13 -04:00
|
|
|
if ( empty( $meta_value ) )
|
|
|
|
continue;
|
|
|
|
|
2010-10-07 22:27:22 -04:00
|
|
|
if ( 'IN' == substr( $meta_compare, -2) ) {
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_field_types = substr( str_repeat( ',%s', count( $meta_value ) ), 1 );
|
|
|
|
$meta_compare_string = "($meta_field_types)";
|
|
|
|
unset( $meta_field_types );
|
2010-10-07 22:27:22 -04:00
|
|
|
} elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) {
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_value = array_slice( $meta_value, 0, 2 );
|
|
|
|
$meta_compare_string = '%s AND %s';
|
2010-10-07 22:27:22 -04:00
|
|
|
} elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) {
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_value = '%' . like_escape( $meta_value ) . '%';
|
|
|
|
$meta_compare_string = '%s';
|
2010-10-04 14:57:13 -04:00
|
|
|
} else {
|
2010-10-04 17:37:08 -04:00
|
|
|
$meta_compare_string = '%s';
|
2010-10-04 14:57:13 -04:00
|
|
|
}
|
2010-10-04 17:37:08 -04:00
|
|
|
$where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
|
|
|
|
unset($meta_compare_string);
|
2010-10-04 14:57:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return array( $join, $where );
|
|
|
|
}
|
2010-10-04 17:05:31 -04:00
|
|
|
|
2010-10-06 06:40:30 -04:00
|
|
|
/*
|
|
|
|
* Used internally to generate an SQL string for searching across multiple taxonomies
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @uses $this->tax_query
|
|
|
|
*
|
|
|
|
* @param string $object_id_column
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_tax_sql( $object_id_column ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$sql = array();
|
|
|
|
foreach ( $this->tax_query as $query ) {
|
|
|
|
if ( !isset( $query['include_children'] ) )
|
|
|
|
$query['include_children'] = true;
|
2010-10-06 08:06:23 -04:00
|
|
|
|
2010-10-06 06:40:30 -04:00
|
|
|
$query['do_query'] = false;
|
2010-10-07 22:27:22 -04:00
|
|
|
|
2010-10-06 08:06:23 -04:00
|
|
|
$sql_single = get_objects_in_term( $query['terms'], $query['taxonomy'], $query );
|
|
|
|
|
|
|
|
if ( empty( $sql_single ) )
|
|
|
|
return ' AND 0 = 1';
|
|
|
|
|
|
|
|
$sql[] = $sql_single;
|
2010-10-06 06:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( 1 == count( $sql ) ) {
|
|
|
|
$ids = $wpdb->get_col( $sql[0] );
|
|
|
|
} else {
|
|
|
|
$r = "SELECT object_id FROM $wpdb->term_relationships WHERE 1=1";
|
|
|
|
foreach ( $sql as $query )
|
|
|
|
$r .= " AND object_id IN ($query)";
|
|
|
|
|
|
|
|
$ids = $wpdb->get_col( $r );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !empty( $ids ) )
|
|
|
|
return " AND $object_id_column IN(" . implode( ', ', $ids ) . ")";
|
|
|
|
else
|
|
|
|
return ' AND 0 = 1';
|
|
|
|
}
|
|
|
|
|
2010-10-04 17:05:31 -04:00
|
|
|
/*
|
|
|
|
* Used internally to generate an SQL string for searching across multiple columns
|
|
|
|
*
|
|
|
|
* @access protected
|
|
|
|
* @since 3.1.0
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @param array $cols
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get_search_sql( $string, $cols ) {
|
|
|
|
$string = esc_sql( $string );
|
|
|
|
|
|
|
|
$searches = array();
|
|
|
|
foreach ( $cols as $col )
|
|
|
|
$searches[] = "$col LIKE '%$string%'";
|
|
|
|
|
|
|
|
return ' AND (' . implode(' OR ', $searches) . ')';
|
|
|
|
}
|
2010-10-04 14:57:13 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* WordPress Error class.
|
|
|
|
*
|
|
|
|
* Container for checking for WordPress errors and error messages. Return
|
|
|
|
* WP_Error and use {@link is_wp_error()} to check if this class is returned.
|
|
|
|
* Many core WordPress functions pass this class in the event of an error and
|
|
|
|
* if not handled properly will result in code errors.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
class WP_Error {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Stores the list of errors.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
var $errors = array();
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the list of data for error codes.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-08-29 16:17:41 -04:00
|
|
|
var $error_data = array();
|
2006-03-30 18:18:14 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* PHP4 Constructor - Sets up error message.
|
|
|
|
*
|
|
|
|
* If code parameter is empty then nothing will be done. It is possible to
|
|
|
|
* add multiple messages to the same code, but with other methods in the
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* All parameters are optional, but if the code parameter is set, then the
|
|
|
|
* data parameter is optional.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string|int $code Error code
|
|
|
|
* @param string $message Error message
|
|
|
|
* @param mixed $data Optional. Error data.
|
|
|
|
* @return WP_Error
|
|
|
|
*/
|
2006-08-29 16:17:41 -04:00
|
|
|
function WP_Error($code = '', $message = '', $data = '') {
|
|
|
|
if ( empty($code) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$this->errors[$code][] = $message;
|
|
|
|
|
|
|
|
if ( ! empty($data) )
|
|
|
|
$this->error_data[$code] = $data;
|
2006-03-30 18:18:14 -05:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Retrieve all error codes.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @return array List of error codes, if avaiable.
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
function get_error_codes() {
|
|
|
|
if ( empty($this->errors) )
|
|
|
|
return array();
|
|
|
|
|
|
|
|
return array_keys($this->errors);
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Retrieve first error code available.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @return string|int Empty string, if no error codes.
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
function get_error_code() {
|
|
|
|
$codes = $this->get_error_codes();
|
|
|
|
|
|
|
|
if ( empty($codes) )
|
|
|
|
return '';
|
|
|
|
|
2006-11-19 02:56:05 -05:00
|
|
|
return $codes[0];
|
2006-03-30 18:18:14 -05:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Retrieve all error messages or error messages matching code.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string|int $code Optional. Retrieve messages matching code, if exists.
|
|
|
|
* @return array Error strings on success, or empty array on failure (if using codee parameter).
|
|
|
|
*/
|
2006-04-01 19:48:14 -05:00
|
|
|
function get_error_messages($code = '') {
|
|
|
|
// Return all messages if no code specified.
|
|
|
|
if ( empty($code) ) {
|
|
|
|
$all_messages = array();
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $this->errors as $code => $messages )
|
2006-04-01 19:48:14 -05:00
|
|
|
$all_messages = array_merge($all_messages, $messages);
|
|
|
|
|
|
|
|
return $all_messages;
|
|
|
|
}
|
|
|
|
|
2006-03-30 18:18:14 -05:00
|
|
|
if ( isset($this->errors[$code]) )
|
|
|
|
return $this->errors[$code];
|
|
|
|
else
|
2006-11-19 02:56:05 -05:00
|
|
|
return array();
|
2006-03-30 18:18:14 -05:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Get single error message.
|
|
|
|
*
|
|
|
|
* This will get the first message available for the code. If no code is
|
|
|
|
* given then the first code available will be used.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string|int $code Optional. Error code to retrieve message.
|
|
|
|
* @return string
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
function get_error_message($code = '') {
|
|
|
|
if ( empty($code) )
|
|
|
|
$code = $this->get_error_code();
|
|
|
|
$messages = $this->get_error_messages($code);
|
|
|
|
if ( empty($messages) )
|
|
|
|
return '';
|
|
|
|
return $messages[0];
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Retrieve error data for error code.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string|int $code Optional. Error code.
|
|
|
|
* @return mixed Null, if no errors.
|
|
|
|
*/
|
2006-08-29 16:17:41 -04:00
|
|
|
function get_error_data($code = '') {
|
|
|
|
if ( empty($code) )
|
|
|
|
$code = $this->get_error_code();
|
|
|
|
|
|
|
|
if ( isset($this->error_data[$code]) )
|
|
|
|
return $this->error_data[$code];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Append more error messages to list of error messages.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @access public
|
|
|
|
*
|
|
|
|
* @param string|int $code Error code.
|
|
|
|
* @param string $message Error message.
|
|
|
|
* @param mixed $data Optional. Error data.
|
|
|
|
*/
|
2006-08-29 16:17:41 -04:00
|
|
|
function add($code, $message, $data = '') {
|
|
|
|
$this->errors[$code][] = $message;
|
|
|
|
if ( ! empty($data) )
|
|
|
|
$this->error_data[$code] = $data;
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Add data for error code.
|
|
|
|
*
|
|
|
|
* The error code can only contain one error data.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param mixed $data Error data.
|
|
|
|
* @param string|int $code Error code.
|
|
|
|
*/
|
2006-08-29 16:17:41 -04:00
|
|
|
function add_data($data, $code = '') {
|
|
|
|
if ( empty($code) )
|
|
|
|
$code = $this->get_error_code();
|
|
|
|
|
|
|
|
$this->error_data[$code] = $data;
|
2006-03-30 18:18:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Check whether variable is a WordPress Error.
|
|
|
|
*
|
|
|
|
* Looks at the object and if a WP_Error class. Does not check to see if the
|
|
|
|
* parent is also WP_Error, so can't inherit WP_Error and still use this
|
|
|
|
* function.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param mixed $thing Check if unknown variable is WordPress Error object.
|
|
|
|
* @return bool True, if WP_Error. False, if not WP_Error.
|
|
|
|
*/
|
2006-03-30 18:18:14 -05:00
|
|
|
function is_wp_error($thing) {
|
|
|
|
if ( is_object($thing) && is_a($thing, 'WP_Error') )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
2008-02-05 01:47:27 -05:00
|
|
|
* A class for displaying various tree-like structures.
|
2008-09-15 20:37:05 -04:00
|
|
|
*
|
|
|
|
* Extend the Walker class to use it, see examples at the below. Child classes
|
|
|
|
* do not need to implement all of the abstract methods in the class. The child
|
|
|
|
* only needs to implement the methods that are needed. Also, the methods are
|
|
|
|
* not strictly abstract in that the parameter definition needs to be followed.
|
|
|
|
* The child classes can have additional parameters.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
* @abstract
|
2007-12-14 16:46:52 -05:00
|
|
|
*/
|
2006-11-19 02:56:05 -05:00
|
|
|
class Walker {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* What the class handles.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $tree_type;
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* DB fields to use.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var array
|
|
|
|
* @access protected
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $db_fields;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
/**
|
2008-12-09 13:03:31 -05:00
|
|
|
* Max number of pages walked by the paged walker
|
2008-09-23 17:11:27 -04:00
|
|
|
*
|
|
|
|
* @since 2.7.0
|
|
|
|
* @var int
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
var $max_pages = 1;
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Starts the list before the elements are added.
|
|
|
|
*
|
|
|
|
* Additional parameters are used in child classes. The args parameter holds
|
|
|
|
* additional values that may be used with the child class methods. This
|
|
|
|
* method is called at the start of the output list.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_lvl(&$output) {}
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ends the list of after the elements are added.
|
|
|
|
*
|
|
|
|
* Additional parameters are used in child classes. The args parameter holds
|
|
|
|
* additional values that may be used with the child class methods. This
|
|
|
|
* method finishes the list at the end of output of the elements.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_lvl(&$output) {}
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the element output.
|
|
|
|
*
|
|
|
|
* Additional parameters are used in child classes. The args parameter holds
|
|
|
|
* additional values that may be used with the child class methods. Includes
|
|
|
|
* the element output also.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_el(&$output) {}
|
2008-09-15 20:37:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ends the element output, if needed.
|
|
|
|
*
|
|
|
|
* Additional parameters are used in child classes. The args parameter holds
|
|
|
|
* additional values that may be used with the child class methods.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @abstract
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_el(&$output) {}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Traverse elements to create list from elements.
|
|
|
|
*
|
|
|
|
* Display one element if the element doesn't have any children otherwise,
|
|
|
|
* display the element and its children. Will only traverse up to the max
|
|
|
|
* depth and no ignore elements under that depth. It is possible to set the
|
|
|
|
* max depth to include all depths, see walk() method.
|
|
|
|
*
|
|
|
|
* This method shouldn't be called directly, use the walk() method instead.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param object $element Data object
|
|
|
|
* @param array $children_elements List of elements to continue traversing.
|
|
|
|
* @param int $max_depth Max depth to traverse.
|
|
|
|
* @param int $depth Depth of current element.
|
|
|
|
* @param array $args
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @return null Null on failure with no changes to parameters.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2008-04-21 15:30:54 -04:00
|
|
|
if ( !$element )
|
|
|
|
return;
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$id_field = $this->db_fields['id'];
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-14 16:46:52 -05:00
|
|
|
//display this element
|
2008-11-21 12:17:18 -05:00
|
|
|
if ( is_array( $args[0] ) )
|
2008-11-20 08:36:44 -05:00
|
|
|
$args[0]['has_children'] = ! empty( $children_elements[$element->$id_field] );
|
2008-04-21 15:30:54 -04:00
|
|
|
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
|
|
|
call_user_func_array(array(&$this, 'start_el'), $cb_args);
|
2007-12-14 16:46:52 -05:00
|
|
|
|
2008-08-09 01:36:14 -04:00
|
|
|
$id = $element->$id_field;
|
|
|
|
|
2008-09-19 02:59:47 -04:00
|
|
|
// descend only when the depth is right and there are childrens for this element
|
2008-08-09 01:36:14 -04:00
|
|
|
if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
|
2008-07-29 18:50:57 -04:00
|
|
|
|
|
|
|
foreach( $children_elements[ $id ] as $child ){
|
2008-08-09 01:36:14 -04:00
|
|
|
|
2008-07-29 18:50:57 -04:00
|
|
|
if ( !isset($newlevel) ) {
|
|
|
|
$newlevel = true;
|
|
|
|
//start the child delimiter
|
|
|
|
$cb_args = array_merge( array(&$output, $depth), $args);
|
|
|
|
call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
|
2008-02-15 02:34:52 -05:00
|
|
|
}
|
2008-07-29 18:50:57 -04:00
|
|
|
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
2008-08-09 01:36:14 -04:00
|
|
|
unset( $children_elements[ $id ] );
|
2007-12-14 16:46:52 -05:00
|
|
|
}
|
2008-03-02 15:17:30 -05:00
|
|
|
|
2008-02-15 02:34:52 -05:00
|
|
|
if ( isset($newlevel) && $newlevel ){
|
2007-12-16 15:31:44 -05:00
|
|
|
//end the child delimiter
|
2008-04-21 15:30:54 -04:00
|
|
|
$cb_args = array_merge( array(&$output, $depth), $args);
|
|
|
|
call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
|
2007-12-16 15:31:44 -05:00
|
|
|
}
|
2008-03-02 15:17:30 -05:00
|
|
|
|
2008-02-15 02:34:52 -05:00
|
|
|
//end this element
|
2008-04-21 15:30:54 -04:00
|
|
|
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
|
|
|
call_user_func_array(array(&$this, 'end_el'), $cb_args);
|
2007-12-14 16:46:52 -05:00
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Display array of elements hierarchically.
|
|
|
|
*
|
|
|
|
* It is a generic function which does not assume any existing order of
|
|
|
|
* elements. max_depth = -1 means flatly display every element. max_depth =
|
|
|
|
* 0 means display all levels. max_depth > 0 specifies the number of
|
|
|
|
* display levels.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param array $elements
|
|
|
|
* @param int $max_depth
|
|
|
|
* @return string
|
|
|
|
*/
|
2007-12-14 16:46:52 -05:00
|
|
|
function walk( $elements, $max_depth) {
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-14 16:46:52 -05:00
|
|
|
$args = array_slice(func_get_args(), 2);
|
|
|
|
$output = '';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2007-12-16 15:31:44 -05:00
|
|
|
if ($max_depth < -1) //invalid parameter
|
2008-02-05 01:47:27 -05:00
|
|
|
return $output;
|
|
|
|
|
2007-12-21 13:49:20 -05:00
|
|
|
if (empty($elements)) //nothing to walk
|
2008-02-05 01:47:27 -05:00
|
|
|
return $output;
|
|
|
|
|
2007-12-14 16:46:52 -05:00
|
|
|
$id_field = $this->db_fields['id'];
|
|
|
|
$parent_field = $this->db_fields['parent'];
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-21 13:49:20 -05:00
|
|
|
// flat display
|
|
|
|
if ( -1 == $max_depth ) {
|
2008-02-05 01:47:27 -05:00
|
|
|
$empty_array = array();
|
|
|
|
foreach ( $elements as $e )
|
2008-04-21 15:30:54 -04:00
|
|
|
$this->display_element( $e, $empty_array, 1, 0, $args, $output );
|
2008-02-05 01:47:27 -05:00
|
|
|
return $output;
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
2008-02-05 01:47:27 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* need to display in hierarchical order
|
2010-02-26 00:46:08 -05:00
|
|
|
* separate elements into two buckets: top level and children elements
|
2008-08-09 01:36:14 -04:00
|
|
|
* children_elements is two dimensional array, eg.
|
|
|
|
* children_elements[10][] contains all sub-elements whose parent is 10.
|
2007-12-14 16:46:52 -05:00
|
|
|
*/
|
|
|
|
$top_level_elements = array();
|
|
|
|
$children_elements = array();
|
|
|
|
foreach ( $elements as $e) {
|
|
|
|
if ( 0 == $e->$parent_field )
|
2008-02-05 01:47:27 -05:00
|
|
|
$top_level_elements[] = $e;
|
2007-12-14 16:46:52 -05:00
|
|
|
else
|
2008-07-29 18:50:57 -04:00
|
|
|
$children_elements[ $e->$parent_field ][] = $e;
|
2007-12-14 16:46:52 -05:00
|
|
|
}
|
2010-03-26 15:36:49 -04:00
|
|
|
|
2008-02-05 01:47:27 -05:00
|
|
|
/*
|
2008-07-29 18:50:57 -04:00
|
|
|
* when none of the elements is top level
|
|
|
|
* assume the first one must be root of the sub elements
|
2007-12-21 13:49:20 -05:00
|
|
|
*/
|
2008-07-29 18:50:57 -04:00
|
|
|
if ( empty($top_level_elements) ) {
|
|
|
|
|
2008-12-09 13:03:31 -05:00
|
|
|
$first = array_slice( $elements, 0, 1 );
|
|
|
|
$root = $first[0];
|
2008-08-09 01:36:14 -04:00
|
|
|
|
2008-07-29 18:50:57 -04:00
|
|
|
$top_level_elements = array();
|
|
|
|
$children_elements = array();
|
|
|
|
foreach ( $elements as $e) {
|
|
|
|
if ( $root->$parent_field == $e->$parent_field )
|
|
|
|
$top_level_elements[] = $e;
|
|
|
|
else
|
|
|
|
$children_elements[ $e->$parent_field ][] = $e;
|
2007-12-21 13:49:20 -05:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-12-14 16:46:52 -05:00
|
|
|
foreach ( $top_level_elements as $e )
|
2008-04-21 15:30:54 -04:00
|
|
|
$this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2008-09-19 02:59:47 -04:00
|
|
|
/*
|
|
|
|
* if we are displaying all levels, and remaining children_elements is not empty,
|
2008-09-15 20:37:05 -04:00
|
|
|
* then we got orphans, which should be displayed regardless
|
|
|
|
*/
|
2008-08-06 16:31:54 -04:00
|
|
|
if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
|
2008-02-05 01:47:27 -05:00
|
|
|
$empty_array = array();
|
2008-07-29 18:50:57 -04:00
|
|
|
foreach ( $children_elements as $orphans )
|
|
|
|
foreach( $orphans as $op )
|
|
|
|
$this->display_element( $op, $empty_array, 1, 0, $args, $output );
|
2007-12-14 16:46:52 -05:00
|
|
|
}
|
2008-08-09 01:36:14 -04:00
|
|
|
|
2007-12-14 16:46:52 -05:00
|
|
|
return $output;
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
2008-09-19 02:59:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* paged_walk() - produce a page of nested elements
|
|
|
|
*
|
|
|
|
* Given an array of hierarchical elements, the maximum depth, a specific page number,
|
|
|
|
* and number of elements per page, this function first determines all top level root elements
|
|
|
|
* belonging to that page, then lists them and all of their children in hierarchical order.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.7
|
2010-09-07 07:21:11 -04:00
|
|
|
* @param int $max_depth = 0 means display all levels; $max_depth > 0 specifies the number of display levels.
|
|
|
|
* @param int $page_num the specific page number, beginning with 1.
|
2008-09-19 02:59:47 -04:00
|
|
|
* @return XHTML of the specified page of elements
|
|
|
|
*/
|
|
|
|
function paged_walk( $elements, $max_depth, $page_num, $per_page ) {
|
|
|
|
|
|
|
|
/* sanity check */
|
2008-09-23 17:11:27 -04:00
|
|
|
if ( empty($elements) || $max_depth < -1 )
|
2008-09-19 02:59:47 -04:00
|
|
|
return '';
|
|
|
|
|
|
|
|
$args = array_slice( func_get_args(), 4 );
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$id_field = $this->db_fields['id'];
|
|
|
|
$parent_field = $this->db_fields['parent'];
|
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
$count = -1;
|
|
|
|
if ( -1 == $max_depth )
|
|
|
|
$total_top = count( $elements );
|
|
|
|
if ( $page_num < 1 || $per_page < 0 ) {
|
|
|
|
// No paging
|
|
|
|
$paging = false;
|
|
|
|
$start = 0;
|
|
|
|
if ( -1 == $max_depth )
|
|
|
|
$end = $total_top;
|
|
|
|
$this->max_pages = 1;
|
|
|
|
} else {
|
|
|
|
$paging = true;
|
|
|
|
$start = ( (int)$page_num - 1 ) * (int)$per_page;
|
|
|
|
$end = $start + $per_page;
|
|
|
|
if ( -1 == $max_depth )
|
|
|
|
$this->max_pages = ceil($total_top / $per_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
// flat display
|
|
|
|
if ( -1 == $max_depth ) {
|
2008-10-23 12:08:47 -04:00
|
|
|
if ( !empty($args[0]['reverse_top_level']) ) {
|
|
|
|
$elements = array_reverse( $elements );
|
|
|
|
$oldstart = $start;
|
|
|
|
$start = $total_top - $end;
|
|
|
|
$end = $total_top - $oldstart;
|
|
|
|
}
|
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
$empty_array = array();
|
|
|
|
foreach ( $elements as $e ) {
|
|
|
|
$count++;
|
|
|
|
if ( $count < $start )
|
|
|
|
continue;
|
|
|
|
if ( $count >= $end )
|
|
|
|
break;
|
|
|
|
$this->display_element( $e, $empty_array, 1, 0, $args, $output );
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2008-09-19 02:59:47 -04:00
|
|
|
/*
|
2010-02-26 00:46:08 -05:00
|
|
|
* separate elements into two buckets: top level and children elements
|
2008-09-19 02:59:47 -04:00
|
|
|
* children_elements is two dimensional array, eg.
|
|
|
|
* children_elements[10][] contains all sub-elements whose parent is 10.
|
|
|
|
*/
|
|
|
|
$top_level_elements = array();
|
|
|
|
$children_elements = array();
|
|
|
|
foreach ( $elements as $e) {
|
|
|
|
if ( 0 == $e->$parent_field )
|
|
|
|
$top_level_elements[] = $e;
|
|
|
|
else
|
|
|
|
$children_elements[ $e->$parent_field ][] = $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
$total_top = count( $top_level_elements );
|
2008-09-23 17:11:27 -04:00
|
|
|
if ( $paging )
|
|
|
|
$this->max_pages = ceil($total_top / $per_page);
|
2008-09-24 01:20:17 -04:00
|
|
|
else
|
|
|
|
$end = $total_top;
|
2008-09-19 02:59:47 -04:00
|
|
|
|
2008-10-23 12:08:47 -04:00
|
|
|
if ( !empty($args[0]['reverse_top_level']) ) {
|
|
|
|
$top_level_elements = array_reverse( $top_level_elements );
|
|
|
|
$oldstart = $start;
|
|
|
|
$start = $total_top - $end;
|
|
|
|
$end = $total_top - $oldstart;
|
|
|
|
}
|
|
|
|
if ( !empty($args[0]['reverse_children']) ) {
|
|
|
|
foreach ( $children_elements as $parent => $children )
|
|
|
|
$children_elements[$parent] = array_reverse( $children );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( $top_level_elements as $e ) {
|
2008-09-19 02:59:47 -04:00
|
|
|
$count++;
|
|
|
|
|
|
|
|
//for the last page, need to unset earlier children in order to keep track of orphans
|
|
|
|
if ( $end >= $total_top && $count < $start )
|
|
|
|
$this->unset_children( $e, $children_elements );
|
|
|
|
|
|
|
|
if ( $count < $start )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( $count >= $end )
|
|
|
|
break;
|
|
|
|
|
|
|
|
$this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
|
|
|
|
}
|
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
if ( $end >= $total_top && count( $children_elements ) > 0 ) {
|
2008-09-19 02:59:47 -04:00
|
|
|
$empty_array = array();
|
|
|
|
foreach ( $children_elements as $orphans )
|
|
|
|
foreach( $orphans as $op )
|
|
|
|
$this->display_element( $op, $empty_array, 1, 0, $args, $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_number_of_root_elements( $elements ){
|
|
|
|
|
|
|
|
$num = 0;
|
|
|
|
$parent_field = $this->db_fields['parent'];
|
|
|
|
|
|
|
|
foreach ( $elements as $e) {
|
|
|
|
if ( 0 == $e->$parent_field )
|
|
|
|
$num++;
|
|
|
|
}
|
|
|
|
return $num;
|
|
|
|
}
|
|
|
|
|
|
|
|
// unset all the children for a given top level element
|
|
|
|
function unset_children( $e, &$children_elements ){
|
|
|
|
|
|
|
|
if ( !$e || !$children_elements )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$id_field = $this->db_fields['id'];
|
|
|
|
$id = $e->$id_field;
|
|
|
|
|
2008-11-04 15:16:54 -05:00
|
|
|
if ( !empty($children_elements[$id]) && is_array($children_elements[$id]) )
|
|
|
|
foreach ( (array) $children_elements[$id] as $child )
|
|
|
|
$this->unset_children( $child, $children_elements );
|
2008-09-19 02:59:47 -04:00
|
|
|
|
2008-09-23 17:11:27 -04:00
|
|
|
if ( isset($children_elements[$id]) )
|
|
|
|
unset( $children_elements[$id] );
|
2008-09-19 02:59:47 -04:00
|
|
|
|
|
|
|
}
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Create HTML list of pages.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
* @uses Walker
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
class Walker_Page extends Walker {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$tree_type
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $tree_type = 'page';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$db_fields
|
|
|
|
* @since 2.1.0
|
|
|
|
* @todo Decouple this.
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Walker::start_lvl()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param int $depth Depth of page. Used for padding.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_lvl(&$output, $depth) {
|
2006-04-13 00:40:48 -04:00
|
|
|
$indent = str_repeat("\t", $depth);
|
2010-05-19 13:24:28 -04:00
|
|
|
$output .= "\n$indent<ul class='children'>\n";
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::end_lvl()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param int $depth Depth of page. Used for padding.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_lvl(&$output, $depth) {
|
2006-04-13 00:40:48 -04:00
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent</ul>\n";
|
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::start_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $page Page data object.
|
|
|
|
* @param int $depth Depth of page. Used for padding.
|
|
|
|
* @param int $current_page Page ID.
|
|
|
|
* @param array $args
|
|
|
|
*/
|
2008-11-21 12:17:18 -05:00
|
|
|
function start_el(&$output, $page, $depth, $args, $current_page) {
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( $depth )
|
|
|
|
$indent = str_repeat("\t", $depth);
|
2007-12-20 16:25:12 -05:00
|
|
|
else
|
|
|
|
$indent = '';
|
2008-02-05 01:47:27 -05:00
|
|
|
|
2007-06-14 18:45:40 -04:00
|
|
|
extract($args, EXTR_SKIP);
|
2009-03-18 17:43:51 -04:00
|
|
|
$css_class = array('page_item', 'page-item-'.$page->ID);
|
2008-03-24 16:30:33 -04:00
|
|
|
if ( !empty($current_page) ) {
|
|
|
|
$_current_page = get_page( $current_page );
|
2008-12-02 14:05:24 -05:00
|
|
|
if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
|
2009-03-18 17:43:51 -04:00
|
|
|
$css_class[] = 'current_page_ancestor';
|
2008-03-24 16:30:33 -04:00
|
|
|
if ( $page->ID == $current_page )
|
2009-03-18 17:43:51 -04:00
|
|
|
$css_class[] = 'current_page_item';
|
2008-03-24 16:30:33 -04:00
|
|
|
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
|
2009-03-18 17:43:51 -04:00
|
|
|
$css_class[] = 'current_page_parent';
|
2008-11-03 01:10:18 -05:00
|
|
|
} elseif ( $page->ID == get_option('page_for_posts') ) {
|
2009-03-18 17:43:51 -04:00
|
|
|
$css_class[] = 'current_page_parent';
|
2008-03-24 16:30:33 -04:00
|
|
|
}
|
2009-04-20 14:18:39 -04:00
|
|
|
|
|
|
|
$css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
|
2006-04-13 00:40:48 -04:00
|
|
|
|
2010-09-07 00:31:07 -04:00
|
|
|
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( !empty($show_date) ) {
|
|
|
|
if ( 'modified' == $show_date )
|
|
|
|
$time = $page->post_modified;
|
|
|
|
else
|
|
|
|
$time = $page->post_date;
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$output .= " " . mysql2date($date_format, $time);
|
|
|
|
}
|
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::end_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $page Page data object. Not used.
|
|
|
|
* @param int $depth Depth of page. Not Used.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_el(&$output, $page, $depth) {
|
2006-04-13 00:40:48 -04:00
|
|
|
$output .= "</li>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Create HTML dropdown list of pages.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
* @uses Walker
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
class Walker_PageDropdown extends Walker {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$tree_type
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $tree_type = 'page';
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$db_fields
|
|
|
|
* @since 2.1.0
|
|
|
|
* @todo Decouple this
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Walker::start_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $page Page data object.
|
|
|
|
* @param int $depth Depth of page in reference to parent pages. Used for padding.
|
|
|
|
* @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_el(&$output, $page, $depth, $args) {
|
|
|
|
$pad = str_repeat(' ', $depth * 3);
|
2006-04-13 00:40:48 -04:00
|
|
|
|
2008-12-05 14:19:24 -05:00
|
|
|
$output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
|
2008-04-21 15:30:54 -04:00
|
|
|
if ( $page->ID == $args['selected'] )
|
|
|
|
$output .= ' selected="selected"';
|
|
|
|
$output .= '>';
|
2009-05-18 11:11:07 -04:00
|
|
|
$title = esc_html($page->post_title);
|
2008-04-21 15:30:54 -04:00
|
|
|
$output .= "$pad$title";
|
|
|
|
$output .= "</option>\n";
|
2006-04-13 00:40:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Create HTML list of categories.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
* @uses Walker
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
class Walker_Category extends Walker {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$tree_type
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $tree_type = 'category';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$db_fields
|
|
|
|
* @since 2.1.0
|
|
|
|
* @todo Decouple this
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Walker::start_lvl()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param int $depth Depth of category. Used for tab indentation.
|
|
|
|
* @param array $args Will only append content if style argument value is 'list'.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_lvl(&$output, $depth, $args) {
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( 'list' != $args['style'] )
|
2008-04-21 15:30:54 -04:00
|
|
|
return;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent<ul class='children'>\n";
|
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::end_lvl()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param int $depth Depth of category. Used for tab indentation.
|
|
|
|
* @param array $args Will only append content if style argument value is 'list'.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_lvl(&$output, $depth, $args) {
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( 'list' != $args['style'] )
|
2008-04-21 15:30:54 -04:00
|
|
|
return;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent</ul>\n";
|
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::start_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $category Category data object.
|
|
|
|
* @param int $depth Depth of category in reference to parents.
|
|
|
|
* @param array $args
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_el(&$output, $category, $depth, $args) {
|
2006-04-13 00:40:48 -04:00
|
|
|
extract($args);
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2010-09-07 00:29:00 -04:00
|
|
|
$cat_name = esc_attr( $category->name );
|
2007-03-09 22:56:35 -05:00
|
|
|
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
2010-09-07 00:29:00 -04:00
|
|
|
$link = '<a href="' . esc_attr( get_term_link($category) ) . '" ';
|
2007-05-23 14:59:12 -04:00
|
|
|
if ( $use_desc_for_title == 0 || empty($category->description) )
|
2006-12-01 13:28:43 -05:00
|
|
|
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
|
2006-04-13 00:40:48 -04:00
|
|
|
else
|
2009-05-08 09:47:26 -04:00
|
|
|
$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= '>';
|
2007-03-09 22:56:35 -05:00
|
|
|
$link .= $cat_name . '</a>';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( (! empty($feed_image)) || (! empty($feed)) ) {
|
|
|
|
$link .= ' ';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( empty($feed_image) )
|
|
|
|
$link .= '(';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2010-05-17 12:21:12 -04:00
|
|
|
$link .= '<a href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-12-04 07:02:30 -05:00
|
|
|
if ( empty($feed) )
|
2006-12-01 13:28:43 -05:00
|
|
|
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
|
|
|
else {
|
2006-04-13 00:40:48 -04:00
|
|
|
$title = ' title="' . $feed . '"';
|
|
|
|
$alt = ' alt="' . $feed . '"';
|
|
|
|
$name = $feed;
|
|
|
|
$link .= $title;
|
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= '>';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-12-01 13:28:43 -05:00
|
|
|
if ( empty($feed_image) )
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= $name;
|
2006-12-01 13:28:43 -05:00
|
|
|
else
|
|
|
|
$link .= "<img src='$feed_image'$alt$title" . ' />';
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= '</a>';
|
2006-12-01 13:28:43 -05:00
|
|
|
if ( empty($feed_image) )
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= ')';
|
|
|
|
}
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-09-19 19:56:28 -04:00
|
|
|
if ( isset($show_count) && $show_count )
|
2007-05-23 14:59:12 -04:00
|
|
|
$link .= ' (' . intval($category->count) . ')';
|
2007-02-27 10:24:54 -05:00
|
|
|
|
2006-09-19 19:56:28 -04:00
|
|
|
if ( isset($show_date) && $show_date ) {
|
2006-04-13 00:40:48 -04:00
|
|
|
$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
|
|
|
|
}
|
2006-12-01 07:05:21 -05:00
|
|
|
|
2007-12-20 16:25:12 -05:00
|
|
|
if ( isset($current_category) && $current_category )
|
2006-12-01 13:55:27 -05:00
|
|
|
$_current_category = get_category( $current_category );
|
2006-12-01 07:05:21 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( 'list' == $args['style'] ) {
|
|
|
|
$output .= "\t<li";
|
2007-08-22 18:59:45 -04:00
|
|
|
$class = 'cat-item cat-item-'.$category->term_id;
|
2007-12-20 16:25:12 -05:00
|
|
|
if ( isset($current_category) && $current_category && ($category->term_id == $current_category) )
|
2007-08-22 18:59:45 -04:00
|
|
|
$class .= ' current-cat';
|
2007-12-20 16:25:12 -05:00
|
|
|
elseif ( isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent) )
|
2007-08-22 18:59:45 -04:00
|
|
|
$class .= ' current-cat-parent';
|
|
|
|
$output .= ' class="'.$class.'"';
|
2006-04-13 00:40:48 -04:00
|
|
|
$output .= ">$link\n";
|
|
|
|
} else {
|
|
|
|
$output .= "\t$link<br />\n";
|
|
|
|
}
|
|
|
|
}
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::end_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $page Not used.
|
|
|
|
* @param int $depth Depth of category. Not used.
|
|
|
|
* @param array $args Only uses 'list' for whether should append to output.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function end_el(&$output, $page, $depth, $args) {
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( 'list' != $args['style'] )
|
2008-04-21 15:30:54 -04:00
|
|
|
return;
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2006-04-13 00:40:48 -04:00
|
|
|
$output .= "</li>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Create HTML dropdown list of Categories.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
* @uses Walker
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
class Walker_CategoryDropdown extends Walker {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$tree_type
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var string
|
|
|
|
*/
|
2006-04-13 00:40:48 -04:00
|
|
|
var $tree_type = 'category';
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* @see Walker::$db_fields
|
|
|
|
* @since 2.1.0
|
|
|
|
* @todo Decouple this
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Walker::start_el()
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $output Passed by reference. Used to append additional content.
|
|
|
|
* @param object $category Category data object.
|
|
|
|
* @param int $depth Depth of category. Used for padding.
|
|
|
|
* @param array $args Uses 'selected', 'show_count', and 'show_last_update' keys, if they exist.
|
|
|
|
*/
|
2008-04-21 15:30:54 -04:00
|
|
|
function start_el(&$output, $category, $depth, $args) {
|
2006-04-13 00:40:48 -04:00
|
|
|
$pad = str_repeat(' ', $depth * 3);
|
2006-11-19 02:56:05 -05:00
|
|
|
|
2007-05-23 14:59:12 -04:00
|
|
|
$cat_name = apply_filters('list_cats', $category->name, $category);
|
2008-10-05 00:43:52 -04:00
|
|
|
$output .= "\t<option class=\"level-$depth\" value=\"".$category->term_id."\"";
|
2007-05-23 14:59:12 -04:00
|
|
|
if ( $category->term_id == $args['selected'] )
|
2006-04-13 00:40:48 -04:00
|
|
|
$output .= ' selected="selected"';
|
|
|
|
$output .= '>';
|
2006-09-01 16:38:24 -04:00
|
|
|
$output .= $pad.$cat_name;
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( $args['show_count'] )
|
2007-05-23 14:59:12 -04:00
|
|
|
$output .= ' ('. $category->count .')';
|
2006-04-13 00:40:48 -04:00
|
|
|
if ( $args['show_last_update'] ) {
|
|
|
|
$format = 'Y-m-d';
|
|
|
|
$output .= ' ' . gmdate($format, $category->last_update_timestamp);
|
|
|
|
}
|
|
|
|
$output .= "</option>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Send XML response back to AJAX request.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @since 2.1.0
|
|
|
|
*/
|
2006-09-13 17:39:53 -04:00
|
|
|
class WP_Ajax_Response {
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Store XML responses to send.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @var array
|
|
|
|
* @access private
|
|
|
|
*/
|
2006-09-13 17:39:53 -04:00
|
|
|
var $responses = array();
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* PHP4 Constructor - Passes args to {@link WP_Ajax_Response::add()}.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
* @see WP_Ajax_Response::add()
|
|
|
|
*
|
|
|
|
* @param string|array $args Optional. Will be passed to add() method.
|
|
|
|
* @return WP_Ajax_Response
|
|
|
|
*/
|
2006-09-13 17:39:53 -04:00
|
|
|
function WP_Ajax_Response( $args = '' ) {
|
|
|
|
if ( !empty($args) )
|
|
|
|
$this->add($args);
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Append to XML response based on given arguments.
|
|
|
|
*
|
|
|
|
* The arguments that can be passed in the $args parameter are below. It is
|
|
|
|
* also possible to pass a WP_Error object in either the 'id' or 'data'
|
|
|
|
* argument. The parameter isn't actually optional, content should be given
|
|
|
|
* in order to send the correct response.
|
|
|
|
*
|
|
|
|
* 'what' argument is a string that is the XMLRPC response type.
|
|
|
|
* 'action' argument is a boolean or string that acts like a nonce.
|
|
|
|
* 'id' argument can be WP_Error or an integer.
|
|
|
|
* 'old_id' argument is false by default or an integer of the previous ID.
|
|
|
|
* 'position' argument is an integer or a string with -1 = top, 1 = bottom,
|
|
|
|
* html ID = after, -html ID = before.
|
|
|
|
* 'data' argument is a string with the content or message.
|
|
|
|
* 'supplemental' argument is an array of strings that will be children of
|
|
|
|
* the supplemental element.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string|array $args Override defaults.
|
|
|
|
* @return string XML response.
|
|
|
|
*/
|
2006-09-13 17:39:53 -04:00
|
|
|
function add( $args = '' ) {
|
2007-05-10 23:10:05 -04:00
|
|
|
$defaults = array(
|
2007-08-22 18:59:45 -04:00
|
|
|
'what' => 'object', 'action' => false,
|
|
|
|
'id' => '0', 'old_id' => false,
|
2008-09-15 20:37:05 -04:00
|
|
|
'position' => 1,
|
2007-05-10 23:10:05 -04:00
|
|
|
'data' => '', 'supplemental' => array()
|
|
|
|
);
|
2007-06-13 22:25:30 -04:00
|
|
|
|
2007-05-10 23:10:05 -04:00
|
|
|
$r = wp_parse_args( $args, $defaults );
|
2007-06-14 18:45:40 -04:00
|
|
|
extract( $r, EXTR_SKIP );
|
2008-01-04 14:36:34 -05:00
|
|
|
$position = preg_replace( '/[^a-z0-9:_-]/i', '', $position );
|
2006-09-13 17:39:53 -04:00
|
|
|
|
|
|
|
if ( is_wp_error($id) ) {
|
|
|
|
$data = $id;
|
|
|
|
$id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = '';
|
2007-11-01 02:23:16 -04:00
|
|
|
if ( is_wp_error($data) ) {
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $data->get_error_codes() as $code ) {
|
2006-09-13 17:39:53 -04:00
|
|
|
$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
|
2007-11-01 02:23:16 -04:00
|
|
|
if ( !$error_data = $data->get_error_data($code) )
|
|
|
|
continue;
|
|
|
|
$class = '';
|
|
|
|
if ( is_object($error_data) ) {
|
|
|
|
$class = ' class="' . get_class($error_data) . '"';
|
|
|
|
$error_data = get_object_vars($error_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response .= "<wp_error_data code='$code'$class>";
|
|
|
|
|
|
|
|
if ( is_scalar($error_data) ) {
|
2008-03-20 19:34:32 -04:00
|
|
|
$response .= "<![CDATA[$error_data]]>";
|
2007-11-01 02:23:16 -04:00
|
|
|
} elseif ( is_array($error_data) ) {
|
|
|
|
foreach ( $error_data as $k => $v )
|
|
|
|
$response .= "<$k><![CDATA[$v]]></$k>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$response .= "</wp_error_data>";
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-13 17:39:53 -04:00
|
|
|
$response = "<response_data><![CDATA[$data]]></response_data>";
|
2007-11-01 02:23:16 -04:00
|
|
|
}
|
2006-09-13 17:39:53 -04:00
|
|
|
|
|
|
|
$s = '';
|
2008-08-06 16:31:54 -04:00
|
|
|
if ( is_array($supplemental) ) {
|
2006-09-13 17:39:53 -04:00
|
|
|
foreach ( $supplemental as $k => $v )
|
|
|
|
$s .= "<$k><![CDATA[$v]]></$k>";
|
2008-02-29 04:51:36 -05:00
|
|
|
$s = "<supplemental>$s</supplemental>";
|
|
|
|
}
|
2006-09-13 17:39:53 -04:00
|
|
|
|
|
|
|
if ( false === $action )
|
|
|
|
$action = $_POST['action'];
|
|
|
|
|
|
|
|
$x = '';
|
2006-11-08 16:23:41 -05:00
|
|
|
$x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
|
2007-10-09 18:49:42 -04:00
|
|
|
$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
|
2006-09-13 17:39:53 -04:00
|
|
|
$x .= $response;
|
|
|
|
$x .= $s;
|
|
|
|
$x .= "</$what>";
|
|
|
|
$x .= "</response>";
|
|
|
|
|
|
|
|
$this->responses[] = $x;
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
2008-09-15 20:37:05 -04:00
|
|
|
/**
|
|
|
|
* Display XML formatted responses.
|
|
|
|
*
|
|
|
|
* Sets the content type header to text/xml.
|
|
|
|
*
|
|
|
|
* @since 2.1.0
|
|
|
|
*/
|
2006-09-13 17:39:53 -04:00
|
|
|
function send() {
|
2007-06-02 01:21:18 -04:00
|
|
|
header('Content-Type: text/xml');
|
2006-09-13 17:39:53 -04:00
|
|
|
echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
|
2008-08-06 16:31:54 -04:00
|
|
|
foreach ( (array) $this->responses as $response )
|
2006-09-13 17:39:53 -04:00
|
|
|
echo $response;
|
|
|
|
echo '</wp_ajax>';
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* Helper class to remove the need to use eval to replace $matches[] in query strings.
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @since 2.9.0
|
|
|
|
*/
|
|
|
|
class WP_MatchesMapRegex {
|
|
|
|
/**
|
|
|
|
* store for matches
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access private
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $_matches;
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* store for mapping result
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access public
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $output;
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* subject to perform mapping on (query string containing $matches[] references
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access private
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_subject;
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
2009-09-14 10:03:32 -04:00
|
|
|
* regexp pattern to match $matches[] references
|
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* constructor
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @param string $subject subject if regex
|
|
|
|
* @param array $matches data to use in map
|
|
|
|
* @return self
|
2009-09-14 10:03:32 -04:00
|
|
|
*/
|
2009-08-20 16:09:36 -04:00
|
|
|
function WP_MatchesMapRegex($subject, $matches) {
|
|
|
|
$this->_subject = $subject;
|
|
|
|
$this->_matches = $matches;
|
2009-09-14 10:03:32 -04:00
|
|
|
$this->output = $this->_map();
|
2009-08-20 16:09:36 -04:00
|
|
|
}
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* Substitute substring matches in subject.
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* static helper function to ease use
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access public
|
|
|
|
* @param string $subject subject
|
|
|
|
* @param array $matches data used for subsitution
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function apply($subject, $matches) {
|
|
|
|
$oSelf =& new WP_MatchesMapRegex($subject, $matches);
|
2009-09-14 10:03:32 -04:00
|
|
|
return $oSelf->output;
|
2009-08-20 16:09:36 -04:00
|
|
|
}
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
2009-09-14 10:03:32 -04:00
|
|
|
* do the actual mapping
|
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access private
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function _map() {
|
|
|
|
$callback = array(&$this, 'callback');
|
|
|
|
return preg_replace_callback($this->_pattern, $callback, $this->_subject);
|
|
|
|
}
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
/**
|
|
|
|
* preg_replace_callback hook
|
2009-09-14 10:03:32 -04:00
|
|
|
*
|
2009-08-20 16:09:36 -04:00
|
|
|
* @access public
|
|
|
|
* @param array $matches preg_replace regexp matches
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function callback($matches) {
|
|
|
|
$index = intval(substr($matches[0], 9, -1));
|
2010-02-12 19:02:47 -05:00
|
|
|
return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
|
2009-08-20 16:09:36 -04:00
|
|
|
}
|
2009-09-14 10:03:32 -04:00
|
|
|
|
2009-08-20 16:09:36 -04:00
|
|
|
}
|
|
|
|
|
2005-08-30 15:01:45 -04:00
|
|
|
?>
|