From d48e85e0ac5e675ca33fac173f30c75403d1033f Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 22 Jun 2006 18:31:50 +0000 Subject: Moved everything in wp-inst down a directory. Uses's Ryan Boren's htaccess rules and mods If you're upgrading, try this on a test server first! git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@591 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/admin-ajax.php | 234 +++++ wp-admin/admin-db.php | 554 ++++++++++ wp-admin/admin-footer.php | 13 + wp-admin/admin-functions.php | 2009 ++++++++++++++++++++++++++++++++++++ wp-admin/admin-header.php | 41 + wp-admin/admin.php | 120 +++ wp-admin/bookmarklet.php | 104 ++ wp-admin/cat-js.php | 35 + wp-admin/categories.js | 5 + wp-admin/categories.php | 135 +++ wp-admin/comment.php | 209 ++++ wp-admin/custom-fields.js | 26 + wp-admin/dbx-admin-key-js.php | 68 ++ wp-admin/edit-category-form.php | 46 + wp-admin/edit-comments.js | 23 + wp-admin/edit-comments.php | 211 ++++ wp-admin/edit-form-advanced.php | 237 +++++ wp-admin/edit-form-ajax-cat.php | 37 + wp-admin/edit-form-comment.php | 80 ++ wp-admin/edit-form.php | 75 ++ wp-admin/edit-link-form.php | 257 +++++ wp-admin/edit-page-form.php | 194 ++++ wp-admin/edit-pages.php | 62 ++ wp-admin/edit.php | 296 ++++++ wp-admin/export.php | 106 ++ wp-admin/images/box-bg.gif | Bin 0 -> 111 bytes wp-admin/images/box-butt.gif | Bin 0 -> 347 bytes wp-admin/images/box-head.gif | Bin 0 -> 879 bytes wp-admin/images/browse-happy.gif | Bin 0 -> 4398 bytes wp-admin/images/fade-butt.png | Bin 0 -> 785 bytes wp-admin/images/notice.gif | Bin 0 -> 156 bytes wp-admin/images/toggle.gif | Bin 0 -> 216 bytes wp-admin/images/wordpress-logo.png | Bin 0 -> 2098 bytes wp-admin/import.php | 62 ++ wp-admin/import/b2.php | 0 wp-admin/import/blogger.php | 675 ++++++++++++ wp-admin/import/blogware.php | 192 ++++ wp-admin/import/dotclear.php | 747 ++++++++++++++ wp-admin/import/greymatter.php | 312 ++++++ wp-admin/import/livejournal.php | 168 +++ wp-admin/import/mt.php | 407 ++++++++ wp-admin/import/rss.php | 171 +++ wp-admin/import/textpattern.php | 663 ++++++++++++ wp-admin/import/wordpress.php | 288 ++++++ wp-admin/index.php | 181 ++++ wp-admin/inline-uploading.php | 728 +++++++++++++ wp-admin/install-helper.php | 152 +++ wp-admin/invites.php | 196 ++++ wp-admin/link-add.php | 49 + wp-admin/link-import.php | 133 +++ wp-admin/link-manager.php | 209 ++++ wp-admin/link-parse-opml.php | 65 ++ wp-admin/link.php | 128 +++ wp-admin/list-manipulation-js.php | 163 +++ wp-admin/menu-header.php | 61 ++ wp-admin/menu.php | 141 +++ wp-admin/moderation.php | 232 +++++ wp-admin/options-discussion.php | 101 ++ wp-admin/options-general.php | 123 +++ wp-admin/options-head.php | 24 + wp-admin/options-misc.php | 52 + wp-admin/options-permalink.php | 180 ++++ wp-admin/options-reading.php | 95 ++ wp-admin/options-writing.php | 66 ++ wp-admin/options.php | 163 +++ wp-admin/page-new.php | 23 + wp-admin/page.php | 159 +++ wp-admin/plugin-editor.php | 127 +++ wp-admin/plugins.php | 142 +++ wp-admin/post-new.php | 94 ++ wp-admin/post.php | 161 +++ wp-admin/profile-update.php | 34 + wp-admin/profile.php | 148 +++ wp-admin/setup-config.php | 189 ++++ wp-admin/sidebar.php | 80 ++ wp-admin/templates.php | 171 +++ wp-admin/theme-editor.php | 162 +++ wp-admin/themes.php | 142 +++ wp-admin/update-links.php | 44 + wp-admin/upgrade-functions.php | 1076 +++++++++++++++++++ wp-admin/upgrade-schema.php | 467 +++++++++ wp-admin/upgrade.php | 106 ++ wp-admin/user-edit.php | 280 +++++ wp-admin/users.js | 20 + wp-admin/users.php | 597 +++++++++++ wp-admin/wp-admin.css | 1009 ++++++++++++++++++ wp-admin/wpmu-admin.php | 52 + wp-admin/wpmu-blogs.php | 527 ++++++++++ wp-admin/wpmu-edit.php | 263 +++++ wp-admin/wpmu-feedback.php | 10 + wp-admin/wpmu-feeds.php | 43 + wp-admin/wpmu-options.php | 131 +++ wp-admin/wpmu-themes.php | 57 + wp-admin/wpmu-upgrade-site.php | 73 ++ wp-admin/wpmu-users.php | 339 ++++++ wp-admin/xfn.js | 46 + 96 files changed, 18876 insertions(+) create mode 100644 wp-admin/admin-ajax.php create mode 100644 wp-admin/admin-db.php create mode 100644 wp-admin/admin-footer.php create mode 100644 wp-admin/admin-functions.php create mode 100644 wp-admin/admin-header.php create mode 100644 wp-admin/admin.php create mode 100644 wp-admin/bookmarklet.php create mode 100644 wp-admin/cat-js.php create mode 100644 wp-admin/categories.js create mode 100644 wp-admin/categories.php create mode 100644 wp-admin/comment.php create mode 100644 wp-admin/custom-fields.js create mode 100644 wp-admin/dbx-admin-key-js.php create mode 100644 wp-admin/edit-category-form.php create mode 100644 wp-admin/edit-comments.js create mode 100644 wp-admin/edit-comments.php create mode 100644 wp-admin/edit-form-advanced.php create mode 100644 wp-admin/edit-form-ajax-cat.php create mode 100644 wp-admin/edit-form-comment.php create mode 100644 wp-admin/edit-form.php create mode 100644 wp-admin/edit-link-form.php create mode 100644 wp-admin/edit-page-form.php create mode 100644 wp-admin/edit-pages.php create mode 100644 wp-admin/edit.php create mode 100644 wp-admin/export.php create mode 100644 wp-admin/images/box-bg.gif create mode 100644 wp-admin/images/box-butt.gif create mode 100644 wp-admin/images/box-head.gif create mode 100644 wp-admin/images/browse-happy.gif create mode 100644 wp-admin/images/fade-butt.png create mode 100644 wp-admin/images/notice.gif create mode 100644 wp-admin/images/toggle.gif create mode 100644 wp-admin/images/wordpress-logo.png create mode 100644 wp-admin/import.php create mode 100644 wp-admin/import/b2.php create mode 100644 wp-admin/import/blogger.php create mode 100644 wp-admin/import/blogware.php create mode 100644 wp-admin/import/dotclear.php create mode 100644 wp-admin/import/greymatter.php create mode 100644 wp-admin/import/livejournal.php create mode 100644 wp-admin/import/mt.php create mode 100644 wp-admin/import/rss.php create mode 100644 wp-admin/import/textpattern.php create mode 100644 wp-admin/import/wordpress.php create mode 100644 wp-admin/index.php create mode 100644 wp-admin/inline-uploading.php create mode 100644 wp-admin/install-helper.php create mode 100644 wp-admin/invites.php create mode 100644 wp-admin/link-add.php create mode 100644 wp-admin/link-import.php create mode 100644 wp-admin/link-manager.php create mode 100644 wp-admin/link-parse-opml.php create mode 100644 wp-admin/link.php create mode 100644 wp-admin/list-manipulation-js.php create mode 100644 wp-admin/menu-header.php create mode 100644 wp-admin/menu.php create mode 100644 wp-admin/moderation.php create mode 100644 wp-admin/options-discussion.php create mode 100644 wp-admin/options-general.php create mode 100644 wp-admin/options-head.php create mode 100644 wp-admin/options-misc.php create mode 100644 wp-admin/options-permalink.php create mode 100644 wp-admin/options-reading.php create mode 100644 wp-admin/options-writing.php create mode 100644 wp-admin/options.php create mode 100644 wp-admin/page-new.php create mode 100644 wp-admin/page.php create mode 100644 wp-admin/plugin-editor.php create mode 100644 wp-admin/plugins.php create mode 100644 wp-admin/post-new.php create mode 100644 wp-admin/post.php create mode 100644 wp-admin/profile-update.php create mode 100644 wp-admin/profile.php create mode 100644 wp-admin/setup-config.php create mode 100644 wp-admin/sidebar.php create mode 100644 wp-admin/templates.php create mode 100644 wp-admin/theme-editor.php create mode 100644 wp-admin/themes.php create mode 100644 wp-admin/update-links.php create mode 100644 wp-admin/upgrade-functions.php create mode 100644 wp-admin/upgrade-schema.php create mode 100644 wp-admin/upgrade.php create mode 100644 wp-admin/user-edit.php create mode 100644 wp-admin/users.js create mode 100644 wp-admin/users.php create mode 100644 wp-admin/wp-admin.css create mode 100644 wp-admin/wpmu-admin.php create mode 100644 wp-admin/wpmu-blogs.php create mode 100644 wp-admin/wpmu-edit.php create mode 100644 wp-admin/wpmu-feedback.php create mode 100644 wp-admin/wpmu-feeds.php create mode 100644 wp-admin/wpmu-options.php create mode 100644 wp-admin/wpmu-themes.php create mode 100644 wp-admin/wpmu-upgrade-site.php create mode 100644 wp-admin/wpmu-users.php create mode 100644 wp-admin/xfn.js (limited to 'wp-admin') diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php new file mode 100644 index 0000000..088ce31 --- /dev/null +++ b/wp-admin/admin-ajax.php @@ -0,0 +1,234 @@ +escape( rawurldecode(stripslashes($i)) ); + return $i; +} + +function wp_ajax_echo_meta( $pid, $mid, $key, $value ) { + $value = wp_specialchars($value, true); + $key_js = addslashes(wp_specialchars($key, 'double')); + $key = wp_specialchars($key, true); + $r = "$mid$pid"; + $r .= ""; + $r .= ""; + $r .= ""; + $r .= "
"; + $r .= ""; + $r .= "]]>
"; + return $r; +} + +$_POST = wp_clean_ajax_input( $_POST ); +$id = (int) $_POST['id']; +switch ( $_POST['action'] ) : +case 'delete-comment' : + if ( !$comment = get_comment( $id ) ) + die('0'); + if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) + die('-1'); + + if ( wp_delete_comment( $comment->comment_ID ) ) + die('1'); + else die('0'); + break; +case 'delete-comment-as-spam' : + if ( !$comment = get_comment( $id ) ) + die('0'); + if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) + die('-1'); + + if ( wp_set_comment_status( $comment->comment_ID, 'spam' ) ) + die('1'); + else die('0'); + break; +case 'delete-cat' : + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + + if ( wp_delete_category( $id ) ) + die('1'); + else die('0'); + break; +case 'delete-link' : + if ( !current_user_can( 'manage_links' ) ) + die('-1'); + + if ( wp_delete_link( $id ) ) + die('1'); + else die('0'); + break; +case 'delete-meta' : + if ( !$meta = get_post_meta_by_id( $id ) ) + die('0'); + if ( !current_user_can( 'edit_post', $meta->post_id ) ) + die('-1'); + if ( delete_meta( $meta->meta_id ) ) + die('1'); + die('0'); + break; +case 'delete-post' : + if ( !current_user_can( 'delete_post', $id ) ) + die('-1'); + + if ( wp_delete_post( $id ) ) + die('1'); + else die('0'); + break; +case 'delete-page' : + if ( !current_user_can( 'delete_page', $id ) ) + die('-1'); + + if ( wp_delete_post( $id ) ) + die('1'); + else die('0'); + break; +case 'dim-comment' : + if ( !$comment = get_comment( $id ) ) + die('0'); + if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) ) + die('-1'); + if ( !current_user_can( 'moderate_comments' ) ) + die('-1'); + + if ( 'unapproved' == wp_get_comment_status($comment->comment_ID) ) { + if ( wp_set_comment_status( $comment->comment_ID, 'approve' ) ) + die('1'); + } else { + if ( wp_set_comment_status( $comment->comment_ID, 'hold' ) ) + die('1'); + } + die('0'); + break; +case 'add-category' : // On the Fly + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + $names = explode(',', $_POST['newcat']); + $r = ""; + foreach ( $names as $cat_name ) { + $cat_name = trim($cat_name); + if ( !$category_nicename = sanitize_title($cat_name) ) + die('0'); + if ( !$cat_id = category_exists( $cat_name ) ) + $cat_id = wp_create_category( $cat_name ); + $cat_name = wp_specialchars(stripslashes($cat_name)); + $r .= "$cat_id"; + $r .= "]]>"; + } + $r .= ''; + header('Content-type: text/xml'); + die($r); + break; +case 'add-cat' : // From Manage->Categories + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + if ( !$cat = wp_insert_category( $_POST ) ) + die('0'); + if ( !$cat = get_category( $cat ) ) + die('0'); + $pad = 0; + $_cat = $cat; + while ( $_cat->category_parent ) { + $_cat = get_category( $_cat->category_parent ); + $pad++; + } + $pad = str_repeat('— ', $pad); + + $r = ""; + $r .= "$cat->cat_ID"; + $r .= "$cat->cat_ID$pad $cat->cat_name"; + $r .= "$cat->category_description$cat->category_count$cat->link_count"; + $r .= "" . __('Edit') . ""; + $r .= "cat_name)); + $r .= "\" );' class='delete'>".__('Delete').""; + $r .= "]]>"; + header('Content-type: text/xml'); + die($r); + + break; +case 'add-meta' : + if ( !current_user_can( 'edit_post', $id ) ) + die('-1'); + if ( $id < 0 ) { + if ( $pid = write_post() ) + $meta = has_meta( $pid ); + else + die('0'); + $key = $meta[0]['meta_key']; + $value = $meta[0]['meta_value']; + $mid = (int) $meta[0]['meta_id']; + } else { + if ( $mid = add_meta( $id ) ) + $meta = get_post_meta_by_id( $mid ); + else + die('0'); + $key = $meta->meta_key; + $value = $meta->meta_value; + $pid = (int) $meta->post_id; + } + $r = ""; + $r .= wp_ajax_echo_meta( $pid, $mid, $key, $value ); + $r .= ''; + header('Content-type: text/xml'); + die($r); + break; +case 'update-meta' : + $mid = (int) array_pop(array_keys($_POST['meta'])); + $key = $_POST['meta'][$mid]['key']; + $value = $_POST['meta'][$mid]['value']; + if ( !$meta = get_post_meta_by_id( $mid ) ) + die('0'); + if ( !current_user_can( 'edit_post', $meta->post_id ) ) + die('-1'); + $r = ""; + if ( $u = update_meta( $mid, $key, $value ) ) { + $key = stripslashes($key); + $value = stripslashes($value); + $r .= wp_ajax_echo_meta( $meta->post_id, $mid, $key, $value ); + } + $r .= ''; + header('Content-type: text/xml'); + die($r); + break; +case 'add-user' : + if ( !current_user_can('edit_users') ) + die('-1'); + require_once(ABSPATH . WPINC . '/registration.php'); + $user_id = add_user(); + if ( is_wp_error( $user_id ) ) { + foreach( $user_id->get_error_messages() as $message ) + echo "$message
"; + exit; + } elseif ( !$user_id ) { + die('0'); + } + $r = "$user_id"; + $r .= user_row( $user_id ); + $r .= "]]>"; + header('Content-type: text/xml'); + die($r); + break; +default : + die('0'); + break; +endswitch; +?> diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php new file mode 100644 index 0000000..0b8c264 --- /dev/null +++ b/wp-admin/admin-db.php @@ -0,0 +1,554 @@ +posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = $user_id ORDER BY ID DESC"; + $query = apply_filters('get_users_drafts', $query); + return $wpdb->get_results( $query ); +} + +function get_others_drafts( $user_id ) { + global $wpdb; + $user = get_userdata( $user_id ); + $level_key = $wpdb->prefix . 'user_level'; + + $editable = get_editable_user_ids( $user_id ); + + if( !$editable ) { + $other_drafts = ''; + } else { + $editable = join(',', $editable); + $other_drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author IN ($editable) AND post_author != '$user_id' "); + } + + return apply_filters('get_others_drafts', $other_drafts); +} + +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)" ); + } + + 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; + } + + $level_key = $wpdb->prefix . 'user_level'; + + $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'"; + if ( $exclude_zeros ) + $query .= " AND meta_value != '0'"; + + return $wpdb->get_col( $query ); +} + +function get_author_user_ids() { + global $wpdb; + $level_key = $wpdb->prefix . 'user_level'; + + $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value != '0'"; + + return $wpdb->get_col( $query ); +} + +function get_nonauthor_user_ids() { + global $wpdb; + $level_key = $wpdb->prefix . 'user_level'; + + $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value = '0'"; + + return $wpdb->get_col( $query ); +} + +function wp_insert_category($catarr) { + global $wpdb; + + extract($catarr); + + $cat_ID = (int) $cat_ID; + + // Are we updating or creating? + if (!empty ($cat_ID)) + $update = true; + else + $update = false; + + $cat_name = apply_filters('pre_category_name', $cat_name); + + if ( !$update && category_exists($cat_name) ) + return 0; + + if (empty ($category_nicename)) + $category_nicename = sanitize_title($cat_name); + else + $category_nicename = sanitize_title($category_nicename); + $category_nicename = apply_filters('pre_category_nicename', $category_nicename); + + if (empty ($category_description)) + $category_description = ''; + $category_description = apply_filters('pre_category_description', $category_description); + + $category_parent = (int) $category_parent; + if (empty ($category_parent)) + $category_parent = 0; + + if ( isset($posts_private) ) + $posts_private = (int) $posts_private; + else + $posts_private = 0; + + if ( isset($links_private) ) + $links_private = (int) $links_private; + else + $links_private = 0; + + if (!$update) { + $maxcat = $wpdb->get_var( "SELECT max(cat_ID) FROM {$wpdb->categories}" ); + $cat_ID = mt_rand( $maxcat+100, $maxcat+4000 ); + $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent, links_private, posts_private) VALUES ('$cat_ID', '$cat_name', '$category_nicename', '$category_description', '$category_parent', '$links_private', '$posts_private')"); + } else { + $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent', links_private = '$links_private', posts_private = '$posts_private' WHERE cat_ID = '$cat_ID'"); + } + + if ( $category_nicename == '' ) { + $category_nicename = sanitize_title($cat_name, $cat_ID ); + $wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$category_nicename' WHERE cat_ID = '$cat_ID'" ); + } + + wp_cache_delete($cat_ID, 'category'); + + if ($update) { + do_action('edit_category', $cat_ID); + } else { + wp_cache_delete('all_category_ids', 'category'); + do_action('create_category', $cat_ID); + do_action('add_category', $cat_ID); + } + $cat_ID = apply_filters( "cat_id_filter", $cat_ID ); + + return $cat_ID; +} + +function wp_update_category($catarr) { + global $wpdb; + + $cat_ID = (int) $catarr['cat_ID']; + + // 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); +} + +function wp_delete_category($cat_ID) { + global $wpdb; + + $cat_ID = (int) $cat_ID; + + // Don't delete the default cat. + if ( $cat_ID == get_option('default_category') ) + return 0; + + if ( $cat_ID == get_option('default_link_category') ) + return 0; + + $category = get_category($cat_ID); + + $parent = $category->category_parent; + + // Delete the category. + if ( !$wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'") ) + return 0; + + // Update children to point to new parent. + $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); + + // Only set posts and links to the default category if they're not in another category already. + $default_cat = get_option('default_category'); + $posts = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE category_id='$cat_ID'"); + if ( is_array($posts) ) foreach ($posts as $post_id) { + $cats = wp_get_post_categories($post_id); + if ( 1 == count($cats) ) + $cats = array($default_cat); + else + $cats = array_diff($cats, array($cat_ID)); + wp_set_post_categories($post_id, $cats); + } + + $default_link_cat = get_option('default_link_category'); + $links = $wpdb->get_col("SELECT link_id FROM $wpdb->link2cat WHERE category_id='$cat_ID'"); + if ( is_array($links) ) foreach ($links as $link_id) { + $cats = wp_get_link_cats($link_id); + if ( 1 == count($cats) ) + $cats = array($default_link_cat); + else + $cats = array_diff($cats, array($cat_ID)); + wp_set_link_cats($link_id, $cats); + } + + wp_cache_delete($cat_ID, 'category'); + wp_cache_delete('all_category_ids', 'category'); + + do_action('delete_category', $cat_ID); + + return 1; +} + +function wp_create_category($cat_name) { + $cat_array = compact('cat_name'); + return wp_insert_category($cat_array); +} + +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 category_exists($cat_name) { + global $wpdb; + if (!$category_nicename = sanitize_title($cat_name)) + return 0; + + return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); +} + +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 + $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'); + + do_action('delete_user', $id); + + return true; +} + +function wp_revoke_user($id) { + $id = (int) $id; + + $user = new WP_User($id); + $user->remove_all_caps(); +} + +function wp_insert_link($linkdata) { + global $wpdb, $current_user; + + extract($linkdata); + + $update = false; + if ( !empty($link_id) ) + $update = true; + + if ( empty($link_rating) ) + $link_rating = 0; + + 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 = ''; + + // 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 = $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_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); +} + +function wp_delete_link($link_id) { + global $wpdb; + + do_action('delete_link', $link_id); + + $categories = wp_get_link_cats($link_id); + if( is_array( $categories ) ) { + foreach ( $categories as $category ) { + $wpdb->query("UPDATE $wpdb->categories SET link_count = link_count - 1 WHERE cat_ID = '$category'"); + wp_cache_delete($category, 'category'); + } + } + + $wpdb->query("DELETE FROM $wpdb->link2cat WHERE link_id = '$link_id'"); + return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); +} + +function wp_get_link_cats($link_ID = 0) { + global $wpdb; + + $sql = "SELECT category_id + FROM $wpdb->link2cat + WHERE link_id = $link_ID + ORDER BY category_id"; + + $result = $wpdb->get_col($sql); + + if ( !$result ) + $result = array(); + + return array_unique($result); +} + +function wp_set_link_cats($link_ID = 0, $link_categories = array()) { + global $wpdb; + // 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_unique($link_categories); + + // First the old categories + $old_categories = $wpdb->get_col(" + SELECT category_id + FROM $wpdb->link2cat + WHERE link_id = $link_ID"); + + if (!$old_categories) { + $old_categories = array(); + } else { + $old_categories = array_unique($old_categories); + } + + // Delete any? + $delete_cats = array_diff($old_categories,$link_categories); + + if ($delete_cats) { + foreach ($delete_cats as $del) { + $wpdb->query(" + DELETE FROM $wpdb->link2cat + WHERE category_id = $del + AND link_id = $link_ID + "); + } + } + + // Add any? + $add_cats = array_diff($link_categories, $old_categories); + + if ($add_cats) { + foreach ($add_cats as $new_cat) { + $wpdb->query(" + INSERT INTO $wpdb->link2cat (link_id, category_id) + VALUES ($link_ID, $new_cat)"); + } + } + + // Update category counts. + $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); + foreach ( $all_affected_cats as $cat_id ) { + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); + $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); + wp_cache_delete($cat_id, 'category'); + } +} // wp_set_link_cats() + +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; +} + +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 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 ); + + while( list( $key, $val ) = each( $drop_tables ) ) + $wpdb->query( "DROP TABLE IF EXISTS $val" ); + + $wpdb->query( "DELETE FROM $wpdb->blogs WHERE blog_id = '$blog_id'" ); + } + + if ( $switch ) + restore_current_blog(); +} + +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; +} + +?> diff --git a/wp-admin/admin-footer.php b/wp-admin/admin-footer.php new file mode 100644 index 0000000..783be91 --- /dev/null +++ b/wp-admin/admin-footer.php @@ -0,0 +1,13 @@ + + + + + + + diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php new file mode 100644 index 0000000..d229073 --- /dev/null +++ b/wp-admin/admin-functions.php @@ -0,0 +1,2009 @@ + 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); + add_meta($post_ID); + + // Reunite any orphaned attachments with their parent + if ( $_POST['temp_ID'] ) + relocate_children($_POST['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; +} + +// 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"); +} + +// 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 = "#]+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 = "# id=(\"|')p(\d+)\\1#i"; + foreach ( $anchor_matches[0] as $anchor ) { + if ( 0 == preg_match($search, $anchor, $id_matches) ) + continue; + + $id = $id_matches[2]; + + // 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); +} + +// 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) ) + die(__('You are not allowed to edit this page.')); + } else { + if ( !current_user_can('edit_post', $post_ID) ) + die(__('You are not allowed to edit this post.')); + } + + // 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') ) + die(__('You cannot edit pages as this user.')); + } else { + if ( !current_user_can('edit_others_posts') ) + die(__('You cannot 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'] = 'draft'; + } else { + if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_posts')) + $_POST['post_status'] = 'draft'; + } + + 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); + + // Now that we have an ID we can fix any attachment anchor hrefs + fix_attachment_links($post_ID); + + return $post_ID; +} + +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)) + 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); +} + +// Get an existing post and format it for editing. +function get_post_to_edit($id) { + global $richedit; + $richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false; + + $post = get_post($id); + + $post->post_content = format_to_edit($post->post_content, $richedit); + $post->post_content = apply_filters('content_edit_pre', $post->post_content); + + $post->post_excerpt = format_to_edit($post->post_excerpt); + $post->post_excerpt = apply_filters('excerpt_edit_pre', $post->post_excerpt); + + $post->post_title = format_to_edit($post->post_title); + $post->post_title = apply_filters('title_edit_pre', $post->post_title); + + if ($post->post_type == 'page') + $post->page_template = get_post_meta($id, '_wp_page_template', true); + + return $post; +} + +// 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 = wp_specialchars($_REQUEST['popupurl']); + $post_content = ''.$post_title.''."\n$text"; + } + + if ( !empty($_REQUEST['excerpt']) ) + $post_excerpt = wp_specialchars(stripslashes($_REQUEST['excerpt'])); + else + $post_excerpt = ''; + + $post->post_status = 'draft'; + $post->comment_status = get_settings('default_comment_status'); + $post->ping_status = get_settings('default_ping_status'); + $post->post_pingback = get_settings('default_pingback_flag'); + $post->post_category = get_settings('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; +} + +function get_comment_to_edit($id) { + global $richedit; + $richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false; + + $comment = get_comment($id); + + $comment->comment_content = format_to_edit($comment->comment_content, $richedit); + $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 = format_to_edit($comment->comment_author_url); + + return $comment; +} + +function get_category_to_edit($id) { + $category = get_category($id); + + return $category; +} + +function wp_dropdown_roles( $default = false ) { + global $wp_roles; + $r = ''; + foreach($wp_roles->role_names as $role => $name) + if ( $default == $role ) // Make default first in list + $p = "\n\t"; + else + $r .= "\n\t"; + echo $p . $r; +} + + +// 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 = 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 = $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'])) { + 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 = wp_specialchars(trim($_POST['url'])); + $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/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 = wp_specialchars(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'])); + + $errors = new WP_Error(); + + /* checking that username has been typed */ + if ($user->user_login == '') + $errors->add('user_login', __('ERROR: Please enter a username.')); + + /* checking the password has been typed twice */ + do_action('check_passwords', array ($user->user_login, & $pass1, & $pass2)); + + if (!$update) { + if ($pass1 == '' || $pass2 == '') + $errors->add('pass', __('ERROR: Please enter your password twice.')); + } else { + if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))) + $errors->add('pass', __("ERROR: you typed your new password only once.")); + } + + /* Check for "\" in password */ + if( strpos( " ".$pass1, "\\" ) ) + $errors->add('pass', __('ERROR: Passwords may not contain the character "\\".')); + + /* checking the password has been typed twice the same */ + if ($pass1 != $pass2) + $errors->add('pass', __('ERROR: Please type the same password in the two password fields.')); + + if (!empty ($pass1)) + $user->user_pass = $pass1; + + if ( !validate_username($user->user_login) ) + $errors->add('user_login', __('ERROR: This username is invalid. Please enter a valid username.')); + + if (!$update && username_exists($user->user_login)) + $errors->add('user_login', __('ERROR: This username is already registered, please choose another one.')); + + /* checking e-mail address */ + if (empty ($user->user_email)) { + $errors->add('user_email', __("ERROR: please type an e-mail address")); + } else + if (!is_email($user->user_email)) { + $errors->add('user_email', __("ERROR: 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_link_to_edit($link_id) { + $link = get_link($link_id); + + $link->link_url = wp_specialchars($link->link_url, 1); + $link->link_name = wp_specialchars($link->link_name, 1); + $link->link_description = wp_specialchars($link->link_description); + $link->link_notes = wp_specialchars($link->link_notes); + $link->link_rss = wp_specialchars($link->link_rss); + $link->post_category = $link->link_category; + + return $link; +} + +function get_default_link_to_edit() { + if ( isset($_GET['linkurl']) ) + $link->link_url = wp_specialchars($_GET['linkurl'], 1); + else + $link->link_url = ''; + + if ( isset($_GET['name']) ) + $link->link_name = wp_specialchars($_GET['name'], 1); + else + $link->link_name = ''; + + $link->link_visible = 'Y'; + + return $link; +} + +function add_link() { + return edit_link(); +} + +function edit_link($link_id = '') { + if (!current_user_can('manage_links')) + die(__("Cheatin' uh ?")); + + $_POST['link_url'] = wp_specialchars($_POST['link_url']); + $_POST['link_url'] = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url']) ? $_POST['link_url'] : 'http://' . $_POST['link_url']; + $_POST['link_name'] = wp_specialchars($_POST['link_name']); + $_POST['link_image'] = wp_specialchars($_POST['link_image']); + $_POST['link_rss'] = wp_specialchars($_POST['link_rss']); + $_POST['link_category'] = $_POST['post_category']; + + if ( !empty($link_id) ) { + $_POST['link_id'] = $link_id; + return wp_update_link($_POST); + } else { + return wp_insert_link($_POST); + } +} + +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 selected($selected, $current) { + if ($selected == $current) + echo ' selected="selected"'; +} + +function checked($checked, $current) { + if ($checked == $current) + echo ' checked="checked"'; +} + +function return_categories_list($parent = 0) { + global $wpdb; + return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC"); +} + +function sort_cats($cat1, $cat2) { + return strcasecmp($cat1['cat_name'], $cat2['cat_name']); +} + +function get_nested_categories($default = 0, $parent = 0) { + global $post_ID, $link_id, $mode, $wpdb; + + if ($post_ID) { + $checked_categories = $wpdb->get_col(" + SELECT category_id + FROM $wpdb->categories, $wpdb->post2cat + WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' + "); + + if (count($checked_categories) == 0) { + // No selected categories, strange + $checked_categories[] = $default; + } + } else if ($link_id) { + $checked_categories = $wpdb->get_col(" + SELECT category_id + FROM $wpdb->categories, $wpdb->link2cat + WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' + "); + + if (count($checked_categories) == 0) { + // No selected categories, strange + $checked_categories[] = $default; + } + } else { + $checked_categories[] = $default; + } + + $cats = return_categories_list($parent); + $result = array (); + + if (is_array($cats)) { + foreach ($cats as $cat) { + if ( $cat == 0 ) { // HACK, added 2006-05-13 + $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_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); + } + } + + usort($result, 'sort_cats'); + + return $result; +} + +function write_nested_categories($categories) { + foreach ($categories as $category) { + echo '
  • \n"; + + if ( $category['children'] ) { + echo "\n"; + } + } +} + +function dropdown_categories($default = 0) { + write_nested_categories(get_nested_categories($default)); +} + +// Dandy new recursive multiple category stuff. +function cat_rows($parent = 0, $level = 0, $categories = 0) { + global $wpdb, $class; + + if (!$categories) + $categories = get_categories('hide_empty=0'); + + if ($categories) { + foreach ($categories as $category) { + if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 + $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); + continue; + } + if ($category->category_parent == $parent) { + $category->cat_name = wp_specialchars($category->cat_name,'double'); + $pad = str_repeat('— ', $level); + if ( current_user_can('manage_categories') ) { + $edit = "".__('Edit').""; + $default_cat_id = get_option('default_category'); + $default_link_cat_id = get_option('default_link_category'); + + if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) + $edit .= "cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category "%s".\\nAll of its posts will go into the default category of "%s"\\nAll of its bookmarks will go into the default category of "%s".\\n"OK" to delete, "Cancel" to stop."), addslashes($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete').""; + else + $edit .= "".__("Default"); + } + else + $edit = ''; + + $class = ('alternate' == $class) ? '' : 'alternate'; + + $category->category_count = number_format( $category->category_count ); + $category->link_count = number_format( $category->link_count ); + echo "$category->cat_ID$pad $category->cat_name + $category->category_description + $category->category_count + $category->link_count + $edit + "; + cat_rows($category->cat_ID, $level +1, $categories); + } + } + } else { + return false; + } +} + +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('— ', $level); + $id = $post->ID; + $class = ('alternate' == $class) ? '' : 'alternate'; +?> + + ID; ?> + + + post_status) _e(' - Private'); ?> + + + post_modified); ?> + + " . __('Edit') . ""; } ?> + " . __('Delete') . ""; } ?> + + +user_email; + if( $current_user->ID != $user_object->ID && is_site_admin() == false ) + $email = "N/A"; + $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 = " + + + + $email + $short_url"; + $r .= "\n\t\t"; + if ($numposts > 0) { + $r .= ""; + $r .= sprintf(__('View %1$s %2$s'), $numposts, __ngettext('post', 'posts', $numposts)); + } + $r .= "\n\t\t"; + $edit_link = add_query_arg('wp_http_referer', wp_specialchars(urlencode(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id=$user_object->ID"); + if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can('edit_user', $user_object->ID) ) + $r .= "".__('Edit').""; + $r .= "\n\t"; + return $r; +} + +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->cat_ID && $parent == $category->category_parent) { + $pad = str_repeat('– ', $level); + $category->cat_name = wp_specialchars($category->cat_name); + echo "\n\t"; + wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level +1, $categories); + } + } + } else { + return false; + } +} + +function return_link_categories_list($parent = 0) { + global $wpdb; + return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC"); +} + +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 it's 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 $thumbpath; + } +} + +// 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 list_meta($meta) { + global $post_ID; + // Exit if no meta + if (!$meta) { + echo ''; //TBODY needed for list-manipulation JS + return; + } + $count = 0; +?> + + + + + + + +"; + foreach ($meta as $entry) { + ++ $count; + if ($count % 2) + $style = 'alternate'; + else + $style = ''; + if ('_' == $entry['meta_key'] { 0 }) + $style .= ' hidden'; + $key_js = addslashes(wp_specialchars( $entry['meta_key'], 'double' )); + $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true ); + $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true ); + $r .= "\n\t"; + $r .= "\n\t\t"; + $r .= "\n\t\t"; + $r .= "\n\t\t
    "; + $r .= "\n\t\t"; + $r .= "\n\t"; + } + echo $r; + echo "\n\t"; +} + +// 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 meta_form() { + global $wpdb; + $keys = $wpdb->get_col(" + SELECT meta_key + FROM $wpdb->postmeta + GROUP BY meta_key + ORDER BY meta_id DESC + LIMIT 10"); +?> +

    + + + + + + + + + + + +
    + + + +
    +

    +escape(stripslashes(trim($_POST['metakeyselect']))); + $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput']))); + $metavalue = $wpdb->escape(stripslashes(trim($_POST['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 + + $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'"); +} + +function update_meta($mid, $mkey, $mvalue) { + global $wpdb; + $mid = (int) $mid; + + return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'"); +} + +function get_post_meta_by_id($mid) { + global $wpdb; + $mid = (int) $mid; + + return $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'"); +} + +function touch_time($edit = 1, $for_post = 1) { + global $wp_locale, $post, $comment; + + if ( $for_post ) + $edit = ( ('draft' == $post->post_status) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date) ) ? false : true; + + echo '
    '; + + $time_adj = time() + (get_settings('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 " + + @ + : + + +get_month($mm) . "$jj, $aa @ $hh:$mn"; + echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn); + } +?> +
    + $markerline) { + if (strstr($markerline, "# BEGIN {$marker}")) + $state = false; + if ($state) { + if ( $n + 1 < count($markerdata) ) + fwrite($f, "{$markerline}\n"); + else + fwrite($f, "{$markerline}"); + } + if (strstr($markerline, "# END {$marker}")) { + 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; + } +} + +// extract_from_markers: Owen Winkler +// 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 (strstr($markerline, "# END {$marker}")) + $state = false; + if ($state) + $result[] = $markerline; + if (strstr($markerline, "# BEGIN {$marker}")) + $state = true; + } + } + + return $result; +} + +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; +} + +function save_mod_rewrite_rules() { + global $is_apache, $wp_rewrite; + $home_path = get_home_path(); + + if (!$wp_rewrite->using_mod_rewrite_permalinks()) + return; + + if (!((!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess'))) + return; + + if (! got_mod_rewrite()) + return; + + $rules = explode("\n", $wp_rewrite->mod_rewrite_rules()); + insert_with_markers($home_path.'.htaccess', 'WordPress', $rules); +} + +function the_quicktags() { + // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP + if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari')) { + echo ' +
    + '; + wp_print_scripts( 'quicktags' ); + echo ' +
    +'; + } else echo ' + +'; +} + +function validate_current_theme() { + $theme_loc = 'wp-content/themes'; + $theme_root = ABSPATH.$theme_loc; + + $template = get_settings('template'); + $stylesheet = get_settings('stylesheet'); + + if (($template != 'default') && (!file_exists("$theme_root/$template/index.php"))) { + update_option('template', 'default'); + update_option('stylesheet', 'default'); + do_action('switch_theme', 'Default'); + return false; + } + + if (($stylesheet != 'default') && (!file_exists("$theme_root/$stylesheet/style.css"))) { + update_option('template', 'default'); + update_option('stylesheet', 'default'); + do_action('switch_theme', 'Default'); + return false; + } + + return true; +} + +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:(.*)|i", $template_data, $name); + preg_match("|Description:(.*)|i", $template_data, $description); + + $name = $name[1]; + $description = $description[1]; + + if (!empty ($name)) { + $page_templates[trim($name)] = basename($template); + } + } + } + + return $page_templates; +} + +function page_template_dropdown($default = '') { + $templates = get_page_templates(); + foreach (array_keys($templates) as $template) + : if ($default == $templates[$template]) + $selected = " selected='selected'"; + else + $selected = ''; + echo "\n\t"; + 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 it's own parent. + if (!empty ($post_ID)) { + if ($item->ID == $post_ID) { + continue; + } + } + $pad = str_repeat(' ', $level * 3); + if ($item->ID == $default) + $current = ' selected="selected"'; + else + $current = ''; + + echo "\n\t"; + parent_dropdown($default, $item->ID, $level +1); + } + } else { + return false; + } +} + +function user_can_access_admin_page() { + global $pagenow; + global $menu; + global $submenu; + global $menu_nopriv; + + $parent = get_admin_page_parent(); + + if ( isset($menu_nopriv[$pagenow]) ) + return false; + + if ( empty($parent) ) + return true; + + if (isset ($submenu[$parent])) { + foreach ($submenu[$parent] as $submenu_array) { + if ($submenu_array[2] == $pagenow) { + if (current_user_can($submenu_array[1])) + return true; + else + return false; + } + } + } + + foreach ($menu as $menu_array) { + //echo "parent array: " . $menu_array[2]; + if ($menu_array[2] == $parent) { + if (current_user_can($menu_array[1])) + return true; + else + return false; + } + } + + return true; +} + +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 { + foreach (array_keys($submenu) as $parent) { + foreach ($submenu[$parent] as $submenu_array) { + if (isset ($submenu_array[3])) { + if ($submenu_array[2] == $pagenow) { + $title = $submenu_array[3]; + return $submenu_array[3]; + } else + 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]; + } + } + } + } + } + + return ''; +} + +function get_admin_page_parent() { + global $parent_file; + global $menu; + global $submenu; + global $pagenow; + global $plugin_page; + global $real_parent_file; + + if ( !empty ($parent_file) ) { + if ( isset($real_parent_file[$parent_file]) ) + $parent_file = $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($real_parent_file[$parent_file]) ) + $parent_file = $real_parent_file[$parent_file]; + + return $parent_file; + } + } + } + + foreach (array_keys($submenu) as $parent) { + foreach ($submenu[$parent] as $submenu_array) { + if ( isset($real_parent_file[$parent]) ) + $parent = $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 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 $real_parent_file; + + $parent = plugin_basename($parent); + if ( isset($real_parent_file[$parent]) ) + $parent = $real_parent_file[$parent]; + + $file = plugin_basename($file); + + // 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) { + $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_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_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_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 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 : + die(__('Sorry, can’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 : + die(__('Sorry, can’t call files with their real path.')); + + case 3 : + die(__('Sorry, that file cannot be edited.')); + } +} + +function get_home_path() { + $home = get_settings('home'); + if ($home != '' && $home != get_settings('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; +} + +$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 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); +} + +function get_plugin_data($plugin_file) { + $plugin_data = implode('', file($plugin_file)); + preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); + preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri); + preg_match("|Description:(.*)|i", $plugin_data, $description); + preg_match("|Author:(.*)|i", $plugin_data, $author_name); + preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri); + if (preg_match("|Version:(.*)|i", $plugin_data, $version)) + $version = $version[1]; + else + $version = ''; + + $description = wptexturize($description[1]); + + $name = $plugin_name[1]; + $name = trim($name); + $plugin = $name; + if ('' != $plugin_uri[1] && '' != $name) { + $plugin = ''.$plugin.''; + } + + if ('' == $author_uri[1]) { + $author = $author_name[1]; + } else { + $author = ''.$author_name[1].''; + } + + return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]); +} + +function get_plugins() { + global $wp_plugins; + + if (isset ($wp_plugins)) { + return $wp_plugins; + } + + $wp_plugins = array (); + $plugin_loc = 'wp-content/plugins'; + $plugin_root = ABSPATH.$plugin_loc; + + // Files in wp-content/plugins directory + $plugins_dir = @ dir($plugin_root); + if ($plugins_dir) { + while (($file = $plugins_dir->read()) !== false) { + if (preg_match('|^\.+$|', $file)) + continue; + if (is_dir($plugin_root.'/'.$file)) { + $plugins_subdir = @ dir($plugin_root.'/'.$file); + if ($plugins_subdir) { + while (($subfile = $plugins_subdir->read()) !== false) { + if (preg_match('|^\.+$|', $subfile)) + continue; + if (preg_match('|\.php$|', $subfile)) + $plugin_files[] = "$file/$subfile"; + } + } + } else { + if (preg_match('|\.php$|', $file)) + $plugin_files[] = $file; + } + } + } + + if (!$plugins_dir || !$plugin_files) { + return $wp_plugins; + } + + sort($plugin_files); + + 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; + } + + return $wp_plugins; +} + +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 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 ''; +} + +function browse_happy() { + $getit = __('WordPress recommends a better browser'); + echo ' +

    Browse Happy

    + '; +} +if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) + add_action('admin_footer', 'browse_happy'); + +function documentation_link($for) { + return; +} + +function register_importer($id, $name, $description, $callback) { + global $wp_importers; + + $wp_importers[$id] = array ($name, $description, $callback); +} + +function get_importers() { + global $wp_importers; + + return $wp_importers; +} + +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; +} + + +// 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 upload_max_filesize directive in php.ini."), + __("The uploaded file exceeds the MAX_FILE_SIZE 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 ) + return $upload_error_handler($file, __('File type does not meet security guidelines. Try another.')); + } + + // 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) ) + die(printf(__('The uploaded file could not be moved to %s.'), $file['path'])); + + // 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; +} + +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); +} + +function wp_import_cleanup($id) { + wp_delete_attachment($id); +} + +function wp_import_upload_form($action) { +?> +
    +

    + + +

    +

    + +

    +
    + false, 'test_type' => false); + $file = wp_handle_upload($_FILES['import'], $overrides); + + if ( isset($file['error']) ) + return $file; + + $url = $file['url']; + $file = addslashes( $file['file'] ); + $filename = basename($file); + + // Construct the object array + $object = array( + 'post_title' => $filename, + 'post_content' => $url, + 'post_mime_type' => 'import', + 'guid' => $url + ); + + // Save the data + $id = wp_insert_attachment($object, $file); + + return array('file' => $file, 'id' => $id); +} + +function user_can_richedit() { + if ( 'true' != get_user_option('rich_editing') ) + return false; + + if ( preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) ) + return false; + + return true; // Best guess +} + +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); + +?> +


    +

    +


    +

    + +


    +

    +


    +

    + + 4 / 3 ) + return array(128, (int) ($height / $width * 128)); + else + return array((int) ($width / $height * 96), 96); +} + +function autocomplete_css() { + ?> + + + + + diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php new file mode 100644 index 0000000..ee0c286 --- /dev/null +++ b/wp-admin/admin-header.php @@ -0,0 +1,41 @@ + + + + + +<?php bloginfo('name') ?> › <?php echo $title; ?> — WordPress + + + + + + + + +

    %s.'), $user_identity) ?> [, ]

    + + diff --git a/wp-admin/admin.php b/wp-admin/admin.php new file mode 100644 index 0000000..ffec08f --- /dev/null +++ b/wp-admin/admin.php @@ -0,0 +1,120 @@ +fetch( get_option( "siteurl" ) . "wp-admin/upgrade.php?step=1"); + } +} + + +require_once(ABSPATH . 'wp-admin/admin-functions.php'); +require_once(ABSPATH . 'wp-admin/admin-db.php'); +require_once(ABSPATH . WPINC . '/registration.php'); + +auth_redirect(); + +nocache_headers(); + +update_category_cache(); + +wp_get_current_user(); + +$posts_per_page = get_settings('posts_per_page'); +$what_to_show = get_settings('what_to_show'); +$date_format = get_settings('date_format'); +$time_format = get_settings('time_format'); + +$wpvarstoreset = array('profile','redirect','redirect_url','a','popuptitle','popupurl','text', 'trackback', 'pingback'); +for ($i=0; $i diff --git a/wp-admin/bookmarklet.php b/wp-admin/bookmarklet.php new file mode 100644 index 0000000..4345340 --- /dev/null +++ b/wp-admin/bookmarklet.php @@ -0,0 +1,104 @@ + + + + + + + +post_title = stripslashes($post_title); +else + $post->post_title = $popuptitle; + + +$content = wp_specialchars($_REQUEST['content']); +$popupurl = wp_specialchars($_REQUEST['popupurl']); + if ( !empty($content) ) { + $post->post_content = wp_specialchars( stripslashes($_REQUEST['content']) ); + } else { + $post->post_content = ''.$popuptitle.''."\n$text"; + } + + /* /big funky fixes */ + +?> + + +<?php bloginfo('name') ?> › Bookmarklet — WordPress + + + + + + + + + + + + + + diff --git a/wp-admin/cat-js.php b/wp-admin/cat-js.php new file mode 100644 index 0000000..08393b7 --- /dev/null +++ b/wp-admin/cat-js.php @@ -0,0 +1,35 @@ + +addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;}); +addLoadEvent(newCatAddIn); +function newCatAddIn() { + if ( !document.getElementById('jaxcat') ) return false; + var ajaxcat = document.createElement('span'); + ajaxcat.id = 'ajaxcat'; + + newcat = document.createElement('input'); + newcat.type = 'text'; + newcat.name = 'newcat'; + newcat.id = 'newcat'; + newcat.size = '16'; + newcat.setAttribute('autocomplete', 'off'); + newcat.onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','categorydiv');", e); }; + + var newcatSub = document.createElement('input'); + newcatSub.type = 'button'; + newcatSub.name = 'Button'; + newcatSub.id = 'catadd'; + newcatSub.value = 'Add'; + newcatSub.onclick = function() { catList.ajaxAdder('category', 'categorydiv'); }; + + ajaxcat.appendChild(newcat); + ajaxcat.appendChild(newcatSub); + document.getElementById('jaxcat').appendChild(ajaxcat); + + howto = document.createElement('span'); + howto.innerHTML = ""; + howto.id = 'howto'; + ajaxcat.appendChild(howto); +} diff --git a/wp-admin/categories.js b/wp-admin/categories.js new file mode 100644 index 0000000..46ae62f --- /dev/null +++ b/wp-admin/categories.js @@ -0,0 +1,5 @@ +addLoadEvent(newCategoryAddIn); +function newCategoryAddIn() { + if (!theList.theList) return false; + document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); }; +} diff --git a/wp-admin/categories.php b/wp-admin/categories.php new file mode 100644 index 0000000..3e33f0c --- /dev/null +++ b/wp-admin/categories.php @@ -0,0 +1,135 @@ +%s category: this is the default one"), $cat_name)); + + if ( $cat_ID == get_option('default_link_category') ) + die(sprintf(__("Can't delete the %s category: this is the default one for bookmarks"), $cat_name)); + + wp_delete_category($cat_ID); + + header('Location: categories.php?message=2'); + +break; + +case 'edit': + + require_once ('admin-header.php'); + $cat_ID = (int) $_GET['cat_ID']; + $category = get_category_to_edit($cat_ID); + include('edit-category-form.php'); + +break; + +case 'editedcat': + $cat_ID = (int) $_POST['cat_ID']; + check_admin_referer('update-category_' . $cat_ID); + + if ( !current_user_can('manage_categories') ) + die (__('Cheatin’ uh?')); + + wp_update_category($_POST); + + header('Location: categories.php?message=3'); +break; + +default: + +wp_enqueue_script( 'admin-categories' ); +require_once ('admin-header.php'); + +$messages[1] = __('Category added.'); +$messages[2] = __('Category deleted.'); +$messages[3] = __('Category updated.'); +?> + + +

    + + +
    + +

    add new)'), '#addcat') ?>

    + +

    + + + + + + + + + + + + + + + +
    + +
    + + +
    +

    Note:
    Deleting a category does not delete the posts and bookmarks in that category. Instead, posts in the deleted category are set to the category %s and bookmarks are set to %s.'), get_catname(get_option('default_category')), get_catname(get_option('default_link_category'))) ?>

    +

    Also Note:
    Categories will appear on your blog once you have posted something in them. Empty categories remain invisible.'); ?>

    +
    + + + + + diff --git a/wp-admin/comment.php b/wp-admin/comment.php new file mode 100644 index 0000000..a8be39e --- /dev/null +++ b/wp-admin/comment.php @@ -0,0 +1,209 @@ +Go back!'), 'javascript:history.go(-1)')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + die( __('You are not allowed to edit comments on this post.') ); + + $comment = get_comment_to_edit($comment); + + include('edit-form-comment.php'); + + break; + +case 'confirmdeletecomment': +case 'mailapprovecomment': + + require_once('./admin-header.php'); + + $comment = (int) $_GET['comment']; + $p = (int) $_GET['p']; + $formaction = 'confirmdeletecomment' == $action ? 'deletecomment' : 'approvecomment'; + $nonce_action = 'confirmdeletecomment' == $action ? 'delete-comment_' : 'approve-comment_'; + $nonce_action .= $comment; + + if ( ! $comment = get_comment($comment) ) + die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + die( 'confirmdeletecomment' == $action ? __('You are not allowed to delete comments on this post.') : __('You are not allowed to edit comments on this post, so you cannot approve this comment.') ); + + echo "
    \n"; + if ( 'spam' == $_GET['delete_type'] ) + echo "

    " . __('Caution: You are about to mark the following comment as spam:') . "

    \n"; + elseif ( 'confirmdeletecomment' == $action ) + echo "

    " . __('Caution: You are about to delete the following comment:') . "

    \n"; + else + echo "

    " . __('Caution: You are about to approve the following comment:') . "

    \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
    " . __('Author:') . "$comment->comment_author
    " . __('E-mail:') . "$comment->comment_author_email
    ". __('URL:') . "$comment->comment_author_url
    ". __('Comment:') . "$comment->comment_content
    \n"; + echo "

    " . __('Are you sure you want to do that?') . "

    \n"; + + echo "
    \n"; + wp_nonce_field($nonce_action); + echo "\n"; + if ( 'spam' == $_GET['delete_type'] ) + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo ""; + echo "  "; + echo "\n"; + echo "
    \n"; + echo "
    \n"; + + break; + +case 'deletecomment': + $comment = (int) $_REQUEST['comment']; + check_admin_referer('delete-comment_' . $comment); + + $p = (int) $_REQUEST['p']; + if ( isset($_REQUEST['noredir']) ) { + $noredir = true; + } else { + $noredir = false; + } + + $postdata = get_post($p) or + die(sprintf(__('Oops, no post with this ID. Go back!'), 'edit.php')); + + if ( ! $comment = get_comment($comment) ) + die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit-comments.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + die( __('You are not allowed to edit comments on this post.') ); + + if ( 'spam' == $_REQUEST['delete_type'] ) + wp_set_comment_status($comment->comment_ID, 'spam'); + else + wp_delete_comment($comment->comment_ID); + + if (($_SERVER['HTTP_REFERER'] != '') && (false == $noredir)) { + header('Location: ' . $_SERVER['HTTP_REFERER']); + } else { + header('Location: '. get_settings('siteurl') .'/wp-admin/edit-comments.php'); + } + exit(); + break; + +case 'unapprovecomment': + $comment = (int) $_GET['comment']; + check_admin_referer('unapprove-comment_' . $comment); + + $p = (int) $_GET['p']; + if (isset($_GET['noredir'])) { + $noredir = true; + } else { + $noredir = false; + } + + if ( ! $comment = get_comment($comment) ) + die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + die( __('You are not allowed to edit comments on this post, so you cannot disapprove this comment.') ); + + wp_set_comment_status($comment->comment_ID, "hold"); + + if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) { + header('Location: ' . $_SERVER['HTTP_REFERER']); + } else { + header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); + } + exit(); + break; + +case 'approvecomment': + $comment = (int) $_GET['comment']; + check_admin_referer('approve-comment_' . $comment); + + $p = (int) $_GET['p']; + if (isset($_GET['noredir'])) { + $noredir = true; + } else { + $noredir = false; + } + + if ( ! $comment = get_comment($comment) ) + die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + die( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') ); + + wp_set_comment_status($comment->comment_ID, "approve"); + if (get_settings("comments_notify") == true) { + wp_notify_postauthor($comment->comment_ID); + } + + + if (($_SERVER['HTTP_REFERER'] != "") && (false == $noredir)) { + header('Location: ' . $_SERVER['HTTP_REFERER']); + } else { + header('Location: '. get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); + } + exit(); + break; + +case 'editedcomment': + + $comment_ID = (int) $_POST['comment_ID']; + $comment_post_ID = (int) $_POST['comment_post_id']; + + check_admin_referer('update-comment_' . $comment_ID); + + edit_comment(); + + $referredby = $_POST['referredby']; + if (!empty($referredby)) { + header('Location: ' . $referredby); + } else { + header ("Location: edit.php?p=$comment_post_ID&c=1#comments"); + } + + break; +default: + break; +} // end switch + +include('admin-footer.php'); + +?> diff --git a/wp-admin/custom-fields.js b/wp-admin/custom-fields.js new file mode 100644 index 0000000..e86c87e --- /dev/null +++ b/wp-admin/custom-fields.js @@ -0,0 +1,26 @@ +function customFieldsOnComplete() { + var pidEl = document.getElementById('post_ID'); + pidEl.name = 'post_ID'; + pidEl.value = getNodeValue(theList.ajaxAdd.responseXML, 'postid'); + var aEl = document.getElementById('hiddenaction') + if ( aEl.value == 'post' ) aEl.value = 'postajaxpost'; +} +addLoadEvent(customFieldsAddIn); +function customFieldsAddIn() { + theList.showLink=0; + theList.addComplete = customFieldsOnComplete; + if (!theList.theList) return false; + inputs = theList.theList.getElementsByTagName('input'); + for ( var i=0; i < inputs.length; i++ ) { + if ('text' == inputs[i].type) { + inputs[i].setAttribute('autocomplete', 'off'); + inputs[i].onkeypress = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.name.slice(5),10) + '");', e); }; + } + if ('updatemeta' == inputs[i].className) { + inputs[i].onclick = function(e) {return killSubmit('theList.ajaxUpdater("meta", "meta-' + parseInt(this.parentNode.parentNode.id.slice(5),10) + '");', e); }; + } + } + + document.getElementById('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); }; + document.getElementById('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+document.getElementById("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); }; +} diff --git a/wp-admin/dbx-admin-key-js.php b/wp-admin/dbx-admin-key-js.php new file mode 100644 index 0000000..bca04ce --- /dev/null +++ b/wp-admin/dbx-admin-key-js.php @@ -0,0 +1,68 @@ + +addLoadEvent( function() {var manager = new dbxManager('');} ); + +addLoadEvent( function() +{ + //create new docking boxes group + var meta = new dbxGroup( + 'grabit', // container ID [/-_a-zA-Z0-9/] + 'vertical', // orientation ['vertical'|'horizontal'] + '10', // drag threshold ['n' pixels] + 'no', // restrict drag movement to container axis ['yes'|'no'] + '10', // animate re-ordering [frames per transition, or '0' for no effect] + 'yes', // include open/close toggle buttons ['yes'|'no'] + 'closed', // default state ['open'|'closed'] + 'open', // word for "open", as in "open this box" + 'close', // word for "close", as in "close this box" + 'click-down and drag to move this box', // sentence for "move this box" by mouse + 'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse + 'use the arrow keys to move this box', // sentence for "move this box" by keyboard + ', or press the enter key to %toggle% it', // pattern-match sentence-fragment for "(open|close) this box" by keyboard + '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts + ); + + // Boxes are closed by default. Open the Category box if the cookie isn't already set. + var catdiv = document.getElementById('categorydiv'); + if ( catdiv ) { + var button = catdiv.getElementsByTagName('A')[0]; + if ( dbx.cookiestate == null && /dbx\-toggle\-closed/.test(button.className) ) + meta.toggleBoxState(button, true); + } + + var advanced = new dbxGroup( + 'advancedstuff', // container ID [/-_a-zA-Z0-9/] + 'vertical', // orientation ['vertical'|'horizontal'] + '10', // drag threshold ['n' pixels] + 'yes', // restrict drag movement to container axis ['yes'|'no'] + '10', // animate re-ordering [frames per transition, or '0' for no effect] + 'yes', // include open/close toggle buttons ['yes'|'no'] + 'closed', // default state ['open'|'closed'] + 'open', // word for "open", as in "open this box" + 'close', // word for "close", as in "close this box" + 'click-down and drag to move this box', // sentence for "move this box" by mouse + 'click to %toggle% this box', // pattern-match sentence for "(open|close) this box" by mouse + 'use the arrow keys to move this box', // sentence for "move this box" by keyboard + ', or press the enter key to %toggle% it', // pattern-match sentence-fragment for "(open|close) this box" by keyboard + '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts + ); +}); diff --git a/wp-admin/edit-category-form.php b/wp-admin/edit-category-form.php new file mode 100644 index 0000000..9b700af --- /dev/null +++ b/wp-admin/edit-category-form.php @@ -0,0 +1,46 @@ +'; + $action = 'editedcat'; + $nonce_action = 'update-category_' . $cat_ID; +} else { + $heading = __('Add Category'); + $submit_text = __('Add Category »'); + $form = '
    '; + $action = 'addcat'; + $nonce_action = 'add-category'; +} +?> + +
    +

    + + + + + + + + + + + + + + + + + + +
    +
    + +

    +
    + +
    diff --git a/wp-admin/edit-comments.js b/wp-admin/edit-comments.js new file mode 100644 index 0000000..4dfe755 --- /dev/null +++ b/wp-admin/edit-comments.js @@ -0,0 +1,23 @@ +addLoadEvent(function() { + theCommentList = new listMan('the-comment-list'); + if ( !theCommentList ) + return false; + theCommentList.dimComplete = function(what,id,dimClass) { + var m = document.getElementById('awaitmod'); + if ( document.getElementById(what + '-' + id).className.match(dimClass) ) m.innerHTML = parseInt(m.innerHTML,10) + 1; + else m.innerHTML = parseInt(m.innerHTML,10) - 1; + } + theCommentList.delComplete = function(what,id) { + var m = document.getElementById('awaitmod'); + if ( document.getElementById(what + '-' + id).className.match('unapproved') ) m.innerHTML = parseInt(m.innerHTML,10) - 1; + } + if ( theList ) // the post list: edit.php + theList.delComplete = function() { + var comments = document.getElementById('comments'); + var commdel = encloseFunc(function(a){a.parentNode.removeChild(a);},comments); + var listdel = encloseFunc(function(a){a.parentNode.removeChild(a);},theCommentList.theList); + setTimeout(commdel,705); + setTimeout(listdel,705); + } +}); + diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php new file mode 100644 index 0000000..db8ad12 --- /dev/null +++ b/wp-admin/edit-comments.php @@ -0,0 +1,211 @@ + + + +
    +

    +
    +
    + + + + + +
    +
    +

    |

    +get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment"); + // $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") ); + if ( current_user_can('edit_post', $post_id) ) { + if ( !empty( $_POST['spam_button'] ) ) + wp_set_comment_status($comment, 'spam'); + else + wp_set_comment_status($comment, 'delete'); + ++$i; + } + endforeach; + echo '

    '; + if ( !empty( $_POST['spam_button'] ) ) + printf(__('%s comments marked as spam.'), $i); + else + printf(__('%s comments deleted.'), $i); + echo '

    '; +endif; + +if (isset($_GET['s'])) { + $s = $wpdb->escape($_GET['s']); + $comments = $wpdb->get_results("SELECT * 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"); +} else { + if ( isset($_GET['offset']) ) + $offset = (int) $_GET['offset'] * 20; + else + $offset = 0; + + $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $offset,20"); +} +if ('view' == $mode) { + if ($comments) { + if ($offset) + $start = " start='$offset'"; + else + $start = ''; + + echo "
      "; + $i = 0; + foreach ($comments as $comment) { + ++$i; $class = ''; + $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID")); + $comment_status = wp_get_comment_status($comment->comment_ID); + if ('unapproved' == $comment_status) + $class .= ' unapproved'; + if ($i % 2) + $class .= ' alternate'; + echo "
    1. "; +?> +

      comment_author_email) { ?>| comment_author_url && 'http://' != $comment->comment_author_url) { ?> | |

      + + + +

      — [ +comment_post_ID) ) { + echo " " . __('Edit') . ''; + echo ' | comment_author)) . "', theCommentList );\">" . __('Delete') . ' '; + if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) { + echo ' | ' . __('Unapprove') . ' '; + echo ' | ' . __('Approve') . ' '; + } + echo " | comment_post_ID . "&comment=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . sprintf(__("You are about to mark as spam this comment by "%s".\\n"Cancel" to stop, "OK" to mark as spam."), js_escape( $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . " "; +} +$post = get_post($comment->comment_post_ID); +$post_title = wp_specialchars( $post->post_title, 'double' ); +$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; +?> + | ]

      +
    2. + + +
    + +
    + + +

    +

    + + '; + wp_nonce_field('bulk-comments'); + echo ' + + + + + + + + + +'; + foreach ($comments as $comment) { + $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID")); + $comment_status = wp_get_comment_status($comment->comment_ID); + $class = ('alternate' == $class) ? '' : 'alternate'; + $class .= ('unapproved' == $comment_status) ? ' unapproved' : ''; +?> + + + + + + + + + + +
    ' . __('Name') . '' . __('E-mail') . '' . __('IP') . '' . __('Comment Excerpt') . '' . __('Actions') . '
    comment_post_ID) ) { ?> + + (Unapproved) + + + + comment_post_ID) ) { + echo "" . __('Edit') . ""; } ?>comment_post_ID) ) { + echo "comment_post_ID."&comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by "%s".\\n"Cancel" to stop, "OK" to delete."), js_escape( $comment->comment_author )) . "', theCommentList );\" class='delete'>" . __('Delete') . " "; + } ?>
    +

    '); return false } return confirm('')" /> + ')" />

    + +
    + +

    + +

    + + +
    + + diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php new file mode 100644 index 0000000..894e239 --- /dev/null +++ b/wp-admin/edit-form-advanced.php @@ -0,0 +1,237 @@ + + +

    + + +
    + + + + +
    +

    +

    +"; + wp_nonce_field('add-post'); +} else { + $form_action = 'editpost'; + $form_extra = ""; + wp_nonce_field('update-post_' . $post_ID); +} + +$form_pingback = ''; + +$form_prevstatus = ''; + +$form_trackback = 'to_ping) .'" />'; + +if ('' != $post->pinged) { + $pings = '

    '. __('Already pinged:') . '

      '; + $already_pinged = explode("\n", trim($post->pinged)); + foreach ($already_pinged as $pinged_url) { + $pings .= "\n\t
    • $pinged_url
    • "; + } + $pings .= '
    '; +} + +$saveasdraft = ''; + +if (empty($post->post_status)) $post->post_status = 'draft'; + +?> + + + + + + + + $_GET['message']) : ?> + + + +
    + +
    +
    + +
    +

    +
    +

    + +
    + + +
    +
    +
    + +
    +

    +
    + + + +
    +
    + +
    +

    +
    +
    + +
    +

    +
    +
    + +
    +

    +
    + + + +
    +
    + + +
    +

    :

    +
    +
    + + +id ) ) : // TODO: ROLE SYSTEM ?> +
    +

    :

    +
    + +
    +
    + + + + +
    +
    + +
    + +
    +
    + +
    + + + post_content); ?> + + + + + +

    +post_status || 0 == $post_ID) { +?> + + + + +

    + + + +' . __('This feature requires iframe support.') . ''; +} +?> + +
    + +
    +

    +
    +
    + +
    +

    +
    : () + +
    +
    + +
    +

    +
    + + + +
    + +
    +
    +
    + + + +
    + + +post_title) ) . "') ) { document.forms.post._wpnonce.value = '$delete_nonce'; return true;}return false;\""; ?> /> + + +
    + +
    + +
    diff --git a/wp-admin/edit-form-ajax-cat.php b/wp-admin/edit-form-ajax-cat.php new file mode 100644 index 0000000..4a4665c --- /dev/null +++ b/wp-admin/edit-form-ajax-cat.php @@ -0,0 +1,37 @@ + diff --git a/wp-admin/edit-form-comment.php b/wp-admin/edit-form-comment.php new file mode 100644 index 0000000..1f23cef --- /dev/null +++ b/wp-admin/edit-form-comment.php @@ -0,0 +1,80 @@ +comment_ID); +$form_action = 'editedcomment'; +$form_extra = "' />\n\ncomment_ID) ?> +
    + + + + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    + +
    + + comment_content, 'content', 'newcomment_author_url'); ?> +
    + +

    + +

    + +
    + +
    +

    + + + + + + + + + + + + + + + + + + +
    :
    +
    +
    :
    : /> + + + +
    + +
    + + diff --git a/wp-admin/edit-form.php b/wp-admin/edit-form.php new file mode 100644 index 0000000..dd4bc75 --- /dev/null +++ b/wp-admin/edit-form.php @@ -0,0 +1,75 @@ + +
    +

    +
    + + + + + + + + + +
    +
    + +
    +
    + +
    + +
    post_category); ?>
    +
    + +
    +
    + + + 100)) { + $rows = 10; + } +?> +
    +
    + + + + + + +

    (Separate multiple URIs with spaces.)
    '), 'http://wordpress.org/docs/reference/post/#trackback') ?> +

    + +

    + + + + + + +'; + } ?> + +

    + + + +
    +
    + +
    diff --git a/wp-admin/edit-link-form.php b/wp-admin/edit-link-form.php new file mode 100644 index 0000000..faa4956 --- /dev/null +++ b/wp-admin/edit-link-form.php @@ -0,0 +1,257 @@ +'; + $nonce_action = 'update-bookmark_' . $link_id; +} else { + $heading = __('Create Bookmark'); + $submit_text = __('Add Bookmark »'); + $form = ' diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php new file mode 100644 index 0000000..530f979 --- /dev/null +++ b/wp-admin/edit-page-form.php @@ -0,0 +1,194 @@ + +
    +

    +

    +"; +} else { + $form_action = 'editpost'; + $nonce_action = 'update-page_' . $post_ID; + $form_extra = ""; +} + +$sendto = $_SERVER['HTTP_REFERER']; + +if ( 0 != $post_ID && $sendto == get_permalink($post_ID) ) + $sendto = 'redo'; +$sendto = wp_specialchars( $sendto ); + +?> + +
    + +'; +} +?> + + + + + + +
    + +
    +
    +
    +

    +
    + + + +
    +
    + +
    +

    +
    + + + +
    +
    + +
    +

    +
    +
    + +
    +

    +

    +
    +
    + + +
    +

    +

    +
    +
    + + +
    +

    +
    +
    + +id ) ) : // TODO: ROLE SYSTEM ?> +
    +

    :

    +
    + +
    +
    + + +
    +

    +

    +
    + + + +
    +
    + +
    + +
    +
    + + +
    + + post_content); ?> +
    + +

    + + +post_status || 0 == $post_ID): +?> + + + + +

    + + + +' . __('This feature requires iframe support.') . ''; +} +?> + +
    + +
    +

    +
    + + + +
    + +
    +
    + + + +
    + +ID) ) ?> + escape($post->post_title) ) . "')\""; ?> /> + + + +
    + +
    diff --git a/wp-admin/edit-pages.php b/wp-admin/edit-pages.php new file mode 100644 index 0000000..ce169b8 --- /dev/null +++ b/wp-admin/edit-pages.php @@ -0,0 +1,62 @@ + + +
    +

    +

    + +
    +
    + + + +
    +
    + + + + + + + + + + + + + + + +
    + +
    + + +

    + + +

    + +
    + + diff --git a/wp-admin/edit.php b/wp-admin/edit.php new file mode 100644 index 0000000..a39338d --- /dev/null +++ b/wp-admin/edit.php @@ -0,0 +1,296 @@ + +
    + +

    + post_title = stripslashes($draft->post_title); + if ($draft->post_title == '') + $draft->post_title = sprintf(__('Post #%s'), $draft->ID); + echo "$draft->post_title"; + ++$i; + } + ?> + .

    + + + +

    + post_title = stripslashes($draft->post_title); + if ($draft->post_title == '') + $draft->post_title = sprintf(__('Post #%s'), $draft->ID); + echo "$draft->post_title"; + ++$i; + } + ?> + .

    + + + +
    + + +
    +

    +post_title); + elseif ( ! is_paged() || get_query_var('paged') == 1 ) + _e('Last 15 Posts'); + else + _e('Previous Posts'); +} +?> +

    + +
    +
    + + + +
    +
    + +get_results("SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'post' ORDER BY post_date DESC"); + +if ( count($arc_result) ) { ?> + +
    +
    + + + +
    +
    + + + +
    + + 'display name' +$posts_columns = array( + 'id' => __('ID'), + 'date' => __('When'), + 'title' => __('Title'), + 'categories' => __('Categories'), + 'comments' => __('Comments'), + 'author' => __('Author') +); +$posts_columns = apply_filters('manage_posts_columns', $posts_columns); + +// you can not edit these at the moment +$posts_columns['control_view'] = ''; +$posts_columns['control_edit'] = ''; +$posts_columns['control_delete'] = ''; + +?> + + + + + + + + + + + + + + + +$column_display_name) { + + switch($column_name) { + + case 'id': + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    g:i:s a'); ?> + post_status) _e(' - Private'); ?> + + ID) ) { echo "" . __('Edit') . ""; } ?>ID) ) { echo "ID) . "' class='delete' onclick=\"return deleteSomething( 'post', " . $id . ", '" . sprintf(__("You are about to delete this post "%s".\\n"OK" to delete, "Cancel" to stop."), js_escape(get_the_title()) ) . "' );\">" . __('Delete') . ""; } ?>
    + +
    + + + +get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved != 'spam' ORDER BY comment_date"); + if ($comments) { + ?> +

    +
      +get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID")); + $comment_status = wp_get_comment_status($comment->comment_ID); + if ('unapproved' == $comment_status) + $class .= ' unapproved'; + if ($i % 2) + $class .= ' alternate'; + echo "
    1. "; +?> +

      comment_author_email) { ?>| comment_author_url && 'http://' != $comment->comment_author_url) { ?> | |

      + + + +

      — [ +comment_post_ID) ) { + echo " " . __('Edit') . ''; + echo ' | comment_author)) . "', theCommentList );\">" . __('Delete') . ' '; + if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) { + echo ' | ' . __('Unapprove') . ' '; + echo ' | ' . __('Approve') . ' '; + } + echo " | comment_post_ID."&comment=".$comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . sprintf(__("You are about to mark as spam this comment by "%s".\\n"Cancel" to stop, "OK" to mark as spam."), js_escape( $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . " ]"; +} // end if any comments to show +?> +

      +
    2. + +'; + }//end if comments + ?> + +
    + diff --git a/wp-admin/export.php b/wp-admin/export.php new file mode 100644 index 0000000..8894f29 --- /dev/null +++ b/wp-admin/export.php @@ -0,0 +1,106 @@ + + +
    +

    +

    +

    We need some more text here. Maybe talking about the export file or how to save it.

    +
    +

    + +

    +
    +
    + +get_results("SELECT * FROM $wpdb->posts ORDER BY post_date_gmt ASC"); +?> + + + + + <?php bloginfo_rss('name'); ?> + + + + http://wordpress.org/?v= + + + + +<?php the_title_rss() ?> + + + + + + + +post_content ?>]]> +post_date; ?> +post_date_gmt; ?> +comment_status; ?> +ping_status; ?> +post_name; ?> +post_status; ?> +post_parent; ?> +post_type; ?> +get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID"); +if ( $postmeta ) { +?> + + +meta_key; ?> +meta_value; ?> + + + +get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID"); +if ( $comments ) { foreach ( $comments as $c ) { ?> + +comment_author; ?> +comment_author_email; ?> +comment_author_url; ?> +comment_author_IP; ?> +comment_date; ?> +comment_date_gmt; ?> +comment_content; ?> +comment_approved; ?> +comment_type; ?> +comment_parent; ?> + + + + + + + \ No newline at end of file diff --git a/wp-admin/images/box-bg.gif b/wp-admin/images/box-bg.gif new file mode 100644 index 0000000..2eb7f58 Binary files /dev/null and b/wp-admin/images/box-bg.gif differ diff --git a/wp-admin/images/box-butt.gif b/wp-admin/images/box-butt.gif new file mode 100644 index 0000000..514a165 Binary files /dev/null and b/wp-admin/images/box-butt.gif differ diff --git a/wp-admin/images/box-head.gif b/wp-admin/images/box-head.gif new file mode 100644 index 0000000..5c09a9a Binary files /dev/null and b/wp-admin/images/box-head.gif differ diff --git a/wp-admin/images/browse-happy.gif b/wp-admin/images/browse-happy.gif new file mode 100644 index 0000000..09f13bc Binary files /dev/null and b/wp-admin/images/browse-happy.gif differ diff --git a/wp-admin/images/fade-butt.png b/wp-admin/images/fade-butt.png new file mode 100644 index 0000000..42f08b7 Binary files /dev/null and b/wp-admin/images/fade-butt.png differ diff --git a/wp-admin/images/notice.gif b/wp-admin/images/notice.gif new file mode 100644 index 0000000..ba6eab0 Binary files /dev/null and b/wp-admin/images/notice.gif differ diff --git a/wp-admin/images/toggle.gif b/wp-admin/images/toggle.gif new file mode 100644 index 0000000..72e8b44 Binary files /dev/null and b/wp-admin/images/toggle.gif differ diff --git a/wp-admin/images/wordpress-logo.png b/wp-admin/images/wordpress-logo.png new file mode 100644 index 0000000..7d8e672 Binary files /dev/null and b/wp-admin/images/wordpress-logo.png differ diff --git a/wp-admin/import.php b/wp-admin/import.php new file mode 100644 index 0000000..cd1951a --- /dev/null +++ b/wp-admin/import.php @@ -0,0 +1,62 @@ + + +
    +

    +

    + +read()) !== false) { + if (preg_match('|^\.+$|', $file)) + continue; + if (preg_match('|\.php$|', $file)) + require_once("$import_root/$file"); + } +} + +$importers = get_importers(); + +if (empty ($importers)) { + echo '

    '.__('No importers are available.').'

    '; // TODO: make more helpful +} else { +?> + + + $data) { + $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate'; + $action = "{$data[0]}"; + + if ($style != '') + $style = 'class="'.$style.'"'; + echo " + + + + "; + } +?> + +
    $action{$data[1]}
    + + +
    + + + diff --git a/wp-admin/import/b2.php b/wp-admin/import/b2.php new file mode 100644 index 0000000..e69de29 diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php new file mode 100644 index 0000000..8de766c --- /dev/null +++ b/wp-admin/import/blogger.php @@ -0,0 +1,675 @@ +

    $title

    $welcome

    "; + if ( function_exists('curl_init') ) + echo "

    $reset

    "; + else + echo "

    $incompat

    "; + echo "\n"; + } + + function reencode($text) { + return $text; + return mb_convert_encoding($text, get_setting('blog_charset'), $this->import['blogs'][$_GET['blog']]['options']['blog-formatting']['backup']['encoding']); + } + + // Deletes saved data and redirect. + function restart() { + delete_option('import-blogger'); + header("Location: admin.php?import=blogger"); + die(); + } + + // Generates a string that will make the page reload in a specified interval. + function refresher($msec) { + if ( $msec ) + return "\n\n\n"; + else + return "\n\n\n"; + } + + // Returns associative array of code, header, cookies, body. Based on code from php.net. + function parse_response($this_response) { + // Split response into header and body sections + list($response_headers, $response_body) = explode("\r\n\r\n", $this_response, 2); + $response_header_lines = explode("\r\n", $response_headers); + + // First line of headers is the HTTP response code + $http_response_line = array_shift($response_header_lines); + if(preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@',$http_response_line, $matches)) { $response_code = $matches[1]; } + + // put the rest of the headers in an array + $response_header_array = array(); + foreach($response_header_lines as $header_line) { + list($header,$value) = explode(': ', $header_line, 2); + $response_header_array[$header] .= $value."\n"; + } + + $cookie_array = array(); + $cookies = explode("\n", $response_header_array["Set-Cookie"]); + foreach($cookies as $this_cookie) { array_push($cookie_array, "Cookie: ".$this_cookie); } + + return array("code" => $response_code, "header" => $response_header_array, "cookies" => $cookie_array, "body" => $response_body); + } + + // Prints a form for the user to enter Blogger creds. + function login_form($text='') { + echo '

    ' . __('Log in to Blogger') . "

    \n$text\n"; + echo '
    ' . __('Username') . ':
    ' . __('Password') . ':
    '; + die; + } + + // Sends creds to Blogger, returns the session cookies an array of headers. + function login_blogger($user, $pass) { + $_url = 'http://www.blogger.com/login.do'; + $params = "username=$user&password=$pass"; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST,1); + curl_setopt($ch, CURLOPT_POSTFIELDS,$params); + curl_setopt($ch, CURLOPT_URL,$_url); + curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); + curl_setopt($ch, CURLOPT_HEADER,1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + $response = curl_exec ($ch); + + $response = $this->parse_response($response); + + sleep(1); + + return $response['cookies']; + } + + // Requests page from Blogger, returns the response array. + function get_blogger($url, $header = '', $user=false, $pass=false) { + $ch = curl_init(); + if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}"); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); + curl_setopt($ch, CURLOPT_HEADER,1); + if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + $response = curl_exec ($ch); + + $response = $this->parse_response($response); + $response['url'] = $url; + + if (curl_errno($ch)) { + print curl_error($ch); + } else { + curl_close($ch); + } + + return $response; + } + + // Posts data to Blogger, returns response array. + function post_blogger($url, $header = false, $paramary = false, $parse=true) { + $params = ''; + if ( is_array($paramary) ) { + foreach($paramary as $key=>$value) + if($key && $value != '') + $params.=$key."=".urlencode(stripslashes($value))."&"; + } + if ($user && $pass) $params .= "username=$user&password=$pass"; + $params = trim($params,'&'); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_POST,1); + curl_setopt($ch, CURLOPT_POSTFIELDS,$params); + if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}"); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_HEADER,$parse); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); + if ($header) curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + $response = curl_exec ($ch); + + if ($parse) { + $response = $this->parse_response($response); + $response['url'] = $url; + return $response; + } + + return $response; + } + + // Prints the list of blogs for import. + function show_blogs() { + global $import; + echo '

    ' . __('Selecting a Blog') . "

    \n
      "; + foreach ( $this->import['blogs'] as $blog ) { + if (9 == $blog['nextstep']) $status = "100%"; + elseif (8 == $blog['nextstep']) $status = "90%"; + elseif (7 == $blog['nextstep']) $status = "82.5%"; + elseif (6 == $blog['nextstep']) $status = "75%"; + elseif (5 == $blog['nextstep']) $status = "57%"; + elseif (4 == $blog['nextstep']) $status = "28%"; + elseif (3 == $blog['nextstep']) $status = "14%"; + else $status = "0%"; + echo "\t
    • {$blog['title']} $status
    • \n"; + } + die("
    \n"); + } + + // Publishes. + function publish_blogger($i, $text) { + $head = $this->refresher(2000) . "

    $text

    \n"; + if ( ! strstr($this->import['blogs'][$_GET['blog']]['publish'][$i], 'http') ) { + // First call. Start the publish process with a fresh set of cookies. + $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']); + update_option('import-blogger', $this->import); + $paramary = array('blogID' => $_GET['blog'], 'all' => '1', 'republishAll' => 'Republish Entire Blog', 'publish' => '1', 'redirectUrl' => "/publish.do?blogID={$_GET['blog']}&inprogress=true"); + + $response = $this->post_blogger("http://www.blogger.com/publish.do?blogID={$_GET['blog']}", $this->import['cookies'], $paramary); + if ( $response['code'] == '302' ) { + $url = str_replace('publish.g', 'publish-body.g', $response['header']['Location']); + $this->import['blogs'][$_GET['blog']]['publish'][$i] = $url; + update_option('import-blogger', $this->import); + $response = $this->get_blogger($url, $this->import['cookies']); + preg_match('#

    .*

    #U', $response['body'], $matches); + $progress = $matches[0]; + die($head . $progress); + } else { + $this->import['blogs'][$_GET['blog']]['publish'][$i] = false; + update_option('import-blogger', $this->import); + die($head); + } + } else { + // Subsequent call. Keep checking status until Blogger reports publish complete. + $url = $this->import['blogs'][$_GET['blog']]['publish'][$i]; + $response = $this->get_blogger($url, $this->import['cookies']); + if ( preg_match('#

    .*

    #U', $response['body'], $matches) ) { + $progress = $matches[0]; + if ( strstr($progress, '100%') ) { + $this->set_next_step($i); + $progress .= '

    '.__('Moving on...').'

    '; + } + die($head . $progress); + } else { + $this->import['blogs'][$_GET['blog']]['publish'][$i] = false; + update_option('import-blogger', $this->import); + die("$head

    " . __('Trying again...') . '

    '); + } + } + } + + // Sets next step, saves options + function set_next_step($step) { + $this->import['blogs'][$_GET['blog']]['nextstep'] = $step; + update_option('import-blogger', $this->import); + } + + // Redirects to next step + function do_next_step() { + header("Location: admin.php?import=blogger&noheader=true&blog={$_GET['blog']}"); + die(); + } + + // Step 0: Do Blogger login, get blogid/title pairs. + function do_login() { + if ( ( ! $this->import['user'] && ! is_array($this->import['cookies']) ) ) { + // The user must provide a Blogger username and password. + if ( ! ( $_POST['user'] && $_POST['pass'] ) ) { + $this->login_form(__('The script will log into your Blogger account, change some settings so it can read your blog, and restore the original settings when it\'s done. Here\'s what you do:').'

    1. '.__('Back up your Blogger template.').'
    2. '.__('Back up any other Blogger settings you might need later.').'
    3. '.__('Log out of Blogger').'
    4. '.__('Log in here with your Blogger username and password.').'
    5. '.__('On the next screen, click one of your Blogger blogs.').'
    6. '.__('Do not close this window or navigate away until the process is complete.').'
    '); + } + + // Try logging in. If we get an array of cookies back, we at least connected. + $this->import['cookies'] = $this->login_blogger($_POST['user'], $_POST['pass']); + if ( !is_array( $this->import['cookies'] ) ) { + $this->login_form(__('Login failed. Please enter your credentials again.')); + } + + // Save the password so we can log the browser in when it's time to publish. + $this->import['pass'] = $_POST['pass']; + $this->import['user'] = $_POST['user']; + + // Get the Blogger welcome page and scrape the blog numbers and names from it + $response = $this->get_blogger('http://www.blogger.com/home', $this->import['cookies']); + if (! stristr($response['body'], 'signed in as') ) $this->login_form(__('Login failed. Please re-enter your username and password.')); + $blogsary = array(); + preg_match_all('#posts\.g\?blogID=(\d+)">([^<]+)#U', $response['body'], $blogsary); + if ( ! count( $blogsary[1] < 1 ) ) + die(__('No blogs found for this user.')); + $this->import['blogs'] = array(); + $template = ''; + foreach ( $blogsary[1] as $key => $id ) { + // Define the required Blogger options. + $blog_opts = array( + 'blog-options-basic' => false, + 'blog-options-archiving' => array('archiveFrequency' => 'm'), + 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false'), + 'blog-formatting' => array('timeStampFormat' => '0', 'convertLineBreaks'=>'false', 'floatAlignment'=>'false'), + 'blog-comments' => array('commentsTimeStampFormat' => '0'), + 'template-edit' => array( 'templateText' => str_replace('%title%', trim($blogsary[2][$key]), $template) ) + ); + + // Build the blog options array template + foreach ($blog_opts as $blog_opt => $modify) + $new_opts["$blog_opt"] = array('backup'=>false, 'modify' => $modify, 'error'=>false); + + $this->import['blogs']["$id"] = array( + 'id' => $id, + 'title' => trim($blogsary[2][$key]), + 'options' => $new_opts, + 'url' => false, + 'publish_cookies' => false, + 'published' => false, + 'archives' => false, + 'lump_authors' => false, + 'newusers' => array(), + 'nextstep' => 2 + ); + } + update_option('import-blogger', $this->import); + header("Location: admin.php?import=blogger&noheader=true&step=1"); + } + die(); + } + + // Step 1: Select one of the blogs belonging to the user logged in. + function select_blog() { + if ( is_array($this->import['blogs']) ) { + $this->show_blogs(); + die(); + } else { + $this->restart(); + } + } + + // Step 2: Backup the Blogger options pages, updating some of them. + function backup_settings() { + $output.= '

    '.__('Backing up Blogger options')."

    \n"; + $form = false; + foreach ($this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary) { + if ( $blog_opt == $_GET['form'] ) { + // Save the posted form data + $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] = $_POST; + update_option('import-blogger',$this->import); + + // Post the modified form data to Blogger + if ( $optary['modify'] ) { + $posturl = "http://www.blogger.com/{$blog_opt}.do"; + $headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']); + if ( 'blog-publishing' == $blog_opt ) { + if ( $_POST['publishMode'] > 0 ) { + $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode=0", $headers); + if ( $response['code'] >= 400 ) + die('

    '.__('Failed attempt to change publish mode from FTP to BlogSpot.').'

    ' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '
    '); + $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $optary['modify']['subdomain'] . '.blogspot.com/'; + sleep(2); + } else { + $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $_POST['subdomain'] . '.blogspot.com/'; + update_option('import-blogger', $this->import); + $output .= "

    $blog_opt

    \n"; + continue; + } + $paramary = $optary['modify']; + } elseif ( 'template-edit' == $blog_opt ) { + $optary['modify']['templateText'] = $_POST['templateText'] . $optary['modify']['templateText']; + $paramary = array_merge($_POST, $optary['modify']); + } else { + $paramary = array_merge($_POST, $optary['modify']); + } + $response = $this->post_blogger($posturl, $headers, $paramary); + if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) + die('

    '.__('Error on form submission. Retry or reset the importer.').'

    ' . addslashes(print_r($response, 1))); + } + $output .= "

    $blog_opt

    \n"; + } elseif ( is_array($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup']) ) { + // This option set has already been backed up. + $output .= "

    $blog_opt

    \n"; + } elseif ( ! $form ) { + // This option page needs to be downloaded and given to the browser for submission back to this script. + $response = $this->get_blogger("http://www.blogger.com/{$blog_opt}.g?blogID={$_GET['blog']}", $this->import['cookies']); + $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'] = $response['cookies']; + update_option('import-blogger',$this->import); + $body = $response['body']; + $body = preg_replace("|\]*>|ms","",$body); + $body = preg_replace("|/?{$blog_opt}.do|","admin.php?import=blogger&noheader=true&step=2&blog={$_GET['blog']}&form={$blog_opt}",$body); + $body = str_replace("name='submit'","name='supermit'",$body); + $body = str_replace('name="submit"','name="supermit"',$body); + $body = str_replace('','',str_replace('','',$body)); + $form = "
    "; + $form.= $body; + $form.= "
    "; + $output.= '

    '.sprintf('%s in progress, please wait...', $blog_opt)."

    \n"; + } else { + $output.= "

    $blog_opt

    \n"; + } + } + if ( $form ) + die($output . $form); + + $this->set_next_step(4); + $this->do_next_step(); + } + + // Step 3: Cancelled :-) + + // Step 4: Publish with the new template and settings. + function publish_blog() { + $this->publish_blogger(5, __('Publishing with new template and options')); + } + + // Step 5: Get the archive URLs from the new blog. + function get_archive_urls() { + $bloghtml = $this->get_blogger($this->import['blogs'][$_GET['blog']]['url']); + if (! strstr($bloghtml['body'], 'import['blogs'][$_GET['blog']]['archives'][$archive] = false; + } + $this->set_next_step(6); + $this->do_next_step(); + } + + // Step 6: Get each monthly archive, import it, mark it done. + function get_archive() { + global $wpdb; + $output = '

    '.__('Importing Blogger archives into WordPress').'

    '; + $did_one = false; + $post_array = $posts = array(); + foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) { + $archivename = substr(basename($url),0,7); + if ( $status || $did_one ) { + $foo = 'bar'; + // Do nothing. + } else { + // Import the selected month + $postcount = 0; + $skippedpostcount = 0; + $commentcount = 0; + $skippedcommentcount = 0; + $status = __('in progress...'); + $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status; + update_option('import-blogger', $import); + $archive = $this->get_blogger($url); + if ( $archive['code'] > 200 ) + continue; + $posts = explode('', $archive['body']); + for ($i = 1; $i < count($posts); $i = $i + 1) { + $postparts = explode('', $posts[$i]); + $postinfo = explode('|W|P|', $postparts[0]); + $post_date = $postinfo[0]; + $post_content = $postinfo[2]; + // Don't try to re-use the original numbers + // because the new, longer numbers are too + // big to handle as ints. + //$post_number = $postinfo[3]; + $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3]; + $post_author_name = $wpdb->escape(trim($postinfo[1])); + $post_author_email = $postinfo[5] ? $postinfo[5] : 'user@wordpress.org'; + + if ( $this->lump_authors ) { + // Ignore Blogger authors. Use the current user_ID for all posts imported. + $post_author = $GLOBALS['user_ID']; + } else { + // Add a user for each new author encountered. + if (! username_exists($post_author_name) ) { + $user_login = $wpdb->escape($post_author_name); + $user_email = $wpdb->escape($post_author_email); + $user_password = substr(md5(uniqid(microtime())), 0, 6); + $result = wp_create_user( $user_login, $user_password, $user_email ); + $status.= sprintf('Registered user %s.', $user_login); + $this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login; + } + $userdata = get_userdatabylogin( $post_author_name ); + $post_author = $userdata->ID; + } + $post_date = explode(' ', $post_date); + $post_date_Ymd = explode('/', $post_date[0]); + $postyear = $post_date_Ymd[2]; + $postmonth = zeroise($post_date_Ymd[0], 2); + $postday = zeroise($post_date_Ymd[1], 2); + $post_date_His = explode(':', $post_date[1]); + $posthour = zeroise($post_date_His[0], 2); + $postminute = zeroise($post_date_His[1], 2); + $postsecond = zeroise($post_date_His[2], 2); + + if (($post_date[2] == 'PM') && ($posthour != '12')) + $posthour = $posthour + 12; + else if (($post_date[2] == 'AM') && ($posthour == '12')) + $posthour = '00'; + + $post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond"; + + $post_content = addslashes($this->reencode($post_content)); + $post_content = str_replace(array('
    ','
    ','
    ','
    ','
    ','
    '), "\n", $post_content); // the XHTML touch... ;) + + $post_title = addslashes($this->reencode($post_title)); + + $post_status = 'publish'; + + if ( $ID = post_exists($post_title, '', $post_date) ) { + $post_array[$i]['ID'] = $ID; + $skippedpostcount++; + } else { + $post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status'); + $post_array[$i]['comments'] = false; + } + + // Import any comments attached to this post. + if ($postparts[1]) : + for ($j = 1; $j < count($postparts); $j = $j + 1) { + $commentinfo = explode('|W|P|', $postparts[$j]); + $comment_date = explode(' ', $commentinfo[0]); + $comment_date_Ymd = explode('/', $comment_date[0]); + $commentyear = $comment_date_Ymd[2]; + $commentmonth = zeroise($comment_date_Ymd[0], 2); + $commentday = zeroise($comment_date_Ymd[1], 2); + $comment_date_His = explode(':', $comment_date[1]); + $commenthour = zeroise($comment_date_His[0], 2); + $commentminute = zeroise($comment_date_His[1], 2); + $commentsecond = '00'; + if (($comment_date[2] == 'PM') && ($commenthour != '12')) + $commenthour = $commenthour + 12; + else if (($comment_date[2] == 'AM') && ($commenthour == '12')) + $commenthour = '00'; + $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond"; + $comment_author = addslashes($this->reencode(strip_tags($commentinfo[1]))); + if ( strpos($commentinfo[1], 'a href') ) { + $comment_author_parts = explode('"', htmlentities($commentinfo[1])); + $comment_author_url = $comment_author_parts[1]; + } else $comment_author_url = ''; + $comment_content = $this->reencode($commentinfo[2]); + $comment_content = str_replace(array('
    ','
    ','
    ','
    ','
    ','
    '), "\n", $comment_content); + $comment_approved = 1; + if ( comment_exists($comment_author, $comment_date) ) { + $skippedcommentcount++; + } else { + $comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved'); + $post_array[$i]['comments'][$j] = wp_filter_comment($comment); + } + $commentcount++; + } + endif; + $postcount++; + } + if ( count($post_array) ) { + krsort($post_array); + foreach($post_array as $post) { + if ( ! $comment_post_ID = $post['ID'] ) + $comment_post_ID = wp_insert_post($post['post']); + if ( $post['comments'] ) { + foreach ( $post['comments'] as $comment ) { + $comment['comment_post_ID'] = $comment_post_ID; + wp_insert_comment($comment); + } + } + } + } + $status = sprintf(__('%s post(s) parsed, %s skipped...'), $postcount, $skippedpostcount).' '. + sprintf(__('%s comment(s) parsed, %s skipped...'), $commentcount, $skippedcommentcount).' '. + ' '.__('Done').''; + $import = $this->import; + $import['blogs'][$_GET['blog']]['archives']["$url"] = $status; + update_option('import-blogger', $import); + $did_one = true; + } + $output.= "

    $archivename $status

    \n"; + } + if ( ! $did_one ) + $this->set_next_step(7); + die( $this->refresher(1000) . $output ); + } + + // Step 7: Restore the backed-up settings to Blogger + function restore_settings() { + $output = '

    '.__('Restoring your Blogger options')."

    \n"; + $did_one = false; + // Restore options in reverse order. + if ( ! $this->import['reversed'] ) { + $this->import['blogs'][$_GET['blog']]['options'] = array_reverse($this->import['blogs'][$_GET['blog']]['options'], true); + $this->import['reversed'] = true; + update_option('import-blogger', $this->import); + } + foreach ( $this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary ) { + if ( $did_one ) { + $output .= "

    $blog_opt

    \n"; + } elseif ( $optary['restored'] || ! $optary['modify'] ) { + $output .= "

    $blog_opt

    \n"; + } else { + $posturl = "http://www.blogger.com/{$blog_opt}.do"; + $headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']); + if ( 'blog-publishing' == $blog_opt) { + if ( $optary['backup']['publishMode'] > 0 ) { + $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode={$optary['backup']['publishMode']}", $headers); + sleep(2); + if ( $response['code'] >= 400 ) + die('

    Error restoring publishMode.

    Please tell the devs.

    ' . addslashes(print_r($response, 1)) ); + } + } + if ( $optary['backup'] != $optary['modify'] ) { + $response = $this->post_blogger($posturl, $headers, $optary['backup']); + if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) { + $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['error'] = true; + update_option('import-blogger', $this->import); + $output .= sprintf(__('%s failed. Trying again.'), "

    $blog_opt ").'

    '; + } else { + $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true; + update_option('import-blogger', $this->import); + $output .= sprintf(__('%s restored.'), "

    $blog_opt ").'

    '; + } + } + $did_one = true; + } + } + + if ( $did_one ) { + die( $this->refresher(1000) . $output ); + } elseif ( $this->import['blogs'][$_GET['blog']]['options']['blog-publishing']['backup']['publishMode'] > 0 ) { + $this->set_next_step(9); + } else { + $this->set_next_step(8); + } + + $this->do_next_step(); + } + + // Step 8: Republish, all back to normal + function republish_blog() { + $this->publish_blogger(9, __('Publishing with original template and options')); + } + + // Step 9: Congratulate the user + function congrats() { + echo '

    '.__('Congratulations!').'

    '.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'

    '; + } + + // Figures out what to do, then does it. + function start() { + if ( $_GET['restart'] == 'true' ) { + $this->restart(); + } + + if ( isset($_GET['noheader']) ) { + header('Content-Type: text/html; charset=utf-8'); + + $this->import = get_settings('import-blogger'); + + if ( false === $this->import ) { + $step = 0; + } elseif ( isset($_GET['step']) ) { + $step = (int) $_GET['step']; + } elseif ( isset($_GET['blog']) && isset($this->import['blogs'][$_GET['blog']]['nextstep']) ) { + $step = $this->import['blogs'][$_GET['blog']]['nextstep']; + } elseif ( is_array($this->import['blogs']) ) { + $step = 1; + } else { + $step = 0; + } +//echo "Step $step."; +//die('
    '.print_r($this->import,1).'do_login();
    +					break;
    +				case 1 :
    +					$this->select_blog();
    +					break;
    +				case 2 :
    +					$this->backup_settings();
    +					break;
    +				case 3 :
    +					$this->wait_for_blogger();
    +					break;
    +				case 4 :
    +					$this->publish_blog();
    +					break;
    +				case 5 :
    +					$this->get_archive_urls();
    +					break;
    +				case 6 :
    +					$this->get_archive();
    +					break;
    +				case 7 :
    +					$this->restore_settings();
    +					break;
    +				case 8 :
    +					$this->republish_blog();
    +					break;
    +				case 9 :
    +					$this->congrats();
    +					break;
    +			}
    +			die;
    +
    +		} else {
    +			$this->greet();
    +		}
    +	}
    +
    +	function Blogger_Import() {
    +		// This space intentionally left blank.
    +	}
    +}
    +
    +$blogger_import = new Blogger_Import();
    +
    +register_importer('blogger', 'Blogger and Blogspot', __('Import posts and comments from your Blogger account'), array ($blogger_import, 'start'));
    +
    +?>
    diff --git a/wp-admin/import/blogware.php b/wp-admin/import/blogware.php
    new file mode 100644
    index 0000000..35ab610
    --- /dev/null
    +++ b/wp-admin/import/blogware.php
    @@ -0,0 +1,192 @@
    +';
    +		echo '

    '.__('Import Blogware').'

    '; + } + + function footer() { + echo ''; + } + + function unhtmlentities($string) { // From php.net for < 4.3 compat + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } + + function greet() { + echo '

    '.__('Howdy! This importer allows you to extract posts from Blogware XML export file into your blog. Pick a Blogware file to upload and click Import.').'

    '; + wp_import_upload_form("admin.php?import=blogware&step=1"); + } + + function import_posts() { + global $wpdb, $current_user; + + set_magic_quotes_runtime(0); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); + + preg_match_all('|(]+>(.*?))|is', $importdata, $posts); + $posts = $posts[1]; + unset($importdata); + echo '
      '; + foreach ($posts as $post) { + flush(); + preg_match('||is', $post, $post_type); + $post_type = $post_type[1]; + if($post_type == "photo") { + preg_match('|(.*?)|is', $post, $post_title); + } else { + preg_match('|(.*?)|is', $post, $post_title); + } + $post_title = $wpdb->escape(trim($post_title[1])); + + preg_match('|(.*?)|is', $post, $post_date); + $post_date = strtotime($post_date[1]); + $post_date = gmdate('Y-m-d H:i:s', $post_date); + + preg_match_all('|(.*?)|is', $post, $categories); + $categories = $categories[1]; + + $cat_index = 0; + foreach ($categories as $category) { + $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category)); + $cat_index++; + } + + if(strcasecmp($post_type, "photo") === 0) { + preg_match('|(.*?)|is', $post, $post_content); + $post_content = ''; + $post_content = $this->unhtmlentities($post_content); + } else { + preg_match('|(.*?)|is', $post, $post_content); + $post_content = str_replace(array (''), '', trim($post_content[1])); + $post_content = $this->unhtmlentities($post_content); + } + + // Clean up content + $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + $post_content = $wpdb->escape($post_content); + + $post_author = $current_user->ID; + preg_match('|(.*?)|is', $post, $post_status); + $post_status = trim($post_status[1]); + + echo '
    1. '; + if ($post_id = post_exists($post_title, $post_content, $post_date)) { + printf(__('Post %s already exists.'), stripslashes($post_title)); + } else { + printf(__('Importing post %s...'), stripslashes($post_title)); + $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status'); + $post_id = wp_insert_post($postdata); + if (!$post_id) { + _e("Couldn't get post ID"); + echo '
    2. '; + break; + } + if(0 != count($categories)) + wp_create_categories($categories, $post_id); + } + + preg_match_all('|(.*?)|is', $post, $comments); + $comments = $comments[1]; + + if ( $comments ) { + $comment_post_ID = $post_id; + $num_comments = 0; + foreach ($comments as $comment) { + preg_match('|(.*?)|is', $comment, $comment_content); + $comment_content = str_replace(array (''), '', trim($comment_content[1])); + $comment_content = $this->unhtmlentities($comment_content); + + // Clean up content + $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content); + $comment_content = str_replace('
      ', '
      ', $comment_content); + $comment_content = str_replace('
      ', '
      ', $comment_content); + $comment_content = $wpdb->escape($comment_content); + + preg_match('|(.*?)|is', $comment, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + + preg_match('|(.*?)|is', $comment, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + + $comment_author_email = NULL; + + $comment_approved = 1; + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_comments++; + } + } + } + if ( $num_comments ) { + echo ' '; + printf(__('(%s comments)'), $num_comments); + } + echo ''; + flush(); + ob_flush(); + } + echo '
    '; + } + + function import() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo $file['error']; + return; + } + + $this->file = $file['file']; + $this->import_posts(); + wp_import_cleanup($file['id']); + + echo '

    '; + printf(__('All done. Have fun!'), get_option('home')); + echo '

    '; + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->import(); + break; + } + + $this->footer(); + } + + function BW_Import() { + // Nothing. + } +} + +$blogware_import = new BW_Import(); + +register_importer('blogware', 'Blogware', __('Import posts from Blogware'), array ($blogware_import, 'dispatch')); +?> diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php new file mode 100644 index 0000000..9dc8a6e --- /dev/null +++ b/wp-admin/import/dotclear.php @@ -0,0 +1,747 @@ +get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); + + return $name; + } +} + +if(!function_exists('get_comment_count')) +{ + function get_comment_count($post_ID) + { + global $wpdb; + return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + } +} + +if(!function_exists('link_cat_exists')) +{ + function link_cat_exists($catname) + { + global $wpdb; + return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"'); + } +} + +if(!function_exists('link_exists')) +{ + function link_exists($linkname) + { + global $wpdb; + return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"'); + } +} + +/* + Identify UTF-8 text + Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087 +*/ +// +// utf8 encoding validation developed based on Wikipedia entry at: +// http://en.wikipedia.org/wiki/UTF-8 +// +// Implemented as a recursive descent parser based on a simple state machine +// copyright 2005 Maarten Meijer +// +// This cries out for a C-implementation to be included in PHP core +// + function valid_1byte($char) { + if(!is_int($char)) return false; + return ($char & 0x80) == 0x00; + } + + function valid_2byte($char) { + if(!is_int($char)) return false; + return ($char & 0xE0) == 0xC0; + } + + function valid_3byte($char) { + if(!is_int($char)) return false; + return ($char & 0xF0) == 0xE0; + } + + function valid_4byte($char) { + if(!is_int($char)) return false; + return ($char & 0xF8) == 0xF0; + } + + function valid_nextbyte($char) { + if(!is_int($char)) return false; + return ($char & 0xC0) == 0x80; + } + + function valid_utf8($string) { + $len = strlen($string); + $i = 0; + while( $i < $len ) { + $char = ord(substr($string, $i++, 1)); + if(valid_1byte($char)) { // continue + continue; + } else if(valid_2byte($char)) { // check 1 byte + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } else if(valid_3byte($char)) { // check 2 bytes + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } else if(valid_4byte($char)) { // check 3 bytes + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } // goto next char + } + return true; // done + } + +function csc ($s) { + if (valid_utf8 ($s)) { + return $s; + } else { + return iconv(get_option ("dccharset"),"UTF-8",$s); + } +} + +function textconv ($s) { + return csc (preg_replace ('|(?)\s*\n|', ' ', $s)); +} + +/** + The Main Importer Class +**/ +class Dotclear_Import { + + function header() + { + echo '
    '; + echo '

    '.__('Import Dotclear').'

    '; + echo '

    '.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

    '; + } + + function footer() + { + echo '
    '; + } + + function greet() + { + echo '

    '.__('Howdy! This importer allows you to extract posts from a Dotclear database into your blog. Mileage may vary.').'

    '; + echo '

    '.__('Your Dotclear Configuration settings are as follows:').'

    '; + echo '
    '; + $this->db_form(); + echo ''; + echo '
    '; + } + + function get_dc_cats() + { + global $wpdb; + // General Housekeeping + $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); + set_magic_quotes_runtime(0); + $dbprefix = get_option('dcdbprefix'); + + // Get Categories + return $dcdb->get_results('SELECT * FROM '.$dbprefix.'categorie', ARRAY_A); + } + + function get_dc_users() + { + global $wpdb; + // General Housekeeping + $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); + set_magic_quotes_runtime(0); + $dbprefix = get_option('dcdbprefix'); + + // Get Users + + return $dcdb->get_results('SELECT * FROM '.$dbprefix.'user', ARRAY_A); + } + + function get_dc_posts() + { + // General Housekeeping + $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); + set_magic_quotes_runtime(0); + $dbprefix = get_option('dcdbprefix'); + + // Get Posts + return $dcdb->get_results('SELECT '.$dbprefix.'post.*, '.$dbprefix.'categorie.cat_libelle_url AS post_cat_name + FROM '.$dbprefix.'post INNER JOIN '.$dbprefix.'categorie + ON '.$dbprefix.'post.cat_id = '.$dbprefix.'categorie.cat_id', ARRAY_A); + } + + function get_dc_comments() + { + global $wpdb; + // General Housekeeping + $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); + set_magic_quotes_runtime(0); + $dbprefix = get_option('dcdbprefix'); + + // Get Comments + return $dcdb->get_results('SELECT * FROM '.$dbprefix.'comment', ARRAY_A); + } + + function get_dc_links() + { + //General Housekeeping + $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); + set_magic_quotes_runtime(0); + $dbprefix = get_option('dcdbprefix'); + + return $dcdb->get_results('SELECT * FROM '.$dbprefix.'link ORDER BY position', ARRAY_A); + } + + function cat2wp($categories='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $dccat2wpcat = array(); + // Do the Magic + if(is_array($categories)) + { + echo '

    '.__('Importing Categories...').'

    '; + foreach ($categories as $category) + { + $count++; + extract($category); + + // Make Nice Variables + $name = $wpdb->escape($cat_libelle_url); + $title = $wpdb->escape(csc ($cat_libelle)); + $desc = $wpdb->escape(csc ($cat_desc)); + + if($cinfo = category_exists($name)) + { + $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); + } + else + { + $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); + } + $dccat2wpcat[$id] = $ret_id; + } + + // Store category translation for future use + add_option('dccat2wpcat',$dccat2wpcat); + echo '

    '.sprintf(__('Done! %1$s categories imported.'), $count).'

    '; + return true; + } + echo __('No Categories to Import!'); + return false; + } + + function users2wp($users='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $dcid2wpid = array(); + + // Midnight Mojo + if(is_array($users)) + { + echo '

    '.__('Importing Users...').'

    '; + foreach($users as $user) + { + $count++; + extract($user); + + // Make Nice Variables + $name = $wpdb->escape(csc ($name)); + $RealName = $wpdb->escape(csc ($user_pseudo)); + + if($uinfo = get_userdatabylogin($name)) + { + + $ret_id = wp_insert_user(array( + 'ID' => $uinfo->ID, + 'user_login' => $user_id, + 'user_nicename' => $Realname, + 'user_email' => $user_email, + 'user_url' => 'http://', + 'display_name' => $Realname) + ); + } + else + { + $ret_id = wp_insert_user(array( + 'user_login' => $user_id, + 'user_nicename' => csc ($user_pseudo), + 'user_email' => $user_email, + 'user_url' => 'http://', + 'display_name' => $Realname) + ); + } + $dcid2wpid[$user_id] = $ret_id; + + // Set Dotclear-to-WordPress permissions translation + + // Update Usermeta Data + $user = new WP_User($ret_id); + $wp_perms = $user_level + 1; + if(10 == $wp_perms) { $user->set_role('administrator'); } + else if(9 == $wp_perms) { $user->set_role('editor'); } + else if(5 <= $wp_perms) { $user->set_role('editor'); } + else if(4 <= $wp_perms) { $user->set_role('author'); } + else if(3 <= $wp_perms) { $user->set_role('contributor'); } + else if(2 <= $wp_perms) { $user->set_role('contributor'); } + else { $user->set_role('subscriber'); } + + update_usermeta( $ret_id, 'wp_user_level', $wp_perms); + update_usermeta( $ret_id, 'rich_editing', 'false'); + update_usermeta( $ret_id, 'first_name', csc ($user_prenom)); + update_usermeta( $ret_id, 'last_name', csc ($user_nom)); + }// End foreach($users as $user) + + // Store id translation array for future use + add_option('dcid2wpid',$dcid2wpid); + + + echo '

    '.sprintf(__('Done! %1$s users imported.'), $count).'

    '; + return true; + }// End if(is_array($users) + + echo __('No Users to Import!'); + return false; + + }// End function user2wp() + + function posts2wp($posts='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $dcposts2wpposts = array(); + $cats = array(); + + // Do the Magic + if(is_array($posts)) + { + echo '

    '.__('Importing Posts...').'

    '; + foreach($posts as $post) + { + $count++; + extract($post); + + // Set Dotclear-to-WordPress status translation + $stattrans = array(0 => 'draft', 1 => 'publish'); + $comment_status_map = array (0 => 'closed', 1 => 'open'); + + //Can we do this more efficiently? + $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1; + $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; + + $Title = $wpdb->escape(csc ($post_titre)); + $post_content = textconv ($post_content); + $post_excerpt = ""; + if ($post_chapo != "") { + $post_excerpt = textconv ($post_chapo); + $post_content = $post_excerpt ."\n\n".$post_content; + } + $post_excerpt = $wpdb->escape ($post_excerpt); + $post_content = $wpdb->escape ($post_content); + $post_status = $stattrans[$post_pub]; + + // Import Post data into WordPress + + if($pinfo = post_exists($Title,$post_content)) + { + $ret_id = wp_insert_post(array( + 'ID' => $pinfo, + 'post_author' => $authorid, + 'post_date' => $post_dt, + 'post_date_gmt' => $post_dt, + 'post_modified' => $post_upddt, + 'post_modified_gmt' => $post_upddt, + 'post_title' => $Title, + 'post_content' => $post_content, + 'post_excerpt' => $post_excerpt, + 'post_status' => $post_status, + 'post_name' => $post_titre_url, + 'comment_status' => $comment_status_map[$post_open_comment], + 'ping_status' => $comment_status_map[$post_open_tb], + 'comment_count' => $post_nb_comment + $post_nb_trackback) + ); + } + else + { + $ret_id = wp_insert_post(array( + 'post_author' => $authorid, + 'post_date' => $post_dt, + 'post_date_gmt' => $post_dt, + 'post_modified' => $post_modified_gmt, + 'post_modified_gmt' => $post_modified_gmt, + 'post_title' => $Title, + 'post_content' => $post_content, + 'post_excerpt' => $post_excerpt, + 'post_status' => $post_status, + 'post_name' => $post_titre_url, + 'comment_status' => $comment_status_map[$post_open_comment], + 'ping_status' => $comment_status_map[$post_open_tb], + 'comment_count' => $post_nb_comment + $post_nb_trackback) + ); + } + $dcposts2wpposts[$post_id] = $ret_id; + + // Make Post-to-Category associations + $cats = array(); + if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; } + + if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + } + } + // Store ID translation for later use + add_option('dcposts2wpposts',$dcposts2wpposts); + + echo '

    '.sprintf(__('Done! %1$s posts imported.'), $count).'

    '; + return true; + } + + function comments2wp($comments='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $dccm2wpcm = array(); + $postarr = get_option('dcposts2wpposts'); + + // Magic Mojo + if(is_array($comments)) + { + echo '

    '.__('Importing Comments...').'

    '; + foreach($comments as $comment) + { + $count++; + extract($comment); + + // WordPressify Data + $comment_ID = ltrim($comment_id, '0'); + $comment_post_ID = $postarr[$post_id]; + $comment_approved = "$comment_pub"; + $name = $wpdb->escape(csc ($comment_auteur)); + $email = $wpdb->escape($comment_email); + $web = "http://".$wpdb->escape($comment_site); + $message = $wpdb->escape(textconv ($comment_content)); + + if($cinfo = comment_exists($name, $comment_dt)) + { + // Update comments + $ret_id = wp_update_comment(array( + 'comment_ID' => $cinfo, + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_author_IP' => $comment_ip, + 'comment_date' => $comment_dt, + 'comment_date_gmt' => $comment_dt, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + else + { + // Insert comments + $ret_id = wp_insert_comment(array( + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_author_IP' => $comment_ip, + 'comment_date' => $comment_dt, + 'comment_date_gmt' => $comment_dt, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + $dccm2wpcm[$comment_ID] = $ret_id; + } + // Store Comment ID translation for future use + add_option('dccm2wpcm', $dccm2wpcm); + + // Associate newly formed categories with posts + get_comment_count($ret_id); + + + echo '

    '.sprintf(__('Done! %1$s comments imported.'), $count).'

    '; + return true; + } + echo __('No Comments to Import!'); + return false; + } + + function links2wp($links='') + { + // General Housekeeping + global $wpdb; + $count = 0; + + // Deal with the links + if(is_array($links)) + { + echo '

    '.__('Importing Links...').'

    '; + foreach($links as $link) + { + $count++; + extract($link); + + if ($title != "") { + if ($cinfo = link_cat_exists (csc ($title))) { + $category = $cinfo; + } else { + $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('". + $wpdb->escape (csc ($title))."')"); + $category = $wpdb->insert_id; + } + } else { + $linkname = $wpdb->escape(csc ($label)); + $description = $wpdb->escape(csc ($title)); + + if($linfo = link_exists($linkname)) { + $ret_id = wp_insert_link(array( + 'link_id' => $linfo, + 'link_url' => $href, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description) + ); + } else { + $ret_id = wp_insert_link(array( + 'link_url' => $url, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description) + ); + } + $dclinks2wplinks[$link_id] = $ret_id; + } + } + add_option('dclinks2wplinks',$dclinks2wplinks); + echo '

    '; + printf(__('Done! %s links or link categories imported'), $count); + echo '

    '; + return true; + } + echo __('No Links to Import!'); + return false; + } + + function import_categories() + { + // Category Import + $cats = $this->get_dc_cats(); + $this->cat2wp($cats); + add_option('dc_cats', $cats); + + + + echo '
    '; + printf('', __('Import Users')); + echo '
    '; + + } + + function import_users() + { + // User Import + $users = $this->get_dc_users(); + $this->users2wp($users); + + echo '
    '; + printf('', __('Import Posts')); + echo '
    '; + } + + function import_posts() + { + // Post Import + $posts = $this->get_dc_posts(); + $this->posts2wp($posts); + + echo '
    '; + printf('', __('Import Comments')); + echo '
    '; + } + + function import_comments() + { + // Comment Import + $comments = $this->get_dc_comments(); + $this->comments2wp($comments); + + echo '
    '; + printf('', __('Import Links')); + echo '
    '; + } + + function import_links() + { + //Link Import + $links = $this->get_dc_links(); + $this->links2wp($links); + add_option('dc_links', $links); + + echo '
    '; + printf('', __('Finish')); + echo '
    '; + } + + function cleanup_dcimport() + { + delete_option('dcdbprefix'); + delete_option('dc_cats'); + delete_option('dcid2wpid'); + delete_option('dccat2wpcat'); + delete_option('dcposts2wpposts'); + delete_option('dccm2wpcm'); + delete_option('dclinks2wplinks'); + delete_option('dcuser'); + delete_option('dcpass'); + delete_option('dcname'); + delete_option('dchost'); + delete_option('dccharset'); + $this->tips(); + } + + function tips() + { + echo '

    '.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Dotclear, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'

    '; + echo '

    '.__('Users').'

    '; + echo '

    '.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in Dotclear, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Dotclear uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Login and change it.'), '/wp-login.php').'

    '; + echo '

    '.__('Preserving Authors').'

    '; + echo '

    '.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'

    '; + echo '

    '.__('Textile').'

    '; + echo '

    '.__('Also, since you\'re coming from Dotclear, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You\'ll want it.').'

    '; + echo '

    '.__('WordPress Resources').'

    '; + echo '

    '.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

    '; + echo ''; + echo '

    '.sprintf(__('That\'s it! What are you waiting for? Go login!'), '/wp-login.php').'

    '; + } + + function db_form() + { + echo '
      '; + printf('
    • ', __('Dotclear Database User:')); + printf('
    • ', __('Dotclear Database Password:')); + printf('
    • ', __('Dotclear Database Name:')); + printf('
    • ', __('Dotclear Database Host:')); + printf('
    • ', __('Dotclear Table prefix:')); + printf('
    • ', __('Originating character set:')); + echo '
    '; + } + + function dispatch() + { + + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + $this->header(); + + if ( $step > 0 ) + { + if($_POST['dbuser']) + { + if(get_option('dcuser')) + delete_option('dcuser'); + add_option('dcuser',$_POST['dbuser']); + } + if($_POST['dbpass']) + { + if(get_option('dcpass')) + delete_option('dcpass'); + add_option('dcpass',$_POST['dbpass']); + } + + if($_POST['dbname']) + { + if(get_option('dcname')) + delete_option('dcname'); + add_option('dcname',$_POST['dbname']); + } + if($_POST['dbhost']) + { + if(get_option('dchost')) + delete_option('dchost'); + add_option('dchost',$_POST['dbhost']); + } + if($_POST['dccharset']) + { + if(get_option('dccharset')) + delete_option('dccharset'); + add_option('dccharset',$_POST['dccharset']); + } + if($_POST['dbprefix']) + { + if(get_option('dcdbprefix')) + delete_option('dcdbprefix'); + add_option('dcdbprefix',$_POST['dbprefix']); + } + + + } + + switch ($step) + { + default: + case 0 : + $this->greet(); + break; + case 1 : + $this->import_categories(); + break; + case 2 : + $this->import_users(); + break; + case 3 : + $this->import_posts(); + break; + case 4 : + $this->import_comments(); + break; + case 5 : + $this->import_links(); + break; + case 6 : + $this->cleanup_dcimport(); + break; + } + + $this->footer(); + } + + function Dotclear_Import() + { + // Nothing. + } +} + +$dc_import = new Dotclear_Import(); +register_importer('dotclear', 'Dotclear', __('Import posts from a Dotclear Blog'), array ($dc_import, 'dispatch')); +?> diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php new file mode 100644 index 0000000..f2b4e2d --- /dev/null +++ b/wp-admin/import/greymatter.php @@ -0,0 +1,312 @@ +'; + echo '

    '.__('Import Greymatter').'

    '; + } + + function footer() { + echo ''; + } + + function greet() { + $this->header(); +?> +

    This is a basic GreyMatter to WordPress import script.

    +

    What it does:

    +
      +
    • Parses gm-authors.cgi to import (new) authors. Everyone is imported at level 1.
    • +
    • Parses the entries cgi files to import posts, comments, and karma on posts (although karma is not used on WordPress yet).
      If authors are found not to be in gm-authors.cgi, imports them at level 0.
    • +
    • Detects duplicate entries or comments. If you don't import everything the first time, or this import should fail in the middle, duplicate entries will not be made when you try again.
    • +
    +

    What it does not:

    +
      +
    • Parse gm-counter.cgi, gm-banlist.cgi, gm-cplog.cgi (you can make a CP log hack if you really feel like it, but I question the need of a CP log).
    • +
    • Import gm-templates.
    • +
    • Doesn't keep entries on top.
    • +
    +

     

    + +
    + + +

    Second step: GreyMatter details:

    +

    + + + + + + + + + + + + + + + +
    Path to GM files:
    Path to GM entries:

    This importer will search for files 00000001.cgi to 000-whatever.cgi,
    so you need to enter the number of the last GM post here.
    (if you don't know that number, just log into your FTP and look it out
    in the entries' folder)
    Last entry's number:
    +

    +

    When you're ready, click OK to start importing:

    +
    +

     

    +footer(); + } + + + + function gm2autobr($string) { // transforms GM's |*| into b2's
    \n + $string = str_replace("|*|","
    \n",$string); + return($string); + } + + function import() { + global $wpdb; + + $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry'); + for ($i=0; $iheader(); +?> +

    The importer is running...

    +
      +
    • importing users...
        escape($userdata[0]); + $pass1=$wpdb->escape($userdata[1]); + $user_nickname=$wpdb->escape($userdata[0]); + $user_email=$wpdb->escape($userdata[2]); + $user_url=$wpdb->escape($userdata[3]); + $user_joindate=$wpdb->escape($user_joindate); + + $user_id = username_exists($user_login); + if ($user_id) { + echo "
      • user $user_login... Already exists
      • "; + $this->gmnames[$userdata[0]] = $user_id; + continue; + } + + $user_info = array("user_login"=>"$user_login", "user_pass"=>"$pass1", "user_nickname"=>"$user_nickname", "user_email"=>"$user_email", "user_url"=>"$user_url", "user_ip"=>"$user_ip", "user_domain"=>"$user_domain", "user_browser"=>"$user_browser", "dateYMDhour"=>"$user_joindate", "user_level"=>"1", "user_idmode"=>"nickname"); + $user_id = wp_insert_user($user_info); + $this->gmnames[$userdata[0]] = $user_id; + + echo "
      • user $user_login... Done
      • "; + + } + +?>
      Done
    • +
    • importing posts, comments, and karma...
        entry # $entryfile "; + $postinfo=explode("|",$entry[0]); + $postmaincontent=$this->gm2autobr($entry[2]); + $postmorecontent=$this->gm2autobr($entry[3]); + + $post_author=trim($wpdb->escape($postinfo[1])); + + $post_title=$this->gm2autobr($postinfo[2]); + echo " : $post_title : by $postinfo[1]"; + $post_title=$wpdb->escape($post_title); + + $postyear=$postinfo[6]; + $postmonth=zeroise($postinfo[4],2); + $postday=zeroise($postinfo[5],2); + $posthour=zeroise($postinfo[7],2); + $postminute=zeroise($postinfo[8],2); + $postsecond=zeroise($postinfo[9],2); + + if (($postinfo[10]=="PM") && ($posthour!="12")) + $posthour=$posthour+12; + + $post_date="$postyear-$postmonth-$postday $posthour:$postminute:$postsecond"; + + $post_content=$postmaincontent; + if (strlen($postmorecontent)>3) + $post_content .= "

        ".$postmorecontent; + $post_content=$wpdb->escape($post_content); + + $post_karma=$postinfo[12]; + + $post_status = 'publish'; //in greymatter, there are no drafts + $comment_status = 'open'; + $ping_status = 'closed'; + + if ($post_ID = post_exists($post_title, '', $post_date)) { + echo ' (already exists)'; + } else { + //just so that if a post already exists, new users are not created by checkauthor + // we'll check the author is registered, or if it's a deleted author + $user_id = username_exists($post_author); + if (!$user_id) { // if deleted from GM, we register the author as a level 0 user + $user_ip="127.0.0.1"; + $user_domain="localhost"; + $user_browser="server"; + $user_joindate="1979-06-06 00:41:00"; + $user_login=$wpdb->escape($post_author); + $pass1=$wpdb->escape("password"); + $user_nickname=$wpdb->escape($post_author); + $user_email=$wpdb->escape("user@deleted.com"); + $user_url=$wpdb->escape(""); + $user_joindate=$wpdb->escape($user_joindate); + + $user_info = array("user_login"=>$user_login, "user_pass"=>$pass1, "user_nickname"=>$user_nickname, "user_email"=>$user_email, "user_url"=>$user_url, "user_ip"=>$user_ip, "user_domain"=>$user_domain, "user_browser"=>$user_browser, "dateYMDhour"=>$user_joindate, "user_level"=>0, "user_idmode"=>"nickname"); + $user_id = wp_insert_user($user_info); + $this->gmnames[$postinfo[1]] = $user_id; + + echo ": registered deleted user $user_login at level 0 "; + } + + if (array_key_exists($postinfo[1], $this->gmnames)) { + $post_author = $this->gmnames[$postinfo[1]]; + } else { + $post_author = $user_id; + } + + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); + $post_ID = wp_insert_post($postdata); + } + + $c=count($entry); + if ($c>4) { + $numAddedComments = 0; + $numComments = 0; + for ($j=4;$j<$c;$j++) { + $entry[$j]=$this->gm2autobr($entry[$j]); + $commentinfo=explode("|",$entry[$j]); + $comment_post_ID=$post_ID; + $comment_author=$wpdb->escape($commentinfo[0]); + $comment_author_email=$wpdb->escape($commentinfo[2]); + $comment_author_url=$wpdb->escape($commentinfo[3]); + $comment_author_IP=$wpdb->escape($commentinfo[1]); + + $commentyear=$commentinfo[7]; + $commentmonth=zeroise($commentinfo[5],2); + $commentday=zeroise($commentinfo[6],2); + $commenthour=zeroise($commentinfo[8],2); + $commentminute=zeroise($commentinfo[9],2); + $commentsecond=zeroise($commentinfo[10],2); + if (($commentinfo[11]=="PM") && ($commenthour!="12")) + $commenthour=$commenthour+12; + $comment_date="$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond"; + + $comment_content=$wpdb->escape($commentinfo[12]); + + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $numAddedComments++; + } + $numComments++; + } + if ($numAddedComments > 0) { + echo ": imported $numAddedComments comment"; + if ($numAddedComments != 1) + echo "s"; + } + $preExisting = $numComments - numAddedComments; + if ($preExisting > 0) + echo " (ignored $preExisting pre-existing comments)"; + } + echo "... Done"; + } + } + ?> +
      Done
    +

     

    +

    Completed Greymatter import !

    +footer(); + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1: + $this->import(); + break; + } + } + + function GM_Import() { + // Nothing. + } +} + +$gm_import = new GM_Import(); + +register_importer('greymatter', 'Greymatter', __('Import posts and comments from your Greymatter blog'), array ($gm_import, 'dispatch')); +?> diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php new file mode 100644 index 0000000..44b92a5 --- /dev/null +++ b/wp-admin/import/livejournal.php @@ -0,0 +1,168 @@ +'; + echo '

    '.__('Import LiveJournal').'

    '; + } + + function footer() { + echo ''; + } + + function unhtmlentities($string) { // From php.net for < 4.3 compat + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } + + function greet() { + echo '

    '.__('Howdy! This importer allows you to extract posts from LiveJournal XML export file into your blog. Pick a LiveJournal file to upload and click Import.').'

    '; + wp_import_upload_form("admin.php?import=livejournal&step=1"); + } + + function import_posts() { + global $wpdb, $current_user; + + set_magic_quotes_runtime(0); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); + + preg_match_all('|(.*?)|is', $importdata, $posts); + $posts = $posts[1]; + unset($importdata); + echo '
      '; + foreach ($posts as $post) { + preg_match('|(.*?)|is', $post, $post_title); + $post_title = $wpdb->escape(trim($post_title[1])); + if ( empty($post_title) ) { + preg_match('|(.*?)|is', $post, $post_title); + $post_title = $wpdb->escape(trim($post_title[1])); + } + + preg_match('|(.*?)|is', $post, $post_date); + $post_date = strtotime($post_date[1]); + $post_date = gmdate('Y-m-d H:i:s', $post_date); + + preg_match('|(.*?)|is', $post, $post_content); + $post_content = str_replace(array (''), '', trim($post_content[1])); + $post_content = $this->unhtmlentities($post_content); + + // Clean up content + $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + $post_content = $wpdb->escape($post_content); + + $post_author = $current_user->ID; + $post_status = 'publish'; + + echo '
    1. '; + if ($post_id = post_exists($post_title, $post_content, $post_date)) { + printf(__('Post %s already exists.'), stripslashes($post_title)); + } else { + printf(__('Importing post %s...'), stripslashes($post_title)); + $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status'); + $post_id = wp_insert_post($postdata); + if (!$post_id) { + _e("Couldn't get post ID"); + echo '
    2. '; + break; + } + } + + preg_match_all('|(.*?)|is', $post, $comments); + $comments = $comments[1]; + + if ( $comments ) { + $comment_post_ID = $post_id; + $num_comments = 0; + foreach ($comments as $comment) { + preg_match('|(.*?)|is', $comment, $comment_content); + $comment_content = str_replace(array (''), '', trim($comment_content[1])); + $comment_content = $this->unhtmlentities($comment_content); + + // Clean up content + $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content); + $comment_content = str_replace('
      ', '
      ', $comment_content); + $comment_content = str_replace('
      ', '
      ', $comment_content); + $comment_content = $wpdb->escape($comment_content); + + preg_match('|(.*?)|is', $comment, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + + preg_match('|(.*?)|is', $comment, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + + preg_match('|(.*?)|is', $comment, $comment_author_email); + $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); + + $comment_approved = 1; + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_comments++; + } + } + } + if ( $num_comments ) { + echo ' '; + printf(__('(%s comments)'), $num_comments); + } + echo ''; + } + echo '
    '; + } + + function import() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo $file['error']; + return; + } + + $this->file = $file['file']; + $this->import_posts(); + wp_import_cleanup($file['id']); + + echo '

    '; + printf(__('All done. Have fun!'), get_option('home')); + echo '

    '; + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->import(); + break; + } + + $this->footer(); + } + + function LJ_Import() { + // Nothing. + } +} + +$livejournal_import = new LJ_Import(); + +register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch')); +?> diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php new file mode 100644 index 0000000..59259ea --- /dev/null +++ b/wp-admin/import/mt.php @@ -0,0 +1,407 @@ +'; + echo '

    '.__('Import Movable Type and Typepad').'

    '; + } + + function footer() { + echo ''; + } + + function greet() { + $this->header(); +?> +

    + +

    out of memory error try splitting up the import file into pieces.'); ?>

    +footer(); + } + + function users_form($n) { + global $wpdb, $testing; + $users = get_users_of_blog($wpdb->blogid); +?> + mtnames); //find the array key for $author in the $mtnames array + $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames + + return $user_id; + } + + function get_entries() { + set_magic_quotes_runtime(0); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata); + $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata); + $this->posts = explode("--MT-ENTRY--", $importdata); + } + + function get_mt_authors() { + $temp = array (); + $i = -1; + foreach ($this->posts as $post) { + if ('' != trim($post)) { + ++ $i; + preg_match("|AUTHOR:(.*)|", $post, $thematch); + $thematch = trim($thematch[1]); + array_push($temp, "$thematch"); //store the extracted author names in a temporary array + } + } + + //we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. + $authors[0] = array_shift($temp); + $y = count($temp) + 1; + for ($x = 1; $x < $y; $x ++) { + $next = array_shift($temp); + if (!(in_array($next, $authors))) + array_push($authors, "$next"); + } + + return $authors; + } + + function get_authors_from_post() { + $formnames = array (); + $selectnames = array (); + + foreach ($_POST['userselect'] as $user => $key) { + $selected = trim(stripslashes($key)); + array_push($selectnames, "$selected"); + } + + $count = count($formnames); + for ($i = 0; $i < $count; $i ++) { + if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form + array_push($this->newauthornames, "$selectnames[$i]"); + } else { + array_push($this->newauthornames, "$formnames[$i]"); + } + } + } + + function mt_authors_form() { +?> +
    +

    +

    admins entries.'); ?>

    +

    italics. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.'); ?>

    +

    + get_mt_authors(); + echo '
      '; + echo '
      '; + $j = -1; + foreach ($authors as $author) { + ++ $j; + echo '
    1. '.$author.'
      '.''; + $this->users_form($j); + echo '
    2. '; + } + + echo ''.'
      '; + echo '
      '; + echo '
    '; + + } + + function select_authors() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo $file['error']; + return; + } + $this->file = $file['file']; + $this->id = $file['id']; + + $this->get_entries(); + $this->mt_authors_form(); + } + + function process_posts() { + global $wpdb; + $i = -1; + echo "
      "; + foreach ($this->posts as $post) { + if ('' != trim($post)) { + ++ $i; + unset ($post_categories); + + // Take the pings out first + preg_match("|(-----\n\nPING:.*)|s", $post, $pings); + $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post); + + // Then take the comments out + preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments); + $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post); + + // We ignore the keywords + $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post); + + // We want the excerpt + preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt); + $excerpt = $wpdb->escape(trim($excerpt[1])); + $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post); + + // We're going to put extended body into main body with a more tag + preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended); + $extended = trim($extended[1]); + if ('' != $extended) + $extended = "\n\n$extended"; + $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post); + + // Now for the main body + preg_match("|-----\nBODY:(.*)|s", $post, $body); + $body = trim($body[1]); + $post_content = $wpdb->escape($body.$extended); + $post = preg_replace("|(-----\nBODY:.*)|s", '', $post); + + // Grab the metadata from what's left + $metadata = explode("\n", $post); + foreach ($metadata as $line) { + preg_match("/^(.*?):(.*)/", $line, $token); + $key = trim($token[1]); + $value = trim($token[2]); + // Now we decide what it is and what to do with it + switch ($key) { + case '' : + break; + case 'AUTHOR' : + $post_author = $value; + break; + case 'TITLE' : + $post_title = $wpdb->escape($value); + break; + case 'STATUS' : + // "publish" and "draft" enumeration items match up; no change required + $post_status = $value; + if (empty ($post_status)) + $post_status = 'publish'; + break; + case 'ALLOW COMMENTS' : + $post_allow_comments = $value; + if ($post_allow_comments == 1) { + $comment_status = 'open'; + } else { + $comment_status = 'closed'; + } + break; + case 'CONVERT BREAKS' : + $post_convert_breaks = $value; + break; + case 'ALLOW PINGS' : + $ping_status = trim($meta[2][0]); + if ($ping_status == 1) { + $ping_status = 'open'; + } else { + $ping_status = 'closed'; + } + break; + case 'PRIMARY CATEGORY' : + if (! empty ($value) ) + $post_categories[] = $wpdb->escape($value); + break; + case 'CATEGORY' : + if (! empty ($value) ) + $post_categories[] = $wpdb->escape($value); + break; + case 'DATE' : + $post_modified = strtotime($value); + $post_modified = date('Y-m-d H:i:s', $post_modified); + $post_modified_gmt = get_gmt_from_date("$post_modified"); + $post_date = $post_modified; + $post_date_gmt = $post_modified_gmt; + break; + default : + // echo "\n$key: $value"; + break; + } // end switch + } // End foreach + + // Let's check to see if it's in already + if ($post_id = post_exists($post_title, '', $post_date)) { + echo '
    1. '; + printf(__('Post %s already exists.'), stripslashes($post_title)); + } else { + echo '
    2. '; + printf(__('Importing post %s...'), stripslashes($post_title)); + + $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor + + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); + $post_id = wp_insert_post($postdata); + // Add categories. + if (0 != count($post_categories)) { + wp_create_categories($post_categories, $post_id); + } + } + + $comment_post_ID = $post_id; + $comment_approved = 1; + + // Now for comments + $comments = explode("-----\nCOMMENT:", $comments[0]); + $num_comments = 0; + foreach ($comments as $comment) { + if ('' != trim($comment)) { + // Author + preg_match("|AUTHOR:(.*)|", $comment, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + $comment = preg_replace('|(\n?AUTHOR:.*)|', '', $comment); + preg_match("|EMAIL:(.*)|", $comment, $comment_author_email); + $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); + $comment = preg_replace('|(\n?EMAIL:.*)|', '', $comment); + + preg_match("|IP:(.*)|", $comment, $comment_author_IP); + $comment_author_IP = trim($comment_author_IP[1]); + $comment = preg_replace('|(\n?IP:.*)|', '', $comment); + + preg_match("|URL:(.*)|", $comment, $comment_author_url); + $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); + $comment = preg_replace('|(\n?URL:.*)|', '', $comment); + + preg_match("|DATE:(.*)|", $comment, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + $comment = preg_replace('|(\n?DATE:.*)|', '', $comment); + + $comment_content = $wpdb->escape(trim($comment)); + $comment_content = str_replace('-----', '', $comment_content); + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_comments++; + } + } + } + if ( $num_comments ) + printf(__(' (%s comments)'), $num_comments); + + // Finally the pings + // fix the double newline on the first one + $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]); + $pings = explode("-----\nPING:", $pings[0]); + $num_pings = 0; + foreach ($pings as $ping) { + if ('' != trim($ping)) { + // 'Author' + preg_match("|BLOG NAME:(.*)|", $ping, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + $ping = preg_replace('|(\n?BLOG NAME:.*)|', '', $ping); + + preg_match("|IP:(.*)|", $ping, $comment_author_IP); + $comment_author_IP = trim($comment_author_IP[1]); + $ping = preg_replace('|(\n?IP:.*)|', '', $ping); + + preg_match("|URL:(.*)|", $ping, $comment_author_url); + $comment_author_url = $wpdb->escape(trim($comment_author_url[1])); + $ping = preg_replace('|(\n?URL:.*)|', '', $ping); + + preg_match("|DATE:(.*)|", $ping, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + $ping = preg_replace('|(\n?DATE:.*)|', '', $ping); + + preg_match("|TITLE:(.*)|", $ping, $ping_title); + $ping_title = $wpdb->escape(trim($ping_title[1])); + $ping = preg_replace('|(\n?TITLE:.*)|', '', $ping); + + $comment_content = $wpdb->escape(trim($ping)); + $comment_content = str_replace('-----', '', $comment_content); + + $comment_content = "$ping_title\n\n$comment_content"; + + $comment_type = 'trackback'; + + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_pings++; + } + } + } + if ( $num_pings ) + printf(__(' (%s pings)'), $num_pings); + + echo "
    3. "; + } + } + + echo '
    '; + + wp_import_cleanup($this->id); + + echo '

    '.sprintf(__('All done. Have fun!'), get_option('home')).'

    '; + } + + function import() { + $this->id = (int) $_GET['id']; + + $this->file = get_attached_file($this->id); + $this->get_authors_from_post(); + $this->get_entries(); + $this->process_posts(); + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->select_authors(); + break; + case 2: + $this->import(); + break; + } + } + + function MT_Import() { + // Nothing. + } +} + +$mt_import = new MT_Import(); + +register_importer('mt', 'Movable Type and Typepad', __('Imports posts and comments from your Movable Type or Typepad blog'), array ($mt_import, 'dispatch')); +?> diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php new file mode 100644 index 0000000..69972f3 --- /dev/null +++ b/wp-admin/import/rss.php @@ -0,0 +1,171 @@ +'; + echo '

    '.__('Import RSS').'

    '; + } + + function footer() { + echo ''; + } + + function unhtmlentities($string) { // From php.net for < 4.3 compat + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } + + function greet() { + echo '

    '.__('Howdy! This importer allows you to extract posts from any RSS 2.0 file into your blog. This is useful if you want to import your posts from a system that is not handled by a custom import tool. Pick an RSS file to upload and click Import.').'

    '; + wp_import_upload_form("admin.php?import=rss&step=1"); + } + + function get_posts() { + global $wpdb; + + set_magic_quotes_runtime(0); + $datalines = file($this->file); // Read the file into an array + $importdata = implode('', $datalines); // squish it + $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); + + preg_match_all('|(.*?)|is', $importdata, $this->posts); + $this->posts = $this->posts[1]; + $index = 0; + foreach ($this->posts as $post) { + preg_match('|(.*?)|is', $post, $post_title); + $post_title = $wpdb->escape(trim($post_title[1])); + + preg_match('|(.*?)|is', $post, $post_date); + + if ($post_date) { + $post_date = strtotime($post_date[1]); + } else { + // if we don't already have something from pubDate + preg_match('|(.*?)|is', $post, $post_date); + $post_date = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $post_date[1]); + $post_date = str_replace('T', ' ', $post_date); + $post_date = strtotime($post_date); + } + + $post_date = gmdate('Y-m-d H:i:s', $post_date); + + preg_match_all('|(.*?)|is', $post, $categories); + $categories = $categories[1]; + + if (!$categories) { + preg_match_all('|(.*?)|is', $post, $categories); + $categories = $categories[1]; + } + + $cat_index = 0; + foreach ($categories as $category) { + $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category)); + $cat_index++; + } + + preg_match('|(.*?)|is', $post, $guid); + if ($guid) + $guid = $wpdb->escape(trim($guid[1])); + else + $guid = ''; + + preg_match('|(.*?)|is', $post, $post_content); + $post_content = str_replace(array (''), '', $wpdb->escape(trim($post_content[1]))); + + if (!$post_content) { + // This is for feeds that put content in description + preg_match('|(.*?)|is', $post, $post_content); + $post_content = $wpdb->escape($this->unhtmlentities(trim($post_content[1]))); + } + + // Clean up content + $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); + $post_content = str_replace('
    ', '
    ', $post_content); + $post_content = str_replace('
    ', '
    ', $post_content); + + $post_author = 1; + $post_status = 'publish'; + $this->posts[$index] = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'guid', 'categories'); + $index++; + } + } + + function import_posts() { + echo '
      '; + + foreach ($this->posts as $post) { + echo "
    1. ".__('Importing post...'); + + extract($post); + + if ($post_id = post_exists($post_title, $post_content, $post_date)) { + _e('Post already imported'); + } else { + $post_id = wp_insert_post($post); + if (!$post_id) { + _e("Couldn't get post ID"); + return; + } + + if (0 != count($categories)) + wp_create_categories($categories, $post_id); + _e('Done !'); + } + echo '
    2. '; + } + + echo '
    '; + + } + + function import() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo $file['error']; + return; + } + + $this->file = $file['file']; + $this->get_posts(); + $this->import_posts(); + wp_import_cleanup($file['id']); + + echo '

    '; + printf(__('All done. Have fun!'), get_option('home')); + echo '

    '; + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->import(); + break; + } + + $this->footer(); + } + + function RSS_Import() { + // Nothing. + } +} + +$rss_import = new RSS_Import(); + +register_importer('rss', 'RSS', __('Import posts from an RSS feed'), array ($rss_import, 'dispatch')); +?> diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php new file mode 100644 index 0000000..17cae87 --- /dev/null +++ b/wp-admin/import/textpattern.php @@ -0,0 +1,663 @@ +get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); + + return $name; + } +} + +if(!function_exists('get_comment_count')) +{ + function get_comment_count($post_ID) + { + global $wpdb; + return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + } +} + +if(!function_exists('link_exists')) +{ + function link_exists($linkname) + { + global $wpdb; + return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"'); + } +} + +/** + The Main Importer Class +**/ +class Textpattern_Import { + + function header() + { + echo '
    '; + echo '

    '.__('Import Textpattern').'

    '; + echo '

    '.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

    '; + } + + function footer() + { + echo '
    '; + } + + function greet() + { + echo '

    '.__('Howdy! This importer allows you to extract posts from any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern. Mileage may vary.').'

    '; + echo '

    '.__('Your Textpattern Configuration settings are as follows:').'

    '; + echo '
    '; + $this->db_form(); + echo ''; + echo '
    '; + } + + function get_txp_cats() + { + global $wpdb; + // General Housekeeping + $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Categories + return $txpdb->get_results('SELECT + id, + name, + title + FROM '.$prefix.'txp_category + WHERE type = "article"', + ARRAY_A); + } + + function get_txp_users() + { + global $wpdb; + // General Housekeeping + $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Users + + return $txpdb->get_results('SELECT + user_id, + name, + RealName, + email, + privs + FROM '.$prefix.'txp_users', ARRAY_A); + } + + function get_txp_posts() + { + // General Housekeeping + $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Posts + return $txpdb->get_results('SELECT + ID, + Posted, + AuthorID, + LastMod, + Title, + Body, + Excerpt, + Category1, + Category2, + Status, + Keywords, + url_title, + comments_count + FROM '.$prefix.'textpattern + ', ARRAY_A); + } + + function get_txp_comments() + { + global $wpdb; + // General Housekeeping + $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Comments + return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); + } + + function get_txp_links() + { + //General Housekeeping + $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + return $txpdb->get_results('SELECT + id, + date, + category, + url, + linkname, + description + FROM '.$prefix.'txp_link', + ARRAY_A); + } + + function cat2wp($categories='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpcat2wpcat = array(); + // Do the Magic + if(is_array($categories)) + { + echo '

    '.__('Importing Categories...').'

    '; + foreach ($categories as $category) + { + $count++; + extract($category); + + + // Make Nice Variables + $name = $wpdb->escape($name); + $title = $wpdb->escape($title); + + if($cinfo = category_exists($name)) + { + $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); + } + else + { + $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); + } + $txpcat2wpcat[$id] = $ret_id; + } + + // Store category translation for future use + add_option('txpcat2wpcat',$txpcat2wpcat); + echo '

    '.sprintf(__('Done! %1$s categories imported.'), $count).'

    '; + return true; + } + echo __('No Categories to Import!'); + return false; + } + + function users2wp($users='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpid2wpid = array(); + + // Midnight Mojo + if(is_array($users)) + { + echo '

    '.__('Importing Users...').'

    '; + foreach($users as $user) + { + $count++; + extract($user); + + // Make Nice Variables + $name = $wpdb->escape($name); + $RealName = $wpdb->escape($RealName); + + if($uinfo = get_userdatabylogin($name)) + { + + $ret_id = wp_insert_user(array( + 'ID' => $uinfo->ID, + 'user_login' => $name, + 'user_nicename' => $RealName, + 'user_email' => $email, + 'user_url' => 'http://', + 'display_name' => $name) + ); + } + else + { + $ret_id = wp_insert_user(array( + 'user_login' => $name, + 'user_nicename' => $RealName, + 'user_email' => $email, + 'user_url' => 'http://', + 'display_name' => $name) + ); + } + $txpid2wpid[$user_id] = $ret_id; + + // Set Textpattern-to-WordPress permissions translation + $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); + + // Update Usermeta Data + $user = new WP_User($ret_id); + if('10' == $transperms[$privs]) { $user->set_role('administrator'); } + if('9' == $transperms[$privs]) { $user->set_role('editor'); } + if('5' == $transperms[$privs]) { $user->set_role('editor'); } + if('4' == $transperms[$privs]) { $user->set_role('author'); } + if('3' == $transperms[$privs]) { $user->set_role('contributor'); } + if('2' == $transperms[$privs]) { $user->set_role('contributor'); } + if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } + + update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] ); + update_usermeta( $ret_id, 'rich_editing', 'false'); + }// End foreach($users as $user) + + // Store id translation array for future use + add_option('txpid2wpid',$txpid2wpid); + + + echo '

    '.sprintf(__('Done! %1$s users imported.'), $count).'

    '; + return true; + }// End if(is_array($users) + + echo __('No Users to Import!'); + return false; + + }// End function user2wp() + + function posts2wp($posts='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpposts2wpposts = array(); + $cats = array(); + + // Do the Magic + if(is_array($posts)) + { + echo '

    '.__('Importing Posts...').'

    '; + foreach($posts as $post) + { + $count++; + extract($post); + + // Set Textpattern-to-WordPress status translation + $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); + + //Can we do this more efficiently? + $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1; + $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; + + $Title = $wpdb->escape($Title); + $Body = $wpdb->escape($Body); + $Excerpt = $wpdb->escape($Excerpt); + $post_status = $stattrans[$Status]; + + // Import Post data into WordPress + + if($pinfo = post_exists($Title,$Body)) + { + $ret_id = wp_insert_post(array( + 'ID' => $pinfo, + 'post_date' => $Posted, + 'post_date_gmt' => $post_date_gmt, + 'post_author' => $authorid, + 'post_modified' => $LastMod, + 'post_modified_gmt' => $post_modified_gmt, + 'post_title' => $Title, + 'post_content' => $Body, + 'post_excerpt' => $Excerpt, + 'post_status' => $post_status, + 'post_name' => $url_title, + 'comment_count' => $comments_count) + ); + } + else + { + $ret_id = wp_insert_post(array( + 'post_date' => $Posted, + 'post_date_gmt' => $post_date_gmt, + 'post_author' => $authorid, + 'post_modified' => $LastMod, + 'post_modified_gmt' => $post_modified_gmt, + 'post_title' => $Title, + 'post_content' => $Body, + 'post_excerpt' => $Excerpt, + 'post_status' => $post_status, + 'post_name' => $url_title, + 'comment_count' => $comments_count) + ); + } + $txpposts2wpposts[$ID] = $ret_id; + + // Make Post-to-Category associations + $cats = array(); + if($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; } + if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; } + + if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + } + } + // Store ID translation for later use + add_option('txpposts2wpposts',$txpposts2wpposts); + + echo '

    '.sprintf(__('Done! %1$s posts imported.'), $count).'

    '; + return true; + } + + function comments2wp($comments='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpcm2wpcm = array(); + $postarr = get_option('txpposts2wpposts'); + + // Magic Mojo + if(is_array($comments)) + { + echo '

    '.__('Importing Comments...').'

    '; + foreach($comments as $comment) + { + $count++; + extract($comment); + + // WordPressify Data + $comment_ID = ltrim($discussid, '0'); + $comment_post_ID = $postarr[$parentid]; + $comment_approved = (1 == $visible) ? 1 : 0; + $name = $wpdb->escape($name); + $email = $wpdb->escape($email); + $web = $wpdb->escape($web); + $message = $wpdb->escape($message); + + if($cinfo = comment_exists($name, $posted)) + { + // Update comments + $ret_id = wp_update_comment(array( + 'comment_ID' => $cinfo, + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + else + { + // Insert comments + $ret_id = wp_insert_comment(array( + 'comment_post_ID' => $comment_post_ID, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_author_IP' => $ip, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + $txpcm2wpcm[$comment_ID] = $ret_id; + } + // Store Comment ID translation for future use + add_option('txpcm2wpcm', $txpcm2wpcm); + + // Associate newly formed categories with posts + get_comment_count($ret_id); + + + echo '

    '.sprintf(__('Done! %1$s comments imported.'), $count).'

    '; + return true; + } + echo __('No Comments to Import!'); + return false; + } + + function links2wp($links='') + { + // General Housekeeping + global $wpdb; + $count = 0; + + // Deal with the links + if(is_array($links)) + { + echo '

    '.__('Importing Links...').'

    '; + foreach($links as $link) + { + $count++; + extract($link); + + // Make nice vars + $category = $wpdb->escape($category); + $linkname = $wpdb->escape($linkname); + $description = $wpdb->escape($description); + + if($linfo = link_exists($linkname)) + { + $ret_id = wp_insert_link(array( + 'link_id' => $linfo, + 'link_url' => $url, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description, + 'link_updated' => $date) + ); + } + else + { + $ret_id = wp_insert_link(array( + 'link_url' => $url, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description, + 'link_updated' => $date) + ); + } + $txplinks2wplinks[$link_id] = $ret_id; + } + add_option('txplinks2wplinks',$txplinks2wplinks); + echo '

    '; + printf(__('Done! %s Links imported'), $count); + echo '

    '; + return true; + } + echo __('No Links to Import!'); + return false; + } + + function import_categories() + { + // Category Import + $cats = $this->get_txp_cats(); + $this->cat2wp($cats); + add_option('txp_cats', $cats); + + + + echo '
    '; + printf('', __('Import Users')); + echo '
    '; + + } + + function import_users() + { + // User Import + $users = $this->get_txp_users(); + $this->users2wp($users); + + echo '
    '; + printf('', __('Import Posts')); + echo '
    '; + } + + function import_posts() + { + // Post Import + $posts = $this->get_txp_posts(); + $this->posts2wp($posts); + + echo '
    '; + printf('', __('Import Comments')); + echo '
    '; + } + + function import_comments() + { + // Comment Import + $comments = $this->get_txp_comments(); + $this->comments2wp($comments); + + echo '
    '; + printf('', __('Import Links')); + echo '
    '; + } + + function import_links() + { + //Link Import + $links = $this->get_txp_links(); + $this->links2wp($links); + add_option('txp_links', $links); + + echo '
    '; + printf('', __('Finish')); + echo '
    '; + } + + function cleanup_txpimport() + { + delete_option('tpre'); + delete_option('txp_cats'); + delete_option('txpid2wpid'); + delete_option('txpcat2wpcat'); + delete_option('txpposts2wpposts'); + delete_option('txpcm2wpcm'); + delete_option('txplinks2wplinks'); + delete_option('txpuser'); + delete_option('txppass'); + delete_option('txpname'); + delete_option('txphost'); + $this->tips(); + } + + function tips() + { + echo '

    '.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'

    '; + echo '

    '.__('Users').'

    '; + echo '

    '.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Login and change it.'), '/wp-login.php').'

    '; + echo '

    '.__('Preserving Authors').'

    '; + echo '

    '.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'

    '; + echo '

    '.__('Textile').'

    '; + echo '

    '.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You\'ll want it.').'

    '; + echo '

    '.__('WordPress Resources').'

    '; + echo '

    '.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

    '; + echo ''; + echo '

    '.sprintf(__('That\'s it! What are you waiting for? Go login!'), '/wp-login.php').'

    '; + } + + function db_form() + { + echo '
      '; + printf('
    • ', __('Textpattern Database User:')); + printf('
    • ', __('Textpattern Database Password:')); + printf('
    • ', __('Textpattern Database Name:')); + printf('
    • ', __('Textpattern Database Host:')); + printf('
    • ', __('Textpattern Table prefix (if any):')); + echo '
    '; + } + + function dispatch() + { + + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + $this->header(); + + if ( $step > 0 ) + { + if($_POST['dbuser']) + { + if(get_option('txpuser')) + delete_option('txpuser'); + add_option('txpuser',$_POST['dbuser']); + } + if($_POST['dbpass']) + { + if(get_option('txppass')) + delete_option('txppass'); + add_option('txppass',$_POST['dbpass']); + } + + if($_POST['dbname']) + { + if(get_option('txpname')) + delete_option('txpname'); + add_option('txpname',$_POST['dbname']); + } + if($_POST['dbhost']) + { + if(get_option('txphost')) + delete_option('txphost'); + add_option('txphost',$_POST['dbhost']); + } + if($_POST['dbprefix']) + { + if(get_option('tpre')) + delete_option('tpre'); + add_option('tpre',$_POST['dbprefix']); + } + + + } + + switch ($step) + { + default: + case 0 : + $this->greet(); + break; + case 1 : + $this->import_categories(); + break; + case 2 : + $this->import_users(); + break; + case 3 : + $this->import_posts(); + break; + case 4 : + $this->import_comments(); + break; + case 5 : + $this->import_links(); + break; + case 6 : + $this->cleanup_txpimport(); + break; + } + + $this->footer(); + } + + function Textpattern_Import() + { + // Nothing. + } +} + +$txp_import = new Textpattern_Import(); +register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch')); +?> diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php new file mode 100644 index 0000000..997628b --- /dev/null +++ b/wp-admin/import/wordpress.php @@ -0,0 +1,288 @@ +'; + echo '

    '.__('Import WordPress').'

    '; + } + + function footer() { + echo ''; + } + + function unhtmlentities($string) { // From php.net for < 4.3 compat + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } + + function greet() { + echo '

    '.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts and comments into this blog.').'

    '; + wp_import_upload_form("admin.php?import=wordpress&step=1"); + } + + function get_tag( $string, $tag ) { + preg_match("|<$tag.*?>(.*?)|is", $string, $return); + $return = addslashes( trim( $return[1] ) ); + return $return; + } + + function users_form($n) { + global $wpdb, $testing; + $users = get_users_of_blog($wpdb->blogid); +?> + mtnames); //find the array key for $author in the $mtnames array + $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames + + return $user_id; + } + + function get_entries() { + set_magic_quotes_runtime(0); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata); + preg_match_all('|(.*?)|is', $importdata, $this->posts); + $this->posts = $this->posts[1]; + } + + function get_wp_authors() { + $temp = array (); + $i = -1; + foreach ($this->posts as $post) { + if ('' != trim($post)) { + ++ $i; + $author = $this->get_tag( $post, 'dc:creator' ); + array_push($temp, "$author"); //store the extracted author names in a temporary array + } + } + + // We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. + $authors[0] = array_shift($temp); + $y = count($temp) + 1; + for ($x = 1; $x < $y; $x ++) { + $next = array_shift($temp); + if (!(in_array($next, $authors))) + array_push($authors, "$next"); + } + + return $authors; + } + + function get_authors_from_post() { + $formnames = array (); + $selectnames = array (); + + foreach ($_POST['userselect'] as $user => $key) { + $selected = trim(stripslashes($key)); + array_push($selectnames, "$selected"); + } + + $count = count($formnames); + for ($i = 0; $i < $count; $i ++) { + if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form + array_push($this->newauthornames, "$selectnames[$i]"); + } else { + array_push($this->newauthornames, "$formnames[$i]"); + } + } + } + + function wp_authors_form() { +?> +

    +

    admins entries.'); ?>

    +

    + get_wp_authors(); + echo '
      '; + echo '
      '; + $j = -1; + foreach ($authors as $author) { + ++ $j; + echo '
    1. Current author: '.$author.'
      '.'Map to existing: '; + $this->users_form($j); + echo '
    2. '; + } + + echo ''.'
      '; + echo '
      '; + echo '
    '; + + } + + function select_authors() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + $this->header(); + echo '

    Sorry, there has been an error.

    '; + echo '

    ' . $file['error'] . '

    '; + $this->footer(); + return; + } + $this->file = $file['file']; + $this->id = $file['id']; + + $this->get_entries(); + $this->wp_authors_form(); + } + + function process_posts() { + global $wpdb; + $i = -1; + echo '
      '; + foreach ($this->posts as $post) { + + // There are only ever one of these + $post_title = $this->get_tag( $post, 'title' ); + $post_date = $this->get_tag( $post, 'wp:post_date' ); + $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' ); + $comment_status = $this->get_tag( $post, 'wp:comment_status' ); + $ping_status = $this->get_tag( $post, 'wp:ping_status' ); + $post_status = $this->get_tag( $post, 'wp:status' ); + $post_parent = $this->get_tag( $post, 'wp:post_parent' ); + $post_type = $this->get_tag( $post, 'wp:post_type' ); + $guid = $this->get_tag( $post, 'guid' ); + $post_author = $this->get_tag( $post, 'dc:creator' ); + + $post_content = $this->get_tag( $post, 'content:encoded' ); + $post_content = str_replace(array (''), '', $post_content); + $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + $post_content = str_replace('
      ', '
      ', $post_content); + + preg_match_all('|(.*?)|is', $post, $categories); + $categories = $categories[1]; + + $cat_index = 0; + foreach ($categories as $category) { + $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category)); + $cat_index++; + } + + if ($post_id = post_exists($post_title, '', $post_date)) { + echo '
    1. '; + printf(__('Post %s already exists.'), stripslashes($post_title)); + } else { + echo '
    2. '; + printf(__('Importing post %s...'), stripslashes($post_title)); + + $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor + + $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'post_type'); + $comment_post_ID = $post_id = wp_insert_post($postdata); + // Add categories. + if (0 != count($categories)) { + wp_create_categories($categories, $post_id); + } + } + + // Now for comments + preg_match_all('|(.*?)|is', $post, $comments); + $comments = $comments[1]; + $num_comments = 0; + if ( $comments) { foreach ($comments as $comment) { + $comment_author = $this->get_tag( $comment, 'wp:comment_author'); + $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email'); + $comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP'); + $comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url'); + $comment_date = $this->get_tag( $comment, 'wp:comment_date'); + $comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt'); + $comment_content = $this->get_tag( $comment, 'wp:comment_content'); + $comment_approved = $this->get_tag( $comment, 'wp:comment_approved'); + $comment_type = $this->get_tag( $comment, 'wp:comment_type'); + $comment_parent = $this->get_tag( $comment, 'wp:comment_parent'); + + if ( !comment_exists($comment_author, $comment_date) ) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent'); + wp_insert_comment($commentdata); + $num_comments++; + } + } } + if ( $num_comments ) + printf(__(' (%s comments)'), $num_comments); + + // Now for post meta + preg_match_all('|(.*?)|is', $post, $postmeta); + $postmeta = $postmeta[1]; + if ( $postmeta) { foreach ($postmeta as $p) { + $key = $this->get_tag( $p, 'wp:meta_key' ); + $value = $this->get_tag( $p, 'wp:meta_value' ); + add_post_meta( $post_id, $key, $value ); + } } + + $index++; + } + + echo '
    '; + + wp_import_cleanup($this->id); + + echo '

    '.sprintf(__('All done. Have fun!'), get_option('home')).'

    '; + } + + function import() { + $this->id = (int) $_GET['id']; + + $this->file = get_attached_file($this->id); + $this->get_authors_from_post(); + $this->get_entries(); + $this->process_posts(); + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->select_authors(); + break; + case 2: + $this->import(); + break; + } + $this->footer(); + } + + function WP_Import() { + // Nothing. + } +} + +$wp_import = new WP_Import(); + +register_importer('wordpress', 'WordPress', __('Import posts from a WordPress export file'), array ($wp_import, 'dispatch')); + +?> diff --git a/wp-admin/index.php b/wp-admin/index.php new file mode 100644 index 0000000..306e0b3 --- /dev/null +++ b/wp-admin/index.php @@ -0,0 +1,181 @@ + + +
    + +

    + +
    +

    + +items) && 0 != count($rss->items) ) { +?> + + + +get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5"); +$numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); + +if ( $comments || $numcomments ) : +?> +
    +

    »

    + + +

    »

    + +
    + + + + + +get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) : +?> +
    +

    »

    + +
    + + +get_results("SELECT ID, post_title, post_date_gmt FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_date_gmt > '$today' ORDER BY post_date ASC") ) : +?> +
    +

    +
      +post_title == '') + $post->post_title = sprintf(__('Post #%s'), $post->ID); + echo "
    • " . sprintf(__('%1$s in %2$s'), "$post->post_title", human_time_diff( current_time('timestamp', 1), strtotime($post->post_date_gmt. ' GMT') )) . "
    • "; +} +?> +
    +
    + + +
    +

    +get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); +if (0 < $numposts) $numposts = number_format($numposts); + +$numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); +if (0 < $numcomms) $numcomms = number_format($numcomms); + +$numcats = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories"); +if (0 < $numcats) $numcats = number_format($numcats); +?> +

    posts and %3$s comments, contained within %5$s categories.'), $numposts, 'edit.php', $numcomms, 'edit-comments.php', $numcats, 'categories.php'); ?>

    +
    + + +
    +items) && 0 != count($rss->items) ) { + print "

    $title

    "; + $rss->items = array_slice($rss->items, 0, 3); + foreach ($rss->items as $item ) { +?> +

    '>

    +

    + + + +items) && 0 != count($rss->items) ) { +?> +
    +

    »

    +
      +items = array_slice($rss->items, 0, 20); +foreach ($rss->items as $item ) { +?> +
    • '>
    • + +
    +
    + +
      +
    +
    +
    + + diff --git a/wp-admin/inline-uploading.php b/wp-admin/inline-uploading.php new file mode 100644 index 0000000..601f530 --- /dev/null +++ b/wp-admin/inline-uploading.php @@ -0,0 +1,728 @@ +".__('Go back').''); + +wp_delete_attachment($attachment); + +header("Location: " . basename(__FILE__) ."?post=$post&all=$all&action=view&start=$start"); +die; + +case 'save': + +check_admin_referer('inlineuploading'); + +$overrides = array('action'=>'save'); + +$file = wp_handle_upload($_FILES['image'], $overrides); + +if( isset( $file[ 'error' ] ) == false ) + $file[ 'error' ] = apply_filters( "check_uploaded_file", $file[ 'error' ] ); + +if ( isset($file['error']) ) + die($file['error'] . '
    '.__('Back to Image Uploading').''); + +$url = $file['url']; +$type = $file['type']; +$file = $file['file']; +$filename = basename($file); + +// Construct the attachment array +$attachment = array( + 'post_title' => $imgtitle ? $imgtitle : $filename, + 'post_content' => $descr, + 'post_type' => 'attachment', + 'post_parent' => $post, + 'post_mime_type' => $type, + 'guid' => $url + ); + +// Save the data +$id = wp_insert_attachment($attachment, $file, $post); + +if ( preg_match('!^image/!', $attachment['post_mime_type']) ) { + // Generate the attachment's postmeta. + $imagesize = getimagesize($file); + $imagedata['width'] = $imagesize['0']; + $imagedata['height'] = $imagesize['1']; + list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']); + $imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'"; + $imagedata['file'] = $file; + + add_post_meta($id, '_wp_attachment_metadata', $imagedata); + + if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) { + if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 ) + $thumb = wp_create_thumbnail($file, 128); + elseif ( $imagedata['height'] > 96 ) + $thumb = wp_create_thumbnail($file, 96); + + if ( @file_exists($thumb) ) { + $newdata = $imagedata; + $newdata['thumb'] = basename($thumb); + update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata); + } else { + $error = $thumb; + } + } +} else { + add_post_meta($id, '_wp_attachment_metadata', array()); +} + +header("Location: " . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0"); +die(); + +case 'upload': + +$current_1 = ' class="current"'; +$back = $next = false; +break; + +case 'view': + +// How many images do we show? How many do we query? +$num = 5; +$double = $num * 2; + +if ( $post && (empty($all) || $all == 'false') ) { + $and_post = "AND post_parent = '$post'"; + $current_2 = ' class="current"'; +} else { + $current_3 = ' class="current"'; +} + +if (! current_user_can('edit_others_posts') ) + $and_user = "AND post_author = " . $user_ID; + +if ( $last ) + $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment' $and_user $and_post") - $num; +else + $start = (int) $start; + +if ( $start < 0 ) + $start = 0; + +if ( '' == $sort ) + $sort = "post_date_gmt DESC"; + +$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_type = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A); + +if ( count($attachments) == 0 ) { + header("Location: " . basename(__FILE__) ."?post=$post&action=upload" ); + die; +} elseif ( count($attachments) > $num ) { + $next = $start + count($attachments) - $num; +} else { + $next = false; +} + +if ( $start > 0 ) { + $back = $start - $num; + if ( $back < 1 ) + $back = '0'; +} else { + $back = false; +} + +$uwidth_sum = 0; +$html = ''; +$popups = ''; +$style = ''; +$script = ''; +if ( count($attachments) > 0 ) { + $attachments = array_slice( $attachments, 0, $num ); + $__delete = __('Delete'); + $__not_linked = __('Not Linked'); + $__linked_to_page = __('Linked to Page'); + $__linked_to_image = __('Linked to Image'); + $__linked_to_file = __('Linked to File'); + $__using_thumbnail = __('Using Thumbnail'); + $__using_original = __('Using Original'); + $__using_title = __('Using Title'); + $__using_filename = __('Using Filename'); + $__using_icon = __('Using Icon'); + $__no_thumbnail = ''.__('No Thumbnail').''; + $__send_to_editor = __('Send to editor'); + $__close = __('Close Options'); + $__confirmdelete = __('Delete this file from the server?'); + $__nothumb = __('There is no thumbnail associated with this photo.'); + $script .= "notlinked = '$__not_linked'; +linkedtoimage = '$__linked_to_image'; +linkedtopage = '$__linked_to_page'; +linkedtofile = '$__linked_to_file'; +usingthumbnail = '$__using_thumbnail'; +usingoriginal = '$__using_original'; +usingtitle = '$__using_title'; +usingfilename = '$__using_filename'; +usingicon = '$__using_icon'; +var aa = new Array(); +var ab = new Array(); +var imga = new Array(); +var imgb = new Array(); +var srca = new Array(); +var srcb = new Array(); +var title = new Array(); +var filename = new Array(); +var icon = new Array(); +"; + foreach ( $attachments as $key => $attachment ) { + $ID = $attachment['ID']; + $href = get_attachment_link($ID); + $meta = get_post_meta($ID, '_wp_attachment_metadata', true); + if (!is_array($meta)) { + $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key + if (!is_array($meta)) { + $meta = array(); + } + add_post_meta($ID, '_wp_attachment_metadata', $meta); + } + $attachment = array_merge($attachment, $meta); + $noscript = " +"; + $send_delete_cancel = "$__send_to_editor +$__delete + $__close +"; + $uwidth_sum += 128; + if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) { + $image = & $attachment; + if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) { + $src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']); + $script .= "srca[{$ID}] = '$src'; +srcb[{$ID}] = '{$image['guid']}'; +"; + $thumb = 'true'; + $thumbtext = $__using_thumbnail; + } else { + $src = $image['guid']; + $thumb = 'false'; + $thumbtext = $__no_thumbnail; + } + list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']); + $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"'; + $xpadding = (128 - $image['uwidth']) / 2; + $ypadding = (96 - $image['uheight']) / 2; + $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n"; + $title = wp_specialchars($image['post_title'], ENT_QUOTES); + $script .= "aa[{$ID}] = ''; +ab[{$ID}] = ''; +imga[{$ID}] = '\"{$title}\"'; +imgb[{$ID}] = '\"{$title}\"'; +"; + $html .= "
    +
    + \"{$title}\" +
    + {$noscript} +
    +"; + $popups .= "
    +"; + } else { + $title = wp_specialchars($attachment['post_title'], ENT_QUOTES); + $filename = basename($attachment['guid']); + $icon = get_attachment_icon($ID); + $toggle_icon = "$__using_title"; + $script .= "aa[{$ID}] = ''; +ab[{$ID}] = ''; +title[{$ID}] = '{$title}'; +filename[{$ID}] = '{$filename}'; +icon[{$ID}] = '{$icon}'; +"; + $html .= "
    + + {$noscript} +
    +"; + $popups .= " +"; + } + } +} + +$images_width = $uwidth_sum + ( count($images) * 6 ) + 35; + +break; + +default: +die(__('This script was not meant to be called directly.')); +} + +?> + + + + + + + + + +
      +>"> +get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ) { ?> +>"> + +get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_type = 'attachment'")) { ?> +>"> + +
    • + + +
    • " title="">|«
    • +
    • ">«
    • + +
    • +
    • «
    • + + +
    • ">
    • +
    • " title="">»|
    • + +
    • +
    • »|
    • + + +
    + +
    + +
    + + +
    +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + +
    + + + + + +
    + + + + +
    +
    + +
    + + + + + + diff --git a/wp-admin/install-helper.php b/wp-admin/install-helper.php new file mode 100644 index 0000000..86138db --- /dev/null +++ b/wp-admin/install-helper.php @@ -0,0 +1,152 @@ +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; +} + +/** + ** 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
    "); + 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; +} + + +/** + ** maybe_drop_column() + ** Drop column from db table if it exists. + ** Returns: true if it doesn't already exist or on successful drop + ** false on error + */ +function maybe_drop_column($table_name, $column_name, $drop_ddl) { + global $wpdb; + foreach ($wpdb->get_col("DESC $table_name",0) as $column ) { + if ($column == $column_name) { + //found it try to drop it. + $q = $wpdb->query($drop_ddl); + // we cannot directly tell that whether this succeeded! + foreach ($wpdb->get_col("DESC $table_name",0) as $column ) { + if ($column == $column_name) { + return false; + } + } + } + } + // else didn't find it + return true; +} + + +/** + ** check_column() + ** Check column matches passed in criteria. + ** Pass in null to skip checking that criteria + ** Returns: true if it matches + ** false otherwise + ** (case sensitive) Column names returned from DESC table are: + ** Field + ** Type + ** Null + ** Key + ** Default + ** Extra + */ +function check_column($table_name, $col_name, $col_type, $is_null = null, $key = null, $default = null, $extra = null) { + global $wpdb, $debug; + $diffs = 0; + $results = $wpdb->get_results("DESC $table_name"); + + foreach ($results as $row ) { + if ($debug > 1) print_r($row); + if ($row->Field == $col_name) { + // got our column, check the params + if ($debug) echo ("checking $row->Type against $col_type\n"); + if (($col_type != null) && ($row->Type != $col_type)) { + ++$diffs; + } + if (($is_null != null) && ($row->Null != $is_null)) { + ++$diffs; + } + if (($key != null) && ($row->Key != $key)) { + ++$diffs; + } + if (($default != null) && ($row->Default != $default)) { + ++$diffs; + } + if (($extra != null) && ($row->Extra != $extra)) { + ++$diffs; + } + if ($diffs > 0) { + if ($debug) echo ("diffs = $diffs returning false\n"); + return false; + } + return true; + } // end if found our column + } + return false; +} + +/* +echo "

    testing

    "; +echo "
    ";
    +
    +//check_column('wp_links', 'link_description', 'mediumtext'); 
    +//if (check_column($wpdb->comments, 'comment_author', 'tinytext'))
    +//    echo "ok\n";
    +$error_count = 0;
    +$tablename = $wpdb->links;
    +// check the column
    +if (!check_column($wpdb->links, 'link_description', 'varchar(255)'))
    +{
    +    $ddl = "ALTER TABLE $wpdb->links MODIFY COLUMN link_description varchar(255) NOT NULL DEFAULT '' ";
    +    $q = $wpdb->query($ddl);
    +}
    +if (check_column($wpdb->links, 'link_description', 'varchar(255)')) {
    +    $res .= $tablename . ' - ok 
    '; +} else { + $res .= 'There was a problem with ' . $tablename . '
    '; + ++$error_count; +} +echo "
    "; +*/ +?> \ No newline at end of file diff --git a/wp-admin/invites.php b/wp-admin/invites.php new file mode 100644 index 0000000..d955387 --- /dev/null +++ b/wp-admin/invites.php @@ -0,0 +1,196 @@ +data->ID, "invites_list" ); + $pos = strpos( $invites_list, substr( $email, 1 ) ); + if( $pos == true ) { + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=alreadysent&to=" . urlencode( $email ) ); + exit; + } + $invites_list .= strtolower( $email ) . " "; + update_usermeta( $current_user->data->ID, "invites_list", $invites_list ); + + $msg = get_site_option( "invites_default_message" ); + $subject = get_site_option( "invites_default_subject" ); + $from = $cache_userdata[ $user_ID ]->user_email; + + $visitor_pass = md5( $email ); + $msg = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $msg ); + $msg = str_replace( "LASTNAME", $_POST[ 'lname' ], $msg ); + $msg = str_replace( "PERSONALMESSAGE", $_POST[ 'personalmessage' ], $msg ); + $msg = str_replace( "VISITORPASS", $visitor_pass, $msg ); + $msg = str_replace( "\\r\\n", "\n", stripslashes( str_replace( "REGURL", "http://" . $current_site->domain . "/invite/" . $visitor_pass, $msg ) ) ); + + $subject = str_replace( "FIRSTNAME", $_POST[ 'fname' ], $subject ); + if( $cache_userdata[ $user_ID ]->display_name != '' ) { + $username = $cache_userdata[ $user_ID ]->display_name; + } elseif( $cache_userdata[ $user_ID ]->first_name != '' ) { + $username = $cache_userdata[ $user_ID ]->first_name; + } elseif( $cache_userdata[ $user_ID ]->nickname != '' ) { + $username = $cache_userdata[ $user_ID ]->nickname; + } else { + $username = __( 'Someone' ); + } + $msg = str_replace( "USERNAME", ucfirst( $username ), $msg ); + $subject = str_replace( "USERNAME", ucfirst( $username ), $subject ); + + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', 'invite' , '".md5( strtolower( $email ) )."')" ); + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_invited_by' , '$user_ID')" ); + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_to_email' , '{$_POST[ 'email' ]}')" ); + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_to_name' , '{$_POST[ 'fname' ]}')" ); + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_invite_timestamp' , UNIX_TIMESTAMP())" ); + if( $_POST[ 'add_blog_to_blogroll' ] == '1' ) { + $t = array( "blogid" => $wpdb->blogid, "userid" => get_current_user_id() ); + $wpdb->query( "INSERT INTO ".$wpdb->usermeta." ( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '0', '".md5( strtolower( $email ) )."_add_to_blogroll' , '" . serialize( $t ) . "')" ); + } + + mail( $_POST[ 'email' ], $subject, $msg, "From: $from" ); + if( is_site_admin() == false ) { + $invites_left = $invites_left - 1; + update_usermeta( $user_ID, "invites_left", $invites_left ); + } + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=sent&to=" . urlencode( $email ) ); + exit; + } else { + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=notsent&to=" . urlencode( $email ) ); + exit; + } + } else { + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=completeform" ); + exit; + } +} elseif( $_GET[ 'action' ] == 'deleteinvite' ) { + delete_invite( md5( $_GET[ 'inviteemail' ] ) ); + header( "Location: ".get_settings( "siteurl" )."/wp-admin/invites.php?result=deletedinvite" ); + exit; +} + +if( $_POST[ 'personalmessage' ] == '' ) { + if( $current_site->site_name != '' ) { + $site_name = $current_site->site_name; + } else { + $site_name = get_settings( 'blogname' ); + } + $_POST[ 'personalmessage' ] = sprintf( __( "I've been using %s and thought you might +like to try it out. Here's an invitation to +create an account." ), $site_name ) ; +} + +include('admin-header.php'); +if (isset($_GET['result'] ) && $_GET['result'] == 'sent' ) { + ?>

    escape( $_GET[ 'to' ] ) ) ?>

    escape( $_GET[ 'to' ] ) ) ?>

    escape( $_GET[ 'to' ] ) ) ?>

    + +
    +

    +
    + +
    + + + + + + + + + + + + + + + + + + + + + + +
    +
    +

    + +

    +
    +
    + +
    +

    Sorry, you have used all your invites!

    +
    + data->ID, "invites_list" ); +if( $invites_list != '' ) +{ + if( strlen( $invites_list ) > 3 ) { + ?>
    +

    Already Invited

    + get_row( "SELECT ID FROM {$wpdb->users} WHERE user_email = '$val'" ); + if( $id ) { + $invited_user_id = $id->ID; + } else { + $invited_user_id = $wpdb->get_var( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'invite_hash' AND meta_value = '" . md5( $val ) . "'" ); + } + + if( $invited_user_id != 0 ) { + $invited_user_blog = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$invited_user_id' AND meta_key='source_domain'" ); + } else { + $invited_user_blog = ''; + } + $invited_user_login = $wpdb->get_var( "SELECT user_login FROM $wpdb->users WHERE ID = '$invited_user_id'" ); + if( $invited_user_blog != '' ) { + print ""; + } else { + $invited_time = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '" . md5( $val ) . "_invite_timestamp'" ); + if( $invited_time ) { + $days_left = intval( get_site_option( "invite_time_limit" ) ) - intval( ( time() - $invited_time ) / 86400 ); + print ""; + } else { + print ""; + } + } + } + } + ?>
    $val$invited_user_loginhttp://$invited_user_blog
    $val$invited_user_loginInvite Not Used Yet ($days_left days left)"; + if ( function_exists('delete_invite') ) + print " (Delete)"; + print "
    $val$invited_user_loginInvite Not Used Yet"; + if ( function_exists('delete_invite') ) + print " (Delete)"; + print "
    + diff --git a/wp-admin/link-add.php b/wp-admin/link-add.php new file mode 100644 index 0000000..71ce294 --- /dev/null +++ b/wp-admin/link-add.php @@ -0,0 +1,49 @@ + + + +

    + + + + +
    +You can drag Link This to your toolbar and when you click it a window will pop up that will allow you to add whatever site you’re on to your bookmarks! Right now this only works on Mozilla or Netscape, but we’re working on it.

    '), "javascript:void(linkmanpopup=window.open('" . get_settings('siteurl') . "/wp-admin/link-add.php?action=popup&linkurl='+escape(location.href)+'&name='+escape(document.title),'LinkManager','scrollbars=yes,width=750,height=550,left=15,top=15,status=yes,resizable=yes'));linkmanpopup.focus();window.focus();linkmanpopup.focus();") ?> +
    + + diff --git a/wp-admin/link-import.php b/wp-admin/link-import.php new file mode 100644 index 0000000..352b6e7 --- /dev/null +++ b/wp-admin/link-import.php @@ -0,0 +1,133 @@ + + + +
    +

    +
    + + +

    +

    + + +
    +

    + +
    + +
    +

    + +
    + + +
    + +


    +

    + +

    +
    + +
    + +
    + +

    + false, 'test_type' => false); + $file = wp_handle_upload($_FILES['userfile'], $overrides); + + if ( isset($file['error']) ) + die($file['error']); + + $url = $file['url']; + $opml_url = $file['file']; + $blogrolling = false; + } + + if (isset($opml_url) && $opml_url != '') { + $opml = wp_remote_fopen($opml_url); + include_once('link-parse-opml.php'); + + $link_count = count($names); + for ($i = 0; $i < $link_count; $i++) { + if ('Last' == substr($titles[$i], 0, 4)) + $titles[$i] = ''; + if ('http' == substr($titles[$i], 0, 4)) + $titles[$i] = ''; + $link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i]); + wp_insert_link($link); + echo sprintf('

    '.__('Inserted %s').'

    ', $names[$i]); + } +?> +

    manage those bookmarks.'), $link_count, $cat_id, 'link-manager.php') ?>

    +" . __("You need to supply your OPML url. Press back on your browser and try again") . "

    \n"; + } // end else + + if ( ! $blogrolling ) + @unlink($opml_url); +?> +
    + diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php new file mode 100644 index 0000000..7638d5f --- /dev/null +++ b/wp-admin/link-manager.php @@ -0,0 +1,209 @@ + + + +

    '; + $deleted = (int) $_GET['deleted']; + printf(__('%s bookmarks deleted.'), $deleted); + echo '

    '; +} +?> + +
    + +

    +

    +
    +

    Currently showing + + +bookmarks ordered by + + +

    + +
    + + +get_results( "SELECT link_id, category_id, count( * ) AS c FROM {$wpdb->link2cat} GROUP BY link_id, category_id" ); + if( $results != null ) { + foreach( $results as $link ) { + if( $link->c > 1 ) { + $wpdb->query( "DELETE FROM {$wpdb->link2cat} WHERE link_id='{$link->link_id}' AND category_id='{$link->category_id}'" ); + $wpdb->query( "INSERT INTO {$wpdb->link2cat} VALUES ( 0, '{$link->link_id}', '{$link->category_id}' )" ); + } + } + } + wp_cache_set( "checked_bookmarks_table", "1", "options" ); +} + +?> + + diff --git a/wp-admin/link-parse-opml.php b/wp-admin/link-parse-opml.php new file mode 100644 index 0000000..196f3cb --- /dev/null +++ b/wp-admin/link-parse-opml.php @@ -0,0 +1,65 @@ + 'link_url', + 'HTMLURL' => 'link_url', + 'TEXT' => 'link_name', + 'TITLE' => 'link_name', + 'TARGET' => 'link_target', + 'DESCRIPTION' => 'link_description', + 'XMLURL' => 'link_rss' +); + +$map = $opml_map; + +/** + ** startElement() + ** Callback function. Called at the start of a new xml tag. + **/ +function startElement($parser, $tagName, $attrs) { + global $updated_timestamp, $all_links, $map; + global $names, $urls, $targets, $descriptions, $feeds; + + if ($tagName == 'OUTLINE') { + foreach (array_keys($map) as $key) { + if (isset($attrs[$key])) { + $$map[$key] = $attrs[$key]; + } + } + + //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]
    \n"); + + // save the data away. + $names[] = $link_name; + $urls[] = $link_url; + $targets[] = $link_target; + $feeds[] = $link_rss; + $descriptions[] = $link_description; + } // end if outline +} + +/** + ** endElement() + ** Callback function. Called at the end of an xml tag. + **/ +function endElement($parser, $tagName) { + // nothing to do. +} + +// Create an XML parser +$xml_parser = xml_parser_create(); + +// Set the functions to handle opening and closing tags +xml_set_element_handler($xml_parser, "startElement", "endElement"); + +if (!xml_parse($xml_parser, $opml, true)) { + echo(sprintf(__('XML error: %1$s at line %2$s'), + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); +} + +// Free up memory used by the XML parser +xml_parser_free($xml_parser); +?> diff --git a/wp-admin/link.php b/wp-admin/link.php new file mode 100644 index 0000000..6e3056d --- /dev/null +++ b/wp-admin/link.php @@ -0,0 +1,128 @@ +query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)"); + + header('Location: '.$this_file); + break; + + case 'add' : + check_admin_referer('add-bookmark'); + + add_link(); + + header('Location: '.$_SERVER['HTTP_REFERER'].'?added=true'); + break; + + case 'save' : + $link_id = (int) $_POST['link_id']; + check_admin_referer('update-bookmark_' . $link_id); + + edit_link($link_id); + + wp_redirect($this_file); + exit; + break; + + case 'delete' : + $link_id = (int) $_GET['link_id']; + check_admin_referer('delete-bookmark_' . $link_id); + + if (!current_user_can('manage_links')) + die(__("Cheatin' uh ?")); + + wp_delete_link($link_id); + + wp_redirect($this_file); + break; + + case 'edit' : + wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') ); + if ( current_user_can( 'manage_categories' ) ) + wp_enqueue_script( 'ajaxcat' ); + $parent_file = 'link-manager.php'; + $submenu_file = 'link-manager.php'; + $title = __('Edit Bookmark'); + include_once ('admin-header.php'); + if (!current_user_can('manage_links')) + die(__('You do not have sufficient permissions to edit the bookmarks for this blog.')); + + $link_id = (int) $_GET['link_id']; + + if (!$link = get_link_to_edit($link_id)) + die(__('Link not found.')); + + include ('edit-link-form.php'); + break; + + default : + break; +} + +include ('admin-footer.php'); +?> diff --git a/wp-admin/list-manipulation-js.php b/wp-admin/list-manipulation-js.php new file mode 100644 index 0000000..ef09467 --- /dev/null +++ b/wp-admin/list-manipulation-js.php @@ -0,0 +1,163 @@ + +addLoadEvent(function(){theList=new listMan();}); +function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="";if(confirm(message))return obj.ajaxDelete(what,id);else return false;} +function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);} + +function WPAjax(file, responseEl){//class WPAjax extends sack + this.getResponseElement=function(r){var p=document.getElementById(r+'-p');if(!p){p=document.createElement('span');p.id=r+'-p';document.getElementById(r).appendChild(p);}this.myResponseElement=p; } + this.parseAjaxResponse=function(){ + if(isNaN(this.response)){this.myResponseElement.innerHTML='

    '+this.response+'

    ';return false;} + this.response=parseInt(this.response,10); + if(-1==this.response){this.myResponseElement.innerHTML="

    ";return false;} + else if(0==this.response){this.myResponseElement.innerHTML="

    ";return false;} + return true; + } + this.parseAjaxResponseXML=function(){ + if(this.responseXML&&typeof this.responseXML=='object')return true; + if(isNaN(this.response)){this.myResponseElement.innerHTML='

    '+this.response+'

    ';return false;} + var r=parseInt(this.response,10); + if(-1==r){this.myResponseElement.innerHTML="

    ";} + else if(0==r){this.myResponseElement.innerHTML="

    ";} + return false; + } + this.init(file,responseEl); +} WPAjax.prototype=new sack; + WPAjax.prototype.init=function(f,r){ + this.encVar('cookie', document.cookie); + this.requestFile=f;this.getResponseElement(r);this.method='POST'; + this.onLoading=function(){this.myResponseElement.innerHTML="";}; + this.onLoaded=function(){this.myResponseElement.innerHTML="";}; + this.onInteractive=function(){this.myResponseElement.innerHTML="";}; + } + +function listMan(theListId){ + this.theList=null; + this.ajaxRespEl=null; + this.inputData='';this.clearInputs=new Array();this.showLink=1; + this.topAdder=0;this.alt='alternate';this.recolorPos;this.reg_color='#FFFFFF';this.alt_color='#F1F1F1'; + this.addComplete=null;this.delComplete=null;this.dimComplete=null; + var listType;var listItems; + self.aTrap=0; + + this.ajaxAdder=function(what,where,update){//for TR, server must wrap TR in TABLE TBODY. this.makeEl cleans it + if(self.aTrap)return;self.aTrap=1;setTimeout('aTrap=0',300); + this.ajaxAdd=new WPAjax('admin-ajax.php',this.ajaxRespEl?this.ajaxRespEl:'ajax-response'); + if(this.ajaxAdd.failed)return true; + this.grabInputs(where); + var tempObj=this; + this.ajaxAdd.onCompletion=function(){ + if(!this.parseAjaxResponseXML())return; + var newItems=this.responseXML.getElementsByTagName(what); + if(tempObj.topAdder)tempObj.recolorPos=0; + if(newItems){for (c=0;c

    ';} + else this.myResponseElement.innerHTML=''; + for(var i=0;i +{$item[0]}"; + else + echo "\n\t
  • {$item[0]}
  • "; + } +} + +?> + + + + + diff --git a/wp-admin/menu.php b/wp-admin/menu.php new file mode 100644 index 0000000..f363a76 --- /dev/null +++ b/wp-admin/menu.php @@ -0,0 +1,141 @@ +get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); +$submenu['edit.php'][25] = array(sprintf(__("Awaiting Moderation (%s)"), "$awaiting_mod"), 'edit_posts', 'moderation.php'); +//$submenu['edit.php'][30] = array(__('Files'), 'edit_files', 'templates.php'); +$submenu['edit.php'][35] = array(__('Import'), 'import', 'import.php'); +$submenu['edit.php'][40] = array(__('Export'), 'import', 'export.php'); +//$invites_left = get_usermeta( $user_ID, 'invites_left' ); +//$submenu['edit.php'][45] = array(sprintf(__("Invites (%s)"), $invites_left ), 'edit_posts', 'invites.php'); // TODO: put somewhere else. + +$submenu['link-manager.php'][5] = array(__('Manage Bookmarks'), 'manage_links', 'link-manager.php'); +$submenu['link-manager.php'][10] = array(__('Add Bookmark'), 'manage_links', 'link-add.php'); +$submenu['link-manager.php'][20] = array(__('Import Bookmarks'), 'manage_links', 'link-import.php'); + +if ( current_user_can('edit_users') ) { + $submenu['users.php'][5] = array(__('Authors & Users'), 'edit_users', 'users.php'); + $submenu['users.php'][10] = array(__('Your Profile'), 'read', 'profile.php'); +} else { + $submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php'); +} + +$submenu['options-general.php'][10] = array(__('General'), 'manage_options', 'options-general.php'); +$submenu['options-general.php'][15] = array(__('Writing'), 'manage_options', 'options-writing.php'); +$submenu['options-general.php'][20] = array(__('Reading'), 'manage_options', 'options-reading.php'); +$submenu['options-general.php'][25] = array(__('Discussion'), 'manage_options', 'options-discussion.php'); +//$submenu['options-general.php'][30] = array(__('Privacy'), 'manage_options', 'options-privacy.php'); +//$submenu['options-general.php'][35] = array(__('Permalinks'), 'manage_options', 'options-permalink.php'); +//$submenu['options-general.php'][40] = array(__('Miscellaneous'), 'manage_options', 'options-misc.php'); + +//$submenu['plugins.php'][5] = array(__('Plugins'), 'activate_plugins', 'plugins.php'); +//$submenu['plugins.php'][10] = array(__('Plugin Editor'), 'edit_plugins', 'plugin-editor.php'); + +$submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); +//$submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php'); + +// Create list of page plugin hook names. +foreach ($menu as $menu_page) { + $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]); +} + +do_action('admin_menu', ''); + +// Loop over submenus and remove pages for which the user does not have privs. +foreach ($submenu as $parent => $sub) { + foreach ($sub as $index => $data) { + if ( ! current_user_can($data[1]) ) { + $menu_nopriv[$data[2]] = true; + unset($submenu[$parent][$index]); + } + } + + if ( empty($submenu[$parent]) ) + unset($submenu[$parent]); +} + +// Loop over the top-level menu. +// Remove menus that have no accessible submenus and require privs that the user does not have. +// Menus for which the original parent is not acessible due to lack of privs will have the next +// submenu in line be assigned as the new menu parent. +foreach ( $menu as $id => $data ) { + // If submenu is empty... + if ( empty($submenu[$data[2]]) ) { + // And user doesn't have privs, remove menu. + if ( ! current_user_can($data[1]) ) { + $menu_nopriv[$data[2]] = true; + unset($menu[$id]); + } + } else { + $subs = $submenu[$data[2]]; + $first_sub = array_shift($subs); + $old_parent = $data[2]; + $new_parent = $first_sub[2]; + // If the first submenu is not the same as the assigned parent, + // make the first submenu the new parent. + if ( $new_parent != $old_parent ) { + $real_parent_file[$old_parent] = $new_parent; + $menu[$id][2] = $new_parent; + + foreach ($submenu[$old_parent] as $index => $data) { + $submenu[$new_parent][$index] = $submenu[$old_parent][$index]; + unset($submenu[$old_parent][$index]); + } + unset($submenu[$old_parent]); + } + } +} + +get_currentuserinfo(); +if( is_site_admin() ) { + $menu[1] = array(__('Site Admin'), '10', 'wpmu-admin.php' ); + $submenu[ 'wpmu-admin.php' ][5] = array( 'Blogs', '10', 'wpmu-blogs.php' ); + $submenu[ 'wpmu-admin.php' ][10] = array( 'Users', '10', 'wpmu-users.php' ); + $submenu[ 'wpmu-admin.php' ][15] = array( 'Feeds', '10', 'wpmu-feeds.php' ); + $submenu[ 'wpmu-admin.php' ][20] = array( 'Themes', '10', 'wpmu-themes.php' ); + $submenu[ 'wpmu-admin.php' ][25] = array( 'Options', '10', 'wpmu-options.php' ); + $submenu[ 'wpmu-admin.php' ][30] = array( 'Upgrade', '10', 'wpmu-upgrade-site.php' ); +} +ksort($menu); // make it all pretty + +if (! user_can_access_admin_page()) { + global $wpdb; + // find the blog of this user first + $primary_blog = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '$user_ID' AND meta_key = 'primary_blog'" ); + if( $primary_blog ) { + header( "Location: " . get_blog_option( $primary_blog, "siteurl" ) . "/wp-admin/" ); + exit; + } + die( __('You do not have sufficient permissions to access this page.') ); +} + +?> diff --git a/wp-admin/moderation.php b/wp-admin/moderation.php new file mode 100644 index 0000000..5839e6f --- /dev/null +++ b/wp-admin/moderation.php @@ -0,0 +1,232 @@ + $v) { + $comment[intval($k)] = $v; + } +} + +switch($action) { + +case 'update': + + check_admin_referer('moderate-comments'); + + if ( ! current_user_can('moderate_comments') ) + die('

    '.__('Your level is not high enough to moderate comments.').'

    '); + + $item_ignored = 0; + $item_deleted = 0; + $item_approved = 0; + $item_spam = 0; + + foreach($comment as $key => $value) { + if ($feelinglucky && 'later' == $value) + $value = 'delete'; + switch($value) { + case 'later': + // do nothing with that comment + // wp_set_comment_status($key, "hold"); + ++$item_ignored; + break; + case 'delete': + wp_set_comment_status($key, 'delete'); + ++$item_deleted; + break; + case 'spam': + wp_set_comment_status($key, 'spam'); + ++$item_spam; + break; + case 'approve': + wp_set_comment_status($key, 'approve'); + if ( get_settings('comments_notify') == true ) { + wp_notify_postauthor($key); + } + ++$item_approved; + break; + } + } + + $file = basename(__FILE__); + header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam"); + exit(); + +break; + +default: + +require_once('admin-header.php'); + +if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) { + echo "
    \n

    "; + $approved = (int) $_GET['approved']; + $deleted = (int) $_GET['deleted']; + $ignored = (int) $_GET['ignored']; + $spam = (int) $_GET['spam']; + if ($approved) { + if ('1' == $approved) { + echo __("1 comment approved") . "
    \n"; + } else { + echo sprintf(__("%s comments approved
    "), $approved) . "\n"; + } + } + if ($deleted) { + if ('1' == $deleted) { + echo __("1 comment deleted") . "
    \n"; + } else { + echo sprintf(__("%s comments deleted"), $deleted) . "
    \n"; + } + } + if ($spam) { + if ('1' == $spam) { + echo __("1 comment marked as spam") . "
    \n"; + } else { + echo sprintf(__("%s comments marked as spam"), $spam) . "
    \n"; + } + } + if ($ignored) { + if ('1' == $ignored) { + echo __("1 comment unchanged") . "
    \n"; + } else { + echo sprintf(__("%s comments unchanged"), $ignored) . "
    \n"; + } + } + echo "

    \n"; +} + +?> + +
    + +get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'"); +else + $comments = ''; + +if ($comments) { + // list all comments that are waiting for approval + $file = basename(__FILE__); +?> +

    +
    + + +
      +comment_date); + $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID='$comment->comment_post_ID'"); + if ($i % 2) $class = 'js-unapproved alternate'; + else $class = 'js-unapproved'; + echo "\n\t
    1. "; + ?> +

      comment_author_email) { ?>| comment_author_url && 'http://' != $comment->comment_author_url) { ?> | |

      + +

      — [ comment_ID.'">' . __('Edit') . ' | '; +echo " comment_post_ID."&comment=".$comment->comment_ID."\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . sprintf(__("You are about to delete this comment by "%s".\\n"Cancel" to stop, "OK" to delete."), js_escape($comment->comment_author)) . "', theCommentList );\">" . __('Delete ') . " | "; ?> +comment_post_ID); +$post_title = wp_specialchars( $post->post_title, 'double' ); +$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; +?> + ] — + +   +   +   + +

      + +
    2. + +
    + +
    + +

    + + + +
    +'.__("Currently there are no comments for you to moderate.") . "

    \n"; +} +?> + +
    + + diff --git a/wp-admin/options-discussion.php b/wp-admin/options-discussion.php new file mode 100644 index 0000000..247c01f --- /dev/null +++ b/wp-admin/options-discussion.php @@ -0,0 +1,101 @@ +find_spam(); + echo $retrospaminator->display_edit_form( $result ); + include('./admin-footer.php'); + exit; +} +?> + +
    +

    +
    + +
    +(These settings may be overridden for individual articles.)') ?> +
      +
    • + +
    • +
    • + +
    • +
    • + +
    • +
    +
    +
    + +
      +
    • + +
    • +
    • + +
    • +
    +
    +
    + +
      +
    • + +
    • +
    • +
    • +
    +
    +
    + +

    ' ) ?>

    + +

    Common spam words.') ?>

    +

    + +

    +

    + +

    +
    +
    + +

    +

    + +

    +

    +
    +

    + + + +

    +
    +
    + diff --git a/wp-admin/options-general.php b/wp-admin/options-general.php new file mode 100644 index 0000000..91ac1d7 --- /dev/null +++ b/wp-admin/options-general.php @@ -0,0 +1,123 @@ + + +
    +

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + 1 ) { + ?> + + + + + +
    +
    +
    (more) +
    +
    +
    +

    If you change this we will send you an email at your new address to confirm it. The new address will not become active until confirmed.

    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    UTC time is:') ?>
    +

    +

    +
     Documentation on date formatting. Save option to update sample output.') ?>
    +
    + +

    + + +

    +
    + +
    + + diff --git a/wp-admin/options-head.php b/wp-admin/options-head.php new file mode 100644 index 0000000..54f426c --- /dev/null +++ b/wp-admin/options-head.php @@ -0,0 +1,24 @@ + + +
    + + +

    + diff --git a/wp-admin/options-misc.php b/wp-admin/options-misc.php new file mode 100644 index 0000000..3dd1120 --- /dev/null +++ b/wp-admin/options-misc.php @@ -0,0 +1,52 @@ + + +
    +

    +
    + +
    + + + + + + + + + + +
    : +
    +wp-content/uploads'); ?> +
    + +
    +
    + +

    /> +

    +

    + +

    + +

    + + + +

    +
    +
    + + diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php new file mode 100644 index 0000000..73a610b --- /dev/null +++ b/wp-admin/options-permalink.php @@ -0,0 +1,180 @@ + + +set_permalink_structure($permalink_structure); + } + + if ( isset($_POST['category_base']) ) { + $category_base = $_POST['category_base']; + if (! empty($category_base) ) + $category_base = preg_replace('#/+#', '/', '/' . $_POST['category_base']); + $wp_rewrite->set_category_base($category_base); + } +} + +$permalink_structure = get_settings('permalink_structure'); +$category_base = get_settings('category_base'); + +if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) + $writable = true; +else + $writable = false; + +if ($wp_rewrite->using_index_permalinks()) + $usingpi = true; +else + $usingpi = false; + +$wp_rewrite->flush_rules(); +?> + + +

    + + +
    +

    +

    number of tags are available, and here are some examples to get you started.'); ?>

    + + +
    + +

    +

    + +

    +

    + +

    +

    + +

    +

    + +
    +

    +

    :

    + +

    + +

    /taxonomy/tags would make your category links like http://example.org/taxonomy/tags/uncategorized/. If you leave this blank the default will be used.') ?>

    + +

    /index.php/taxonomy/tags would make your category links like http://example.org/index.php/taxonomy/tags/uncategorized/. If you leave this blank the default will be used.') ?>

    + +

    + : +

    +

    + +

    +
    + +

    .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.') ?>

    +
    + +

    + +

    +
    + + +
    + + diff --git a/wp-admin/options-reading.php b/wp-admin/options-reading.php new file mode 100644 index 0000000..aa806c9 --- /dev/null +++ b/wp-admin/options-reading.php @@ -0,0 +1,95 @@ + + +
    +

    +
    + + + +
    + + + + + + +
    + +
    + +
      +
    • +
    • +
    + +
    +

    + Warning: these pages should not be the same!'); ?> +

    +
    + + +
    +
    + + +
    + + + + + + +
    + + +
    +
    + +
    + + + + + + + + + + +
    +
    + +
    +
    + + + + + +

    +recommended)') ?>
    +

    + + + +

    +
    +
    + diff --git a/wp-admin/options-writing.php b/wp-admin/options-writing.php new file mode 100644 index 0000000..4f362d3 --- /dev/null +++ b/wp-admin/options-writing.php @@ -0,0 +1,66 @@ + + +
    +

    +
    + + + + + + + + + + + + + + + + + + +
    +
    +
    + +
    + + + +

    + + + +

    +
    +
    + + diff --git a/wp-admin/options.php b/wp-admin/options.php new file mode 100644 index 0000000..f2752b9 --- /dev/null +++ b/wp-admin/options.php @@ -0,0 +1,163 @@ + $value) { + $options[] = $key; + } + } else { + $options = explode(',', stripslashes($_POST['page_options'])); + } + + // Save for later. + $old_siteurl = get_settings('siteurl'); + $old_home = get_settings('home'); + + // HACK + // Options that if not there have 0 value but need to be something like "closed" + $nonbools = array('default_ping_status', 'default_comment_status'); + if ($options) { + foreach ($options as $option) { + $option = trim($option); + $value = trim(stripslashes($_POST[$option])); + if( in_array($option, $nonbools) && ( $value == '0' || $value == '') ) + $value = 'closed'; + + if( $option == 'blogdescription' || $option == 'blogname' ) + $value = wp_filter_post_kses( $value ); + + if( $option == 'posts_per_page' && $value == '' ) + $value = 10; + + if( $option == 'new_admin_email' && $value != get_option( 'admin_email' ) ) { + $hash = md5( $value.time().mt_rand() ); + $newadminemail = array( + "hash" => $hash, + "newemail" => $value + ); + update_option( "new_admin_email", $newadminemail ); + wp_mail( $value, "[ " . get_option( 'blogname' ) . " ] New Admin Email Address", "Dear User, + +You recently requested to have the administration email address on +your blog changed. +If this is correct, please click on the following link to change it: +" . get_option( "siteurl" ) . "/adminemail/{$hash}/ + +You can safely ignore and delete this email if you do not want to +take this action. + +" ); + } elseif (update_option($option, $value) ) { + $any_changed++; + } + + if ( 'language' == $option ) { + $value = (int) $value; + update_blog_status( $wpdb->blogid, 'lang_id', $value ); + $any_changed++; + } + if ( 'blog_public' == $option ) { + $value = (int) $value; + update_blog_status( $wpdb->blogid, 'public', $value ); + $any_changed++; + } + } + } + + if ($any_changed) { + // If siteurl or home changed, reset cookies. + if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) { + // 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_settings('home'), get_settings('siteurl')); + } + + //$message = sprintf(__('%d setting(s) saved... '), $any_changed); + } + + $referred = remove_query_arg('updated' , $_SERVER['HTTP_REFERER']); + $goback = add_query_arg('updated', 'true', $_SERVER['HTTP_REFERER']); + $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback); + wp_redirect($goback); + break; + +default: +if (!is_site_admin()) + die('Not admin'); + + include('admin-header.php'); ?> + +
    +

    +
    + + + +get_results("SELECT * FROM $wpdb->options ORDER BY option_name"); + +foreach ($options as $option) : + $value = wp_specialchars($option->option_value, 'single'); + echo " + + + + +"; +endforeach; +?> +
    $option->option_description
    +

    +
    +
    + + + diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php new file mode 100644 index 0000000..4f7fb8f --- /dev/null +++ b/wp-admin/page-new.php @@ -0,0 +1,23 @@ + + + +

    | »

    + + +post_type = 'page'; + + include('edit-page-form.php'); +} +?> + + diff --git a/wp-admin/page.php b/wp-admin/page.php new file mode 100644 index 0000000..cd4d5cc --- /dev/null +++ b/wp-admin/page.php @@ -0,0 +1,159 @@ +flush_rules(); + +$wpvarstoreset = array('action'); + +for ($i=0; $ipost_type == 'post' ) { + header( "Location: " . str_replace( "page.php", "post.php", $_SERVER[ 'REQUEST_URI' ] ) ); + die(); + } + require_once('admin-header.php'); + + if ( !current_user_can('edit_page', $page_ID) ) + die ( __('You are not allowed to edit this page.') ); + + $post = get_post_to_edit($page_ID); + + include('edit-page-form.php'); + ?> +
    +

    + +
    + post_type == 'attachment' ) { + if ( ! wp_delete_attachment($page_id) ) + die( __('Error in deleting...') ); + } else { + if ( !wp_delete_post($page_id) ) + die( __('Error in deleting...') ); + } + + $sendback = $_SERVER['HTTP_REFERER']; + if (strstr($sendback, 'page.php')) $sendback = get_settings('siteurl') .'/wp-admin/page.php'; + elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php'; + $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); + header ('Location: ' . $sendback); + exit(); + break; + +default: + header('Location: edit-pages.php'); + exit(); + break; +} // end switch +include('admin-footer.php'); +?> diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php new file mode 100644 index 0000000..56bab5a --- /dev/null +++ b/wp-admin/plugin-editor.php @@ -0,0 +1,127 @@ +'.__('You have do not have sufficient permissions to edit templates for this blog.').'

    '); + + $newcontent = stripslashes($_POST['newcontent']); + if (is_writeable($real_file)) { + $f = fopen($real_file, 'w+'); + fwrite($f, $newcontent); + fclose($f); + header("Location: plugin-editor.php?file=$file&a=te"); + } else { + header("Location: plugin-editor.php?file=$file"); + } + + exit(); + +break; + +default: + + require_once('admin-header.php'); + if ( !current_user_can('edit_plugins') ) + die('

    '.__('You have do not have sufficient permissions to edit plugins for this blog.').'

    '); + + update_recently_edited("wp-content/plugins/$file"); + + if (!is_file($real_file)) + $error = 1; + + if (!$error) { + $f = fopen($real_file, 'r'); + $content = fread($f, filesize($real_file)); + $content = htmlspecialchars($content); + } + + ?> + +

    + +
    + ' . sprintf(__('Editing %s'), $file) . ''; + } else { + echo '

    ' . sprintf(__('Browsing %s'), $file) . '

    '; + } + ?> +
    +

    + + +
      + +
    • ">
    • + +
    + +
    + +
    + +
    + + +
    + +

    +"; +?> +

    + +

    + +
    +

    ' . __('Oops, no such file exists! Double check the name and try again, merci.') . '

    '; + } + ?> +
     
    + + diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php new file mode 100644 index 0000000..e289e59 --- /dev/null +++ b/wp-admin/plugins.php @@ -0,0 +1,142 @@ + + + +

    activated.') ?>

    +
    + + +

    deactivated.') ?>

    +
    + + +
    +

    +

    +'; + _e("Couldn't open plugins directory or there are no plugins available."); // TODO: make more helpful + echo '

    '; +} else { +?> + + + + + + + + + + $plugin_data) { + $style = ('class="alternate"' == $style|| 'class="alternate active"' == $style) ? '' : 'alternate'; + + if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) { + $action = "".__('Deactivate').""; + $plugin_data['Title'] = "{$plugin_data['Title']}"; + $style .= $style == 'alternate' ? ' active' : 'active'; + } else { + $action = "".__('Activate').""; + } + $plugin_data['Description'] = wp_kses($plugin_data['Description'], array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()) ); ; + if ($style != '') $style = 'class="' . $style . '"'; + echo " + + + + + + "; + } +?> + +
    {$plugin_data['Title']}{$plugin_data['Version']}{$plugin_data['Description']} ".sprintf(__('By %s'), $plugin_data['Author']).".$action
    + + +

    wp-content/plugins directory and it will be automatically deactivated.'); ?>

    + +

    +

    WordPress plugin directory. To install a plugin you generally just need to upload the plugin file into your wp-content/plugins directory. Once a plugin is uploaded, you may activate it here.'); ?>

    + +
    + + diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php new file mode 100644 index 0000000..d0f9844 --- /dev/null +++ b/wp-admin/post-new.php @@ -0,0 +1,94 @@ + +
    +

    +You can also e-mail the admin to ask for a promotion.
    +When you’re promoted, just reload this page and you’ll be able to blog. :)'), get_settings('admin_email')); ?> +

    +
    + +

    View site »'), get_bloginfo('home') . '/'); ?>

    + +
    +

    + 15 ) $num_drafts = 15; + for ( $i = 0; $i < $num_drafts; $i++ ) { + $draft = $drafts[$i]; + if ( 0 != $i ) + echo ', '; + if ( empty($draft->post_title) ) + $draft->post_title = sprintf(__('Post # %s'), $draft->ID); + echo "$draft->post_title"; + } + + if ( 15 < count($drafts) ) { ?> + , » + +.

    +
    + + + +
    +

    +

    +

    + + + + + + +
    +
    +
    + + + + + + +

    +
    + + + diff --git a/wp-admin/post.php b/wp-admin/post.php new file mode 100644 index 0000000..aad14e9 --- /dev/null +++ b/wp-admin/post.php @@ -0,0 +1,161 @@ +post_type == 'page' ) { + header( "Location: " . str_replace( "post.php", "page.php", $_SERVER[ 'REQUEST_URI' ] ) ); + die(); + } + require_once('admin-header.php'); + if ( !current_user_can('edit_post', $post_ID) ) + die ( __('You are not allowed to edit this post.') ); + + $post = get_post_to_edit($post_ID); + + include('edit-form-advanced.php'); + + ?> +
    +

    + +
    + post_type == 'attachment' ) { + if ( ! wp_delete_attachment($post_id) ) + die( __('Error in deleting...') ); + } else { + if ( !wp_delete_post($post_id) ) + die( __('Error in deleting...') ); + } + + $sendback = $_SERVER['HTTP_REFERER']; + if (strstr($sendback, 'post.php')) $sendback = get_settings('siteurl') .'/wp-admin/post-new.php'; + elseif (strstr($sendback, 'attachments.php')) $sendback = get_settings('siteurl') .'/wp-admin/attachments.php'; + $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); + header ('Location: ' . $sendback); + exit(); + break; + +default: + header('Location: edit.php'); + exit(); + break; +} // end switch +include('admin-footer.php'); +?> diff --git a/wp-admin/profile-update.php b/wp-admin/profile-update.php new file mode 100644 index 0000000..4d6595b --- /dev/null +++ b/wp-admin/profile-update.php @@ -0,0 +1,34 @@ +get_error_messages() as $message ) + echo "$message
    "; + exit; +} + +if ( !isset( $_POST['rich_editing'] ) ) + $_POST['rich_editing'] = 'false'; +update_user_option( $current_user->id, 'rich_editing', $_POST['rich_editing'], true ); + +do_action('personal_options_update'); + +if ( 'profile' == $_POST['from'] ) + $to = 'profile.php?updated=true'; +else + $to = 'profile.php?updated=true'; + +wp_redirect( $to ); +exit; + +?> diff --git a/wp-admin/profile.php b/wp-admin/profile.php new file mode 100644 index 0000000..eb66e07 --- /dev/null +++ b/wp-admin/profile.php @@ -0,0 +1,148 @@ + + + +
    +

    +
    + + +
    +

    +
    + +

    + + +

    + +
    + +

    + +

    + +

    + +

    + +

    +
    + +
    + + +

    + +

    + +

    + +

    + +

    +

    +
    +
    +
    + +

    +

    +
    + + +
    + +

    +

    +

    +
    + + + + +
    + +

    + +

    + + + + + caps) > count($profileuser->roles)): + ?> + + + + + +
    caps as $cap => $value) { + if(!$wp_roles->is_role($cap)) { + if($output != '') $output .= ', '; + $output .= $value ? $cap : "Denied: {$cap}"; + } + } + echo $output; + ?>
    +

    + +

    +
    + +
    + + diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php new file mode 100644 index 0000000..d25c58b --- /dev/null +++ b/wp-admin/setup-config.php @@ -0,0 +1,189 @@ + + + + +WordPress › Setup Configuration File + + + + +

    WordPress

    +The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now.

    "); + +switch($step) { + case 0: +?> + +

    Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.

    +
      +
    1. Database name
    2. +
    3. Database username
    4. +
    5. Database password
    6. +
    7. Database host
    8. +
    9. Table prefix (if you want to run more than one WordPress in a single database)
    10. +
    +

    If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php.

    +

    In all likelihood, these items were supplied to you by your ISP. If you do not have this information, then you will need to contact them before you can continue. If you’re all ready, let’s go!

    + +

    +
    +

    Below you should enter your database connection details. If you're not sure about these, contact your host.

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Database NameThe name of the database you want to run WP in.
    User NameYour MySQL username
    Password...and MySQL password.
    Database Host99% chance you won't need to change this value.
    Table PrefixIf you want to run multiple WordPress installations in a single database, change this.
    +

    + +

    +
    + $line) { + switch (substr($line,0,16)) { + case "define('DB_NAME'": + fwrite($handle, str_replace("wordpress", $dbname, $line)); + break; + case "define('DB_USER'": + fwrite($handle, str_replace("'username'", "'$uname'", $line)); + break; + case "define('DB_PASSW": + fwrite($handle, str_replace("'password'", "'$passwrd'", $line)); + break; + case "define('DB_HOST'": + fwrite($handle, str_replace("localhost", $dbhost, $line)); + break; + case '$table_prefix =': + fwrite($handle, str_replace('wp_', $prefix, $line)); + break; + default: + fwrite($handle, $line); + } + } + fclose($handle); + chmod('../wp-config.php', 0666); +?> +

    All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to run the install!

    + + + + diff --git a/wp-admin/sidebar.php b/wp-admin/sidebar.php new file mode 100644 index 0000000..140bd36 --- /dev/null +++ b/wp-admin/sidebar.php @@ -0,0 +1,80 @@ + + + +WordPress › Posted + + + + +

    Posted !

    +

    Click here to post again.

    + + + + +WordPress › Sidebar + + + + + +

    WordPress

    +
    +
    + + +

    Title: + +

    +

    Categories: + + + +

    +

    +Post: + +

    +

    + + + + +

    +
    +
    + + + + diff --git a/wp-admin/templates.php b/wp-admin/templates.php new file mode 100644 index 0000000..c22d56a --- /dev/null +++ b/wp-admin/templates.php @@ -0,0 +1,171 @@ +'.__('You do not have sufficient permissions to edit templates for this blog.').'

    '); + + $newcontent = stripslashes($_POST['newcontent']); + if (is_writeable($real_file)) { + $f = @ fopen($real_file, 'w+'); + if ( $f ) { + fwrite($f, $newcontent); + fclose($f); + header("Location: templates.php?file=$file&a=te"); + } else { + header("Location: templates.php?file=$file&a=err"); + } + } else { + header("Location: templates.php?file=$file&a=err"); + } + + exit(); + +break; + +default: + + require_once('./admin-header.php'); + + if ( ! current_user_can('edit_files') ) + die('

    '.__('You have do not have sufficient permissions to edit templates for this blog.').'

    '); + + if ( strstr( $file, 'wp-config.php' ) ) + die('

    '.__('The config file cannot be edited or viewed through the web interface. Sorry!').'

    '); + + update_recently_edited($file); + + if (!is_file($real_file)) + $error = true; + + if (!$error) { + $f = @ fopen($real_file, 'r'); + if ( $f ) { + $content = fread($f, filesize($real_file)); + $content = htmlspecialchars($content); + } else { + $error = true; + } + } + + ?> + + +

    + +

    + + +
    +' . sprintf(__('Editing %s'), wp_specialchars($file) ) . ''; +} else { + echo '

    ' . sprintf(__('Browsing %s'), wp_specialchars($file) ) . '

    '; +} +?> +
    + +

    +'; +foreach ($recents as $recent) : + echo "
  • " . get_file_description(basename($recent)) . "
  • "; +endforeach; +echo ''; +endif; +?> +

    + +
      + +
    • + +
    +
    + +
    + +
    + + +
    + +

    +"; +?> +

    + +

    + +
    +

    ' . __('Oops, no such file exists! Double check the name and try again, merci.') . '

    '; + } + ?> +
     
    + +
    +

    + +

    writable by the server, e.g. CHMOD 666.') ?>

    +
    + + +
    + +

    +
    + diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php new file mode 100644 index 0000000..10fb8fc --- /dev/null +++ b/wp-admin/theme-editor.php @@ -0,0 +1,162 @@ +'.__('You have do not have sufficient permissions to edit templates for this blog.').'

    '); + + $newcontent = stripslashes($_POST['newcontent']); + $theme = urlencode($theme); + if (is_writeable($real_file)) { + $f = fopen($real_file, 'w+'); + fwrite($f, $newcontent); + fclose($f); + header("Location: theme-editor.php?file=$file&theme=$theme&a=te"); + } else { + header("Location: theme-editor.php?file=$file&theme=$theme"); + } + + exit(); + +break; + +default: + + require_once('admin-header.php'); + if ( !current_user_can('edit_themes') ) + die('

    '.__('You have do not have sufficient permissions to edit themes for this blog.').'

    '); + + update_recently_edited($file); + + if (!is_file($real_file)) + $error = 1; + + if (!$error && filesize($real_file) > 0) { + $f = fopen($real_file, 'r'); + $content = fread($f, filesize($real_file)); + $content = htmlspecialchars($content); + } + + ?> + +

    + +
    +
    + + + +
    +
    + +
    + ' . sprintf(__('Editing %s'), $file_show) . ''; + } else { + echo '

    ' . sprintf(__('Browsing %s'), $file_show) . '

    '; + } + ?> +
    +

    '%s' theme files"), $theme) ?>

    + + + + +
    + +
    + +
    + + + +
    + +

    +"; +?> +

    + +

    + +
    +

    ' . __('Oops, no such file exists! Double check the name and try again, merci.') . '

    '; + } + ?> +
     
    + + diff --git a/wp-admin/themes.php b/wp-admin/themes.php new file mode 100644 index 0000000..f57bd1b --- /dev/null +++ b/wp-admin/themes.php @@ -0,0 +1,142 @@ + + + +

    + +

    View site »'), get_bloginfo('home') . '/'); ?>

    + + +title ] ) == false ) { + $allowed_themes[ $ct->title ] = true; +} +reset( $themes ); +while( list( $key, $val ) = each( $themes ) ) { + if( isset( $allowed_themes[ $key ] ) == false ) { + unset( $themes[ $key ] ); + } +} +reset( $themes ); +?> + +
    +

    +
    +screenshot ) : ?> +<?php _e('Current theme preview'); ?> + +

    title, $ct->version, $ct->author) ; ?>

    +

    description; ?>

    +
    + +

    + + +name ) + continue; + $template = $themes[$theme_name]['Template']; + $stylesheet = $themes[$theme_name]['Stylesheet']; + $title = $themes[$theme_name]['Title']; + $version = $themes[$theme_name]['Version']; + $description = $themes[$theme_name]['Description']; + $author = $themes[$theme_name]['Author']; + $screenshot = $themes[$theme_name]['Screenshot']; + $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir']; + $activate_link = wp_nonce_url("themes.php?action=activate&template=$template&stylesheet=$stylesheet", 'switch-theme_' . $template); +?> +
    +

    + + + + + + + +

    +
    + + + + + + +

    +

    + + + + + + + + + + "; + } +?> +
    $title$description
    + +
    +
    + + diff --git a/wp-admin/update-links.php b/wp-admin/update-links.php new file mode 100644 index 0000000..46a7f5a --- /dev/null +++ b/wp-admin/update-links.php @@ -0,0 +1,44 @@ +get_col("SELECT link_url FROM $wpdb->links"); + +if ( !$link_uris ) + die('No links'); + +$link_uris = urlencode( join( $link_uris, "\n" ) ); + +$query_string = "uris=$link_uris"; + +$http_request = "POST /updated-batch/ HTTP/1.0\r\n"; +$http_request .= "Host: api.pingomatic.com\r\n"; +$http_request .= 'Content-Type: application/x-www-form-urlencoded; charset='.get_settings('blog_charset')."\r\n"; +$http_request .= 'Content-Length: ' . strlen($query_string) . "\r\n"; +$http_request .= 'User-Agent: WordPress/' . $wp_version . "\r\n"; +$http_request .= "\r\n"; +$http_request .= $query_string; + +$response = ''; +if( false !== ( $fs = fsockopen('api.pingomatic.com', 80, $errno, $errstr, 5) ) ) { + 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); + $body = trim( $response[1] ); + $body = str_replace(array("\r\n", "\r"), "\n", $body); + + $returns = explode("\n", $body); + + foreach ($returns as $return) : + $time = $wpdb->escape( substr($return, 0, 19) ); + $uri = $wpdb->escape( preg_replace('/(.*?) | (.*?)/', '$2', $return) ); + $wpdb->query("UPDATE $wpdb->links SET link_updated = '$time' WHERE link_url = '$uri'"); + endforeach; +} +?> diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php new file mode 100644 index 0000000..03c34c2 --- /dev/null +++ b/wp-admin/upgrade-functions.php @@ -0,0 +1,1076 @@ +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 + $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')"); + + // Default link category + $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, link_count, category_description) VALUES ('0', '".$wpdb->escape(__('Blogroll'))."', '".sanitize_title(__('Blogroll'))."', '7', '')"); + + // Now drop in some default links + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://inphotos.org/', 'Donncha', 0, 'http://inphotos.org/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (1, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 0, 'http://zengun.org/weblog/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (2, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 0, 'http://boren.nu/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (3, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 0, 'http://xml.photomatt.net/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (4, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 0, 'http://zed1.com/journalized/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (5, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 0, 'http://www.alexking.org/blog/wp-rss2.php', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (6, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 0, 'http://dougal.gunters.org/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->link2cat (`link_id`, `category_id`) VALUES (7, 2)" ); + + // First post + $now = date('Y-m-d H:i:s'); + $now_gmt = gmdate('Y-m-d H:i:s'); + $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')"); + + $wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 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.
    To delete a comment, just log in, and view the posts\' 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 . ' '; + $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 weblog. 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_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; + } + + 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 < 3845 ) + upgrade_210(); + + $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' + // 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, '', '') WHERE comment_content LIKE '%'"); + $wpdb->query("UPDATE $wpdb->comments SET comment_type='pingback', comment_content = REPLACE(comment_content, '', '') WHERE comment_content LIKE '%'"); + + // 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(); + + if ( 0 == $wpdb->get_var("SELECT SUM(category_count) FROM $wpdb->categories") ) { // Create counts + $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories"); + foreach ( $categories as $cat_id ) { + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_type='post' AND post_status='publish' AND category_id = '$cat_id'"); + $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'"); + } + } + add_option( "gmt_offset", 0 ); + + // 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']) ) + add_post_meta($object->ID, '_wp_attached_file', $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', $post->ID); + } + if ( $wp_current_db_version < 3570 ) { + // Create categories for link categories if a category with the same + // name doesn't exist. Create a map of link cat IDs to cat IDs. + $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories"); + foreach ( $link_cats as $link_cat) { + if ( $cat_id = category_exists($link_cat->cat_name) ) { + $link_cat_id_map[$link_cat->cat_id] = $cat_id; + $default_link_cat = $cat_id; + } else { + $link_cat_id_map[$link_cat->cat_id] = wp_create_category($link_cat->cat_name); + $default_link_cat = $link_cat_id_map[$link_cat->cat_id]; + } + } + + // Associate links to cats. + $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); + if ( !empty($links) ) foreach ( $links as $link ) { + $link_cat = $link_cat_id_map[$link->link_category]; + $cat = $wpdb->get_row("SELECT * FROM $wpdb->link2cat WHERE link_id = '$link->link_id' AND category_id = '$link_cat'"); + if (!$cat && 0 != $link->link_category) { + $wpdb->query("INSERT INTO $wpdb->link2cat (link_id, category_id) + VALUES ('$link->link_id', '$link_cat')"); + } + } + + // Set default to the last category we grabbed during the upgrade loop. + update_option('default_link_category', $default_link_cat); + + // Count links per category. + if ( 0 == $wpdb->get_var("SELECT SUM(link_count) FROM $wpdb->categories") ) { + $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories"); + foreach ( $categories as $cat_id ) { + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->link2cat, $wpdb->links WHERE $wpdb->links.link_id = $wpdb->link2cat.link_id AND category_id = '$cat_id'"); + $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); + } + } + } +} + +// 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
    "); + 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; + + $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 ([^ ]*)|", $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 "
    \n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."

    "; + + // 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)]}
    "; + 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.')'; + + if(!(($aindex = array_search($index_string, $indices)) === false)) { + unset($indices[$aindex]); + //echo "
    {$table}:
    Found index:".$index_string."
    \n"; + } + //else echo "
    {$table}:
    Did not find index:".$index_string."
    ".print_r($indices, true)."
    \n"; + } + } + + // For every remaining index specified for the table + foreach($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 "
    ".print_r($query, true)."
    \n"; + $wpdb->query($query); + } + } + + return $for_update; +} + +function make_db_current() { + global $wp_queries; + + $alterations = dbDelta($wp_queries); + echo "
      \n"; + foreach($alterations as $alteration) echo "
    1. $alteration
    2. \n"; + echo "
    \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 ( strstr( $index, 'WP_USE_THEMES' ) ) { + 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("/wp-layout.css", "", $line); + + // Update comments template inclusion. + $line = str_replace("", "", $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 = @ dir("$default_dir"); + if ($theme_dir) { + while(($theme_file = $theme_dir->read()) !== 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); + } + } + + // 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 (strstr($line, "Theme Name:")) $line = "Theme Name: $theme_name"; + elseif (strstr($line, "Theme URI:")) $line = "Theme URI: " . __get_option('siteurl'); + elseif (strstr($line, "Description:")) $line = "Description: Your theme"; + elseif (strstr($line, "Version:")) $line = "Version: 1"; + elseif (strstr($line, "Author:")) $line = "Author: You"; + fwrite($f, "{$line}\n"); + } + fclose($f); + } + + // Copy the images. + umask(0); + if (! mkdir("$site_dir/images", 0777)) { + return false; + } + + $images_dir = @ dir("$default_dir/images"); + if ($images_dir) { + while(($image = $images_dir->read()) !== 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); + } + } +} + +// 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'; + } +} + +?> diff --git a/wp-admin/upgrade-schema.php b/wp-admin/upgrade-schema.php new file mode 100644 index 0000000..702fe4c --- /dev/null +++ b/wp-admin/upgrade-schema.php @@ -0,0 +1,467 @@ +categories ( + cat_ID bigint(20) NOT NULL auto_increment, + cat_name varchar(55) NOT NULL default '', + category_nicename varchar(200) NOT NULL default '', + category_description longtext NOT NULL, + category_parent bigint(20) NOT NULL default '0', + category_count bigint(20) NOT NULL default '0', + link_count bigint(20) NOT NULL default '0', + posts_private tinyint(1) NOT NULL default '0', + links_private tinyint(1) NOT NULL default '0', + PRIMARY KEY (cat_ID), + KEY category_nicename (category_nicename) +) TYPE=MyISAM; +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) +) TYPE=MyISAM; +CREATE TABLE $wpdb->link2cat ( + rel_id bigint(20) NOT NULL auto_increment, + link_id bigint(20) NOT NULL default '0', + category_id bigint(20) NOT NULL default '0', + PRIMARY KEY (rel_id), + KEY link_id (link_id,category_id) +) TYPE=MyISAM; +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) +) TYPE=MyISAM; +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_can_override enum('Y','N') NOT NULL default 'Y', + option_type int(11) NOT NULL default '1', + option_value longtext NOT NULL, + option_width int(11) NOT NULL default '20', + option_height int(11) NOT NULL default '8', + option_description tinytext NOT NULL, + option_admin_level int(11) NOT NULL default '1', + autoload enum('yes','no') NOT NULL default 'yes', + PRIMARY KEY (option_id,blog_id,option_name), + KEY option_name (option_name) +) TYPE=MyISAM; +CREATE TABLE $wpdb->post2cat ( + rel_id bigint(20) NOT NULL auto_increment, + post_id bigint(20) NOT NULL default '0', + category_id bigint(20) NOT NULL default '0', + PRIMARY KEY (rel_id), + KEY post_id (post_id,category_id) +) TYPE=MyISAM; +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) +) TYPE=MyISAM; +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') 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) +) TYPE=MyISAM; +CREATE TABLE $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) +); +CREATE TABLE $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) +); +CREATE TABLE $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 wp_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 wp_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', + t timestamp NOT NULL, + 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 $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 $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 $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, __('WordPress web address')); + add_option('blogname', __('My Weblog'), __('Blog title')); + 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', ''); + add_option('links_recently_updated_append', ''); + 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, __('Posts by email go to this category')); + add_option('recently_edited'); + add_option('use_linksupdate', 0); + add_option('template', 'default'); + add_option('stylesheet', 'default'); + add_option('comment_whitelist', 0); + add_option('page_uris'); + add_option('blacklist_keys'); + add_option('comment_registration', 0); + add_option('open_proxy_check', 1); + 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('rich_editing', 'true'); + 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'); + + add_site_option( 'customizefeed1', '0' ); + add_site_option( 'customizefeed2', '0' ); + add_site_option( 'dashboardfeed1', 'http://wordpress.org/development/feed/' ); + add_site_option( 'dashboardfeed2', 'http://planet.wordpress.org/feed/' ); + add_site_option( 'dashboardfeed1name', 'WordPress Development Blog' ); + add_site_option( 'dashboardfeed2name', 'Other WordPress News' ); + + // 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'); + 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(); +} + +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('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('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'); + } +} + +?> diff --git a/wp-admin/upgrade.php b/wp-admin/upgrade.php new file mode 100644 index 0000000..66f3fec --- /dev/null +++ b/wp-admin/upgrade.php @@ -0,0 +1,106 @@ + + + + + WordPress › Upgrade + + + + +

    WordPress

    + +

    +

    +get_row( "SELECT blog_id FROM wp_blog_versions WHERE blog_id = '{$wpdb->blogid}'" ) ) { + $wpdb->query( "UPDATE wp_blog_versions SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); + } else { + $wpdb->query( "INSERT INTO wp_blog_versions ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); + } + + if ( empty( $_GET['backto'] ) ) + $backto = __get_option('home'); + else + $backto = wp_specialchars( $_GET['backto'] , 1 ); +?> +

    +

    Have fun!"), $backto); ?>

    + + + + + + diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php new file mode 100644 index 0000000..0aff941 --- /dev/null +++ b/wp-admin/user-edit.php @@ -0,0 +1,280 @@ +ID ) $errors = new WP_Error('head', __('You do not have permission to edit this user.')); + +switch ($action) { +case 'switchposts': + +check_admin_referer(); + +/* TODO: Switch all posts from one user to another user */ + +break; + +case 'update': + +check_admin_referer('update-user_' . $user_id); + +if ( !current_user_can('edit_user', $user_id) ) + $errors = new WP_Error('head', __('You do not have permission to edit this user.')); +else + if( isset( $errors ) == false ) $errors = edit_user($user_id); + +if( !is_wp_error( $errors ) ) { + if( is_site_admin() ) + update_usermeta( $user_id, 'invites_left', intval( $_POST[ 'invites_left' ] ) ); + $redirect = "user-edit.php?user_id=$user_id&updated=true"; + $redirect = add_query_arg('wp_http_referer', urlencode($wp_http_referer), $redirect); + header("Location: $redirect"); + exit; +} + +default: +include ('admin-header.php'); + +$profileuser = new WP_User($user_id); + +if ( !current_user_can('edit_user', $user_id) ) + if ( !is_wp_error( $errors ) ) + $errors = new WP_Error('head', __('You do not have permission to edit this user.')); +?> + + +
    +

    + +

    + +
    + + +
    +
      + get_error_messages() as $message ) + echo "
    • $message
    • "; + ?> +
    +
    + + +
    +

    + +
    + + + + +

    + + +

    + +
    + +

    + +

    + + +

    + +

    + +

    + +

    + +

    +
    + +
    + + +

    + +

    + +

    + +

    + +

    +

    +
    +
    +
    + +

    +

    +
    + + +
    + +

    +

    +

    +
    + + + + +
    + + caps) > count($profileuser->roles)): + ?> + + + + + +
    caps as $cap => $value) { + if(!$wp_roles->is_role($cap)) { + if($output != '') $output .= ', '; + $output .= $value ? $cap : "Denied: {$cap}"; + } + } + echo $output; + ?>
    +

    + + + +

    +
    +
    + 3 ) { + ?>
    +

    Invited Users

    + get_row( "SELECT ID FROM {$wpdb->users} WHERE user_email = '$val'" ); + if( $id ) { + $invited_user_id = $id->ID; + } else { + $invited_user_id = $wpdb->get_var( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = 'invite_hash' AND meta_value = '" . md5( $val ) . "'" ); + } + + if( $invited_user_id != 0 ) { + $invited_user_blog = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$invited_user_id' AND meta_key='source_domain'" ); + } else { + $invited_user_blog = ''; + } + $invited_user_login = $wpdb->get_var( "SELECT user_login FROM $wpdb->users WHERE ID = '$invited_user_id'" ); + if( $invited_user_blog != '' ) { + print ""; + } else { + print ""; + } + } + } + ?>
    $val$invited_user_loginhttp://$invited_user_blog
    $val$invited_user_loginInvite Not Used Yet
    diff --git a/wp-admin/users.js b/wp-admin/users.js new file mode 100644 index 0000000..5e40418 --- /dev/null +++ b/wp-admin/users.js @@ -0,0 +1,20 @@ +addLoadEvent(function() { + theListEls = document.getElementsByTagName('tbody'); + theUserLists = new Array(); + for ( var l = 0; l < theListEls.length; l++ ) { + theUserLists[theListEls[l].id] = new listMan(theListEls[l].id); + } + addUserInputs = document.getElementById('adduser').getElementsByTagName('input'); + for ( var i = 0; i < addUserInputs.length; i++ ) { + addUserInputs[i].onkeypress = function(e) { return killSubmit('addUserSubmit();', e); } + } + document.getElementById('addusersub').onclick = function(e) { return killSubmit('addUserSubmit();', e); } +} +); + +function addUserSubmit() { + var roleEl = document.getElementById('role'); + var role = roleEl.options[roleEl.selectedIndex].value; + if ( !theUserLists['role-' + role] ) return true; + return theUserLists['role-' + role].ajaxAdder('user', 'adduser'); +} diff --git a/wp-admin/users.php b/wp-admin/users.php new file mode 100644 index 0000000..2ed85bf --- /dev/null +++ b/wp-admin/users.php @@ -0,0 +1,597 @@ +'; +} elseif ( isset($_POST['wp_http_referer']) ) { + $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), urlencode(stripslashes($_POST['wp_http_referer']))); + $referer = ''; +} else { + $redirect = 'users.php'; +} + + +// WP_User_Search class +// by Mark Jaquith + + +class WP_User_Search { + var $results; + var $search_term; + var $page; + var $raw_page; + var $users_per_page = 50; + var $first_user; + var $last_user; + var $query_limit; + var $query_from_where; + var $total_users_for_query = 0; + var $too_many_total_users = false; + var $search_errors; + + function WP_User_Search ($search_term = '', $page = '') { // constructor + $this->search_term = $search_term; + $this->raw_page = ( '' == $page ) ? false : (int) $page; + $this->page = (int) ( '' == $page ) ? 1 : $page; + + $this->prepare_query(); + $this->query(); + $this->prepare_vars_for_template_usage(); + $this->do_paging(); + } + + function prepare_query() { + global $wpdb; + $this->first_user = ($this->page - 1) * $this->users_per_page; + $this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page; + if ( $this->search_term ) { + $searches = array(); + $search_sql = 'AND ('; + foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) + $searches[] = $col . " LIKE '%$this->search_term%'"; + $search_sql .= implode(' OR ', $searches); + $search_sql .= ')'; + } + $this->query_from_where = "FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities' $search_sql"; + + if ( !$_GET['update'] && !$this->search_term && !$this->raw_page && $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities'") > $this->users_per_page ) + $this->too_many_total_users = sprintf(__('Because this blog has more than %s users, they cannot all be shown on one page. Use the paging or search functionality in order to find the user you want to edit.'), $this->users_per_page); + } + + function query() { + global $wpdb; + $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_limit); + + if ( $this->results ) + $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit + else + $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); + } + + function prepare_vars_for_template_usage() { + $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone + } + + function do_paging() { + if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results + $prev_page = ( $this->page > 1) ? true : false; + $next_page = ( ($this->page * $this->users_per_page) < $this->total_users_for_query ) ? true : false; + $this->paging_text = ''; + if ( $prev_page ) + $this->paging_text .= '

    « Previous Page

    '; + if ( $next_page ) + $this->paging_text .= '

    Next Page »

    '; + if ( $prev_page || $next_page ) + $this->paging_text .= '
    '; + } + } + + function get_results() { + return $this->results; + } + + function page_links() { + echo $this->paging_text; + } + + function results_are_paged() { + if ( $this->paging_text ) + return true; + return false; + } + + function is_search() { + if ( $this->search_term ) + return true; + return false; + } +} + + +switch ($action) { + +case 'promote': + check_admin_referer('bulk-users'); + + if (empty($_POST['users'])) { + header('Location: ' . $redirect); + } + + if ( !current_user_can('edit_users') ) + die(__('You can’t edit users.')); + + $userids = $_POST['users']; + $update = 'promote'; + foreach($userids as $id) { + if ( ! current_user_can('edit_user', $id) ) + die(__('You can’t edit that user.')); + // The new role of the current user must also have edit_users caps + if($id == $current_user->id && !$wp_roles->role_objects[$_POST['new_role']]->has_cap('edit_users')) { + $update = 'err_admin_role'; + continue; + } + + $user = new WP_User($id); + $user->set_role($_POST['new_role']); + } + + header('Location: ' . add_query_arg('update', $update, $redirect)); + +break; + +case 'dodelete': + die( "This function is disabled." ); + check_admin_referer('delete-users'); + + if ( empty($_POST['users']) ) { + header('Location: ' . $redirect); + } + + if ( !current_user_can('delete_users') ) + die(__('You can’t delete users.')); + + $userids = $_POST['users']; + $update = 'del'; + $delete_count = 0; + + foreach ( (array) $userids as $id) { + if ( ! current_user_can('delete_user', $id) ) + die(__('You can’t delete that user.')); + + if($id == $current_user->id) { + $update = 'err_admin_del'; + continue; + } + switch($_POST['delete_option']) { + case 'delete': + wp_delete_user($id); + break; + case 'reassign': + wp_delete_user($id, $_POST['reassign_user']); + break; + } + ++$delete_count; + } + + $redirect = add_query_arg('delete_count', $delete_count, $redirect); + + header('Location: ' . add_query_arg('update', $update, $redirect)); + +break; + +case 'delete': + die( "This function is disabled." ); + check_admin_referer('bulk-users'); + + if ( empty($_POST['users']) ) + header('Location: ' . $redirect); + + if ( !current_user_can('delete_users') ) + $errors = new WP_Error('edit_users', __('You can’t delete users.')); + + $userids = $_POST['users']; + + include ('admin-header.php'); +?> +
    + + +
    +

    +

    +
      +id ) { + echo "
    • " . sprintf(__('ID #%1s: %2s The current user will not be deleted.'), $id, $user->user_login) . "
    • \n"; + } else { + echo "
    • " . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "
    • \n"; + $go_delete = true; + } + } + $all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities'"); + $user_dropdown = ''; + ?> +
    + +

    +
      +
    • +
    • + '.__('Attribute all posts and links to:')." $user_dropdown"; ?>
    • +
    + +

    + +

    + +
    +
    +id) { + $update = 'err_admin_remove'; + continue; + } + remove_user_from_blog($id); + } + + header('Location: users.php?update=' . $update); + +break; + +case 'removeuser': + + check_admin_referer('bulk-users'); + + if (empty($_POST['users'])) { + header('Location: users.php'); + } + + if ( !current_user_can('edit_users') ) + $error = new WP_Error('edit_users', __('You can’t remove users.')); + + $userids = $_POST['users']; + + include ('admin-header.php'); +?> +
    + +
    +

    +

    +
      +id) { + echo "
    • " . sprintf(__('ID #%1s: %2s The current user will not be removed.'), $id, $user->user_login) . "
    • \n"; + } else { + echo "
    • " . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "
    • \n"; + $go_remove = true; + } + } + ?> + + +

      + +

      + +
    +
    +get_results() as $userid ) { + $tmp_user = new WP_User($userid); + $roles = $tmp_user->roles; + $role = array_shift($roles); + $roleclasses[$role][$tmp_user->user_login] = $tmp_user; + } + + if ( isset($_GET['update']) ) : + switch($_GET['update']) { + case 'del': + case 'del_many': + ?> + +

    + +

    + +

    + +

    + +

    +

    + +

    +

    + +

    +

    + +

    + +

    + + + +
    +
      + get_error_messages() as $message ) + echo "
    • $message
    • "; + ?> +
    +
    + + +too_many_total_users ) : ?> +
    +

    too_many_total_users; ?>

    +
    + + +
    + + is_search() ) : ?> +

    search_term); ?>

    + +

    + + + + + search_errors ) ) : ?> +
    +
      + search_errors->get_error_messages() as $message ) + echo "
    • $message
    • "; + ?> +
    +
    + + + +get_results() ) : ?> + + is_search() ) : ?> +

    + + +

    first_user + 1, min($wp_user_search->first_user + $wp_user_search->users_per_page, $wp_user_search->total_users_for_query), $wp_user_search->total_users_for_query); ?>

    + + results_are_paged() ) : ?> +
    page_links(); ?>

    + + +
    + + + $roleclass) { + ksort($roleclass); +?> + + + + + + + + + + + + + + + + + + + + + +

    role_names[$role]; ?>

    + +results_are_paged() ) : ?> +
    page_links(); ?>
    + + +

    +
      +
    • +
    • + + +
    • +
    +

    + + +

    +
    + +
    + + 'user_login', 'first_name' => 'user_firstname', 'last_name' => 'user_lastname', 'email' => 'user_email', 'url' => 'user_uri', 'role' => 'user_role') as $formpost => $var ) { + $var = 'new_' . $var; + $$var = wp_specialchars(stripslashes($_POST[$formpost])); + } + unset($name); + } +?> + +
    +

    +
    + + +

    Type the e-mail address of another user to add them to your blog.

    + + + + + + +
    User E-Mail:
    +

    + + +

    +
    + + +
    +
      + get_error_messages() as $message ) + echo "$message
      "; + ?> +
    +
    + +
    +
    + + diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css new file mode 100644 index 0000000..eb7052d --- /dev/null +++ b/wp-admin/wp-admin.css @@ -0,0 +1,1009 @@ +* html #poststuff { + height: 100%; /* kill peekaboo bug in IE */ +} + +/* This is the Holly Hack \*/ +* html .wrap { height: 1% } +/* For Win IE's eyes only */ + +body { + border: none; +} +a { + border-bottom: 1px solid #69c; + color: #00019b; + text-decoration: none; +} + +a.delete:hover { + background: #c00; + color: #fff; +} + +#planetnews ul { + list-style: none; + margin: 0; + padding: 0; +} + +#planetnews li { + width: 17%; + margin: 1%; + float: left; +} + +#planetnews li a { + display: block; + padding: .5em; + background: #ddd; + height: 6em; + overflow: hidden; +} + +.widefat { + width: 100%; +} + +.widefat td, .widefat th { + padding: 5px 6px; +} + +.import-system { + font-size: 16px; +} + +thead, .thead { + background: #dfdfdf +} + +#import-upload-form { + width: 300px; + margin: auto; + text-align: center; +} + +a.edit, a.delete, a.edit:hover, a.delete:hover { + border-bottom: none; + display: block; + padding: 5px 0; + text-align: center; +} + +a.edit:hover { + background: #ccc; + color: #036; +} + +a:visited { + color: #006; +} + +a:hover { +/* border-bottom: 1px solid #3a75ae;*/ + color: #069; +} + +body { + background: #f9fcfe; + color: #000; + margin: 0; + padding: 0; +} + +body, td { + font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana; +} + +fieldset { + border: none; + padding: 3px; +} + +fieldset label.selectit { + display: block; + font-size: 11px; + padding: 0 2px; +} + +fieldset label.selectit:hover { + background: #e9e9e9; +} + +fieldset legend { + padding: .1em .3em; +} + +fieldset.options { + padding: 1em; +} + +fieldset.options legend { + font-size: 16px; +} + +form, label input { + margin: 0; + padding: 0; +} + +h2 { + border-bottom: .5em solid #f0f8ff; + color: #333; + font: normal 30px/5px serif; + margin: 5px 10px; +} + +h2 small.quickjump { + display: block; + text-align: right; +} + +h2 small.quickjump a { + text-decoration: none; + border-bottom: 0; + font-size: 15px; + background: #f0f8ff; + padding: 5px 10px; +} + +img, #footer a { + border: 0; +} + +input:focus, textarea:focus, label:focus { + background: #fff; + border: 1px solid #686868; +} + +label { + cursor: pointer; +} + +li, dd { + margin-bottom: 6px; +} + +p, li, dl, dd, dt { + line-height: 130%; +} + +textarea, input, select { + background: #f4f4f4; + border: 1px solid #b2b2b2; + color: #000; + font: 13px Verdana, Arial, Helvetica, sans-serif; + margin: 1px; + padding: 3px; +} + +#uploading { + border-style: none; + padding: 0px; + margin-bottom: 16px; + height: 15em; + width: 100%; +/* overflow-y: hidden;*/ +} + +form#upload th { + text-align: right; +} + +form#upload #post_content, form#upload #post_title { + width: 250px; +} + +form#upload #post_content { + height: 50px; +} + +.attpreview { + width: 1px; /* hug */ + text-align: center; +} + +.alignleft { + float: left +} + +.alignright { + float: right; +} + +.alternate { + background: #f1f1f1; +} + +.anchors { + margin: 10px 20px 10px 20px; +} + +.available-theme { + width: 30%; + margin: 0 1em; + float: left; + text-align: center; + height: 28em; + overflow: hidden; +} + +.available-theme a.screenshot { + width: 250px; + height: 200px; + display: block; + margin: auto; + background: #f1f1f1; + border: 1px solid #ccc; + margin-bottom: 10px; + overflow: hidden; +} + +.available-theme a.screenshot:hover { +/* border: 1px solid #666;*/ +} + +.available-theme img { + width: 100%; +} + +.checkbox { + background: #fff; + border: none; + margin: 0; + padding: 0; +} + +.code { + font-family: "Courier New", Courier, monospace; +} + +.commentlist li { + border-bottom: 1px solid #ccc; + padding: 1em 1em .2em; + margin: 0; +} + +.commentlist p { + padding: 0; + margin: 0 0 .8em; +} + +.clear { + clear: both; + height: 2px; +} + +.hidden { + display: none; +} + +.navigation { + display: block; + text-align: center; + margin-top: 10px; + margin-bottom: 30px; +} + +.post-categories { + display: inline; + margin: 0; + padding: 0; +} + +.post-categories li, #ed_toolbar { + display: inline; +} + +.quicktags, .search { + background: #ccc; + color: #000; + font: 12px Georgia, "Times New Roman", Times, serif; +} + +.submit input, .submit input:focus, .button { + background: url( images/fade-butt.png ); + border: 3px double #999; + border-left-color: #ccc; + border-top-color: #ccc; + color: #333; + padding: 0.25em; +} + +.submit input:active, .button:active { + background: #f4f4f4; + border: 3px double #ccc; + border-left-color: #999; + border-top-color: #999; +} + +.submit, .editform th, #postcustomsubmit { + text-align: right; +} + +.optiontable { + width: 100%; +} + +.optiontable td, .optiontable th { + padding: .5em; +} + +.optiontable th { + width: 33%; + text-align: right; +} + +.unapproved { + color: #888; +} + +.unapproved a:link { + color: #b9bcff; +} + +.unapproved a:visited { + color: #696dff; +} + +.unapproved a:hover { + color: #009ef0; +} + +.approve { + display: none; +} + +.unapproved .approve { + display: inline; +} + +.unapproved .unapprove { + display: none; +} + +.updated, .confirm { + background: #CFEBF7 url(images/notice.gif) no-repeat 1em ; + border: 1px solid #2580B2; + margin: 1em 5% 10px; + padding: 0 1em 0 3em; +} + +.error { + background: #FFEFF7; + border: 1px solid #c69; + margin: 1em 5% 10px; + padding: 0 1em 0 1em; +} + +.wrap { + background: #fff; + border: 1px solid #ccc; + clear: both; + margin: 15px 5%; + padding: .5em 1em; +} + +.wrap h2 { + margin: .8em 0 .5em; + clear: both; +} + +table .vers { + text-align: center; +} + +#adminmenu { + background: #6da6d1; + border-top: 3px solid #448abd; + margin: 0; + padding: .2em .2em .2em 2em; +} + +#adminmenu .current, #submenu .current { + font-weight: bold; +} + +#adminmenu a { + color: #000; + font-size: 14px; + font-weight: normal; + margin: 0; + padding: 3px 5px; + text-decoration: none; +} + +#adminmenu a:hover, .current { + background: #ddeaf4; + color: #333; +} + +#adminmenu li, #submenu li { + display: inline; + line-height: 200%; + list-style: none; + text-align: center; +} + +#submenu { + background: #0d324f; + border-bottom: none; + margin: 0; + padding: 3px 2em 0 3em; +} + +#submenu .current { + background: #f9fcfe; + border-top: 1px solid #045290; + border-right: 2px solid #045290; + color: #000; +} + +#submenu a { + border: none; + color: #fff; + font-size: 12px; + padding: .3em .4em .33em; +} + +#submenu a:hover { + background: #ddeaf4; + color: #393939; +} + +#submenu li { + line-height: 170%; +} + + +#categorydiv input, #poststatusdiv input, #commentstatusdiv input, #pingstatusdiv input { + border: none; +} + +#titlediv, #guiddiv { + margin: 0 8px 0 0; + padding: 0px; +} + +#postdiv { + margin: 0 8px 0 0; + padding: 0px; +} + +#postdivrich { + margin: 0px; + padding: 0px; +} + +#content { + margin: 0 0 0 0; + width: 100%; +} + +#titlediv input, #guiddiv input { + margin: 0px; + width: 100%; +} + +#quicktags { + margin-left: -1px; +} + +#currenttheme img { + float: left; + border: 1px solid #666; + margin-right: 1em; + margin-bottom: 1.5em; + width: 300px; +} + +#deletepost:hover, #deletecomment:hover { + background: #ce0000; + color: #fff; +} + +#deletebookmarks:hover { + background: #ce0000; + color: #fff; +} + +#quicktags #ed_strong { + font-weight: bold; +} + +#quicktags #ed_link { + color: blue; + text-decoration: underline; +} + +#quicktags #ed_del { + text-decoration: line-through; +} + +#quicktags #ed_em { + font-style: italic; +} + +#quicktags #ed_code { + font-family: "Courier New", Courier, mono; +} + +#title { + font-size: 1.5em; +} + +#postexcerpt div, #attachmentlinks div { + margin-right: 8px; +} + +#attachmentlinks textarea { + width: 100%; + height: 2.5em; + margin-bottom: 6px; +} + +* html #postexcerpt .dbx-toggle-open, * html #postexcerpt .dbx-toggle-open { + padding-right: 8px; +} + +#excerpt, .attachmentlinks { + margin: 0px; + height: 4em; + width: 100%; +} + +#footer { + clear: both; + text-align: center; +} + +#login { + background: #fff; + border: 1px solid #a2a2a2; + margin: 5em auto; + padding: 1.5em; + width: 25em; +} + +#login #login_error { + background: #c00; + border: 1px solid #a40000; + color: #fff; + font-size: 16px; + font-weight: bold; + padding: .5em; + text-align: center; +} + +#login h1 { + background: url(images/wordpress-logo.png) no-repeat top left; + margin-top: 0; +} + +#login h1 a { + display: block; + text-indent: -1000px; + height: 66px; + border-bottom: none; +} + +#login input { + padding: 3px; +} + +#login ul { + list-style: none; + margin: 0; + padding: 0; +} + +#login ul li { + display: inline; + margin-left: 1.4em; + text-align: center; +} + +#login #log, #pwd { + font-size: 1.7em; + width: 80%; +} + +#login #submit { + font-size: 1.7em; +} + +#postcustom .updatemeta, #postcustom .deletemeta { + margin: auto; +} + +#postcustom table { + border: 1px solid #ccc; + margin: 0px; + width: 100%; +} + +#postcustom table input, #postcustom table textarea { + width: 95%; +} + +#poststuff { + margin-right: 16em; +} + +#save { + width: 15em; +} + +#template div { + margin-right: 190px; +} + +* html #template div { + margin-right: 0px; +} + +#template, #template div, #editcat, #addcat { + zoom: 1; +} + +#template textarea { + font: small 'Courier New', Courier, monospace; + width: 97%; +} + +#templateside { + float: right; + width: 170px; +} + +#templateside h3, #postcustom p.submit { + margin: 0; +} + +#templateside ol, #templateside ul { + list-style: none; + margin: .5em; + padding: 0; +} + +#user_info { + position: absolute; + right: 1em; + top: 0; + color: #fff; + font-size: .9em; +} + +#user_info a { + color: #fff; +} + +#wphead { + background: #14568a; + padding: .8em 19em .8em 2em; + color: #c3def1; +} + +#wphead a { + color: #fff; +} + +#wphead h1 { + font-size: 2.5em; + font-weight: normal; + letter-spacing: -.05em; + margin: 0; + font-family: Georgia, "Times New Roman", Times, serif +} + +#wphead h1 span { + font-size: .4em; + letter-spacing: 0; +} + +#zeitgeist { + background: #eee; + border: 1px solid #69c; + float: right; + font-size: 90%; + margin-bottom: .5em; + margin-left: 1em; + margin-top: .5em; + padding: 1em; + width: 40%; +} + +#zeitgeist h2, fieldset legend a { + border-bottom: none; +} + +#zeitgeist h2 { + margin-top: .4em; +} + +#zeitgeist h3 { + border-bottom: 1px solid #ccc; + font-size: 16px; + margin: 1em 0 0; +} + +#zeitgeist h3 cite { + font-size: 12px; + font-style: normal; +} + +#zeitgeist li, #zeitgeist p { + margin: .2em 0; +} + +#zeitgeist ul { + margin: 0 0 .3em .6em; + padding: 0 0 0 .6em; +} + +.active td { + background: #BEB; +} +.active .name { + background: #9C9; +} +.alternate.active td { + background: #ADA; +} +.alternate.active .name { + background: #8B8; +} + +#namediv, #emaildiv, #uridiv { + float: left; +} + +#ajax-response { + padding: .5em; +} + +/* A handy div class for hiding controls. + Some browsers will disable them when you + set display:none; */ +.zerosize { + height: 0px; + width: 0px; + margin: 0px; + border: 0px; + padding: 0px; + overflow: hidden; + position: absolute; +} + +/* Box stuff */ +.dbx-clone { + position:absolute; + visibility:hidden; +} +.dbx-clone, .dbx-clone .dbx-handle-cursor { + cursor:move !important; +} +.dbx-dummy { + display:block; + width:0; + height:0; + overflow:hidden; +} +.dbx-group, .dbx-box, .dbx-handle { + position:relative; + display:block; +} + +#grabit { + width: 188px; +} + +* html #themeselect { + padding: 0px 3px; + height: 22px; +} + +/**************************************************************** + avoid padding, margins or borders on dbx-box, + to reduce visual discrepancies between it and the clone. + overall, dbx-box is best left as visually unstyled as possible +*****************************************************************/ +.dbx-box { + margin:0; + padding:0; + border:none; +} + +/* Can change this */ +#moremeta fieldset, #advancedstuff fieldset { + margin-bottom: 1em; +} +#moremeta fieldset div { + margin: 2px 0 0 0px; + padding: 7px; +} +#moremeta { + line-height: 130%; + margin-right: 15px; + position: absolute; + right: 5%; + width: 14.5em; +} +#moremeta select { + width: 96%; +} + +#slugdiv input, #passworddiv input, #authordiv select, #thumbdiv input, #parentdiv input { + margin-top: .5em; + width: 90%; +} + +#moremeta h3, #advancedstuff h3 { + padding: 3px; + font-weight: normal; + font-size: 13px; +} + +#advancedstuff div { + margin-top: .5em; +} + +#categorydiv ul { + list-style: none; + padding: 0; + margin-left:10px; +} +#categorychecklist { + height: 12em; + overflow: auto; + margin-top: 8px; +} +#categorychecklist li { + margin: 0; + padding: 0; +} +#ajaxcat input { + border: 1px solid #ccc; +} + +#your-profile fieldset { + border: 1px solid #ccc; + float: left; + width: 40%; + padding: .5em 2em; + margin: 1em; +} + +#your-profile fieldset input { + width: 100%; + font-size: 20px; + padding: 2px; +} + +#your-profile fieldset textarea { + width: 100%; + padding: 2px; +} + +#your-profile legend { + font-family: Georgia, "Times New Roman", Times, serif; + font-size: 22px; +} + +/* default box styles */ + +/* toggle state of inner content area */ +.dbx-box-open .dbx-content { + display: block; +} +.dbx-box-closed .dbx-content { + display: none; +} + +#moremeta .dbx-content { + background: url(images/box-butt.gif) no-repeat bottom right; + padding-bottom: 15px; + padding-right: 2px; +} + +/* handles */ + +.dbx-handle { + background: #2685af; + padding: 6px 1em 2px; + font-size: 12px; + margin: 0; + color: #E3EFF5; +} + +#moremeta .dbx-handle { + padding: 6px 1em 2px; + font-size: 12px; + background: #2685af url(images/box-head.gif) no-repeat right; +} + +#moremeta .dbx-box { + background: url(images/box-bg.gif) repeat-y right; +} + +/* handle cursors */ +.dbx-handle-cursor { + cursor: move; +} + +/* toggle images */ +a.dbx-toggle, a.dbx-toggle:visited { + display:block; + overflow: hidden; + background-image: url( images/toggle.gif ); + position: absolute; + top: 0px; + right: 0px; + background-repeat: no-repeat; + border: 0px; + margin: 0px; + padding: 0px; +} + +#moremeta a.dbx-toggle, #moremeta a.dbx-toggle-open:visited { + height: 25px; + width: 27px; + background-position: 0 0px; +} + +#moremeta a.dbx-toggle-open, #moremeta a.dbx-toggle-open:visited { + height: 25px; + width: 27px; + background-position: 0 -25px; +} + +#advancedstuff a.dbx-toggle, #advancedstuff a.dbx-toggle-open:visited { + height: 22px; + width: 22px; + background-position: 0 -3px; +} + +#advancedstuff a.dbx-toggle-open, #advancedstuff a.dbx-toggle-open:visited { + height: 22px; + width: 22px; + background-position: 0 -28px; +} + +#categorychecklist { + margin-right: 6px; +} + +/* additional clone styles */ +.dbx-clone { + opacity: 0.8; + -moz-opacity: 0.8; + -khtml-opacity: 0.8; + filter: alpha(opacity=80); +} + +#newcat { width: 120px; margin-right: 5px; } +input#catadd { background: #a4a4a4; + border-bottom: 1px solid #898989; + border-left: 1px solid #bcbcbc; + border-right: 1px solid #898989; + border-top: 1px solid #bcbcbc; + color: #fff; + font-size: 10px; + padding: 0; + margin: 0; + font-weight: bold; + height: 20px; + margin-bottom: 2px; + text-align: center; + width: 37px; } +#howto { + font-size: 11px; + margin: 0 5px; + display: block; +} +#jaxcat { + margin: 0; + padding: 0; +} +#ajax-response.alignleft { + margin-left: 2em; +} diff --git a/wp-admin/wpmu-admin.php b/wp-admin/wpmu-admin.php new file mode 100644 index 0000000..d943761 --- /dev/null +++ b/wp-admin/wpmu-admin.php @@ -0,0 +1,52 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    +
    +Site Stats + There are currently ".$stats[ 'blogs' ]." blogs running on this server and ".$stats[ 'users' ]." users.



    + "; + + print ""; + #$blogs = get_blog_list(); + #print "
    blogs:
    "; + #print_r( $blogs ); + + $most_active = get_most_active_blogs( 10, false ); + if( is_array( $most_active ) ) { + print ""; + print ""; + while( list( $key, $details ) = each( $most_active ) ) { + $class = ('alternate' == $class) ? '' : 'alternate'; + $url = "http://" . $details[ 'domain' ] . $details[ 'path' ]; + print ""; + } + } + print "
    Most Active Blogs
    IDAddressPosts
    " . $details[ 'blog_id' ] . "$url" . $details[ 'postcount' ] . "
    "; + + do_action( "wpmuadmindefaultpage", "" ); + */ + break; +} + +?> +
    + diff --git a/wp-admin/wpmu-blogs.php b/wp-admin/wpmu-blogs.php new file mode 100644 index 0000000..599e4a0 --- /dev/null +++ b/wp-admin/wpmu-blogs.php @@ -0,0 +1,527 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    '; +switch( $_GET[ 'action' ] ) { + case "editblog": + $options_table_name = $wpmuBaseTablePrefix . $_GET[ 'id' ] ."_options"; + $query = "SELECT * + FROM ".$options_table_name." + WHERE option_name NOT LIKE 'rss%' + AND option_name NOT LIKE '%user_roles'"; + $options = $wpdb->get_results( $query, ARRAY_A ); + $query = "SELECT * + FROM ".$wpdb->blogs." + WHERE blog_id = '".$_GET[ 'id' ]."'"; + $details = $wpdb->get_row( $query, ARRAY_A ); + + print "

    Edit Blog

    "; + print "{$details[ 'domain' ]}"; + ?> +
    + + + + + + '; + } + } + if( $out != '' ) { + print "

    Blog Themes

    "; + print '
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '; + } else { + ?> + + + + + +
    URLhttp://
    Path
    Registered
    Last Updated
    Public> Yes   + > No    +
    Archived> Yes   + > No    +
    Mature> Yes   + > No    +
    Spam> Yes   + > No    +
    Deleted> Yes   + > No    +
    +
    +
    +
    ' . ucwords( str_replace( "_", " ", $val[ 'option_name' ] ) ) . ''; + print '
    +

    + +

    +
    +
    + get_var( $query ); + if( $blog_allowed_themes != false ) + $blog_allowed_themes = unserialize( $blog_allowed_themes ); + $allowed_themes = get_site_option( "allowed_themes" ); + if( $allowed_themes == false ) { + $allowed_themes = array_keys( $themes ); + } + $out = ''; + while( list( $key, $val ) = each( $themes ) ) { + if( isset( $allowed_themes[ $key ] ) == false ) { + if( isset( $blog_allowed_themes[ $key ] ) == true ) { + $checked = 'checked '; + } else { + $checked = ''; + } + + $out .= ' +
    '.$key.'
    '; + print ''; + print $out; + print "
    ThemeEnable
    "; + } + $blogusers = get_users_of_blog( $_GET[ 'id' ] ); + print "

    Blog Users

    "; + if( is_array( $blogusers ) ) { + print ""; + print ""; + reset( $blogusers ); + while( list( $key, $val ) = each( $blogusers ) ) + { + $t = @unserialize( $val->meta_value ); + if( is_array( $t ) ) { + reset( $t ); + $existing_role = key( $t ); + } + print ""; + if( $val->user_id != $current_user->data->ID ) { + ?> + "; + } else { + print ""; + } + print ""; + } + print "
    Current Users
    UserRoleRemove
    " . $val->user_login . " N/AN/AEdit
    "; + } + print "

    Add a new user

    "; + ?> + +

    As you type WordPress will offer you a choice of usernames.
    Click them to select and hit Update Options to add the user.

    + + + + + + + +
    User Login:
    +
    +
    Misc Blog Actions +

    +
    +

    + +

    + + + + + blogs." + WHERE site_id = '".$wpdb->siteid."' "; + if( $_GET[ 's' ] != '' ) { + $query = "SELECT blog_id, {$wpdb->blogs}.domain, registered, last_updated + FROM $wpdb->blogs, $wpdb->site + WHERE site_id = '$wpdb->siteid' + AND {$wpdb->blogs}.site_id = {$wpdb->site}.id + AND {$wpdb->blogs}.domain like '%". $_GET[ 's' ]."%'"; + } elseif( $_GET[ 'blog_id' ] != '' ) { + $query = "SELECT * + FROM $wpdb->blogs + WHERE site_id = '$wpdb->siteid' + AND blog_id = '".intval($_GET[ 'blog_id' ])."'"; + } elseif( $_GET[ 'ip_address' ] != '' ) { + $query = "SELECT * + FROM $wpdb->blogs, wp_registration_log + WHERE site_id = '$wpdb->siteid' + AND {$wpdb->blogs}.blog_id = wp_registration_log.blog_id + AND wp_registration_log.IP LIKE ('%".$_GET[ 'ip_address' ]."%')"; + } + if( isset( $_GET[ 'sortby' ] ) == false ) { + $_GET[ 'sortby' ] = 'ID'; + } + if( $_GET[ 'sortby' ] == 'Registered' ) { + $query .= ' ORDER BY registered '; + } elseif( $_GET[ 'sortby' ] == 'ID' ) { + $query .= ' ORDER BY ' . $wpdb->blogs . '.blog_id '; + } elseif( $_GET[ 'sortby' ] == 'Last Updated' ) { + $query .= ' ORDER BY last_updated '; + } elseif( $_GET[ 'sortby' ] == 'Blog Name' ) { + $query .= ' ORDER BY domain '; + } + if( $_GET[ 'order' ] == 'DESC' ) { + $query .= "DESC"; + } else { + $query .= "ASC"; + } + + if ( $_GET[ 'ip_address' ] == '' ) + $query .= " LIMIT " . intval( $start ) . ", " . intval( $num ); + $blog_list = $wpdb->get_results( $query, ARRAY_A ); + if( count( $blog_list ) < $num ) { + $next = false; + } else { + $next = true; + } +?> + + +

    Blogs

    + +
    +
    + + + Name: 
    + Blog ID: 
    + IP Address:
    + +
    + Search Users: +
    +
    + + Previous Blogs'; + } else { + echo 'Previous Blogs'; + } + if ( $next ) { + echo ' || Next Blogs'; + } else { + echo ' || Next Blogs'; + } + ?> +
    +
    +
    + +
    + + 'display name' +$posts_columns = array( + 'id' => __('ID'), + 'blogname' => __('Blog Name'), + 'last_updated' => __('Last Updated'), + 'registered' => __('Registered'), + 'users' => __('Users'), + 'plugins' => __('Actions') +); +$posts_columns = apply_filters('manage_posts_columns', $posts_columns); + +// you can not edit these at the moment +$posts_columns['control_view'] = ''; +$posts_columns['control_edit'] = ''; +$posts_columns['control_backend'] = ''; +$posts_columns['control_deactivate'] = ''; +$posts_columns['control_spam'] = ''; +$posts_columns['control_delete'] = ''; + +?> + +
    + + + + + + + + + + "#fee", "spam" => "#faa", "deleted" => "#f55" ); + foreach ($blog_list as $blog) { + $class = ('alternate' == $class) ? '' : 'alternate'; + reset( $status_list ); + $bgcolour = ""; + while( list( $status, $col ) = each( $status_list ) ) { + if( get_blog_status( $blog[ 'blog_id' ], $status ) == 1 ) { + $bgcolour = "style='background: $col'"; + } + } + print ""; + +foreach($posts_columns as $column_name=>$column_display_name) { + + switch($column_name) { + + case 'id': + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    start=">
    ' name='allblogs[]' value=''> + user_id . '">' . $val->user_login . ' ('.$val->user_email.')
    '; } ?>
    " . __('Edit') . ""; ?>path . "wp-admin/' class='edit'>" . __('Backend') . ""; ?>" . __('Not Spam') . ""; ?>" . __('Spam') . ""; ?>" . __('Activate') . ""; ?>" . __('Deactivate') . ""; ?>" . __('Delete') . ""; ?>
    + +

    Selected Blogs:

      +
    • +
    • +
    +'> +

    +
    + + + + diff --git a/wp-admin/wpmu-edit.php b/wp-admin/wpmu-edit.php new file mode 100644 index 0000000..ee9913c --- /dev/null +++ b/wp-admin/wpmu-edit.php @@ -0,0 +1,263 @@ +You do not have permission to access this page.

    ') ); + } + + update_site_option( "WPLANG", $_POST[ 'WPLANG' ] ); + update_site_option( "illegal_names", split( ' ', $_POST[ 'illegal_names' ] ) ); + if( $_POST[ 'limited_email_domains' ] != '' ) { + update_site_option( "limited_email_domains", split( ' ', $_POST[ 'limited_email_domains' ] ) ); + } else { + update_site_option( "limited_email_domains", '' ); + } + update_site_option( "menu_items", $_POST[ 'menu_items' ] ); + update_site_option( "blog_upload_space", $_POST[ 'blog_upload_space' ] ); + update_site_option( "upload_filetypes", $_POST[ 'upload_filetypes' ] ); + update_site_option( "site_name", $_POST[ 'site_name' ] ); + update_site_option( "first_post", $_POST[ 'first_post' ] ); + update_site_option( "welcome_email", $_POST[ 'welcome_email' ] ); + update_site_option( "fileupload_maxk", $_POST[ 'fileupload_maxk' ] ); + $site_admins = explode( ' ', $_POST['site_admins'] ); + if ( is_array( $site_admins ) ) + update_site_option( 'site_admins' , $site_admins ); + header( "Location: wpmu-options.php?updated=true" ); + exit; + break; + case "searchcategories": + $search = wp_specialchars( $_POST[ 'search' ] ); + $query = "SELECT cat_name FROM " . $wpdb->sitecategories . " WHERE cat_name LIKE '%" . $search . "%' limit 0,10"; + $cats = $wpdb->get_results( $query ); + if( is_array( $cats ) ) { + print "
      "; + while( list( $key, $val ) = each( $cats ) ) + { + print "
    • {$val->cat_name}
    • "; + } + print "
    "; + } + exit; + break; + case "searchusers": + $search = wp_specialchars( $_POST[ 'search' ] ); + $query = "SELECT " . $wpdb->users . ".ID, " . $wpdb->users . ".user_login FROM " . $wpdb->users . " WHERE user_login LIKE '" . $search . "%' limit 0,10"; + $users = $wpdb->get_results( $query ); + if( is_array( $users ) ) { + print "
      "; + while( list( $key, $val ) = each( $users ) ) + { + print "
    • {$val->user_login}
    • "; + } + print "
    "; + } else { + print "No Users Found"; + } + exit; + break; + case "updatefeeds": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + + update_site_option( "customizefeed1", $_POST[ 'customizefeed1' ] ); + update_site_option( "customizefeed2", $_POST[ 'customizefeed2' ] ); + update_site_option( "dashboardfeed1", $_POST[ 'dashboardfeed1' ] ); + update_site_option( "dashboardfeed2", $_POST[ 'dashboardfeed2' ] ); + update_site_option( "dashboardfeed1name", $_POST[ 'dashboardfeed1name' ] ); + update_site_option( "dashboardfeed2name", $_POST[ 'dashboardfeed2name' ] ); + header( "Location: wpmu-feeds.php?updated=true" ); + break; + case "updateblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + $options_table_name = $wpmuBaseTablePrefix . $id ."_options"; + + // themes + if( is_array( $_POST[ 'theme' ] ) ) { + $allowed_themes = $_POST[ 'theme' ]; + $_POST[ 'option' ][ 'allowed_themes' ] = $_POST[ 'theme' ]; + } else { + $_POST[ 'option' ][ 'allowed_themes' ] = ''; + } + if( is_array( $_POST[ 'option' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'option' ] ) ) { + update_blog_option( $id, $key, $val ); + } + } + // update blogs table + $query = "UPDATE $wpdb->blogs + SET domain = '".$_POST[ 'blog' ][ 'domain' ]."', + path = '".$_POST[ 'blog' ][ 'path' ]."', + registered = '".$_POST[ 'blog' ][ 'registered' ]."', + public = '".$_POST[ 'blog' ][ 'public' ]."', + archived = '".$_POST[ 'blog' ][ 'archived' ]."', + mature = '".$_POST[ 'blog' ][ 'mature' ]."', + deleted = '".$_POST[ 'blog' ][ 'deleted' ]."', + spam = '".$_POST[ 'blog' ][ 'spam' ]."' + WHERE blog_id = '$id'"; + $result = $wpdb->query( $query ); + update_blog_status( $id, 'spam', $_POST[ 'blog' ][ 'spam' ] ); + // user roles + if( is_array( $_POST[ 'role' ] ) == true ) { + $newroles = $_POST[ 'role' ]; + reset( $newroles ); + while( list( $userid, $role ) = each( $newroles ) ) { + $role_len = strlen( $role ); + $existing_role = $wpdb->get_var( "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$userid' AND meta_key = '" . $wpmuBaseTablePrefix . $id . "_capabilities'" ); + if( false == $existing_role ) { + $wpdb->query( "INSERT INTO " . $wpdb->usermeta . "( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '$userid', '" . $wpmuBaseTablePrefix . $id . "_capabilities', 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}')" ); + } elseif( $existing_role != "a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}" ) { + $wpdb->query( "UPDATE $wpdb->usermeta SET meta_value = 'a:1:{s:" . strlen( $role ) . ":\"" . $role . "\";b:1;}' WHERE user_id = '$userid' AND meta_key = '" . $wpmuBaseTablePrefix . $id . "_capabilities'" ); + } + + } + } + + // remove user + if( is_array( $_POST[ 'blogusers' ] ) ) { + reset( $_POST[ 'blogusers' ] ); + while( list( $key, $val ) = each( $_POST[ 'blogusers' ] ) ) { + $wpdb->query( "DELETE FROM " . $wpdb->usermeta . " WHERE meta_key = '" . $wpmuBaseTablePrefix . $id . "_capabilities' AND user_id = '" . $key . "'" ); + } + } + + + // add user? + if( $_POST[ 'newuser' ] != '' ) { + $newuser = $_POST[ 'newuser' ]; + $userid = $wpdb->get_var( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = '$newuser'" ); + if( $userid ) { + $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='wp_" . $id . "_capabilities'" ); + if( $user == false ) + $wpdb->query( "INSERT INTO " . $wpdb->usermeta . "( `umeta_id` , `user_id` , `meta_key` , `meta_value` ) VALUES ( NULL, '$userid', '" . $wpmuBaseTablePrefix . $id . "_capabilities', 'a:1:{s:" . strlen( $_POST[ 'new_role' ] ) . ":\"" . $_POST[ 'new_role' ] . "\";b:1;}')" ); + } + } + header( "Location: wpmu-blogs.php?action=editblog&id=".$id."&updated=true" ); + break; + case "deleteblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + $id = $_GET[ 'id' ]; + if( $id != '0' && $id != '1' ) + wpmu_delete_blog( $id, true ); + wpmu_admin_do_redirect( "wpmu-blogs.php" ); + break; + case "allblogs": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + if( is_array( $_POST[ 'allblogs' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'allblogs' ] ) ) { + if( $val != '0' && $val != '1' ) { + if( $_POST[ 'blogfunction' ] == 'delete' ) { + wpmu_delete_blog( $val, true ); + } elseif( $_POST[ 'blogfunction' ] == 'spam' ) { + update_blog_status( $val, "spam", '1' ); + } + } + } + } + + if( isset( $_POST[ 'redirect' ] ) ) { + wpmu_admin_do_redirect( $_POST[ 'redirect' ] ); + } else { + header( "Location: wpmu-blogs.php?updated=true" ); + } + break; + case "activateblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + update_archived( $_GET[ 'id' ], '0' ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "deactivateblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + do_action( "deactivate_blog", $_GET[ 'id' ] ); + update_archived( $_GET[ 'id' ], '1' ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "unspamblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + update_blog_status( $_GET[ 'id' ], "spam", '0' ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "spamblog": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + do_action( "make_spam_blog", $_GET[ 'id' ] ); + update_blog_status( $_GET[ 'id' ], "spam", '1' ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "mature": + update_blog_status( $_GET[ 'id' ], 'mature', '1' ); + do_action( 'mature_blog', $_GET[ 'id' ] ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "unmature": + update_blog_status( $_GET[ 'id' ], 'mature', '0' ); + do_action( 'unmature_blog', $_GET[ 'id' ] ); + header( "Location: wpmu-blogs.php?updated=true" ); + break; + case "updateuser": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + unset( $_POST[ 'option' ][ 'ID' ] ); + if( is_array( $_POST[ 'option' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'option' ] ) ) { + $query = "UPDATE ".$wpdb->users." SET ".$key." = '".$val."' WHERE ID = '".$id."'"; + $wpdb->query( $query ); + } + } + if( is_array( $_POST[ 'meta' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'meta' ] ) ) { + $query = "UPDATE ".$wpdb->usermeta." SET meta_key = '".$_POST[ 'metaname' ][ $key ]."', meta_value = '".$val."' WHERE umeta_id = '".$key."'"; + $wpdb->query( $query ); + } + } + if( is_array( $_POST[ 'metadelete' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'metadelete' ] ) ) { + $query = "DELETE FROM ".$wpdb->usermeta." WHERE umeta_id = '".$key."'"; + $wpdb->query( $query ); + } + } + header( "Location: wpmu-users.php?action=edit&id=".$id."&updated=true" ); + break; + case "updatethemes": + if( is_site_admin() == false ) { + die( __('

    You do not have permission to access this page.

    ') ); + } + if( is_array( $_POST[ 'theme' ] ) ) { + $themes = array_flip( array_keys( get_themes() ) ); + reset( $themes ); + while( list( $key, $val ) = each( $themes ) ) + { + if( $_POST[ 'theme' ][ addslashes( $key ) ] == 'enabled' ) + $allowed_themes[ $key ] = true; + } + update_site_option( 'allowed_themes', $allowed_themes ); + } + header( "Location: wpmu-themes.php?updated=true" ); + break; + default: + header( "Location: wpmu-admin.php" ); + break; +} +?> diff --git a/wp-admin/wpmu-feedback.php b/wp-admin/wpmu-feedback.php new file mode 100644 index 0000000..ff8c2bb --- /dev/null +++ b/wp-admin/wpmu-feedback.php @@ -0,0 +1,10 @@ + diff --git a/wp-admin/wpmu-feeds.php b/wp-admin/wpmu-feeds.php new file mode 100644 index 0000000..98fd213 --- /dev/null +++ b/wp-admin/wpmu-feeds.php @@ -0,0 +1,43 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    '; +switch( $_GET[ 'action' ] ) { + default: + break; +} + +$customizefeed1 = get_site_option( 'customizefeed1' ); +$customizefeed2 = get_site_option( 'customizefeed2' ); +$dashboardfeed1 = get_site_option( 'dashboardfeed1' ); +$dashboardfeed2 = get_site_option( 'dashboardfeed2' ); +$dashboardfeed1name = get_site_option( 'dashboardfeed1name' ); +$dashboardfeed2name = get_site_option( 'dashboardfeed2name' ); + +?> +

    Dashboard Feeds

    +

    The dashboard displays two feeds. You can allow your users to customize those feeds to set them to a feed of your own.

    +
    + + + + +
    Feed 1
    • User customizable: > Yes > No
    • +
    • Title:
    • +
    • Default Feed URL:
    Feed 2
    • User customizable: > Yes > No
    • +
    • Title:
    • +
    • Default Feed URL:
    + +
    + + + diff --git a/wp-admin/wpmu-options.php b/wp-admin/wpmu-options.php new file mode 100644 index 0000000..bded6ea --- /dev/null +++ b/wp-admin/wpmu-options.php @@ -0,0 +1,131 @@ +You do not have permission to access this page.

    ') ); +} + +if (isset($_GET['updated'])) { + ?>

    +
    +

    +
    +
    + (These settings cannot be modified by blog owners)') ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    " size="45" /> +
    +
    " size="45" /> +
    +
    MB +
    +
    KB +
    +
    +
    + + + + + + +
    " size="45" /> +
    +
    +
    +
    + (These settings may be overridden by blog owners)') ?> + + + + + + + +
    +
    +
    + (Enable or disable WP Backend Menus)') ?> + + + "; + } + ?> +
    MenuEnabled
    " . ucfirst( $val ) . "
    +
    +
    +
    +

    + +

    +
    +
    + diff --git a/wp-admin/wpmu-themes.php b/wp-admin/wpmu-themes.php new file mode 100644 index 0000000..a8e679c --- /dev/null +++ b/wp-admin/wpmu-themes.php @@ -0,0 +1,57 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    '; +$themes = get_themes(); +$allowed_themes = get_site_option( "allowed_themes" ); +if( $allowed_themes == false ) { + $allowed_themes = array_keys( $themes ); +} +?> + +
    +

    Site Themes

    + + + + + + + + + + + +
    Disable themes site-wide. You can enable themes on a blog by blog basis.
    DisabledThemeDescription
    + +    + +
    +

    + +

    +
    + + + diff --git a/wp-admin/wpmu-upgrade-site.php b/wp-admin/wpmu-upgrade-site.php new file mode 100644 index 0000000..284b9ca --- /dev/null +++ b/wp-admin/wpmu-upgrade-site.php @@ -0,0 +1,73 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    '; +switch( $_GET[ 'action' ] ) { + case "upgrade": + if( isset( $_GET[ 'n' ] ) == false ) { + $n = 0; + } else { + $n = $_GET[ 'n' ]; + } + $blogs = $wpdb->get_results( "SELECT * FROM $wpdb->blogs WHERE site_id = '$wpdb->siteid' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT $n, 5", ARRAY_A ); + if( is_array( $blogs ) ) { + print "
      "; + foreach( $blogs as $details ) { + if( $details[ 'spam' ] == 0 && $details[ 'deleted' ] == 0 && $details[ 'archived' ] == 0 ) { + $siteurl = $wpdb->get_var( "SELECT option_value from {$wpmuBaseTablePrefix}{$details[ 'blog_id' ]}_options WHERE option_name = 'siteurl'" ); + print "
    • $siteurl
    • "; + if($http_fopen) { + $fp = fopen( $siteurl . "wp-admin/upgrade.php?step=1", "r" ); + if( $fp ) { + while( feof( $fp ) == false ) { + fgets($fp, 4096); + } + fclose( $fp ); + } + } else { + $client = new Snoopy(); + @$client->fetch($siteurl . "wp-admin/upgrade.php?step=1"); + } + } + } + print "
    "; + ?> +

    If your browser doesn't start loading the next page automatically click this link: Next Blogs

    + + +

    You can upgrade all the blogs on your site through this page. It works by calling the upgrade script of each blog automatically. Hit the link below to upgrade.

    +

    Upgrade Site

    + + + diff --git a/wp-admin/wpmu-users.php b/wp-admin/wpmu-users.php new file mode 100644 index 0000000..fdcf55e --- /dev/null +++ b/wp-admin/wpmu-users.php @@ -0,0 +1,339 @@ +You do not have permission to access this page.

    ') ); +} +if (isset($_GET['updated'])) { + ?>

    '; +switch( $_GET[ 'action' ] ) { + case "edit": + print "

    Edit User

    "; + $options_table_name = $wpmuBaseTablePrefix . $_GET[ 'id' ] ."_options"; + $query = "SELECT * + FROM ".$wpdb->users." + WHERE ID = '".$_GET[ 'id' ]."'"; + $userdetails = $wpdb->get_results( $query, ARRAY_A ); + $query = "SELECT * + FROM ".$wpdb->usermeta." + WHERE user_id = '".$_GET[ 'id' ]."'"; + $usermetadetails= $wpdb->get_results( $query, ARRAY_A ); + ?> +
    +
    + + + + + + + + +
    +
    + + + + + + + + + +
    NameValueDelete
    ]'>
    +
    + +

    + +

    + You do not have permission to access this page.

    ') ); + } + if( is_array( $_POST[ 'allusers' ] ) ) { + while( list( $key, $val ) = each( $_POST[ 'allusers' ] ) ) { + if( $val != '' && $val != '0' && $val != '1' ) { + $user_details = get_userdata( $val ); + if( $_POST[ 'userfunction' ] == 'delete' ) { + wpmu_delete_user($val); + } elseif( $_POST[ 'userfunction' ] == 'spam' ) { + $blogs = get_blogs_of_user( $val ); + if( is_array( $blogs ) ) { + while( list( $key, $details ) = each( $blogs ) ) { + update_blog_status( $details->userblog_id, "spam", '1' ); + do_action( "make_spam_blog", $details->userblog_id ); + } + } + } + } + } + } + header( "Location: wpmu-users.php?updated=true" ); + break; + default: + if( isset( $_GET[ 'start' ] ) == false ) { + $start = 0; + } else { + $start = intval( $_GET[ 'start' ] ); + } + if( isset( $_GET[ 'num' ] ) == false ) { + $num = 30; + } else { + $num = intval( $_GET[ 'num' ] ); + } + + $query = "SELECT * + FROM ".$wpdb->users; + if( $_GET[ 's' ] != '' ) { + $search = '%' . addslashes( $_GET['s'] ) . '%'; + $query .= " WHERE user_login LIKE '$search' OR user_email LIKE '$search'"; + } + if( isset( $_GET[ 'sortby' ] ) == false ) { + $_GET[ 'sortby' ] = 'ID'; + } + if( $_GET[ 'sortby' ] == 'Email' ) { + $query .= ' ORDER BY user_email '; + } elseif( $_GET[ 'sortby' ] == 'ID' ) { + $query .= ' ORDER BY ID '; + } elseif( $_GET[ 'sortby' ] == 'Login' ) { + $query .= ' ORDER BY user_login '; + } elseif( $_GET[ 'sortby' ] == 'Name' ) { + $query .= ' ORDER BY display_name '; + } elseif( $_GET[ 'sortby' ] == 'Registered' ) { + $query .= ' ORDER BY registered '; + } + if( $_GET[ 'order' ] == 'DESC' ) { + $query .= "DESC"; + } else { + $query .= "ASC"; + } + $query .= " LIMIT " . intval( $start ) . ", " . intval( $num ); + $user_list = $wpdb->get_results( $query, ARRAY_A ); + if( count( $user_list ) < $num ) { + $next = false; + } else { + $next = true; + } +?> +

    Users

    + +
    +
    + + + + +
    + Search Blogs: +
    +
    + + Previous Users'; + } else { + echo 'Previous Users'; + } + if ( $next ) { + echo ' || Next Users'; + } else { + echo ' || Next Users'; + } + ?> +
    +
    + + +
    + + 'display name' +$posts_columns = array( + 'ID' => __('ID'), + 'user_login' => __('Login'), + 'user_email' => __('Email'), + 'display_name' => __('Name'), + 'user_registered' => __('Registered'), + 'blogs' => __('Blogs') +); +$posts_columns = apply_filters('manage_posts_columns', $posts_columns); + +// you can not edit these at the moment +$posts_columns['control_edit'] = ''; +$posts_columns['control_delete'] = ''; + +?> + + +
    + + + + + + + + + + + + +$column_display_name) { + + switch($column_name) { + + case 'ID': + ?> + + + + + + + + + + + + + + + + + + + + + + + + +
    start=">
    ' name='allusers[]' value=''> + userblog_id . '">' . str_replace( '.' . $current_site->domain, '', $val->domain ) . ' (userblog_id, 'spam' ) == 1 ) + print 'style="background-color: #f66" '; + print 'target="_new" href="http://'.$val->domain . $val->path.'">View)
    '; + } ?>
    " . __('Edit') . ""; ?>" . __('Delete') . ""; ?>
    +

    Selected Users:

      +
    • +
    • +
    +

    +
    + + + + diff --git a/wp-admin/xfn.js b/wp-admin/xfn.js new file mode 100644 index 0000000..3cdf608 --- /dev/null +++ b/wp-admin/xfn.js @@ -0,0 +1,46 @@ +function GetElementsWithClassName(elementName, className) { + var allElements = document.getElementsByTagName(elementName); + var elemColl = new Array(); + for (i = 0; i < allElements.length; i++) { + if (allElements[i].className == className) { + elemColl[elemColl.length] = allElements[i]; + } + } + return elemColl; +} + +function meChecked() { + var undefined; + var eMe = document.getElementById('me'); + if (eMe == undefined) return false; + else return eMe.checked; +} + +function upit() { + var isMe = meChecked(); //document.getElementById('me').checked; + var inputColl = GetElementsWithClassName('input', 'valinp'); + var results = document.getElementById('link_rel'); + var linkText, linkUrl, inputs = ''; + for (i = 0; i < inputColl.length; i++) { + inputColl[i].disabled = isMe; + inputColl[i].parentNode.className = isMe ? 'disabled' : ''; + if (!isMe && inputColl[i].checked && inputColl[i].value != '') { + inputs += inputColl[i].value + ' '; + } + } + inputs = inputs.substr(0,inputs.length - 1); + if (isMe) inputs='me'; + results.value = inputs; + } + +function blurry() { + if (!document.getElementById) return; + + var aInputs = document.getElementsByTagName('input'); + + for (var i = 0; i < aInputs.length; i++) { + aInputs[i].onclick = aInputs[i].onkeyup = upit; + } +} + +addLoadEvent(blurry); -- cgit