[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wp-includes/ -> classes.php (source)

   1  <?php
   2  
   3  class WP {
   4      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', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots');
   5  
   6      var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type');
   7      var $extra_query_vars = array();
   8  
   9      var $query_vars;
  10      var $query_string;
  11      var $request;
  12      var $matched_rule;
  13      var $matched_query;
  14      var $did_permalink = false;
  15  
  16  	function add_query_var($qv) {
  17          $this->public_query_vars[] = $qv;
  18      }
  19  
  20  	function parse_request($extra_query_vars = '') {
  21          global $wp_rewrite;
  22  
  23          $this->query_vars = array();
  24  
  25          if ( is_array($extra_query_vars) )
  26              $this->extra_query_vars = & $extra_query_vars;
  27          else if (! empty($extra_query_vars))
  28              parse_str($extra_query_vars, $this->extra_query_vars);
  29  
  30          // Process PATH_INFO, REQUEST_URI, and 404 for permalinks.
  31  
  32          // Fetch the rewrite rules.
  33          $rewrite = $wp_rewrite->wp_rewrite_rules();
  34  
  35          if (! empty($rewrite)) {
  36              // If we match a rewrite rule, this will be cleared.
  37              $error = '404';
  38              $this->did_permalink = true;
  39  
  40              if ( isset($_SERVER['PATH_INFO']) )
  41                  $pathinfo = $_SERVER['PATH_INFO'];
  42              else
  43                  $pathinfo = '';
  44              $pathinfo_array = explode('?', $pathinfo);
  45              $pathinfo = str_replace("%", "%25", $pathinfo_array[0]);
  46              $req_uri = $_SERVER['REQUEST_URI'];
  47              $req_uri_array = explode('?', $req_uri);
  48              $req_uri = $req_uri_array[0];
  49              $self = $_SERVER['PHP_SELF'];
  50              $home_path = parse_url(get_option('home'));
  51              if ( isset($home_path['path']) )
  52                  $home_path = $home_path['path'];
  53              else
  54                  $home_path = '';
  55              $home_path = trim($home_path, '/');
  56  
  57              // Trim path info from the end and the leading home path from the
  58              // front.  For path info requests, this leaves us with the requesting
  59              // filename, if any.  For 404 requests, this leaves us with the
  60              // requested permalink.
  61              $req_uri = str_replace($pathinfo, '', $req_uri);
  62              $req_uri = trim($req_uri, '/');
  63              $req_uri = preg_replace("|^$home_path|", '', $req_uri);
  64              $req_uri = trim($req_uri, '/');
  65              $pathinfo = trim($pathinfo, '/');
  66              $pathinfo = preg_replace("|^$home_path|", '', $pathinfo);
  67              $pathinfo = trim($pathinfo, '/');
  68              $self = trim($self, '/');
  69              $self = preg_replace("|^$home_path|", '', $self);
  70              $self = str_replace($home_path, '', $self);
  71              $self = trim($self, '/');
  72  
  73              // The requested permalink is in $pathinfo for path info requests and
  74              //  $req_uri for other requests.
  75              if ( ! empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo) ) {
  76                  $request = $pathinfo;
  77              } else {
  78                  // If the request uri is the index, blank it out so that we don't try to match it against a rule.
  79                  if ( $req_uri == $wp_rewrite->index )
  80                      $req_uri = '';
  81                  $request = $req_uri;
  82              }
  83  
  84              $this->request = $request;
  85  
  86              // Look for matches.
  87              $request_match = $request;
  88              foreach ($rewrite as $match => $query) {
  89                  // If the requesting file is the anchor of the match, prepend it
  90                  // to the path info.
  91                  if ((! empty($req_uri)) && (strpos($match, $req_uri) === 0) && ($req_uri != $request)) {
  92                      $request_match = $req_uri . '/' . $request;
  93                  }
  94  
  95                  if (preg_match("!^$match!", $request_match, $matches) ||
  96                      preg_match("!^$match!", urldecode($request_match), $matches)) {
  97                      // Got a match.
  98                      $this->matched_rule = $match;
  99  
 100                      // Trim the query of everything up to the '?'.
 101                      $query = preg_replace("!^.+\?!", '', $query);
 102  
 103                      // Substitute the substring matches into the query.
 104                      eval("\$query = \"$query\";");
 105                      $this->matched_query = $query;
 106  
 107                      // Parse the query.
 108                      parse_str($query, $perma_query_vars);
 109  
 110                      // If we're processing a 404 request, clear the error var
 111                      // since we found something.
 112                      if (isset($_GET['error']))
 113                          unset($_GET['error']);
 114  
 115                      if (isset($error))
 116                          unset($error);
 117  
 118                      break;
 119                  }
 120              }
 121  
 122              // If req_uri is empty or if it is a request for ourself, unset error.
 123              if ( empty($request) || $req_uri == $self || strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) {
 124                  if (isset($_GET['error']))
 125                      unset($_GET['error']);
 126  
 127                  if (isset($error))
 128                      unset($error);
 129  
 130                  if ( isset($perma_query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') )
 131                      unset($perma_query_vars);
 132  
 133                  $this->did_permalink = false;
 134              }
 135          }
 136  
 137          $this->public_query_vars = apply_filters('query_vars', $this->public_query_vars);
 138  
 139          for ($i=0; $i<count($this->public_query_vars); $i += 1) {
 140              $wpvar = $this->public_query_vars[$i];
 141              if (isset($this->extra_query_vars[$wpvar]))
 142                  $this->query_vars[$wpvar] = $this->extra_query_vars[$wpvar];
 143              elseif (isset($GLOBALS[$wpvar]))
 144                  $this->query_vars[$wpvar] = $GLOBALS[$wpvar];
 145              elseif (!empty($_POST[$wpvar]))
 146                  $this->query_vars[$wpvar] = $_POST[$wpvar];
 147              elseif (!empty($_GET[$wpvar]))
 148                  $this->query_vars[$wpvar] = $_GET[$wpvar];
 149              elseif (!empty($perma_query_vars[$wpvar]))
 150                  $this->query_vars[$wpvar] = $perma_query_vars[$wpvar];
 151          }
 152  
 153          foreach ($this->private_query_vars as $var) {
 154              if (isset($this->extra_query_vars[$var]))
 155                  $this->query_vars[$var] = $this->extra_query_vars[$var];
 156              elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
 157                  $this->query_vars[$var] = $GLOBALS[$var];
 158          }
 159  
 160          if ( isset($error) )
 161              $this->query_vars['error'] = $error;
 162  
 163          $this->query_vars = apply_filters('request', $this->query_vars);
 164  
 165          do_action_ref_array('parse_request', array(&$this));
 166      }
 167  
 168  	function send_headers() {
 169          @header('X-Pingback: '. get_bloginfo('pingback_url'));
 170          if ( is_user_logged_in() )
 171              nocache_headers();
 172          if ( !empty($this->query_vars['error']) && '404' == $this->query_vars['error'] ) {
 173              status_header( 404 );
 174              if ( !is_user_logged_in() )
 175                  nocache_headers();
 176              @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
 177          } else if ( empty($this->query_vars['feed']) ) {
 178              @header('Content-type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
 179          } else {
 180              // We're showing a feed, so WP is indeed the only thing that last changed
 181              if ( $this->query_vars['withcomments']
 182                  || ( !$this->query_vars['withoutcomments']
 183                      && ( $this->query_vars['p']
 184                          || $this->query_vars['name']
 185                          || $this->query_vars['page_id']
 186                          || $this->query_vars['pagename']
 187                          || $this->query_vars['attachment']
 188                          || $this->query_vars['attachment_id']
 189                      )
 190                  )
 191              )
 192                  $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastcommentmodified('GMT'), 0).' GMT';
 193              else
 194                  $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT';
 195              $wp_etag = '"' . md5($wp_last_modified) . '"';
 196              @header("Last-Modified: $wp_last_modified");
 197              @header("ETag: $wp_etag");
 198  
 199              // Support for Conditional GET
 200              if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
 201                  $client_etag = stripslashes(stripslashes($_SERVER['HTTP_IF_NONE_MATCH']));
 202              else $client_etag = false;
 203  
 204              $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']);
 205              // If string is empty, return 0. If not, attempt to parse into a timestamp
 206              $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0;
 207  
 208              // Make a timestamp for our most recent modification...
 209              $wp_modified_timestamp = strtotime($wp_last_modified);
 210  
 211              if ( ($client_last_modified && $client_etag) ?
 212                       (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) :
 213                       (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) {
 214                  status_header( 304 );
 215                  exit;
 216              }
 217          }
 218  
 219          do_action_ref_array('send_headers', array(&$this));
 220      }
 221  
 222  	function build_query_string() {
 223          $this->query_string = '';
 224          foreach (array_keys($this->query_vars) as $wpvar) {
 225              if ( '' != $this->query_vars[$wpvar] ) {
 226                  $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
 227                  if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
 228                      continue;
 229                  $this->query_string .= $wpvar . '=' . rawurlencode($this->query_vars[$wpvar]);
 230              }
 231          }
 232  
 233          // query_string filter deprecated.  Use request filter instead.
 234          global $wp_filter;
 235          if ( isset($wp_filter['query_string']) ) {  // Don't bother filtering and parsing if no plugins are hooked in.
 236              $this->query_string = apply_filters('query_string', $this->query_string);
 237              parse_str($this->query_string, $this->query_vars);
 238          }
 239      }
 240  
 241  	function register_globals() {
 242          global $wp_query;
 243          // Extract updated query vars back into global namespace.
 244          foreach ($wp_query->query_vars as $key => $value) {
 245              $GLOBALS[$key] = $value;
 246          }
 247  
 248          $GLOBALS['query_string'] = & $this->query_string;
 249          $GLOBALS['posts'] = & $wp_query->posts;
 250          $GLOBALS['post'] = & $wp_query->post;
 251          $GLOBALS['request'] = & $wp_query->request;
 252  
 253          if ( is_single() || is_page() ) {
 254              $GLOBALS['more'] = 1;
 255              $GLOBALS['single'] = 1;
 256          }
 257      }
 258  
 259  	function init() {
 260          wp_get_current_user();
 261      }
 262  
 263  	function query_posts() {
 264          global $wp_the_query;
 265          $this->build_query_string();
 266          $wp_the_query->query($this->query_vars);
 267       }
 268  
 269  	function handle_404() {
 270          global $wp_query;
 271          // Issue a 404 if a permalink request doesn't match any posts.  Don't
 272          // issue a 404 if one was already issued, if the request was a search,
 273          // or if the request was a regular query string request rather than a
 274          // permalink request.
 275          if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) {
 276              $wp_query->set_404();
 277              status_header( 404 );
 278              nocache_headers();
 279          }    elseif( is_404() != true ) {
 280              status_header( 200 );
 281          }
 282      }
 283  
 284  	function main($query_args = '') {
 285          $this->init();
 286          $this->parse_request($query_args);
 287          $this->send_headers();
 288          $this->query_posts();
 289          $this->handle_404();
 290          $this->register_globals();
 291          do_action_ref_array('wp', array(&$this));
 292      }
 293  
 294      function WP() {
 295          // Empty.
 296      }
 297  }
 298  
 299  class WP_Error {
 300      var $errors = array();
 301      var $error_data = array();
 302  
 303  	function WP_Error($code = '', $message = '', $data = '') {
 304          if ( empty($code) )
 305              return;
 306  
 307          $this->errors[$code][] = $message;
 308  
 309          if ( ! empty($data) )
 310              $this->error_data[$code] = $data;
 311      }
 312  
 313  	function get_error_codes() {
 314          if ( empty($this->errors) )
 315              return array();
 316  
 317          return array_keys($this->errors);
 318      }
 319  
 320  	function get_error_code() {
 321          $codes = $this->get_error_codes();
 322  
 323          if ( empty($codes) )
 324              return '';
 325  
 326          return $codes[0];
 327      }
 328  
 329  	function get_error_messages($code = '') {
 330          // Return all messages if no code specified.
 331          if ( empty($code) ) {
 332              $all_messages = array();
 333              foreach ( $this->errors as $code => $messages )
 334                  $all_messages = array_merge($all_messages, $messages);
 335  
 336              return $all_messages;
 337          }
 338  
 339          if ( isset($this->errors[$code]) )
 340              return $this->errors[$code];
 341          else
 342              return array();
 343      }
 344  
 345  	function get_error_message($code = '') {
 346          if ( empty($code) )
 347              $code = $this->get_error_code();
 348          $messages = $this->get_error_messages($code);
 349          if ( empty($messages) )
 350              return '';
 351          return $messages[0];
 352      }
 353  
 354  	function get_error_data($code = '') {
 355          if ( empty($code) )
 356              $code = $this->get_error_code();
 357  
 358          if ( isset($this->error_data[$code]) )
 359              return $this->error_data[$code];
 360          return null;
 361      }
 362  
 363  	function add($code, $message, $data = '') {
 364          $this->errors[$code][] = $message;
 365          if ( ! empty($data) )
 366              $this->error_data[$code] = $data;
 367      }
 368  
 369  	function add_data($data, $code = '') {
 370          if ( empty($code) )
 371              $code = $this->get_error_code();
 372  
 373          $this->error_data[$code] = $data;
 374      }
 375  }
 376  
 377  function is_wp_error($thing) {
 378      if ( is_object($thing) && is_a($thing, 'WP_Error') )
 379          return true;
 380      return false;
 381  }
 382  
 383  
 384  // A class for displaying various tree-like structures. Extend the Walker class to use it, see examples at the bottom
 385  
 386  class Walker {
 387      var $tree_type;
 388      var $db_fields;
 389  
 390      //abstract callbacks
 391  	function start_lvl($output) { return $output; }
 392  	function end_lvl($output)   { return $output; }
 393  	function start_el($output)  { return $output; }
 394  	function end_el($output)    { return $output; }
 395  
 396  	function walk($elements, $to_depth) {
 397          $args = array_slice(func_get_args(), 2); $parents = array(); $depth = 1; $previous_element = ''; $output = '';
 398  
 399          //padding at the end
 400          $last_element->post_parent = 0;
 401          $last_element->post_id = 0;
 402          $elements[] = $last_element;
 403  
 404          $id_field = $this->db_fields['id'];
 405          $parent_field = $this->db_fields['parent'];
 406  
 407          $flat = ($to_depth == -1) ? true : false;
 408  
 409          foreach ( $elements as $element ) {
 410              // If flat, start and end the element and skip the level checks.
 411              if ( $flat) {
 412                  // Start the element.
 413                  if ( isset($element->$id_field) && $element->$id_field != 0 ) {
 414                      $cb_args = array_merge( array($output, $element, $depth - 1), $args);
 415                      $output = call_user_func_array(array(&$this, 'start_el'), $cb_args);
 416                  }
 417      
 418                  // End the element.
 419                  if ( isset($element->$id_field) && $element->$id_field != 0 ) {
 420                      $cb_args = array_merge( array($output, $element, $depth - 1), $args);
 421                      $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 422                  }
 423      
 424                  continue;    
 425              }
 426      
 427              // Walk the tree.
 428              if ( !empty($previous_element) && ($element->$parent_field == $previous_element->$id_field) ) {
 429                  // Previous element is my parent. Descend a level.
 430                  array_unshift($parents, $previous_element);
 431                  if ( !$to_depth || ($depth < $to_depth) ) { //only descend if we're below $to_depth
 432                      $cb_args = array_merge( array($output, $depth), $args);
 433                      $output = call_user_func_array(array(&$this, 'start_lvl'), $cb_args);
 434                  } else if ( $to_depth && $depth == $to_depth  ) {  // If we've reached depth, end the previous element.
 435                      $cb_args = array_merge( array($output, $previous_element, $depth), $args);
 436                      $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 437                  }
 438                  $depth++; //always do this so when we start the element further down, we know where we are
 439              } else if ( $element->$parent_field == $previous_element->$parent_field) {
 440                  // On the same level as previous element.
 441                  if ( !$to_depth || ($depth <= $to_depth) ) {
 442                      $cb_args = array_merge( array($output, $previous_element, $depth - 1), $args);
 443                      $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 444                  }
 445              } else if ( $depth > 1 ) {
 446                  // Ascend one or more levels.
 447                  if ( !$to_depth || ($depth <= $to_depth) ) {
 448                      $cb_args = array_merge( array($output, $previous_element, $depth - 1), $args);
 449                      $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 450                  }
 451  
 452                  while ( $parent = array_shift($parents) ) {
 453                      $depth--;
 454                      if ( !$to_depth || ($depth < $to_depth) ) {
 455                          $cb_args = array_merge( array($output, $depth), $args);
 456                          $output = call_user_func_array(array(&$this, 'end_lvl'), $cb_args);
 457                          $cb_args = array_merge( array($output, $parent, $depth - 1), $args);
 458                          $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 459                      }
 460                      if ( $element->$parent_field == $parents[0]->$id_field ) {
 461                          break;
 462                      }
 463                  }
 464              } else if ( !empty($previous_element) ) {
 465                  // Close off previous element.
 466                  if ( !$to_depth || ($depth <= $to_depth) ) {
 467                      $cb_args = array_merge( array($output, $previous_element, $depth - 1), $args);
 468                      $output = call_user_func_array(array(&$this, 'end_el'), $cb_args);
 469                  }
 470              }
 471  
 472              // Start the element.
 473              if ( !$to_depth || ($depth <= $to_depth) ) {
 474                  if ( $element->$id_field != 0 ) {
 475                      $cb_args = array_merge( array($output, $element, $depth - 1), $args);
 476                      $output = call_user_func_array(array(&$this, 'start_el'), $cb_args);
 477                  }
 478              }
 479  
 480              $previous_element = $element;
 481          }
 482  
 483          return $output;
 484      }
 485  }
 486  
 487  class Walker_Page extends Walker {
 488      var $tree_type = 'page';
 489      var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this
 490  
 491  	function start_lvl($output, $depth) {
 492          $indent = str_repeat("\t", $depth);
 493          $output .= "\n$indent<ul>\n";
 494          return $output;
 495      }
 496  
 497  	function end_lvl($output, $depth) {
 498          $indent = str_repeat("\t", $depth);
 499          $output .= "$indent</ul>\n";
 500          return $output;
 501      }
 502  
 503  	function start_el($output, $page, $depth, $current_page, $args) {
 504          if ( $depth )
 505              $indent = str_repeat("\t", $depth);
 506          extract($args);
 507          $css_class = 'page_item';
 508          $_current_page = get_page( $current_page );
 509          if ( $page->ID == $current_page )
 510              $css_class .= ' current_page_item';
 511          elseif ( $_current_page && $page->ID == $_current_page->post_parent )
 512              $css_class .= ' current_page_parent';
 513  
 514          $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape($page->post_title) . '">' . $page->post_title . '</a>';
 515      
 516          if ( !empty($show_date) ) {
 517              if ( 'modified' == $show_date )
 518                  $time = $page->post_modified;
 519              else
 520                  $time = $page->post_date;
 521      
 522              $output .= " " . mysql2date($date_format, $time);
 523          }
 524  
 525          return $output;
 526      }
 527      
 528  	function end_el($output, $page, $depth) {
 529          $output .= "</li>\n";
 530  
 531          return $output;
 532      }
 533  
 534  }
 535  
 536  class Walker_PageDropdown extends Walker {
 537      var $tree_type = 'page';
 538      var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this
 539  
 540  	function start_el($output, $page, $depth, $args) {
 541                  $pad = str_repeat('&nbsp;', $depth * 3);
 542  
 543                  $output .= "\t<option value=\"$page->ID\"";
 544                  if ( $page->ID == $args['selected'] )
 545                                  $output .= ' selected="selected"';
 546                  $output .= '>';
 547                  $title = wp_specialchars($page->post_title);
 548                  $output .= "$pad$title";
 549                  $output .= "</option>\n";
 550  
 551                  return $output;
 552      }
 553  }
 554  
 555  class Walker_Category extends Walker {
 556      var $tree_type = 'category';
 557      var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
 558  
 559  	function start_lvl($output, $depth, $args) {
 560          if ( 'list' != $args['style'] )
 561              return $output;
 562  
 563          $indent = str_repeat("\t", $depth);
 564          $output .= "$indent<ul class='children'>\n";
 565          return $output;
 566      }
 567  
 568  	function end_lvl($output, $depth, $args) {
 569          if ( 'list' != $args['style'] )
 570              return $output;
 571  
 572          $indent = str_repeat("\t", $depth);
 573          $output .= "$indent</ul>\n";
 574          return $output;
 575      }
 576  
 577  	function start_el($output, $category, $depth, $args) {
 578          extract($args);
 579  
 580          $cat_name = attribute_escape( $category->cat_name);
 581          $link = '<a href="' . get_category_link( $category->cat_ID ) . '" ';
 582          if ( $use_desc_for_title == 0 || empty($category->category_description) )
 583              $link .= 'title="' . sprintf(__( 'View all posts filed under %s' ), $cat_name) . '"';
 584          else
 585              $link .= 'title="' . attribute_escape( apply_filters( 'category_description', $category->category_description, $category )) . '"';
 586          $link .= '>';
 587          $link .= apply_filters( 'list_cats', $category->cat_name, $category ).'</a>';
 588  
 589          if ( (! empty($feed_image)) || (! empty($feed)) ) {
 590              $link .= ' ';
 591  
 592              if ( empty($feed_image) )
 593                  $link .= '(';
 594  
 595              $link .= '<a href="' . get_category_rss_link( 0, $category->cat_ID, $category->category_nicename ) . '"';
 596  
 597              if ( empty($feed) )
 598                  $alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
 599              else {
 600                  $title = ' title="' . $feed . '"';
 601                  $alt = ' alt="' . $feed . '"';
 602                  $name = $feed;
 603                  $link .= $title;
 604              }
 605  
 606              $link .= '>';
 607  
 608              if ( empty($feed_image) )
 609                  $link .= $name;
 610              else
 611                  $link .= "<img src='$feed_image'$alt$title" . ' />';
 612              $link .= '</a>';
 613              if ( empty($feed_image) )
 614                  $link .= ')';
 615          }
 616      
 617          if ( isset($show_count) && $show_count )
 618              $link .= ' (' . intval($category->category_count) . ')';
 619      
 620          if ( isset($show_date) && $show_date ) {
 621              $link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);
 622          }
 623  
 624          if ( $current_category )
 625              $_current_category = get_category( $current_category );
 626  
 627          if ( 'list' == $args['style'] ) {
 628              $output .= "\t<li";
 629              if ( $current_category && ($category->cat_ID == $current_category) )
 630                  $output .=  ' class="current-cat"';
 631              elseif ( $_current_category && ($category->cat_ID == $_current_category->category_parent) )
 632                  $output .=  ' class="current-cat-parent"';
 633              $output .= ">$link\n";
 634          } else {
 635              $output .= "\t$link<br />\n";
 636          }
 637  
 638          return $output;
 639      }
 640  
 641  	function end_el($output, $page, $depth, $args) {
 642          if ( 'list' != $args['style'] )
 643              return $output;
 644  
 645          $output .= "</li>\n";
 646          return $output;
 647      }
 648  
 649  }
 650  
 651  class Walker_CategoryDropdown extends Walker {
 652      var $tree_type = 'category';
 653      var $db_fields = array ('parent' => 'category_parent', 'id' => 'cat_ID'); //TODO: decouple this
 654  
 655  	function start_el($output, $category, $depth, $args) {
 656          $pad = str_repeat('&nbsp;', $depth * 3);
 657  
 658          $cat_name = apply_filters('list_cats', $category->cat_name, $category);
 659          $output .= "\t<option value=\"".$category->cat_ID."\"";
 660          if ( $category->cat_ID == $args['selected'] )
 661              $output .= ' selected="selected"';
 662          $output .= '>';
 663          $output .= $pad.$cat_name;
 664          if ( $args['show_count'] )
 665              $output .= '&nbsp;&nbsp;('. $category->category_count .')';
 666          if ( $args['show_last_update'] ) {
 667              $format = 'Y-m-d';
 668              $output .= '&nbsp;&nbsp;' . gmdate($format, $category->last_update_timestamp);
 669          }
 670          $output .= "</option>\n";
 671  
 672          return $output;
 673      }
 674  }
 675  
 676  class WP_Ajax_Response {
 677      var $responses = array();
 678  
 679  	function WP_Ajax_Response( $args = '' ) {
 680          if ( !empty($args) )
 681              $this->add($args);
 682      }
 683  
 684      // a WP_Error object can be passed in 'id' or 'data'
 685  	function add( $args = '' ) {
 686          if ( is_array($args) )
 687              $r = &$args;
 688          else
 689              parse_str($args, $r);
 690  
 691          $defaults = array('what' => 'object', 'action' => false, 'id' => '0', 'old_id' => false,
 692                  'data' => '', 'supplemental' => array());
 693  
 694          $r = array_merge($defaults, $r);
 695          extract($r);
 696  
 697          if ( is_wp_error($id) ) {
 698              $data = $id;
 699              $id = 0;
 700          }
 701  
 702          $response = '';
 703          if ( is_wp_error($data) )
 704              foreach ( $data->get_error_codes() as $code )
 705                  $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
 706          else
 707              $response = "<response_data><![CDATA[$data]]></response_data>";
 708  
 709          $s = '';
 710          if ( (array) $supplemental )
 711              foreach ( $supplemental as $k => $v )
 712                  $s .= "<$k><![CDATA[$v]]></$k>";
 713  
 714          if ( false === $action )
 715              $action = $_POST['action'];
 716  
 717          $x = '';
 718          $x .= "<response action='{$action}_$id'>"; // The action attribute in the xml output is formatted like a nonce action
 719          $x .=    "<$what id='$id'" . ( false !== $old_id ? "old_id='$old_id'>" : '>' );
 720          $x .=        $response;
 721          $x .=        $s;
 722          $x .=    "</$what>";
 723          $x .= "</response>";
 724  
 725          $this->responses[] = $x;
 726          return $x;
 727      }
 728  
 729  	function send() {
 730          header('Content-type: text/xml');
 731          echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
 732          foreach ( $this->responses as $response )
 733              echo $response;
 734          echo '</wp_ajax>';
 735          die();
 736      }
 737  }
 738  
 739  ?>


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7