[ Index ]
 

Code source de WordPress 2.1.2

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

title

Body

[fermer]

/wp-admin/ -> upgrade-functions.php (source)

   1  <?php
   2  
   3  if ( file_exists(ABSPATH . 'wp-content/install.php') )
   4      require (ABSPATH . 'wp-content/install.php');
   5  require_once (ABSPATH . '/wp-admin/admin-functions.php');
   6  require_once (ABSPATH . '/wp-admin/admin-db.php');
   7  require_once (ABSPATH . '/wp-admin/upgrade-schema.php');
   8  require_once(ABSPATH . WPINC . '/registration.php');
   9  
  10  if ( !function_exists('wp_install') ) :
  11  function wp_install($blog_title, $user_name, $user_email, $public, $meta='') {
  12      global $wp_rewrite;
  13  
  14      wp_check_mysql_version();
  15      wp_cache_flush();
  16      make_db_current_silent();
  17      populate_options();
  18      populate_roles();
  19  
  20      update_option('blogname', $blog_title);
  21      update_option('admin_email', $user_email);
  22      update_option('blog_public', $public);
  23      $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
  24      $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  25      update_option('siteurl', $guessurl);
  26  
  27      // If not a public blog, don't ping.
  28      if ( ! $public )
  29          update_option('default_pingback_flag', 0);
  30  
  31      // Create default user.  If the user already exists, the user tables are
  32      // being shared among blogs.  Just set the role in that case.
  33      $user_id = username_exists($user_name);
  34      if ( !$user_id ) {
  35          $random_password = substr(md5(uniqid(microtime())), 0, 6);
  36          $user_id = wp_create_user($user_name, $random_password, $user_email);
  37      } else {
  38          $random_password = __('User already exists.  Password inherited.');
  39      }
  40  
  41      $user = new WP_User($user_id);
  42      $user->set_role('administrator');
  43  
  44      wp_install_defaults($user_id);
  45  
  46      $wp_rewrite->flush_rules();
  47  
  48      wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
  49  
  50      wp_cache_flush();
  51  
  52      return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
  53  }
  54  endif;
  55  
  56  if ( !function_exists('wp_install_defaults') ) :
  57  function wp_install_defaults($user_id) {
  58      global $wpdb;
  59  
  60      // Default category
  61      $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
  62  
  63      // Default link category
  64      $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, link_count, category_description) VALUES ('0', '".$wpdb->escape(__('Blogroll'))."', '".sanitize_title(__('Blogroll'))."', '7', '')");
  65  
  66      // Now drop in some default links
  67      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://inphotos.org/', 'Donncha', 0, 'http://inphotos.org/feed/', '');");
  68      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (1, 2)" );
  69  
  70      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 0, 'http://zengun.org/weblog/feed/', '');");
  71      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (2, 2)" );
  72  
  73      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 0, 'http://boren.nu/feed/', '');");
  74      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (3, 2)" );
  75  
  76      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 0, 'http://xml.photomatt.net/feed/', '');");
  77      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (4, 2)" );
  78  
  79      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 0, 'http://zed1.com/journalized/feed/', '');");
  80      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (5, 2)" );
  81  
  82      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 0, 'http://www.alexking.org/blog/wp-rss2.php', '');");
  83      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (6, 2)" );
  84  
  85      $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 0, 'http://dougal.gunters.org/feed/', '');");
  86      $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (7, 2)" );
  87  
  88      // First post
  89      $now = date('Y-m-d H:i:s');
  90      $now_gmt = gmdate('Y-m-d H:i:s');
  91      $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");
  92  
  93      $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
  94  
  95      // Default comment
  96      $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.'))."')");
  97  
  98      // First Page
  99      $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
 100  }
 101  endif;
 102  
 103  if ( !function_exists('wp_new_blog_notification') ) :
 104  function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
 105      $user = new WP_User($user_id);
 106      $email = $user->user_email;
 107      $name = $user->user_login;
 108      $message_headers = 'From: "' . $blog_title . '" <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
 109      $message = sprintf(__("Your new WordPress blog has been successfully set up at:
 110  
 111  %1\$s
 112  
 113  You can log in to the administrator account with the following information:
 114  
 115  Username: %2\$s
 116  Password: %3\$s
 117  
 118  We hope you enjoy your new weblog. Thanks!
 119  
 120  --The WordPress Team
 121  http://wordpress.org/
 122  "), $blog_url, $name, $password);
 123  
 124      @wp_mail($email, __('New WordPress Blog'), $message, $message_headers);
 125  }
 126  endif;
 127  
 128  if ( !function_exists('wp_upgrade') ) :
 129  function wp_upgrade() {
 130      global $wp_current_db_version, $wp_db_version;
 131  
 132      $wp_current_db_version = __get_option('db_version');
 133  
 134      // We are up-to-date.  Nothing to do.
 135      if ( $wp_db_version == $wp_current_db_version )
 136          return;
 137  
 138      wp_check_mysql_version();
 139      wp_cache_flush();
 140      make_db_current_silent();
 141      upgrade_all();
 142      wp_cache_flush();
 143  }
 144  endif;
 145  
 146  // Functions to be called in install and upgrade scripts
 147  function upgrade_all() {
 148      global $wp_current_db_version, $wp_db_version, $wp_rewrite;
 149      $wp_current_db_version = __get_option('db_version');
 150  
 151      // We are up-to-date.  Nothing to do.
 152      if ( $wp_db_version == $wp_current_db_version )
 153          return;
 154  
 155      // If the version is not set in the DB, try to guess the version.
 156      if ( empty($wp_current_db_version) ) {
 157          $wp_current_db_version = 0;
 158  
 159          // If the template option exists, we have 1.5.
 160          $template = __get_option('template');
 161          if ( !empty($template) )
 162              $wp_current_db_version = 2541;
 163      }
 164  
 165      populate_options();
 166  
 167      if ( $wp_current_db_version < 2541 ) {
 168          upgrade_100();
 169          upgrade_101();
 170          upgrade_110();
 171          upgrade_130();
 172      }
 173  
 174      if ( $wp_current_db_version < 3308 )
 175          upgrade_160();
 176  
 177      if ( $wp_current_db_version < 4772 )
 178          upgrade_210();
 179  
 180      if ( $wp_current_db_version < 4351 )
 181          upgrade_old_slugs();
 182  
 183      $wp_rewrite->flush_rules();
 184  
 185      update_option('db_version', $wp_db_version);
 186  }
 187  
 188  function upgrade_100() {
 189      global $wpdb;
 190  
 191      // Get the title and ID of every post, post_name to check if it already has a value
 192      $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''");
 193      if ($posts) {
 194          foreach($posts as $post) {
 195              if ('' == $post->post_name) {
 196                  $newtitle = sanitize_title($post->post_title);
 197                  $wpdb->query("UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
 198              }
 199          }
 200      }
 201  
 202      $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories");
 203      foreach ($categories as $category) {
 204          if ('' == $category->category_nicename) {
 205              $newtitle = sanitize_title($category->cat_name);
 206              $wpdb->query("UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'");
 207          }
 208      }
 209  
 210  
 211      $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
 212      WHERE option_name LIKE 'links_rating_image%'
 213      AND option_value LIKE 'wp-links/links-images/%'");
 214  
 215      $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
 216      if ($done_ids) :
 217          foreach ($done_ids as $done_id) :
 218              $done_posts[] = $done_id->post_id;
 219          endforeach;
 220          $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
 221      else:
 222          $catwhere = '';
 223      endif;
 224  
 225      $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere");
 226      if ($allposts) :
 227          foreach ($allposts as $post) {
 228              // Check to see if it's already been imported
 229              $cat = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
 230              if (!$cat && 0 != $post->post_category) { // If there's no result
 231                  $wpdb->query("
 232                      INSERT INTO $wpdb->post2cat
 233                      (post_id, category_id)
 234                      VALUES
 235                      ('$post->ID', '$post->post_category')
 236                      ");
 237              }
 238          }
 239      endif;
 240  }
 241  
 242  function upgrade_101() {
 243      global $wpdb;
 244  
 245      // Clean up indices, add a few
 246      add_clean_index($wpdb->posts, 'post_name');
 247      add_clean_index($wpdb->posts, 'post_status');
 248      add_clean_index($wpdb->categories, 'category_nicename');
 249      add_clean_index($wpdb->comments, 'comment_approved');
 250      add_clean_index($wpdb->comments, 'comment_post_ID');
 251      add_clean_index($wpdb->links , 'link_category');
 252      add_clean_index($wpdb->links , 'link_visible');
 253  }
 254  
 255  
 256  function upgrade_110() {
 257      global $wpdb;
 258  
 259      // Set user_nicename.
 260      $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");
 261      foreach ($users as $user) {
 262          if ('' == $user->user_nicename) {
 263              $newname = sanitize_title($user->user_nickname);
 264              $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'");
 265          }
 266      }
 267  
 268      $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users");
 269      foreach ($users as $row) {
 270          if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
 271              $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\'');
 272          }
 273      }
 274  
 275  
 276      // Get the GMT offset, we'll use that later on
 277      $all_options = get_alloptions_110();
 278  
 279      $time_difference = $all_options->time_difference;
 280  
 281      $server_time = time()+date('Z');
 282      $weblogger_time = $server_time + $time_difference*3600;
 283      $gmt_time = time();
 284  
 285      $diff_gmt_server = ($gmt_time - $server_time) / 3600;
 286      $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
 287      $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
 288      $gmt_offset = -$diff_gmt_weblogger;
 289  
 290      // Add a gmt_offset option, with value $gmt_offset
 291      add_option('gmt_offset', $gmt_offset);
 292  
 293      // Check if we already set the GMT fields (if we did, then
 294      // MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
 295      // <michel_v> I just slapped myself silly for not thinking about it earlier
 296      $got_gmt_fields = ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00') ? false : true;
 297  
 298      if (!$got_gmt_fields) {
 299  
 300          // Add or substract time to all dates, to get GMT dates
 301          $add_hours = intval($diff_gmt_weblogger);
 302          $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
 303          $wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
 304          $wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
 305          $wpdb->query("UPDATE $wpdb->posts SET post_modified_gmt = DATE_ADD(post_modified, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE) WHERE post_modified != '0000-00-00 00:00:00'");
 306          $wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
 307          $wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
 308      }
 309  
 310  }
 311  
 312  function upgrade_130() {
 313      global $wpdb;
 314  
 315      // Remove extraneous backslashes.
 316      $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
 317      if ($posts) {
 318          foreach($posts as $post) {
 319              $post_content = addslashes(deslash($post->post_content));
 320              $post_title = addslashes(deslash($post->post_title));
 321              $post_excerpt = addslashes(deslash($post->post_excerpt));
 322              if ( empty($post->guid) )
 323                  $guid = get_permalink($post->ID);
 324              else
 325                  $guid = $post->guid;
 326  
 327              $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'");
 328          }
 329      }
 330  
 331      // Remove extraneous backslashes.
 332      $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
 333      if ($comments) {
 334          foreach($comments as $comment) {
 335              $comment_content = addslashes(deslash($comment->comment_content));
 336              $comment_author = addslashes(deslash($comment->comment_author));
 337              $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
 338          }
 339      }
 340  
 341      // Remove extraneous backslashes.
 342      $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
 343      if ($links) {
 344          foreach($links as $link) {
 345              $link_name = addslashes(deslash($link->link_name));
 346              $link_description = addslashes(deslash($link->link_description));
 347              $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
 348          }
 349      }
 350  
 351      // The "paged" option for what_to_show is no more.
 352      if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
 353          $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
 354      }
 355  
 356      $active_plugins = __get_option('active_plugins');
 357  
 358      // If plugins are not stored in an array, they're stored in the old
 359      // newline separated format.  Convert to new format.
 360      if ( !is_array( $active_plugins ) ) {
 361          $active_plugins = explode("\n", trim($active_plugins));
 362          update_option('active_plugins', $active_plugins);
 363      }
 364  
 365      // Obsolete tables
 366      $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
 367      $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
 368      $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
 369      $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');
 370  
 371      // Update comments table to use comment_type
 372      $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
 373      $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
 374  
 375      // Some versions have multiple duplicate option_name rows with the same values
 376      $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
 377      foreach ( $options as $option ) {
 378          if ( 1 != $option->dupes ) { // Could this be done in the query?
 379              $limit = $option->dupes - 1;
 380              $dupe_ids = $wpdb->get_col("SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit");
 381              $dupe_ids = join($dupe_ids, ',');
 382              $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
 383          }
 384      }
 385  
 386      make_site_theme();
 387  }
 388  
 389  function upgrade_160() {
 390      global $wpdb, $wp_current_db_version;
 391  
 392      populate_roles_160();
 393  
 394      $users = $wpdb->get_results("SELECT * FROM $wpdb->users");
 395      foreach ( $users as $user ) :
 396          if ( !empty( $user->user_firstname ) )
 397              update_usermeta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
 398          if ( !empty( $user->user_lastname ) )
 399              update_usermeta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
 400          if ( !empty( $user->user_nickname ) )
 401              update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
 402          if ( !empty( $user->user_level ) )
 403              update_usermeta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
 404          if ( !empty( $user->user_icq ) )
 405              update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
 406          if ( !empty( $user->user_aim ) )
 407              update_usermeta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
 408          if ( !empty( $user->user_msn ) )
 409              update_usermeta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
 410          if ( !empty( $user->user_yim ) )
 411              update_usermeta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
 412          if ( !empty( $user->user_description ) )
 413              update_usermeta( $user->ID, 'description', $wpdb->escape($user->user_description) );
 414  
 415          if ( isset( $user->user_idmode ) ):
 416              $idmode = $user->user_idmode;
 417              if ($idmode == 'nickname') $id = $user->user_nickname;
 418              if ($idmode == 'login') $id = $user->user_login;
 419              if ($idmode == 'firstname') $id = $user->user_firstname;
 420              if ($idmode == 'lastname') $id = $user->user_lastname;
 421              if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
 422              if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
 423              if (!$idmode) $id = $user->user_nickname;
 424              $id = $wpdb->escape( $id );
 425              $wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'");
 426          endif;
 427  
 428          // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
 429          $caps = get_usermeta( $user->ID, $wpdb->prefix . 'capabilities');
 430          if ( empty($caps) || defined('RESET_CAPS') ) {
 431              $level = get_usermeta($user->ID, $wpdb->prefix . 'user_level');
 432              $role = translate_level_to_role($level);
 433              update_usermeta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
 434          }
 435  
 436      endforeach;
 437      $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' );
 438      $wpdb->hide_errors();
 439      foreach ( $old_user_fields as $old )
 440          $wpdb->query("ALTER TABLE $wpdb->users DROP $old");
 441      $wpdb->show_errors();
 442  
 443      if ( 0 == $wpdb->get_var("SELECT SUM(category_count) FROM $wpdb->categories") ) { // Create counts
 444          $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
 445          foreach ( $categories as $cat_id ) {
 446              $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status='publish' AND category_id = '$cat_id'");
 447              $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
 448          }
 449      }
 450  
 451      // populate comment_count field of posts table
 452      $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
 453      if( is_array( $comments ) ) {
 454          foreach ($comments as $comment) {
 455              $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID'" );
 456          }
 457      }
 458  
 459      // Some alpha versions used a post status of object instead of attachment and put
 460      // the mime type in post_type instead of post_mime_type.
 461      if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
 462          $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
 463          foreach ($objects as $object) {
 464              $wpdb->query("UPDATE $wpdb->posts SET post_status = 'attachment',
 465              post_mime_type = '$object->post_type',
 466              post_type = ''
 467              WHERE ID = $object->ID");
 468  
 469              $meta = get_post_meta($object->ID, 'imagedata', true);
 470              if ( ! empty($meta['file']) )
 471                  update_attached_file( $object->ID, $meta['file'] );
 472          }
 473      }
 474  }
 475  
 476  function upgrade_210() {
 477      global $wpdb, $wp_current_db_version;
 478  
 479      if ( $wp_current_db_version < 3506 ) {
 480          // Update status and type.
 481          $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
 482  
 483          if ( ! empty($posts) ) foreach ($posts as $post) {
 484              $status = $post->post_status;
 485              $type = 'post';
 486  
 487              if ( 'static' == $status ) {
 488                  $status = 'publish';
 489                  $type = 'page';
 490              } else if ( 'attachment' == $status ) {
 491                  $status = 'inherit';
 492                  $type = 'attachment';
 493              }
 494  
 495              $wpdb->query("UPDATE $wpdb->posts SET post_status = '$status', post_type = '$type' WHERE ID = '$post->ID'");
 496          }
 497      }
 498  
 499      if ( $wp_current_db_version < 3845 ) {
 500          populate_roles_210();
 501      }
 502  
 503      if ( $wp_current_db_version < 3531 ) {
 504          // Give future posts a post_status of future.
 505          $now = gmdate('Y-m-d H:i:59');
 506          $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");
 507  
 508          $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");
 509          if ( !empty($posts) )
 510              foreach ( $posts as $post )
 511                  wp_schedule_single_event(mysql2date('U', $post->post_date), 'publish_future_post', array($post->ID));
 512      }
 513  
 514      if ( $wp_current_db_version < 3570 ) {
 515          // Create categories for link categories if a category with the same
 516          // name doesn't exist.  Create a map of link cat IDs to cat IDs.
 517          $link_cat_id_map = array();
 518          $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
 519          foreach ( $link_cats as $link_cat) {
 520              if ( $cat_id = category_exists($link_cat->cat_name) ) {
 521                  $link_cat_id_map[$link_cat->cat_id] = $cat_id;
 522                  $default_link_cat = $cat_id;
 523              } else {
 524                  $link_cat_id_map[$link_cat->cat_id] = wp_create_category($link_cat->cat_name);
 525                  $default_link_cat = $link_cat_id_map[$link_cat->cat_id];
 526              }
 527          }
 528  
 529          // Associate links to cats.
 530          $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links");
 531          if ( !empty($links) ) foreach ( $links as $link ) {
 532              if ( 0 == $link->link_category )
 533                  continue;
 534              if ( ! isset($link_cat_id_map[$link->link_category]) )
 535                  continue;
 536              $link_cat = $link_cat_id_map[$link->link_category];
 537              $cat = $wpdb->get_row("SELECT * FROM $wpdb->link2cat WHERE link_id = '$link->link_id' AND category_id = '$link_cat'");
 538              if ( !$cat ) {
 539                  $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id)
 540                      VALUES ('$link->link_id', '$link_cat')");
 541              }
 542          }
 543  
 544          // Set default to the last category we grabbed during the upgrade loop.
 545          update_option('default_link_category', $default_link_cat);
 546  
 547          // Count links per category.
 548          if ( 0 == $wpdb->get_var("SELECT SUM(link_count) FROM $wpdb->categories") ) {
 549              $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
 550              foreach ( $categories as $cat_id ) {
 551                  $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'");
 552                  $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'");
 553              }
 554          }
 555      }
 556  
 557      if ( $wp_current_db_version < 4772 ) {
 558          // Obsolete linkcategories table
 559          $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories');
 560      }
 561  }
 562  
 563  function upgrade_old_slugs() {
 564      // upgrade people who were using the Redirect Old Slugs plugin
 565      global $wpdb;
 566      $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'");
 567  }
 568  
 569  
 570  // The functions we use to actually do stuff
 571  
 572  // General
 573  function maybe_create_table($table_name, $create_ddl) {
 574      global $wpdb;
 575      foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
 576          if ($table == $table_name) {
 577              return true;
 578          }
 579      }
 580      //didn't find it try to create it.
 581      $q = $wpdb->query($create_ddl);
 582      // we cannot directly tell that whether this succeeded!
 583      foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
 584          if ($table == $table_name) {
 585              return true;
 586          }
 587      }
 588      return false;
 589  }
 590  
 591  function drop_index($table, $index) {
 592      global $wpdb;
 593      $wpdb->hide_errors();
 594      $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
 595      // Now we need to take out all the extra ones we may have created
 596      for ($i = 0; $i < 25; $i++) {
 597          $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
 598      }
 599      $wpdb->show_errors();
 600      return true;
 601  }
 602  
 603  function add_clean_index($table, $index) {
 604      global $wpdb;
 605      drop_index($table, $index);
 606      $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
 607      return true;
 608  }
 609  
 610  /**
 611   ** maybe_add_column()
 612   ** Add column to db table if it doesn't exist.
 613   ** Returns:  true if already exists or on successful completion
 614   **           false on error
 615   */
 616  function maybe_add_column($table_name, $column_name, $create_ddl) {
 617      global $wpdb, $debug;
 618      foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
 619          if ($debug) echo("checking $column == $column_name<br />");
 620          if ($column == $column_name) {
 621              return true;
 622          }
 623      }
 624      //didn't find it try to create it.
 625      $q = $wpdb->query($create_ddl);
 626      // we cannot directly tell that whether this succeeded!
 627      foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
 628          if ($column == $column_name) {
 629              return true;
 630          }
 631      }
 632      return false;
 633  }
 634  
 635  
 636  // get_alloptions as it was for 1.2.
 637  function get_alloptions_110() {
 638      global $wpdb;
 639      if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) {
 640          foreach ($options as $option) {
 641              // "When trying to design a foolproof system,
 642              //  never underestimate the ingenuity of the fools :)" -- Dougal
 643              if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 644              if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 645              if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
 646              $all_options->{$option->option_name} = stripslashes($option->option_value);
 647          }
 648      }
 649      return $all_options;
 650  }
 651  
 652  // Version of get_option that is private to install/upgrade.
 653  function __get_option($setting) {
 654      global $wpdb;
 655  
 656      $option = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'");
 657  
 658      if ( 'home' == $setting && '' == $option )
 659          return __get_option('siteurl');
 660  
 661      if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
 662          $option = preg_replace('|/+$|', '', $option);
 663  
 664      @ $kellogs = unserialize($option);
 665      if ($kellogs !== FALSE)
 666          return $kellogs;
 667      else
 668          return $option;
 669  }
 670  
 671  function deslash($content) {
 672      // Note: \\\ inside a regex denotes a single backslash.
 673  
 674      // Replace one or more backslashes followed by a single quote with
 675      // a single quote.
 676      $content = preg_replace("/\\\+'/", "'", $content);
 677  
 678      // Replace one or more backslashes followed by a double quote with
 679      // a double quote.
 680      $content = preg_replace('/\\\+"/', '"', $content);
 681  
 682      // Replace one or more backslashes with one backslash.
 683      $content = preg_replace("/\\\+/", "\\", $content);
 684  
 685      return $content;
 686  }
 687  
 688  function dbDelta($queries, $execute = true) {
 689      global $wpdb;
 690  
 691      // Seperate individual queries into an array
 692      if( !is_array($queries) ) {
 693          $queries = explode( ';', $queries );
 694          if('' == $queries[count($queries) - 1]) array_pop($queries);
 695      }
 696  
 697      $cqueries = array(); // Creation Queries
 698      $iqueries = array(); // Insertion Queries
 699      $for_update = array();
 700  
 701      // Create a tablename index for an array ($cqueries) of queries
 702      foreach($queries as $qry) {
 703          if(preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
 704              $cqueries[strtolower($matches[1])] = $qry;
 705              $for_update[$matches[1]] = 'Created table '.$matches[1];
 706          }
 707          else if(preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
 708              array_unshift($cqueries, $qry);
 709          }
 710          else if(preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
 711              $iqueries[] = $qry;
 712          }
 713          else if(preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
 714              $iqueries[] = $qry;
 715          }
 716          else {
 717              // Unrecognized query type
 718          }
 719      }
 720  
 721      // Check to see which tables and fields exist
 722      if($tables = $wpdb->get_col('SHOW TABLES;')) {
 723          // For every table in the database
 724          foreach($tables as $table) {
 725              // If a table query exists for the database table...
 726              if( array_key_exists(strtolower($table), $cqueries) ) {
 727                  // Clear the field and index arrays
 728                  unset($cfields);
 729                  unset($indices);
 730                  // Get all of the field names in the query from between the parens
 731                  preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
 732                  $qryline = trim($match2[1]);
 733  
 734                  // Separate field lines into an array
 735                  $flds = explode("\n", $qryline);
 736  
 737                  //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
 738  
 739                  // For every field line specified in the query
 740                  foreach($flds as $fld) {
 741                      // Extract the field name
 742                      preg_match("|^([^ ]*)|", trim($fld), $fvals);
 743                      $fieldname = $fvals[1];
 744  
 745                      // Verify the found field name
 746                      $validfield = true;
 747                      switch(strtolower($fieldname))
 748                      {
 749                      case '':
 750                      case 'primary':
 751                      case 'index':
 752                      case 'fulltext':
 753                      case 'unique':
 754                      case 'key':
 755                          $validfield = false;
 756                          $indices[] = trim(trim($fld), ", \n");
 757                          break;
 758                      }
 759                      $fld = trim($fld);
 760  
 761                      // If it's a valid field, add it to the field array
 762                      if($validfield) {
 763                          $cfields[strtolower($fieldname)] = trim($fld, ", \n");
 764                      }
 765                  }
 766  
 767                  // Fetch the table column structure from the database
 768                  $tablefields = $wpdb->get_results("DESCRIBE {$table};");
 769  
 770                  // For every field in the table
 771                  foreach($tablefields as $tablefield) {
 772                      // If the table field exists in the field array...
 773                      if(array_key_exists(strtolower($tablefield->Field), $cfields)) {
 774                          // Get the field type from the query
 775                          preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
 776                          $fieldtype = $matches[1];
 777  
 778                          // Is actual field type different from the field type in query?
 779                          if($tablefield->Type != $fieldtype) {
 780                              // Add a query to change the column type
 781                              $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
 782                              $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
 783                          }
 784  
 785                          // Get the default value from the array
 786                              //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
 787                          if(preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
 788                              $default_value = $matches[1];
 789                              if($tablefield->Default != $default_value)
 790                              {
 791                                  // Add a query to change the column's default value
 792                                  $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
 793                                  $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
 794                              }
 795                          }
 796  
 797                          // Remove the field from the array (so it's not added)
 798                          unset($cfields[strtolower($tablefield->Field)]);
 799                      }
 800                      else {
 801                          // This field exists in the table, but not in the creation queries?
 802                      }
 803                  }
 804  
 805                  // For every remaining field specified for the table
 806                  foreach($cfields as $fieldname => $fielddef) {
 807                      // Push a query line into $cqueries that adds the field to that table
 808                      $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
 809                      $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
 810                  }
 811  
 812                  // Index stuff goes here
 813                  // Fetch the table index structure from the database
 814                  $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
 815  
 816                  if($tableindices) {
 817                      // Clear the index array
 818                      unset($index_ary);
 819  
 820                      // For every index in the table
 821                      foreach($tableindices as $tableindex) {
 822                          // Add the index to the index data array
 823                          $keyname = $tableindex->Key_name;
 824                          $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
 825                          $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
 826                      }
 827  
 828                      // For each actual index in the index array
 829                      foreach($index_ary as $index_name => $index_data) {
 830                          // Build a create string to compare to the query
 831                          $index_string = '';
 832                          if($index_name == 'PRIMARY') {
 833                              $index_string .= 'PRIMARY ';
 834                          }
 835                          else if($index_data['unique']) {
 836                              $index_string .= 'UNIQUE ';
 837                          }
 838                          $index_string .= 'KEY ';
 839                          if($index_name != 'PRIMARY') {
 840                              $index_string .= $index_name;
 841                          }
 842                          $index_columns = '';
 843                          // For each column in the index
 844                          foreach($index_data['columns'] as $column_data) {
 845                              if($index_columns != '') $index_columns .= ',';
 846                              // Add the field to the column list string
 847                              $index_columns .= $column_data['fieldname'];
 848                              if($column_data['subpart'] != '') {
 849                                  $index_columns .= '('.$column_data['subpart'].')';
 850                              }
 851                          }
 852                          // Add the column list to the index create string
 853                          $index_string .= ' ('.$index_columns.')';
 854  
 855                          if(!(($aindex = array_search($index_string, $indices)) === false)) {
 856                              unset($indices[$aindex]);
 857                              //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br/>Found index:".$index_string."</pre>\n";
 858                          }
 859                          //else echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br/><b>Did not find index:</b>".$index_string."<br/>".print_r($indices, true)."</pre>\n";
 860                      }
 861                  }
 862  
 863                  // For every remaining index specified for the table
 864                  foreach($indices as $index) {
 865                      // Push a query line into $cqueries that adds the index to that table
 866                      $cqueries[] = "ALTER TABLE {$table} ADD $index";
 867                      $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
 868                  }
 869  
 870                  // Remove the original table creation query from processing
 871                  unset($cqueries[strtolower($table)]);
 872                  unset($for_update[strtolower($table)]);
 873              } else {
 874                  // This table exists in the database, but not in the creation queries?
 875              }
 876          }
 877      }
 878  
 879      $allqueries = array_merge($cqueries, $iqueries);
 880      if($execute) {
 881          foreach($allqueries as $query) {
 882              //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
 883              $wpdb->query($query);
 884          }
 885      }
 886  
 887      return $for_update;
 888  }
 889  
 890  function make_db_current() {
 891      global $wp_queries;
 892  
 893      $alterations = dbDelta($wp_queries);
 894      echo "<ol>\n";
 895      foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
 896      echo "</ol>\n";
 897  }
 898  
 899  function make_db_current_silent() {
 900      global $wp_queries;
 901  
 902      $alterations = dbDelta($wp_queries);
 903  }
 904  
 905  function make_site_theme_from_oldschool($theme_name, $template) {
 906      $home_path = get_home_path();
 907      $site_dir = ABSPATH . "wp-content/themes/$template";
 908  
 909      if (! file_exists("$home_path/index.php"))
 910          return false;
 911  
 912      // Copy files from the old locations to the site theme.
 913      // TODO: This does not copy arbitarary include dependencies.  Only the
 914      // standard WP files are copied.
 915      $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
 916  
 917      foreach ($files as $oldfile => $newfile) {
 918          if ($oldfile == 'index.php')
 919              $oldpath = $home_path;
 920          else
 921              $oldpath = ABSPATH;
 922  
 923          if ($oldfile == 'index.php') { // Check to make sure it's not a new index
 924              $index = implode('', file("$oldpath/$oldfile"));
 925              if ( strstr( $index, 'WP_USE_THEMES' ) ) {
 926                  if (! @copy(ABSPATH . 'wp-content/themes/default/index.php', "$site_dir/$newfile"))
 927                      return false;
 928                  continue; // Don't copy anything
 929                  }
 930          }
 931  
 932          if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile"))
 933              return false;
 934  
 935          chmod("$site_dir/$newfile", 0777);
 936  
 937          // Update the blog header include in each file.
 938          $lines = explode("\n", implode('', file("$site_dir/$newfile")));
 939          if ($lines) {
 940              $f = fopen("$site_dir/$newfile", 'w');
 941  
 942              foreach ($lines as $line) {
 943                  if (preg_match('/require.*wp-blog-header/', $line))
 944                      $line = '//' . $line;
 945  
 946                  // Update stylesheet references.
 947                  $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
 948  
 949                  // Update comments template inclusion.
 950                  $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
 951  
 952                  fwrite($f, "{$line}\n");
 953              }
 954              fclose($f);
 955          }
 956      }
 957  
 958      // Add a theme header.
 959      $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the upgrade.\nVersion: 1.0\nAuthor: Moi\n*/\n";
 960  
 961      $stylelines = file_get_contents("$site_dir/style.css");
 962      if ($stylelines) {
 963          $f = fopen("$site_dir/style.css", 'w');
 964  
 965          fwrite($f, $header);
 966          fwrite($f, $stylelines);
 967          fclose($f);
 968      }
 969  
 970      return true;
 971  }
 972  
 973  function make_site_theme_from_default($theme_name, $template) {
 974      $site_dir = ABSPATH . "wp-content/themes/$template";
 975      $default_dir = ABSPATH . 'wp-content/themes/default';
 976  
 977      // Copy files from the default theme to the site theme.
 978      //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
 979  
 980      $theme_dir = @ dir("$default_dir");
 981      if ($theme_dir) {
 982          while(($theme_file = $theme_dir->read()) !== false) {
 983              if (is_dir("$default_dir/$theme_file"))
 984                  continue;
 985              if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
 986                  return;
 987              chmod("$site_dir/$theme_file", 0777);
 988          }
 989      }
 990  
 991      // Rewrite the theme header.
 992      $stylelines = explode("\n", implode('', file("$site_dir/style.css")));
 993      if ($stylelines) {
 994          $f = fopen("$site_dir/style.css", 'w');
 995  
 996          foreach ($stylelines as $line) {
 997              if (strstr($line, "Theme Name:")) $line = "Theme Name: $theme_name";
 998              elseif (strstr($line, "Theme URI:")) $line = "Theme URI: " . __get_option('siteurl');
 999              elseif (strstr($line, "Description:")) $line = "Description: Your theme";
1000              elseif (strstr($line, "Version:")) $line = "Version: 1";
1001              elseif (strstr($line, "Author:")) $line = "Author: You";
1002              fwrite($f, "{$line}\n");
1003          }
1004          fclose($f);
1005      }
1006  
1007      // Copy the images.
1008      umask(0);
1009      if (! mkdir("$site_dir/images", 0777)) {
1010          return false;
1011      }
1012  
1013      $images_dir = @ dir("$default_dir/images");
1014      if ($images_dir) {
1015          while(($image = $images_dir->read()) !== false) {
1016              if (is_dir("$default_dir/images/$image"))
1017                  continue;
1018              if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
1019                  return;
1020              chmod("$site_dir/images/$image", 0777);
1021          }
1022      }
1023  }
1024  
1025  // Create a site theme from the default theme.
1026  function make_site_theme() {
1027      // Name the theme after the blog.
1028      $theme_name = __get_option('blogname');
1029      $template = sanitize_title($theme_name);
1030      $site_dir = ABSPATH . "wp-content/themes/$template";
1031  
1032      // If the theme already exists, nothing to do.
1033      if ( is_dir($site_dir)) {
1034          return false;
1035      }
1036  
1037      // We must be able to write to the themes dir.
1038      if (! is_writable(ABSPATH . "wp-content/themes")) {
1039          return false;
1040      }
1041  
1042      umask(0);
1043      if (! mkdir($site_dir, 0777)) {
1044          return false;
1045      }
1046  
1047      if (file_exists(ABSPATH . 'wp-layout.css')) {
1048          if (! make_site_theme_from_oldschool($theme_name, $template)) {
1049              // TODO:  rm -rf the site theme directory.
1050              return false;
1051          }
1052      } else {
1053          if (! make_site_theme_from_default($theme_name, $template))
1054              // TODO:  rm -rf the site theme directory.
1055              return false;
1056      }
1057  
1058      // Make the new site theme active.
1059      $current_template = __get_option('template');
1060      if ($current_template == 'default') {
1061          update_option('template', $template);
1062          update_option('stylesheet', $template);
1063      }
1064      return $template;
1065  }
1066  
1067  function translate_level_to_role($level) {
1068      switch ($level) {
1069      case 10:
1070      case 9:
1071      case 8:
1072          return 'administrator';
1073      case 7:
1074      case 6:
1075      case 5:
1076          return 'editor';
1077      case 4:
1078      case 3:
1079      case 2:
1080          return 'author';
1081      case 1:
1082          return 'contributor';
1083      case 0:
1084          return 'subscriber';
1085      }
1086  }
1087  
1088  function wp_check_mysql_version() {
1089      global $wp_version;
1090  
1091      // Make sure the server has MySQL 4.0
1092      $mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info());
1093      if ( version_compare($mysql_version, '4.0.0', '<') )
1094          die(sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
1095  }
1096  
1097  ?>


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