[ Index ]
 

Code source de WordPress 2.1.2

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

title

Body

[fermer]

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

   1  <?php
   2  
   3  require_once(dirname(__FILE__).'/compat.php');
   4  
   5  function mysql2date($dateformatstring, $mysqlstring, $translate = true) {
   6      global $wp_locale;
   7      $m = $mysqlstring;
   8      if ( empty($m) ) {
   9          return false;
  10      }
  11      $i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4));
  12  
  13      if( 'U' == $dateformatstring )
  14          return $i;
  15  
  16      if ( -1 == $i || false == $i )
  17          $i = 0;
  18  
  19      if ( !empty($wp_locale->month) && !empty($wp_locale->weekday) && $translate ) {
  20          $datemonth = $wp_locale->get_month(date('m', $i));
  21          $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
  22          $dateweekday = $wp_locale->get_weekday(date('w', $i));
  23          $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
  24          $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
  25          $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
  26          $dateformatstring = ' '.$dateformatstring;
  27          $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
  28          $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
  29          $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
  30          $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
  31          $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring);
  32          $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring);
  33  
  34          $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
  35      }
  36      $j = @date($dateformatstring, $i);
  37      if ( !$j ) {
  38      // for debug purposes
  39      //    echo $i." ".$mysqlstring;
  40      }
  41      return $j;
  42  }
  43  
  44  function current_time($type, $gmt = 0) {
  45      switch ($type) {
  46          case 'mysql':
  47              if ( $gmt ) $d = gmdate('Y-m-d H:i:s');
  48              else $d = gmdate('Y-m-d H:i:s', (time() + (get_option('gmt_offset') * 3600)));
  49              return $d;
  50              break;
  51          case 'timestamp':
  52              if ( $gmt ) $d = time();
  53              else $d = time() + (get_option('gmt_offset') * 3600);
  54              return $d;
  55              break;
  56      }
  57  }
  58  
  59  function date_i18n($dateformatstring, $unixtimestamp) {
  60      global $wp_locale;
  61      $i = $unixtimestamp;
  62      if ( (!empty($wp_locale->month)) && (!empty($wp_locale->weekday)) ) {
  63          $datemonth = $wp_locale->get_month(date('m', $i));
  64          $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
  65          $dateweekday = $wp_locale->get_weekday(date('w', $i));
  66          $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
  67          $datemeridiem = $wp_locale->get_meridiem(date('a', $i));
  68          $datemeridiem_capital = $wp_locale->get_meridiem(date('A', $i));
  69          $dateformatstring = ' '.$dateformatstring;
  70          $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit($dateweekday_abbrev), $dateformatstring);
  71          $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring);
  72          $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring);
  73          $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit($datemonth_abbrev), $dateformatstring);
  74          $dateformatstring = preg_replace("/([^\\\])a/", "\\1".backslashit($datemeridiem), $dateformatstring);
  75          $dateformatstring = preg_replace("/([^\\\])A/", "\\1".backslashit($datemeridiem_capital), $dateformatstring);
  76  
  77          $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1);
  78      }
  79      $j = @date($dateformatstring, $i);
  80      return $j;
  81  }
  82  
  83  function get_weekstartend($mysqlstring, $start_of_week) {
  84      $my = substr($mysqlstring,0,4);
  85      $mm = substr($mysqlstring,8,2);
  86      $md = substr($mysqlstring,5,2);
  87      $day = mktime(0,0,0, $md, $mm, $my);
  88      $weekday = date('w',$day);
  89      $i = 86400;
  90  
  91      if ( $weekday < get_option('start_of_week') )
  92          $weekday = 7 - (get_option('start_of_week') - $weekday);
  93  
  94      while ($weekday > get_option('start_of_week')) {
  95          $weekday = date('w',$day);
  96          if ( $weekday < get_option('start_of_week') )
  97              $weekday = 7 - (get_option('start_of_week') - $weekday);
  98  
  99          $day = $day - 86400;
 100          $i = 0;
 101      }
 102      $week['start'] = $day + 86400 - $i;
 103      // $week['end'] = $day - $i + 691199;
 104      $week['end'] = $week['start'] + 604799;
 105      return $week;
 106  }
 107  
 108  function get_lastpostdate($timezone = 'server') {
 109      global $cache_lastpostdate, $pagenow, $wpdb, $blog_id;
 110      $add_seconds_blog = get_option('gmt_offset') * 3600;
 111      $add_seconds_server = date('Z');
 112      if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) {
 113          switch(strtolower($timezone)) {
 114              case 'gmt':
 115                  $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
 116                  break;
 117              case 'blog':
 118                  $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
 119                  break;
 120              case 'server':
 121                  $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1");
 122                  break;
 123          }
 124          $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate;
 125      } else {
 126          $lastpostdate = $cache_lastpostdate[$blog_id][$timezone];
 127      }
 128      return $lastpostdate;
 129  }
 130  
 131  function get_lastpostmodified($timezone = 'server') {
 132      global $cache_lastpostmodified, $pagenow, $wpdb, $blog_id;
 133      $add_seconds_blog = get_option('gmt_offset') * 3600;
 134      $add_seconds_server = date('Z');
 135      if ( !isset($cache_lastpostmodified[$blog_id][$timezone]) ) {
 136          switch(strtolower($timezone)) {
 137              case 'gmt':
 138                  $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
 139                  break;
 140              case 'blog':
 141                  $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
 142                  break;
 143              case 'server':
 144                  $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1");
 145                  break;
 146          }
 147          $lastpostdate = get_lastpostdate($timezone);
 148          if ( $lastpostdate > $lastpostmodified ) {
 149              $lastpostmodified = $lastpostdate;
 150          }
 151          $cache_lastpostmodified[$blog_id][$timezone] = $lastpostmodified;
 152      } else {
 153          $lastpostmodified = $cache_lastpostmodified[$blog_id][$timezone];
 154      }
 155      return $lastpostmodified;
 156  }
 157  
 158  function maybe_unserialize($original) {
 159      if ( is_serialized($original) ) // don't attempt to unserialize data that wasn't serialized going in
 160          if ( false !== $gm = @ unserialize($original) )
 161              return $gm;
 162      return $original;
 163  }
 164  
 165  function is_serialized($data) {
 166      // if it isn't a string, it isn't serialized
 167      if ( !is_string($data) )
 168          return false;
 169      $data = trim($data);
 170      if ( 'N;' == $data )
 171          return true;
 172      if ( !preg_match('/^([adObis]):/', $data, $badions) )
 173          return false;
 174      switch ( $badions[1] ) :
 175      case 'a' :
 176      case 'O' :
 177      case 's' :
 178          if ( preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data) )
 179              return true;
 180          break;
 181      case 'b' :
 182      case 'i' :
 183      case 'd' :
 184          if ( preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data) )
 185              return true;
 186          break;
 187      endswitch;
 188      return false;
 189  }
 190  
 191  function is_serialized_string($data) {
 192      // if it isn't a string, it isn't a serialized string
 193      if ( !is_string($data) )
 194          return false;
 195      $data = trim($data);
 196      if ( preg_match('/^s:[0-9]+:.*;$/s',$data) ) // this should fetch all serialized strings
 197          return true;
 198      return false;
 199  }
 200  
 201  /* Options functions */
 202  
 203  function get_option($setting) {
 204      global $wpdb;
 205  
 206      $value = wp_cache_get($setting, 'options');
 207  
 208      if ( false === $value ) {
 209          if ( defined('WP_INSTALLING') )
 210              $wpdb->hide_errors();
 211          $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
 212          if ( defined('WP_INSTALLING') )
 213              $wpdb->show_errors();
 214  
 215          if( is_object( $row) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
 216              $value = $row->option_value;
 217              wp_cache_set($setting, $value, 'options');
 218          } else {
 219              return false;
 220          }
 221      }
 222  
 223      // If home is not set use siteurl.
 224      if ( 'home' == $setting && '' == $value )
 225          return get_option('siteurl');
 226  
 227      if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
 228          $value = preg_replace('|/+$|', '', $value);
 229  
 230      return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
 231  }
 232  
 233  function form_option($option) {
 234      echo attribute_escape(get_option($option));
 235  }
 236  
 237  function get_alloptions() {
 238      global $wpdb, $wp_queries;
 239      $wpdb->hide_errors();
 240      if ( !$options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'") ) {
 241          $options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options");
 242      }
 243      $wpdb->show_errors();
 244  
 245      foreach ($options as $option) {
 246          // "When trying to design a foolproof system,
 247          //  never underestimate the ingenuity of the fools :)" -- Dougal
 248          if ( 'siteurl' == $option->option_name )
 249              $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 250          if ( 'home' == $option->option_name )
 251              $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 252          if ( 'category_base' == $option->option_name )
 253              $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 254          $value = maybe_unserialize($option->option_value);
 255          $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value);
 256      }
 257      return apply_filters('all_options', $all_options);
 258  }
 259  
 260  function update_option($option_name, $newvalue) {
 261      global $wpdb;
 262  
 263      if ( is_string($newvalue) )
 264          $newvalue = trim($newvalue);
 265  
 266      // If the new and old values are the same, no need to update.
 267      $oldvalue = get_option($option_name);
 268      if ( $newvalue == $oldvalue ) {
 269          return false;
 270      }
 271  
 272      if ( false === $oldvalue ) {
 273          add_option($option_name, $newvalue);
 274          return true;
 275      }
 276  
 277      $_newvalue = $newvalue;
 278      $newvalue = maybe_serialize($newvalue);
 279  
 280      wp_cache_set($option_name, $newvalue, 'options');
 281  
 282      $newvalue = $wpdb->escape($newvalue);
 283      $option_name = $wpdb->escape($option_name);
 284      $wpdb->query("UPDATE $wpdb->options SET option_value = '$newvalue' WHERE option_name = '$option_name'");
 285      if ( $wpdb->rows_affected == 1 ) {
 286          do_action("update_option_{$option_name}", $oldvalue, $_newvalue);
 287          return true;
 288      }
 289      return false;
 290  }
 291  
 292  // thx Alex Stapleton, http://alex.vort-x.net/blog/
 293  function add_option($name, $value = '', $description = '', $autoload = 'yes') {
 294      global $wpdb;
 295  
 296      // Make sure the option doesn't already exist
 297      if ( false !== get_option($name) )
 298          return;
 299  
 300      $value = maybe_serialize($value);
 301  
 302      wp_cache_set($name, $value, 'options');
 303  
 304      $name = $wpdb->escape($name);
 305      $value = $wpdb->escape($value);
 306      $description = $wpdb->escape($description);
 307      $wpdb->query("INSERT INTO $wpdb->options (option_name, option_value, option_description, autoload) VALUES ('$name', '$value', '$description', '$autoload')");
 308  
 309      return;
 310  }
 311  
 312  function delete_option($name) {
 313      global $wpdb;
 314      // Get the ID, if no ID then return
 315      $option_id = $wpdb->get_var("SELECT option_id FROM $wpdb->options WHERE option_name = '$name'");
 316      if ( !$option_id ) return false;
 317      $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
 318      wp_cache_delete($name, 'options');
 319      return true;
 320  }
 321  
 322  function maybe_serialize($data) {
 323      if ( is_string($data) )
 324          $data = trim($data);
 325      elseif ( is_array($data) || is_object($data) )
 326          return serialize($data);
 327      if ( is_serialized($data) )
 328          return serialize($data);
 329      return $data;
 330  }
 331  
 332  function gzip_compression() {
 333      if ( !get_option('gzipcompression') ) return false;
 334  
 335      if ( extension_loaded('zlib') ) {
 336          ob_start('ob_gzhandler');
 337      }
 338  }
 339  
 340  function make_url_footnote($content) {
 341      preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches);
 342      $j = 0;
 343      for ($i=0; $i<count($matches[0]); $i++) {
 344          $links_summary = (!$j) ? "\n" : $links_summary;
 345          $j++;
 346          $link_match = $matches[0][$i];
 347          $link_number = '['.($i+1).']';
 348          $link_url = $matches[2][$i];
 349          $link_text = $matches[4][$i];
 350          $content = str_replace($link_match, $link_text.' '.$link_number, $content);
 351          $link_url = ((strtolower(substr($link_url,0,7)) != 'http://') && (strtolower(substr($link_url,0,8)) != 'https://')) ? get_option('home') . $link_url : $link_url;
 352          $links_summary .= "\n".$link_number.' '.$link_url;
 353      }
 354      $content = strip_tags($content);
 355      $content .= $links_summary;
 356      return $content;
 357  }
 358  
 359  
 360  function xmlrpc_getposttitle($content) {
 361      global $post_default_title;
 362      if ( preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle) ) {
 363          $post_title = $matchtitle[0];
 364          $post_title = preg_replace('/<title>/si', '', $post_title);
 365          $post_title = preg_replace('/<\/title>/si', '', $post_title);
 366      } else {
 367          $post_title = $post_default_title;
 368      }
 369      return $post_title;
 370  }
 371  
 372  function xmlrpc_getpostcategory($content) {
 373      global $post_default_category;
 374      if ( preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat) ) {
 375          $post_category = trim($matchcat[1], ',');
 376          $post_category = explode(',', $post_category);
 377      } else {
 378          $post_category = $post_default_category;
 379      }
 380      return $post_category;
 381  }
 382  
 383  function xmlrpc_removepostdata($content) {
 384      $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content);
 385      $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content);
 386      $content = trim($content);
 387      return $content;
 388  }
 389  
 390  function debug_fopen($filename, $mode) {
 391      global $debug;
 392      if ( $debug == 1 ) {
 393          $fp = fopen($filename, $mode);
 394          return $fp;
 395      } else {
 396          return false;
 397      }
 398  }
 399  
 400  function debug_fwrite($fp, $string) {
 401      global $debug;
 402      if ( $debug == 1 ) {
 403          fwrite($fp, $string);
 404      }
 405  }
 406  
 407  function debug_fclose($fp) {
 408      global $debug;
 409      if ( $debug == 1 ) {
 410          fclose($fp);
 411      }
 412  }
 413  
 414  function do_enclose( $content, $post_ID ) {
 415      global $wp_version, $wpdb;
 416      include_once  (ABSPATH . WPINC . '/class-IXR.php');
 417  
 418      $log = debug_fopen(ABSPATH . '/enclosures.log', 'a');
 419      $post_links = array();
 420      debug_fwrite($log, 'BEGIN '.date('YmdHis', time())."\n");
 421  
 422      $pung = get_enclosed( $post_ID );
 423  
 424      $ltrs = '\w';
 425      $gunk = '/#~:.?+=&%@!\-';
 426      $punc = '.:?\-';
 427      $any = $ltrs . $gunk . $punc;
 428  
 429      preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
 430  
 431      debug_fwrite($log, 'Post contents:');
 432      debug_fwrite($log, $content."\n");
 433  
 434      foreach($post_links_temp[0] as $link_test) :
 435          if ( !in_array($link_test, $pung) ) : // If we haven't pung it already
 436              $test = parse_url($link_test);
 437              if ( isset($test['query']) )
 438                  $post_links[] = $link_test;
 439              elseif (($test['path'] != '/') && ($test['path'] != ''))
 440                  $post_links[] = $link_test;
 441          endif;
 442      endforeach;
 443  
 444      foreach ($post_links as $url) :
 445          if ( $url != '' && !$wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE post_id = '$post_ID' AND meta_key = 'enclosure' AND meta_value LIKE ('$url%')") ) {
 446              if ( $headers = wp_get_http_headers( $url) ) {
 447                  $len = (int) $headers['content-length'];
 448                  $type = $wpdb->escape( $headers['content-type'] );
 449                  $allowed_types = array( 'video', 'audio' );
 450                  if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
 451                      $meta_value = "$url\n$len\n$type\n";
 452                      $wpdb->query( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
 453                      VALUES ( '$post_ID', 'enclosure' , '$meta_value')" );
 454                  }
 455              }
 456          }
 457      endforeach;
 458  }
 459  
 460  function wp_get_http_headers( $url, $red = 1 ) {
 461      global $wp_version;
 462      @set_time_limit( 60 );
 463  
 464      if ( $red > 5 )
 465           return false;
 466  
 467      $parts = parse_url( $url );
 468      $file = $parts['path'] . ($parts['query'] ? '?'.$parts['query'] : '');
 469      $host = $parts['host'];
 470      if ( !isset( $parts['port'] ) )
 471          $parts['port'] = 80;
 472  
 473      $head = "HEAD $file HTTP/1.1\r\nHOST: $host\r\nUser-Agent: WordPress/" . $wp_version . "\r\n\r\n";
 474  
 475      $fp = @fsockopen($host, $parts['port'], $err_num, $err_msg, 3);
 476      if ( !$fp )
 477          return false;
 478  
 479      $response = '';
 480      fputs( $fp, $head );
 481      while ( !feof( $fp ) && strpos( $response, "\r\n\r\n" ) == false )
 482          $response .= fgets( $fp, 2048 );
 483      fclose( $fp );
 484      preg_match_all('/(.*?): (.*)\r/', $response, $matches);
 485      $count = count($matches[1]);
 486      for ( $i = 0; $i < $count; $i++) {
 487          $key = strtolower($matches[1][$i]);
 488          $headers["$key"] = $matches[2][$i];
 489      }
 490  
 491      preg_match('/.*([0-9]{3}).*/', $response, $return);
 492      $headers['response'] = $return[1]; // HTTP response code eg 204, 200, 404
 493  
 494          $code = $headers['response'];
 495          if ( ('302' == $code || '301' == $code) && isset($headers['location']) )
 496                  return wp_get_http_headers( $headers['location'], ++$red );
 497  
 498      return $headers;
 499  }
 500  
 501  function is_new_day() {
 502      global $day, $previousday;
 503      if ( $day != $previousday ) {
 504          return(1);
 505      } else {
 506          return(0);
 507      }
 508  }
 509  
 510  function update_post_cache(&$posts) {
 511      global $post_cache, $blog_id;
 512  
 513      if ( !$posts )
 514          return;
 515  
 516      for ($i = 0; $i < count($posts); $i++) {
 517          $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
 518      }
 519  }
 520  
 521  function clean_post_cache($id) {
 522      global $post_cache, $post_meta_cache, $category_cache, $blog_id;
 523  
 524      if ( isset( $post_cache[$blog_id][$id] ) )
 525          unset( $post_cache[$blog_id][$id] );
 526  
 527      if ( isset ($post_meta_cache[$blog_id][$id] ) )
 528          unset( $post_meta_cache[$blog_id][$id] );
 529  
 530      if ( isset( $category_cache[$blog_id][$id]) )
 531          unset ( $category_cache[$blog_id][$id] );
 532  }
 533  
 534  function update_page_cache(&$pages) {
 535      global $page_cache, $blog_id;
 536  
 537      if ( !$pages )
 538          return;
 539  
 540      for ($i = 0; $i < count($pages); $i++) {
 541          $page_cache[$blog_id][$pages[$i]->ID] = &$pages[$i];
 542          wp_cache_add($pages[$i]->ID, $pages[$i], 'pages');
 543      }
 544  }
 545  
 546  function clean_page_cache($id) {
 547      global $page_cache, $blog_id;
 548  
 549      if ( isset( $page_cache[$blog_id][$id] ) )
 550          unset( $page_cache[$blog_id][$id] );
 551  
 552      wp_cache_delete($id, 'pages');
 553      wp_cache_delete( 'all_page_ids', 'pages' );
 554      wp_cache_delete( 'get_pages', 'page' );
 555  }
 556  
 557  function update_post_category_cache($post_ids) {
 558      global $wpdb, $category_cache, $blog_id;
 559  
 560      if ( empty($post_ids) )
 561          return;
 562  
 563      if ( is_array($post_ids) )
 564          $post_id_list = implode(',', $post_ids);
 565  
 566      $post_id_array = (array) explode(',', $post_ids);
 567      $count = count( $post_id_array);
 568      for ( $i = 0; $i < $count; $i++ ) {
 569          $post_id = $post_id_array[ $i ];
 570          if ( isset( $category_cache[$blog_id][$post_id] ) ) {
 571              unset( $post_id_array[ $i ] );
 572              continue;
 573          }
 574      }
 575      if ( count( $post_id_array ) == 0 )
 576          return;
 577      $post_id_list = join( ',', $post_id_array ); // with already cached stuff removed
 578  
 579      $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_id_list)");
 580  
 581      if ( empty($dogs) )
 582          return;
 583  
 584      foreach ($dogs as $catt)
 585          $category_cache[$blog_id][$catt->post_id][$catt->category_id] = &get_category($catt->category_id);
 586  }
 587  
 588  function update_post_caches(&$posts) {
 589      global $post_cache, $category_cache, $post_meta_cache;
 590      global $wpdb, $blog_id;
 591  
 592      // No point in doing all this work if we didn't match any posts.
 593      if ( !$posts )
 594          return;
 595  
 596      // Get the categories for all the posts
 597      for ($i = 0; $i < count($posts); $i++) {
 598          $post_id_array[] = $posts[$i]->ID;
 599          $post_cache[$blog_id][$posts[$i]->ID] = &$posts[$i];
 600      }
 601  
 602      $post_id_list = implode(',', $post_id_array);
 603  
 604      update_post_category_cache($post_id_list);
 605  
 606      update_postmeta_cache($post_id_list);
 607  }
 608  
 609  function update_postmeta_cache($post_id_list = '') {
 610      global $wpdb, $post_meta_cache, $blog_id;
 611  
 612      // We should validate this comma-separated list for the upcoming SQL query
 613      $post_id_list = preg_replace('|[^0-9,]|', '', $post_id_list);
 614  
 615      if ( empty( $post_id_list ) )
 616          return false;
 617  
 618      // we're marking each post as having its meta cached (with no keys... empty array), to prevent posts with no meta keys from being queried again
 619      // any posts that DO have keys will have this empty array overwritten with a proper array, down below
 620      $post_id_array = (array) explode(',', $post_id_list);
 621      $count = count( $post_id_array);
 622      for ( $i = 0; $i < $count; $i++ ) {
 623          $post_id = $post_id_array[ $i ];
 624          if ( isset( $post_meta_cache[$blog_id][$post_id] ) ) { // If the meta is already cached
 625              unset( $post_id_array[ $i ] );
 626              continue;
 627          }
 628          $post_meta_cache[$blog_id][$post_id] = array();
 629      }
 630      if ( count( $post_id_array ) == 0 )
 631          return;
 632      $post_id_list = join( ',', $post_id_array ); // with already cached stuff removeds
 633  
 634      // Get post-meta info
 635      if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) {
 636          // Change from flat structure to hierarchical:
 637          if ( !isset($post_meta_cache) )
 638              $post_meta_cache[$blog_id] = array();
 639  
 640          foreach ($meta_list as $metarow) {
 641              $mpid = (int) $metarow['post_id'];
 642              $mkey = $metarow['meta_key'];
 643              $mval = $metarow['meta_value'];
 644  
 645              // Force subkeys to be array type:
 646              if ( !isset($post_meta_cache[$blog_id][$mpid]) || !is_array($post_meta_cache[$blog_id][$mpid]) )
 647                  $post_meta_cache[$blog_id][$mpid] = array();
 648              if ( !isset($post_meta_cache[$blog_id][$mpid]["$mkey"]) || !is_array($post_meta_cache[$blog_id][$mpid]["$mkey"]) )
 649                  $post_meta_cache[$blog_id][$mpid]["$mkey"] = array();
 650  
 651              // Add a value to the current pid/key:
 652              $post_meta_cache[$blog_id][$mpid][$mkey][] = $mval;
 653          }
 654      }
 655  }
 656  
 657  function update_category_cache() {
 658      return true;
 659  }
 660  
 661  function clean_category_cache($id) {
 662      wp_cache_delete($id, 'category');
 663      wp_cache_delete('all_category_ids', 'category');
 664      wp_cache_delete('get_categories', 'category');
 665  }
 666  
 667  /*
 668  add_query_arg: Returns a modified querystring by adding
 669  a single key & value or an associative array.
 670  Setting a key value to emptystring removes the key.
 671  Omitting oldquery_or_uri uses the $_SERVER value.
 672  
 673  Parameters:
 674  add_query_arg(newkey, newvalue, oldquery_or_uri) or
 675  add_query_arg(associative_array, oldquery_or_uri)
 676  */
 677  function add_query_arg() {
 678      $ret = '';
 679      if ( is_array(func_get_arg(0)) ) {
 680          if ( @func_num_args() < 2 || '' == @func_get_arg(1) )
 681              $uri = $_SERVER['REQUEST_URI'];
 682          else
 683              $uri = @func_get_arg(1);
 684      } else {
 685          if ( @func_num_args() < 3 || '' == @func_get_arg(2) )
 686              $uri = $_SERVER['REQUEST_URI'];
 687          else
 688              $uri = @func_get_arg(2);
 689      }
 690  
 691      if ( $frag = strstr($uri, '#') )
 692          $uri = substr($uri, 0, -strlen($frag));
 693      else
 694          $frag = '';
 695  
 696      if ( preg_match('|^https?://|i', $uri, $matches) ) {
 697          $protocol = $matches[0];
 698          $uri = substr($uri, strlen($protocol));
 699      } else {
 700          $protocol = '';
 701      }
 702  
 703      if ( strstr($uri, '?') ) {
 704          $parts = explode('?', $uri, 2);
 705          if ( 1 == count($parts) ) {
 706              $base = '?';
 707              $query = $parts[0];
 708          } else {
 709              $base = $parts[0] . '?';
 710              $query = $parts[1];
 711          }
 712      } else if ( !empty($protocol) || strstr($uri, '/') ) {
 713          $base = $uri . '?';
 714          $query = '';
 715      } else {
 716          $base = '';
 717          $query = $uri;
 718      }
 719  
 720      parse_str($query, $qs);
 721      if ( is_array(func_get_arg(0)) ) {
 722          $kayvees = func_get_arg(0);
 723          $qs = array_merge($qs, $kayvees);
 724      } else {
 725          $qs[func_get_arg(0)] = func_get_arg(1);
 726      }
 727  
 728      foreach($qs as $k => $v) {
 729          if ( $v !== FALSE ) {
 730              if ( $ret != '' )
 731                  $ret .= '&';
 732              if ( empty($v) && !preg_match('|[?&]' . preg_quote($k, '|') . '=|', $query) )
 733                  $ret .= $k;
 734              else
 735                  $ret .= "$k=$v";
 736          }
 737      }
 738      $ret = $protocol . $base . $ret . $frag;
 739      if ( get_magic_quotes_gpc() )
 740          $ret = stripslashes($ret); // parse_str() adds slashes if magicquotes is on.  See: http://php.net/parse_str
 741      return trim($ret, '?');
 742  }
 743  
 744  /*
 745  remove_query_arg: Returns a modified querystring by removing
 746  a single key or an array of keys.
 747  Omitting oldquery_or_uri uses the $_SERVER value.
 748  
 749  Parameters:
 750  remove_query_arg(removekey, [oldquery_or_uri]) or
 751  remove_query_arg(removekeyarray, [oldquery_or_uri])
 752  */
 753  
 754  function remove_query_arg($key, $query='') {
 755      if ( is_array($key) ) { // removing multiple keys
 756          foreach ( (array) $key as $k )
 757              $query = add_query_arg($k, FALSE, $query);
 758          return $query;
 759      }
 760      return add_query_arg($key, FALSE, $query);
 761  }
 762  
 763  function add_magic_quotes($array) {
 764      global $wpdb;
 765  
 766      foreach ($array as $k => $v) {
 767          if ( is_array($v) ) {
 768              $array[$k] = add_magic_quotes($v);
 769          } else {
 770              $array[$k] = $wpdb->escape($v);
 771          }
 772      }
 773      return $array;
 774  }
 775  
 776  function wp_remote_fopen( $uri ) {
 777      $timeout = 10;
 778      $parsed_url = @parse_url($uri);
 779  
 780      if ( !$parsed_url || !is_array($parsed_url) )
 781          return false;
 782  
 783      if ( !isset($parsed_url['scheme']) || !in_array($parsed_url['scheme'], array('http','https')) )
 784          $uri = 'http://' . $uri;
 785  
 786      if ( ini_get('allow_url_fopen') ) {
 787          $fp = @fopen( $uri, 'r' );
 788          if ( !$fp )
 789              return false;
 790  
 791          //stream_set_timeout($fp, $timeout); // Requires php 4.3
 792          $linea = '';
 793          while( $remote_read = fread($fp, 4096) )
 794              $linea .= $remote_read;
 795          fclose($fp);
 796          return $linea;
 797      } else if ( function_exists('curl_init') ) {
 798          $handle = curl_init();
 799          curl_setopt ($handle, CURLOPT_URL, $uri);
 800          curl_setopt ($handle, CURLOPT_CONNECTTIMEOUT, 1);
 801          curl_setopt ($handle, CURLOPT_RETURNTRANSFER, 1);
 802          curl_setopt ($handle, CURLOPT_TIMEOUT, $timeout);
 803          $buffer = curl_exec($handle);
 804          curl_close($handle);
 805          return $buffer;
 806      } else {
 807          return false;
 808      }
 809  }
 810  
 811  function wp($query_vars = '') {
 812      global $wp;
 813  
 814      $wp->main($query_vars);
 815  }
 816  
 817  function status_header( $header ) {
 818      if ( 200 == $header )
 819          $text = 'OK';
 820      elseif ( 301 == $header )
 821          $text = 'Moved Permanently';
 822      elseif ( 302 == $header )
 823          $text = 'Moved Temporarily';
 824      elseif ( 304 == $header )
 825          $text = 'Not Modified';
 826      elseif ( 404 == $header )
 827          $text = 'Not Found';
 828      elseif ( 410 == $header )
 829          $text = 'Gone';
 830  
 831      if ( version_compare(phpversion(), '4.3.0', '>=') )
 832          @header("HTTP/1.1 $header $text", true, $header);
 833      else
 834          @header("HTTP/1.1 $header $text");
 835  }
 836  
 837  function nocache_headers() {
 838      @ header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
 839      @ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
 840      @ header('Cache-Control: no-cache, must-revalidate, max-age=0');
 841      @ header('Pragma: no-cache');
 842  }
 843  
 844  function cache_javascript_headers() {
 845      $expiresOffset = 864000; // 10 days
 846      header("Content-type: text/javascript; charset=" . get_bloginfo('charset'));
 847      header("Vary: Accept-Encoding"); // Handle proxies
 848      header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
 849  }
 850  
 851  function get_num_queries() {
 852      global $wpdb;
 853      return $wpdb->num_queries;
 854  }
 855  
 856  function bool_from_yn($yn) {
 857          if ($yn == 'Y') return 1;
 858          return 0;
 859  }
 860  
 861  function do_feed() {
 862      $feed = get_query_var('feed');
 863  
 864      // Remove the pad, if present.
 865      $feed = preg_replace('/^_+/', '', $feed);
 866  
 867      if ($feed == '' || $feed == 'feed')
 868          $feed = 'rss2';
 869  
 870      $for_comments = false;
 871      if ( 1 != get_query_var('withoutcomments') && ( is_singular() || get_query_var('withcomments') == 1 || $feed == 'comments-rss2' ) ) {
 872          $feed = 'rss2';
 873          $for_comments = true;    
 874      }
 875  
 876      $hook = 'do_feed_' . $feed;
 877      do_action($hook, $for_comments);
 878  }
 879  
 880  function do_feed_rdf() {
 881      load_template(ABSPATH . 'wp-rdf.php');
 882  }
 883  
 884  function do_feed_rss() {
 885      load_template(ABSPATH . 'wp-rss.php');
 886  }
 887  
 888  function do_feed_rss2($for_comments) {
 889      if ( $for_comments ) {
 890          load_template(ABSPATH . 'wp-commentsrss2.php');
 891      } else {
 892          load_template(ABSPATH . 'wp-rss2.php');
 893      }
 894  }
 895  
 896  function do_feed_atom() {
 897      load_template(ABSPATH . 'wp-atom.php');
 898  }
 899  
 900  function do_robots() {
 901      do_action('do_robotstxt');
 902      if ( '0' == get_option('blog_public') ) {
 903          echo "User-agent: *\n";
 904          echo "Disallow: /\n";
 905      } else {
 906          echo "User-agent: *\n";
 907          echo "Disallow:\n";
 908      }
 909  }
 910  
 911  function is_blog_installed() {
 912      global $wpdb;
 913      $wpdb->hide_errors();
 914      $installed = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'siteurl'");
 915      $wpdb->show_errors();
 916      return $installed;
 917  }
 918  
 919  function wp_nonce_url($actionurl, $action = -1) {
 920      return wp_specialchars(add_query_arg('_wpnonce', wp_create_nonce($action), $actionurl));
 921  }
 922  
 923  function wp_nonce_field($action = -1) {
 924      echo '<input type="hidden" name="_wpnonce" value="' . wp_create_nonce($action) . '" />';
 925      wp_referer_field();
 926  }
 927  
 928  function wp_referer_field() {
 929      $ref = attribute_escape($_SERVER['REQUEST_URI']);
 930      echo '<input type="hidden" name="_wp_http_referer" value="'. $ref . '" />';
 931      if ( wp_get_original_referer() ) {
 932          $original_ref = attribute_escape(stripslashes(wp_get_original_referer()));
 933          echo '<input type="hidden" name="_wp_original_http_referer" value="'. $original_ref . '" />';
 934      }
 935  }
 936  
 937  function wp_original_referer_field() {
 938      echo '<input type="hidden" name="_wp_original_http_referer" value="' . attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
 939  }
 940  
 941  function wp_get_referer() {
 942      foreach ( array($_REQUEST['_wp_http_referer'], $_SERVER['HTTP_REFERER']) as $ref )
 943          if ( !empty($ref) )
 944              return $ref;
 945      return false;
 946  }
 947  
 948  function wp_get_original_referer() {
 949      if ( !empty($_REQUEST['_wp_original_http_referer']) )
 950          return $_REQUEST['_wp_original_http_referer'];
 951      return false;
 952  }
 953  
 954  function wp_mkdir_p($target) {
 955      // from php.net/mkdir user contributed notes
 956      if (file_exists($target)) {
 957          if (! @ is_dir($target))
 958              return false;
 959          else
 960              return true;
 961      }
 962  
 963      // Attempting to create the directory may clutter up our display.
 964      if (@ mkdir($target)) {
 965          $stat = @ stat(dirname($target));
 966          $dir_perms = $stat['mode'] & 0007777;  // Get the permission bits.
 967          @ chmod($target, $dir_perms);
 968          return true;
 969      } else {
 970          if ( is_dir(dirname($target)) )
 971              return false;
 972      }
 973  
 974      // If the above failed, attempt to create the parent node, then try again.
 975      if (wp_mkdir_p(dirname($target)))
 976          return wp_mkdir_p($target);
 977  
 978      return false;
 979  }
 980  
 981  // Returns an array containing the current upload directory's path and url, or an error message.
 982  function wp_upload_dir() {
 983      $siteurl = get_option('siteurl');
 984      //prepend ABSPATH to $dir and $siteurl to $url if they're not already there
 985      $path = str_replace(ABSPATH, '', trim(get_option('upload_path')));
 986      $dir = ABSPATH . $path;
 987      $url = trailingslashit($siteurl) . $path;
 988  
 989      if ( $dir == ABSPATH ) { //the option was empty
 990          $dir = ABSPATH . 'wp-content/uploads';
 991      }
 992  
 993      if ( defined('UPLOADS') ) {
 994          $dir = ABSPATH . UPLOADS;
 995          $url = trailingslashit($siteurl) . UPLOADS;
 996      }
 997  
 998      if ( get_option('uploads_use_yearmonth_folders')) {
 999          // Generate the yearly and monthly dirs
1000          $time = current_time( 'mysql' );
1001          $y = substr( $time, 0, 4 );
1002          $m = substr( $time, 5, 2 );
1003          $dir = $dir . "/$y/$m";
1004          $url = $url . "/$y/$m";
1005      }
1006  
1007      // Make sure we have an uploads dir
1008      if ( ! wp_mkdir_p( $dir ) ) {
1009          $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir);
1010          return array('error' => $message);
1011      }
1012  
1013          $uploads = array('path' => $dir, 'url' => $url, 'error' => false);
1014      return apply_filters('upload_dir', $uploads);
1015  }
1016  
1017  function wp_upload_bits($name, $type, $bits) {
1018      if ( empty($name) )
1019          return array('error' => __("Empty filename"));
1020  
1021      $wp_filetype = wp_check_filetype($name);
1022      if ( !$wp_filetype['ext'] )
1023          return array('error' => __("Invalid file type"));
1024  
1025      $upload = wp_upload_dir();
1026  
1027      if ( $upload['error'] !== false )
1028          return $upload;
1029  
1030      $number = '';
1031      $filename = $name;
1032      $path_parts = pathinfo($filename);
1033      $ext = $path_parts['extension'];
1034      if ( empty($ext) )
1035          $ext = '';
1036      else
1037          $ext = ".$ext";
1038      while ( file_exists($upload['path'] . "/$filename") ) {
1039          if ( '' == "$number$ext" )
1040              $filename = $filename . ++$number . $ext;
1041          else
1042              $filename = str_replace("$number$ext", ++$number . $ext, $filename);
1043      }
1044  
1045      $new_file = $upload['path'] . "/$filename";
1046      if ( ! wp_mkdir_p( dirname($new_file) ) ) {
1047          $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file));
1048          return array('error' => $message);
1049      }
1050  
1051      $ifp = @ fopen($new_file, 'wb');
1052      if ( ! $ifp )
1053          return array('error' => sprintf(__('Could not write file %s'), $new_file));
1054  
1055      $success = @ fwrite($ifp, $bits);
1056      fclose($ifp);
1057      // Set correct file permissions
1058      $stat = @ stat(dirname($new_file));
1059      $perms = $stat['mode'] & 0007777;
1060      $perms = $perms & 0000666;
1061      @ chmod($new_file, $perms);
1062  
1063      // Compute the URL
1064      $url = $upload['url'] . "/$filename";
1065  
1066      return array('file' => $new_file, 'url' => $url, 'error' => false);
1067  }
1068  
1069  function wp_check_filetype($filename, $mimes = null) {
1070      // Accepted MIME types are set here as PCRE unless provided.
1071      $mimes = is_array($mimes) ? $mimes : apply_filters('upload_mimes', array (
1072          'jpg|jpeg|jpe' => 'image/jpeg',
1073          'gif' => 'image/gif',
1074          'png' => 'image/png',
1075          'bmp' => 'image/bmp',
1076          'tif|tiff' => 'image/tiff',
1077          'ico' => 'image/x-icon',
1078          'asf|asx|wax|wmv|wmx' => 'video/asf',
1079          'avi' => 'video/avi',
1080          'mov|qt' => 'video/quicktime',
1081          'mpeg|mpg|mpe' => 'video/mpeg',
1082          'txt|c|cc|h' => 'text/plain',
1083          'rtx' => 'text/richtext',
1084          'css' => 'text/css',
1085          'htm|html' => 'text/html',
1086          'mp3|mp4' => 'audio/mpeg',
1087          'ra|ram' => 'audio/x-realaudio',
1088          'wav' => 'audio/wav',
1089          'ogg' => 'audio/ogg',
1090          'mid|midi' => 'audio/midi',
1091          'wma' => 'audio/wma',
1092          'rtf' => 'application/rtf',
1093          'js' => 'application/javascript',
1094          'pdf' => 'application/pdf',
1095          'doc' => 'application/msword',
1096          'pot|pps|ppt' => 'application/vnd.ms-powerpoint',
1097          'wri' => 'application/vnd.ms-write',
1098          'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',
1099          'mdb' => 'application/vnd.ms-access',
1100          'mpp' => 'application/vnd.ms-project',
1101          'swf' => 'application/x-shockwave-flash',
1102          'class' => 'application/java',
1103          'tar' => 'application/x-tar',
1104          'zip' => 'application/zip',
1105          'gz|gzip' => 'application/x-gzip',
1106          'exe' => 'application/x-msdownload'
1107      ));
1108  
1109      $type = false;
1110      $ext = false;
1111  
1112      foreach ($mimes as $ext_preg => $mime_match) {
1113          $ext_preg = '!\.(' . $ext_preg . ')$!i';
1114          if ( preg_match($ext_preg, $filename, $ext_matches) ) {
1115              $type = $mime_match;
1116              $ext = $ext_matches[1];
1117              break;
1118          }
1119      }
1120  
1121      return compact('ext', 'type');
1122  }
1123  
1124  function wp_explain_nonce($action) {
1125      if ( $action !== -1 && preg_match('/([a-z]+)-([a-z]+)(_(.+))?/', $action, $matches) ) {
1126          $verb = $matches[1];
1127          $noun = $matches[2];
1128  
1129          $trans = array();
1130          $trans['update']['attachment'] = array(__('Are you sure you want to edit this attachment: &quot;%s&quot;?'), 'get_the_title');
1131  
1132          $trans['add']['category'] = array(__('Are you sure you want to add this category?'), false);
1133          $trans['delete']['category'] = array(__('Are you sure you want to delete this category: &quot;%s&quot;?'), 'get_catname');
1134          $trans['update']['category'] = array(__('Are you sure you want to edit this category: &quot;%s&quot;?'), 'get_catname');
1135  
1136          $trans['delete']['comment'] = array(__('Are you sure you want to delete this comment: &quot;%s&quot;?'), 'use_id');
1137          $trans['unapprove']['comment'] = array(__('Are you sure you want to unapprove this comment: &quot;%s&quot;?'), 'use_id');
1138          $trans['approve']['comment'] = array(__('Are you sure you want to approve this comment: &quot;%s&quot;?'), 'use_id');
1139          $trans['update']['comment'] = array(__('Are you sure you want to edit this comment: &quot;%s&quot;?'), 'use_id');
1140          $trans['bulk']['comments'] = array(__('Are you sure you want to bulk modify comments?'), false);
1141          $trans['moderate']['comments'] = array(__('Are you sure you want to moderate comments?'), false);
1142  
1143          $trans['add']['bookmark'] = array(__('Are you sure you want to add this bookmark?'), false);
1144          $trans['delete']['bookmark'] = array(__('Are you sure you want to delete this bookmark: &quot;%s&quot;?'), 'use_id');
1145          $trans['update']['bookmark'] = array(__('Are you sure you want to edit this bookmark: &quot;%s&quot;?'), 'use_id');
1146          $trans['bulk']['bookmarks'] = array(__('Are you sure you want to bulk modify bookmarks?'), false);
1147  
1148          $trans['add']['page'] = array(__('Are you sure you want to add this page?'), false);
1149          $trans['delete']['page'] = array(__('Are you sure you want to delete this page: &quot;%s&quot;?'), 'get_the_title');
1150          $trans['update']['page'] = array(__('Are you sure you want to edit this page: &quot;%s&quot;?'), 'get_the_title');
1151  
1152          $trans['edit']['plugin'] = array(__('Are you sure you want to edit this plugin file: &quot;%s&quot;?'), 'use_id');
1153          $trans['activate']['plugin'] = array(__('Are you sure you want to activate this plugin: &quot;%s&quot;?'), 'use_id');
1154          $trans['deactivate']['plugin'] = array(__('Are you sure you want to deactivate this plugin: &quot;%s&quot;?'), 'use_id');
1155  
1156          $trans['add']['post'] = array(__('Are you sure you want to add this post?'), false);
1157          $trans['delete']['post'] = array(__('Are you sure you want to delete this post: &quot;%s&quot;?'), 'get_the_title');
1158          $trans['update']['post'] = array(__('Are you sure you want to edit this post: &quot;%s&quot;?'), 'get_the_title');
1159  
1160          $trans['add']['user'] = array(__('Are you sure you want to add this user?'), false);
1161          $trans['delete']['users'] = array(__('Are you sure you want to delete users?'), false);
1162          $trans['bulk']['users'] = array(__('Are you sure you want to bulk modify users?'), false);
1163          $trans['update']['user'] = array(__('Are you sure you want to edit this user: &quot;%s&quot;?'), 'get_author_name');
1164          $trans['update']['profile'] = array(__('Are you sure you want to modify the profile for: &quot;%s&quot;?'), 'get_author_name');
1165  
1166          $trans['update']['options'] = array(__('Are you sure you want to edit your settings?'), false);
1167          $trans['update']['permalink'] = array(__('Are you sure you want to change your permalink structure to: %s?'), 'use_id');
1168          $trans['edit']['file'] = array(__('Are you sure you want to edit this file: &quot;%s&quot;?'), 'use_id');
1169          $trans['edit']['theme'] = array(__('Are you sure you want to edit this theme file: &quot;%s&quot;?'), 'use_id');
1170          $trans['switch']['theme'] = array(__('Are you sure you want to switch to this theme: &quot;%s&quot;?'), 'use_id');
1171  
1172          if ( isset($trans[$verb][$noun]) ) {
1173              if ( !empty($trans[$verb][$noun][1]) ) {
1174                  $lookup = $trans[$verb][$noun][1];
1175                  $object = $matches[4];
1176                  if ( 'use_id' != $lookup )
1177                      $object = call_user_func($lookup, $object);
1178                  return sprintf($trans[$verb][$noun][0], $object);
1179              } else {
1180                  return $trans[$verb][$noun][0];
1181              }
1182          }
1183      }
1184  
1185      return apply_filters( 'explain_nonce_' . $verb . '-' . $noun, __('Are you sure you want to do this?'), $matches[4] );
1186  }
1187  
1188  function wp_nonce_ays($action) {
1189      global $pagenow, $menu, $submenu, $parent_file, $submenu_file;
1190  
1191      $adminurl = get_option('siteurl') . '/wp-admin';
1192      if ( wp_get_referer() )
1193          $adminurl = attribute_escape(wp_get_referer());
1194  
1195      $title = __('WordPress Confirmation');
1196      // Remove extra layer of slashes.
1197      $_POST   = stripslashes_deep($_POST  );
1198      if ( $_POST ) {
1199          $q = http_build_query($_POST);
1200          $q = explode( ini_get('arg_separator.output'), $q);
1201          $html .= "\t<form method='post' action='$pagenow'>\n";
1202          foreach ( (array) $q as $a ) {
1203              $v = substr(strstr($a, '='), 1);
1204              $k = substr($a, 0, -(strlen($v)+1));
1205              $html .= "\t\t<input type='hidden' name='" . attribute_escape(urldecode($k)) . "' value='" . attribute_escape(urldecode($v)) . "' />\n";
1206          }
1207          $html .= "\t\t<input type='hidden' name='_wpnonce' value='" . wp_create_nonce($action) . "' />\n";
1208          $html .= "\t\t<div id='message' class='confirm fade'>\n\t\t<p>" . wp_specialchars(wp_explain_nonce($action)) . "</p>\n\t\t<p><a href='$adminurl'>" . __('No') . "</a> <input type='submit' value='" . __('Yes') . "' /></p>\n\t\t</div>\n\t</form>\n";
1209      } else {
1210          $html .= "\t<div id='message' class='confirm fade'>\n\t<p>" . wp_specialchars(wp_explain_nonce($action)) . "</p>\n\t<p><a href='$adminurl'>" . __('No') . "</a> <a href='" . attribute_escape(add_query_arg( '_wpnonce', wp_create_nonce($action), $_SERVER['REQUEST_URI'] )) . "'>" . __('Yes') . "</a></p>\n\t</div>\n";
1211      }
1212      $html .= "</body>\n</html>";
1213      wp_die($html, $title);
1214  }
1215  
1216  function wp_die($message, $title = '') {
1217      global $wp_locale;
1218  
1219      header('Content-Type: text/html; charset=utf-8');
1220  
1221      if ( empty($title) )
1222          $title = __('WordPress &rsaquo; Error');
1223  
1224      if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
1225          $admin_dir = '';
1226      else
1227          $admin_dir = 'wp-admin/';
1228  
1229  ?>
1230  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1231  <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists('language_attributes') ) language_attributes(); ?>>
1232  <head>
1233      <title><?php echo $title ?></title>
1234      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1235      <link rel="stylesheet" href="<?php echo $admin_dir; ?>install.css" type="text/css" />
1236  <?php if ( ('rtl' == $wp_locale->text_direction) ) : ?>
1237      <link rel="stylesheet" href="<?php echo $admin_dir; ?>install-rtl.css" type="text/css" />
1238  <?php endif; ?>
1239  </head>
1240  <body>
1241      <h1 id="logo"><img alt="WordPress" src="<?php echo $admin_dir; ?>images/wordpress-logo.png" /></h1>
1242      <p><?php echo $message; ?></p>
1243  </body>
1244  </html>
1245  <?php
1246  
1247      die();
1248  }
1249  
1250  function _mce_set_direction() {
1251      global $wp_locale;
1252  
1253      if ('rtl' == $wp_locale->text_direction) {
1254          echo 'directionality : "rtl" ,';
1255          echo 'theme_advanced_toolbar_align : "right" ,';
1256      }
1257  }
1258  
1259  function _mce_load_rtl_plugin($input) {
1260      global $wp_locale;
1261  
1262      if ('rtl' == $wp_locale->text_direction)
1263          $input[] = 'directionality';
1264  
1265      return $input;
1266  }
1267  
1268  function _mce_add_direction_buttons($input) {
1269      global $wp_locale;
1270  
1271      if ('rtl' == $wp_locale->text_direction) {
1272          $new_buttons = array('separator', 'ltr', 'rtl');
1273          $input = array_merge($input, $new_buttons);
1274      }
1275  
1276      return $input;
1277  }
1278  ?>


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