2004-06-30 17:31:49 +02:00
|
|
|
<?php
|
|
|
|
|
2005-06-11 01:15:13 +02:00
|
|
|
class WP {
|
2007-09-03 20:14:05 +02: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');
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2008-02-29 22:49:49 +01:00
|
|
|
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');
|
2006-02-21 09:39:58 +01:00
|
|
|
var $extra_query_vars = array();
|
2005-06-11 01:15:13 +02:00
|
|
|
|
|
|
|
var $query_vars;
|
|
|
|
var $query_string;
|
2005-11-22 22:07:48 +01:00
|
|
|
var $request;
|
|
|
|
var $matched_rule;
|
|
|
|
var $matched_query;
|
2005-06-11 01:15:13 +02:00
|
|
|
var $did_permalink = false;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-03-12 23:57:00 +01:00
|
|
|
function add_query_var($qv) {
|
|
|
|
$this->public_query_vars[] = $qv;
|
|
|
|
}
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2007-08-16 00:08:51 +02:00
|
|
|
function set_query_var($key, $value) {
|
|
|
|
$this->query_vars[$key] = $value;
|
|
|
|
}
|
|
|
|
|
2005-06-11 01:15:13 +02:00
|
|
|
function parse_request($extra_query_vars = '') {
|
|
|
|
global $wp_rewrite;
|
|
|
|
|
|
|
|
$this->query_vars = array();
|
|
|
|
|
2006-08-30 07:41:38 +02:00
|
|
|
if ( is_array($extra_query_vars) )
|
|
|
|
$this->extra_query_vars = & $extra_query_vars;
|
|
|
|
else if (! empty($extra_query_vars))
|
2006-02-21 09:39:58 +01:00
|
|
|
parse_str($extra_query_vars, $this->extra_query_vars);
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-06-13 04:09:24 +02:00
|
|
|
// Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// Fetch the rewrite rules.
|
|
|
|
$rewrite = $wp_rewrite->wp_rewrite_rules();
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
if (! empty($rewrite)) {
|
2005-06-11 01:15:13 +02:00
|
|
|
// If we match a rewrite rule, this will be cleared.
|
|
|
|
$error = '404';
|
2005-11-16 23:54:52 +01:00
|
|
|
$this->did_permalink = true;
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2006-09-21 23:03:11 +02:00
|
|
|
if ( isset($_SERVER['PATH_INFO']) )
|
|
|
|
$pathinfo = $_SERVER['PATH_INFO'];
|
|
|
|
else
|
|
|
|
$pathinfo = '';
|
2005-11-16 23:54:52 +01:00
|
|
|
$pathinfo_array = explode('?', $pathinfo);
|
2006-09-19 05:05:08 +02:00
|
|
|
$pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
|
2005-11-16 23:54:52 +01:00
|
|
|
$req_uri = $_SERVER['REQUEST_URI'];
|
|
|
|
$req_uri_array = explode('?', $req_uri);
|
|
|
|
$req_uri = $req_uri_array[0];
|
|
|
|
$self = $_SERVER['PHP_SELF'];
|
2006-08-30 23:46:31 +02:00
|
|
|
$home_path = parse_url(get_option('home'));
|
2006-09-21 23:03:11 +02:00
|
|
|
if ( isset($home_path['path']) )
|
|
|
|
$home_path = $home_path['path'];
|
|
|
|
else
|
|
|
|
$home_path = '';
|
2005-12-28 02:48:29 +01:00
|
|
|
$home_path = trim($home_path, '/');
|
2005-11-16 23:54:52 +01: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 08:53:23 +01:00
|
|
|
// requested permalink.
|
2007-03-07 02:44:53 +01:00
|
|
|
$req_uri = str_replace($pathinfo, '', rawurldecode($req_uri));
|
2005-11-16 23:54:52 +01:00
|
|
|
$req_uri = trim($req_uri, '/');
|
2005-12-28 02:48:29 +01: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 23:54:52 +01:00
|
|
|
$pathinfo = trim($pathinfo, '/');
|
2005-12-28 02:48:29 +01:00
|
|
|
$self = trim($self, '/');
|
|
|
|
$self = preg_replace("|^$home_path|", '', $self);
|
2005-11-16 23:54:52 +01:00
|
|
|
$self = str_replace($home_path, '', $self);
|
|
|
|
$self = trim($self, '/');
|
|
|
|
|
|
|
|
// The requested permalink is in $pathinfo for path info requests and
|
|
|
|
// $req_uri for other requests.
|
2006-01-03 01:59:31 +01:00
|
|
|
if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
|
2005-11-16 23:54:52 +01:00
|
|
|
$request = $pathinfo;
|
|
|
|
} else {
|
2005-12-01 02:34:29 +01: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 23:54:52 +01:00
|
|
|
$request = $req_uri;
|
|
|
|
}
|
2005-12-01 02:34:29 +01:00
|
|
|
|
2005-11-22 22:07:48 +01:00
|
|
|
$this->request = $request;
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// Look for matches.
|
|
|
|
$request_match = $request;
|
|
|
|
foreach ($rewrite as $match => $query) {
|
|
|
|
// If the requesting file is the anchor of the match, prepend it
|
|
|
|
// to the path info.
|
|
|
|
if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
|
|
|
|
$request_match = $req_uri . '/' . $request;
|
|
|
|
}
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-29 02:43:32 +01:00
|
|
|
if (preg_match("!^$match!", $request_match, $matches) ||
|
|
|
|
preg_match("!^$match!", urldecode($request_match), $matches)) {
|
2005-11-16 23:54:52 +01:00
|
|
|
// Got a match.
|
2005-11-22 22:07:48 +01:00
|
|
|
$this->matched_rule = $match;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// Trim the query of everything up to the '?'.
|
|
|
|
$query = preg_replace("!^.+\?!", '', $query);
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// Substitute the substring matches into the query.
|
|
|
|
eval("\$query = \"$query\";");
|
2005-11-22 22:07:48 +01:00
|
|
|
$this->matched_query = $query;
|
2005-06-11 01:15:13 +02:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// Parse the query.
|
2006-02-21 09:39:58 +01:00
|
|
|
parse_str($query, $perma_query_vars);
|
2005-11-16 11:16:20 +01:00
|
|
|
|
2005-11-16 23:54:52 +01:00
|
|
|
// If we're processing a 404 request, clear the error var
|
|
|
|
// since we found something.
|
2005-11-29 00:30:42 +01:00
|
|
|
if (isset($_GET['error']))
|
2005-11-16 11:16:20 +01:00
|
|
|
unset($_GET['error']);
|
|
|
|
|
2005-11-29 00:30:42 +01:00
|
|
|
if (isset($error))
|
2005-11-16 11:16:20 +01:00
|
|
|
unset($error);
|
2005-11-16 23:54:52 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If req_uri is empty or if it is a request for ourself, unset error.
|
2007-03-07 06:29:15 +01:00
|
|
|
if (empty($request) || $req_uri == $self || strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false) {
|
2005-11-29 00:30:42 +01:00
|
|
|
if (isset($_GET['error']))
|
2005-11-16 23:54:52 +01:00
|
|
|
unset($_GET['error']);
|
|
|
|
|
2005-11-29 00:30:42 +01:00
|
|
|
if (isset($error))
|
2005-11-16 23:54:52 +01:00
|
|
|
unset($error);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2007-03-07 06:29:15 +01:00
|
|
|
if (isset($perma_query_vars) && strpos($_SERVER['PHP_SELF'], 'wp-admin/') !== false)
|
2006-02-21 09:39:58 +01:00
|
|
|
unset($perma_query_vars);
|
2006-02-12 08:53:23 +01:00
|
|
|
|
2005-11-29 00:30:42 +01:00
|
|
|
$this->did_permalink = false;
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
|
|
|
|
|
|
|
|
for ($i=0; $i<count($this->public_query_vars); $i += 1) {
|
|
|
|
$wpvar = $this->public_query_vars[$i];
|
2006-02-21 09:39:58 +01:00
|
|
|
if (isset($this->extra_query_vars[$wpvar]))
|
|
|
|
$this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
|
2005-06-11 01:15:13 +02:00
|
|
|
elseif (isset($GLOBALS[$wpvar]))
|
|
|
|
$this->query_vars[$wpvar] = $GLOBALS[$wpvar];
|
|
|
|
elseif (!empty($_POST[$wpvar]))
|
|
|
|
$this->query_vars[$wpvar] = $_POST[$wpvar];
|
|
|
|
elseif (!empty($_GET[$wpvar]))
|
|
|
|
$this->query_vars[$wpvar] = $_GET[$wpvar];
|
2006-02-21 09:39:58 +01:00
|
|
|
elseif (!empty($perma_query_vars[$wpvar]))
|
|
|
|
$this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
|
2007-03-04 19:08:33 +01:00
|
|
|
|
2007-03-16 23:00:43 +01:00
|
|
|
if ( !empty( $this->query_vars[$wpvar] ) )
|
|
|
|
$this->query_vars[$wpvar] = (string) $this->query_vars[$wpvar];
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
2005-11-16 11:16:20 +01:00
|
|
|
|
2006-08-30 07:41:38 +02:00
|
|
|
foreach ($this->private_query_vars as $var) {
|
2006-08-30 20:37:33 +02:00
|
|
|
if (isset($this->extra_query_vars[$var]))
|
|
|
|
$this->query_vars[$var] = $this->extra_query_vars[$var];
|
|
|
|
elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
|
2006-08-30 07:41:38 +02:00
|
|
|
$this->query_vars[$var] = $GLOBALS[$var];
|
2006-02-21 09:39:58 +01:00
|
|
|
}
|
|
|
|
|
2005-11-16 11:16:20 +01:00
|
|
|
if ( isset($error) )
|
|
|
|
$this->query_vars['error'] = $error;
|
2006-05-22 21:23:46 +02:00
|
|
|
|
2006-08-30 07:41:38 +02:00
|
|
|
$this->query_vars = apply_filters('request', $this->query_vars);
|
|
|
|
|
2006-09-12 19:45:23 +02:00
|
|
|
do_action_ref_array('parse_request', array(&$this));
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function send_headers() {
|
|
|
|
@header('X-Pingback: '. get_bloginfo('pingback_url'));
|
2005-12-15 17:31:41 +01:00
|
|
|
if ( is_user_logged_in() )
|
2005-11-11 02:44:41 +01:00
|
|
|
nocache_headers();
|
2005-06-11 01:15:13 +02:00
|
|
|
if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
|
|
|
|
status_header( 404 );
|
2006-10-04 05:54:10 +02:00
|
|
|
if ( !is_user_logged_in() )
|
|
|
|
nocache_headers();
|
2007-06-02 07:21:18 +02:00
|
|
|
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
|
2005-06-11 01:15:13 +02:00
|
|
|
} else if ( empty($this->query_vars['feed']) ) {
|
2007-06-02 07:21:18 +02:00
|
|
|
@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
|
2005-06-11 01:15:13 +02:00
|
|
|
} else {
|
|
|
|
// We're showing a feed, so WP is indeed the only thing that last changed
|
2008-02-02 19:42:09 +01: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 21:46:43 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2005-06-11 01:15:13 +02:00
|
|
|
$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
|
2006-11-19 08:56:05 +01:00
|
|
|
else
|
2005-06-11 01:15:13 +02:00
|
|
|
$wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
|
|
|
|
$wp_etag = '"' . md5($wp_last_modified) . '"';
|
|
|
|
@header("Last-Modified: $wp_last_modified");
|
|
|
|
@header("ETag: $wp_etag");
|
|
|
|
|
|
|
|
// Support for Conditional GET
|
2006-11-19 08:56:05 +01:00
|
|
|
if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
|
2006-04-03 07:59:03 +02:00
|
|
|
$client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
|
2005-06-11 01:15:13 +02:00
|
|
|
else $client_etag = false;
|
|
|
|
|
2008-02-02 19:42:09 +01:00
|
|
|
$client_last_modified = empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? '' : trim($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
2005-06-11 01:15:13 +02: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 08:53:23 +01:00
|
|
|
// Make a timestamp for our most recent modification...
|
2005-06-11 01:15:13 +02: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)) ) {
|
|
|
|
status_header( 304 );
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2006-05-22 21:23:46 +02:00
|
|
|
|
2006-09-12 19:45:23 +02:00
|
|
|
do_action_ref_array('send_headers', array(&$this));
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_query_string() {
|
|
|
|
$this->query_string = '';
|
2006-02-21 09:39:58 +01:00
|
|
|
foreach (array_keys($this->query_vars) as $wpvar) {
|
|
|
|
if ( '' != $this->query_vars[$wpvar] ) {
|
2005-06-11 01:15:13 +02:00
|
|
|
$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
|
2007-01-16 20:05:01 +01:00
|
|
|
if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
|
|
|
|
continue;
|
2005-06-11 01:15:13 +02:00
|
|
|
$this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-30 07:41:38 +02:00
|
|
|
// query_string filter deprecated. Use request filter instead.
|
2007-11-07 05:30:11 +01:00
|
|
|
if ( has_filter('query_string') ) { // Don't bother filtering and parsing if no plugins are hooked in.
|
2006-08-30 07:41:38 +02:00
|
|
|
$this->query_string = apply_filters('query_string', $this->query_string);
|
|
|
|
parse_str($this->query_string, $this->query_vars);
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function register_globals() {
|
|
|
|
global $wp_query;
|
|
|
|
// Extract updated query vars back into global namespace.
|
|
|
|
foreach ($wp_query->query_vars as $key => $value) {
|
|
|
|
$GLOBALS[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$GLOBALS['query_string'] = & $this->query_string;
|
|
|
|
$GLOBALS['posts'] = & $wp_query->posts;
|
|
|
|
$GLOBALS['post'] = & $wp_query->post;
|
2006-01-11 12:06:26 +01:00
|
|
|
$GLOBALS['request'] = & $wp_query->request;
|
2005-06-11 01:15:13 +02:00
|
|
|
|
|
|
|
if ( is_single() || is_page() ) {
|
|
|
|
$GLOBALS['more'] = 1;
|
|
|
|
$GLOBALS['single'] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-18 23:08:01 +01:00
|
|
|
function init() {
|
2006-02-22 20:08:55 +01:00
|
|
|
wp_get_current_user();
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function query_posts() {
|
2006-11-09 07:50:58 +01:00
|
|
|
global $wp_the_query;
|
2005-06-11 01:15:13 +02:00
|
|
|
$this->build_query_string();
|
2006-11-09 07:50:58 +01:00
|
|
|
$wp_the_query->query($this->query_vars);
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function handle_404() {
|
|
|
|
global $wp_query;
|
|
|
|
// Issue a 404 if a permalink request doesn't match any posts. Don't
|
|
|
|
// issue a 404 if one was already issued, if the request was a search,
|
|
|
|
// or if the request was a regular query string request rather than a
|
|
|
|
// permalink request.
|
2006-01-25 04:59:41 +01:00
|
|
|
if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
|
2005-09-16 05:16:12 +02:00
|
|
|
$wp_query->set_404();
|
2005-06-11 01:15:13 +02:00
|
|
|
status_header( 404 );
|
2006-10-04 05:54:10 +02:00
|
|
|
nocache_headers();
|
2005-11-16 11:16:20 +01:00
|
|
|
} elseif( is_404() != true ) {
|
2005-06-11 01:15:13 +02:00
|
|
|
status_header( 200 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function main($query_args = '') {
|
2005-12-18 23:08:01 +01:00
|
|
|
$this->init();
|
2005-06-11 01:15:13 +02:00
|
|
|
$this->parse_request($query_args);
|
2005-11-11 02:44:41 +01:00
|
|
|
$this->send_headers();
|
2005-06-11 01:15:13 +02:00
|
|
|
$this->query_posts();
|
|
|
|
$this->handle_404();
|
|
|
|
$this->register_globals();
|
2006-09-12 19:45:23 +02:00
|
|
|
do_action_ref_array('wp', array(&$this));
|
2005-06-11 01:15:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function WP() {
|
|
|
|
// Empty.
|
|
|
|
}
|
2004-12-03 03:38:11 +01:00
|
|
|
}
|
|
|
|
|
2006-03-31 01:18:14 +02:00
|
|
|
class WP_Error {
|
|
|
|
var $errors = array();
|
2006-08-29 22:17:41 +02:00
|
|
|
var $error_data = array();
|
2006-03-31 01:18:14 +02:00
|
|
|
|
2006-08-29 22:17:41 +02: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-31 01:18:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function get_error_codes() {
|
|
|
|
if ( empty($this->errors) )
|
|
|
|
return array();
|
|
|
|
|
|
|
|
return array_keys($this->errors);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_error_code() {
|
|
|
|
$codes = $this->get_error_codes();
|
|
|
|
|
|
|
|
if ( empty($codes) )
|
|
|
|
return '';
|
|
|
|
|
2006-11-19 08:56:05 +01:00
|
|
|
return $codes[0];
|
2006-03-31 01:18:14 +02:00
|
|
|
}
|
|
|
|
|
2006-04-02 02:48:14 +02:00
|
|
|
function get_error_messages($code = '') {
|
|
|
|
// Return all messages if no code specified.
|
|
|
|
if ( empty($code) ) {
|
|
|
|
$all_messages = array();
|
|
|
|
foreach ( $this->errors as $code => $messages )
|
|
|
|
$all_messages = array_merge($all_messages, $messages);
|
|
|
|
|
|
|
|
return $all_messages;
|
|
|
|
}
|
|
|
|
|
2006-03-31 01:18:14 +02:00
|
|
|
if ( isset($this->errors[$code]) )
|
|
|
|
return $this->errors[$code];
|
|
|
|
else
|
2006-11-19 08:56:05 +01:00
|
|
|
return array();
|
2006-03-31 01:18:14 +02: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];
|
|
|
|
}
|
|
|
|
|
2006-08-29 22:17:41 +02: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add($code, $message, $data = '') {
|
|
|
|
$this->errors[$code][] = $message;
|
|
|
|
if ( ! empty($data) )
|
|
|
|
$this->error_data[$code] = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_data($data, $code = '') {
|
|
|
|
if ( empty($code) )
|
|
|
|
$code = $this->get_error_code();
|
|
|
|
|
|
|
|
$this->error_data[$code] = $data;
|
2006-03-31 01:18:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_wp_error($thing) {
|
|
|
|
if ( is_object($thing) && is_a($thing, 'WP_Error') )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-05 07:47:27 +01:00
|
|
|
/*
|
|
|
|
* A class for displaying various tree-like structures.
|
2007-12-14 22:46:52 +01:00
|
|
|
* Extend the Walker class to use it, see examples at the bottom
|
|
|
|
*/
|
2006-11-19 08:56:05 +01:00
|
|
|
class Walker {
|
2006-04-13 06:40:48 +02:00
|
|
|
var $tree_type;
|
|
|
|
var $db_fields;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
//abstract callbacks
|
|
|
|
function start_lvl($output) { return $output; }
|
|
|
|
function end_lvl($output) { return $output; }
|
|
|
|
function start_el($output) { return $output; }
|
|
|
|
function end_el($output) { return $output; }
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
/*
|
|
|
|
* display one element if the element doesn't have any children
|
|
|
|
* otherwise, display the element and its children
|
|
|
|
*/
|
|
|
|
function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, $output ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
if ( !$element)
|
2008-02-05 07:47:27 +01:00
|
|
|
return $output;
|
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$id_field = $this->db_fields['id'];
|
|
|
|
$parent_field = $this->db_fields['parent'];
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
//display this element
|
|
|
|
$cb_args = array_merge( array($output, $element, $depth), $args);
|
|
|
|
$output = call_user_func_array(array(&$this, 'start_el'), $cb_args);
|
|
|
|
|
2008-03-02 21:17:30 +01:00
|
|
|
if ( $max_depth == 0 ||
|
2008-02-15 08:34:52 +01:00
|
|
|
($max_depth != 0 && $max_depth > $depth+1 )) { //whether to descend
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-02-15 08:34:52 +01:00
|
|
|
for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) {
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-02-15 08:34:52 +01:00
|
|
|
$child = $children_elements[$i];
|
|
|
|
if ( $child->$parent_field == $element->$id_field ) {
|
|
|
|
|
|
|
|
if ( !isset($newlevel) ) {
|
2008-03-02 21:17:30 +01:00
|
|
|
$newlevel = true;
|
2008-02-15 08:34:52 +01:00
|
|
|
//start the child delimiter
|
|
|
|
$cb_args = array_merge( array($output, $depth), $args);
|
|
|
|
$output = call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
|
|
|
|
}
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-02-15 08:34:52 +01:00
|
|
|
array_splice( $children_elements, $i, 1 );
|
|
|
|
$output = $this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
|
|
|
|
$i = -1;
|
|
|
|
}
|
2006-04-13 06:40:48 +02:00
|
|
|
}
|
2007-12-14 22:46:52 +01:00
|
|
|
}
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-02-15 08:34:52 +01:00
|
|
|
if ( isset($newlevel) && $newlevel ){
|
2007-12-16 21:31:44 +01:00
|
|
|
//end the child delimiter
|
|
|
|
$cb_args = array_merge( array($output, $depth), $args);
|
|
|
|
$output = call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
|
|
|
|
}
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-02-15 08:34:52 +01:00
|
|
|
//end this element
|
|
|
|
$cb_args = array_merge( array($output, $element, $depth), $args);
|
|
|
|
$output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
|
2008-02-05 07:47:27 +01:00
|
|
|
|
|
|
|
return $output;
|
2007-12-14 22:46:52 +01:00
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
/*
|
|
|
|
* displays array of elements hierarchically
|
2007-12-16 21:31:44 +01:00
|
|
|
* it is a generic function which does not assume any existing order of elements
|
2008-02-05 07:47:27 +01:00
|
|
|
* max_depth = -1 means flatly display every element
|
|
|
|
* max_depth = 0 means display all levels
|
|
|
|
* max_depth > 0 specifies the number of display levels.
|
2007-12-14 22:46:52 +01:00
|
|
|
*/
|
|
|
|
function walk( $elements, $max_depth) {
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
$args = array_slice(func_get_args(), 2);
|
|
|
|
$output = '';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-12-16 21:31:44 +01:00
|
|
|
if ($max_depth < -1) //invalid parameter
|
2008-02-05 07:47:27 +01:00
|
|
|
return $output;
|
|
|
|
|
2007-12-21 19:49:20 +01:00
|
|
|
if (empty($elements)) //nothing to walk
|
2008-02-05 07:47:27 +01:00
|
|
|
return $output;
|
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
$id_field = $this->db_fields['id'];
|
|
|
|
$parent_field = $this->db_fields['parent'];
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-21 19:49:20 +01:00
|
|
|
// flat display
|
|
|
|
if ( -1 == $max_depth ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
$empty_array = array();
|
|
|
|
foreach ( $elements as $e )
|
2007-12-14 22:46:52 +01:00
|
|
|
$output = $this->display_element( $e, $empty_array, 1, 0, $args, $output );
|
2008-02-05 07:47:27 +01:00
|
|
|
return $output;
|
2006-04-13 06:40:48 +02:00
|
|
|
}
|
2008-02-05 07:47:27 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* need to display in hierarchical order
|
2007-12-14 22:46:52 +01:00
|
|
|
* splice elements into two buckets: those without parent and those with parent
|
|
|
|
*/
|
|
|
|
$top_level_elements = array();
|
|
|
|
$children_elements = array();
|
|
|
|
foreach ( $elements as $e) {
|
|
|
|
if ( 0 == $e->$parent_field )
|
2008-02-05 07:47:27 +01:00
|
|
|
$top_level_elements[] = $e;
|
2007-12-14 22:46:52 +01:00
|
|
|
else
|
2008-02-05 07:47:27 +01:00
|
|
|
$children_elements[] = $e;
|
2007-12-14 22:46:52 +01:00
|
|
|
}
|
2008-02-05 07:47:27 +01:00
|
|
|
|
|
|
|
/*
|
2007-12-21 19:49:20 +01:00
|
|
|
* none of the elements is top level
|
|
|
|
* the first one must be root of the sub elements
|
|
|
|
*/
|
|
|
|
if ( !$top_level_elements ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-21 19:49:20 +01:00
|
|
|
$root = $children_elements[0];
|
|
|
|
for ( $i = 0; $i < sizeof( $children_elements ); $i++ ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-21 19:49:20 +01:00
|
|
|
$child = $children_elements[$i];
|
|
|
|
if ($root->$parent_field == $child->$parent_field )
|
2008-02-05 07:47:27 +01:00
|
|
|
$top_level_elements[] = $child;
|
2007-12-21 19:49:20 +01:00
|
|
|
array_splice( $children_elements, $i, 1 );
|
2008-02-05 07:47:27 +01:00
|
|
|
$i--;
|
2007-12-21 19:49:20 +01:00
|
|
|
}
|
|
|
|
}
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-12-14 22:46:52 +01:00
|
|
|
foreach ( $top_level_elements as $e )
|
|
|
|
$output = $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
|
2008-02-05 07:47:27 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if we are displaying all levels, and remaining children_elements is not empty,
|
2007-12-14 22:46:52 +01:00
|
|
|
* then we got orphans, which should be displayed regardless
|
|
|
|
*/
|
|
|
|
if ( ( $max_depth == 0 ) && sizeof( $children_elements ) > 0 ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
$empty_array = array();
|
2007-12-14 22:46:52 +01:00
|
|
|
foreach ( $children_elements as $orphan_e )
|
|
|
|
$output = $this->display_element( $orphan_e, $empty_array, 1, 0, $args, $output );
|
|
|
|
}
|
|
|
|
return $output;
|
2006-04-13 06:40:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Walker_Page extends Walker {
|
|
|
|
var $tree_type = 'page';
|
|
|
|
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function start_lvl($output, $depth) {
|
|
|
|
$indent = str_repeat("\t", $depth);
|
2007-01-22 08:05:48 +01:00
|
|
|
$output .= "\n$indent<ul>\n";
|
2006-04-13 06:40:48 +02:00
|
|
|
return $output;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function end_lvl($output, $depth) {
|
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent</ul>\n";
|
|
|
|
return $output;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-01-12 04:54:22 +01:00
|
|
|
function start_el($output, $page, $depth, $current_page, $args) {
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( $depth )
|
|
|
|
$indent = str_repeat("\t", $depth);
|
2007-12-20 22:25:12 +01:00
|
|
|
else
|
|
|
|
$indent = '';
|
2008-02-05 07:47:27 +01:00
|
|
|
|
2007-06-15 00:45:40 +02:00
|
|
|
extract($args, EXTR_SKIP);
|
2007-08-23 00:59:45 +02:00
|
|
|
$css_class = 'page_item page-item-'.$page->ID;
|
2006-12-01 13:05:21 +01:00
|
|
|
$_current_page = get_page( $current_page );
|
2008-02-28 07:43:45 +01:00
|
|
|
if ( in_array($page->ID, (array) $_current_page->ancestors) )
|
2008-02-28 00:28:18 +01:00
|
|
|
$css_class .= ' current_page_ancestor';
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( $page->ID == $current_page )
|
2008-02-28 00:28:18 +01:00
|
|
|
$css_class .= ' current_page_item';
|
2006-12-01 13:05:21 +01:00
|
|
|
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
|
|
|
|
$css_class .= ' current_page_parent';
|
2006-04-13 06:40:48 +02:00
|
|
|
|
2007-04-01 17:40:50 +02:00
|
|
|
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( !empty($show_date) ) {
|
|
|
|
if ( 'modified' == $show_date )
|
|
|
|
$time = $page->post_modified;
|
|
|
|
else
|
|
|
|
$time = $page->post_date;
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$output .= " " . mysql2date($date_format, $time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function end_el($output, $page, $depth) {
|
|
|
|
$output .= "</li>\n";
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Walker_PageDropdown extends Walker {
|
|
|
|
var $tree_type = 'page';
|
|
|
|
var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this
|
|
|
|
|
|
|
|
function start_el($output, $page, $depth, $args) {
|
2006-11-19 08:56:05 +01:00
|
|
|
$pad = str_repeat(' ', $depth * 3);
|
2006-04-13 06:40:48 +02:00
|
|
|
|
2006-11-19 08:56:05 +01:00
|
|
|
$output .= "\t<option value=\"$page->ID\"";
|
|
|
|
if ( $page->ID == $args['selected'] )
|
|
|
|
$output .= ' selected="selected"';
|
|
|
|
$output .= '>';
|
|
|
|
$title = wp_specialchars($page->post_title);
|
|
|
|
$output .= "$pad$title";
|
|
|
|
$output .= "</option>\n";
|
2006-04-13 06:40:48 +02:00
|
|
|
|
2006-11-19 08:56:05 +01:00
|
|
|
return $output;
|
2006-04-13 06:40:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Walker_Category extends Walker {
|
|
|
|
var $tree_type = 'category';
|
2007-05-23 20:59:12 +02:00
|
|
|
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function start_lvl($output, $depth, $args) {
|
|
|
|
if ( 'list' != $args['style'] )
|
|
|
|
return $output;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent<ul class='children'>\n";
|
|
|
|
return $output;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function end_lvl($output, $depth, $args) {
|
|
|
|
if ( 'list' != $args['style'] )
|
|
|
|
return $output;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$indent = str_repeat("\t", $depth);
|
|
|
|
$output .= "$indent</ul>\n";
|
|
|
|
return $output;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
function start_el($output, $category, $depth, $args) {
|
|
|
|
extract($args);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-05-23 20:59:12 +02:00
|
|
|
$cat_name = attribute_escape( $category->name);
|
2007-03-10 04:56:35 +01:00
|
|
|
$cat_name = apply_filters( 'list_cats', $cat_name, $category );
|
2007-05-23 20:59:12 +02:00
|
|
|
$link = '<a href="' . get_category_link( $category->term_id ) . '" ';
|
|
|
|
if ( $use_desc_for_title == 0 || empty($category->description) )
|
2006-12-01 19:28:43 +01:00
|
|
|
$link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
|
2006-04-13 06:40:48 +02:00
|
|
|
else
|
2007-05-23 20:59:12 +02:00
|
|
|
$link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->description, $category )) . '"';
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= '>';
|
2007-03-10 04:56:35 +01:00
|
|
|
$link .= $cat_name . '</a>';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( (! empty($feed_image)) || (! empty($feed)) ) {
|
|
|
|
$link .= ' ';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( empty($feed_image) )
|
|
|
|
$link .= '(';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-12-06 20:58:15 +01:00
|
|
|
$link .= '<a href="' . get_category_feed_link($category->term_id, $feed_type) . '"';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-12-04 13:02:30 +01:00
|
|
|
if ( empty($feed) )
|
2006-12-01 19:28:43 +01:00
|
|
|
$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
|
|
|
|
else {
|
2006-04-13 06:40:48 +02:00
|
|
|
$title = ' title="' . $feed . '"';
|
|
|
|
$alt = ' alt="' . $feed . '"';
|
|
|
|
$name = $feed;
|
|
|
|
$link .= $title;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= '>';
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-12-01 19:28:43 +01:00
|
|
|
if ( empty($feed_image) )
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= $name;
|
2006-12-01 19:28:43 +01:00
|
|
|
else
|
|
|
|
$link .= "<img src='$feed_image'$alt$title" . ' />';
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= '</a>';
|
2006-12-01 19:28:43 +01:00
|
|
|
if ( empty($feed_image) )
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= ')';
|
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-09-20 01:56:28 +02:00
|
|
|
if ( isset($show_count) && $show_count )
|
2007-05-23 20:59:12 +02:00
|
|
|
$link .= ' (' . intval($category->count) . ')';
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-09-20 01:56:28 +02:00
|
|
|
if ( isset($show_date) && $show_date ) {
|
2006-04-13 06:40:48 +02:00
|
|
|
$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
|
|
|
|
}
|
2006-12-01 13:05:21 +01:00
|
|
|
|
2007-12-20 22:25:12 +01:00
|
|
|
if ( isset($current_category) && $current_category )
|
2006-12-01 19:55:27 +01:00
|
|
|
$_current_category = get_category( $current_category );
|
2006-12-01 13:05:21 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( 'list' == $args['style'] ) {
|
|
|
|
$output .= "\t<li";
|
2007-08-23 00:59:45 +02:00
|
|
|
$class = 'cat-item cat-item-'.$category->term_id;
|
2007-12-20 22:25:12 +01:00
|
|
|
if ( isset($current_category) && $current_category && ($category->term_id == $current_category) )
|
2007-08-23 00:59:45 +02:00
|
|
|
$class .= ' current-cat';
|
2007-12-20 22:25:12 +01:00
|
|
|
elseif ( isset($_current_category) && $_current_category && ($category->term_id == $_current_category->parent) )
|
2007-08-23 00:59:45 +02:00
|
|
|
$class .= ' current-cat-parent';
|
|
|
|
$output .= ' class="'.$class.'"';
|
2006-04-13 06:40:48 +02:00
|
|
|
$output .= ">$link\n";
|
|
|
|
} else {
|
|
|
|
$output .= "\t$link<br />\n";
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
return $output;
|
|
|
|
}
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-19 04:33:47 +02:00
|
|
|
function end_el($output, $page, $depth, $args) {
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( 'list' != $args['style'] )
|
|
|
|
return $output;
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
$output .= "</li>\n";
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Walker_CategoryDropdown extends Walker {
|
|
|
|
var $tree_type = 'category';
|
2007-05-23 20:59:12 +02:00
|
|
|
var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this
|
2006-11-19 08:56:05 +01:00
|
|
|
|
|
|
|
function start_el($output, $category, $depth, $args) {
|
2006-04-13 06:40:48 +02:00
|
|
|
$pad = str_repeat(' ', $depth * 3);
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2007-05-23 20:59:12 +02:00
|
|
|
$cat_name = apply_filters('list_cats', $category->name, $category);
|
|
|
|
$output .= "\t<option value=\"".$category->term_id."\"";
|
|
|
|
if ( $category->term_id == $args['selected'] )
|
2006-04-13 06:40:48 +02:00
|
|
|
$output .= ' selected="selected"';
|
|
|
|
$output .= '>';
|
2006-09-01 22:38:24 +02:00
|
|
|
$output .= $pad.$cat_name;
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( $args['show_count'] )
|
2007-05-23 20:59:12 +02:00
|
|
|
$output .= ' ('. $category->count .')';
|
2006-04-13 06:40:48 +02:00
|
|
|
if ( $args['show_last_update'] ) {
|
|
|
|
$format = 'Y-m-d';
|
|
|
|
$output .= ' ' . gmdate($format, $category->last_update_timestamp);
|
|
|
|
}
|
|
|
|
$output .= "</option>\n";
|
2006-11-19 08:56:05 +01:00
|
|
|
|
2006-04-13 06:40:48 +02:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-13 23:39:53 +02:00
|
|
|
class WP_Ajax_Response {
|
|
|
|
var $responses = array();
|
|
|
|
|
|
|
|
function WP_Ajax_Response( $args = '' ) {
|
|
|
|
if ( !empty($args) )
|
|
|
|
$this->add($args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// a WP_Error object can be passed in 'id' or 'data'
|
|
|
|
function add( $args = '' ) {
|
2007-05-11 05:10:05 +02:00
|
|
|
$defaults = array(
|
2007-08-23 00:59:45 +02:00
|
|
|
'what' => 'object', 'action' => false,
|
|
|
|
'id' => '0', 'old_id' => false,
|
2007-10-10 00:49:42 +02:00
|
|
|
'position' => 1, // -1 = top, 1 = bottom, html ID = after, -html ID = before
|
2007-05-11 05:10:05 +02:00
|
|
|
'data' => '', 'supplemental' => array()
|
|
|
|
);
|
2007-06-14 04:25:30 +02:00
|
|
|
|
2007-05-11 05:10:05 +02:00
|
|
|
$r = wp_parse_args( $args, $defaults );
|
2007-06-15 00:45:40 +02:00
|
|
|
extract( $r, EXTR_SKIP );
|
2008-01-04 20:36:34 +01:00
|
|
|
$position = preg_replace( '/[^a-z0-9:_-]/i', '', $position );
|
2006-09-13 23:39:53 +02:00
|
|
|
|
|
|
|
if ( is_wp_error($id) ) {
|
|
|
|
$data = $id;
|
|
|
|
$id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = '';
|
2007-11-01 07:23:16 +01:00
|
|
|
if ( is_wp_error($data) ) {
|
2008-02-05 07:47:27 +01:00
|
|
|
foreach ( $data->get_error_codes() as $code ) {
|
2006-09-13 23:39:53 +02:00
|
|
|
$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
|
2007-11-01 07:23:16 +01: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) ) {
|
|
|
|
$response .= "<![CDATA[$v]]>";
|
|
|
|
} elseif ( is_array($error_data) ) {
|
|
|
|
foreach ( $error_data as $k => $v )
|
|
|
|
$response .= "<$k><![CDATA[$v]]></$k>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$response .= "</wp_error_data>";
|
|
|
|
}
|
|
|
|
} else {
|
2006-09-13 23:39:53 +02:00
|
|
|
$response = "<response_data><![CDATA[$data]]></response_data>";
|
2007-11-01 07:23:16 +01:00
|
|
|
}
|
2006-09-13 23:39:53 +02:00
|
|
|
|
|
|
|
$s = '';
|
2008-02-29 10:51:36 +01:00
|
|
|
if ( (array) $supplemental ) {
|
2006-09-13 23:39:53 +02:00
|
|
|
foreach ( $supplemental as $k => $v )
|
|
|
|
$s .= "<$k><![CDATA[$v]]></$k>";
|
2008-02-29 10:51:36 +01:00
|
|
|
$s = "<supplemental>$s</supplemental>";
|
|
|
|
}
|
2006-09-13 23:39:53 +02:00
|
|
|
|
|
|
|
if ( false === $action )
|
|
|
|
$action = $_POST['action'];
|
|
|
|
|
|
|
|
$x = '';
|
2006-11-08 22:23:41 +01:00
|
|
|
$x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
|
2007-10-10 00:49:42 +02:00
|
|
|
$x .= "<$what id='$id' " . ( false === $old_id ? '' : "old_id='$old_id' " ) . "position='$position'>";
|
2006-09-13 23:39:53 +02:00
|
|
|
$x .= $response;
|
|
|
|
$x .= $s;
|
|
|
|
$x .= "</$what>";
|
|
|
|
$x .= "</response>";
|
|
|
|
|
|
|
|
$this->responses[] = $x;
|
|
|
|
return $x;
|
|
|
|
}
|
|
|
|
|
|
|
|
function send() {
|
2007-06-02 07:21:18 +02:00
|
|
|
header('Content-Type: text/xml');
|
2006-09-13 23:39:53 +02:00
|
|
|
echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
|
|
|
|
foreach ( $this->responses as $response )
|
|
|
|
echo $response;
|
|
|
|
echo '</wp_ajax>';
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-30 21:01:45 +02:00
|
|
|
?>
|