summaryrefslogtreecommitdiffstats
path: root/wp-admin/includes
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
commit3a4570b0fc8b3d6339bef71d17d7701554e0bbf7 (patch)
tree2a06e5261263c68d8afd95a6328879dc289cb909 /wp-admin/includes
parentb83c34a7010faee0223f6037025c350da12e05e6 (diff)
downloadwordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.gz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.xz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.zip
Merge with WP 2.3 - testing use only!
Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1069 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/includes')
-rw-r--r--wp-admin/includes/admin.php22
-rw-r--r--wp-admin/includes/bookmark.php177
-rw-r--r--wp-admin/includes/comment.php68
-rw-r--r--wp-admin/includes/file.php189
-rw-r--r--wp-admin/includes/image.php192
-rw-r--r--wp-admin/includes/import.php45
-rw-r--r--wp-admin/includes/misc.php178
-rw-r--r--wp-admin/includes/mu.php202
-rw-r--r--wp-admin/includes/plugin.php382
-rw-r--r--wp-admin/includes/post.php471
-rw-r--r--wp-admin/includes/schema.php474
-rw-r--r--wp-admin/includes/taxonomy.php148
-rw-r--r--wp-admin/includes/template.php626
-rw-r--r--wp-admin/includes/theme.php52
-rw-r--r--wp-admin/includes/update.php122
-rw-r--r--wp-admin/includes/upgrade.php1271
-rw-r--r--wp-admin/includes/upload.php381
-rw-r--r--wp-admin/includes/user.php284
18 files changed, 5284 insertions, 0 deletions
diff --git a/wp-admin/includes/admin.php b/wp-admin/includes/admin.php
new file mode 100644
index 0000000..04a4bc1
--- /dev/null
+++ b/wp-admin/includes/admin.php
@@ -0,0 +1,22 @@
+<?php
+
+require_once(ABSPATH . 'wp-admin/includes/bookmark.php');
+require_once(ABSPATH . 'wp-admin/includes/comment.php');
+require_once(ABSPATH . 'wp-admin/includes/file.php');
+require_once(ABSPATH . 'wp-admin/includes/image.php');
+require_once(ABSPATH . 'wp-admin/includes/import.php');
+require_once(ABSPATH . 'wp-admin/includes/misc.php');
+require_once(ABSPATH . 'wp-admin/includes/plugin.php');
+require_once(ABSPATH . 'wp-admin/includes/post.php');
+require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
+require_once(ABSPATH . 'wp-admin/includes/template.php');
+require_once(ABSPATH . 'wp-admin/includes/theme.php');
+require_once(ABSPATH . 'wp-admin/includes/user.php');
+require_once(ABSPATH . 'wp-admin/includes/update.php');
+
+// MU specific
+require_once(ABSPATH . 'wp-admin/includes/mu.php');
+
+require_once(ABSPATH . WPINC . '/registration.php');
+
+?>
diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php
new file mode 100644
index 0000000..35cc9c9
--- /dev/null
+++ b/wp-admin/includes/bookmark.php
@@ -0,0 +1,177 @@
+<?php
+
+function add_link() {
+ return edit_link();
+}
+
+function edit_link( $link_id = '' ) {
+ if (!current_user_can( 'manage_links' ))
+ wp_die( __( 'Cheatin&#8217; uh?' ));
+
+ $_POST['link_url'] = wp_specialchars( $_POST['link_url'] );
+ $_POST['link_url'] = clean_url($_POST['link_url']);
+ $_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
+ $_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
+ $_POST['link_rss'] = clean_url($_POST['link_rss']);
+
+ if ( !empty( $link_id ) ) {
+ $_POST['link_id'] = $link_id;
+ return wp_update_link( $_POST);
+ } else {
+ return wp_insert_link( $_POST);
+ }
+}
+
+function get_default_link_to_edit() {
+ if ( isset( $_GET['linkurl'] ) )
+ $link->link_url = clean_url( $_GET['linkurl']);
+ else
+ $link->link_url = '';
+
+ if ( isset( $_GET['name'] ) )
+ $link->link_name = attribute_escape( $_GET['name']);
+ else
+ $link->link_name = '';
+
+ $link->link_visible = 'Y';
+
+ return $link;
+}
+
+function wp_delete_link($link_id) {
+ global $wpdb;
+
+ do_action('delete_link', $link_id);
+
+ wp_delete_object_term_relationships($link_id, 'link_category');
+
+ $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'");
+
+ do_action('deleted_link', $link_id);
+
+ return true;
+}
+
+function wp_get_link_cats($link_id = 0) {
+
+ $cats = wp_get_object_terms($link_id, 'link_category', 'fields=ids');
+
+ return array_unique($cats);
+}
+
+function get_link_to_edit( $link_id ) {
+ return get_link( $link_id, OBJECT, 'edit' );
+}
+
+function wp_insert_link($linkdata) {
+ global $wpdb, $current_user;
+
+ $defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 );
+
+ $linkdata = wp_parse_args($linkdata, $defaults);
+ $linkdata = sanitize_bookmark($linkdata, 'db');
+
+ extract($linkdata, EXTR_SKIP);
+
+ $update = false;
+
+ if ( !empty($link_id) )
+ $update = true;
+
+ if ( trim( $link_name ) == '' )
+ return 0;
+
+ if ( trim( $link_url ) == '' )
+ return 0;
+
+ if ( empty($link_rating) )
+ $link_rating = 0;
+
+ if ( empty($link_image) )
+ $link_image = '';
+
+ if ( empty($link_target) )
+ $link_target = '';
+
+ if ( empty($link_visible) )
+ $link_visible = 'Y';
+
+ if ( empty($link_owner) )
+ $link_owner = $current_user->id;
+
+ if ( empty($link_notes) )
+ $link_notes = '';
+
+ if ( empty($link_description) )
+ $link_description = '';
+
+ if ( empty($link_rss) )
+ $link_rss = '';
+
+ if ( empty($link_rel) )
+ $link_rel = '';
+
+ // Make sure we set a valid category
+ if (0 == count($link_category) || !is_array($link_category)) {
+ $link_category = array(get_option('default_link_category'));
+ }
+
+ if ( $update ) {
+ $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url',
+ link_name='$link_name', link_image='$link_image',
+ link_target='$link_target',
+ link_visible='$link_visible', link_description='$link_description',
+ link_rating='$link_rating', link_rel='$link_rel',
+ link_notes='$link_notes', link_rss = '$link_rss'
+ WHERE link_id='$link_id'");
+ } else {
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')");
+ $link_id = (int) $wpdb->insert_id;
+ }
+
+ wp_set_link_cats($link_id, $link_category);
+
+ if ( $update )
+ do_action('edit_link', $link_id);
+ else
+ do_action('add_link', $link_id);
+
+ return $link_id;
+}
+
+function wp_set_link_cats($link_id = 0, $link_categories = array()) {
+ // If $link_categories isn't already an array, make it one:
+ if (!is_array($link_categories) || 0 == count($link_categories))
+ $link_categories = array(get_option('default_link_category'));
+
+ $link_categories = array_map('intval', $link_categories);
+ $link_categories = array_unique($link_categories);
+
+ wp_set_object_terms($link_id, $link_categories, 'link_category');
+} // wp_set_link_cats()
+
+function wp_update_link($linkdata) {
+ global $wpdb;
+
+ $link_id = (int) $linkdata['link_id'];
+
+ $link = get_link($link_id, ARRAY_A);
+
+ // Escape data pulled from DB.
+ $link = add_magic_quotes($link);
+
+ // Passed link category list overwrites existing category list if not empty.
+ if ( isset($linkdata['link_category']) && is_array($linkdata['link_category'])
+ && 0 != count($linkdata['link_category']) )
+ $link_cats = $linkdata['link_category'];
+ else
+ $link_cats = $link['link_category'];
+
+ // Merge old and new fields with new fields overwriting old ones.
+ $linkdata = array_merge($link, $linkdata);
+ $linkdata['link_category'] = $link_cats;
+
+ return wp_insert_link($linkdata);
+}
+
+?> \ No newline at end of file
diff --git a/wp-admin/includes/comment.php b/wp-admin/includes/comment.php
new file mode 100644
index 0000000..ae0d1d9
--- /dev/null
+++ b/wp-admin/includes/comment.php
@@ -0,0 +1,68 @@
+<?php
+
+function comment_exists($comment_author, $comment_date) {
+ global $wpdb;
+
+ return $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments
+ WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");
+}
+
+function edit_comment() {
+ global $user_ID;
+
+ $comment_ID = (int) $_POST['comment_ID'];
+ $comment_post_ID = (int) $_POST['comment_post_ID'];
+
+ if (!current_user_can( 'edit_post', $comment_post_ID ))
+ wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' ));
+
+ $_POST['comment_author'] = $_POST['newcomment_author'];
+ $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
+ $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
+ $_POST['comment_approved'] = $_POST['comment_status'];
+ $_POST['comment_content'] = $_POST['content'];
+ $_POST['comment_ID'] = (int) $_POST['comment_ID'];
+
+ if (!empty ( $_POST['edit_date'] ) ) {
+ $aa = $_POST['aa'];
+ $mm = $_POST['mm'];
+ $jj = $_POST['jj'];
+ $hh = $_POST['hh'];
+ $mn = $_POST['mn'];
+ $ss = $_POST['ss'];
+ $jj = ($jj > 31 ) ? 31 : $jj;
+ $hh = ($hh > 23 ) ? $hh -24 : $hh;
+ $mn = ($mn > 59 ) ? $mn -60 : $mn;
+ $ss = ($ss > 59 ) ? $ss -60 : $ss;
+ $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
+ }
+
+ wp_update_comment( $_POST);
+}
+
+function get_comment_to_edit( $id ) {
+ if ( !$comment = get_comment($id) )
+ return false;
+
+ $comment->comment_ID = (int) $comment->comment_ID;
+ $comment->comment_post_ID = (int) $comment->comment_post_ID;
+
+ $comment->comment_content = format_to_edit( $comment->comment_content );
+ $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);
+
+ $comment->comment_author = format_to_edit( $comment->comment_author );
+ $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
+ $comment->comment_author_url = clean_url($comment->comment_author_url);
+ $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
+
+ return $comment;
+}
+
+function get_pending_comments_num( $post_id ) {
+ global $wpdb;
+ $post_id = (int) $post_id;
+ $pending = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '0'" );
+ return $pending;
+}
+
+?> \ No newline at end of file
diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php
new file mode 100644
index 0000000..2d58852
--- /dev/null
+++ b/wp-admin/includes/file.php
@@ -0,0 +1,189 @@
+<?php
+
+$wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ),
+ // Deprecated files
+ 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ));
+function get_file_description( $file ) {
+ global $wp_file_descriptions;
+
+ if ( isset( $wp_file_descriptions[basename( $file )] ) ) {
+ return $wp_file_descriptions[basename( $file )];
+ }
+ elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) {
+ $template_data = implode( '', file( ABSPATH . $file ) );
+ if ( preg_match( "|Template Name:(.*)|i", $template_data, $name ))
+ return $name[1];
+ }
+
+ return basename( $file );
+}
+
+function get_home_path() {
+ $home = get_option( 'home' );
+ if ( $home != '' && $home != get_option( 'siteurl' ) ) {
+ $home_path = parse_url( $home );
+ $home_path = $home_path['path'];
+ $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] );
+ $home_path = trailingslashit( $root.$home_path );
+ } else {
+ $home_path = ABSPATH;
+ }
+
+ return $home_path;
+}
+
+function get_real_file_to_edit( $file ) {
+ if ('index.php' == $file || '.htaccess' == $file ) {
+ $real_file = get_home_path().$file;
+ } else {
+ $real_file = ABSPATH.$file;
+ }
+
+ return $real_file;
+}
+
+function validate_file( $file, $allowed_files = '' ) {
+ if ( false !== strpos( $file, './' ))
+ return 1;
+
+ if (':' == substr( $file, 1, 1 ))
+ return 2;
+
+ if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) )
+ return 3;
+
+ return 0;
+}
+
+function validate_file_to_edit( $file, $allowed_files = '' ) {
+ $file = stripslashes( $file );
+
+ $code = validate_file( $file, $allowed_files );
+
+ if (!$code )
+ return $file;
+
+ switch ( $code ) {
+ case 1 :
+ wp_die( __('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
+
+ case 2 :
+ wp_die( __('Sorry, can&#8217;t call files with their real path.' ));
+
+ case 3 :
+ wp_die( __('Sorry, that file cannot be edited.' ));
+ }
+}
+
+// array wp_handle_upload ( array &file [, array overrides] )
+// file: reference to a single element of $_FILES. Call the function once for each uploaded file.
+// overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
+// On success, returns an associative array of file attributes.
+// On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
+function wp_handle_upload( &$file, $overrides = false ) {
+ // The default error handler.
+ if (! function_exists( 'wp_handle_upload_error' ) ) {
+ function wp_handle_upload_error( &$file, $message ) {
+ return array( 'error'=>$message );
+ }
+ }
+
+ // You may define your own function and pass the name in $overrides['upload_error_handler']
+ $upload_error_handler = 'wp_handle_upload_error';
+
+ // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
+ $action = 'wp_handle_upload';
+
+ // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error'].
+ $upload_error_strings = array( false,
+ __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ),
+ __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ),
+ __( "The uploaded file was only partially uploaded." ),
+ __( "No file was uploaded." ),
+ __( "Missing a temporary folder." ),
+ __( "Failed to write file to disk." ));
+
+ // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
+ $test_form = true;
+ $test_size = true;
+
+ // If you override this, you must provide $ext and $type!!!!
+ $test_type = true;
+
+ // Install user overrides. Did we mention that this voids your warranty?
+ if ( is_array( $overrides ) )
+ extract( $overrides, EXTR_OVERWRITE );
+
+ // A correct form post will pass this test.
+ if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
+ return $upload_error_handler( $file, __( 'Invalid form submission.' ));
+
+ // A successful upload will pass this test. It makes no sense to override this one.
+ if ( $file['error'] > 0 )
+ return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
+
+ // A non-empty file will pass this test.
+ if ( $test_size && !($file['size'] > 0 ) )
+ return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' ));
+
+ // A properly uploaded file will pass this test. There should be no reason to override this one.
+ if (! @ is_uploaded_file( $file['tmp_name'] ) )
+ return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
+
+ // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
+ if ( $test_type ) {
+ $wp_filetype = wp_check_filetype( $file['name'], $mimes );
+
+ extract( $wp_filetype );
+
+ if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
+ return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
+
+ if ( !$ext )
+ $ext = ltrim(strrchr($file['name'], '.'), '.');
+ }
+
+ // A writable uploads dir will pass this test. Again, there's no point overriding this one.
+ if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
+ return $upload_error_handler( $file, $uploads['error'] );
+
+ // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
+ if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) {
+ $filename = $unique_filename_callback( $uploads['path'], $file['name'] );
+ } else {
+ $number = '';
+ $filename = str_replace( '#', '_', $file['name'] );
+ $filename = str_replace( array( '\\', "'" ), '', $filename );
+ if ( empty( $ext) )
+ $ext = '';
+ else
+ $ext = ".$ext";
+ while ( file_exists( $uploads['path'] . "/$filename" ) ) {
+ if ( '' == "$number$ext" )
+ $filename = $filename . ++$number . $ext;
+ else
+ $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
+ }
+ $filename = str_replace( $ext, '', $filename );
+ $filename = sanitize_title_with_dashes( $filename ) . $ext;
+ }
+
+ // Move the file to the uploads dir
+ $new_file = $uploads['path'] . "/$filename";
+ if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
+ wp_die( __('There was a problem uploading your file. Please try again.' ) );
+
+ // Set correct file permissions
+ $stat = stat( dirname( $new_file ));
+ $perms = $stat['mode'] & 0000666;
+ @ chmod( $new_file, $perms );
+
+ // Compute the URL
+ $url = $uploads['url'] . "/$filename";
+
+ $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) );
+
+ return $return;
+}
+
+?>
diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php
new file mode 100644
index 0000000..ec4466e
--- /dev/null
+++ b/wp-admin/includes/image.php
@@ -0,0 +1,192 @@
+<?php
+
+function get_udims( $width, $height) {
+ if ( $height <= 96 && $width <= 128 )
+ return array( $width, $height);
+ elseif ( $width / $height > 4 / 3 )
+ return array( 128, (int) ($height / $width * 128 ));
+ else
+ return array( (int) ($width / $height * 96 ), 96 );
+}
+
+function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
+
+ // 1 = GIF, 2 = JPEG, 3 = PNG
+
+ if ( file_exists( $file ) ) {
+ $type = getimagesize( $file );
+
+ // if the associated function doesn't exist - then it's not
+ // handle. duh. i hope.
+
+ if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
+ $error = __( 'Filetype not supported. Thumbnail not created.' );
+ }
+ elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
+ $error = __( 'Filetype not supported. Thumbnail not created.' );
+ }
+ elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
+ $error = __( 'Filetype not supported. Thumbnail not created.' );
+ } else {
+
+ // create the initial copy from the original file
+ if ( $type[2] == 1 ) {
+ $image = imagecreatefromgif( $file );
+ }
+ elseif ( $type[2] == 2 ) {
+ $image = imagecreatefromjpeg( $file );
+ }
+ elseif ( $type[2] == 3 ) {
+ $image = imagecreatefrompng( $file );
+ }
+
+ if ( function_exists( 'imageantialias' ))
+ imageantialias( $image, TRUE );
+
+ $image_attr = getimagesize( $file );
+
+ // figure out the longest side
+
+ if ( $image_attr[0] > $image_attr[1] ) {
+ $image_width = $image_attr[0];
+ $image_height = $image_attr[1];
+ $image_new_width = $max_side;
+
+ $image_ratio = $image_width / $image_new_width;
+ $image_new_height = $image_height / $image_ratio;
+ //width is > height
+ } else {
+ $image_width = $image_attr[0];
+ $image_height = $image_attr[1];
+ $image_new_height = $max_side;
+
+ $image_ratio = $image_height / $image_new_height;
+ $image_new_width = $image_width / $image_ratio;
+ //height > width
+ }
+
+ $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
+ @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
+
+ // If no filters change the filename, we'll do a default transformation.
+ if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
+ $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail' . '$1', basename( $file ), 1 );
+
+ $thumbpath = str_replace( basename( $file ), $thumb, $file );
+
+ // move the thumbnail to its final destination
+ if ( $type[2] == 1 ) {
+ if (!imagegif( $thumbnail, $thumbpath ) ) {
+ $error = __( "Thumbnail path invalid" );
+ }
+ }
+ elseif ( $type[2] == 2 ) {
+ if (!imagejpeg( $thumbnail, $thumbpath ) ) {
+ $error = __( "Thumbnail path invalid" );
+ }
+ }
+ elseif ( $type[2] == 3 ) {
+ if (!imagepng( $thumbnail, $thumbpath ) ) {
+ $error = __( "Thumbnail path invalid" );
+ }
+ }
+
+ }
+ } else {
+ $error = __( 'File not found' );
+ }
+
+ if (!empty ( $error ) ) {
+ return $error;
+ } else {
+ return apply_filters( 'wp_create_thumbnail', $thumbpath );
+ }
+}
+
+function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
+ if ( ctype_digit( $src_file ) ) // Handle int as attachment ID
+ $src_file = get_attached_file( $src_file );
+
+ $src = wp_load_image( $src_file );
+
+ if ( !is_resource( $src ))
+ return $src;
+
+ $dst = imagecreatetruecolor( $dst_w, $dst_h );
+
+ if ( $src_abs ) {
+ $src_w -= $src_x;
+ $src_h -= $src_y;
+ }
+
+ if (function_exists('imageantialias'))
+ imageantialias( $dst, true );
+
+ imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
+
+ if ( !$dst_file )
+ $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file );
+
+ $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
+
+ if ( imagejpeg( $dst, $dst_file ) )
+ return $dst_file;
+ else
+ return false;
+}
+
+function wp_generate_attachment_metadata( $attachment_id, $file ) {
+ $attachment = get_post( $attachment_id );
+
+ $metadata = array();
+ if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {
+ $imagesize = getimagesize($file);
+ $metadata['width'] = $imagesize['0'];
+ $metadata['height'] = $imagesize['1'];
+ list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']);
+ $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
+ $metadata['file'] = $file;
+
+ $max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file );
+
+ if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) {
+ $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );
+ $thumb = wp_create_thumbnail( $file, $max_side );
+
+ if ( @file_exists($thumb) )
+ $metadata['thumb'] = basename($thumb);
+ }
+ }
+ return apply_filters( 'wp_generate_attachment_metadata', $metadata );
+}
+
+function wp_load_image( $file ) {
+ if ( ctype_digit( $file ) )
+ $file = get_attached_file( $file );
+
+ if ( !file_exists( $file ) )
+ return sprintf(__("File '%s' doesn't exist?"), $file);
+
+ if ( ! function_exists('imagecreatefromstring') )
+ return __('The GD image library is not installed.');
+
+ $contents = file_get_contents( $file );
+
+ $image = imagecreatefromstring( $contents );
+
+ if ( !is_resource( $image ) )
+ return sprintf(__("File '%s' is not an image."), $file);
+
+ return $image;
+}
+
+function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
+ if ( $height <= $hmax && $width <= $wmax )
+ return array( $width, $height);
+ elseif ( $width / $height > $wmax / $hmax )
+ return array( $wmax, (int) ($height / $width * $wmax ));
+ else
+ return array( (int) ($width / $height * $hmax ), $hmax );
+}
+
+?>
diff --git a/wp-admin/includes/import.php b/wp-admin/includes/import.php
new file mode 100644
index 0000000..9835bb1
--- /dev/null
+++ b/wp-admin/includes/import.php
@@ -0,0 +1,45 @@
+<?php
+
+function get_importers() {
+ global $wp_importers;
+ uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
+ return $wp_importers;
+}
+
+function register_importer( $id, $name, $description, $callback ) {
+ global $wp_importers;
+ if ( is_wp_error( $callback ) )
+ return $callback;
+ $wp_importers[$id] = array ( $name, $description, $callback );
+}
+
+function wp_import_cleanup( $id ) {
+ wp_delete_attachment( $id );
+}
+
+function wp_import_handle_upload() {
+ $overrides = array( 'test_form' => false, 'test_type' => false );
+ $file = wp_handle_upload( $_FILES['import'], $overrides );
+
+ if ( isset( $file['error'] ) )
+ return $file;
+
+ $url = $file['url'];
+ $type = $file['type'];
+ $file = addslashes( $file['file'] );
+ $filename = basename( $file );
+
+ // Construct the object array
+ $object = array( 'post_title' => $filename,
+ 'post_content' => $url,
+ 'post_mime_type' => $type,
+ 'guid' => $url
+ );
+
+ // Save the data
+ $id = wp_insert_attachment( $object, $file );
+
+ return array( 'file' => $file, 'id' => $id );
+}
+
+?>
diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php
new file mode 100644
index 0000000..db28014
--- /dev/null
+++ b/wp-admin/includes/misc.php
@@ -0,0 +1,178 @@
+<?php
+
+function got_mod_rewrite() {
+ global $is_apache;
+
+ // take 3 educated guesses as to whether or not mod_rewrite is available
+ if ( !$is_apache )
+ return false;
+
+ if ( function_exists( 'apache_get_modules' ) ) {
+ if ( !in_array( 'mod_rewrite', apache_get_modules() ) )
+ return false;
+ }
+
+ return true;
+}
+
+// Returns an array of strings from a file (.htaccess ) from between BEGIN
+// and END markers.
+function extract_from_markers( $filename, $marker ) {
+ $result = array ();
+
+ if (!file_exists( $filename ) ) {
+ return $result;
+ }
+
+ if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
+ {
+ $state = false;
+ foreach ( $markerdata as $markerline ) {
+ if (strpos($markerline, '# END ' . $marker) !== false)
+ $state = false;
+ if ( $state )
+ $result[] = $markerline;
+ if (strpos($markerline, '# BEGIN ' . $marker) !== false)
+ $state = true;
+ }
+ }
+
+ return $result;
+}
+
+// Inserts an array of strings into a file (.htaccess ), placing it between
+// BEGIN and END markers. Replaces existing marked info. Retains surrounding
+// data. Creates file if none exists.
+// Returns true on write success, false on failure.
+function insert_with_markers( $filename, $marker, $insertion ) {
+ return;
+ if (!file_exists( $filename ) || is_writeable( $filename ) ) {
+ if (!file_exists( $filename ) ) {
+ $markerdata = '';
+ } else {
+ $markerdata = explode( "\n", implode( '', file( $filename ) ) );
+ }
+
+ $f = fopen( $filename, 'w' );
+ $foundit = false;
+ if ( $markerdata ) {
+ $state = true;
+ foreach ( $markerdata as $n => $markerline ) {
+ if (strpos($markerline, '# BEGIN ' . $marker) !== false)
+ $state = false;
+ if ( $state ) {
+ if ( $n + 1 < count( $markerdata ) )
+ fwrite( $f, "{$markerline}\n" );
+ else
+ fwrite( $f, "{$markerline}" );
+ }
+ if (strpos($markerline, '# END ' . $marker) !== false) {
+ fwrite( $f, "# BEGIN {$marker}\n" );
+ if ( is_array( $insertion ))
+ foreach ( $insertion as $insertline )
+ fwrite( $f, "{$insertline}\n" );
+ fwrite( $f, "# END {$marker}\n" );
+ $state = true;
+ $foundit = true;
+ }
+ }
+ }
+ if (!$foundit) {
+ fwrite( $f, "# BEGIN {$marker}\n" );
+ foreach ( $insertion as $insertline )
+ fwrite( $f, "{$insertline}\n" );
+ fwrite( $f, "# END {$marker}\n" );
+ }
+ fclose( $f );
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/**
+ * Updates the htaccess file with the current rules if it is writable.
+ *
+ * Always writes to the file if it exists and is writable to ensure that we blank out old rules.
+ */
+
+function save_mod_rewrite_rules() {
+ global $wp_rewrite;
+
+ $home_path = get_home_path();
+ $htaccess_file = $home_path.'.htaccess';
+
+ // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
+ // else check for write access to the file.
+ if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
+ if ( got_mod_rewrite() ) {
+ $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
+ return insert_with_markers( $htaccess_file, 'WordPress', $rules );
+ }
+ }
+
+ return false;
+}
+
+function update_recently_edited( $file ) {
+ $oldfiles = (array ) get_option( 'recently_edited' );
+ if ( $oldfiles ) {
+ $oldfiles = array_reverse( $oldfiles );
+ $oldfiles[] = $file;
+ $oldfiles = array_reverse( $oldfiles );
+ $oldfiles = array_unique( $oldfiles );
+ if ( 5 < count( $oldfiles ))
+ array_pop( $oldfiles );
+ } else {
+ $oldfiles[] = $file;
+ }
+ update_option( 'recently_edited', $oldfiles );
+}
+
+// If siteurl or home changed, reset cookies and flush rewrite rules.
+function update_home_siteurl( $old_value, $value ) {
+ global $wp_rewrite, $user_login, $user_pass_md5;
+
+ if ( defined( "WP_INSTALLING" ) )
+ return;
+
+ // If home changed, write rewrite rules to new location.
+ $wp_rewrite->flush_rules();
+ // Clear cookies for old paths.
+ wp_clearcookie();
+ // Set cookies for new paths.
+ wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' ));
+}
+
+add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
+add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
+
+function url_shorten( $url ) {
+ $short_url = str_replace( 'http://', '', stripslashes( $url ));
+ $short_url = str_replace( 'www.', '', $short_url );
+ if ('/' == substr( $short_url, -1 ))
+ $short_url = substr( $short_url, 0, -1 );
+ if ( strlen( $short_url ) > 35 )
+ $short_url = substr( $short_url, 0, 32 ).'...';
+ return $short_url;
+}
+
+function wp_reset_vars( $vars ) {
+ for ( $i=0; $i<count( $vars ); $i += 1 ) {
+ $var = $vars[$i];
+ global $$var;
+
+ if (!isset( $$var ) ) {
+ if ( empty( $_POST["$var"] ) ) {
+ if ( empty( $_GET["$var"] ) )
+ $$var = '';
+ else
+ $$var = $_GET["$var"];
+ } else {
+ $$var = $_POST["$var"];
+ }
+ }
+ }
+}
+
+?>
diff --git a/wp-admin/includes/mu.php b/wp-admin/includes/mu.php
new file mode 100644
index 0000000..8599860
--- /dev/null
+++ b/wp-admin/includes/mu.php
@@ -0,0 +1,202 @@
+<?php
+
+function wpmu_delete_blog($blog_id, $drop = false) {
+ global $wpdb, $wpmuBaseTablePrefix;
+
+ if ( $blog_id != $wpdb->blogid ) {
+ $switch = true;
+ switch_to_blog($blog_id);
+ }
+
+ do_action('delete_blog', $blog_id, $drop);
+
+ $users = get_users_of_blog($blog_id);
+
+ // Remove users from this blog.
+ if ( !empty($users) ) foreach ($users as $user) {
+ remove_user_from_blog($user->user_id, $blog_id);
+ }
+
+ update_blog_status( $wpdb->blogid, 'deleted', 1 );
+
+ if ( $drop ) {
+ $drop_tables = array( $wpmuBaseTablePrefix . $blog_id . "_categories",
+ $wpmuBaseTablePrefix . $blog_id . "_comments",
+ $wpmuBaseTablePrefix . $blog_id . "_linkcategories",
+ $wpmuBaseTablePrefix . $blog_id . "_links",
+ $wpmuBaseTablePrefix . $blog_id . "_link2cat",
+ $wpmuBaseTablePrefix . $blog_id . "_options",
+ $wpmuBaseTablePrefix . $blog_id . "_post2cat",
+ $wpmuBaseTablePrefix . $blog_id . "_postmeta",
+ $wpmuBaseTablePrefix . $blog_id . "_posts",
+ $wpmuBaseTablePrefix . $blog_id . "_referer_visitLog",
+ $wpmuBaseTablePrefix . $blog_id . "_referer_blacklist" );
+ reset( $drop_tables );
+
+ foreach ($drop_tables as $drop_table)
+ $wpdb->query( "DROP TABLE IF EXISTS $drop_table" );
+
+ $wpdb->query( "DELETE FROM $wpdb->blogs WHERE blog_id = '$blog_id'" );
+ $dir = constant( "ABSPATH" ) . "wp-content/blogs.dir/" . $blog_id ."/files/";
+ $dir = rtrim($dir, DIRECTORY_SEPARATOR);
+ $top_dir = $dir;
+ $stack = array($dir);
+ $index = 0;
+
+ while ($index < count($stack)) {
+ # Get indexed directory from stack
+ $dir = $stack[$index];
+
+ $dh = @ opendir($dir);
+ if ($dh) {
+ while (($file = @ readdir($dh)) !== false) {
+ if ($file == '.' or $file == '..')
+ continue;
+
+ if (@ is_dir($dir . DIRECTORY_SEPARATOR . $file))
+ $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
+ else if (@ is_file($dir . DIRECTORY_SEPARATOR . $file))
+ @ unlink($dir . DIRECTORY_SEPARATOR . $file);
+ }
+ }
+ $index++;
+ }
+
+ $stack = array_reverse($stack); // Last added dirs are deepest
+ foreach($stack as $dir) {
+ if ( $dir != $top_dir)
+ @ rmdir($dir);
+ }
+ }
+ $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key='wp_{$blog_id}_autosave_draft_ids'");
+
+ if ( $switch )
+ restore_current_blog();
+}
+
+function update_blog_public($old_value, $value) {
+ global $wpdb;
+ $value = (int) $value;
+ do_action('update_blog_public');
+ update_blog_status( $wpdb->blogid, 'public', $value );
+}
+
+add_action('update_option_blog_public', 'update_blog_public', 10, 2);
+
+function wpmu_delete_user($id) {
+ global $wpdb;
+
+ $id = (int) $id;
+ $user = get_userdata($id);
+
+ do_action('wpmu_delete_user', $id);
+
+ $blogs = get_blogs_of_user($id);
+
+ if ( ! empty($blogs) ) foreach ($blogs as $blog) {
+ switch_to_blog($blog->userblog_id);
+ remove_user_from_blog($id, $blog->userblog_id);
+
+ $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
+
+ if ($post_ids) {
+ foreach ($post_ids as $post_id)
+ wp_delete_post($post_id);
+ }
+
+ // Clean links
+ $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
+
+ restore_current_blog();
+ }
+
+ $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id");
+ $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$id'");
+
+ wp_cache_delete($id, 'users');
+ wp_cache_delete($user->user_login, 'userlogins');
+
+ return true;
+}
+
+function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
+ $themes = get_themes();
+ if( $blog_id == 0 )
+ $blog_allowed_themes = get_option( "allowedthemes" );
+ else
+ $blog_allowed_themes = get_blog_option( $blog_id, "allowedthemes" );
+ if( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes
+ if( $blog_id == 0 )
+ $blog_allowed_themes = get_option( "allowed_themes" );
+ else
+ $blog_allowed_themes = get_blog_option( $blog_id, "allowed_themes" );
+ if( is_array( $blog_allowed_themes ) ) {
+ foreach( $themes as $key => $theme ) {
+ $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] );
+ if( isset( $blog_allowed_themes[ $key ] ) == true ) {
+ $blog_allowedthemes[ $theme_key ] = 1;
+ }
+ }
+ $blog_allowed_themes = $blog_allowedthemes;
+ if( $blog_id == 0 ) {
+ add_option( "allowedthemes", $blog_allowed_themes );
+ delete_option( "allowed_themes" );
+ } else {
+ add_blog_option( $blog_id, "allowedthemes", $blog_allowed_themes );
+ delete_blog_option( $blog_id, "allowed_themes" );
+ }
+ }
+ }
+ return $blog_allowed_themes;
+}
+
+function update_option_new_admin_email($old_value, $value) {
+ if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
+ return;
+
+ $hash = md5( $value.time().mt_rand() );
+ $newadminemail = array(
+ "hash" => $hash,
+ "newemail" => $value
+ );
+ update_option( 'adminhash', $newadminemail );
+
+ $content = __("Dear user,\n\n
+You recently requested to have the administration email address on
+your blog changed.\n
+If this is correct, please click on the following link to change it:\n
+###ADMIN_URL###\n\n
+You can safely ignore and delete this email if you do not want to take this action.\n\n
+This email has been sent to ###EMAIL###\n\n
+Regards,\n
+The Webmaster");
+
+ $content = str_replace('###ADMIN_URL###', get_option( "siteurl" ).'/wp-admin/options.php?adminhash='.$hash, $content);
+ $content = str_replace('###EMAIL###', $value, $content);
+
+ wp_mail( $value, sprintf(__('[%s] New Admin Email Address'), get_option('blogname')), $content );
+}
+
+add_action('update_option_new_admin_email', 'update_option_new_admin_email', 10, 2);
+
+function get_site_allowed_themes() {
+ $themes = get_themes();
+ $allowed_themes = get_site_option( 'allowedthemes' );
+ if( !is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
+ $allowed_themes = get_site_option( "allowed_themes" ); // convert old allowed_themes format
+ if( !is_array( $allowed_themes ) ) {
+ $allowed_themes = array();
+ } else {
+ foreach( $themes as $key => $theme ) {
+ $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] );
+ if( isset( $allowed_themes[ $key ] ) == true ) {
+ $allowedthemes[ $theme_key ] = 1;
+ }
+ }
+ $allowed_themes = $allowedthemes;
+ }
+ }
+
+ return $allowed_themes;
+}
+?>
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php
new file mode 100644
index 0000000..e5911bd
--- /dev/null
+++ b/wp-admin/includes/plugin.php
@@ -0,0 +1,382 @@
+<?php
+
+function get_plugin_data( $plugin_file ) {
+ $plugin_data = implode( '', file( $plugin_file ));
+ preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $plugin_name );
+ preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $plugin_uri );
+ preg_match( '|Description:(.*)$|mi', $plugin_data, $description );
+ preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name );
+ preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri );
+
+ if ( preg_match( "|Version:(.*)|i", $plugin_data, $version ))
+ $version = trim( $version[1] );
+ else
+ $version = '';
+
+ $description = wptexturize( trim( $description[1] ));
+
+ $name = $plugin_name[1];
+ $name = trim( $name );
+ $plugin = $name;
+ if ('' != trim($plugin_uri[1]) && '' != $name ) {
+ $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>';
+ }
+
+ if ('' == $author_uri[1] ) {
+ $author = trim( $author_name[1] );
+ } else {
+ $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>';
+ }
+
+ return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
+}
+
+function get_plugins() {
+ global $wp_plugins;
+
+ if ( isset( $wp_plugins ) ) {
+ return $wp_plugins;
+ }
+
+ $wp_plugins = array ();
+ $plugin_root = ABSPATH . PLUGINDIR;
+
+ // Files in wp-content/plugins directory
+ $plugins_dir = @ opendir( $plugin_root);
+ if ( $plugins_dir ) {
+ while (($file = readdir( $plugins_dir ) ) !== false ) {
+ if ( substr($file, 0, 1) == '.' )
+ continue;
+ if ( is_dir( $plugin_root.'/'.$file ) ) {
+ $plugins_subdir = @ opendir( $plugin_root.'/'.$file );
+ if ( $plugins_subdir ) {
+ while (($subfile = readdir( $plugins_subdir ) ) !== false ) {
+ if ( substr($subfile, 0, 1) == '.' )
+ continue;
+ if ( substr($subfile, -4) == '.php' )
+ $plugin_files[] = "$file/$subfile";
+ }
+ }
+ } else {
+ if ( substr($file, -4) == '.php' )
+ $plugin_files[] = $file;
+ }
+ }
+ }
+ @closedir( $plugins_dir );
+ @closedir( $plugins_subdir );
+
+ if ( !$plugins_dir || !$plugin_files )
+ return $wp_plugins;
+
+ foreach ( $plugin_files as $plugin_file ) {
+ if ( !is_readable( "$plugin_root/$plugin_file" ) )
+ continue;
+
+ $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" );
+
+ if ( empty ( $plugin_data['Name'] ) )
+ continue;
+
+ $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data;
+ }
+
+ uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
+
+ return $wp_plugins;
+}
+
+//
+// Menu
+//
+
+function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ global $menu, $admin_page_hooks;
+
+ $file = plugin_basename( $file );
+
+ $menu[] = array ( $menu_title, $access_level, $file, $page_title );
+
+ $admin_page_hooks[$file] = sanitize_title( $menu_title );
+
+ $hookname = get_plugin_page_hookname( $file, '' );
+ if (!empty ( $function ) && !empty ( $hookname ))
+ add_action( $hookname, $function );
+
+ return $hookname;
+}
+
+function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ global $submenu;
+ global $menu;
+ global $_wp_real_parent_file;
+ global $_wp_submenu_nopriv;
+ global $_wp_menu_nopriv;
+
+ $file = plugin_basename( $file );
+
+ $parent = plugin_basename( $parent);
+ if ( isset( $_wp_real_parent_file[$parent] ) )
+ $parent = $_wp_real_parent_file[$parent];
+
+ if ( !current_user_can( $access_level ) ) {
+ $_wp_submenu_nopriv[$parent][$file] = true;
+ return false;
+ }
+
+ // If the parent doesn't already have a submenu, add a link to the parent
+ // as the first item in the submenu. If the submenu file is the same as the
+ // parent file someone is trying to link back to the parent manually. In
+ // this case, don't automatically add a link back to avoid duplication.
+ if (!isset( $submenu[$parent] ) && $file != $parent ) {
+ foreach ( $menu as $parent_menu ) {
+ if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) )
+ $submenu[$parent][] = $parent_menu;
+ }
+ }
+
+ $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title );
+
+ $hookname = get_plugin_page_hookname( $file, $parent);
+ if (!empty ( $function ) && !empty ( $hookname ))
+ add_action( $hookname, $function );
+
+ return $hookname;
+}
+
+function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function );
+}
+
+function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function );
+}
+
+function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function );
+}
+
+function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) {
+ if ( current_user_can('edit_users') )
+ $parent = 'users.php';
+ else
+ $parent = 'profile.php';
+ return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function );
+}
+
+//
+// Pluggable Menu Support -- Private
+//
+
+function get_admin_page_parent() {
+ global $parent_file;
+ global $menu;
+ global $submenu;
+ global $pagenow;
+ global $plugin_page;
+ global $_wp_real_parent_file;
+ global $_wp_menu_nopriv;
+ global $_wp_submenu_nopriv;
+
+ if ( !empty ( $parent_file ) ) {
+ if ( isset( $_wp_real_parent_file[$parent_file] ) )
+ $parent_file = $_wp_real_parent_file[$parent_file];
+
+ return $parent_file;
+ }
+
+ if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) {
+ foreach ( $menu as $parent_menu ) {
+ if ( $parent_menu[2] == $plugin_page ) {
+ $parent_file = $plugin_page;
+ if ( isset( $_wp_real_parent_file[$parent_file] ) )
+ $parent_file = $_wp_real_parent_file[$parent_file];
+ return $parent_file;
+ }
+ }
+ if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) {
+ $parent_file = $plugin_page;
+ if ( isset( $_wp_real_parent_file[$parent_file] ) )
+ $parent_file = $_wp_real_parent_file[$parent_file];
+ return $parent_file;
+ }
+ }
+
+ if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) {
+ $parent_file = $pagenow;
+ if ( isset( $_wp_real_parent_file[$parent_file] ) )
+ $parent_file = $_wp_real_parent_file[$parent_file];
+ return $parent_file;
+ }
+
+ foreach (array_keys( $submenu ) as $parent) {
+ foreach ( $submenu[$parent] as $submenu_array ) {
+ if ( isset( $_wp_real_parent_file[$parent] ) )
+ $parent = $_wp_real_parent_file[$parent];
+ if ( $submenu_array[2] == $pagenow ) {
+ $parent_file = $parent;
+ return $parent;
+ } else
+ if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) {
+ $parent_file = $parent;
+ return $parent;
+ }
+ }
+ }
+
+ $parent_file = '';
+ return '';
+}
+
+function get_admin_page_title() {
+ global $title;
+ global $menu;
+ global $submenu;
+ global $pagenow;
+ global $plugin_page;
+
+ if ( isset( $title ) && !empty ( $title ) ) {
+ return $title;
+ }
+
+ $hook = get_plugin_page_hook( $plugin_page, $pagenow );
+
+ $parent = $parent1 = get_admin_page_parent();
+ if ( empty ( $parent) ) {
+ foreach ( $menu as $menu_array ) {
+ if ( isset( $menu_array[3] ) ) {
+ if ( $menu_array[2] == $pagenow ) {
+ $title = $menu_array[3];
+ return $menu_array[3];
+ } else
+ if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) {
+ $title = $menu_array[3];
+ return $menu_array[3];
+ }
+ } else {
+ $title = $menu_array[0];
+ return $title;
+ }
+ }
+ } else {
+ foreach (array_keys( $submenu ) as $parent) {
+ foreach ( $submenu[$parent] as $submenu_array ) {
+ if ( isset( $plugin_page ) &&
+ ($plugin_page == $submenu_array[2] ) &&
+ (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) )
+ ) {
+ $title = $submenu_array[3];
+ return $submenu_array[3];
+ }
+
+ if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page
+ continue;
+
+ if ( isset( $submenu_array[3] ) ) {
+ $title = $submenu_array[3];
+ return $submenu_array[3];
+ } else {
+ $title = $submenu_array[0];
+ return $title;
+ }
+ }
+ }
+ }
+
+ return $title;
+}
+
+function get_plugin_page_hook( $plugin_page, $parent_page ) {
+ global $wp_filter;
+
+ $hook = get_plugin_page_hookname( $plugin_page, $parent_page );
+ if ( isset( $wp_filter[$hook] ))
+ return $hook;
+ else
+ return null;
+}
+
+function get_plugin_page_hookname( $plugin_page, $parent_page ) {
+ global $admin_page_hooks;
+
+ $parent = get_admin_page_parent();
+
+ if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) {
+ if ( isset( $admin_page_hooks[$plugin_page] ))
+ $page_type = 'toplevel';
+ else
+ if ( isset( $admin_page_hooks[$parent] ))
+ $page_type = $admin_page_hooks[$parent];
+ } else
+ if ( isset( $admin_page_hooks[$parent_page] ) ) {
+ $page_type = $admin_page_hooks[$parent_page];
+ } else {
+ $page_type = 'admin';
+ }
+
+ $plugin_name = preg_replace( '!\.php!', '', $plugin_page );
+
+ return $page_type.'_page_'.$plugin_name;
+}
+
+function user_can_access_admin_page() {
+ global $pagenow;
+ global $menu;
+ global $submenu;
+ global $_wp_menu_nopriv;
+ global $_wp_submenu_nopriv;
+ global $plugin_page;
+
+ $parent = get_admin_page_parent();
+
+ if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )
+ return false;
+
+ if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) )
+ return false;
+
+ if ( empty( $parent) ) {
+ if ( isset( $_wp_menu_nopriv[$pagenow] ) )
+ return false;
+ if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) )
+ return false;
+ if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) )
+ return false;
+ foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {
+ if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) )
+ return false;
+ if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) )
+ return false;
+ }
+ return true;
+ }
+
+ if ( isset( $submenu[$parent] ) ) {
+ foreach ( $submenu[$parent] as $submenu_array ) {
+ if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {
+ if ( current_user_can( $submenu_array[1] ))
+ return true;
+ else
+ return false;
+ } else if ( $submenu_array[2] == $pagenow ) {
+ if ( current_user_can( $submenu_array[1] ))
+ return true;
+ else
+ return false;
+ }
+ }
+ }
+
+ foreach ( $menu as $menu_array ) {
+ if ( $menu_array[2] == $parent) {
+ if ( current_user_can( $menu_array[1] ))
+ return true;
+ else
+ return false;
+ }
+ }
+
+ return true;
+}
+
+?>
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
new file mode 100644
index 0000000..e27482c
--- /dev/null
+++ b/wp-admin/includes/post.php
@@ -0,0 +1,471 @@
+<?php
+
+// Update an existing post with values provided in $_POST.
+function edit_post() {
+ global $user_ID;
+
+ $post_ID = (int) $_POST['post_ID'];
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( !current_user_can( 'edit_page', $post_ID ) )
+ wp_die( __('You are not allowed to edit this page.' ));
+ } else {
+ if ( !current_user_can( 'edit_post', $post_ID ) )
+ wp_die( __('You are not allowed to edit this post.' ));
+ }
+
+ // Autosave shouldn't save too soon after a real save
+ if ( 'autosave' == $_POST['action'] ) {
+ $post =& get_post( $post_ID );
+ $now = time();
+ $then = strtotime($post->post_date_gmt . ' +0000');
+ // Keep autosave_interval in sync with autosave-js.php.
+ $delta = apply_filters( 'autosave_interval', 120 ) / 2;
+ if ( ($now - $then) < $delta )
+ return $post_ID;
+ }
+
+ // Rename.
+ $_POST['ID'] = (int) $_POST['post_ID'];
+ $_POST['post_content'] = $_POST['content'];
+ $_POST['post_excerpt'] = $_POST['excerpt'];
+ $_POST['post_parent'] = $_POST['parent_id'];
+ $_POST['to_ping'] = $_POST['trackback_url'];
+
+ if (!empty ( $_POST['post_author_override'] ) ) {
+ $_POST['post_author'] = (int) $_POST['post_author_override'];
+ } else
+ if (!empty ( $_POST['post_author'] ) ) {
+ $_POST['post_author'] = (int) $_POST['post_author'];
+ } else {
+ $_POST['post_author'] = (int) $_POST['user_ID'];
+ }
+
+ if ( $_POST['post_author'] != $_POST['user_ID'] ) {
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( !current_user_can( 'edit_others_pages' ) )
+ wp_die( __('You are not allowed to edit pages as this user.' ));
+ } else {
+ if ( !current_user_can( 'edit_others_posts' ) )
+ wp_die( __('You are not allowed to edit posts as this user.' ));
+
+ }
+ }
+
+ // What to do based on which button they pressed
+ if ('' != $_POST['saveasdraft'] )
+ $_POST['post_status'] = 'draft';
+ if ('' != $_POST['saveasprivate'] )
+ $_POST['post_status'] = 'private';
+ if ('' != $_POST['publish'] )
+ $_POST['post_status'] = 'publish';
+ if ('' != $_POST['advanced'] )
+ $_POST['post_status'] = 'draft';
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' ))
+ $_POST['post_status'] = 'pending';
+ } else {
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' ))
+ $_POST['post_status'] = 'pending';
+ }
+
+ if (!isset( $_POST['comment_status'] ))
+ $_POST['comment_status'] = 'closed';
+
+ if (!isset( $_POST['ping_status'] ))
+ $_POST['ping_status'] = 'closed';
+
+ if (!empty ( $_POST['edit_date'] ) ) {
+ $aa = $_POST['aa'];
+ $mm = $_POST['mm'];
+ $jj = $_POST['jj'];
+ $hh = $_POST['hh'];
+ $mn = $_POST['mn'];
+ $ss = $_POST['ss'];
+ $jj = ($jj > 31 ) ? 31 : $jj;
+ $hh = ($hh > 23 ) ? $hh -24 : $hh;
+ $mn = ($mn > 59 ) ? $mn -60 : $mn;
+ $ss = ($ss > 59 ) ? $ss -60 : $ss;
+ $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
+ $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
+ }
+
+ // Meta Stuff
+ if ( $_POST['meta'] ) {
+ foreach ( $_POST['meta'] as $key => $value )
+ update_meta( $key, $value['key'], $value['value'] );
+ }
+
+ if ( $_POST['deletemeta'] ) {
+ foreach ( $_POST['deletemeta'] as $key => $value )
+ delete_meta( $key );
+ }
+
+ add_meta( $post_ID );
+
+ wp_update_post( $_POST );
+
+ // Reunite any orphaned attachments with their parent
+ if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
+ $draft_ids = array();
+ if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
+ _relocate_children( $draft_temp_id, $post_ID );
+
+ // Now that we have an ID we can fix any attachment anchor hrefs
+ _fix_attachment_links( $post_ID );
+
+ return $post_ID;
+}
+
+// Default post information to use when populating the "Write Post" form.
+function get_default_post_to_edit() {
+ if ( !empty( $_REQUEST['post_title'] ) )
+ $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
+ else if ( !empty( $_REQUEST['popuptitle'] ) ) {
+ $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] ));
+ $post_title = funky_javascript_fix( $post_title );
+ } else {
+ $post_title = '';
+ }
+
+ if ( !empty( $_REQUEST['content'] ) )
+ $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
+ else if ( !empty( $post_title ) ) {
+ $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) );
+ $text = funky_javascript_fix( $text);
+ $popupurl = clean_url($_REQUEST['popupurl']);
+ $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
+ }
+
+ if ( !empty( $_REQUEST['excerpt'] ) )
+ $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] ));
+ else
+ $post_excerpt = '';
+
+ $post->post_status = 'draft';
+ $post->comment_status = get_option( 'default_comment_status' );
+ $post->ping_status = get_option( 'default_ping_status' );
+ $post->post_pingback = get_option( 'default_pingback_flag' );
+ $post->post_category = get_option( 'default_category' );
+ $post->post_content = apply_filters( 'default_content', $post_content);
+ $post->post_title = apply_filters( 'default_title', $post_title );
+ $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
+ $post->page_template = 'default';
+ $post->post_parent = 0;
+ $post->menu_order = 0;
+
+ return $post;
+}
+
+// Get an existing post and format it for editing.
+function get_post_to_edit( $id ) {
+
+ $post = get_post( $id, OBJECT, 'edit' );
+
+ if ( $post->post_type == 'page' )
+ $post->page_template = get_post_meta( $id, '_wp_page_template', true );
+
+ return $post;
+}
+
+function post_exists($title, $content = '', $post_date = '') {
+ global $wpdb;
+
+ if (!empty ($post_date))
+ $post_date = "AND post_date = '$post_date'";
+
+ if (!empty ($title))
+ return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' $post_date");
+ else
+ if (!empty ($content))
+ return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date");
+
+ return 0;
+}
+
+// Creates a new post from the "Write Post" form using $_POST information.
+function wp_write_post() {
+ global $user_ID;
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( !current_user_can( 'edit_pages' ) )
+ return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
+ } else {
+ if ( !current_user_can( 'edit_posts' ) )
+ return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
+ }
+
+
+ // Check for autosave collisions
+ $temp_id = false;
+ if ( isset($_POST['temp_ID']) ) {
+ $temp_id = (int) $_POST['temp_ID'];
+ if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
+ $draft_ids = array();
+ foreach ( $draft_ids as $temp => $real )
+ if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
+ unset($draft_ids[$temp]);
+
+ if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
+ $_POST['post_ID'] = $draft_ids[$temp_id];
+ unset($_POST['temp_ID']);
+ update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
+ return edit_post();
+ }
+ }
+
+ // Rename.
+ $_POST['post_content'] = $_POST['content'];
+ $_POST['post_excerpt'] = $_POST['excerpt'];
+ $_POST['post_parent'] = $_POST['parent_id'];
+ $_POST['to_ping'] = $_POST['trackback_url'];
+
+ if (!empty ( $_POST['post_author_override'] ) ) {
+ $_POST['post_author'] = (int) $_POST['post_author_override'];
+ } else {
+ if (!empty ( $_POST['post_author'] ) ) {
+ $_POST['post_author'] = (int) $_POST['post_author'];
+ } else {
+ $_POST['post_author'] = (int) $_POST['user_ID'];
+ }
+
+ }
+
+ if ( $_POST['post_author'] != $_POST['user_ID'] ) {
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( !current_user_can( 'edit_others_pages' ) )
+ return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) );
+ } else {
+ if ( !current_user_can( 'edit_others_posts' ) )
+ return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) );
+
+ }
+ }
+
+ // What to do based on which button they pressed
+ if ('' != $_POST['saveasdraft'] )
+ $_POST['post_status'] = 'draft';
+ if ('' != $_POST['saveasprivate'] )
+ $_POST['post_status'] = 'private';
+ if ('' != $_POST['publish'] )
+ $_POST['post_status'] = 'publish';
+ if ('' != $_POST['advanced'] )
+ $_POST['post_status'] = 'draft';
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) )
+ $_POST['post_status'] = 'pending';
+ } else {
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) )
+ $_POST['post_status'] = 'pending';
+ }
+
+ if (!isset( $_POST['comment_status'] ))
+ $_POST['comment_status'] = 'closed';
+
+ if (!isset( $_POST['ping_status'] ))
+ $_POST['ping_status'] = 'closed';
+
+ if (!empty ( $_POST['edit_date'] ) ) {
+ $aa = $_POST['aa'];
+ $mm = $_POST['mm'];
+ $jj = $_POST['jj'];
+ $hh = $_POST['hh'];
+ $mn = $_POST['mn'];
+ $ss = $_POST['ss'];
+ $jj = ($jj > 31 ) ? 31 : $jj;
+ $hh = ($hh > 23 ) ? $hh -24 : $hh;
+ $mn = ($mn > 59 ) ? $mn -60 : $mn;
+ $ss = ($ss > 59 ) ? $ss -60 : $ss;
+ $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
+ $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
+ }
+
+ // Create the post.
+ $post_ID = wp_insert_post( $_POST );
+ if ( is_wp_error( $post_ID ) )
+ return $post_ID;
+
+ if ( empty($post_ID) )
+ return 0;
+
+ add_meta( $post_ID );
+
+ // Reunite any orphaned attachments with their parent
+ if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
+ $draft_ids = array();
+ if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
+ _relocate_children( $draft_temp_id, $post_ID );
+ if ( $temp_id && $temp_id != $draft_temp_id )
+ _relocate_children( $temp_id, $post_ID );
+
+ // Update autosave collision detection
+ if ( $temp_id ) {
+ $draft_ids[$temp_id] = $post_ID;
+ update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
+ }
+
+ // Now that we have an ID we can fix any attachment anchor hrefs
+ _fix_attachment_links( $post_ID );
+
+ return $post_ID;
+}
+
+function write_post() {
+ $result = wp_write_post();
+ if( is_wp_error( $result ) )
+ wp_die( $result->get_error_message() );
+ else
+ return $result;
+}
+
+//
+// Post Meta
+//
+
+function add_meta( $post_ID ) {
+ global $wpdb;
+ $post_ID = (int) $post_ID;
+
+ $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
+
+ $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) );
+ $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) );
+ $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) ));
+ $metavalue = $wpdb->escape( $metavalue );
+
+ if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
+ // We have a key/value pair. If both the select and the
+ // input for the key have data, the input takes precedence:
+
+ if ('#NONE#' != $metakeyselect)
+ $metakey = $metakeyselect;
+
+ if ( $metakeyinput)
+ $metakey = $metakeyinput; // default
+
+ if ( in_array($metakey, $protected) )
+ return false;
+
+ $result = $wpdb->query( "
+ INSERT INTO $wpdb->postmeta
+ (post_id,meta_key,meta_value )
+ VALUES ('$post_ID','$metakey','$metavalue' )
+ " );
+ return $wpdb->insert_id;
+ }
+ return false;
+} // add_meta
+
+function delete_meta( $mid ) {
+ global $wpdb;
+ $mid = (int) $mid;
+
+ return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
+}
+
+// Get a list of previously defined keys
+function get_meta_keys() {
+ global $wpdb;
+
+ $keys = $wpdb->get_col( "
+ SELECT meta_key
+ FROM $wpdb->postmeta
+ GROUP BY meta_key
+ ORDER BY meta_key" );
+
+ return $keys;
+}
+
+function get_post_meta_by_id( $mid ) {
+ global $wpdb;
+ $mid = (int) $mid;
+
+ $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
+ if ( is_serialized_string( $meta->meta_value ) )
+ $meta->meta_value = maybe_unserialize( $meta->meta_value );
+ return $meta;
+}
+
+// Some postmeta stuff
+function has_meta( $postid ) {
+ global $wpdb;
+
+ return $wpdb->get_results( "
+ SELECT meta_key, meta_value, meta_id, post_id
+ FROM $wpdb->postmeta
+ WHERE post_id = '$postid'
+ ORDER BY meta_key,meta_id", ARRAY_A );
+
+}
+
+function update_meta( $mid, $mkey, $mvalue ) {
+ global $wpdb;
+
+ $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
+
+ if ( in_array($mkey, $protected) )
+ return false;
+
+ $mvalue = maybe_serialize( stripslashes( $mvalue ));
+ $mvalue = $wpdb->escape( $mvalue );
+ $mid = (int) $mid;
+ return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" );
+}
+
+//
+// Private
+//
+
+// Replace hrefs of attachment anchors with up-to-date permalinks.
+function _fix_attachment_links( $post_ID ) {
+ global $wp_rewrite;
+
+ $post = & get_post( $post_ID, ARRAY_A );
+
+ $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
+
+ // See if we have any rel="attachment" links
+ if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
+ return;
+
+ $i = 0;
+ $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i";
+ foreach ( $anchor_matches[0] as $anchor ) {
+ if ( 0 == preg_match( $search, $anchor, $id_matches ) )
+ continue;
+
+ $id = (int) $id_matches[3];
+
+ // While we have the attachment ID, let's adopt any orphans.
+ $attachment = & get_post( $id, ARRAY_A );
+ if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) {
+ $attachment['post_parent'] = $post_ID;
+ // Escape data pulled from DB.
+ $attachment = add_magic_quotes( $attachment);
+ wp_update_post( $attachment);
+ }
+
+ $post_search[$i] = $anchor;
+ $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
+ ++$i;
+ }
+
+ $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
+
+ // Escape data pulled from DB.
+ $post = add_magic_quotes( $post);
+
+ return wp_update_post( $post);
+}
+
+// Move child posts to a new parent
+function _relocate_children( $old_ID, $new_ID ) {
+ global $wpdb;
+ $old_ID = (int) $old_ID;
+ $new_ID = (int) $new_ID;
+ return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" );
+}
+
+?> \ No newline at end of file
diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php
new file mode 100644
index 0000000..678f127
--- /dev/null
+++ b/wp-admin/includes/schema.php
@@ -0,0 +1,474 @@
+<?php
+// Here we keep the DB structure and option values
+
+global $wp_queries;
+$charset_collate = '';
+
+if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
+ if ( ! empty($wpdb->charset) )
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
+ if ( ! empty($wpdb->collate) )
+ $charset_collate .= " COLLATE $wpdb->collate";
+}
+
+$wp_queries="CREATE TABLE $wpdb->terms (
+ term_id bigint(20) NOT NULL auto_increment,
+ name varchar(55) NOT NULL default '',
+ slug varchar(200) NOT NULL default '',
+ term_group bigint(10) NOT NULL default 0,
+ PRIMARY KEY (term_id),
+ UNIQUE KEY slug (slug)
+) $charset_collate;
+CREATE TABLE $wpdb->term_taxonomy (
+ term_taxonomy_id bigint(20) NOT NULL auto_increment,
+ term_id bigint(20) NOT NULL default 0,
+ taxonomy varchar(32) NOT NULL default '',
+ description longtext NOT NULL,
+ parent bigint(20) NOT NULL default 0,
+ count bigint(20) NOT NULL default 0,
+ PRIMARY KEY (term_taxonomy_id),
+ UNIQUE KEY term_id_taxonomy (term_id,taxonomy)
+) $charset_collate;
+CREATE TABLE $wpdb->term_relationships (
+ object_id bigint(20) NOT NULL default 0,
+ term_taxonomy_id bigint(20) NOT NULL default 0,
+ PRIMARY KEY (object_id,term_taxonomy_id),
+ KEY term_taxonomy_id (term_taxonomy_id)
+) $charset_collate;
+CREATE TABLE $wpdb->comments (
+ comment_ID bigint(20) unsigned NOT NULL auto_increment,
+ comment_post_ID int(11) NOT NULL default '0',
+ comment_author tinytext NOT NULL,
+ comment_author_email varchar(100) NOT NULL default '',
+ comment_author_url varchar(200) NOT NULL default '',
+ comment_author_IP varchar(100) NOT NULL default '',
+ comment_date datetime NOT NULL default '0000-00-00 00:00:00',
+ comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
+ comment_content text NOT NULL,
+ comment_karma int(11) NOT NULL default '0',
+ comment_approved enum('0','1','spam') NOT NULL default '1',
+ comment_agent varchar(255) NOT NULL default '',
+ comment_type varchar(20) NOT NULL default '',
+ comment_parent bigint(20) NOT NULL default '0',
+ user_id bigint(20) NOT NULL default '0',
+ PRIMARY KEY (comment_ID),
+ KEY comment_approved (comment_approved),
+ KEY comment_post_ID (comment_post_ID)
+) $charset_collate;
+CREATE TABLE $wpdb->links (
+ link_id bigint(20) NOT NULL auto_increment,
+ link_url varchar(255) NOT NULL default '',
+ link_name varchar(255) NOT NULL default '',
+ link_image varchar(255) NOT NULL default '',
+ link_target varchar(25) NOT NULL default '',
+ link_category bigint(20) NOT NULL default '0',
+ link_description varchar(255) NOT NULL default '',
+ link_visible enum('Y','N') NOT NULL default 'Y',
+ link_owner int(11) NOT NULL default '1',
+ link_rating int(11) NOT NULL default '0',
+ link_updated datetime NOT NULL default '0000-00-00 00:00:00',
+ link_rel varchar(255) NOT NULL default '',
+ link_notes mediumtext NOT NULL,
+ link_rss varchar(255) NOT NULL default '',
+ PRIMARY KEY (link_id),
+ KEY link_category (link_category),
+ KEY link_visible (link_visible)
+) $charset_collate;
+CREATE TABLE $wpdb->options (
+ option_id bigint(20) NOT NULL auto_increment,
+ blog_id int(11) NOT NULL default '0',
+ option_name varchar(64) NOT NULL default '',
+ option_value longtext NOT NULL,
+ autoload enum('yes','no') NOT NULL default 'yes',
+ PRIMARY KEY (option_id,blog_id,option_name),
+ KEY option_name (option_name)
+) $charset_collate;
+CREATE TABLE $wpdb->postmeta (
+ meta_id bigint(20) NOT NULL auto_increment,
+ post_id bigint(20) NOT NULL default '0',
+ meta_key varchar(255) default NULL,
+ meta_value longtext,
+ PRIMARY KEY (meta_id),
+ KEY post_id (post_id),
+ KEY meta_key (meta_key)
+) $charset_collate;
+CREATE TABLE $wpdb->posts (
+ ID bigint(20) unsigned NOT NULL auto_increment,
+ post_author bigint(20) NOT NULL default '0',
+ post_date datetime NOT NULL default '0000-00-00 00:00:00',
+ post_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
+ post_content longtext NOT NULL,
+ post_title text NOT NULL,
+ post_category int(4) NOT NULL default '0',
+ post_excerpt text NOT NULL,
+ post_status enum('publish','draft','private','static','object','attachment','inherit','future', 'pending') NOT NULL default 'publish',
+ comment_status enum('open','closed','registered_only') NOT NULL default 'open',
+ ping_status enum('open','closed') NOT NULL default 'open',
+ post_password varchar(20) NOT NULL default '',
+ post_name varchar(200) NOT NULL default '',
+ to_ping text NOT NULL,
+ pinged text NOT NULL,
+ post_modified datetime NOT NULL default '0000-00-00 00:00:00',
+ post_modified_gmt datetime NOT NULL default '0000-00-00 00:00:00',
+ post_content_filtered text NOT NULL,
+ post_parent bigint(20) NOT NULL default '0',
+ guid varchar(255) NOT NULL default '',
+ menu_order int(11) NOT NULL default '0',
+ post_type varchar(20) NOT NULL default 'post',
+ post_mime_type varchar(100) NOT NULL default '',
+ comment_count bigint(20) NOT NULL default '0',
+ PRIMARY KEY (ID),
+ KEY post_name (post_name),
+ KEY type_status_date (post_type,post_status,post_date,ID)
+) $charset_collate;
+CREATE TABLE IF NOT EXISTS $wpdb->users (
+ ID bigint(20) unsigned NOT NULL auto_increment,
+ user_login varchar(60) NOT NULL default '',
+ user_pass varchar(64) NOT NULL default '',
+ user_nicename varchar(50) NOT NULL default '',
+ user_email varchar(100) NOT NULL default '',
+ user_url varchar(100) NOT NULL default '',
+ user_registered datetime NOT NULL default '0000-00-00 00:00:00',
+ user_activation_key varchar(60) NOT NULL default '',
+ user_status int(11) NOT NULL default '0',
+ display_name varchar(250) NOT NULL default '',
+ spam tinyint(2) NOT NULL default '0',
+ deleted tinyint(2) NOT NULL default '0',
+ PRIMARY KEY (ID),
+ KEY user_login_key (user_login),
+ KEY user_nicename (user_nicename)
+) $charset_collate;
+CREATE TABLE IF NOT EXISTS $wpdb->usermeta (
+ umeta_id bigint(20) NOT NULL auto_increment,
+ user_id bigint(20) NOT NULL default '0',
+ meta_key varchar(255) default NULL,
+ meta_value longtext,
+ PRIMARY KEY (umeta_id),
+ KEY user_id (user_id),
+ KEY meta_key (meta_key)
+) $charset_collate;
+CREATE TABLE IF NOT EXISTS $wpdb->blogs (
+ blog_id bigint(20) NOT NULL auto_increment,
+ site_id bigint(20) NOT NULL default '0',
+ domain varchar(200) NOT NULL default '',
+ path varchar(100) NOT NULL default '',
+ registered datetime NOT NULL default '0000-00-00 00:00:00',
+ last_updated datetime NOT NULL default '0000-00-00 00:00:00',
+ public tinyint(2) NOT NULL default '1',
+ archived enum('0','1') NOT NULL default '0',
+ mature tinyint(2) NOT NULL default '0',
+ spam tinyint(2) NOT NULL default '0',
+ deleted tinyint(2) NOT NULL default '0',
+ lang_id int(11) NOT NULL default '0',
+ PRIMARY KEY (blog_id),
+ KEY domain (domain(50),path(5)),
+ KEY lang_id (lang_id)
+);
+CREATE TABLE IF NOT EXISTS $wpdb->blog_versions (
+ blog_id bigint(20) NOT NULL default '0',
+ db_version varchar(20) NOT NULL default '',
+ last_updated datetime NOT NULL default '0000-00-00 00:00:00',
+ PRIMARY KEY (blog_id),
+ KEY db_version (db_version)
+);
+CREATE TABLE IF NOT EXISTS $wpdb->registration_log (
+ ID bigint(20) NOT NULL auto_increment,
+ email varchar(255) NOT NULL default '',
+ IP varchar(30) NOT NULL default '',
+ blog_id bigint(20) NOT NULL default '0',
+ date_registered datetime NOT NULL default '0000-00-00 00:00:00',
+ PRIMARY KEY (ID),
+ KEY IP (IP)
+);
+CREATE TABLE $wpdb->site (
+ id bigint(20) NOT NULL auto_increment,
+ domain varchar(200) NOT NULL default '',
+ path varchar(100) NOT NULL default '',
+ PRIMARY KEY (id),
+ KEY domain (domain,path)
+);
+CREATE TABLE IF NOT EXISTS $wpdb->sitemeta (
+ meta_id bigint(20) NOT NULL auto_increment,
+ site_id bigint(20) NOT NULL default '0',
+ meta_key varchar(255) default NULL,
+ meta_value longtext,
+ PRIMARY KEY (meta_id),
+ KEY meta_key (meta_key),
+ KEY site_id (site_id)
+);
+CREATE TABLE IF NOT EXISTS $wpdb->sitecategories (
+ cat_ID bigint(20) NOT NULL auto_increment,
+ cat_name varchar(55) NOT NULL default '',
+ category_nicename varchar(200) NOT NULL default '',
+ last_updated timestamp NOT NULL,
+ PRIMARY KEY (cat_ID),
+ KEY category_nicename (category_nicename),
+ KEY last_updated (last_updated)
+);
+CREATE TABLE IF NOT EXISTS $wpdb->signups (
+ domain varchar(200) NOT NULL default '',
+ path varchar(100) NOT NULL default '',
+ title longtext NOT NULL,
+ user_login varchar(60) NOT NULL default '',
+ user_email varchar(100) NOT NULL default '',
+ registered datetime NOT NULL default '0000-00-00 00:00:00',
+ activated datetime NOT NULL default '0000-00-00 00:00:00',
+ active tinyint(1) NOT NULL default '0',
+ activation_key varchar(50) NOT NULL default '',
+ meta longtext,
+ KEY activation_key (activation_key),
+ KEY domain (domain)
+);
+";
+
+function populate_options() {
+ global $wpdb, $wp_db_version, $wpblog, $current_site;
+
+ $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
+ $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+ add_option('siteurl', $guessurl);
+ add_option('blogname', __('My Blog'));
+ add_option('blogdescription', __('Just another ' . $current_site->site_name . ' weblog'), __('Short tagline'));
+ add_option('new_users_can_blog', 0);
+ add_option('users_can_register', 0);
+ add_option('admin_email', 'you@example.com');
+ add_option('start_of_week', 1);
+ add_option('use_balanceTags', 0);
+ add_option('use_smilies', 1);
+ add_option('require_name_email', 1);
+ add_option('comments_notify', 1);
+ add_option('posts_per_rss', 10);
+ add_option('rss_excerpt_length', 50);
+ add_option('rss_use_excerpt', 0);
+ add_option('mailserver_url', 'mail.example.com');
+ add_option('mailserver_login', 'login@example.com');
+ add_option('mailserver_pass', 'password');
+ add_option('mailserver_port', 110);
+ add_option('default_category', 1);
+ add_option('default_comment_status', 'open');
+ add_option('default_ping_status', 'open');
+ add_option('default_pingback_flag', 1);
+ add_option('default_post_edit_rows', 10);
+ add_option('posts_per_page', 10);
+ add_option('what_to_show', 'posts');
+ add_option('date_format', __('F j, Y'));
+ add_option('time_format', __('g:i a'));
+ add_option('links_updated_date_format', __('F j, Y g:i a'));
+ add_option('links_recently_updated_prepend', '<em>');
+ add_option('links_recently_updated_append', '</em>');
+ add_option('links_recently_updated_time', 120);
+ add_option('comment_moderation', 0);
+ add_option('moderation_notify', 1);
+ add_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');
+ add_option('gzipcompression', 0);
+ add_option('hack_file', 0);
+ add_option('blog_charset', 'UTF-8');
+ add_option('moderation_keys');
+ add_option('active_plugins');
+ add_option('home', $guessurl);
+ // in case it is set, but blank, update "home"
+ if ( !__get_option('home') ) update_option('home', $guessurl);
+ add_option('category_base');
+ add_option('ping_sites', 'http://rpc.pingomatic.com/');
+ add_option('advanced_edit', 0);
+ add_option('comment_max_links', 2);
+ add_option('gmt_offset', date('Z') / 3600);
+ // 1.5
+ add_option('default_email_category', 1);
+ add_option('recently_edited');
+ add_option('use_linksupdate', 0);
+ add_option('template', 'default');
+ add_option('stylesheet', 'default');
+ add_option('comment_whitelist', 1);
+ add_option('page_uris');
+ add_option('blacklist_keys');
+ add_option('comment_registration', 0);
+ add_option('rss_language', 'en');
+ add_option('html_type', 'text/html');
+ // 1.5.1
+ add_option('use_trackback', 0);
+ // 2.0
+ add_option('default_role', 'subscriber');
+ add_option('db_version', $wp_db_version);
+ // 2.0.1
+ if ( ini_get('safe_mode') ) {
+ // Safe mode screws up mkdir(), so we must use a flat structure.
+ add_option('uploads_use_yearmonth_folders', 0);
+ add_option('upload_path', 'wp-content');
+ } else {
+ add_option('uploads_use_yearmonth_folders', 1);
+ add_option('upload_path', 'wp-content/uploads');
+ }
+
+ // 2.0.3
+ add_option('secret', md5(uniqid(microtime())));
+
+ // 2.1
+ add_option('blog_public', '1');
+ add_option('default_link_category', 2);
+ add_option('show_on_front', 'posts');
+
+ // 2.2
+ add_option('tag_base');
+
+ // Delete unused options
+ $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing');
+ foreach ($unusedoptions as $option) :
+ delete_option($option);
+ endforeach;
+
+ // Set up a few options not to load by default
+ $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
+ foreach ($fatoptions as $fatoption) :
+ $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
+ endforeach;
+}
+
+function populate_roles() {
+ populate_roles_160();
+ populate_roles_210();
+ populate_roles_230();
+}
+
+function populate_roles_160() {
+ global $wp_roles;
+
+ // Add roles
+ add_role('administrator', __('Administrator'));
+ add_role('editor', __('Editor'));
+ add_role('author', __('Author'));
+ add_role('contributor', __('Contributor'));
+ add_role('subscriber', __('Subscriber'));
+
+ // Add caps for Administrator role
+ $role = get_role('administrator');
+ $role->add_cap('switch_themes');
+ $role->add_cap('edit_themes');
+ $role->add_cap('activate_plugins');
+ $role->add_cap('edit_plugins');
+ $role->add_cap('edit_users');
+ $role->add_cap('edit_files');
+ $role->add_cap('manage_options');
+ $role->add_cap('moderate_comments');
+ $role->add_cap('manage_categories');
+ $role->add_cap('manage_links');
+ $role->add_cap('upload_files');
+ $role->add_cap('import');
+ $role->add_cap('unfiltered_html');
+ $role->add_cap('edit_posts');
+ $role->add_cap('edit_others_posts');
+ $role->add_cap('edit_published_posts');
+ $role->add_cap('publish_posts');
+ $role->add_cap('edit_pages');
+ $role->add_cap('read');
+ $role->add_cap('level_10');
+ $role->add_cap('level_9');
+ $role->add_cap('level_8');
+ $role->add_cap('level_7');
+ $role->add_cap('level_6');
+ $role->add_cap('level_5');
+ $role->add_cap('level_4');
+ $role->add_cap('level_3');
+ $role->add_cap('level_2');
+ $role->add_cap('level_1');
+ $role->add_cap('level_0');
+
+ // Add caps for Editor role
+ $role = get_role('editor');
+ $role->add_cap('moderate_comments');
+ $role->add_cap('manage_categories');
+ $role->add_cap('manage_links');
+ $role->add_cap('upload_files');
+ $role->add_cap('unfiltered_html');
+ $role->add_cap('edit_posts');
+ $role->add_cap('edit_others_posts');
+ $role->add_cap('edit_published_posts');
+ $role->add_cap('publish_posts');
+ $role->add_cap('edit_pages');
+ $role->add_cap('read');
+ $role->add_cap('level_7');
+ $role->add_cap('level_6');
+ $role->add_cap('level_5');
+ $role->add_cap('level_4');
+ $role->add_cap('level_3');
+ $role->add_cap('level_2');
+ $role->add_cap('level_1');
+ $role->add_cap('level_0');
+
+ // Add caps for Author role
+ $role = get_role('author');
+ $role->add_cap('upload_files');
+ $role->add_cap('edit_posts');
+ $role->add_cap('edit_published_posts');
+ $role->add_cap('publish_posts');
+ $role->add_cap('read');
+ $role->add_cap('level_2');
+ $role->add_cap('level_1');
+ $role->add_cap('level_0');
+
+ // Add caps for Contributor role
+ $role = get_role('contributor');
+ $role->add_cap('edit_posts');
+ $role->add_cap('read');
+ $role->add_cap('level_1');
+ $role->add_cap('level_0');
+
+ // Add caps for Subscriber role
+ $role = get_role('subscriber');
+ $role->add_cap('read');
+ $role->add_cap('level_0');
+}
+
+function populate_roles_210() {
+ $roles = array('administrator', 'editor');
+ foreach ($roles as $role) {
+ $role = get_role($role);
+ if ( empty($role) )
+ continue;
+
+ $role->add_cap('edit_others_pages');
+ $role->add_cap('edit_published_pages');
+ $role->add_cap('publish_pages');
+ $role->add_cap('delete_pages');
+ $role->add_cap('delete_others_pages');
+ $role->add_cap('delete_published_pages');
+ $role->add_cap('delete_posts');
+ $role->add_cap('delete_others_posts');
+ $role->add_cap('delete_published_posts');
+ $role->add_cap('delete_private_posts');
+ $role->add_cap('edit_private_posts');
+ $role->add_cap('read_private_posts');
+ $role->add_cap('delete_private_pages');
+ $role->add_cap('edit_private_pages');
+ $role->add_cap('read_private_pages');
+ }
+
+ $role = get_role('administrator');
+ if ( ! empty($role) ) {
+ $role->add_cap('delete_users');
+ $role->add_cap('create_users');
+ }
+
+ $role = get_role('author');
+ if ( ! empty($role) ) {
+ $role->add_cap('delete_posts');
+ $role->add_cap('delete_published_posts');
+ }
+
+ $role = get_role('contributor');
+ if ( ! empty($role) ) {
+ $role->add_cap('delete_posts');
+ }
+}
+
+function populate_roles_230() {
+ /*
+ $role = get_role( 'administrator' );
+
+ if ( !empty( $role ) ) {
+ $role->add_cap( 'unfiltered_upload' );
+ }
+ */
+}
+
+?>
diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php
new file mode 100644
index 0000000..3f70f45
--- /dev/null
+++ b/wp-admin/includes/taxonomy.php
@@ -0,0 +1,148 @@
+<?php
+
+//
+// Category
+//
+
+function category_exists($cat_name) {
+ $id = is_term($cat_name, 'category');
+ if ( is_array($id) )
+ $id = $id['term_id'];
+ return $id;
+}
+
+function get_category_to_edit( $id ) {
+ $category = get_category( $id, OBJECT, 'edit' );
+ return $category;
+}
+
+function wp_create_category($cat_name) {
+ if ( $id = category_exists($cat_name) )
+ return $id;
+
+ return wp_insert_category( array('cat_name' => $cat_name) );
+}
+
+function wp_create_categories($categories, $post_id = '') {
+ $cat_ids = array ();
+ foreach ($categories as $category) {
+ if ($id = category_exists($category))
+ $cat_ids[] = $id;
+ else
+ if ($id = wp_create_category($category))
+ $cat_ids[] = $id;
+ }
+
+ if ($post_id)
+ wp_set_post_categories($post_id, $cat_ids);
+
+ return $cat_ids;
+}
+
+function wp_delete_category($cat_ID) {
+ global $wpdb;
+
+ $cat_ID = (int) $cat_ID;
+ $default = get_option('default_category');
+
+ // Don't delete the default cat
+ if ( $cat_ID == $default )
+ return 0;
+
+ return wp_delete_term($cat_ID, 'category', "default=$default");
+}
+
+function wp_insert_category($catarr) {
+ global $wpdb;
+
+ extract($catarr, EXTR_SKIP);
+
+ if ( trim( $cat_name ) == '' )
+ return 0;
+
+ $cat_ID = (int) $cat_ID;
+
+ // Are we updating or creating?
+ if ( !empty ($cat_ID) )
+ $update = true;
+ else
+ $update = false;
+
+ $name = $cat_name;
+ $description = $category_description;
+ $slug = $category_nicename;
+ $parent = $category_parent;
+
+ $parent = (int) $parent;
+ if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
+ $parent = 0;
+
+ $args = compact('name', 'slug', 'parent', 'description');
+
+ if ( $update )
+ $cat_ID = wp_update_term($cat_ID, 'category', $args);
+ else
+ $cat_ID = wp_insert_term($cat_name, 'category', $args);
+
+ if ( is_wp_error($cat_ID) )
+ return 0;
+
+ return $cat_ID['term_id'];
+}
+
+function wp_update_category($catarr) {
+ global $wpdb;
+
+ $cat_ID = (int) $catarr['cat_ID'];
+
+ if ( $cat_ID == $catarr['category_parent'] )
+ return false;
+
+ // First, get all of the original fields
+ $category = get_category($cat_ID, ARRAY_A);
+
+ // Escape data pulled from DB.
+ $category = add_magic_quotes($category);
+
+ // Merge old and new fields with new fields overwriting old ones.
+ $catarr = array_merge($category, $catarr);
+
+ return wp_insert_category($catarr);
+}
+
+//
+// Tags
+//
+
+function get_tags_to_edit( $post_id ) {
+ global $wpdb;
+
+ $post_id = (int) $post_id;
+ if ( !$post_id )
+ return false;
+
+ $tags = wp_get_post_tags($post_id);
+
+ if ( !$tags )
+ return false;
+
+ foreach ( $tags as $tag )
+ $tag_names[] = $tag->name;
+ $tags_to_edit = join( ', ', $tag_names );
+ $tags_to_edit = attribute_escape( $tags_to_edit );
+ $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit );
+ return $tags_to_edit;
+}
+
+function tag_exists($tag_name) {
+ return is_term($tag_name, 'post_tag');
+}
+
+function wp_create_tag($tag_name) {
+ if ( $id = tag_exists($tag_name) )
+ return $id;
+
+ return wp_insert_term($tag_name, 'post_tag');
+}
+
+?> \ No newline at end of file
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
new file mode 100644
index 0000000..1cf9284
--- /dev/null
+++ b/wp-admin/includes/template.php
@@ -0,0 +1,626 @@
+<?php
+
+//
+// Big Mess
+//
+
+// Dandy new recursive multiple category stuff.
+function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
+ if ( !$categories )
+ $categories = get_categories( 'hide_empty=0' );
+
+ $children = _get_term_hierarchy('category');
+
+ if ( $categories ) {
+ ob_start();
+ foreach ( $categories as $category ) {
+ if ( $category->term_id == 0 ) {
+ $wpdb->query("DELETE FROM $wpdb->terms WHERE term_id = 0");
+ continue;
+ }
+ if ( $category->parent == $parent) {
+ echo "\t" . _cat_row( $category, $level );
+ if ( isset($children[$category->term_id]) )
+ cat_rows( $category->term_id, $level +1, $categories );
+ }
+ }
+ $output = ob_get_contents();
+ ob_end_clean();
+
+ $output = apply_filters('cat_rows', $output);
+
+ echo $output;
+ } else {
+ return false;
+ }
+}
+
+function _cat_row( $category, $level, $name_override = false ) {
+ global $class;
+
+ $pad = str_repeat( '&#8212; ', $level );
+ if ( current_user_can( 'manage_categories' ) ) {
+ $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
+ $default_cat_id = (int) get_option( 'default_category' );
+
+ if ( $category->term_id != $default_cat_id )
+ $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&amp;cat_ID=$category->term_id", 'delete-category_' . $category->term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>";
+ else
+ $edit .= "<td style='text-align:center'>".__( "Default" );
+ } else
+ $edit = '';
+
+ $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
+
+ $category->count = number_format_i18n( $category->count );
+ $posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
+ $output = "<tr id='cat-$category->term_id'$class>
+ <th scope='row' style='text-align: center'>$category->term_id</th>
+ <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
+ <td>$category->description</td>
+ <td align='center'>$posts_count</td>
+ <td>$edit</td>\n\t</tr>\n";
+
+ return apply_filters('cat_row', $output);
+}
+
+function checked( $checked, $current) {
+ if ( $checked == $current)
+ echo ' checked="checked"';
+}
+
+// TODO: Remove?
+function documentation_link( $for ) {
+ return;
+}
+
+function selected( $selected, $current) {
+ if ( $selected == $current)
+ echo ' selected="selected"';
+}
+
+//
+// Nasty Category Stuff
+//
+
+function sort_cats( $cat1, $cat2 ) {
+ if ( $cat1['checked'] || $cat2['checked'] )
+ return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1;
+ else
+ return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
+}
+
+function get_nested_categories( $default = 0, $parent = 0 ) {
+ global $post_ID, $mode, $wpdb, $checked_categories;
+
+ if ( empty($checked_categories) ) {
+ if ( $post_ID ) {
+ $checked_categories = wp_get_post_categories($post_ID);
+
+ if ( count( $checked_categories ) == 0 ) {
+ // No selected categories, strange
+ $checked_categories[] = $default;
+ }
+ } else {
+ $checked_categories[] = $default;
+ }
+ }
+
+ $cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
+
+ $result = array ();
+ if ( is_array( $cats ) ) {
+ foreach ( $cats as $cat) {
+ if ( $cat == 0 ) {
+ $wpdb->query("DELETE FROM $wpdb->terms WHERE term_id = 0");
+ continue;
+ }
+ $result[$cat]['children'] = get_nested_categories( $default, $cat);
+ $result[$cat]['cat_ID'] = $cat;
+ $result[$cat]['checked'] = in_array( $cat, $checked_categories );
+ $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
+ }
+ }
+
+ $result = apply_filters('get_nested_categories', $result);
+ usort( $result, 'sort_cats' );
+
+ return $result;
+}
+
+function write_nested_categories( $categories ) {
+ foreach ( $categories as $category ) {
+ echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>";
+
+ if ( $category['children'] ) {
+ echo "<ul>\n";
+ write_nested_categories( $category['children'] );
+ echo "</ul>\n";
+ }
+ }
+}
+
+function dropdown_categories( $default = 0 ) {
+ write_nested_categories( get_nested_categories( $default) );
+}
+
+function dropdown_link_categories( $default = 0 ) {
+ global $link_id;
+
+ if ( $link_id ) {
+ $checked_categories = wp_get_link_cats($link_id);
+
+ if ( count( $checked_categories ) == 0 ) {
+ // No selected categories, strange
+ $checked_categories[] = $default;
+ }
+ } else {
+ $checked_categories[] = $default;
+ }
+
+ $categories = get_terms('link_category', 'orderby=count&hide_empty=0');
+
+ if ( empty($categories) )
+ return;
+
+ foreach ( $categories as $category ) {
+ $cat_id = $category->term_id;
+ $name = wp_specialchars( apply_filters('the_category', $category->name));
+ $checked = in_array( $cat_id, $checked_categories );
+ echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', ($checked ? ' checked="checked"' : "" ), '/> ', $name, "</label></li>";
+ }
+}
+
+function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
+ global $wpdb, $class, $post;
+
+ if (!$pages )
+ $pages = get_pages( 'sort_column=menu_order' );
+
+ if (! $pages )
+ return false;
+
+ foreach ( $pages as $post) {
+ setup_postdata( $post);
+ if ( $hierarchy && ($post->post_parent != $parent) )
+ continue;
+
+ $post->post_title = wp_specialchars( $post->post_title );
+ $pad = str_repeat( '&#8212; ', $level );
+ $id = (int) $post->ID;
+ $class = ('alternate' == $class ) ? '' : 'alternate';
+?>
+ <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
+ <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>
+ <td>
+ <?php echo $pad; ?><?php the_title() ?>
+ </td>
+ <td><?php the_author() ?></td>
+ <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>
+ <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td>
+ <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
+ <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
+ </tr>
+
+<?php
+ if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
+ }
+}
+
+function user_row( $user_object, $style = '' ) {
+ global $current_user;
+
+ if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
+ $user_object = new WP_User( (int) $user_object );
+ $email = $user_object->user_email;
+ $url = $user_object->user_url;
+ $short_url = str_replace( 'http://', '', $url );
+ $short_url = str_replace( 'www.', '', $short_url );
+ if ('/' == substr( $short_url, -1 ))
+ $short_url = substr( $short_url, 0, -1 );
+ if ( strlen( $short_url ) > 35 )
+ $short_url = substr( $short_url, 0, 32 ).'...';
+ $numposts = get_usernumposts( $user_object->ID );
+ $r = "<tr id='user-$user_object->ID'$style>
+ <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
+ <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
+ <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
+ <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
+ <td><a href='$url' title='website: $url'>$short_url</a></td>";
+ $r .= "\n\t\t<td align='center'>";
+ if ( $numposts > 0 ) {
+ $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
+ $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts);
+ $r .= '</a>';
+ }
+ $r .= "</td>\n\t\t<td>";
+ if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can( 'edit_user', $user_object->ID ) ) {
+ $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
+ $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
+ }
+ $r .= "</td>\n\t</tr>";
+ return $r;
+}
+
+function _wp_get_comment_list( $s = false, $start, $num ) {
+ global $wpdb;
+
+ $start = abs( (int) $start );
+ $num = (int) $num;
+
+ if ( $s ) {
+ $s = $wpdb->escape($s);
+ $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
+ (comment_author LIKE '%$s%' OR
+ comment_author_email LIKE '%$s%' OR
+ comment_author_url LIKE ('%$s%') OR
+ comment_author_IP LIKE ('%$s%') OR
+ comment_content LIKE ('%$s%') ) AND
+ comment_approved != 'spam'
+ ORDER BY comment_date DESC LIMIT $start, $num");
+ } else {
+ $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
+ }
+
+ update_comment_cache($comments);
+
+ $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
+
+ return array($comments, $total);
+}
+
+function _wp_comment_list_item( $id, $alt = 0 ) {
+ global $authordata, $comment, $wpdb;
+ $id = (int) $id;
+ $comment =& get_comment( $id );
+ $class = '';
+ $post = get_post($comment->comment_post_ID);
+ $authordata = get_userdata($post->post_author);
+ $comment_status = wp_get_comment_status($comment->comment_ID);
+ if ( 'unapproved' == $comment_status )
+ $class .= ' unapproved';
+ if ( $alt % 2 )
+ $class .= ' alternate';
+ echo "<li id='comment-$comment->comment_ID' class='$class'>";
+?>
+<p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
+
+<?php comment_text() ?>
+
+<p><?php comment_date(__('M j, g:i A')); ?> &#8212; [
+<?php
+if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
+ echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" . __('Edit') . '</a>';
+ echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
+ if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
+ echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
+ echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
+ }
+ echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
+}
+$post = get_post($comment->comment_post_ID, OBJECT, 'display');
+$post_title = wp_specialchars( $post->post_title, 'double' );
+$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
+?>
+ ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
+ </li>
+<?php
+}
+
+function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
+ global $wpdb;
+ if (!$categories )
+ $categories = get_categories( 'hide_empty=0' );
+
+ if ( $categories ) {
+ foreach ( $categories as $category ) {
+ if ( $currentcat != $category->term_id && $parent == $category->parent) {
+ $pad = str_repeat( '&#8211; ', $level );
+ $category->name = wp_specialchars( $category->name );
+ echo "\n\t<option value='$category->term_id'";
+ if ( $currentparent == $category->term_id )
+ echo " selected='selected'";
+ echo ">$pad$category->name</option>";
+ wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories );
+ }
+ }
+ } else {
+ return false;
+ }
+}
+
+function list_meta( $meta ) {
+ global $post_ID;
+ // Exit if no meta
+ if (!$meta ) {
+ echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
+ return;
+ }
+ $count = 0;
+?>
+ <thead>
+ <tr>
+ <th><?php _e( 'Key' ) ?></th>
+ <th><?php _e( 'Value' ) ?></th>
+ <th colspan='2'><?php _e( 'Action' ) ?></th>
+ </tr>
+ </thead>
+<?php
+ $r ="\n\t<tbody id='the-list'>";
+ foreach ( $meta as $entry ) {
+ ++ $count;
+ if ( $count % 2 )
+ $style = 'alternate';
+ else
+ $style = '';
+ if ('_' == $entry['meta_key'] { 0 } )
+ $style .= ' hidden';
+
+ if ( is_serialized( $entry['meta_value'] ) ) {
+ if ( is_serialized_string( $entry['meta_value'] ) ) {
+ // this is a serialized string, so we should display it
+ $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
+ } else {
+ // this is a serialized array/object so we should NOT display it
+ --$count;
+ continue;
+ }
+ }
+
+ $key_js = js_escape( $entry['meta_key'] );
+ $entry['meta_key'] = attribute_escape($entry['meta_key']);
+ $entry['meta_value'] = attribute_escape($entry['meta_value']);
+ $entry['meta_id'] = (int) $entry['meta_id'];
+ $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
+ $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
+ $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
+ $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".attribute_escape(__( 'Update' ))."' /><br />";
+ $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
+ $r .= js_escape(sprintf( __("You are about to delete the '%s' custom field on this post.\n'OK' to delete, 'Cancel' to stop." ), $key_js ) );
+ $r .= "' );\" class='deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' /></td>";
+ $r .= "\n\t</tr>";
+ }
+ echo $r;
+ echo "\n\t</tbody>";
+}
+
+function meta_form() {
+ global $wpdb;
+ $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
+ $keys = $wpdb->get_col( "
+ SELECT meta_key
+ FROM $wpdb->postmeta
+ WHERE meta_key NOT LIKE '\_%'
+ GROUP BY meta_key
+ ORDER BY meta_id DESC
+ LIMIT $limit" );
+ if ( $keys )
+ natcasesort($keys);
+?>
+<h3><?php _e( 'Add a new custom field:' ) ?></h3>
+<table id="newmeta" cellspacing="3" cellpadding="3">
+ <tr>
+<th colspan="2"><?php _e( 'Key' ) ?></th>
+<th><?php _e( 'Value' ) ?></th>
+</tr>
+ <tr valign="top">
+ <td align="right" width="18%">
+<?php if ( $keys ) : ?>
+<select id="metakeyselect" name="metakeyselect" tabindex="7">
+<option value="#NONE#"><?php _e( '- Select -' ); ?></option>
+<?php
+
+ foreach ( $keys as $key ) {
+ $key = attribute_escape( $key );
+ echo "\n\t<option value='$key'>$key</option>";
+ }
+?>
+</select> <?php _e( 'or' ); ?>
+<?php endif; ?>
+</td>
+<td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
+ <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
+ </tr>
+
+</table>
+<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p>
+<?php
+
+}
+
+function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
+ global $wp_locale, $post, $comment;
+
+ if ( $for_post )
+ $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
+
+ $tab_index_attribute = '';
+ if ( (int) $tab_index > 0 )
+ $tab_index_attribute = " tabindex=\"$tab_index\"";
+
+ echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
+
+ $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
+ $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
+ $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
+ $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
+ $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
+ $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
+ $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
+ $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
+
+ echo "<select name=\"mm\" onchange=\"edit_date.checked=true\"$tab_index_attribute>\n";
+ for ( $i = 1; $i < 13; $i = $i +1 ) {
+ echo "\t\t\t<option value=\"$i\"";
+ if ( $i == $mm )
+ echo ' selected="selected"';
+ echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
+ }
+?>
+</select>
+<input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
+<input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> @
+<input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> :
+<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
+<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
+<?php
+ if ( $edit ) {
+ printf( _c( 'Existing timestamp: %1$s %2$s, %3$s @ %4$s:%5$s|1: month, 2: month string, 3: full year, 4: hours, 5: minutes' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn );
+ }
+?>
+</fieldset>
+ <?php
+
+}
+
+function page_template_dropdown( $default = '' ) {
+ $templates = get_page_templates();
+ ksort( $templates );
+ foreach (array_keys( $templates ) as $template )
+ : if ( $default == $templates[$template] )
+ $selected = " selected='selected'";
+ else
+ $selected = '';
+ echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";
+ endforeach;
+}
+
+function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
+ global $wpdb, $post_ID;
+ $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" );
+
+ if ( $items ) {
+ foreach ( $items as $item ) {
+ // A page cannot be its own parent.
+ if (!empty ( $post_ID ) ) {
+ if ( $item->ID == $post_ID ) {
+ continue;
+ }
+ }
+ $pad = str_repeat( '&nbsp;', $level * 3 );
+ if ( $item->ID == $default)
+ $current = ' selected="selected"';
+ else
+ $current = '';
+
+ echo "\n\t<option value='$item->ID'$current>$pad " . wp_specialchars($item->post_title) . "</option>";
+ parent_dropdown( $default, $item->ID, $level +1 );
+ }
+ } else {
+ return false;
+ }
+}
+
+function browse_happy() {
+ $getit = __( 'WordPress recommends a better browser' );
+ echo '
+ <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p>
+ ';
+}
+
+if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
+ add_action( 'admin_footer', 'browse_happy' );
+
+function the_attachment_links( $id = false ) {
+ $id = (int) $id;
+ $post = & get_post( $id );
+
+ if ( $post->post_type != 'attachment' )
+ return false;
+
+ $icon = get_attachment_icon( $post->ID );
+ $attachment_data = wp_get_attachment_metadata( $id );
+ $thumb = isset( $attachment_data['thumb'] );
+?>
+<form id="the-attachment-links">
+<table>
+ <col />
+ <col class="widefat" />
+ <tr>
+ <th scope="row"><?php _e( 'URL' ) ?></th>
+ <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td>
+ </tr>
+<?php if ( $icon ) : ?>
+ <tr>
+ <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th>
+ <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td>
+ </tr>
+ <tr>
+ <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th>
+ <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td>
+ </tr>
+<?php else : ?>
+ <tr>
+ <th scope="row"><?php _e( 'Link to file' ) ?></th>
+ <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td>
+ </tr>
+ <tr>
+ <th scope="row"><?php _e( 'Link to page' ) ?></th>
+ <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td>
+ </tr>
+<?php endif; ?>
+</table>
+</form>
+<?php
+}
+
+function wp_dropdown_roles( $default = false ) {
+ global $wp_roles;
+ $r = '';
+ foreach( array_reverse($wp_roles->role_names) as $role => $name )
+ if ( $default == $role ) // Make default first in list
+ $p = "\n\t<option selected='selected' value='$role'>$name</option>";
+ else
+ $r .= "\n\t<option value='$role'>$name</option>";
+ echo $p . $r;
+}
+
+function wp_convert_hr_to_bytes( $size ) {
+ $size = strtolower($size);
+ $bytes = (int) $size;
+ if ( strpos($size, 'k') !== false )
+ $bytes = intval($size) * 1024;
+ elseif ( strpos($size, 'm') !== false )
+ $bytes = intval($size) * 1024 * 1024;
+ elseif ( strpos($size, 'g') !== false )
+ $bytes = intval($size) * 1024 * 1024 * 1024;
+ return $bytes;
+}
+
+function wp_convert_bytes_to_hr( $bytes ) {
+ $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
+ $log = log( $bytes, 1024 );
+ $power = (int) $log;
+ $size = pow(1024, $log - $power);
+ return $size . $units[$power];
+}
+
+function wp_import_upload_form( $action ) {
+ $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
+ $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
+ $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
+ $size = wp_convert_bytes_to_hr( $bytes );
+?>
+<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
+<p>
+<?php wp_nonce_field('import-upload'); ?>
+<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?>)
+<input type="file" id="upload" name="import" size="25" />
+<input type="hidden" name="action" value="save" />
+<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
+</p>
+<p class="submit">
+<input type="submit" value="<?php _e( 'Upload file and import &raquo;' ); ?>" />
+</p>
+</form>
+<?php
+}
+
+function wp_remember_old_slug() {
+ global $post;
+ $name = attribute_escape($post->post_name); // just in case
+ if ( strlen($name) )
+ echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
+}
+
+?>
diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php
new file mode 100644
index 0000000..bd39dea
--- /dev/null
+++ b/wp-admin/includes/theme.php
@@ -0,0 +1,52 @@
+<?php
+
+function current_theme_info() {
+ $themes = get_themes();
+ $current_theme = get_current_theme();
+ $ct->name = $current_theme;
+ $ct->title = $themes[$current_theme]['Title'];
+ $ct->version = $themes[$current_theme]['Version'];
+ $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
+ $ct->template_dir = $themes[$current_theme]['Template Dir'];
+ $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
+ $ct->template = $themes[$current_theme]['Template'];
+ $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
+ $ct->screenshot = $themes[$current_theme]['Screenshot'];
+ $ct->description = $themes[$current_theme]['Description'];
+ $ct->author = $themes[$current_theme]['Author'];
+ return $ct;
+}
+
+function get_broken_themes() {
+ global $wp_broken_themes;
+
+ get_themes();
+ return $wp_broken_themes;
+}
+
+function get_page_templates() {
+ $themes = get_themes();
+ $theme = get_current_theme();
+ $templates = $themes[$theme]['Template Files'];
+ $page_templates = array ();
+
+ if ( is_array( $templates ) ) {
+ foreach ( $templates as $template ) {
+ $template_data = implode( '', file( ABSPATH.$template ));
+
+ preg_match( '|Template Name:(.*)$|mi', $template_data, $name );
+ preg_match( '|Description:(.*)$|mi', $template_data, $description );
+
+ $name = $name[1];
+ $description = $description[1];
+
+ if ( !empty( $name ) ) {
+ $page_templates[trim( $name )] = basename( $template );
+ }
+ }
+ }
+
+ return $page_templates;
+}
+
+?>
diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php
new file mode 100644
index 0000000..cbd0d4a
--- /dev/null
+++ b/wp-admin/includes/update.php
@@ -0,0 +1,122 @@
+<?php
+/*
+// The admin side of our 1.0 update system
+
+function core_update_footer( $msg ) {
+ if ( !current_user_can('manage_options') )
+ return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
+
+ $cur = get_option( 'update_core' );
+
+ switch ( $cur->response ) {
+ case 'development' :
+ return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], 'http://wordpress.org/download/svn/' );
+ break;
+
+ case 'upgrade' :
+ return sprintf( '| <strong>'.__( 'Your WordPress %s is out of date. <a href="%s">Please update</a>.' ).'</strong>', $GLOBALS['wp_version'], $cur->url );
+ break;
+
+ case 'latest' :
+ default :
+ return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
+ break;
+ }
+}
+add_filter( 'update_footer', 'core_update_footer' );
+
+function update_nag() {
+ $cur = get_option( 'update_core' );
+
+ if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
+ return false;
+
+ if ( current_user_can('manage_options') )
+ $msg = sprintf( __('A new version of WordPress is available! <a href="%s">Please update now</a>.'), $cur->url );
+ else
+ $msg = __('A new version of WordPress is available! Please notify the site administrator.');
+
+ echo "<div id='update-nag'>$msg</div>";
+}
+add_action( 'admin_notices', 'update_nag', 3 );
+
+function wp_update_plugins() {
+ global $wp_version;
+
+ if ( !function_exists('fsockopen') )
+ return false;
+
+ $plugins = get_plugins();
+ $active = get_option( 'active_plugins' );
+ $current = get_option( 'update_plugins' );
+
+ $new_option = '';
+ $new_option->last_checked = time();
+
+ $plugin_changed = false;
+ foreach ( $plugins as $file => $p ) {
+ $new_option->checked[ $file ] = $p['Version'];
+
+ if ( !isset( $current->checked[ $file ] ) ) {
+ $plugin_changed = true;
+ continue;
+ }
+
+ if ( $current->checked[ $file ] != $p['Version'] )
+ $plugin_changed = true;
+ }
+
+ if (
+ isset( $current->last_checked ) &&
+ 43200 > ( time() - $current->last_checked ) &&
+ !$plugin_changed
+ )
+ return false;
+
+ $to_send->plugins = $plugins;
+ $to_send->active = $active;
+ $send = serialize( $to_send );
+
+ $request = 'plugins=' . urlencode( $send );
+ $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
+ $http_request .= "Host: api.wordpress.org\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
+ $http_request .= "Content-Length: " . strlen($request) . "\r\n";
+ $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $request;
+
+ $response = '';
+ if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {
+ fwrite($fs, $http_request);
+
+ while ( !feof($fs) )
+ $response .= fgets($fs, 1160); // One TCP-IP packet
+ fclose($fs);
+ $response = explode("\r\n\r\n", $response, 2);
+ }
+
+ $response = unserialize( $response[1] );
+
+ if ( $response )
+ $new_option->response = $response;
+
+ update_option( 'update_plugins', $new_option );
+}
+add_action( 'load-plugins.php', 'wp_update_plugins' );
+
+function wp_plugin_update_row( $file ) {
+ global $plugin_data;
+ $current = get_option( 'update_plugins' );
+ if ( !isset( $current->response[ $file ] ) )
+ return false;
+
+ $r = $current->response[ $file ];
+
+ echo "<tr><td colspan='5' class='plugin-update'>";
+ printf( __('There is a new version of %s available. <a href="%s">Download version %s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version );
+ echo "</td></tr>";
+}
+add_action( 'after_plugin_row', 'wp_plugin_update_row' );
+*/
+?>
diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php
new file mode 100644
index 0000000..71e6399
--- /dev/null
+++ b/wp-admin/includes/upgrade.php
@@ -0,0 +1,1271 @@
+<?php
+
+if ( file_exists(ABSPATH . 'wp-content/install.php') )
+ require (ABSPATH . 'wp-content/install.php');
+require_once(ABSPATH . 'wp-admin/includes/admin.php');
+require_once(ABSPATH . 'wp-admin/includes/schema.php');
+
+if ( !function_exists('wp_install') ) :
+function wp_install($blog_title, $user_name, $user_email, $public, $meta='') {
+ global $wp_rewrite;
+
+ wp_check_mysql_version();
+ wp_cache_flush();
+ make_db_current_silent();
+ populate_options();
+ populate_roles();
+
+ update_option('blogname', $blog_title);
+ update_option('admin_email', $user_email);
+ update_option('blog_public', $public);
+ $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
+
+ if ( defined('WP_SITEURL') && '' != WP_SITEURL )
+ $guessurl = WP_SITEURL;
+ else
+ $guessurl = preg_replace('|/wp-admin/.*|i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+
+ update_option('siteurl', $guessurl);
+
+ // If not a public blog, don't ping.
+ if ( ! $public )
+ update_option('default_pingback_flag', 0);
+
+ // Create default user. If the user already exists, the user tables are
+ // being shared among blogs. Just set the role in that case.
+ $user_id = username_exists($user_name);
+ if ( !$user_id ) {
+ $random_password = substr(md5(uniqid(microtime())), 0, 6);
+ $user_id = wp_create_user($user_name, $random_password, $user_email);
+ } else {
+ $random_password = __('User already exists. Password inherited.');
+ }
+
+ $user = new WP_User($user_id);
+ $user->set_role('administrator');
+
+ wp_install_defaults($user_id);
+
+ $wp_rewrite->flush_rules();
+
+ wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password);
+
+ wp_cache_flush();
+
+ return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password);
+}
+endif;
+
+if ( !function_exists('wp_install_defaults') ) :
+function wp_install_defaults($user_id) {
+ global $wpdb;
+
+ // Default category
+ $cat_name = $wpdb->escape(__('Uncategorized'));
+ $cat_slug = sanitize_title(__('Uncategorized'));
+ $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('1', 'category', '', '0', '1')");
+
+ // Default link category
+ $cat_name = $wpdb->escape(__('Blogroll'));
+ $cat_slug = sanitize_title(__('Blogroll'));
+ $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('2', 'link_category', '', '0', '7')");
+
+ // Now drop in some default links
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://codex.wordpress.org/', 'Documentation', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/development/', 'Development Blog', 0, 'http://wordpress.org/development/feed/', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (2, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/ideas/', 'Suggest Ideas', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (3, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/support/', 'Support Forum', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (4, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/plugins/', 'Plugins', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (5, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/themes/', 'Themes', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (6, 2)" );
+
+ $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://planet.wordpress.org/', 'WordPress Planet', 0, '', '');");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (7, 2)" );
+
+ // First post
+ $now = date('Y-m-d H:i:s');
+ $now_gmt = gmdate('Y-m-d H:i:s');
+ $first_post_guid = get_option('home') . '/?p=1';
+ $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, guid, 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', '$first_post_guid', '1', '', '', '')");
+ $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 1)" );
+
+ // Default comment
+ $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.'))."')");
+
+ // First Page
+ $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', '', '', '')");
+}
+endif;
+
+if ( !function_exists('wp_new_blog_notification') ) :
+function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) {
+ $user = new WP_User($user_id);
+ $email = $user->user_email;
+ $name = $user->user_login;
+ $message_headers = 'From: "' . $blog_title . '" <wordpress@' . $_SERVER['SERVER_NAME'] . '>';
+ $message = sprintf(__("Your new WordPress blog has been successfully set up at:
+
+%1\$s
+
+You can log in to the administrator account with the following information:
+
+Username: %2\$s
+Password: %3\$s
+
+We hope you enjoy your new blog. Thanks!
+
+--The WordPress Team
+http://wordpress.org/
+"), $blog_url, $name, $password);
+
+ @wp_mail($email, __('New WordPress Blog'), $message, $message_headers);
+}
+endif;
+
+if ( !function_exists('wp_upgrade') ) :
+function wp_upgrade() {
+ global $wp_current_db_version, $wp_db_version;
+
+ $wp_current_db_version = __get_option('db_version');
+
+ // We are up-to-date. Nothing to do.
+ if ( $wp_db_version == $wp_current_db_version )
+ return;
+
+ wp_check_mysql_version();
+ wp_cache_flush();
+ make_db_current_silent();
+ upgrade_all();
+ wp_cache_flush();
+}
+endif;
+
+// Functions to be called in install and upgrade scripts
+function upgrade_all() {
+ global $wp_current_db_version, $wp_db_version, $wp_rewrite;
+ $wp_current_db_version = __get_option('db_version');
+
+ // We are up-to-date. Nothing to do.
+ if ( $wp_db_version == $wp_current_db_version )
+ return;
+
+ // If the version is not set in the DB, try to guess the version.
+ if ( empty($wp_current_db_version) ) {
+ $wp_current_db_version = 0;
+
+ // If the template option exists, we have 1.5.
+ $template = __get_option('template');
+ if ( !empty($template) )
+ $wp_current_db_version = 2541;
+ }
+
+ if ( $wp_current_db_version < 6039 )
+ upgrade_230_options_table();
+
+ populate_options();
+
+ if ( $wp_current_db_version < 2541 ) {
+ upgrade_100();
+ upgrade_101();
+ upgrade_110();
+ upgrade_130();
+ }
+
+ if ( $wp_current_db_version < 3308 )
+ upgrade_160();
+
+ if ( $wp_current_db_version < 4772 )
+ upgrade_210();
+
+ if ( $wp_current_db_version < 4351 )
+ upgrade_old_slugs();
+
+ if ( $wp_current_db_version < 5539 )
+ upgrade_230();
+
+ if ( $wp_current_db_version < 6124 )
+ upgrade_230_old_tables();
+
+ maybe_disable_automattic_widgets();
+
+ $wp_rewrite->flush_rules();
+
+ update_option('db_version', $wp_db_version);
+}
+
+function upgrade_100() {
+ global $wpdb;
+
+ // Get the title and ID of every post, post_name to check if it already has a value
+ $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''");
+ if ($posts) {
+ foreach($posts as $post) {
+ if ('' == $post->post_name) {
+ $newtitle = sanitize_title($post->post_title);
+ $wpdb->query("UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'");
+ }
+ }
+ }
+
+ $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories");
+ foreach ($categories as $category) {
+ if ('' == $category->category_nicename) {
+ $newtitle = sanitize_title($category->cat_name);
+ $wpdb->query("UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'");
+ }
+ }
+
+
+ $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/')
+ WHERE option_name LIKE 'links_rating_image%'
+ AND option_value LIKE 'wp-links/links-images/%'");
+
+ $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat");
+ if ($done_ids) :
+ foreach ($done_ids as $done_id) :
+ $done_posts[] = $done_id->post_id;
+ endforeach;
+ $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')';
+ else:
+ $catwhere = '';
+ endif;
+
+ $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere");
+ if ($allposts) :
+ foreach ($allposts as $post) {
+ // Check to see if it's already been imported
+ $cat = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post->ID AND category_id = $post->post_category");
+ if (!$cat && 0 != $post->post_category) { // If there's no result
+ $wpdb->query("
+ INSERT INTO $wpdb->post2cat
+ (post_id, category_id)
+ VALUES
+ ('$post->ID', '$post->post_category')
+ ");
+ }
+ }
+ endif;
+}
+
+function upgrade_101() {
+ global $wpdb;
+
+ // Clean up indices, add a few
+ add_clean_index($wpdb->posts, 'post_name');
+ add_clean_index($wpdb->posts, 'post_status');
+ add_clean_index($wpdb->categories, 'category_nicename');
+ add_clean_index($wpdb->comments, 'comment_approved');
+ add_clean_index($wpdb->comments, 'comment_post_ID');
+ add_clean_index($wpdb->links , 'link_category');
+ add_clean_index($wpdb->links , 'link_visible');
+}
+
+
+function upgrade_110() {
+ global $wpdb;
+
+ // Set user_nicename.
+ $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users");
+ foreach ($users as $user) {
+ if ('' == $user->user_nicename) {
+ $newname = sanitize_title($user->user_nickname);
+ $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'");
+ }
+ }
+
+ $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users");
+ foreach ($users as $row) {
+ if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
+ $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\'');
+ }
+ }
+
+
+ // Get the GMT offset, we'll use that later on
+ $all_options = get_alloptions_110();
+
+ $time_difference = $all_options->time_difference;
+
+ $server_time = time()+date('Z');
+ $weblogger_time = $server_time + $time_difference*3600;
+ $gmt_time = time();
+
+ $diff_gmt_server = ($gmt_time - $server_time) / 3600;
+ $diff_weblogger_server = ($weblogger_time - $server_time) / 3600;
+ $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server;
+ $gmt_offset = -$diff_gmt_weblogger;
+
+ // Add a gmt_offset option, with value $gmt_offset
+ add_option('gmt_offset', $gmt_offset);
+
+ // Check if we already set the GMT fields (if we did, then
+ // MAX(post_date_gmt) can't be '0000-00-00 00:00:00'
+ // <michel_v> I just slapped myself silly for not thinking about it earlier
+ $got_gmt_fields = ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00') ? false : true;
+
+ if (!$got_gmt_fields) {
+
+ // Add or substract time to all dates, to get GMT dates
+ $add_hours = intval($diff_gmt_weblogger);
+ $add_minutes = intval(60 * ($diff_gmt_weblogger - $add_hours));
+ $wpdb->query("UPDATE $wpdb->posts SET post_date_gmt = DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
+ $wpdb->query("UPDATE $wpdb->posts SET post_modified = post_date");
+ $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'");
+ $wpdb->query("UPDATE $wpdb->comments SET comment_date_gmt = DATE_ADD(comment_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
+ $wpdb->query("UPDATE $wpdb->users SET user_registered = DATE_ADD(user_registered, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)");
+ }
+
+}
+
+function upgrade_130() {
+ global $wpdb;
+
+ // Remove extraneous backslashes.
+ $posts = $wpdb->get_results("SELECT ID, post_title, post_content, post_excerpt, guid, post_date, post_name, post_status, post_author FROM $wpdb->posts");
+ if ($posts) {
+ foreach($posts as $post) {
+ $post_content = addslashes(deslash($post->post_content));
+ $post_title = addslashes(deslash($post->post_title));
+ $post_excerpt = addslashes(deslash($post->post_excerpt));
+ if ( empty($post->guid) )
+ $guid = get_permalink($post->ID);
+ else
+ $guid = $post->guid;
+
+ $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'");
+ }
+ }
+
+ // Remove extraneous backslashes.
+ $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_content FROM $wpdb->comments");
+ if ($comments) {
+ foreach($comments as $comment) {
+ $comment_content = addslashes(deslash($comment->comment_content));
+ $comment_author = addslashes(deslash($comment->comment_author));
+ $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
+ }
+ }
+
+ // Remove extraneous backslashes.
+ $links = $wpdb->get_results("SELECT link_id, link_name, link_description FROM $wpdb->links");
+ if ($links) {
+ foreach($links as $link) {
+ $link_name = addslashes(deslash($link->link_name));
+ $link_description = addslashes(deslash($link->link_description));
+ $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
+ }
+ }
+
+ // The "paged" option for what_to_show is no more.
+ if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
+ $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
+ }
+
+ $active_plugins = __get_option('active_plugins');
+
+ // If plugins are not stored in an array, they're stored in the old
+ // newline separated format. Convert to new format.
+ if ( !is_array( $active_plugins ) ) {
+ $active_plugins = explode("\n", trim($active_plugins));
+ update_option('active_plugins', $active_plugins);
+ }
+
+ // Obsolete tables
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues');
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes');
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups');
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options');
+
+ // Update comments table to use comment_type
+ $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'");
+ $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '<pingback />', '') WHERE comment_content LIKE '<pingback />%'");
+
+ // Some versions have multiple duplicate option_name rows with the same values
+ $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name");
+ foreach ( $options as $option ) {
+ if ( 1 != $option->dupes ) { // Could this be done in the query?
+ $limit = $option->dupes - 1;
+ $dupe_ids = $wpdb->get_col("SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit");
+ $dupe_ids = join($dupe_ids, ',');
+ $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)");
+ }
+ }
+
+ make_site_theme();
+}
+
+function upgrade_160_helper( $users ) {
+ global $wpdb;
+
+ populate_roles_160();
+
+ foreach ( $users as $user_details ) :
+ $user = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID = '" . $user_details[ 'user_id' ] . "'");
+ if ( !empty( $user->user_firstname ) )
+ update_usermeta( $user->ID, 'first_name', $wpdb->escape($user->user_firstname) );
+ if ( !empty( $user->user_lastname ) )
+ update_usermeta( $user->ID, 'last_name', $wpdb->escape($user->user_lastname) );
+ if ( !empty( $user->user_nickname ) )
+ update_usermeta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) );
+ if ( !empty( $user->user_level ) )
+ update_usermeta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level );
+ if ( !empty( $user->user_icq ) )
+ update_usermeta( $user->ID, 'icq', $wpdb->escape($user->user_icq) );
+ if ( !empty( $user->user_aim ) )
+ update_usermeta( $user->ID, 'aim', $wpdb->escape($user->user_aim) );
+ if ( !empty( $user->user_msn ) )
+ update_usermeta( $user->ID, 'msn', $wpdb->escape($user->user_msn) );
+ if ( !empty( $user->user_yim ) )
+ update_usermeta( $user->ID, 'yim', $wpdb->escape($user->user_icq) );
+ if ( !empty( $user->user_description ) )
+ update_usermeta( $user->ID, 'description', $wpdb->escape($user->user_description) );
+
+ if ( isset( $user->user_idmode ) ):
+ $idmode = $user->user_idmode;
+ if ($idmode == 'nickname') $id = $user->user_nickname;
+ if ($idmode == 'login') $id = $user->user_login;
+ if ($idmode == 'firstname') $id = $user->user_firstname;
+ if ($idmode == 'lastname') $id = $user->user_lastname;
+ if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname;
+ if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
+ if (!$idmode) $id = $user->user_nickname;
+ $id = $wpdb->escape( $id );
+ $wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'");
+ endif;
+
+ // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set.
+ $caps = get_usermeta( $user->ID, $wpdb->prefix . 'capabilities');
+ if ( empty($caps) || defined('RESET_CAPS') ) {
+ $level = get_usermeta($user->ID, $wpdb->prefix . 'user_level');
+ $role = translate_level_to_role($level);
+ update_usermeta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) );
+ }
+
+ endforeach;
+}
+
+function upgrade_160() {
+ global $wpdb, $table_prefix, $wp_current_db_version;
+ $users = $wpdb->get_results("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$table_prefix}capabilities'", ARRAY_A);
+ upgrade_160_helper( $users );
+ $users = $wpdb->get_results("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '{$table_prefix}user_level'", ARRAY_A);
+ upgrade_160_helper( $users );
+ $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' );
+ $wpdb->hide_errors();
+ foreach ( $old_user_fields as $old )
+ $wpdb->query("ALTER TABLE $wpdb->users DROP $old");
+ $wpdb->show_errors();
+
+ // populate comment_count field of posts table
+ $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
+ if( is_array( $comments ) ) {
+ foreach ($comments as $comment) {
+ $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID'" );
+ }
+ }
+
+ // Some alpha versions used a post status of object instead of attachment and put
+ // the mime type in post_type instead of post_mime_type.
+ if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {
+ $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
+ foreach ($objects as $object) {
+ $wpdb->query("UPDATE $wpdb->posts SET post_status = 'attachment',
+ post_mime_type = '$object->post_type',
+ post_type = ''
+ WHERE ID = $object->ID");
+
+ $meta = get_post_meta($object->ID, 'imagedata', true);
+ if ( ! empty($meta['file']) )
+ update_attached_file( $object->ID, $meta['file'] );
+ }
+ }
+}
+
+function upgrade_210() {
+ global $wpdb, $wp_current_db_version;
+
+ if ( $wp_current_db_version < 3506 ) {
+ // Update status and type.
+ $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts");
+
+ if ( ! empty($posts) ) foreach ($posts as $post) {
+ $status = $post->post_status;
+ $type = 'post';
+
+ if ( 'static' == $status ) {
+ $status = 'publish';
+ $type = 'page';
+ } else if ( 'attachment' == $status ) {
+ $status = 'inherit';
+ $type = 'attachment';
+ }
+
+ $wpdb->query("UPDATE $wpdb->posts SET post_status = '$status', post_type = '$type' WHERE ID = '$post->ID'");
+ }
+ }
+
+ if ( $wp_current_db_version < 3845 ) {
+ populate_roles_210();
+ }
+
+ if ( $wp_current_db_version < 3531 ) {
+ // Give future posts a post_status of future.
+ $now = gmdate('Y-m-d H:i:59');
+ $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'");
+
+ $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'");
+ if ( !empty($posts) )
+ foreach ( $posts as $post )
+ wp_schedule_single_event(mysql2date('U', $post->post_date), 'publish_future_post', array($post->ID));
+ }
+}
+
+function upgrade_230() {
+ global $wp_current_db_version, $wpdb;
+
+ if ( $wp_current_db_version < 5200 ) {
+ populate_roles_230();
+ }
+
+ // Convert categories to terms.
+ $tt_ids = array();
+ $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID");
+ foreach ($categories as $category) {
+ $term_id = (int) $category->cat_ID;
+ $name = $wpdb->escape($category->cat_name);
+ $description = $wpdb->escape($category->category_description);
+ $slug = $wpdb->escape($category->category_nicename);
+ $parent = $wpdb->escape($category->category_parent);
+ $term_group = 0;
+
+ // Associate terms with the same slug in a term group and make slugs unique.
+ if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) {
+ $term_group = $exists[0]->term_group;
+ $id = $exists[0]->term_id;
+ $num = 2;
+ do {
+ $alt_slug = $slug . "-$num";
+ $num++;
+ $slug_check = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE slug = '$alt_slug'");
+ } while ( $slug_check );
+
+ $slug = $alt_slug;
+
+ if ( empty( $term_group ) ) {
+ $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1;
+ $wpdb->query("UPDATE $wpdb->terms SET term_group = '$term_group' WHERE term_id = '$id'");
+ }
+ }
+
+ $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')");
+
+ $count = 0;
+ if ( !empty($category->category_count) ) {
+ $count = (int) $category->category_count;
+ $taxonomy = 'category';
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");
+ $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
+ }
+
+ if ( !empty($category->link_count) ) {
+ $count = (int) $category->link_count;
+ $taxonomy = 'link_category';
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");
+ $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
+ }
+
+ if ( !empty($category->tag_count) ) {
+ $count = (int) $category->tag_count;
+ $taxonomy = 'post_tag';
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");
+ $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
+ }
+
+ if ( empty($count) ) {
+ $count = 0;
+ $taxonomy = 'category';
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");
+ $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
+ }
+ }
+
+ $posts = $wpdb->get_results("SELECT * FROM $wpdb->post2cat");
+ foreach ( $posts as $post ) {
+ $post_id = (int) $post->post_id;
+ $term_id = (int) $post->category_id;
+ $taxonomy = 'category';
+ if ( !empty($post->rel_type) && 'tag' == $post->rel_type)
+ $taxonomy = 'tag';
+ $tt_id = $tt_ids[$term_id][$taxonomy];
+ if ( empty($tt_id) )
+ continue;
+
+ $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')");
+ }
+
+ // < 3570 we used linkcategories. >= 3570 we used categories and link2cat.
+ if ( $wp_current_db_version < 3570 ) {
+ // Create link_category terms for link categories. Create a map of link cat IDs
+ // to link_category terms.
+ $link_cat_id_map = array();
+ $default_link_cat = 0;
+ $tt_ids = array();
+ $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories');
+ foreach ( $link_cats as $category) {
+ $cat_id = (int) $category->cat_id;
+ $term_id = 0;
+ $name = $wpdb->escape($category->cat_name);
+ $slug = sanitize_title($name);
+ $term_group = 0;
+
+ // Associate terms with the same slug in a term group and make slugs unique.
+ if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) {
+ $term_group = $exists[0]->term_group;
+ $term_id = $exists[0]->term_id;
+ }
+
+ if ( empty($term_id) ) {
+ $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')");
+ $term_id = (int) $wpdb->insert_id;
+ }
+
+ $link_cat_id_map[$cat_id] = $term_id;
+ $default_link_cat = $term_id;
+
+ $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', 'link_category', '', '0', '0')");
+ $tt_ids[$term_id] = (int) $wpdb->insert_id;
+ }
+
+ // Associate links to cats.
+ $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links");
+ if ( !empty($links) ) foreach ( $links as $link ) {
+ if ( 0 == $link->link_category )
+ continue;
+ if ( ! isset($link_cat_id_map[$link->link_category]) )
+ continue;
+ $term_id = $link_cat_id_map[$link->link_category];
+ $tt_id = $tt_ids[$term_id];
+ if ( empty($tt_id) )
+ continue;
+
+ $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link->link_id', '$tt_id')");
+ }
+
+ // Set default to the last category we grabbed during the upgrade loop.
+ update_option('default_link_category', $default_link_cat);
+ } else {
+ $links = $wpdb->get_results("SELECT * FROM $wpdb->link2cat");
+ foreach ( $links as $link ) {
+ $link_id = (int) $link->link_id;
+ $term_id = (int) $link->category_id;
+ $taxonomy = 'link_category';
+ $tt_id = $tt_ids[$term_id][$taxonomy];
+ if ( empty($tt_id) )
+ continue;
+
+ $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link_id', '$tt_id')");
+ }
+ }
+
+ if ( $wp_current_db_version < 4772 ) {
+ // Obsolete linkcategories table
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories');
+ }
+
+ // Recalculate all counts
+ $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy");
+ foreach ( (array) $terms as $term ) {
+ if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) )
+ $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = '$term->term_taxonomy_id'");
+ else
+ $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term->term_taxonomy_id'");
+ $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term->term_taxonomy_id'");
+ }
+}
+
+function upgrade_230_options_table() {
+ global $wpdb;
+ $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' );
+ $wpdb->hide_errors();
+ foreach ( $old_options_fields as $old )
+ $wpdb->query("ALTER TABLE $wpdb->options DROP $old");
+ $wpdb->show_errors();
+}
+
+function upgrade_230_old_tables() {
+ global $wpdb;
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories');
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat');
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat');
+}
+
+function upgrade_old_slugs() {
+ // upgrade people who were using the Redirect Old Slugs plugin
+ global $wpdb;
+ $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'");
+}
+
+
+// The functions we use to actually do stuff
+
+// General
+function maybe_create_table($table_name, $create_ddl) {
+ global $wpdb;
+ foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
+ if ($table == $table_name) {
+ return true;
+ }
+ }
+ //didn't find it try to create it.
+ $q = $wpdb->query($create_ddl);
+ // we cannot directly tell that whether this succeeded!
+ foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) {
+ if ($table == $table_name) {
+ return true;
+ }
+ }
+ return false;
+}
+
+function drop_index($table, $index) {
+ global $wpdb;
+ $wpdb->hide_errors();
+ $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`");
+ // Now we need to take out all the extra ones we may have created
+ for ($i = 0; $i < 25; $i++) {
+ $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`");
+ }
+ $wpdb->show_errors();
+ return true;
+}
+
+function add_clean_index($table, $index) {
+ global $wpdb;
+ drop_index($table, $index);
+ $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )");
+ return true;
+}
+
+/**
+ ** maybe_add_column()
+ ** Add column to db table if it doesn't exist.
+ ** Returns: true if already exists or on successful completion
+ ** false on error
+ */
+function maybe_add_column($table_name, $column_name, $create_ddl) {
+ global $wpdb, $debug;
+ foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
+ if ($debug) echo("checking $column == $column_name<br />");
+ if ($column == $column_name) {
+ return true;
+ }
+ }
+ //didn't find it try to create it.
+ $q = $wpdb->query($create_ddl);
+ // we cannot directly tell that whether this succeeded!
+ foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
+ if ($column == $column_name) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+// get_alloptions as it was for 1.2.
+function get_alloptions_110() {
+ global $wpdb;
+ if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) {
+ foreach ($options as $option) {
+ // "When trying to design a foolproof system,
+ // never underestimate the ingenuity of the fools :)" -- Dougal
+ if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
+ if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
+ if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
+ $all_options->{$option->option_name} = stripslashes($option->option_value);
+ }
+ }
+ return $all_options;
+}
+
+// Version of get_option that is private to install/upgrade.
+function __get_option($setting) {
+ global $wpdb;
+
+ if ( $setting == 'home' && defined( 'WP_HOME' ) ) {
+ return preg_replace( '|/+$|', '', constant( 'WP_HOME' ) );
+ }
+
+ if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) {
+ return preg_replace( '|/+$|', '', constant( 'WP_SITEURL' ) );
+ }
+
+ $option = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'");
+
+ if ( 'home' == $setting && '' == $option )
+ return __get_option('siteurl');
+
+ if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
+ $option = preg_replace('|/+$|', '', $option);
+
+ @ $kellogs = unserialize($option);
+ if ($kellogs !== FALSE)
+ return $kellogs;
+ else
+ return $option;
+}
+
+function deslash($content) {
+ // Note: \\\ inside a regex denotes a single backslash.
+
+ // Replace one or more backslashes followed by a single quote with
+ // a single quote.
+ $content = preg_replace("/\\\+'/", "'", $content);
+
+ // Replace one or more backslashes followed by a double quote with
+ // a double quote.
+ $content = preg_replace('/\\\+"/', '"', $content);
+
+ // Replace one or more backslashes with one backslash.
+ $content = preg_replace("/\\\+/", "\\", $content);
+
+ return $content;
+}
+
+function dbDelta($queries, $execute = true) {
+ global $wpdb;
+
+ // Seperate individual queries into an array
+ if( !is_array($queries) ) {
+ $queries = explode( ';', $queries );
+ if('' == $queries[count($queries) - 1]) array_pop($queries);
+ }
+
+ $cqueries = array(); // Creation Queries
+ $iqueries = array(); // Insertion Queries
+ $for_update = array();
+
+ // Create a tablename index for an array ($cqueries) of queries
+ foreach($queries as $qry) {
+ if(preg_match("|CREATE TABLE (?:IF NOT EXISTS )?([^ ]*)|", $qry, $matches)) {
+ $cqueries[strtolower($matches[1])] = $qry;
+ $for_update[$matches[1]] = 'Created table '.$matches[1];
+ }
+ else if(preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
+ array_unshift($cqueries, $qry);
+ }
+ else if(preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
+ $iqueries[] = $qry;
+ }
+ else if(preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
+ $iqueries[] = $qry;
+ }
+ else {
+ // Unrecognized query type
+ }
+ }
+
+ // Check to see which tables and fields exist
+ if($tables = $wpdb->get_col('SHOW TABLES;')) {
+ // For every table in the database
+ foreach($tables as $table) {
+ // If a table query exists for the database table...
+ if( array_key_exists(strtolower($table), $cqueries) ) {
+ // Clear the field and index arrays
+ unset($cfields);
+ unset($indices);
+ // Get all of the field names in the query from between the parens
+ preg_match("|\((.*)\)|ms", $cqueries[strtolower($table)], $match2);
+ $qryline = trim($match2[1]);
+
+ // Separate field lines into an array
+ $flds = explode("\n", $qryline);
+
+ //echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
+
+ // For every field line specified in the query
+ foreach($flds as $fld) {
+ // Extract the field name
+ preg_match("|^([^ ]*)|", trim($fld), $fvals);
+ $fieldname = $fvals[1];
+
+ // Verify the found field name
+ $validfield = true;
+ switch(strtolower($fieldname))
+ {
+ case '':
+ case 'primary':
+ case 'index':
+ case 'fulltext':
+ case 'unique':
+ case 'key':
+ $validfield = false;
+ $indices[] = trim(trim($fld), ", \n");
+ break;
+ }
+ $fld = trim($fld);
+
+ // If it's a valid field, add it to the field array
+ if($validfield) {
+ $cfields[strtolower($fieldname)] = trim($fld, ", \n");
+ }
+ }
+
+ // Fetch the table column structure from the database
+ $tablefields = $wpdb->get_results("DESCRIBE {$table};");
+
+ // For every field in the table
+ foreach($tablefields as $tablefield) {
+ // If the table field exists in the field array...
+ if(array_key_exists(strtolower($tablefield->Field), $cfields)) {
+ // Get the field type from the query
+ preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[strtolower($tablefield->Field)], $matches);
+ $fieldtype = $matches[1];
+
+ // Is actual field type different from the field type in query?
+ if($tablefield->Type != $fieldtype) {
+ // Add a query to change the column type
+ $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN {$tablefield->Field} " . $cfields[strtolower($tablefield->Field)];
+ $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}";
+ }
+
+ // Get the default value from the array
+ //echo "{$cfields[strtolower($tablefield->Field)]}<br>";
+ if(preg_match("| DEFAULT '(.*)'|i", $cfields[strtolower($tablefield->Field)], $matches)) {
+ $default_value = $matches[1];
+ if($tablefield->Default != $default_value)
+ {
+ // Add a query to change the column's default value
+ $cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->Field} SET DEFAULT '{$default_value}'";
+ $for_update[$table.'.'.$tablefield->Field] = "Changed default value of {$table}.{$tablefield->Field} from {$tablefield->Default} to {$default_value}";
+ }
+ }
+
+ // Remove the field from the array (so it's not added)
+ unset($cfields[strtolower($tablefield->Field)]);
+ }
+ else {
+ // This field exists in the table, but not in the creation queries?
+ }
+ }
+
+ // For every remaining field specified for the table
+ foreach($cfields as $fieldname => $fielddef) {
+ // Push a query line into $cqueries that adds the field to that table
+ $cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
+ $for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
+ }
+
+ // Index stuff goes here
+ // Fetch the table index structure from the database
+ $tableindices = $wpdb->get_results("SHOW INDEX FROM {$table};");
+
+ if($tableindices) {
+ // Clear the index array
+ unset($index_ary);
+
+ // For every index in the table
+ foreach($tableindices as $tableindex) {
+ // Add the index to the index data array
+ $keyname = $tableindex->Key_name;
+ $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part);
+ $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false;
+ }
+
+ // For each actual index in the index array
+ foreach($index_ary as $index_name => $index_data) {
+ // Build a create string to compare to the query
+ $index_string = '';
+ if($index_name == 'PRIMARY') {
+ $index_string .= 'PRIMARY ';
+ }
+ else if($index_data['unique']) {
+ $index_string .= 'UNIQUE ';
+ }
+ $index_string .= 'KEY ';
+ if($index_name != 'PRIMARY') {
+ $index_string .= $index_name;
+ }
+ $index_columns = '';
+ // For each column in the index
+ foreach($index_data['columns'] as $column_data) {
+ if($index_columns != '') $index_columns .= ',';
+ // Add the field to the column list string
+ $index_columns .= $column_data['fieldname'];
+ if($column_data['subpart'] != '') {
+ $index_columns .= '('.$column_data['subpart'].')';
+ }
+ }
+ // Add the column list to the index create string
+ $index_string .= ' ('.$index_columns.')';
+ error_log("Index string: $index_string", 0);
+ if(!(($aindex = array_search($index_string, $indices)) === false)) {
+ unset($indices[$aindex]);
+ //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">{$table}:<br />Found index:".$index_string."</pre>\n";
+ }
+ //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";
+ }
+ }
+
+ // For every remaining index specified for the table
+ foreach ( (array) $indices as $index ) {
+ // Push a query line into $cqueries that adds the index to that table
+ $cqueries[] = "ALTER TABLE {$table} ADD $index";
+ $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index;
+ }
+
+ // Remove the original table creation query from processing
+ unset($cqueries[strtolower($table)]);
+ unset($for_update[strtolower($table)]);
+ } else {
+ // This table exists in the database, but not in the creation queries?
+ }
+ }
+ }
+
+ $allqueries = array_merge($cqueries, $iqueries);
+ if($execute) {
+ foreach($allqueries as $query) {
+ //echo "<pre style=\"border:1px solid #ccc;margin-top:5px;\">".print_r($query, true)."</pre>\n";
+ $wpdb->query($query);
+ }
+ }
+
+ return $for_update;
+}
+
+function make_db_current() {
+ global $wp_queries;
+
+ $alterations = dbDelta($wp_queries);
+ echo "<ol>\n";
+ foreach($alterations as $alteration) echo "<li>$alteration</li>\n";
+ echo "</ol>\n";
+}
+
+function make_db_current_silent() {
+ global $wp_queries;
+
+ $alterations = dbDelta($wp_queries);
+}
+
+function make_site_theme_from_oldschool($theme_name, $template) {
+ $home_path = get_home_path();
+ $site_dir = ABSPATH . "wp-content/themes/$template";
+
+ if (! file_exists("$home_path/index.php"))
+ return false;
+
+ // Copy files from the old locations to the site theme.
+ // TODO: This does not copy arbitarary include dependencies. Only the
+ // standard WP files are copied.
+ $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php');
+
+ foreach ($files as $oldfile => $newfile) {
+ if ($oldfile == 'index.php')
+ $oldpath = $home_path;
+ else
+ $oldpath = ABSPATH;
+
+ if ($oldfile == 'index.php') { // Check to make sure it's not a new index
+ $index = implode('', file("$oldpath/$oldfile"));
+ if (strpos($index, 'WP_USE_THEMES') !== false) {
+ if (! @copy(ABSPATH . 'wp-content/themes/default/index.php', "$site_dir/$newfile"))
+ return false;
+ continue; // Don't copy anything
+ }
+ }
+
+ if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile"))
+ return false;
+
+ chmod("$site_dir/$newfile", 0777);
+
+ // Update the blog header include in each file.
+ $lines = explode("\n", implode('', file("$site_dir/$newfile")));
+ if ($lines) {
+ $f = fopen("$site_dir/$newfile", 'w');
+
+ foreach ($lines as $line) {
+ if (preg_match('/require.*wp-blog-header/', $line))
+ $line = '//' . $line;
+
+ // Update stylesheet references.
+ $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line);
+
+ // Update comments template inclusion.
+ $line = str_replace("<?php include(ABSPATH . 'wp-comments.php'); ?>", "<?php comments_template(); ?>", $line);
+
+ fwrite($f, "{$line}\n");
+ }
+ fclose($f);
+ }
+ }
+
+ // Add a theme header.
+ $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";
+
+ $stylelines = file_get_contents("$site_dir/style.css");
+ if ($stylelines) {
+ $f = fopen("$site_dir/style.css", 'w');
+
+ fwrite($f, $header);
+ fwrite($f, $stylelines);
+ fclose($f);
+ }
+
+ return true;
+}
+
+function make_site_theme_from_default($theme_name, $template) {
+ $site_dir = ABSPATH . "wp-content/themes/$template";
+ $default_dir = ABSPATH . 'wp-content/themes/default';
+
+ // Copy files from the default theme to the site theme.
+ //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
+
+ $theme_dir = @ opendir("$default_dir");
+ if ($theme_dir) {
+ while(($theme_file = readdir( $theme_dir )) !== false) {
+ if (is_dir("$default_dir/$theme_file"))
+ continue;
+ if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file"))
+ return;
+ chmod("$site_dir/$theme_file", 0777);
+ }
+ }
+ @closedir($theme_dir);
+
+ // Rewrite the theme header.
+ $stylelines = explode("\n", implode('', file("$site_dir/style.css")));
+ if ($stylelines) {
+ $f = fopen("$site_dir/style.css", 'w');
+
+ foreach ($stylelines as $line) {
+ if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name;
+ elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url');
+ elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.';
+ elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1';
+ elseif (strpos($line, 'Author:') !== false) $line = 'Author: You';
+ fwrite($f, $line . "\n");
+ }
+ fclose($f);
+ }
+
+ // Copy the images.
+ umask(0);
+ if (! mkdir("$site_dir/images", 0777)) {
+ return false;
+ }
+
+ $images_dir = @ opendir("$default_dir/images");
+ if ($images_dir) {
+ while(($image = readdir($images_dir)) !== false) {
+ if (is_dir("$default_dir/images/$image"))
+ continue;
+ if (! @copy("$default_dir/images/$image", "$site_dir/images/$image"))
+ return;
+ chmod("$site_dir/images/$image", 0777);
+ }
+ }
+ @closedir($images_dir);
+}
+
+// Create a site theme from the default theme.
+function make_site_theme() {
+ return true;
+ // Name the theme after the blog.
+ $theme_name = __get_option('blogname');
+ $template = sanitize_title($theme_name);
+ $site_dir = ABSPATH . "wp-content/themes/$template";
+
+ // If the theme already exists, nothing to do.
+ if ( is_dir($site_dir)) {
+ return false;
+ }
+
+ // We must be able to write to the themes dir.
+ if (! is_writable(ABSPATH . "wp-content/themes")) {
+ return false;
+ }
+
+ umask(0);
+ if (! mkdir($site_dir, 0777)) {
+ return false;
+ }
+
+ if (file_exists(ABSPATH . 'wp-layout.css')) {
+ if (! make_site_theme_from_oldschool($theme_name, $template)) {
+ // TODO: rm -rf the site theme directory.
+ return false;
+ }
+ } else {
+ if (! make_site_theme_from_default($theme_name, $template))
+ // TODO: rm -rf the site theme directory.
+ return false;
+ }
+
+ // Make the new site theme active.
+ $current_template = __get_option('template');
+ if ($current_template == 'default') {
+ update_option('template', $template);
+ update_option('stylesheet', $template);
+ }
+ return $template;
+}
+
+function translate_level_to_role($level) {
+ switch ($level) {
+ case 10:
+ case 9:
+ case 8:
+ return 'administrator';
+ case 7:
+ case 6:
+ case 5:
+ return 'editor';
+ case 4:
+ case 3:
+ case 2:
+ return 'author';
+ case 1:
+ return 'contributor';
+ case 0:
+ return 'subscriber';
+ }
+}
+
+function wp_check_mysql_version() {
+ global $wp_version;
+
+ // Make sure the server has MySQL 4.0
+ $mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info());
+ if ( version_compare($mysql_version, '4.0.0', '<') )
+ die(sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
+}
+
+function maybe_disable_automattic_widgets() {
+ $plugins = __get_option( 'active_plugins' );
+
+ foreach ( (array) $plugins as $plugin ) {
+ if ( basename( $plugin ) == 'widgets.php' ) {
+ array_splice( $plugins, array_search( $plugin, $plugins ), 1 );
+ update_option( 'active_plugins', $plugins );
+ break;
+ }
+ }
+}
+
+?>
diff --git a/wp-admin/includes/upload.php b/wp-admin/includes/upload.php
new file mode 100644
index 0000000..61b042b
--- /dev/null
+++ b/wp-admin/includes/upload.php
@@ -0,0 +1,381 @@
+<?php
+
+function wp_upload_display( $dims = false, $href = '' ) {
+ global $post;
+ $id = get_the_ID();
+ $attachment_data = wp_get_attachment_metadata( $id );
+ $is_image = (int) wp_attachment_is_image();
+ $filesystem_path = get_attached_file( $id );
+ if ( !isset($attachment_data['width']) && $is_image ) {
+ if ( $image_data = getimagesize( $filesystem_path ) ) {
+ $attachment_data['width'] = $image_data[0];
+ $attachment_data['height'] = $image_data[1];
+ wp_update_attachment_metadata( $id, $attachment_data );
+ }
+ }
+ if ( isset($attachment_data['width']) )
+ list($width,$height) = wp_shrink_dimensions($attachment_data['width'], $attachment_data['height'], 171, 128);
+
+ $post_title = attribute_escape( the_title( '', '', false ) );
+ $post_content = attribute_escape(apply_filters( 'content_edit_pre', $post->post_content ));
+
+ $class = 'text';
+ $innerHTML = get_attachment_innerHTML( $id, false, $dims );
+ if ( $image_src = get_attachment_icon_src() ) {
+ $image_rel = wp_make_link_relative($image_src);
+ $innerHTML = '&nbsp;' . str_replace($image_src, $image_rel, $innerHTML);
+ $class = 'image';
+ }
+
+ $src_base = wp_get_attachment_url();
+ $src = wp_make_link_relative( $src_base );
+ $src_base = str_replace($src, '', $src_base);
+
+ $r = '';
+
+ if ( $href )
+ $r .= "<a id='file-link-$id' href='$href' title='$post_title' class='file-link $class'>\n";
+ if ( $href || $image_src )
+ $r .= "\t\t\t$innerHTML";
+ if ( $href )
+ $r .= "</a>\n";
+ $r .= "\t\t\t\t<span class='upload-file-size'>".size_format(filesize($filesystem_path))."</span>\n";
+ $r .= "\n\t\t<div class='upload-file-data'>\n\t\t\t<p>\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-url-$id' id='attachment-url-$id' value='$src' />\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-url-base-$id' id='attachment-url-base-$id' value='$src_base' />\n";
+
+ if ( !$thumb_base = wp_get_attachment_thumb_url() )
+ $thumb_base = wp_mime_type_icon();
+ if ( $thumb_base ) {
+ $thumb_rel = wp_make_link_relative( $thumb_base );
+ $thumb_base = str_replace( $thumb_rel, '', $thumb_base );
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-$id' id='attachment-thumb-url-$id' value='$thumb_rel' />\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-thumb-url-base-$id' id='attachment-thumb-url-base-$id' value='$thumb_base' />\n";
+ }
+
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-is-image-$id' id='attachment-is-image-$id' value='$is_image' />\n";
+
+ if ( isset($width) ) {
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-width-$id' id='attachment-width-$id' value='$width' />\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-height-$id' id='attachment-height-$id' value='$height' />\n";
+ }
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-page-url-$id' id='attachment-page-url-$id' value='" . get_attachment_link( $id ) . "' />\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-title-$id' id='attachment-title-$id' value='$post_title' />\n";
+ $r .= "\t\t\t\t<input type='hidden' name='attachment-description-$id' id='attachment-description-$id' value='$post_content' />\n";
+ $r .= "\t\t\t</p>\n\t\t</div>\n";
+ return $r;
+}
+
+function wp_upload_view() {
+ global $style, $post_id, $style;
+ $id = get_the_ID();
+ $attachment_data = wp_get_attachment_metadata( $id );
+?>
+ <div id="upload-file">
+ <div id="file-title">
+ <h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
+ echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
+ the_title();
+ if ( !isset($attachment_data['width']) && 'inline' != $style )
+ echo '</a>';
+ ?></h2>
+ <span><?php
+ echo '[&nbsp;';
+ echo '<a href="' . get_permalink() . '">' . __('view') . '</a>';
+ echo '&nbsp;|&nbsp;';
+ echo '<a href="' . clean_url(add_query_arg('action', 'edit')) . '" title="' . __('Edit this file') . '">' . __('edit') . '</a>';
+ echo '&nbsp;|&nbsp;';
+ echo '<a href="' . clean_url(remove_query_arg(array('action', 'ID'))) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
+ echo '&nbsp;]'; ?></span>
+ </div>
+
+ <div id="upload-file-view" class="alignleft">
+<?php if ( isset($attachment_data['width']) && 'inline' != $style )
+ echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
+ echo wp_upload_display( array(171, 128) );
+ if ( isset($attachment_data['width']) && 'inline' != $style )
+ echo '</a>'; ?>
+ </div>
+ <?php the_attachment_links( $id ); ?>
+ </div>
+<?php echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce( 'inlineuploading' ) . "' /></form>\n";
+}
+
+function wp_upload_form() {
+ $id = get_the_ID();
+ global $post_id, $tab, $style;
+ $enctype = $id ? '' : ' enctype="multipart/form-data"';
+ $post_id = (int) $post_id;
+?>
+ <form<?php echo $enctype; ?> id="upload-file" method="post" action="<?php echo get_option('siteurl') . '/wp-admin/upload.php?style=' . attribute_escape($style . '&amp;tab=upload&amp;post_id=' . $post_id); ?>">
+<?php
+ if ( $id ) :
+ $attachment = get_post_to_edit( $id );
+ $attachment_data = wp_get_attachment_metadata( $id );
+?>
+ <div id="file-title">
+ <h2><?php if ( !isset($attachment_data['width']) && 'inline' != $style )
+ echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
+ the_title();
+ if ( !isset($attachment_data['width']) && 'inline' != $style )
+ echo '</a>';
+ ?></h2>
+ <span><?php
+ echo '[&nbsp;';
+ echo '<a href="' . get_permalink() . '">' . __('view') . '</a>';
+ echo '&nbsp;|&nbsp;';
+ echo '<a href="' . clean_url(add_query_arg('action', 'view')) . '">' . __('links') . '</a>';
+ echo '&nbsp;|&nbsp;';
+ echo '<a href="' . clean_url(remove_query_arg(array('action','ID'))) . '" title="' . __('Browse your files') . '">' . __('cancel') . '</a>';
+ echo '&nbsp;]'; ?></span>
+ </div>
+
+ <div id="upload-file-view" class="alignleft">
+<?php if ( isset($attachment_data['width']) && 'inline' != $style )
+ echo "<a href='" . wp_get_attachment_url() . "' title='" . __('Direct link to file') . "'>";
+ echo wp_upload_display( array(171, 128) );
+ if ( isset($attachment_data['width']) && 'inline' != $style )
+ echo '</a>'; ?>
+ </div>
+<?php endif; ?>
+ <table><col /><col class="widefat" />
+<?php if ( $id ): ?>
+ <tr>
+ <th scope="row"><label for="url"><?php _e('URL'); ?></label></th>
+ <td><input type="text" id="url" class="readonly" value="<?php echo wp_get_attachment_url(); ?>" readonly="readonly" /></td>
+ </tr>
+<?php else : ?>
+ <tr>
+ <th scope="row"><label for="upload"><?php _e('File'); ?></label></th>
+ <td><input type="file" id="upload" name="image" /></td>
+ </tr>
+<?php endif; ?>
+ <tr>
+ <th scope="row"><label for="post_title"><?php _e('Title'); ?></label></th>
+ <td><input type="text" id="post_title" name="post_title" value="<?php echo $attachment->post_title; ?>" /></td>
+ </tr>
+ <tr>
+ <th scope="row"><label for="post_content"><?php _e('Description'); ?></label></th>
+ <td><textarea name="post_content" id="post_content"><?php echo $attachment->post_content; ?></textarea></td>
+ </tr>
+ <tr id="buttons" class="submit">
+ <td colspan='2'>
+<?php if ( $id ) : ?>
+ <input type="submit" name="delete" id="delete" class="delete alignleft" value="<?php _e('Delete File'); ?>" />
+<?php else : ?>
+ <p class="alignleft" style="margin:.25em 0; padding: 4px 0;"><?php display_space_usage(); ?></p>
+<?php endif; ?>
+ <input type="hidden" name="from_tab" value="<?php echo $tab; ?>" />
+ <input type="hidden" name="action" value="<?php echo $id ? 'save' : 'upload'; ?>" />
+<?php if ( $post_id ) : ?>
+ <input type="hidden" name="post_id" value="<?php echo $post_id; ?>" />
+<?php endif; if ( $id ) : ?>
+ <input type="hidden" name="ID" value="<?php echo $id; ?>" />
+<?php endif; ?>
+ <?php wp_nonce_field( 'inlineuploading' ); ?>
+ <div class="submit">
+ <input type="submit" value="<?php $id ? _e('Save &raquo;') : _e('Upload &raquo;'); ?>" />
+ </div>
+ </td>
+ </tr>
+ </table>
+ </form>
+<?php
+}
+
+function display_space_usage() {
+ $space = get_space_allowed();
+ $percentused = ( intval( get_dirsize( constant( "ABSPATH" ) . constant( "UPLOADS" ) )/1024/1024 ) / $space ) * 100;
+ $buymore = '';
+ if( $space < 10000 )
+ $buymore = '<a target="_blank" title="opens in new window" href="/wp-admin/paid-upgrades.php">Buy more</a>'; // open in new window in case they have a post open
+
+ /*
+ if( $space < 10000 ) {
+ $buymore = '<a target="_blank" title="opens in new window" href="/wp-admin/paid-upgrades.php">Buy more space</a>'; // open in new window in case they have a post open
+ if( get_option( 'use_upgraded_upload_filetypes' ) != '1' ) { $buymore .= __( " and you can upload " ) . str_replace( " ", ", ", get_site_option( "upgraded_upload_filetypes" ) ) . __(" files");}
+ }
+ */
+ if( $space > 1000 ) {
+ $space = number_format( $space / 1024 );
+ $space .= "GB";
+ } else {
+ $space .= "MB";
+ }
+ ?>
+ <strong>Used: <?php echo number_format( $percentused ) ?>% of <?php echo $space . ". $buymore" ?></strong>
+ <?php
+}
+
+function wp_upload_tab_upload() {
+ wp_upload_form();
+}
+
+function wp_upload_tab_upload_action() {
+ global $action;
+ if ( isset($_POST['delete']) )
+ $action = 'delete';
+
+ switch ( $action ) :
+ case 'upload' :
+ global $from_tab, $post_id, $style;
+ if ( !$from_tab )
+ $from_tab = 'upload';
+
+ check_admin_referer( 'inlineuploading' );
+
+ global $post_id, $post_title, $post_content;
+
+ if ( !current_user_can( 'upload_files' ) )
+ wp_die( __('You are not allowed to upload files.')
+ . " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=" . attribute_escape($style . "&amp;tab=browse-all&amp;post_id=$post_id") . "'>"
+ . __('Browse Files') . '</a>'
+ );
+
+ $overrides = array('action'=>'upload');
+
+ $file = wp_handle_upload($_FILES['image'], $overrides);
+
+ if ( isset($file['error']) )
+ wp_die($file['error'] . "<br /><a href='" . get_option('siteurl')
+ . "/wp-admin/upload.php?style=" . attribute_escape($style . "&amp;tab=$from_tab&amp;post_id=$post_id") . "'>" . __('Back to Image Uploading') . '</a>'
+ );
+
+ $url = $file['url'];
+ $type = $file['type'];
+ $file = $file['file'];
+ $filename = basename($file);
+
+ // Construct the attachment array
+ $attachment = array(
+ 'post_title' => $post_title,
+ 'post_content' => $post_content,
+ 'post_type' => 'attachment',
+ 'post_parent' => $post_id,
+ 'post_mime_type' => $type,
+ 'guid' => $url
+ );
+
+ // Save the data
+ $id = wp_insert_attachment($attachment, $file, $post_id);
+
+ wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
+
+ wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id");
+ die;
+ break;
+
+ case 'save' :
+ global $from_tab, $post_id, $style;
+ if ( !$from_tab )
+ $from_tab = 'upload';
+ check_admin_referer( 'inlineuploading' );
+
+ wp_update_post($_POST);
+ wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id");
+ die;
+ break;
+
+ case 'delete' :
+ global $ID, $post_id, $from_tab, $style;
+ if ( !$from_tab )
+ $from_tab = 'upload';
+
+ check_admin_referer( 'inlineuploading' );
+
+ if ( !current_user_can('edit_post', (int) $ID) )
+ wp_die( __('You are not allowed to delete this attachment.')
+ . " <a href='" . get_option('siteurl') . "/wp-admin/upload.php?style=" . attribute_escape($style . "&amp;tab=$from_tab&amp;post_id=$post_id") . "'>"
+ . __('Go back') . '</a>'
+ );
+
+ wp_delete_attachment($ID);
+
+ wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id" );
+ die;
+ break;
+
+ endswitch;
+}
+
+add_action( 'upload_files_upload', 'wp_upload_tab_upload_action' );
+
+function wp_upload_grab_attachments( $obj ) {
+ $obj->is_attachment = true;
+}
+
+function wp_upload_posts_where( $where ) {
+ global $post_id;
+ return $where . " AND post_parent = '" . (int) $post_id . "'";
+}
+
+function wp_upload_tab_browse() {
+ global $action, $paged;
+ $old_vars = compact( 'paged' );
+
+ switch ( $action ) :
+ case 'edit' :
+ case 'view' :
+ global $ID;
+ $attachments = query_posts("attachment_id=$ID");
+ if ( have_posts() ) : while ( have_posts() ) : the_post();
+ 'edit' == $action ? wp_upload_form() : wp_upload_view();
+ endwhile; endif;
+ break;
+ default :
+ global $tab, $post_id, $style;
+ add_action( 'pre_get_posts', 'wp_upload_grab_attachments' );
+ if ( 'browse' == $tab && $post_id )
+ add_filter( 'posts_where', 'wp_upload_posts_where' );
+ $attachments = query_posts("what_to_show=posts&post_status=any&posts_per_page=10&paged=$paged");
+
+ echo "<ul id='upload-files'>\n";
+ if ( have_posts() ) : while ( have_posts() ) : the_post();
+ $href = wp_specialchars( add_query_arg( array(
+ 'action' => 'inline' == $style ? 'view' : 'edit',
+ 'ID' => get_the_ID())
+ ), 1 );
+
+ echo "\t<li id='file-";
+ the_ID();
+ echo "' class='alignleft'>\n";
+ echo wp_upload_display( array(128,128), $href );
+ echo "\t</li>\n";
+ endwhile;
+ else :
+ echo "\t<li>" . __('There are no attachments to show.') . "</li>\n";
+ endif;
+ echo "</ul>\n\n";
+
+ echo "<form action='' id='browse-form'><input type='hidden' id='nonce-value' value='" . wp_create_nonce( 'inlineuploading' ) . "' /></form>\n";
+ break;
+ endswitch;
+
+ extract($old_vars);
+
+ echo "<div class='clear'></div>";
+}
+
+
+function wp_upload_tab_browse_action() {
+ global $style;
+ if ( 'inline' == $style )
+ wp_enqueue_script('upload');
+}
+
+add_action( 'upload_files_browse', 'wp_upload_tab_browse_action' );
+add_action( 'upload_files_browse-all', 'wp_upload_tab_browse_action' );
+
+function wp_upload_admin_head() {
+ wp_admin_css( 'css/upload' );
+ if ( 'inline' == @$_GET['style'] ) {
+ echo "<style type='text/css' media='screen'>\n";
+ echo "\t#upload-menu { position: absolute; z-index: 2; }\n";
+ echo "\tbody > #upload-menu { position: fixed; }\n";
+ echo "\t#upload-content { top: 2em; }\n";
+ echo "\t#upload-file { position: absolute; top: 15px; }\n";
+ echo "</style>";
+ }
+}
+
+?>
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php
new file mode 100644
index 0000000..ca15057
--- /dev/null
+++ b/wp-admin/includes/user.php
@@ -0,0 +1,284 @@
+<?php
+
+// Creates a new user from the "Users" form using $_POST information.
+function add_user() {
+ if ( func_num_args() ) { // The hackiest hack that ever did hack
+ global $current_user, $wp_roles;
+ $user_id = (int) func_get_arg( 0 );
+
+ if ( isset( $_POST['role'] ) ) {
+ if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) {
+ $user = new WP_User( $user_id );
+ $user->set_role( $_POST['role'] );
+ }
+ }
+ } else {
+ add_action( 'user_register', 'add_user' ); // See above
+ return edit_user();
+ }
+}
+
+function edit_user( $user_id = 0 ) {
+ global $current_user, $wp_roles, $wpdb;
+ if ( $user_id != 0 ) {
+ $update = true;
+ $user->ID = (int) $user_id;
+ $userdata = get_userdata( $user_id );
+ $user->user_login = $wpdb->escape( $userdata->user_login );
+ } else {
+ $update = false;
+ $user = '';
+ }
+
+ if ( isset( $_POST['user_login'] ))
+ $user->user_login = wp_specialchars( trim( $_POST['user_login'] ));
+
+ $pass1 = $pass2 = '';
+ if ( isset( $_POST['pass1'] ))
+ $pass1 = $_POST['pass1'];
+ if ( isset( $_POST['pass2'] ))
+ $pass2 = $_POST['pass2'];
+
+ if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) {
+ if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ))
+ $user->role = $_POST['role'];
+ }
+
+ if ( isset( $_POST['email'] ))
+ $user->user_email = wp_specialchars( trim( $_POST['email'] ));
+ if ( isset( $_POST['url'] ) ) {
+ $user->user_url = clean_url( trim( $_POST['url'] ));
+ $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;
+ }
+ if ( isset( $_POST['first_name'] ))
+ $user->first_name = wp_specialchars( trim( $_POST['first_name'] ));
+ if ( isset( $_POST['last_name'] ))
+ $user->last_name = wp_specialchars( trim( $_POST['last_name'] ));
+ if ( isset( $_POST['nickname'] ))
+ $user->nickname = wp_specialchars( trim( $_POST['nickname'] ));
+ if ( isset( $_POST['display_name'] ))
+ $user->display_name = wp_specialchars( trim( $_POST['display_name'] ));
+ if ( isset( $_POST['description'] ))
+ $user->description = trim( $_POST['description'] );
+ if ( isset( $_POST['jabber'] ))
+ $user->jabber = wp_specialchars( trim( $_POST['jabber'] ));
+ if ( isset( $_POST['aim'] ))
+ $user->aim = wp_specialchars( trim( $_POST['aim'] ));
+ if ( isset( $_POST['yim'] ))
+ $user->yim = wp_specialchars( trim( $_POST['yim'] ));
+ if ( !$update )
+ $user->rich_editing = 'true'; // Default to true for new users.
+ else if ( isset( $_POST['rich_editing'] ) )
+ $user->rich_editing = $_POST['rich_editing'];
+ else
+ $user->rich_editing = 'false';
+
+ $errors = new WP_Error();
+
+ /* checking that username has been typed */
+ if ( $user->user_login == '' )
+ $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' ));
+
+ /* checking the password has been typed twice */
+ do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));
+
+ if (!$update ) {
+ if ( $pass1 == '' || $pass2 == '' )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ));
+ } else {
+ if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) )
+ $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." ));
+ }
+
+ /* Check for "\" in password */
+ if( strpos( " ".$pass1, "\\" ) )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ));
+
+ /* checking the password has been typed twice the same */
+ if ( $pass1 != $pass2 )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' ));
+
+ if (!empty ( $pass1 ))
+ $user->user_pass = $pass1;
+
+ if ( !$update && !validate_username( $user->user_login ) )
+ $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
+
+ if (!$update && username_exists( $user->user_login ))
+ $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ));
+
+ /* checking e-mail address */
+ if ( empty ( $user->user_email ) ) {
+ $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" ));
+ } else
+ if (!is_email( $user->user_email ) ) {
+ $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" ));
+ }
+
+ if ( $errors->get_error_codes() )
+ return $errors;
+
+ if ( $update ) {
+ $user_id = wp_update_user( get_object_vars( $user ));
+ } else {
+ $user_id = wp_insert_user( get_object_vars( $user ));
+ wp_new_user_notification( $user_id );
+ }
+ return $user_id;
+}
+
+function get_author_user_ids() {
+ global $wpdb;
+ // wpmu site admins don't have user_levels
+ $level_key = $wpdb->prefix . 'capabilities';
+
+ $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value != '0'";
+
+ return $wpdb->get_col( $query );
+}
+
+function get_editable_authors( $user_id ) {
+ global $wpdb;
+
+ $editable = get_editable_user_ids( $user_id );
+
+ if( !$editable ) {
+ return false;
+ } else {
+ $editable = join(',', $editable);
+ $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" );
+ }
+
+ return apply_filters('get_editable_authors', $authors);
+}
+
+function get_editable_user_ids( $user_id, $exclude_zeros = true ) {
+ global $wpdb;
+
+ $user = new WP_User( $user_id );
+
+ if ( ! $user->has_cap('edit_others_posts') ) {
+ if ( $user->has_cap('edit_posts') || $exclude_zeros == false )
+ return array($user->id);
+ else
+ return false;
+ }
+
+ // wpmu site admins don't have user_levels
+ $level_key = $wpdb->prefix . 'capabilities';
+
+ $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
+ if ( $exclude_zeros )
+ $query .= " AND meta_value != 'a:1:{s:10:\"subscriber\";b:1;}'";
+
+ return $wpdb->get_col( $query );
+}
+
+function get_nonauthor_user_ids() {
+ global $wpdb;
+ // wpmu site admins don't have user_levels
+ $level_key = $wpdb->prefix . 'capabilities';
+
+ $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value = '0'";
+
+ return $wpdb->get_col( $query );
+}
+
+function get_others_unpublished_posts($user_id, $type='any') {
+ global $wpdb;
+ $user = get_userdata( $user_id );
+ $level_key = $wpdb->prefix . 'user_level';
+
+ $editable = get_editable_user_ids( $user_id );
+
+ if ( in_array($type, array('draft', 'pending')) )
+ $type_sql = " post_status = '$type' ";
+ else
+ $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) ";
+
+ $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC';
+
+ if( !$editable ) {
+ $other_unpubs = '';
+ } else {
+ $editable = join(',', $editable);
+ $other_unpubs = $wpdb->get_results("SELECT ID, post_title, post_author FROM $wpdb->posts WHERE post_type = 'post' AND $type_sql AND post_author IN ($editable) AND post_author != '$user_id' ORDER BY post_modified $dir");
+ }
+
+ return apply_filters('get_others_drafts', $other_unpubs);
+}
+
+function get_others_drafts($user_id) {
+ return get_others_unpublished_posts($user_id, 'draft');
+}
+
+function get_others_pending($user_id) {
+ return get_others_unpublished_posts($user_id, 'pending');
+}
+
+function get_user_to_edit( $user_id ) {
+ $user = new WP_User( $user_id );
+ $user->user_login = attribute_escape($user->user_login);
+ $user->user_email = attribute_escape($user->user_email);
+ $user->user_url = clean_url($user->user_url);
+ $user->first_name = attribute_escape($user->first_name);
+ $user->last_name = attribute_escape($user->last_name);
+ $user->display_name = attribute_escape($user->display_name);
+ $user->nickname = attribute_escape($user->nickname);
+ $user->aim = attribute_escape($user->aim);
+ $user->yim = attribute_escape($user->yim);
+ $user->jabber = attribute_escape($user->jabber);
+ $user->description = wp_specialchars($user->description);
+
+ return $user;
+}
+
+function get_users_drafts( $user_id ) {
+ global $wpdb;
+ $user_id = (int) $user_id;
+ $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = $user_id ORDER BY post_modified DESC";
+ $query = apply_filters('get_users_drafts', $query);
+ return $wpdb->get_results( $query );
+}
+
+function wp_delete_user($id, $reassign = 'novalue') {
+ global $wpdb;
+
+ $id = (int) $id;
+ $user = get_userdata($id);
+
+ if ($reassign == 'novalue') {
+ $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
+
+ if ($post_ids) {
+ foreach ($post_ids as $post_id)
+ wp_delete_post($post_id);
+ }
+
+ // Clean links
+ $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id");
+ } else {
+ $reassign = (int) $reassign;
+ $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}");
+ $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}");
+ }
+
+ // FINALLY, delete user
+ do_action('delete_user', $id);
+
+ $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = $id AND meta_key = '{$wpdb->prefix}capabilities'");
+
+ wp_cache_delete($id, 'users');
+ wp_cache_delete($user->user_login, 'userlogins');
+
+ return true;
+}
+
+function wp_revoke_user($id) {
+ $id = (int) $id;
+
+ $user = new WP_User($id);
+ $user->remove_all_caps();
+}
+
+?>