From: Edward Z. Yang Date: Fri, 20 Nov 2009 23:56:08 +0000 (-0500) Subject: Wordpress 2.3.2 X-Git-Tag: wordpress-2.3.2 X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/commitdiff_plain/7688c6ba71852cd89123b62b2d57683535e4702a?hp=022dfbbbe3215917d84708eb09acca93b21ae9e0 Wordpress 2.3.2 Signed-off-by: Edward Z. Yang --- diff --git a/index.php b/index.php index 3e3db402..b1c655cd 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,4 @@ - -WordPress › ReadMe - - + WordPress › ReadMe + + -

WordPress
- Version 2.0

-

Semantic Personal Publishing Platform

+

+ WordPress +
Version 2.3 +

+

Semantic Personal Publishing Platform

+

First Things First

Welcome. WordPress is a very special project to me. Every developer and contributor adds something unique to the mix, and together we create something beautiful that I'm proud to be a part of. Thousands of hours have gone into WordPress, and we're dedicated to making it better every day. Thank you for making it part of your world.

-

— Matt Mullenweg

+

— Matt Mullenweg

-

Installation: Famous 5-minute install

+

Installation: Famous 5-minute install

    -
  1. Unzip the package in an empty directory
  2. -
  3. Open up wp-config-sample.php with a text editor like WordPad or similar and fill in your database connection details
  4. -
  5. Save the file as wp-config.php
  6. +
  7. Unzip the package in an empty directory.
  8. +
  9. Open up wp-config-sample.php with a text editor like WordPad or similar and fill in your database connection details.
  10. +
  11. Save the file as wp-config.php
  12. Upload everything.
  13. -
  14. Open /wp-admin/install.php in your browser. This should setup the tables needed for your blog. If there is an error, double check your wp-config.php file, and try again. If it fails again, please go to the support forums with as much data as you can gather.
  15. +
  16. Open /wp-admin/install.php in your browser. This should setup the tables needed for your blog. If there is an error, double check your wp-config.php file, and try again. If it fails again, please go to the support forums with as much data as you can gather.
  17. Note the password given to you.
  18. The install script should then send you to the login page. Sign in with the username admin and the password generated during the installation. You can then click on 'Profile' to change the password.

Upgrading

Before you upgrade anything, make sure you have backup copies of any files you may have modified such as index.php.

-

Upgrading from any previous WordPress to 2.0:

+

Upgrading from any previous WordPress to 2.3:

    -
  1. Delete your old WP files, saving ones you've modified
  2. -
  3. Upload the new files
  4. -
  5. Point your browser to /wp-admin/upgrade.php
  6. +
  7. Delete your old WP files, saving ones you've modified.
  8. +
  9. Upload the new files.
  10. +
  11. Point your browser to /wp-admin/upgrade.php.
  12. You wanted more, perhaps? That's it!

Template Changes

If you have customized your templates you will probably have to make some changes to them. If you're converting your 1.2 or earlier templates, we've created a special guide for you.

+

Online Resources

If you have any questions that aren't addressed in this document, please take advantage of WordPress' numerous online resources:

The WordPress Codex
-
The Codex is the encyclopedia of all things WordPress. It is the most comprehensive source of information for WordPress available.
+
The Codex is the encyclopedia of all things WordPress. It is the most comprehensive source of information for WordPress available.
The Development Blog
-
This is where you'll find the latest updates and news related to WordPress. Bookmark and check often.
+
This is where you'll find the latest updates and news related to WordPress. Bookmark and check often.
WordPress Planet
-
The WordPress Planet is a news aggregator that brings together posts from WordPress blogs around the web.
+
The WordPress Planet is a news aggregator that brings together posts from WordPress blogs around the web.
WordPress Support Forums
-
If you've looked everywhere and still can't find an answer, the support forums are very active and have a large community ready to help. To help them help you be sure to use a descriptive thread title and describe your question in as much detail as possible.
+
If you've looked everywhere and still can't find an answer, the support forums are very active and have a large community ready to help. To help them help you be sure to use a descriptive thread title and describe your question in as much detail as possible.
WordPress IRC Channel
-
Finally, there is an online chat channel that is used for discussion among people who use WordPress and occasionally support topics. The above wiki page should point you in the right direction. (irc.freenode.net #wordpress)
+
Finally, there is an online chat channel that is used for discussion among people who use WordPress and occasionally support topics. The above wiki page should point you in the right direction. (irc.freenode.net #wordpress)
-

System Recommendations

+

System Recommendations

-

WordPress is the official continuation of b2/cafélog, which came from Michel V. The work has been continued by the WordPress developers. If you would like to support WordPress, please consider donating.

+

WordPress is the official continuation of b2/cafélog, which came from Michel V. The work has been continued by the WordPress developers. If you would like to support WordPress, please consider donating.

Upgrading from another system

-

WordPress can import from a number of systems. First you need to get WordPress installed and working as described above.

+

WordPress can import from a number of systems. First you need to get WordPress installed and working as described above.

-

XML-RPC Interface

-

You can now post to your WordPress blog with tools like Ecto, BlogBuddy, Bloggar, WapBlogger (post from your Wap cellphone!), Radio Userland (which means you can use Radio's email-to-blog feature), Zempt, NewzCrawler, and other tools that support the Blogging APIs! :) You can read more about XML-RPC support on the Codex.

+

XML-RPC and Atom Interface

+

You can now post to your WordPress blog with tools like Windows Live Writer, Ecto, Bloggar, Radio Userland (which means you can use Radio's email-to-blog feature), NewzCrawler, and other tools that support the Blogging APIs! :) You can read more about XML-RPC support on the Codex.

Post via Email

-

You can post from an email client! To set this up go to your "Writing" options screen and fill in the connection details for your secret POP3 account. Then you need to set up wp-mail.php to execute periodically to check the mailbox for new posts. You can do it with Cron-jobs, or if your host doesn't support it you can look into the various website-monitoring services, and make them check your wp-mail.php URL.

-

Posting is easy: Any email sent to the address you specify will be posted, with the subject as the title. It is best to keep the address dicrete. The script will delete emails that are successfully posted.

-

User Roles

+

You can post from an email client! To set this up go to your "Writing" options screen and fill in the connection details for your secret POP3 account. Then you need to set up wp-mail.php to execute periodically to check the mailbox for new posts. You can do it with Cron-jobs, or if your host doesn't support it you can look into the various website-monitoring services, and make them check your wp-mail.php URL.

+

Posting is easy: Any email sent to the address you specify will be posted, with the subject as the title. It is best to keep the address dicrete. The script will delete emails that are successfully posted.

+

User Roles

We've eliminated user levels in order to make way for the much more flexible roles system introduced in 2.0. You can read more about Roles and Capabilities on the Codex.

Final notes

@@ -117,4 +88,4 @@

WordPress is released under the GPL (see license.txt).

- \ No newline at end of file + diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php new file mode 100644 index 00000000..013e3750 --- /dev/null +++ b/wp-admin/admin-ajax.php @@ -0,0 +1,320 @@ +"; + $r .= ""; + $r .= ""; + $r .= "
"; + $r .= ""; + return $r; +} + +$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']); + $x = new WP_Ajax_Response(); + 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)); + $x->add( array( + 'what' => 'category', + 'id' => $cat_id, + 'data' => "
  • " + ) ); + } + $x->send(); + break; +case 'add-link-category' : // On the Fly + if ( !current_user_can( 'manage_categories' ) ) + die('-1'); + $names = explode(',', $_POST['newcat']); + $x = new WP_Ajax_Response(); + foreach ( $names as $cat_name ) { + $cat_name = trim($cat_name); + if ( !$slug = sanitize_title($cat_name) ) + die('0'); + if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) { + $cat_id = wp_insert_term( $cat_name, 'link_category' ); + $cat_id = $cat_id['term_id']; + } + $cat_name = wp_specialchars(stripslashes($cat_name)); + $x->add( array( + 'what' => 'link-category', + 'id' => $cat_id, + 'data' => "" + ) ); + } + $x->send(); + 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'); + $level = 0; + $cat_full_name = $cat->cat_name; + $_cat = $cat; + while ( $_cat->category_parent ) { + $_cat = get_category( $_cat->category_parent ); + $cat_full_name = $_cat->cat_name . ' — ' . $cat_full_name; + $level++; + } + $cat_full_name = attribute_escape($cat_full_name); + + $x = new WP_Ajax_Response( array( + 'what' => 'cat', + 'id' => $cat->cat_ID, + 'data' => _cat_row( $cat, $level, $cat_full_name ), + 'supplemental' => array('name' => $cat_full_name, 'show-link' => sprintf(__( 'Category %s added' ), "cat-$cat->cat_ID", $cat_full_name)) + ) ); + $x->send(); + break; +case 'add-comment' : + if ( !current_user_can( 'edit_post', $id ) ) + die('-1'); + $search = isset($_POST['s']) ? $_POST['s'] : false; + $start = isset($_POST['page']) ? intval($_POST['page']) * 25 : 25; + + list($comments, $total) = _wp_get_comment_list( $search, $start, 1 ); + + if ( !$comments ) + die('1'); + $x = new WP_Ajax_Response(); + foreach ( (array) $comments as $comment ) { + get_comment( $comment ); + ob_start(); + _wp_comment_list_item( $comment->comment_ID ); + $comment_list_item = ob_get_contents(); + ob_end_clean(); + $x->add( array( + 'what' => 'comment', + 'id' => $comment->comment_ID, + 'data' => $comment_list_item + ) ); + } + $x->send(); + break; +case 'add-meta' : + if ( !current_user_can( 'edit_post', $id ) ) + die('-1'); + if ( $id < 0 ) { + $now = current_time('timestamp', 1); + if ( $pid = wp_insert_post( array( + 'post_title' => sprintf('Draft created on %s at %s', date(get_option('date_format'), $now), date(get_option('time_format'), $now)) + ) ) ) { + if ( is_wp_error( $pid ) ) + return $pid; + $mid = add_meta( $pid ); + } + else + die('0'); + } else if ( !$mid = add_meta( $id ) ) { + die('0'); + } + + $meta = get_post_meta_by_id( $mid ); + $key = $meta->meta_key; + $value = $meta->meta_value; + $pid = (int) $meta->post_id; + + $x = new WP_Ajax_Response( array( + 'what' => 'meta', + 'id' => $mid, + 'data' => wp_ajax_meta_row( $pid, $mid, $key, $value ), + 'supplemental' => array('postid' => $pid) + ) ); + $x->send(); + 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 meta doesn't exist + if ( !current_user_can( 'edit_post', $meta->post_id ) ) + die('-1'); + if ( $u = update_meta( $mid, $key, $value ) ) { + $key = stripslashes($key); + $value = stripslashes($value); + $x = new WP_Ajax_Response( array( + 'what' => 'meta', + 'id' => $mid, + 'data' => wp_ajax_meta_row( $meta->post_id, $mid, $key, $value ), + 'supplemental' => array('postid' => $meta->post_id) + ) ); + $x->send(); + } + die('1'); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). + break; +case 'add-user' : + if ( !current_user_can('edit_users') ) + die('-1'); + require_once(ABSPATH . WPINC . '/registration.php'); + if ( !$user_id = add_user() ) + die('0'); + elseif ( is_wp_error( $user_id ) ) { + foreach( $user_id->get_error_messages() as $message ) + echo "

    $message

    "; + exit; + } + $user_object = new WP_User( $user_id ); + $x = new WP_Ajax_Response( array( + 'what' => 'user', + 'id' => $user_id, + 'data' => user_row( $user_object ), + 'supplemental' => array('show-link' => sprintf(__( 'User %s added' ), "user-$user_id", $user_object->user_login)) + ) ); + $x->send(); + break; +case 'autosave' : // The name of this action is hardcoded in edit_post() + $_POST['post_content'] = $_POST['content']; + $_POST['post_excerpt'] = $_POST['excerpt']; + $_POST['post_status'] = 'draft'; + $_POST['post_category'] = explode(",", $_POST['catslist']); + if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) + unset($_POST['post_category']); + + if($_POST['post_ID'] < 0) { + $_POST['temp_ID'] = $_POST['post_ID']; + $id = wp_write_post(); + if( is_wp_error($id) ) + die($id->get_error_message()); + else + die("$id"); + } else { + $post_ID = (int) $_POST['post_ID']; + $_POST['ID'] = $post_ID; + $post = get_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.')); + } + wp_update_post($_POST); + } + die('0'); +break; +case 'autosave-generate-nonces' : + $ID = (int) $_POST['post_ID']; + if($_POST['post_type'] == 'post') { + if(current_user_can('edit_post', $ID)) + die(wp_create_nonce('update-post_' . $ID)); + } + if($_POST['post_type'] == 'page') { + if(current_user_can('edit_page', $ID)) { + die(wp_create_nonce('update-page_' . $ID)); + } + } + die('0'); +break; +default : + do_action( 'wp_ajax_' . $_POST['action'] ); + die('0'); + break; +endswitch; +?> diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php deleted file mode 100644 index d909ee67..00000000 --- a/wp-admin/admin-db.php +++ /dev/null @@ -1,387 +0,0 @@ -posts WHERE 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_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) ORDER BY display_name" ); - } - - return apply_filters('get_editable_authors', $authors); -} - -function get_editable_user_ids( $user_id, $exclude_zeros = true ) { - global $wpdb; - - $user = new WP_User( $user_id ); - - if ( ! $user->has_cap('edit_others_posts') ) { - if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) - return array($user->id); - else - return false; - } - - $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 (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 (!$update) { - $wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$category_parent')"); - $cat_ID = (int) $wpdb->insert_id; - } else { - $wpdb->query ("UPDATE $wpdb->categories SET cat_name = '$cat_name', category_nicename = '$category_nicename', category_description = '$category_description', category_parent = '$category_parent' 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); - } - - 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; - - $category = get_category($cat_ID); - - $parent = $category->category_parent; - - // Delete the category. - $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = '$cat_ID'"); - - // Update children to point to new parent. - $wpdb->query("UPDATE $wpdb->categories SET category_parent = '$parent' WHERE category_parent = '$cat_ID'"); - - // TODO: Only set categories to general if they're not in another category already - $default_cat = get_option('default_category'); - $wpdb->query("UPDATE $wpdb->post2cat SET category_id='$default_cat' WHERE category_id='$cat_ID'"); - - 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_cats('', $post_id, $cat_ids); - - return $cat_ids; -} - -function category_exists($cat_name) { - global $wpdb; - if (!$category_nicename = sanitize_title($cat_name)) - return 0; - - return (int) $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->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'); - - do_action('delete_user', $id); - - return true; -} - -function get_link($link_id, $output = OBJECT) { - global $wpdb; - - $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'"); - - if ( $output == OBJECT ) { - return $link; - } elseif ( $output == ARRAY_A ) { - return get_object_vars($link); - } elseif ( $output == ARRAY_N ) { - return array_values(get_object_vars($link)); - } else { - return $link; - } -} - -function wp_insert_link($linkdata) { - global $wpdb, $current_user; - - extract($linkdata); - - $update = false; - - if ( !empty($link_id) ) - $update = true; - - $link_id = (int) $link_id; - - if( trim( $link_name ) == '' ) - return 0; - $link_name = apply_filters('pre_link_name', $link_name); - - if( trim( $link_url ) == '' ) - return 0; - $link_url = apply_filters('pre_link_url', $link_url); - - if ( empty($link_rating) ) - $link_rating = 0; - else - $link_rating = (int) $link_rating; - - if ( empty($link_image) ) - $link_image = ''; - $link_image = apply_filters('pre_link_image', $link_image); - - if ( empty($link_target) ) - $link_target = ''; - $link_target = apply_filters('pre_link_target', $link_target); - - if ( empty($link_visible) ) - $link_visible = 'Y'; - $link_visibile = preg_replace('/[^YNyn]/', '', $link_visible); - - if ( empty($link_owner) ) - $link_owner = $current_user->id; - else - $link_owner = (int) $link_owner; - - if ( empty($link_notes) ) - $link_notes = ''; - $link_notes = apply_filters('pre_link_notes', $link_notes); - - if ( empty($link_description) ) - $link_description = ''; - $link_description = apply_filters('pre_link_description', $link_description); - - if ( empty($link_rss) ) - $link_rss = ''; - $link_rss = apply_filters('pre_link_rss', $link_rss); - - if ( empty($link_rel) ) - $link_rel = ''; - $link_rel = apply_filters('pre_link_rel', $link_rel); - - 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_category='$link_category', - 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_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_category', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')"); - $link_id = (int) $wpdb->insert_id; - } - - 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); - - // Merge old and new fields with new fields overwriting old ones. - $linkdata = array_merge($link, $linkdata); - - return wp_insert_link($linkdata); -} - -function wp_delete_link($link_id) { - global $wpdb; - - do_action('delete_link', $link_id); - return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); -} - -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'"); -} - -?> diff --git a/wp-admin/admin-footer.php b/wp-admin/admin-footer.php index 88e69ae4..a96770b5 100644 --- a/wp-admin/admin-footer.php +++ b/wp-admin/admin-footer.php @@ -1,19 +1,13 @@ -

    '; + } + + 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 '
    '; + 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"); + echo '
    '; + } + + 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 ( is_wp_error( $post_id ) ) { + return $post_id; + } + 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 = (int) $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']; + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + return $result; + 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 : + $result = $this->import(); + if ( is_wp_error( $result ) ) + $result->get_error_message(); + 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/btt.php b/wp-admin/import/btt.php new file mode 100644 index 00000000..76a02c32 --- /dev/null +++ b/wp-admin/import/btt.php @@ -0,0 +1,115 @@ +'; + echo '

    '.__('Import Bunny’s Technorati Tags').'

    '; + echo '

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

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

    '.__('Howdy! This imports tags from an existing Bunny’s Technorati Tags installation into this blog using the new WordPress native tagging structure.').'

    '; + echo '

    '.__('This is suitable for Bunny’s Technorati Tags version 0.6.').'

    '; + echo '

    '.__('All existing Bunny’s Technorati Tags will be removed after import.').'

    '; + echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; + echo '
    '; + wp_nonce_field('import-btt'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function dispatch() { + if ( empty($_GET['step']) ) + $step = 0; + else + $step = abs(intval($_GET['step'])); + + // load the header + $this->header(); + + switch ( $step ) { + case 0 : + $this->greet(); + break; + case 1 : + check_admin_referer('import-btt'); + $this->check_post_keyword( true ); + break; + case 2 : + check_admin_referer('import-btt'); + $this->check_post_keyword( false ); + break; + case 3: + $this->done(); + break; + } + + // load the footer + $this->footer(); + } + + function check_post_keyword($precheck = true) { + global $wpdb; + + echo '
    '; + echo '

    '.__('Reading Bunny’s Technorati Tags…').'

    '; + + // import Bunny's Keywords tags + $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'tags'"); + if ( !is_array($metakeys)) { + echo '

    ' . __('No Tags Found!') . '

    '; + return false; + } else { + $count = count($metakeys); + echo '

    ' . sprintf( __('Done! %s posts with tags were read.'), $count ) . '

    '; + echo '
      '; + foreach ( $metakeys as $post_meta ) { + if ( $post_meta->meta_value != '' ) { + $post_keys = explode(' ', $post_meta->meta_value); + foreach ( $post_keys as $keyword ) { + $keyword = addslashes(trim(str_replace('+',' ',$keyword))); + if ( '' != $keyword ) { + echo '
    • ' . $post_meta->post_id . ' - ' . $keyword . '
    • '; + if ( !$precheck ) + wp_add_post_tags($post_meta->post_id, $keyword); + } + } + } + if ( !$precheck ) + delete_post_meta($post_meta->post_id, 'tags'); + } + echo '
    '; + } + + echo '
    '; + wp_nonce_field('import-btt'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function done() { + echo '
    '; + echo '

    '.__('Import Complete!').'

    '; + echo '
    '; + } + + function BunnyTags_Import() { + } + +} + +// create the import object +$btt_import = new BunnyTags_Import(); + +// add it to the import page! +register_importer('btt', 'Bunny’s Technorati Tags', __('Import Bunny’s Technorati Tags into the new native tagging structure.'), array($btt_import, 'dispatch')); + +?> diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php index fd4f2d65..1bf04860 100644 --- a/wp-admin/import/dotclear.php +++ b/wp-admin/import/dotclear.php @@ -7,18 +7,6 @@ /** Add These Functions to make our lives easier **/ -if(!function_exists('get_catbynicename')) -{ - function get_catbynicename($category_nicename) - { - global $wpdb; - - $cat_id -= 0; // force numeric - $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); - - return $name; - } -} if(!function_exists('get_comment_count')) { @@ -29,15 +17,6 @@ if(!function_exists('get_comment_count')) } } -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) @@ -130,19 +109,19 @@ function textconv ($s) { **/ class Dotclear_Import { - function header() + 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() + function footer() { echo '
    '; } - function greet() + 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:').'

    '; @@ -385,6 +364,8 @@ class Dotclear_Import { 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } else { @@ -403,14 +384,19 @@ class Dotclear_Import { 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } $dcposts2wpposts[$post_id] = $ret_id; // Make Post-to-Category associations $cats = array(); - if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; } + $category1 = get_category_by_slug($post_cat_name); + $category1 = $category1->term_id; + + if($cat1 = $category1) { $cats[1] = $cat1; } - if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use @@ -509,12 +495,11 @@ class Dotclear_Import { extract($link); if ($title != "") { - if ($cinfo = link_cat_exists (csc ($title))) { - $category = $cinfo; + if ($cinfo = is_term(csc ($title), 'link_category')) { + $category = $cinfo['term_id']; } else { - $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('". - $wpdb->escape (csc ($title))."')"); - $category = $wpdb->insert_id; + $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category'); + $category = $category['term_id']; } } else { $linkname = $wpdb->escape(csc ($label)); @@ -581,7 +566,9 @@ class Dotclear_Import { { // Post Import $posts = $this->get_dc_posts(); - $this->posts2wp($posts); + $result = $this->posts2wp($posts); + if ( is_wp_error( $result ) ) + return $result; echo '
    '; wp_nonce_field('import-dotclear'); @@ -729,7 +716,9 @@ class Dotclear_Import { $this->import_users(); break; case 3 : - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; case 4 : $this->import_comments(); diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php index 4305cd18..6e92235d 100644 --- a/wp-admin/import/greymatter.php +++ b/wp-admin/import/greymatter.php @@ -233,6 +233,8 @@ class GM_Import { $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); + if ( is_wp_error( $post_ID ) ) + return $post_ID; } $c=count($entry); @@ -287,6 +289,7 @@ class GM_Import {

    footer(); + return; } function dispatch() { @@ -301,7 +304,9 @@ class GM_Import { break; case 1: check_admin_referer('import-greymatter'); - $this->import(); + $result = $this->import(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; } } diff --git a/wp-admin/import/jkw.php b/wp-admin/import/jkw.php new file mode 100644 index 00000000..9f7b48ee --- /dev/null +++ b/wp-admin/import/jkw.php @@ -0,0 +1,178 @@ +'; + echo '

    '.__('Import Jerome’s Keywords').'

    '; + echo '

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

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

    '.__('Howdy! This imports tags from an existing Jerome’s Keywords installation into this blog using the new WordPress native tagging structure.').'

    '; + echo '

    '.__('This is suitable for Jerome’s Keywords version 1.x and 2.0a.').'

    '; + echo '

    '.__('All existing Jerome’s Keywords will be removed after import.').'

    '; + echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; + echo ''; + wp_nonce_field('import-jkw'); + echo '

    '; + echo ''; + echo '
    '; + wp_nonce_field('import-jkw'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function dispatch() { + if ( empty($_GET['step']) ) + $step = 0; + else + $step = abs(intval($_GET['step'])); + + // load the header + $this->header(); + + switch ( $step ) { + case 0 : + $this->greet(); + break; + case 1 : + check_admin_referer('import-jkw'); + $this->check_V1_post_keyword( true ); + break; + case 2 : + check_admin_referer('import-jkw'); + $this->check_V1_post_keyword( false ); + break; + case 3 : + check_admin_referer('import-jkw'); + $this->check_V2_post_keyword( true ); + break; + case 4 : + check_admin_referer('import-jkw'); + $this->check_V2_post_keyword( false ); + break; + case 5: + check_admin_referer('import-jkw'); + $this->cleanup_V2_import(); + break; + case 6: + $this->done(); + break; + } + + // load the footer + $this->footer(); + } + + function check_V1_post_keyword($precheck = true) { + global $wpdb; + + echo '
    '; + echo '

    '.__('Reading Jerome’s Keywords Tags…').'

    '; + + // import Jerome's Keywords tags + $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'keywords'"); + if ( !is_array($metakeys)) { + echo '

    ' . __('No Tags Found!') . '

    '; + return false; + } else { + $count = count($metakeys); + echo '

    ' . sprintf( __('Done! %s posts with tags were read.'), $count ) . '

    '; + echo '
      '; + foreach ( $metakeys as $post_meta ) { + if ( $post_meta->meta_value != '' ) { + $post_keys = explode(',', $post_meta->meta_value); + foreach ( $post_keys as $keyword ) { + $keyword = addslashes(trim($keyword)); + if ( '' != $keyword ) { + echo '
    • ' . $post_meta->post_id . ' - ' . $keyword . '
    • '; + if ( !$precheck ) + wp_add_post_tags($post_meta->post_id, $keyword); + } + } + } + if ( !$precheck ) + delete_post_meta($post_meta->post_id, 'keywords'); + } + echo '
    '; + } + + echo '
    '; + wp_nonce_field('import-jkw'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function check_V2_post_keyword($precheck = true) { + global $wpdb; + + echo '
    '; + echo '

    '.__('Reading Jerome’s Keywords Tags…').'

    '; + + // import Jerome's Keywords tags + $tablename = $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1); + $metakeys = $wpdb->get_results("SELECT post_id, tag_name FROM $tablename"); + if ( !is_array($metakeys) ) { + echo '

    ' . __('No Tags Found!') . '

    '; + return false; + } else { + $count = count($metakeys); + echo '

    ' . sprintf( __('Done! %s tags were read.'), $count ) . '

    '; + echo '
      '; + foreach ( $metakeys as $post_meta ) { + $keyword = addslashes(trim($post_meta->tag_name)); + if ( $keyword != '' ) { + echo '
    • ' . $post_meta->post_id . ' - ' . $keyword . '
    • '; + if ( !$precheck ) + wp_add_post_tags($post_meta->post_id, $keyword); + } + } + echo '
    '; + } + echo '
    '; + wp_nonce_field('import-jkw'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function cleanup_V2_import() { + global $wpdb; + + /* options from V2.0a (jeromes-keywords.php) */ + $options = array('version', 'keywords_table', 'query_varname', 'template', 'meta_always_include', 'meta_includecats', 'meta_autoheader', 'search_strict', 'use_feed_cats', 'post_linkformat', 'post_tagseparator', 'post_includecats', 'post_notagstext', 'cloud_linkformat', 'cloud_tagseparator', 'cloud_includecats', 'cloud_sortorder', 'cloud_displaymax', 'cloud_displaymin', 'cloud_scalemax', 'cloud_scalemin'); + + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1)); + + foreach ( $options as $o ) + delete_option('jkeywords_' . $o); + + $this->done(); + } + + function done() { + echo '
    '; + echo '

    '.__('Import Complete!').'

    '; + echo '
    '; + } + + function JeromesKeyword_Import() { + } + +} + +// create the import object +$jkw_import = new JeromesKeyword_Import(); + +// add it to the import page! +register_importer('jkw', 'Jerome’s Keywords', __('Import Jerome’s Keywords into the new native tagging structure.'), array($jkw_import, 'dispatch')); + +?> diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php index 3c9cdab7..81f0365a 100644 --- a/wp-admin/import/livejournal.php +++ b/wp-admin/import/livejournal.php @@ -18,15 +18,18 @@ class LJ_Import { $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.').'

    '; + echo '
    '; + echo '

    '.__('Howdy! Upload your LiveJournal XML export file and we’ll import the posts into this blog.').'

    '; + echo '

    '.__('Choose a LiveJournal XML file to upload, then click Upload file and import.').'

    '; wp_import_upload_form("admin.php?import=livejournal&step=1"); + echo '
    '; } 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 @@ -35,9 +38,8 @@ class LJ_Import { preg_match_all('|(.*?)|is', $importdata, $posts); $posts = $posts[1]; unset($importdata); - echo '
      '; + echo '
        '; foreach ($posts as $post) { - flush(); preg_match('|(.*?)|is', $post, $post_title); $post_title = $wpdb->escape(trim($post_title[1])); if ( empty($post_title) ) { @@ -47,7 +49,7 @@ class LJ_Import { preg_match('|(.*?)|is', $post, $post_date); $post_date = strtotime($post_date[1]); - $post_date = gmdate('Y-m-d H:i:s', $post_date); + $post_date = date('Y-m-d H:i:s', $post_date); preg_match('|(.*?)|is', $post, $post_content); $post_content = str_replace(array (''), '', trim($post_content[1])); @@ -69,6 +71,8 @@ class LJ_Import { 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 ( is_wp_error( $post_id ) ) + return $post_id; if (!$post_id) { _e("Couldn't get post ID"); echo ''; @@ -78,7 +82,7 @@ class LJ_Import { preg_match_all('|(.*?)|is', $post, $comments); $comments = $comments[1]; - + if ( $comments ) { $comment_post_ID = (int) $post_id; $num_comments = 0; @@ -118,8 +122,6 @@ class LJ_Import { printf(__('(%s comments)'), $num_comments); } echo ''; - flush(); - ob_flush(); } echo '
      '; } @@ -132,9 +134,11 @@ class LJ_Import { } $this->file = $file['file']; - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + return $result; wp_import_cleanup($file['id']); - + echo '

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

      '; @@ -147,26 +151,28 @@ class LJ_Import { $step = (int) $_GET['step']; $this->header(); - + switch ($step) { case 0 : $this->greet(); break; case 1 : check_admin_referer('import-upload'); - $this->import(); + $result = $this->import(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; } - + $this->footer(); } function LJ_Import() { - // Nothing. + // Nothing. } } $livejournal_import = new LJ_Import(); -register_importer('livejournal', __('LiveJournal'), __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch')); +register_importer('livejournal', __('LiveJournal'), __('Import posts from a LiveJournal XML export file'), array ($livejournal_import, 'dispatch')); ?> diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php index f02b0697..d18ef464 100644 --- a/wp-admin/import/mt.php +++ b/wp-admin/import/mt.php @@ -11,7 +11,7 @@ class MT_Import { function header() { echo '
      '; - echo '

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

      '; + echo '

      '.__('Import Movable Type or TypePad').'

      '; } function footer() { @@ -21,9 +21,20 @@ class MT_Import { function greet() { $this->header(); ?> -

      +
      +

      mt-export.txt in your /wp-content/ directory and then click "Import mt-export.txt"'); ?>

      -

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

      +
      + +

      + +mt-export.txt in your /wp-content/ directory'); ?>

      +

      + +

      +
      +

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

      +
      footer(); } @@ -53,9 +64,9 @@ class MT_Import { $pass = 'changeme'; if (!(in_array($author, $this->mtnames))) { //a new mt author name is found ++ $this->j; - $this->mtnames[$this->j] = $author; //add that new mt author name to an array + $this->mtnames[$this->j] = $author; //add that new mt author name to an array $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user - if (!$user_id) { //banging my head against the desk now. + if (!$user_id) { //banging my head against the desk now. if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname $user_id = wp_create_user($author, $pass); $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank. @@ -73,25 +84,27 @@ class MT_Import { 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 - } + $temp = array(); + $authors = array(); + + $handle = fopen($this->file, 'r'); + if ( $handle == null ) + return false; + + $in_comment = false; + while ( $line = fgets($handle) ) { + $line = trim($line); + + if ( 'COMMENT:' == $line ) + $in_comment = true; + else if ( '-----' == $line ) + $in_comment = false; + + if ( $in_comment || 0 !== strpos($line,"AUTHOR:") ) + continue; + + $temp[] = trim( substr($line, strlen("AUTHOR:")) ); } //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. @@ -103,6 +116,8 @@ class MT_Import { array_push($authors, "$next"); } + fclose($handle); + return $authors; } @@ -136,7 +151,7 @@ class MT_Import { ?>

      -

      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.'); ?>

      '; } - echo ''.'
      '; + echo ''.'
      '; echo ''; echo '
    '; } function select_authors() { - $file = wp_import_handle_upload(); + if ( $_POST['upload_type'] === 'ftp' ) { + $file['file'] = ABSPATH . 'wp-content/mt-export.txt'; + if ( !file_exists($file['file']) ) + $file['error'] = __('mt-export.txt does not exist'); + } else { + $file = wp_import_handle_upload(); + } if ( isset($file['error']) ) { $this->header(); echo '

    '.__('Sorry, there has been an error').'.

    '; @@ -172,237 +193,235 @@ class MT_Import { $this->file = $file['file']; $this->id = (int) $file['id']; - $this->get_entries(); $this->mt_authors_form(); } + function save_post(&$post, &$comments, &$pings) { + // Reset the counter + set_time_limit(30); + $post = get_object_vars($post); + $post = add_magic_quotes($post); + $post = (object) $post; + + if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) { + echo '
  • '; + printf(__('Post %s already exists.'), stripslashes($post->post_title)); + } else { + echo '
  • '; + printf(__('Importing post %s...'), stripslashes($post->post_title)); + + if ( '' != trim( $post->extended ) ) + $post->post_content .= "\n\n$post->extended"; + + $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor + $post_id = wp_insert_post($post); + if ( is_wp_error( $post_id ) ) + return $post_id; + + // Add categories. + if ( 0 != count($post->categories) ) { + wp_create_categories($post->categories, $post_id); + } + } + + $num_comments = 0; + foreach ( $comments as $comment ) { + $comment = get_object_vars($comment); + $comment = add_magic_quotes($comment); + + if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) { + $comment['comment_post_ID'] = $post_id; + $comment = wp_filter_comment($comment); + wp_insert_comment($comment); + $num_comments++; + } + } + + if ( $num_comments ) + printf(' '.__('(%s comments)'), $num_comments); + + $num_pings = 0; + foreach ( $pings as $ping ) { + $ping = get_object_vars($ping); + $ping = add_magic_quotes($ping); + + if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) { + $ping['comment_content'] = "{$ping['title']}\n\n{$ping['comment_content']}"; + $ping['comment_post_ID'] = $post_id; + $ping = wp_filter_comment($ping); + wp_insert_comment($ping); + $num_pings++; + } + } + + if ( $num_pings ) + printf(' '.__('(%s pings)'), $num_pings); + + echo "
  • "; + //ob_flush();flush(); + } + 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); - $post_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 + $handle = fopen($this->file, 'r'); + if ( $handle == null ) + return false; - $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); - } - } + $context = ''; + $post = new StdClass(); + $comment = new StdClass(); + $comments = array(); + $ping = new StdClass(); + $pings = array(); + + echo "
        "; - $comment_post_ID = (int) $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++; - } - } + while ( $line = fgets($handle) ) { + $line = trim($line); + + if ( '-----' == $line ) { + // Finishing a multi-line field + if ( 'comment' == $context ) { + $comments[] = $comment; + $comment = new StdClass(); + } else if ( 'ping' == $context ) { + $pings[] = $ping; + $ping = new StdClass(); } - 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++; - } - } + $context = ''; + } else if ( '--------' == $line ) { + // Finishing a post. + $context = ''; + $result = $this->save_post($post, $comments, $pings); + if ( is_wp_error( $result ) ) + return $result; + $post = new StdClass; + $comment = new StdClass(); + $ping = new StdClass(); + $comments = array(); + $pings = array(); + } else if ( 'BODY:' == $line ) { + $context = 'body'; + } else if ( 'EXTENDED BODY:' == $line ) { + $context = 'extended'; + } else if ( 'EXCERPT:' == $line ) { + $context = 'excerpt'; + } else if ( 'KEYWORDS:' == $line ) { + $context = 'keywords'; + } else if ( 'COMMENT:' == $line ) { + $context = 'comment'; + } else if ( 'PING:' == $line ) { + $context = 'ping'; + } else if ( 0 === strpos($line, "AUTHOR:") ) { + $author = trim( substr($line, strlen("AUTHOR:")) ); + if ( '' == $context ) + $post->post_author = $author; + else if ( 'comment' == $context ) + $comment->comment_author = $author; + } else if ( 0 === strpos($line, "TITLE:") ) { + $title = trim( substr($line, strlen("TITLE:")) ); + if ( '' == $context ) + $post->post_title = $title; + else if ( 'ping' == $context ) + $ping->title = $title; + } else if ( 0 === strpos($line, "STATUS:") ) { + $status = trim( substr($line, strlen("STATUS:")) ); + if ( empty($status) ) + $status = 'publish'; + $post->post_status = $status; + } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) { + $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) ); + if ( $allow == 1 ) + $post->comment_status = 'open'; + else + $post->comment_status = 'closed'; + } else if ( 0 === strpos($line, "ALLOW PINGS:") ) { + $allow = trim( substr($line, strlen("ALLOW PINGS:")) ); + if ( $allow == 1 ) + $post->ping_status = 'open'; + else + $post->ping_status = 'closed'; + } else if ( 0 === strpos($line, "CATEGORY:") ) { + $category = trim( substr($line, strlen("CATEGORY:")) ); + if ( '' != $category ) + $post->categories[] = $category; + } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) { + $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) ); + if ( '' != $category ) + $post->categories[] = $category; + } else if ( 0 === strpos($line, "DATE:") ) { + $date = trim( substr($line, strlen("DATE:")) ); + $date = strtotime($date); + $date = date('Y-m-d H:i:s', $date); + $date_gmt = get_gmt_from_date($date); + if ( '' == $context ) { + $post->post_modified = $date; + $post->post_modified_gmt = $date_gmt; + $post->post_date = $date; + $post->post_date_gmt = $date_gmt; + } else if ( 'comment' == $context ) { + $comment->comment_date = $date; + } else if ( 'ping' == $context ) { + $ping->comment_date = $date; + } + } else if ( 0 === strpos($line, "EMAIL:") ) { + $email = trim( substr($line, strlen("EMAIL:")) ); + if ( 'comment' == $context ) + $comment->comment_author_email = $email; + else + $ping->comment_author_email = ''; + } else if ( 0 === strpos($line, "IP:") ) { + $ip = trim( substr($line, strlen("IP:")) ); + if ( 'comment' == $context ) + $comment->comment_author_IP = $ip; + else + $ping->comment_author_IP = $ip; + } else if ( 0 === strpos($line, "URL:") ) { + $url = trim( substr($line, strlen("URL:")) ); + if ( 'comment' == $context ) + $comment->comment_author_url = $url; + else + $ping->comment_author_url = $url; + } else if ( 0 === strpos($line, "BLOG NAME:") ) { + $blog = trim( substr($line, strlen("BLOG NAME:")) ); + $ping->comment_author = $blog; + } else { + // Processing multi-line field, check context. + + $line .= "\n"; + if ( 'body' == $context ) { + $post->post_content .= $line; + } else if ( 'extended' == $context ) { + $post->extended .= $line; + } else if ( 'excerpt' == $context ) { + $post->post_excerpt .= $line; + } else if ( 'comment' == $context ) { + $comment->comment_content .= $line; + } else if ( 'ping' == $context ) { + $ping->comment_content .= $line; } - if ( $num_pings ) - printf(' '.__('(%s pings)'), $num_pings); - - echo ""; } } echo '
      '; wp_import_cleanup($this->id); + do_action('import_done', 'mt'); echo '

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

      '; } function import() { $this->id = (int) $_GET['id']; - - $this->file = get_attached_file($this->id); + if ( $this->id == 0 ) + $this->file = ABSPATH . 'wp-content/mt-export.txt'; + else + $this->file = get_attached_file($this->id); $this->get_authors_from_post(); - $this->get_entries(); - $this->process_posts(); + $result = $this->process_posts(); + if ( is_wp_error( $result ) ) + return $result; } function dispatch() { @@ -421,7 +440,9 @@ class MT_Import { break; case 2: check_admin_referer('import-mt'); - $this->import(); + $result = $this->import(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; } } @@ -433,5 +454,5 @@ class MT_Import { $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')); +register_importer('mt', __('Movable Type and TypePad'), __('Import posts and comments from a Movable Type or Typepad blog'), array ($mt_import, 'dispatch')); ?> diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php index 187c8ac2..11fc7702 100644 --- a/wp-admin/import/rss.php +++ b/wp-admin/import/rss.php @@ -19,15 +19,17 @@ class RSS_Import { $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.').'

      '; + echo '
      '; + echo '

      '.__('Howdy! This importer allows you to extract posts from an 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"); + echo '
      '; } 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 @@ -108,6 +110,8 @@ class RSS_Import { _e('Post already imported'); } else { $post_id = wp_insert_post($post); + if ( is_wp_error( $post_id ) ) + return $post_id; if (!$post_id) { _e("Couldn't get post ID"); return; @@ -133,9 +137,11 @@ class RSS_Import { $this->file = $file['file']; $this->get_posts(); - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + return $result; wp_import_cleanup($file['id']); - + echo '

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

      '; @@ -148,22 +154,24 @@ class RSS_Import { $step = (int) $_GET['step']; $this->header(); - + switch ($step) { case 0 : $this->greet(); break; case 1 : check_admin_referer('import-upload'); - $this->import(); + $result = $this->import(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; } - + $this->footer(); } function RSS_Import() { - // Nothing. + // Nothing. } } diff --git a/wp-admin/import/stp.php b/wp-admin/import/stp.php new file mode 100644 index 00000000..9d5371cf --- /dev/null +++ b/wp-admin/import/stp.php @@ -0,0 +1,155 @@ +'; + echo '

      '.__('Import Simple Tagging').'

      '; + echo '

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

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

    '.__('Howdy! This imports tags from an existing Simple Tagging 1.6.2 installation into this blog using the new WordPress native tagging structure.').'

    '; + echo '

    '.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'

    '; + echo '

    '.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'

    '; + echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; + echo '
    '; + wp_nonce_field('import-stp'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function dispatch () { + if ( empty( $_GET['step'] ) ) { + $step = 0; + } else { + $step = (int) $_GET['step']; + } + // load the header + $this->header(); + switch ( $step ) { + case 0 : + $this->greet(); + break; + case 1 : + check_admin_referer('import-stp'); + $this->import_posts(); + break; + case 2: + check_admin_referer('import-stp'); + $this->import_t2p(); + break; + case 3: + check_admin_referer('import-stp'); + $this->cleanup_import(); + break; + } + // load the footer + $this->footer(); + } + + + function import_posts ( ) { + echo '
    '; + echo '

    '.__('Reading STP Post Tags…').'

    '; + + // read in all the STP tag -> post settings + $posts = $this->get_stp_posts(); + + // if we didn't get any tags back, that's all there is folks! + if ( !is_array($posts) ) { + echo '

    ' . __('No posts were found to have tags!') . '

    '; + return false; + } + else { + // if there's an existing entry, delete it + if ( get_option('stpimp_posts') ) { + delete_option('stpimp_posts'); + } + + add_option('stpimp_posts', $posts); + $count = count($posts); + echo '

    ' . sprintf( __('Done! %s tag to post relationships were read.'), $count ) . '

    '; + } + + echo '
    '; + wp_nonce_field('import-stp'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + + function import_t2p ( ) { + echo '
    '; + echo '

    '.__('Adding Tags to Posts…').'

    '; + + // run that funky magic! + $tags_added = $this->tag2post(); + + echo '

    ' . sprintf( __('Done! %s tags where added!'), $tags_added ) . '

    '; + echo '
    '; + wp_nonce_field('import-stp'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + function get_stp_posts ( ) { + global $wpdb; + // read in all the posts from the STP post->tag table: should be wp_post2tag + $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags"; + $posts = $wpdb->get_results($posts_query); + return $posts; + } + + function tag2post ( ) { + global $wpdb; + + // get the tags and posts we imported in the last 2 steps + $posts = get_option('stpimp_posts'); + + // null out our results + $tags_added = 0; + + // loop through each post and add its tags to the db + foreach ( $posts as $this_post ) { + $the_post = (int) $this_post->post_id; + $the_tag = $wpdb->escape($this_post->tag_name); + // try to add the tag + wp_add_post_tags($the_post, $the_tag); + $tags_added++; + } + + // that's it, all posts should be linked to their tags properly, pending any errors we just spit out! + return $tags_added; + } + + function cleanup_import ( ) { + delete_option('stpimp_posts'); + $this->done(); + } + + function done ( ) { + echo '
    '; + echo '

    '.__('Import Complete!').'

    '; + echo '

    ' . __('OK, so we lied about this being a 4-step program! You’re done!') . '

    '; + echo '

    ' . __('Now wasn’t that easy?') . '

    '; + echo '
    '; + } + + function STP_Import ( ) { + // Nothing. + } +} + +// create the import object +$stp_import = new STP_Import(); + +// add it to the import page! +register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into the new native tagging structure.'), array($stp_import, 'dispatch')); +?> \ No newline at end of file diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php index 2d2b145e..1fe54c8c 100644 --- a/wp-admin/import/textpattern.php +++ b/wp-admin/import/textpattern.php @@ -2,18 +2,6 @@ /** Add These Functions to make our lives easier **/ -if(!function_exists('get_catbynicename')) -{ - function get_catbynicename($category_nicename) - { - global $wpdb; - - $cat_id -= 0; // force numeric - $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); - - return $name; - } -} if(!function_exists('get_comment_count')) { @@ -38,14 +26,14 @@ if(!function_exists('link_exists')) **/ class Textpattern_Import { - function header() + 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() + function footer() { echo '
    '; } @@ -317,6 +305,8 @@ class Textpattern_Import { 'post_name' => $url_title, 'comment_count' => $comments_count) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } else { @@ -333,13 +323,19 @@ class Textpattern_Import { 'post_name' => $url_title, 'comment_count' => $comments_count) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } $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; } + $category1 = get_category_by_slug($Category1); + $category1 = $category1->term_id; + $category2 = get_category_by_slug($Category2); + $category2 = $category1->term_id; + if($cat1 = $category1) { $cats[1] = $cat1; } + if($cat2 = $category2) { $cats[2] = $cat2; } if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } @@ -506,7 +502,9 @@ class Textpattern_Import { { // Post Import $posts = $this->get_txp_posts(); - $this->posts2wp($posts); + $result = $this->posts2wp($posts); + if ( is_wp_error( $result ) ) + return $result; echo '
    '; wp_nonce_field('import-textpattern'); @@ -559,11 +557,11 @@ class Textpattern_Import { { 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 '

    '.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.'), get_bloginfo( 'wpurl' ) . '/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 '

    '.__('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').'

    '; + echo '

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

    '; } function db_form() @@ -646,7 +644,9 @@ class Textpattern_Import { $this->import_users(); break; case 3 : - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; case 4 : $this->import_comments(); diff --git a/wp-admin/import/utw.php b/wp-admin/import/utw.php new file mode 100644 index 00000000..120f50cb --- /dev/null +++ b/wp-admin/import/utw.php @@ -0,0 +1,276 @@ +'; + echo '

    '.__('Import Ultimate Tag Warrior').'

    '; + echo '

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

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

    '.__('Howdy! This imports tags from an existing Ultimate Tag Warrior 3 installation into this blog using the new WordPress native tagging structure.').'

    '; + echo '

    '.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'

    '; + echo '

    '.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'

    '; + echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; + echo ''; + echo '

    '; + echo ''; + echo '
    '; + } + + + function dispatch () { + if ( empty( $_GET['step'] ) ) { + $step = 0; + } else { + $step = (int) $_GET['step']; + } + + if ( $step > 1 ) + check_admin_referer('import-utw'); + + // load the header + $this->header(); + + switch ( $step ) { + case 0 : + $this->greet(); + break; + case 1 : + $this->import_tags(); + break; + case 2 : + $this->import_posts(); + break; + case 3: + $this->import_t2p(); + break; + case 4: + $this->cleanup_import(); + break; + } + + // load the footer + $this->footer(); + } + + + function import_tags ( ) { + echo '
    '; + echo '

    '.__('Reading UTW Tags…').'

    '; + + $tags = $this->get_utw_tags(); + + // if we didn't get any tags back, that's all there is folks! + if ( !is_array($tags) ) { + echo '

    ' . __('No Tags Found!') . '

    '; + return false; + } + else { + + // if there's an existing entry, delete it + if ( get_option('utwimp_tags') ) { + delete_option('utwimp_tags'); + } + + add_option('utwimp_tags', $tags); + + + $count = count($tags); + + echo '

    ' . sprintf( __('Done! %s tags were read.'), $count ) . '

    '; + echo '

    ' . __('The following tags were found:') . '

    '; + + echo '
      '; + + foreach ( $tags as $tag_id => $tag_name ) { + + echo '
    • ' . $tag_name . '
    • '; + + } + + echo '
    '; + + echo '
    '; + + echo '

    ' . __('If you don’t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '

    '; + + + } + + echo '
    '; + wp_nonce_field('import-utw'); + echo '

    '; + echo '
    '; + echo '
    '; + } + + + function import_posts ( ) { + echo '
    '; + echo '

    '.__('Reading UTW Post Tags…').'

    '; + + // read in all the UTW tag -> post settings + $posts = $this->get_utw_posts(); + + // if we didn't get any tags back, that's all there is folks! + if ( !is_array($posts) ) { + echo '

    ' . __('No posts were found to have tags!') . '

    '; + return false; + } + else { + + // if there's an existing entry, delete it + if ( get_option('utwimp_posts') ) { + delete_option('utwimp_posts'); + } + + add_option('utwimp_posts', $posts); + + + $count = count($posts); + + echo '

    ' . sprintf( __('Done! %s tag to post relationships were read.'), $count ) . '

    '; + + } + + echo '
    '; + wp_nonce_field('import-utw'); + echo '

    '; + echo '
    '; + echo '
    '; + + } + + + function import_t2p ( ) { + + echo '
    '; + echo '

    '.__('Adding Tags to Posts…').'

    '; + + // run that funky magic! + $tags_added = $this->tag2post(); + + echo '

    ' . sprintf( __('Done! %s tags were added!'), $tags_added ) . '

    '; + + echo '
    '; + wp_nonce_field('import-utw'); + echo '

    '; + echo '
    '; + echo '
    '; + + } + + + function get_utw_tags ( ) { + + global $wpdb; + + // read in all the tags from the UTW tags table: should be wp_tags + $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags"; + + $tags = $wpdb->get_results($tags_query); + + // rearrange these tags into something we can actually use + foreach ( $tags as $tag ) { + + $new_tags[$tag->tag_id] = $tag->tag; + + } + + return $new_tags; + + } + + function get_utw_posts ( ) { + + global $wpdb; + + // read in all the posts from the UTW post->tag table: should be wp_post2tag + $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag"; + + $posts = $wpdb->get_results($posts_query); + + return $posts; + + } + + + function tag2post ( ) { + + // get the tags and posts we imported in the last 2 steps + $tags = get_option('utwimp_tags'); + $posts = get_option('utwimp_posts'); + + // null out our results + $tags_added = 0; + + // loop through each post and add its tags to the db + foreach ( $posts as $this_post ) { + + $the_post = (int) $this_post->post_id; + $the_tag = (int) $this_post->tag_id; + + // what's the tag name for that id? + $the_tag = $tags[$the_tag]; + + // screw it, just try to add the tag + wp_add_post_tags($the_post, $the_tag); + + $tags_added++; + + } + + // that's it, all posts should be linked to their tags properly, pending any errors we just spit out! + return $tags_added; + + + } + + + function cleanup_import ( ) { + + delete_option('utwimp_tags'); + delete_option('utwimp_posts'); + + $this->done(); + + } + + + function done ( ) { + + echo '
    '; + echo '

    '.__('Import Complete!').'

    '; + + echo '

    ' . __('OK, so we lied about this being a 5-step program! You’re done!') . '

    '; + + echo '

    ' . __('Now wasn’t that easy?') . '

    '; + + echo '
    '; + + } + + + function UTW_Import ( ) { + + // Nothing. + + } + +} + + +// create the import object +$utw_import = new UTW_Import(); + +// add it to the import page! +register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into the new native tagging structure.'), array($utw_import, 'dispatch')); + +?> diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php new file mode 100644 index 00000000..d15f3a43 --- /dev/null +++ b/wp-admin/import/wordpress.php @@ -0,0 +1,489 @@ + XML fragment, [1] => New post ID] + var $file; + var $id; + var $mtnames = array (); + var $newauthornames = array (); + var $j = -1; + + function header() { + echo '
    '; + 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 '
    '; + echo '

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

    '; + echo '

    '.__('Choose a WordPress WXR file to upload, then click Upload file and import.').'

    '; + wp_import_upload_form("admin.php?import=wordpress&step=1"); + echo '
    '; + } + + function get_tag( $string, $tag ) { + global $wpdb; + preg_match("|<$tag.*?>(.*?)|is", $string, $return); + $return = preg_replace('|^$|s', '$1', $return[1]); + $return = $wpdb->escape( trim( $return ) ); + return $return; + } + + function users_form($n) { + global $wpdb, $testing; + $users = $wpdb->get_results("SELECT user_login FROM $wpdb->users ORDER BY user_login"); +?> + mtnames))) { //a new mt author name is found + ++ $this->j; + $this->mtnames[$this->j] = $author; //add that new mt author name to an array + $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user + if (!$user_id) { //banging my head against the desk now. + if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname + $user_id = wp_create_user($author, $pass); + $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank. + } else { + $user_id = wp_create_user($this->newauthornames[$this->j], $pass); + } + } else { + return $user_id; // return pre-existing wp username if it exists + } + } else { + $key = array_search($author, $this->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); + + $this->posts = array(); + $this->categories = array(); + $this->tags = array(); + $num = 0; + $doing_entry = false; + + $fp = fopen($this->file, 'r'); + if ($fp) { + while ( !feof($fp) ) { + $importline = rtrim(fgets($fp)); + + if ( false !== strpos($importline, '') ) { + preg_match('|(.*?)|is', $importline, $category); + $this->categories[] = $category[1]; + continue; + } + if ( false !== strpos($importline, '') ) { + preg_match('|(.*?)|is', $importline, $tag); + $this->tags[] = $tag[1]; + continue; + } + if ( false !== strpos($importline, '') ) { + $this->posts[$num] = ''; + $doing_entry = true; + continue; + } + if ( false !== strpos($importline, '') ) { + $num++; + $doing_entry = false; + continue; + } + if ( $doing_entry ) { + $this->posts[$num] .= $importline . "\n"; + } + } + + foreach ($this->posts as $post) { + $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); + if ($post_ID) { + $this->posts_processed[$post_ID][0] = &$post; + $this->posts_processed[$post_ID][1] = 0; + } + } + + fclose($fp); + } + } + + 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['user'] as $key => $line) { + $newname = trim(stripslashes($line)); + if ($newname == '') + $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form. + array_push($formnames, "$newname"); + } // $formnames is the array with the form entered names + + 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 '
      '; + wp_nonce_field('import-wordpress'); + $j = -1; + foreach ($authors as $author) { + ++ $j; + echo '
    1. '.__('Current author:').' '.$author.'
      '.sprintf(__('Create user %1$s or map to existing'), '
      '); + $this->users_form($j); + echo '
    2. '; + } + + echo ''.'
      '; + echo '
      '; + echo '
    '; + + } + + function select_authors() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo '

    '.__('Sorry, there has been an error.').'

    '; + echo '

    ' . $file['error'] . '

    '; + return; + } + $this->file = $file['file']; + $this->id = (int) $file['id']; + + $this->get_entries(); + $this->wp_authors_form(); + } + + function process_categories() { + global $wpdb; + + $cat_names = (array) get_terms('category', 'fields=names'); + + while ( $c = array_shift($this->categories) ) { + $cat_name = trim($this->get_tag( $c, 'wp:cat_name' )); + + // If the category exists we leave it alone + if ( in_array($cat_name, $cat_names) ) + continue; + + $category_nicename = $this->get_tag( $c, 'wp:category_nicename' ); + $posts_private = (int) $this->get_tag( $c, 'wp:posts_private' ); + $links_private = (int) $this->get_tag( $c, 'wp:links_private' ); + + $parent = $this->get_tag( $c, 'wp:category_parent' ); + + if ( empty($parent) ) + $category_parent = '0'; + else + $category_parent = category_exists($parent); + + $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name'); + + $cat_ID = wp_insert_category($catarr); + } + } + + function process_tags() { + global $wpdb; + + $tag_names = (array) get_terms('post_tag', 'fields=names'); + + while ( $c = array_shift($this->tags) ) { + $tag_name = trim($this->get_tag( $c, 'wp:tag_name' )); + + // If the category exists we leave it alone + if ( in_array($tag_name, $tag_names) ) + continue; + + $slug = $this->get_tag( $c, 'wp:tag_slug' ); + $description = $this->get_tag( $c, 'wp:tag_description' ); + + $tagarr = compact('slug', 'description'); + + $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr); + } + } + + function process_posts() { + $i = -1; + echo '
      '; + + foreach ($this->posts as $post) { + $result = $this->process_post($post); + if ( is_wp_error( $result ) ) + return $result; + } + + echo '
    '; + + wp_import_cleanup($this->id); + + echo '

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

    '; + } + + function process_post($post) { + global $wpdb; + + $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); + if ( $post_ID && !empty($this->posts_processed[$post_ID][1]) ) // Processed already + return 0; + + // 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_name = $this->get_tag( $post, 'wp:post_name' ); + $post_parent = $this->get_tag( $post, 'wp:post_parent' ); + $menu_order = $this->get_tag( $post, 'wp:menu_order' ); + $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 = 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, $tags); + $tags = $tags[1]; + + $tag_index = 0; + foreach ($tags as $tag) { + $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array (''), '', $tag))); + $tag_index++; + } + + preg_match_all('|(.*?)|is', $post, $categories); + $categories = $categories[1]; + + $cat_index = 0; + foreach ($categories as $category) { + $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array (''), '', $category))); + $cat_index++; + } + + if ($post_id = post_exists($post_title, '', $post_date)) { + echo '
  • '; + printf(__('Post %s already exists.'), stripslashes($post_title)); + } else { + + // If it has parent, process parent first. + $post_parent = (int) $post_parent; + if ($parent = $this->posts_processed[$post_parent]) { + if (!$parent[1]) { + $result = $this->process_post($parent[0]); // If not yet, process the parent first. + if ( is_wp_error( $result ) ) + return $result; + } + $post_parent = $parent[1]; // New ID of the parent; + } + + echo '
  • '; + 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', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type'); + $comment_post_ID = $post_id = wp_insert_post($postdata); + if ( is_wp_error( $post_id ) ) + return $post_id; + + // Memorize old and new ID. + if ( $post_id && $post_ID && $this->posts_processed[$post_ID] ) + $this->posts_processed[$post_ID][1] = $post_id; // New ID. + + // Add categories. + if (count($categories) > 0) { + $post_cats = array(); + foreach ($categories as $category) { + $slug = sanitize_term_field('slug', $category, 0, 'category', 'db'); + $cat = get_term_by('slug', $slug, 'category'); + $cat_ID = 0; + if ( ! empty($cat) ) + $cat_ID = $cat->term_id; + if ($cat_ID == 0) { + $category = $wpdb->escape($category); + $cat_ID = wp_insert_category(array('cat_name' => $category)); + } + $post_cats[] = $cat_ID; + } + wp_set_post_categories($post_id, $post_cats); + } + + // Add tags. + if (count($tags) > 0) { + $post_tags = array(); + foreach ($tags as $tag) { + $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); + $tag_obj = get_term_by('slug', $slug, 'post_tag'); + $tag_id = 0; + if ( ! empty($tag_obj) ) + $tag_id = $tag_obj->term_id; + if ( $tag_id == 0 ) { + $tag = $wpdb->escape($tag); + $tag_id = wp_insert_term($tag, 'post_tag'); + $tag_id = $tag_id['term_id']; + } + $post_tags[] = $tag_id; + } + wp_set_post_tags($post_id, $post_tags); + } + } + + // 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' ); + $value = stripslashes($value); // add_post_meta() will escape. + add_post_meta( $post_id, $key, $value ); + } } + } + + function import() { + $this->id = (int) $_GET['id']; + + $this->file = get_attached_file($this->id); + $this->get_authors_from_post(); + $this->get_entries(); + $this->process_categories(); + $this->process_tags(); + $result = $this->process_posts(); + if ( is_wp_error( $result ) ) + return $result; + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + check_admin_referer('import-upload'); + $this->select_authors(); + break; + case 2: + check_admin_referer('import-wordpress'); + $result = $this->import(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); + break; + } + $this->footer(); + } + + function WP_Import() { + // Nothing. + } +} + +$wp_import = new WP_Import(); + +register_importer('wordpress', 'WordPress', __('Import posts, comments, custom fields, pages, and categories from a WordPress export file'), array ($wp_import, 'dispatch')); + +?> diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php new file mode 100644 index 00000000..d38e17a1 --- /dev/null +++ b/wp-admin/import/wp-cat2tag.php @@ -0,0 +1,212 @@ +'; + print '

    ' . __('Convert Categories to Tags') . '

    '; + } + + function footer() { + print ''; + } + + function populate_all_categories() { + global $wpdb; + + $categories = get_categories('get=all'); + foreach ( $categories as $category ) { + if ( !tag_exists($wpdb->escape($category->name)) ) + $this->all_categories[] = $category; + } + } + + function welcome() { + $this->populate_all_categories(); + + print '
    '; + + if (count($this->all_categories) > 0) { + print '

    ' . __('Howdy! This converter allows you to selectively convert existing categories to tags. To get started, check the checkboxes of the categories you wish to be converted, then click the Convert button.') . '

    '; + print '

    ' . __('Keep in mind that if you convert a category with child categories, those child categories get their parent setting removed, so they\'re in the root.') . '

    '; + + $this->categories_form(); + } else { + print '

    '.__('You have no categories to convert!').'

    '; + } + + print '
    '; + } + + function categories_form() { + print '
    '; + wp_nonce_field('import-cat2tag'); + print '
      '; + + $hier = _get_term_hierarchy('category'); + + foreach ($this->all_categories as $category) { + $category = sanitize_term( $category, 'category', 'display' ); + + if ((int) $category->parent == 0) { + print '
    • '; + + if (isset($hier[$category->term_id])) { + $this->_category_children($category, $hier); + } + + print '
    • '; + } + } + + print '
    '; + + print '

    '; + print '
    '; + } + + function _category_children($parent, $hier) { + print '
      '; + + foreach ($hier[$parent->term_id] as $child_id) { + $child =& get_category($child_id); + + print '
    • '; + + if (isset($hier[$child->term_id])) { + $this->_category_children($child, $hier); + } + + print '
    • '; + } + + print '
    '; + } + + function _category_exists($cat_id) { + global $wpdb; + + $cat_id = (int) $cat_id; + + $maybe_exists = category_exists($cat_id); + + if ( $maybe_exists ) { + return true; + } else { + return false; + } + } + + function convert_them() { + global $wpdb; + + if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { + print '
    '; + print '

    ' . sprintf(__('Uh, oh. Something didn\'t work. Please try again.'), 'admin.php?import=wp-cat2tag') . '

    '; + print '
    '; + return; + } + + + if ( empty($this->categories_to_convert) ) + $this->categories_to_convert = $_POST['cats_to_convert']; + $hier = _get_term_hierarchy('category'); + + print '
      '; + + foreach ( (array) $this->categories_to_convert as $cat_id) { + $cat_id = (int) $cat_id; + + print '
    • ' . sprintf(__('Converting category #%s ... '), $cat_id); + + if (!$this->_category_exists($cat_id)) { + _e('Category doesn\'t exist!'); + } else { + $category =& get_category($cat_id); + + if ( tag_exists($wpdb->escape($category->name)) ) { + _e('Category is already a tag.'); + print '
    • '; + continue; + } + + // If the category is the default, leave category in place and create tag. + if ( get_option('default_category') == $category->term_id ) { + $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); + $id = $id['term_taxonomy_id']; + $posts = get_objects_in_term($category->term_id, 'category'); + foreach ( $posts as $post ) { + if ( !$wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") ) + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')"); + clean_post_cache($post); + } + } else { + $tt_ids = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); + if ( $tt_ids ) { + $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); + foreach ( (array) $posts as $post ) + clean_post_cache($post); + } + + // Change the category to a tag. + $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'"); + + $terms = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); + foreach ( (array) $terms as $term ) + clean_category_cache($term); + + // Set all parents to 0 (root-level) if their parent was the converted tag + $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'"); + } + // Clean the cache + clean_category_cache($category->term_id); + + _e('Converted successfully.'); + } + + print ''; + } + + print '
    '; + } + + function init() { + + $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; + + $this->header(); + + if (!current_user_can('manage_categories')) { + print '
    '; + print '

    ' . __('Cheatin’ uh?') . '

    '; + print '
    '; + } else { + if ( $step > 1 ) + check_admin_referer('import-cat2tag'); + + switch ($step) { + case 1 : + $this->welcome(); + break; + + case 2 : + $this->convert_them(); + break; + } + } + + $this->footer(); + } + + function WP_Categories_to_Tags() { + // Do nothing. + } +} + +$wp_cat2tag_importer = new WP_Categories_to_Tags(); + +register_importer('wp-cat2tag', __('Categories to Tags Converter'), __('Convert existing categories to tags, selectively.'), array(&$wp_cat2tag_importer, 'init')); + +?> diff --git a/wp-admin/includes/admin.php b/wp-admin/includes/admin.php new file mode 100644 index 00000000..fc50709a --- /dev/null +++ b/wp-admin/includes/admin.php @@ -0,0 +1,19 @@ + diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php new file mode 100644 index 00000000..35cc9c9d --- /dev/null +++ b/wp-admin/includes/bookmark.php @@ -0,0 +1,177 @@ +link_url = clean_url( $_GET['linkurl']); + else + $link->link_url = ''; + + if ( isset( $_GET['name'] ) ) + $link->link_name = attribute_escape( $_GET['name']); + else + $link->link_name = ''; + + $link->link_visible = 'Y'; + + return $link; +} + +function wp_delete_link($link_id) { + global $wpdb; + + do_action('delete_link', $link_id); + + wp_delete_object_term_relationships($link_id, 'link_category'); + + $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); + + do_action('deleted_link', $link_id); + + return true; +} + +function wp_get_link_cats($link_id = 0) { + + $cats = wp_get_object_terms($link_id, 'link_category', 'fields=ids'); + + return array_unique($cats); +} + +function get_link_to_edit( $link_id ) { + return get_link( $link_id, OBJECT, 'edit' ); +} + +function wp_insert_link($linkdata) { + global $wpdb, $current_user; + + $defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 ); + + $linkdata = wp_parse_args($linkdata, $defaults); + $linkdata = sanitize_bookmark($linkdata, 'db'); + + extract($linkdata, EXTR_SKIP); + + $update = false; + + if ( !empty($link_id) ) + $update = true; + + if ( trim( $link_name ) == '' ) + return 0; + + if ( trim( $link_url ) == '' ) + return 0; + + if ( empty($link_rating) ) + $link_rating = 0; + + if ( empty($link_image) ) + $link_image = ''; + + if ( empty($link_target) ) + $link_target = ''; + + if ( empty($link_visible) ) + $link_visible = 'Y'; + + if ( empty($link_owner) ) + $link_owner = $current_user->id; + + if ( empty($link_notes) ) + $link_notes = ''; + + if ( empty($link_description) ) + $link_description = ''; + + if ( empty($link_rss) ) + $link_rss = ''; + + if ( empty($link_rel) ) + $link_rel = ''; + + // Make sure we set a valid category + if (0 == count($link_category) || !is_array($link_category)) { + $link_category = array(get_option('default_link_category')); + } + + if ( $update ) { + $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url', + link_name='$link_name', link_image='$link_image', + link_target='$link_target', + link_visible='$link_visible', link_description='$link_description', + link_rating='$link_rating', link_rel='$link_rel', + link_notes='$link_notes', link_rss = '$link_rss' + WHERE link_id='$link_id'"); + } else { + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')"); + $link_id = (int) $wpdb->insert_id; + } + + wp_set_link_cats($link_id, $link_category); + + if ( $update ) + do_action('edit_link', $link_id); + else + do_action('add_link', $link_id); + + return $link_id; +} + +function wp_set_link_cats($link_id = 0, $link_categories = array()) { + // If $link_categories isn't already an array, make it one: + if (!is_array($link_categories) || 0 == count($link_categories)) + $link_categories = array(get_option('default_link_category')); + + $link_categories = array_map('intval', $link_categories); + $link_categories = array_unique($link_categories); + + wp_set_object_terms($link_id, $link_categories, 'link_category'); +} // wp_set_link_cats() + +function wp_update_link($linkdata) { + global $wpdb; + + $link_id = (int) $linkdata['link_id']; + + $link = get_link($link_id, ARRAY_A); + + // Escape data pulled from DB. + $link = add_magic_quotes($link); + + // Passed link category list overwrites existing category list if not empty. + if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) + && 0 != count($linkdata['link_category']) ) + $link_cats = $linkdata['link_category']; + else + $link_cats = $link['link_category']; + + // Merge old and new fields with new fields overwriting old ones. + $linkdata = array_merge($link, $linkdata); + $linkdata['link_category'] = $link_cats; + + return wp_insert_link($linkdata); +} + +?> \ No newline at end of file diff --git a/wp-admin/includes/comment.php b/wp-admin/includes/comment.php new file mode 100644 index 00000000..ae0d1d96 --- /dev/null +++ b/wp-admin/includes/comment.php @@ -0,0 +1,68 @@ +get_var("SELECT comment_post_ID FROM $wpdb->comments + WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'"); +} + +function edit_comment() { + global $user_ID; + + $comment_ID = (int) $_POST['comment_ID']; + $comment_post_ID = (int) $_POST['comment_post_ID']; + + if (!current_user_can( 'edit_post', $comment_post_ID )) + wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' )); + + $_POST['comment_author'] = $_POST['newcomment_author']; + $_POST['comment_author_email'] = $_POST['newcomment_author_email']; + $_POST['comment_author_url'] = $_POST['newcomment_author_url']; + $_POST['comment_approved'] = $_POST['comment_status']; + $_POST['comment_content'] = $_POST['content']; + $_POST['comment_ID'] = (int) $_POST['comment_ID']; + + if (!empty ( $_POST['edit_date'] ) ) { + $aa = $_POST['aa']; + $mm = $_POST['mm']; + $jj = $_POST['jj']; + $hh = $_POST['hh']; + $mn = $_POST['mn']; + $ss = $_POST['ss']; + $jj = ($jj > 31 ) ? 31 : $jj; + $hh = ($hh > 23 ) ? $hh -24 : $hh; + $mn = ($mn > 59 ) ? $mn -60 : $mn; + $ss = ($ss > 59 ) ? $ss -60 : $ss; + $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; + } + + wp_update_comment( $_POST); +} + +function get_comment_to_edit( $id ) { + if ( !$comment = get_comment($id) ) + return false; + + $comment->comment_ID = (int) $comment->comment_ID; + $comment->comment_post_ID = (int) $comment->comment_post_ID; + + $comment->comment_content = format_to_edit( $comment->comment_content ); + $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content); + + $comment->comment_author = format_to_edit( $comment->comment_author ); + $comment->comment_author_email = format_to_edit( $comment->comment_author_email ); + $comment->comment_author_url = clean_url($comment->comment_author_url); + $comment->comment_author_url = format_to_edit( $comment->comment_author_url ); + + return $comment; +} + +function get_pending_comments_num( $post_id ) { + global $wpdb; + $post_id = (int) $post_id; + $pending = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = $post_id AND comment_approved = '0'" ); + return $pending; +} + +?> \ No newline at end of file diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php new file mode 100644 index 00000000..c201359b --- /dev/null +++ b/wp-admin/includes/file.php @@ -0,0 +1,192 @@ + __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ), + // Deprecated files + 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' )); +function get_file_description( $file ) { + global $wp_file_descriptions; + + if ( isset( $wp_file_descriptions[basename( $file )] ) ) { + return $wp_file_descriptions[basename( $file )]; + } + elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) { + $template_data = implode( '', file( ABSPATH . $file ) ); + if ( preg_match( "|Template Name:(.*)|i", $template_data, $name )) + return $name[1]; + } + + return basename( $file ); +} + +function get_home_path() { + $home = get_option( 'home' ); + if ( $home != '' && $home != get_option( 'siteurl' ) ) { + $home_path = parse_url( $home ); + $home_path = $home_path['path']; + $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); + $home_path = trailingslashit( $root.$home_path ); + } else { + $home_path = ABSPATH; + } + + return $home_path; +} + +function get_real_file_to_edit( $file ) { + if ('index.php' == $file || '.htaccess' == $file ) { + $real_file = get_home_path().$file; + } else { + $real_file = ABSPATH.$file; + } + + return $real_file; +} + +function validate_file( $file, $allowed_files = '' ) { + if ( false !== strpos( $file, '..' )) + return 1; + + if ( false !== strpos( $file, './' )) + return 1; + + if (':' == substr( $file, 1, 1 )) + return 2; + + if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) + return 3; + + return 0; +} + +function validate_file_to_edit( $file, $allowed_files = '' ) { + $file = stripslashes( $file ); + + $code = validate_file( $file, $allowed_files ); + + if (!$code ) + return $file; + + switch ( $code ) { + case 1 : + wp_die( __('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' )); + + case 2 : + wp_die( __('Sorry, can’t call files with their real path.' )); + + case 3 : + wp_die( __('Sorry, that file cannot be edited.' )); + } +} + +// array wp_handle_upload ( array &file [, array overrides] ) +// file: reference to a single element of $_FILES. Call the function once for each uploaded file. +// overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). +// On success, returns an associative array of file attributes. +// On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). +function wp_handle_upload( &$file, $overrides = false ) { + // The default error handler. + if (! function_exists( 'wp_handle_upload_error' ) ) { + function wp_handle_upload_error( &$file, $message ) { + return array( 'error'=>$message ); + } + } + + // You may define your own function and pass the name in $overrides['upload_error_handler'] + $upload_error_handler = 'wp_handle_upload_error'; + + // $_POST['action'] must be set and its value must equal $overrides['action'] or this: + $action = 'wp_handle_upload'; + + // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. + $upload_error_strings = array( false, + __( "The uploaded file exceeds the 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. This error could also be caused by uploads being disabled in your php.ini.' )); + + // A properly uploaded file will pass this test. There should be no reason to override this one. + if (! @ is_uploaded_file( $file['tmp_name'] ) ) + return $upload_error_handler( $file, __( 'Specified file failed upload test.' )); + + // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. + if ( $test_type ) { + $wp_filetype = wp_check_filetype( $file['name'], $mimes ); + + extract( $wp_filetype ); + + if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) ) + return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' )); + + if ( !$ext ) + $ext = ltrim(strrchr($file['name'], '.'), '.'); + } + + // A writable uploads dir will pass this test. Again, there's no point overriding this one. + if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) + return $upload_error_handler( $file, $uploads['error'] ); + + // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. + if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) { + $filename = $unique_filename_callback( $uploads['path'], $file['name'] ); + } else { + $number = ''; + $filename = str_replace( '#', '_', $file['name'] ); + $filename = str_replace( array( '\\', "'" ), '', $filename ); + if ( empty( $ext) ) + $ext = ''; + else + $ext = ".$ext"; + while ( file_exists( $uploads['path'] . "/$filename" ) ) { + if ( '' == "$number$ext" ) + $filename = $filename . ++$number . $ext; + else + $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); + } + $filename = str_replace( $ext, '', $filename ); + $filename = sanitize_title_with_dashes( $filename ) . $ext; + } + + // Move the file to the uploads dir + $new_file = $uploads['path'] . "/$filename"; + if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) + wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['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; +} + +?> diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php new file mode 100644 index 00000000..ec4466e5 --- /dev/null +++ b/wp-admin/includes/image.php @@ -0,0 +1,192 @@ + 4 / 3 ) + return array( 128, (int) ($height / $width * 128 )); + else + return array( (int) ($width / $height * 96 ), 96 ); +} + +function wp_create_thumbnail( $file, $max_side, $effect = '' ) { + + // 1 = GIF, 2 = JPEG, 3 = PNG + + if ( file_exists( $file ) ) { + $type = getimagesize( $file ); + + // if the associated function doesn't exist - then it's not + // handle. duh. i hope. + + if (!function_exists( 'imagegif' ) && $type[2] == 1 ) { + $error = __( 'Filetype not supported. Thumbnail not created.' ); + } + elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) { + $error = __( 'Filetype not supported. Thumbnail not created.' ); + } + elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) { + $error = __( 'Filetype not supported. Thumbnail not created.' ); + } else { + + // create the initial copy from the original file + if ( $type[2] == 1 ) { + $image = imagecreatefromgif( $file ); + } + elseif ( $type[2] == 2 ) { + $image = imagecreatefromjpeg( $file ); + } + elseif ( $type[2] == 3 ) { + $image = imagecreatefrompng( $file ); + } + + if ( function_exists( 'imageantialias' )) + imageantialias( $image, TRUE ); + + $image_attr = getimagesize( $file ); + + // figure out the longest side + + if ( $image_attr[0] > $image_attr[1] ) { + $image_width = $image_attr[0]; + $image_height = $image_attr[1]; + $image_new_width = $max_side; + + $image_ratio = $image_width / $image_new_width; + $image_new_height = $image_height / $image_ratio; + //width is > height + } else { + $image_width = $image_attr[0]; + $image_height = $image_attr[1]; + $image_new_height = $max_side; + + $image_ratio = $image_height / $image_new_height; + $image_new_width = $image_width / $image_ratio; + //height > width + } + + $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); + @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] ); + + // If no filters change the filename, we'll do a default transformation. + if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) ) + $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail' . '$1', basename( $file ), 1 ); + + $thumbpath = str_replace( basename( $file ), $thumb, $file ); + + // move the thumbnail to its final destination + if ( $type[2] == 1 ) { + if (!imagegif( $thumbnail, $thumbpath ) ) { + $error = __( "Thumbnail path invalid" ); + } + } + elseif ( $type[2] == 2 ) { + if (!imagejpeg( $thumbnail, $thumbpath ) ) { + $error = __( "Thumbnail path invalid" ); + } + } + elseif ( $type[2] == 3 ) { + if (!imagepng( $thumbnail, $thumbpath ) ) { + $error = __( "Thumbnail path invalid" ); + } + } + + } + } else { + $error = __( 'File not found' ); + } + + if (!empty ( $error ) ) { + return $error; + } else { + return apply_filters( 'wp_create_thumbnail', $thumbpath ); + } +} + +function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { + if ( ctype_digit( $src_file ) ) // Handle int as attachment ID + $src_file = get_attached_file( $src_file ); + + $src = wp_load_image( $src_file ); + + if ( !is_resource( $src )) + return $src; + + $dst = imagecreatetruecolor( $dst_w, $dst_h ); + + if ( $src_abs ) { + $src_w -= $src_x; + $src_h -= $src_y; + } + + if (function_exists('imageantialias')) + imageantialias( $dst, true ); + + imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); + + if ( !$dst_file ) + $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file ); + + $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); + + if ( imagejpeg( $dst, $dst_file ) ) + return $dst_file; + else + return false; +} + +function wp_generate_attachment_metadata( $attachment_id, $file ) { + $attachment = get_post( $attachment_id ); + + $metadata = array(); + if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) { + $imagesize = getimagesize($file); + $metadata['width'] = $imagesize['0']; + $metadata['height'] = $imagesize['1']; + list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']); + $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; + $metadata['file'] = $file; + + $max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file ); + + if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) { + $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file ); + $thumb = wp_create_thumbnail( $file, $max_side ); + + if ( @file_exists($thumb) ) + $metadata['thumb'] = basename($thumb); + } + } + return apply_filters( 'wp_generate_attachment_metadata', $metadata ); +} + +function wp_load_image( $file ) { + if ( ctype_digit( $file ) ) + $file = get_attached_file( $file ); + + if ( !file_exists( $file ) ) + return sprintf(__("File '%s' doesn't exist?"), $file); + + if ( ! function_exists('imagecreatefromstring') ) + return __('The GD image library is not installed.'); + + $contents = file_get_contents( $file ); + + $image = imagecreatefromstring( $contents ); + + if ( !is_resource( $image ) ) + return sprintf(__("File '%s' is not an image."), $file); + + return $image; +} + +function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { + if ( $height <= $hmax && $width <= $wmax ) + return array( $width, $height); + elseif ( $width / $height > $wmax / $hmax ) + return array( $wmax, (int) ($height / $width * $wmax )); + else + return array( (int) ($width / $height * $hmax ), $hmax ); +} + +?> diff --git a/wp-admin/includes/import.php b/wp-admin/includes/import.php new file mode 100644 index 00000000..9835bb14 --- /dev/null +++ b/wp-admin/includes/import.php @@ -0,0 +1,45 @@ + false, 'test_type' => false ); + $file = wp_handle_upload( $_FILES['import'], $overrides ); + + if ( isset( $file['error'] ) ) + return $file; + + $url = $file['url']; + $type = $file['type']; + $file = addslashes( $file['file'] ); + $filename = basename( $file ); + + // Construct the object array + $object = array( 'post_title' => $filename, + 'post_content' => $url, + 'post_mime_type' => $type, + 'guid' => $url + ); + + // Save the data + $id = wp_insert_attachment( $object, $file ); + + return array( 'file' => $file, 'id' => $id ); +} + +?> diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php new file mode 100644 index 00000000..5902c4e8 --- /dev/null +++ b/wp-admin/includes/misc.php @@ -0,0 +1,177 @@ + $markerline ) { + if (strpos($markerline, '# BEGIN ' . $marker) !== false) + $state = false; + if ( $state ) { + if ( $n + 1 < count( $markerdata ) ) + fwrite( $f, "{$markerline}\n" ); + else + fwrite( $f, "{$markerline}" ); + } + if (strpos($markerline, '# END ' . $marker) !== false) { + fwrite( $f, "# BEGIN {$marker}\n" ); + if ( is_array( $insertion )) + foreach ( $insertion as $insertline ) + fwrite( $f, "{$insertline}\n" ); + fwrite( $f, "# END {$marker}\n" ); + $state = true; + $foundit = true; + } + } + } + if (!$foundit) { + fwrite( $f, "# BEGIN {$marker}\n" ); + foreach ( $insertion as $insertline ) + fwrite( $f, "{$insertline}\n" ); + fwrite( $f, "# END {$marker}\n" ); + } + fclose( $f ); + return true; + } else { + return false; + } +} + +/** + * Updates the htaccess file with the current rules if it is writable. + * + * Always writes to the file if it exists and is writable to ensure that we blank out old rules. + */ + +function save_mod_rewrite_rules() { + global $wp_rewrite; + + $home_path = get_home_path(); + $htaccess_file = $home_path.'.htaccess'; + + // If the file doesn't already exists check for write access to the directory and whether of not we have some rules. + // else check for write access to the file. + if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) { + if ( got_mod_rewrite() ) { + $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); + return insert_with_markers( $htaccess_file, 'WordPress', $rules ); + } + } + + return false; +} + +function update_recently_edited( $file ) { + $oldfiles = (array ) get_option( 'recently_edited' ); + if ( $oldfiles ) { + $oldfiles = array_reverse( $oldfiles ); + $oldfiles[] = $file; + $oldfiles = array_reverse( $oldfiles ); + $oldfiles = array_unique( $oldfiles ); + if ( 5 < count( $oldfiles )) + array_pop( $oldfiles ); + } else { + $oldfiles[] = $file; + } + update_option( 'recently_edited', $oldfiles ); +} + +// If siteurl or home changed, reset cookies and flush rewrite rules. +function update_home_siteurl( $old_value, $value ) { + global $wp_rewrite, $user_login, $user_pass_md5; + + if ( defined( "WP_INSTALLING" ) ) + return; + + // If home changed, write rewrite rules to new location. + $wp_rewrite->flush_rules(); + // Clear cookies for old paths. + wp_clearcookie(); + // Set cookies for new paths. + wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' )); +} + +add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); +add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); + +function url_shorten( $url ) { + $short_url = str_replace( 'http://', '', stripslashes( $url )); + $short_url = str_replace( 'www.', '', $short_url ); + if ('/' == substr( $short_url, -1 )) + $short_url = substr( $short_url, 0, -1 ); + if ( strlen( $short_url ) > 35 ) + $short_url = substr( $short_url, 0, 32 ).'...'; + return $short_url; +} + +function wp_reset_vars( $vars ) { + for ( $i=0; $i diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php new file mode 100644 index 00000000..e5911bda --- /dev/null +++ b/wp-admin/includes/plugin.php @@ -0,0 +1,382 @@ +'.$plugin.''; + } + + if ('' == $author_uri[1] ) { + $author = trim( $author_name[1] ); + } else { + $author = '' . trim( $author_name[1] ) . ''; + } + + return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version); +} + +function get_plugins() { + global $wp_plugins; + + if ( isset( $wp_plugins ) ) { + return $wp_plugins; + } + + $wp_plugins = array (); + $plugin_root = ABSPATH . PLUGINDIR; + + // Files in wp-content/plugins directory + $plugins_dir = @ opendir( $plugin_root); + if ( $plugins_dir ) { + while (($file = readdir( $plugins_dir ) ) !== false ) { + if ( substr($file, 0, 1) == '.' ) + continue; + if ( is_dir( $plugin_root.'/'.$file ) ) { + $plugins_subdir = @ opendir( $plugin_root.'/'.$file ); + if ( $plugins_subdir ) { + while (($subfile = readdir( $plugins_subdir ) ) !== false ) { + if ( substr($subfile, 0, 1) == '.' ) + continue; + if ( substr($subfile, -4) == '.php' ) + $plugin_files[] = "$file/$subfile"; + } + } + } else { + if ( substr($file, -4) == '.php' ) + $plugin_files[] = $file; + } + } + } + @closedir( $plugins_dir ); + @closedir( $plugins_subdir ); + + if ( !$plugins_dir || !$plugin_files ) + return $wp_plugins; + + foreach ( $plugin_files as $plugin_file ) { + if ( !is_readable( "$plugin_root/$plugin_file" ) ) + continue; + + $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" ); + + if ( empty ( $plugin_data['Name'] ) ) + continue; + + $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; + } + + uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); + + return $wp_plugins; +} + +// +// Menu +// + +function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { + global $menu, $admin_page_hooks; + + $file = plugin_basename( $file ); + + $menu[] = array ( $menu_title, $access_level, $file, $page_title ); + + $admin_page_hooks[$file] = sanitize_title( $menu_title ); + + $hookname = get_plugin_page_hookname( $file, '' ); + if (!empty ( $function ) && !empty ( $hookname )) + add_action( $hookname, $function ); + + return $hookname; +} + +function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { + global $submenu; + global $menu; + global $_wp_real_parent_file; + global $_wp_submenu_nopriv; + global $_wp_menu_nopriv; + + $file = plugin_basename( $file ); + + $parent = plugin_basename( $parent); + if ( isset( $_wp_real_parent_file[$parent] ) ) + $parent = $_wp_real_parent_file[$parent]; + + if ( !current_user_can( $access_level ) ) { + $_wp_submenu_nopriv[$parent][$file] = true; + return false; + } + + // If the parent doesn't already have a submenu, add a link to the parent + // as the first item in the submenu. If the submenu file is the same as the + // parent file someone is trying to link back to the parent manually. In + // this case, don't automatically add a link back to avoid duplication. + if (!isset( $submenu[$parent] ) && $file != $parent ) { + foreach ( $menu as $parent_menu ) { + if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) + $submenu[$parent][] = $parent_menu; + } + } + + $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title ); + + $hookname = get_plugin_page_hookname( $file, $parent); + if (!empty ( $function ) && !empty ( $hookname )) + add_action( $hookname, $function ); + + return $hookname; +} + +function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { + return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); +} + +function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { + return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); +} + +function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { + return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); +} + +function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { + if ( current_user_can('edit_users') ) + $parent = 'users.php'; + else + $parent = 'profile.php'; + return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function ); +} + +// +// Pluggable Menu Support -- Private +// + +function get_admin_page_parent() { + global $parent_file; + global $menu; + global $submenu; + global $pagenow; + global $plugin_page; + global $_wp_real_parent_file; + global $_wp_menu_nopriv; + global $_wp_submenu_nopriv; + + if ( !empty ( $parent_file ) ) { + if ( isset( $_wp_real_parent_file[$parent_file] ) ) + $parent_file = $_wp_real_parent_file[$parent_file]; + + return $parent_file; + } + + if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { + foreach ( $menu as $parent_menu ) { + if ( $parent_menu[2] == $plugin_page ) { + $parent_file = $plugin_page; + if ( isset( $_wp_real_parent_file[$parent_file] ) ) + $parent_file = $_wp_real_parent_file[$parent_file]; + return $parent_file; + } + } + if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { + $parent_file = $plugin_page; + if ( isset( $_wp_real_parent_file[$parent_file] ) ) + $parent_file = $_wp_real_parent_file[$parent_file]; + return $parent_file; + } + } + + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { + $parent_file = $pagenow; + if ( isset( $_wp_real_parent_file[$parent_file] ) ) + $parent_file = $_wp_real_parent_file[$parent_file]; + return $parent_file; + } + + foreach (array_keys( $submenu ) as $parent) { + foreach ( $submenu[$parent] as $submenu_array ) { + if ( isset( $_wp_real_parent_file[$parent] ) ) + $parent = $_wp_real_parent_file[$parent]; + if ( $submenu_array[2] == $pagenow ) { + $parent_file = $parent; + return $parent; + } else + if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { + $parent_file = $parent; + return $parent; + } + } + } + + $parent_file = ''; + return ''; +} + +function get_admin_page_title() { + global $title; + global $menu; + global $submenu; + global $pagenow; + global $plugin_page; + + if ( isset( $title ) && !empty ( $title ) ) { + return $title; + } + + $hook = get_plugin_page_hook( $plugin_page, $pagenow ); + + $parent = $parent1 = get_admin_page_parent(); + if ( empty ( $parent) ) { + foreach ( $menu as $menu_array ) { + if ( isset( $menu_array[3] ) ) { + if ( $menu_array[2] == $pagenow ) { + $title = $menu_array[3]; + return $menu_array[3]; + } else + if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { + $title = $menu_array[3]; + return $menu_array[3]; + } + } else { + $title = $menu_array[0]; + return $title; + } + } + } else { + foreach (array_keys( $submenu ) as $parent) { + foreach ( $submenu[$parent] as $submenu_array ) { + if ( isset( $plugin_page ) && + ($plugin_page == $submenu_array[2] ) && + (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) ) + ) { + $title = $submenu_array[3]; + return $submenu_array[3]; + } + + if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page + continue; + + if ( isset( $submenu_array[3] ) ) { + $title = $submenu_array[3]; + return $submenu_array[3]; + } else { + $title = $submenu_array[0]; + return $title; + } + } + } + } + + return $title; +} + +function get_plugin_page_hook( $plugin_page, $parent_page ) { + global $wp_filter; + + $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); + if ( isset( $wp_filter[$hook] )) + return $hook; + else + return null; +} + +function get_plugin_page_hookname( $plugin_page, $parent_page ) { + global $admin_page_hooks; + + $parent = get_admin_page_parent(); + + if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) { + if ( isset( $admin_page_hooks[$plugin_page] )) + $page_type = 'toplevel'; + else + if ( isset( $admin_page_hooks[$parent] )) + $page_type = $admin_page_hooks[$parent]; + } else + if ( isset( $admin_page_hooks[$parent_page] ) ) { + $page_type = $admin_page_hooks[$parent_page]; + } else { + $page_type = 'admin'; + } + + $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); + + return $page_type.'_page_'.$plugin_name; +} + +function user_can_access_admin_page() { + global $pagenow; + global $menu; + global $submenu; + global $_wp_menu_nopriv; + global $_wp_submenu_nopriv; + global $plugin_page; + + $parent = get_admin_page_parent(); + + if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) + return false; + + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) + return false; + + if ( empty( $parent) ) { + if ( isset( $_wp_menu_nopriv[$pagenow] ) ) + return false; + if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) + return false; + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) + return false; + foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { + if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) + return false; + if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) + return false; + } + return true; + } + + if ( isset( $submenu[$parent] ) ) { + foreach ( $submenu[$parent] as $submenu_array ) { + if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { + if ( current_user_can( $submenu_array[1] )) + return true; + else + return false; + } else if ( $submenu_array[2] == $pagenow ) { + if ( current_user_can( $submenu_array[1] )) + return true; + else + return false; + } + } + } + + foreach ( $menu as $menu_array ) { + if ( $menu_array[2] == $parent) { + if ( current_user_can( $menu_array[1] )) + return true; + else + return false; + } + } + + return true; +} + +?> diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php new file mode 100644 index 00000000..e27482c5 --- /dev/null +++ b/wp-admin/includes/post.php @@ -0,0 +1,471 @@ +post_date_gmt . ' +0000'); + // Keep autosave_interval in sync with autosave-js.php. + $delta = apply_filters( 'autosave_interval', 120 ) / 2; + if ( ($now - $then) < $delta ) + return $post_ID; + } + + // Rename. + $_POST['ID'] = (int) $_POST['post_ID']; + $_POST['post_content'] = $_POST['content']; + $_POST['post_excerpt'] = $_POST['excerpt']; + $_POST['post_parent'] = $_POST['parent_id']; + $_POST['to_ping'] = $_POST['trackback_url']; + + if (!empty ( $_POST['post_author_override'] ) ) { + $_POST['post_author'] = (int) $_POST['post_author_override']; + } else + if (!empty ( $_POST['post_author'] ) ) { + $_POST['post_author'] = (int) $_POST['post_author']; + } else { + $_POST['post_author'] = (int) $_POST['user_ID']; + } + + if ( $_POST['post_author'] != $_POST['user_ID'] ) { + if ( 'page' == $_POST['post_type'] ) { + if ( !current_user_can( 'edit_others_pages' ) ) + wp_die( __('You are not allowed to edit pages as this user.' )); + } else { + if ( !current_user_can( 'edit_others_posts' ) ) + wp_die( __('You are not allowed to edit posts as this user.' )); + + } + } + + // What to do based on which button they pressed + if ('' != $_POST['saveasdraft'] ) + $_POST['post_status'] = 'draft'; + if ('' != $_POST['saveasprivate'] ) + $_POST['post_status'] = 'private'; + if ('' != $_POST['publish'] ) + $_POST['post_status'] = 'publish'; + if ('' != $_POST['advanced'] ) + $_POST['post_status'] = 'draft'; + + if ( 'page' == $_POST['post_type'] ) { + if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' )) + $_POST['post_status'] = 'pending'; + } else { + if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' )) + $_POST['post_status'] = 'pending'; + } + + if (!isset( $_POST['comment_status'] )) + $_POST['comment_status'] = 'closed'; + + if (!isset( $_POST['ping_status'] )) + $_POST['ping_status'] = 'closed'; + + if (!empty ( $_POST['edit_date'] ) ) { + $aa = $_POST['aa']; + $mm = $_POST['mm']; + $jj = $_POST['jj']; + $hh = $_POST['hh']; + $mn = $_POST['mn']; + $ss = $_POST['ss']; + $jj = ($jj > 31 ) ? 31 : $jj; + $hh = ($hh > 23 ) ? $hh -24 : $hh; + $mn = ($mn > 59 ) ? $mn -60 : $mn; + $ss = ($ss > 59 ) ? $ss -60 : $ss; + $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; + $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" ); + } + + // Meta Stuff + if ( $_POST['meta'] ) { + foreach ( $_POST['meta'] as $key => $value ) + update_meta( $key, $value['key'], $value['value'] ); + } + + if ( $_POST['deletemeta'] ) { + foreach ( $_POST['deletemeta'] as $key => $value ) + delete_meta( $key ); + } + + add_meta( $post_ID ); + + wp_update_post( $_POST ); + + // Reunite any orphaned attachments with their parent + if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) + $draft_ids = array(); + if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) + _relocate_children( $draft_temp_id, $post_ID ); + + // Now that we have an ID we can fix any attachment anchor hrefs + _fix_attachment_links( $post_ID ); + + return $post_ID; +} + +// Default post information to use when populating the "Write Post" form. +function get_default_post_to_edit() { + if ( !empty( $_REQUEST['post_title'] ) ) + $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); + else if ( !empty( $_REQUEST['popuptitle'] ) ) { + $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); + $post_title = funky_javascript_fix( $post_title ); + } else { + $post_title = ''; + } + + if ( !empty( $_REQUEST['content'] ) ) + $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); + else if ( !empty( $post_title ) ) { + $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); + $text = funky_javascript_fix( $text); + $popupurl = clean_url($_REQUEST['popupurl']); + $post_content = ''.$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_option( 'default_comment_status' ); + $post->ping_status = get_option( 'default_ping_status' ); + $post->post_pingback = get_option( 'default_pingback_flag' ); + $post->post_category = get_option( 'default_category' ); + $post->post_content = apply_filters( 'default_content', $post_content); + $post->post_title = apply_filters( 'default_title', $post_title ); + $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt); + $post->page_template = 'default'; + $post->post_parent = 0; + $post->menu_order = 0; + + return $post; +} + +// Get an existing post and format it for editing. +function get_post_to_edit( $id ) { + + $post = get_post( $id, OBJECT, 'edit' ); + + if ( $post->post_type == 'page' ) + $post->page_template = get_post_meta( $id, '_wp_page_template', true ); + + return $post; +} + +function post_exists($title, $content = '', $post_date = '') { + global $wpdb; + + if (!empty ($post_date)) + $post_date = "AND post_date = '$post_date'"; + + if (!empty ($title)) + return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' $post_date"); + else + if (!empty ($content)) + return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date"); + + return 0; +} + +// Creates a new post from the "Write Post" form using $_POST information. +function wp_write_post() { + global $user_ID; + + if ( 'page' == $_POST['post_type'] ) { + if ( !current_user_can( 'edit_pages' ) ) + return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) ); + } else { + if ( !current_user_can( 'edit_posts' ) ) + return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) ); + } + + + // Check for autosave collisions + $temp_id = false; + if ( isset($_POST['temp_ID']) ) { + $temp_id = (int) $_POST['temp_ID']; + if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) + $draft_ids = array(); + foreach ( $draft_ids as $temp => $real ) + if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) + unset($draft_ids[$temp]); + + if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write + $_POST['post_ID'] = $draft_ids[$temp_id]; + unset($_POST['temp_ID']); + update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); + return edit_post(); + } + } + + // Rename. + $_POST['post_content'] = $_POST['content']; + $_POST['post_excerpt'] = $_POST['excerpt']; + $_POST['post_parent'] = $_POST['parent_id']; + $_POST['to_ping'] = $_POST['trackback_url']; + + if (!empty ( $_POST['post_author_override'] ) ) { + $_POST['post_author'] = (int) $_POST['post_author_override']; + } else { + if (!empty ( $_POST['post_author'] ) ) { + $_POST['post_author'] = (int) $_POST['post_author']; + } else { + $_POST['post_author'] = (int) $_POST['user_ID']; + } + + } + + if ( $_POST['post_author'] != $_POST['user_ID'] ) { + if ( 'page' == $_POST['post_type'] ) { + if ( !current_user_can( 'edit_others_pages' ) ) + return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); + } else { + if ( !current_user_can( 'edit_others_posts' ) ) + return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) ); + + } + } + + // What to do based on which button they pressed + if ('' != $_POST['saveasdraft'] ) + $_POST['post_status'] = 'draft'; + if ('' != $_POST['saveasprivate'] ) + $_POST['post_status'] = 'private'; + if ('' != $_POST['publish'] ) + $_POST['post_status'] = 'publish'; + if ('' != $_POST['advanced'] ) + $_POST['post_status'] = 'draft'; + + if ( 'page' == $_POST['post_type'] ) { + if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) + $_POST['post_status'] = 'pending'; + } else { + if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) ) + $_POST['post_status'] = 'pending'; + } + + if (!isset( $_POST['comment_status'] )) + $_POST['comment_status'] = 'closed'; + + if (!isset( $_POST['ping_status'] )) + $_POST['ping_status'] = 'closed'; + + if (!empty ( $_POST['edit_date'] ) ) { + $aa = $_POST['aa']; + $mm = $_POST['mm']; + $jj = $_POST['jj']; + $hh = $_POST['hh']; + $mn = $_POST['mn']; + $ss = $_POST['ss']; + $jj = ($jj > 31 ) ? 31 : $jj; + $hh = ($hh > 23 ) ? $hh -24 : $hh; + $mn = ($mn > 59 ) ? $mn -60 : $mn; + $ss = ($ss > 59 ) ? $ss -60 : $ss; + $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); + $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); + } + + // Create the post. + $post_ID = wp_insert_post( $_POST ); + if ( is_wp_error( $post_ID ) ) + return $post_ID; + + if ( empty($post_ID) ) + return 0; + + add_meta( $post_ID ); + + // Reunite any orphaned attachments with their parent + if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) + $draft_ids = array(); + if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) + _relocate_children( $draft_temp_id, $post_ID ); + if ( $temp_id && $temp_id != $draft_temp_id ) + _relocate_children( $temp_id, $post_ID ); + + // Update autosave collision detection + if ( $temp_id ) { + $draft_ids[$temp_id] = $post_ID; + update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); + } + + // Now that we have an ID we can fix any attachment anchor hrefs + _fix_attachment_links( $post_ID ); + + return $post_ID; +} + +function write_post() { + $result = wp_write_post(); + if( is_wp_error( $result ) ) + wp_die( $result->get_error_message() ); + else + return $result; +} + +// +// Post Meta +// + +function add_meta( $post_ID ) { + global $wpdb; + $post_ID = (int) $post_ID; + + $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); + + $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) ); + $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) ); + $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) )); + $metavalue = $wpdb->escape( $metavalue ); + + if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) { + // We have a key/value pair. If both the select and the + // input for the key have data, the input takes precedence: + + if ('#NONE#' != $metakeyselect) + $metakey = $metakeyselect; + + if ( $metakeyinput) + $metakey = $metakeyinput; // default + + if ( in_array($metakey, $protected) ) + return false; + + $result = $wpdb->query( " + INSERT INTO $wpdb->postmeta + (post_id,meta_key,meta_value ) + VALUES ('$post_ID','$metakey','$metavalue' ) + " ); + return $wpdb->insert_id; + } + return false; +} // add_meta + +function delete_meta( $mid ) { + global $wpdb; + $mid = (int) $mid; + + return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); +} + +// Get a list of previously defined keys +function get_meta_keys() { + global $wpdb; + + $keys = $wpdb->get_col( " + SELECT meta_key + FROM $wpdb->postmeta + GROUP BY meta_key + ORDER BY meta_key" ); + + return $keys; +} + +function get_post_meta_by_id( $mid ) { + global $wpdb; + $mid = (int) $mid; + + $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); + if ( is_serialized_string( $meta->meta_value ) ) + $meta->meta_value = maybe_unserialize( $meta->meta_value ); + return $meta; +} + +// Some postmeta stuff +function has_meta( $postid ) { + global $wpdb; + + return $wpdb->get_results( " + SELECT meta_key, meta_value, meta_id, post_id + FROM $wpdb->postmeta + WHERE post_id = '$postid' + ORDER BY meta_key,meta_id", ARRAY_A ); + +} + +function update_meta( $mid, $mkey, $mvalue ) { + global $wpdb; + + $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); + + if ( in_array($mkey, $protected) ) + return false; + + $mvalue = maybe_serialize( stripslashes( $mvalue )); + $mvalue = $wpdb->escape( $mvalue ); + $mid = (int) $mid; + return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" ); +} + +// +// Private +// + +// Replace hrefs of attachment anchors with up-to-date permalinks. +function _fix_attachment_links( $post_ID ) { + global $wp_rewrite; + + $post = & get_post( $post_ID, ARRAY_A ); + + $search = "#]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; + + // See if we have any rel="attachment" links + if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) + return; + + $i = 0; + $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; + foreach ( $anchor_matches[0] as $anchor ) { + if ( 0 == preg_match( $search, $anchor, $id_matches ) ) + continue; + + $id = (int) $id_matches[3]; + + // While we have the attachment ID, let's adopt any orphans. + $attachment = & get_post( $id, ARRAY_A ); + if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { + $attachment['post_parent'] = $post_ID; + // Escape data pulled from DB. + $attachment = add_magic_quotes( $attachment); + wp_update_post( $attachment); + } + + $post_search[$i] = $anchor; + $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); + ++$i; + } + + $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); + + // Escape data pulled from DB. + $post = add_magic_quotes( $post); + + return wp_update_post( $post); +} + +// Move child posts to a new parent +function _relocate_children( $old_ID, $new_ID ) { + global $wpdb; + $old_ID = (int) $old_ID; + $new_ID = (int) $new_ID; + return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); +} + +?> \ No newline at end of file diff --git a/wp-admin/upgrade-schema.php b/wp-admin/includes/schema.php similarity index 77% rename from wp-admin/upgrade-schema.php rename to wp-admin/includes/schema.php index 9567960e..0ccf674a 100644 --- a/wp-admin/upgrade-schema.php +++ b/wp-admin/includes/schema.php @@ -1,16 +1,39 @@ 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', - PRIMARY KEY (cat_ID), - KEY category_nicename (category_nicename) -); +$charset_collate = ''; + +if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { + if ( ! empty($wpdb->charset) ) + $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; + if ( ! empty($wpdb->collate) ) + $charset_collate .= " COLLATE $wpdb->collate"; +} + +$wp_queries="CREATE TABLE $wpdb->terms ( + term_id bigint(20) NOT NULL auto_increment, + name varchar(55) NOT NULL default '', + slug varchar(200) NOT NULL default '', + term_group bigint(10) NOT NULL default 0, + PRIMARY KEY (term_id), + UNIQUE KEY slug (slug) +) $charset_collate; +CREATE TABLE $wpdb->term_taxonomy ( + term_taxonomy_id bigint(20) NOT NULL auto_increment, + term_id bigint(20) NOT NULL default 0, + taxonomy varchar(32) NOT NULL default '', + description longtext NOT NULL, + parent bigint(20) NOT NULL default 0, + count bigint(20) NOT NULL default 0, + PRIMARY KEY (term_taxonomy_id), + UNIQUE KEY term_id_taxonomy (term_id,taxonomy) +) $charset_collate; +CREATE TABLE $wpdb->term_relationships ( + object_id bigint(20) NOT NULL default 0, + term_taxonomy_id bigint(20) NOT NULL default 0, + PRIMARY KEY (object_id,term_taxonomy_id), + KEY term_taxonomy_id (term_taxonomy_id) +) $charset_collate; CREATE TABLE $wpdb->comments ( comment_ID bigint(20) unsigned NOT NULL auto_increment, comment_post_ID int(11) NOT NULL default '0', @@ -30,23 +53,7 @@ CREATE TABLE $wpdb->comments ( PRIMARY KEY (comment_ID), KEY comment_approved (comment_approved), KEY comment_post_ID (comment_post_ID) -); -CREATE TABLE $wpdb->linkcategories ( - cat_id bigint(20) NOT NULL auto_increment, - cat_name tinytext NOT NULL, - auto_toggle enum('Y','N') NOT NULL default 'N', - show_images enum('Y','N') NOT NULL default 'Y', - show_description enum('Y','N') NOT NULL default 'N', - show_rating enum('Y','N') NOT NULL default 'Y', - show_updated enum('Y','N') NOT NULL default 'Y', - sort_order varchar(64) NOT NULL default 'rand', - sort_desc enum('Y','N') NOT NULL default 'N', - text_before_link varchar(128) NOT NULL default '
  • ', - text_after_link varchar(128) NOT NULL default '
    ', - text_after_all varchar(128) NOT NULL default '
  • ', - list_limit int(11) NOT NULL default '-1', - PRIMARY KEY (cat_id) -); +) $charset_collate; CREATE TABLE $wpdb->links ( link_id bigint(20) NOT NULL auto_increment, link_url varchar(255) NOT NULL default '', @@ -65,29 +72,16 @@ CREATE TABLE $wpdb->links ( PRIMARY KEY (link_id), KEY link_category (link_category), KEY link_visible (link_visible) -); +) $charset_collate; CREATE TABLE $wpdb->options ( option_id bigint(20) NOT NULL auto_increment, blog_id int(11) NOT NULL default '0', option_name varchar(64) NOT NULL default '', - option_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) -); -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) -); +) $charset_collate; CREATE TABLE $wpdb->postmeta ( meta_id bigint(20) NOT NULL auto_increment, post_id bigint(20) NOT NULL default '0', @@ -96,7 +90,7 @@ CREATE TABLE $wpdb->postmeta ( PRIMARY KEY (meta_id), KEY post_id (post_id), KEY meta_key (meta_key) -); +) $charset_collate; CREATE TABLE $wpdb->posts ( ID bigint(20) unsigned NOT NULL auto_increment, post_author bigint(20) NOT NULL default '0', @@ -106,7 +100,7 @@ CREATE TABLE $wpdb->posts ( 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') NOT NULL default 'publish', + post_status enum('publish','draft','private','static','object','attachment','inherit','future', 'pending') NOT NULL default 'publish', comment_status enum('open','closed','registered_only') NOT NULL default 'open', ping_status enum('open','closed') NOT NULL default 'open', post_password varchar(20) NOT NULL default '', @@ -119,13 +113,13 @@ CREATE TABLE $wpdb->posts ( 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(100) NOT NULL default '', + 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 post_status (post_status) -); + KEY type_status_date (post_type,post_status,post_date,ID) +) $charset_collate; CREATE TABLE $wpdb->users ( ID bigint(20) unsigned NOT NULL auto_increment, user_login varchar(60) NOT NULL default '', @@ -138,8 +132,9 @@ CREATE TABLE $wpdb->users ( user_status int(11) NOT NULL default '0', display_name varchar(250) NOT NULL default '', PRIMARY KEY (ID), - KEY user_login_key (user_login) -); + KEY user_login_key (user_login), + KEY user_nicename (user_nicename) +) $charset_collate; CREATE TABLE $wpdb->usermeta ( umeta_id bigint(20) NOT NULL auto_increment, user_id bigint(20) NOT NULL default '0', @@ -148,17 +143,16 @@ CREATE TABLE $wpdb->usermeta ( PRIMARY KEY (umeta_id), KEY user_id (user_id), KEY meta_key (meta_key) -);"; +) $charset_collate;"; function populate_options() { global $wpdb, $wp_db_version; $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 WordPress weblog'), __('Short tagline')); - add_option('new_users_can_blog', 0); + add_option('siteurl', $guessurl); + add_option('blogname', __('My Blog')); + add_option('blogdescription', __('Just another WordPress weblog')); add_option('users_can_register', 0); add_option('admin_email', 'you@example.com'); add_option('start_of_week', 1); @@ -203,7 +197,7 @@ function populate_options() { 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('default_email_category', 1); add_option('recently_edited'); add_option('use_linksupdate', 0); add_option('template', 'default'); @@ -212,14 +206,12 @@ function populate_options() { add_option('page_uris'); add_option('blacklist_keys'); add_option('comment_registration', 0); - add_option('open_proxy_check', 0); add_option('rss_language', 'en'); add_option('html_type', 'text/html'); // 1.5.1 add_option('use_trackback', 0); // 2.0 add_option('default_role', 'subscriber'); - add_option('rich_editing', 'true'); add_option('db_version', $wp_db_version); // 2.0.1 if ( ini_get('safe_mode') ) { @@ -230,12 +222,20 @@ function populate_options() { add_option('uploads_use_yearmonth_folders', 1); add_option('upload_path', 'wp-content/uploads'); } - + // 2.0.3 add_option('secret', md5(uniqid(microtime()))); + // 2.1 + add_option('blog_public', '1'); + add_option('default_link_category', 2); + add_option('show_on_front', 'posts'); + + // 2.2 + add_option('tag_base'); + // Delete unused options - $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog'); + $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing'); foreach ($unusedoptions as $option) : delete_option($option); endforeach; @@ -248,7 +248,9 @@ function populate_options() { } function populate_roles() { - populate_roles_160(); + populate_roles_160(); + populate_roles_210(); + populate_roles_230(); } function populate_roles_160() { @@ -260,7 +262,7 @@ function populate_roles_160() { 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'); @@ -293,7 +295,7 @@ function populate_roles_160() { $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'); @@ -315,7 +317,7 @@ function populate_roles_160() { $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'); @@ -326,18 +328,68 @@ function populate_roles_160() { $role->add_cap('level_2'); $role->add_cap('level_1'); $role->add_cap('level_0'); - + // Add caps for Contributor role $role = get_role('contributor'); $role->add_cap('edit_posts'); $role->add_cap('read'); $role->add_cap('level_1'); $role->add_cap('level_0'); - + // Add caps for Subscriber role $role = get_role('subscriber'); $role->add_cap('read'); $role->add_cap('level_0'); } +function populate_roles_210() { + $roles = array('administrator', 'editor'); + foreach ($roles as $role) { + $role = get_role($role); + if ( empty($role) ) + continue; + + $role->add_cap('edit_others_pages'); + $role->add_cap('edit_published_pages'); + $role->add_cap('publish_pages'); + $role->add_cap('delete_pages'); + $role->add_cap('delete_others_pages'); + $role->add_cap('delete_published_pages'); + $role->add_cap('delete_posts'); + $role->add_cap('delete_others_posts'); + $role->add_cap('delete_published_posts'); + $role->add_cap('delete_private_posts'); + $role->add_cap('edit_private_posts'); + $role->add_cap('read_private_posts'); + $role->add_cap('delete_private_pages'); + $role->add_cap('edit_private_pages'); + $role->add_cap('read_private_pages'); + } + + $role = get_role('administrator'); + if ( ! empty($role) ) { + $role->add_cap('delete_users'); + $role->add_cap('create_users'); + } + + $role = get_role('author'); + if ( ! empty($role) ) { + $role->add_cap('delete_posts'); + $role->add_cap('delete_published_posts'); + } + + $role = get_role('contributor'); + if ( ! empty($role) ) { + $role->add_cap('delete_posts'); + } +} + +function populate_roles_230() { + $role = get_role( 'administrator' ); + + if ( !empty( $role ) ) { + $role->add_cap( 'unfiltered_upload' ); + } +} + ?> diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php new file mode 100644 index 00000000..3f70f45b --- /dev/null +++ b/wp-admin/includes/taxonomy.php @@ -0,0 +1,148 @@ + $cat_name) ); +} + +function wp_create_categories($categories, $post_id = '') { + $cat_ids = array (); + foreach ($categories as $category) { + if ($id = category_exists($category)) + $cat_ids[] = $id; + else + if ($id = wp_create_category($category)) + $cat_ids[] = $id; + } + + if ($post_id) + wp_set_post_categories($post_id, $cat_ids); + + return $cat_ids; +} + +function wp_delete_category($cat_ID) { + global $wpdb; + + $cat_ID = (int) $cat_ID; + $default = get_option('default_category'); + + // Don't delete the default cat + if ( $cat_ID == $default ) + return 0; + + return wp_delete_term($cat_ID, 'category', "default=$default"); +} + +function wp_insert_category($catarr) { + global $wpdb; + + extract($catarr, EXTR_SKIP); + + if ( trim( $cat_name ) == '' ) + return 0; + + $cat_ID = (int) $cat_ID; + + // Are we updating or creating? + if ( !empty ($cat_ID) ) + $update = true; + else + $update = false; + + $name = $cat_name; + $description = $category_description; + $slug = $category_nicename; + $parent = $category_parent; + + $parent = (int) $parent; + if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) ) + $parent = 0; + + $args = compact('name', 'slug', 'parent', 'description'); + + if ( $update ) + $cat_ID = wp_update_term($cat_ID, 'category', $args); + else + $cat_ID = wp_insert_term($cat_name, 'category', $args); + + if ( is_wp_error($cat_ID) ) + return 0; + + return $cat_ID['term_id']; +} + +function wp_update_category($catarr) { + global $wpdb; + + $cat_ID = (int) $catarr['cat_ID']; + + if ( $cat_ID == $catarr['category_parent'] ) + return false; + + // First, get all of the original fields + $category = get_category($cat_ID, ARRAY_A); + + // Escape data pulled from DB. + $category = add_magic_quotes($category); + + // Merge old and new fields with new fields overwriting old ones. + $catarr = array_merge($category, $catarr); + + return wp_insert_category($catarr); +} + +// +// Tags +// + +function get_tags_to_edit( $post_id ) { + global $wpdb; + + $post_id = (int) $post_id; + if ( !$post_id ) + return false; + + $tags = wp_get_post_tags($post_id); + + if ( !$tags ) + return false; + + foreach ( $tags as $tag ) + $tag_names[] = $tag->name; + $tags_to_edit = join( ', ', $tag_names ); + $tags_to_edit = attribute_escape( $tags_to_edit ); + $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); + return $tags_to_edit; +} + +function tag_exists($tag_name) { + return is_term($tag_name, 'post_tag'); +} + +function wp_create_tag($tag_name) { + if ( $id = tag_exists($tag_name) ) + return $id; + + return wp_insert_term($tag_name, 'post_tag'); +} + +?> \ No newline at end of file diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php new file mode 100644 index 00000000..71bf387c --- /dev/null +++ b/wp-admin/includes/template.php @@ -0,0 +1,617 @@ +parent == $parent) { + echo "\t" . _cat_row( $category, $level ); + if ( isset($children[$category->term_id]) ) + cat_rows( $category->term_id, $level +1, $categories ); + } + } + $output = ob_get_contents(); + ob_end_clean(); + + $output = apply_filters('cat_rows', $output); + + echo $output; + } else { + return false; + } +} + +function _cat_row( $category, $level, $name_override = false ) { + global $class; + + $pad = str_repeat( '— ', $level ); + if ( current_user_can( 'manage_categories' ) ) { + $edit = "".__( 'Edit' ).""; + $default_cat_id = (int) get_option( 'default_category' ); + $default_link_cat_id = (int) get_option( 'default_link_category' ); + + if ( $category->term_id != $default_cat_id ) + $edit .= "term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' ).""; + else + $edit .= "".__( "Default" ); + } else + $edit = ''; + + $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; + + $category->count = number_format_i18n( $category->count ); + $posts_count = ( $category->count > 0 ) ? "$category->count" : $category->count; + $output = " + $category->term_id + " . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . " + $category->description + $posts_count + $edit\n\t\n"; + + return apply_filters('cat_row', $output); +} + +function checked( $checked, $current) { + if ( $checked == $current) + echo ' checked="checked"'; +} + +// TODO: Remove? +function documentation_link( $for ) { + return; +} + +function selected( $selected, $current) { + if ( $selected == $current) + echo ' selected="selected"'; +} + +// +// Nasty Category Stuff +// + +function sort_cats( $cat1, $cat2 ) { + if ( $cat1['checked'] || $cat2['checked'] ) + return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; + else + return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); +} + +function get_nested_categories( $default = 0, $parent = 0 ) { + global $post_ID, $mode, $wpdb, $checked_categories; + + if ( empty($checked_categories) ) { + if ( $post_ID ) { + $checked_categories = wp_get_post_categories($post_ID); + + if ( count( $checked_categories ) == 0 ) { + // No selected categories, strange + $checked_categories[] = $default; + } + } else { + $checked_categories[] = $default; + } + } + + $cats = get_categories("parent=$parent&hide_empty=0&fields=ids"); + + $result = array (); + if ( is_array( $cats ) ) { + foreach ( $cats as $cat) { + $result[$cat]['children'] = get_nested_categories( $default, $cat); + $result[$cat]['cat_ID'] = $cat; + $result[$cat]['checked'] = in_array( $cat, $checked_categories ); + $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); + } + } + + $result = apply_filters('get_nested_categories', $result); + usort( $result, 'sort_cats' ); + + return $result; +} + +function write_nested_categories( $categories ) { + foreach ( $categories as $category ) { + echo '
  • "; + + if ( $category['children'] ) { + echo "
      \n"; + write_nested_categories( $category['children'] ); + echo "
    \n"; + } + } +} + +function dropdown_categories( $default = 0 ) { + write_nested_categories( get_nested_categories( $default) ); +} + +function dropdown_link_categories( $default = 0 ) { + global $link_id; + + if ( $link_id ) { + $checked_categories = wp_get_link_cats($link_id); + + if ( count( $checked_categories ) == 0 ) { + // No selected categories, strange + $checked_categories[] = $default; + } + } else { + $checked_categories[] = $default; + } + + $categories = get_terms('link_category', 'orderby=count&hide_empty=0'); + + if ( empty($categories) ) + return; + + foreach ( $categories as $category ) { + $cat_id = $category->term_id; + $name = wp_specialchars( apply_filters('the_category', $category->name)); + $checked = in_array( $cat_id, $checked_categories ); + echo '"; + } +} + +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 = (int) $post->ID; + $class = ('alternate' == $class ) ? '' : 'alternate'; +?> + + ID; ?> + + + + + post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?> + + " . __( 'Edit' ) . ""; } ?> + " . __( 'Delete' ) . ""; } ?> + + +user_email; + $url = $user_object->user_url; + $short_url = str_replace( 'http://', '', $url ); + $short_url = str_replace( 'www.', '', $short_url ); + if ('/' == substr( $short_url, -1 )) + $short_url = substr( $short_url, 0, -1 ); + if ( strlen( $short_url ) > 35 ) + $short_url = substr( $short_url, 0, 32 ).'...'; + $numposts = get_usernumposts( $user_object->ID ); + $r = " + + + + $email + $short_url"; + $r .= "\n\t\t"; + if ( $numposts > 0 ) { + $r .= ""; + $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts); + $r .= ''; + } + $r .= "\n\t\t"; + if ( current_user_can( 'edit_user', $user_object->ID ) ) { + $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ); + $r .= "".__( 'Edit' ).""; + } + $r .= "\n\t"; + return $r; +} + +function _wp_get_comment_list( $s = false, $start, $num ) { + global $wpdb; + + $start = abs( (int) $start ); + $num = (int) $num; + + if ( $s ) { + $s = $wpdb->escape($s); + $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE + (comment_author LIKE '%$s%' OR + comment_author_email LIKE '%$s%' OR + comment_author_url LIKE ('%$s%') OR + comment_author_IP LIKE ('%$s%') OR + comment_content LIKE ('%$s%') ) AND + comment_approved != 'spam' + ORDER BY comment_date DESC LIMIT $start, $num"); + } else { + $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" ); + } + + update_comment_cache($comments); + + $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); + + return array($comments, $total); +} + +function _wp_comment_list_item( $id, $alt = 0 ) { + global $authordata, $comment, $wpdb; + $id = (int) $id; + $comment =& get_comment( $id ); + $class = ''; + $post = get_post($comment->comment_post_ID); + $authordata = get_userdata($post->post_author); + $comment_status = wp_get_comment_status($comment->comment_ID); + if ( 'unapproved' == $comment_status ) + $class .= ' unapproved'; + if ( $alt % 2 ) + $class .= ' alternate'; + echo "
  • "; +?> +

    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 . "&c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . " "; +} +$post = get_post($comment->comment_post_ID, OBJECT, 'display'); +$post_title = wp_specialchars( $post->post_title, 'double' ); +$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; +?> + ] —

    +
  • +term_id && $parent == $category->parent) { + $pad = str_repeat( '– ', $level ); + $category->name = wp_specialchars( $category->name ); + echo "\n\t"; + wp_dropdown_cats( $currentcat, $currentparent, $category->term_id, $level +1, $categories ); + } + } + } else { + return false; + } +} + +function list_meta( $meta ) { + global $post_ID; + // Exit if no meta + if (!$meta ) { + echo ' '; //TBODY 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'; + + if ( is_serialized( $entry['meta_value'] ) ) { + if ( is_serialized_string( $entry['meta_value'] ) ) { + // this is a serialized string, so we should display it + $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); + } else { + // this is a serialized array/object so we should NOT display it + --$count; + continue; + } + } + + $key_js = js_escape( $entry['meta_key'] ); + $entry['meta_key'] = attribute_escape($entry['meta_key']); + $entry['meta_value'] = attribute_escape($entry['meta_value']); + $entry['meta_id'] = (int) $entry['meta_id']; + $r .= "\n\t"; + $r .= "\n\t\t"; + $r .= "\n\t\t"; + $r .= "\n\t\t
    "; + $r .= "\n\t\t"; + $r .= "\n\t"; + } + echo $r; + echo "\n\t"; +} + +function meta_form() { + global $wpdb; + $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); + $keys = $wpdb->get_col( " + SELECT meta_key + FROM $wpdb->postmeta + WHERE meta_key NOT LIKE '\_%' + GROUP BY meta_key + ORDER BY meta_id DESC + LIMIT $limit" ); + if ( $keys ) + natcasesort($keys); +?> +

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

    +post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true; + + $tab_index_attribute = ''; + if ( (int) $tab_index > 0 ) + $tab_index_attribute = " tabindex=\"$tab_index\""; + + echo '
    '; + + $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 ); + $post_date = ($for_post) ? $post->post_date : $comment->comment_date; + $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj ); + $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj ); + $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj ); + $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj ); + $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); + $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); + + echo " + /> + /> @ + /> : + /> + +get_month( $mm ), $jj, $aa, $hh, $mn ); + } +?> +
    + $template"; + endforeach; +} + +function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { + global $wpdb, $post_ID; + $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" ); + + if ( $items ) { + foreach ( $items as $item ) { + // A page cannot be its own parent. + if (!empty ( $post_ID ) ) { + if ( $item->ID == $post_ID ) { + continue; + } + } + $pad = str_repeat( ' ', $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 browse_happy() { + $getit = __( 'WordPress recommends a better browser' ); + echo ' +

    Browse Happy

    + '; +} + +if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) + add_action( 'admin_footer', 'browse_happy' ); + +function the_attachment_links( $id = false ) { + $id = (int) $id; + $post = & get_post( $id ); + + if ( $post->post_type != 'attachment' ) + return false; + + $icon = get_attachment_icon( $post->ID ); + $attachment_data = wp_get_attachment_metadata( $id ); + $thumb = isset( $attachment_data['thumb'] ); +?> + +role_names as $role => $name ) + if ( $default == $role ) // Make default first in list + $p = "\n\t"; + else + $r .= "\n\t"; + echo $p . $r; +} + +function wp_convert_hr_to_bytes( $size ) { + $size = strtolower($size); + $bytes = (int) $size; + if ( strpos($size, 'k') !== false ) + $bytes = intval($size) * 1024; + elseif ( strpos($size, 'm') !== false ) + $bytes = intval($size) * 1024 * 1024; + elseif ( strpos($size, 'g') !== false ) + $bytes = intval($size) * 1024 * 1024 * 1024; + return $bytes; +} + +function wp_convert_bytes_to_hr( $bytes ) { + $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); + $log = log( $bytes, 1024 ); + $power = (int) $log; + $size = pow(1024, $log - $power); + return $size . $units[$power]; +} + +function wp_import_upload_form( $action ) { + $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); + $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); + $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes ); + $size = wp_convert_bytes_to_hr( $bytes ); +?> +
    +

    + + () + + + +

    +

    + +

    +
    +post_name); // just in case + if ( strlen($name) ) + echo ''; +} + +?> diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php new file mode 100644 index 00000000..bd39dea2 --- /dev/null +++ b/wp-admin/includes/theme.php @@ -0,0 +1,52 @@ +name = $current_theme; + $ct->title = $themes[$current_theme]['Title']; + $ct->version = $themes[$current_theme]['Version']; + $ct->parent_theme = $themes[$current_theme]['Parent Theme']; + $ct->template_dir = $themes[$current_theme]['Template Dir']; + $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; + $ct->template = $themes[$current_theme]['Template']; + $ct->stylesheet = $themes[$current_theme]['Stylesheet']; + $ct->screenshot = $themes[$current_theme]['Screenshot']; + $ct->description = $themes[$current_theme]['Description']; + $ct->author = $themes[$current_theme]['Author']; + return $ct; +} + +function get_broken_themes() { + global $wp_broken_themes; + + get_themes(); + return $wp_broken_themes; +} + +function get_page_templates() { + $themes = get_themes(); + $theme = get_current_theme(); + $templates = $themes[$theme]['Template Files']; + $page_templates = array (); + + if ( is_array( $templates ) ) { + foreach ( $templates as $template ) { + $template_data = implode( '', file( ABSPATH.$template )); + + preg_match( '|Template Name:(.*)$|mi', $template_data, $name ); + preg_match( '|Description:(.*)$|mi', $template_data, $description ); + + $name = $name[1]; + $description = $description[1]; + + if ( !empty( $name ) ) { + $page_templates[trim( $name )] = basename( $template ); + } + } + } + + return $page_templates; +} + +?> diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php new file mode 100644 index 00000000..41945d2b --- /dev/null +++ b/wp-admin/includes/update.php @@ -0,0 +1,122 @@ +response ) { + case 'development' : + return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please stay updated.' ), $GLOBALS['wp_version'], 'http://wordpress.org/download/svn/' ); + break; + + case 'upgrade' : + return sprintf( '| '.__( 'Your WordPress %s is out of date. Please update.' ).'', $GLOBALS['wp_version'], $cur->url ); + break; + + case 'latest' : + default : + return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] ); + break; + } +} +add_filter( 'update_footer', 'core_update_footer' ); + +function update_nag() { + $cur = get_option( 'update_core' ); + + if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) + return false; + + if ( current_user_can('manage_options') ) + $msg = sprintf( __('A new version of WordPress is available! Please update now.'), $cur->url ); + else + $msg = __('A new version of WordPress is available! Please notify the site administrator.'); + + echo "
    $msg
    "; +} +add_action( 'admin_notices', 'update_nag', 3 ); + +function wp_update_plugins() { + global $wp_version; + + if ( !function_exists('fsockopen') ) + return false; + + $plugins = get_plugins(); + $active = get_option( 'active_plugins' ); + $current = get_option( 'update_plugins' ); + + $new_option = ''; + $new_option->last_checked = time(); + + $plugin_changed = false; + foreach ( $plugins as $file => $p ) { + $new_option->checked[ $file ] = $p['Version']; + + if ( !isset( $current->checked[ $file ] ) ) { + $plugin_changed = true; + continue; + } + + if ( $current->checked[ $file ] != $p['Version'] ) + $plugin_changed = true; + } + + if ( + isset( $current->last_checked ) && + 43200 > ( time() - $current->last_checked ) && + !$plugin_changed + ) + return false; + + $to_send->plugins = $plugins; + $to_send->active = $active; + $send = serialize( $to_send ); + + $request = 'plugins=' . urlencode( $send ); + $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n"; + $http_request .= "Host: api.wordpress.org\r\n"; + $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n"; + $http_request .= "Content-Length: " . strlen($request) . "\r\n"; + $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n"; + $http_request .= "\r\n"; + $http_request .= $request; + + $response = ''; + if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) { + fwrite($fs, $http_request); + + while ( !feof($fs) ) + $response .= fgets($fs, 1160); // One TCP-IP packet + fclose($fs); + $response = explode("\r\n\r\n", $response, 2); + } + + $response = unserialize( $response[1] ); + + if ( $response ) + $new_option->response = $response; + + update_option( 'update_plugins', $new_option ); +} +add_action( 'load-plugins.php', 'wp_update_plugins' ); + +function wp_plugin_update_row( $file ) { + global $plugin_data; + $current = get_option( 'update_plugins' ); + if ( !isset( $current->response[ $file ] ) ) + return false; + + $r = $current->response[ $file ]; + + echo ""; + printf( __('There is a new version of %s available. Download version %s here.'), $plugin_data['Name'], $r->url, $r->new_version ); + echo ""; +} +add_action( 'after_plugin_row', 'wp_plugin_update_row' ); + +?> diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php new file mode 100644 index 00000000..402e65cc --- /dev/null +++ b/wp-admin/includes/upgrade.php @@ -0,0 +1,1267 @@ +set_role('administrator'); + + wp_install_defaults($user_id); + + $wp_rewrite->flush_rules(); + + wp_new_blog_notification($blog_title, $guessurl, $user_id, $random_password); + + wp_cache_flush(); + + return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $random_password); +} +endif; + +if ( !function_exists('wp_install_defaults') ) : +function wp_install_defaults($user_id) { + global $wpdb; + + // Default category + $cat_name = $wpdb->escape(__('Uncategorized')); + $cat_slug = sanitize_title(__('Uncategorized')); + $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')"); + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('1', 'category', '', '0', '1')"); + + // Default link category + $cat_name = $wpdb->escape(__('Blogroll')); + $cat_slug = sanitize_title(__('Blogroll')); + $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')"); + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('2', 'link_category', '', '0', '7')"); + + // Now drop in some default links + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://codex.wordpress.org/', 'Documentation', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/development/', 'Development Blog', 0, 'http://wordpress.org/development/feed/', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (2, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/ideas/', 'Suggest Ideas', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (3, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/support/', 'Support Forum', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (4, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/plugins/', 'Plugins', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (5, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/themes/', 'Themes', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (6, 2)" ); + + $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://planet.wordpress.org/', 'WordPress Planet', 0, '', '');"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (7, 2)" ); + + // First post + $now = date('Y-m-d H:i:s'); + $now_gmt = gmdate('Y-m-d H:i:s'); + $first_post_guid = get_option('home') . '/?p=1'; + $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '$first_post_guid', '1', '', '', '')"); + $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 1)" ); + + // Default comment + $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.
    To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.'))."')"); + + // First Page + $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')"); +} +endif; + +if ( !function_exists('wp_new_blog_notification') ) : +function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) { + $user = new WP_User($user_id); + $email = $user->user_email; + $name = $user->user_login; + $message_headers = 'From: "' . $blog_title . '" '; + $message = sprintf(__("Your new WordPress blog has been successfully set up at: + +%1\$s + +You can log in to the administrator account with the following information: + +Username: %2\$s +Password: %3\$s + +We hope you enjoy your new blog. Thanks! + +--The WordPress Team +http://wordpress.org/ +"), $blog_url, $name, $password); + + @wp_mail($email, __('New WordPress Blog'), $message, $message_headers); +} +endif; + +if ( !function_exists('wp_upgrade') ) : +function wp_upgrade() { + global $wp_current_db_version, $wp_db_version; + + $wp_current_db_version = __get_option('db_version'); + + // We are up-to-date. Nothing to do. + if ( $wp_db_version == $wp_current_db_version ) + return; + + wp_check_mysql_version(); + wp_cache_flush(); + make_db_current_silent(); + upgrade_all(); + wp_cache_flush(); +} +endif; + +// Functions to be called in install and upgrade scripts +function upgrade_all() { + global $wp_current_db_version, $wp_db_version, $wp_rewrite; + $wp_current_db_version = __get_option('db_version'); + + // We are up-to-date. Nothing to do. + if ( $wp_db_version == $wp_current_db_version ) + return; + + // If the version is not set in the DB, try to guess the version. + if ( empty($wp_current_db_version) ) { + $wp_current_db_version = 0; + + // If the template option exists, we have 1.5. + $template = __get_option('template'); + if ( !empty($template) ) + $wp_current_db_version = 2541; + } + + if ( $wp_current_db_version < 6039 ) + upgrade_230_options_table(); + + populate_options(); + + if ( $wp_current_db_version < 2541 ) { + upgrade_100(); + upgrade_101(); + upgrade_110(); + upgrade_130(); + } + + if ( $wp_current_db_version < 3308 ) + upgrade_160(); + + if ( $wp_current_db_version < 4772 ) + upgrade_210(); + + if ( $wp_current_db_version < 4351 ) + upgrade_old_slugs(); + + if ( $wp_current_db_version < 5539 ) + upgrade_230(); + + if ( $wp_current_db_version < 6124 ) + upgrade_230_old_tables(); + + maybe_disable_automattic_widgets(); + + $wp_rewrite->flush_rules(); + + update_option('db_version', $wp_db_version); +} + +function upgrade_100() { + global $wpdb; + + // Get the title and ID of every post, post_name to check if it already has a value + $posts = $wpdb->get_results("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE post_name = ''"); + if ($posts) { + foreach($posts as $post) { + if ('' == $post->post_name) { + $newtitle = sanitize_title($post->post_title); + $wpdb->query("UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'"); + } + } + } + + $categories = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename FROM $wpdb->categories"); + foreach ($categories as $category) { + if ('' == $category->category_nicename) { + $newtitle = sanitize_title($category->cat_name); + $wpdb->query("UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'"); + } + } + + + $wpdb->query("UPDATE $wpdb->options SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/') + WHERE option_name LIKE 'links_rating_image%' + AND option_value LIKE 'wp-links/links-images/%'"); + + $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat"); + if ($done_ids) : + foreach ($done_ids as $done_id) : + $done_posts[] = $done_id->post_id; + endforeach; + $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')'; + else: + $catwhere = ''; + endif; + + $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere"); + if ($allposts) : + foreach ($allposts as $post) { + // Check to see if it's already been imported + $cat = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post->ID AND category_id = $post->post_category"); + if (!$cat && 0 != $post->post_category) { // If there's no result + $wpdb->query(" + INSERT INTO $wpdb->post2cat + (post_id, category_id) + VALUES + ('$post->ID', '$post->post_category') + "); + } + } + endif; +} + +function upgrade_101() { + global $wpdb; + + // Clean up indices, add a few + add_clean_index($wpdb->posts, 'post_name'); + add_clean_index($wpdb->posts, 'post_status'); + add_clean_index($wpdb->categories, 'category_nicename'); + add_clean_index($wpdb->comments, 'comment_approved'); + add_clean_index($wpdb->comments, 'comment_post_ID'); + add_clean_index($wpdb->links , 'link_category'); + add_clean_index($wpdb->links , 'link_visible'); +} + + +function upgrade_110() { + global $wpdb; + + // Set user_nicename. + $users = $wpdb->get_results("SELECT ID, user_nickname, user_nicename FROM $wpdb->users"); + foreach ($users as $user) { + if ('' == $user->user_nicename) { + $newname = sanitize_title($user->user_nickname); + $wpdb->query("UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'"); + } + } + + $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users"); + foreach ($users as $row) { + if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) { + $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\''); + } + } + + + // Get the GMT offset, we'll use that later on + $all_options = get_alloptions_110(); + + $time_difference = $all_options->time_difference; + + $server_time = time()+date('Z'); + $weblogger_time = $server_time + $time_difference*3600; + $gmt_time = time(); + + $diff_gmt_server = ($gmt_time - $server_time) / 3600; + $diff_weblogger_server = ($weblogger_time - $server_time) / 3600; + $diff_gmt_weblogger = $diff_gmt_server - $diff_weblogger_server; + $gmt_offset = -$diff_gmt_weblogger; + + // Add a gmt_offset option, with value $gmt_offset + add_option('gmt_offset', $gmt_offset); + + // Check if we already set the GMT fields (if we did, then + // MAX(post_date_gmt) can't be '0000-00-00 00:00:00' + // 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() { + global $wpdb, $wp_current_db_version; + + populate_roles_160(); + + $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); + foreach ( $users as $user ) : + 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; + $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' ); + $wpdb->hide_errors(); + foreach ( $old_user_fields as $old ) + $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); + $wpdb->show_errors(); + + // populate comment_count field of posts table + $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); + if( is_array( $comments ) ) { + foreach ($comments as $comment) { + $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID'" ); + } + } + + // Some alpha versions used a post status of object instead of attachment and put + // the mime type in post_type instead of post_mime_type. + if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) { + $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); + foreach ($objects as $object) { + $wpdb->query("UPDATE $wpdb->posts SET post_status = 'attachment', + post_mime_type = '$object->post_type', + post_type = '' + WHERE ID = $object->ID"); + + $meta = get_post_meta($object->ID, 'imagedata', true); + if ( ! empty($meta['file']) ) + update_attached_file( $object->ID, $meta['file'] ); + } + } +} + +function upgrade_210() { + global $wpdb, $wp_current_db_version; + + if ( $wp_current_db_version < 3506 ) { + // Update status and type. + $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts"); + + if ( ! empty($posts) ) foreach ($posts as $post) { + $status = $post->post_status; + $type = 'post'; + + if ( 'static' == $status ) { + $status = 'publish'; + $type = 'page'; + } else if ( 'attachment' == $status ) { + $status = 'inherit'; + $type = 'attachment'; + } + + $wpdb->query("UPDATE $wpdb->posts SET post_status = '$status', post_type = '$type' WHERE ID = '$post->ID'"); + } + } + + if ( $wp_current_db_version < 3845 ) { + populate_roles_210(); + } + + if ( $wp_current_db_version < 3531 ) { + // Give future posts a post_status of future. + $now = gmdate('Y-m-d H:i:59'); + $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); + + $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'"); + if ( !empty($posts) ) + foreach ( $posts as $post ) + wp_schedule_single_event(mysql2date('U', $post->post_date), 'publish_future_post', array($post->ID)); + } +} + +function upgrade_230() { + global $wp_current_db_version, $wpdb; + + if ( $wp_current_db_version < 5200 ) { + populate_roles_230(); + } + + // Convert categories to terms. + $tt_ids = array(); + $have_tags = false; + $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_ID"); + foreach ($categories as $category) { + $term_id = (int) $category->cat_ID; + $name = $wpdb->escape($category->cat_name); + $description = $wpdb->escape($category->category_description); + $slug = $wpdb->escape($category->category_nicename); + $parent = $wpdb->escape($category->category_parent); + $term_group = 0; + + // Associate terms with the same slug in a term group and make slugs unique. + if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) { + $term_group = $exists[0]->term_group; + $id = $exists[0]->term_id; + $num = 2; + do { + $alt_slug = $slug . "-$num"; + $num++; + $slug_check = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE slug = '$alt_slug'"); + } while ( $slug_check ); + + $slug = $alt_slug; + + if ( empty( $term_group ) ) { + $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1; + $wpdb->query("UPDATE $wpdb->terms SET term_group = '$term_group' WHERE term_id = '$id'"); + } + } + + $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')"); + + $count = 0; + if ( !empty($category->category_count) ) { + $count = (int) $category->category_count; + $taxonomy = 'category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } + + if ( !empty($category->link_count) ) { + $count = (int) $category->link_count; + $taxonomy = 'link_category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } + + if ( !empty($category->tag_count) ) { + $have_tags = true; + $count = (int) $category->tag_count; + $taxonomy = 'post_tag'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } + + if ( empty($count) ) { + $count = 0; + $taxonomy = 'category'; + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')"); + $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; + } + } + + $select = 'post_id, category_id'; + if ( $have_tags ) + $select .= ', rel_type'; + + $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id"); + foreach ( $posts as $post ) { + $post_id = (int) $post->post_id; + $term_id = (int) $post->category_id; + $taxonomy = 'category'; + if ( !empty($post->rel_type) && 'tag' == $post->rel_type) + $taxonomy = 'tag'; + $tt_id = $tt_ids[$term_id][$taxonomy]; + if ( empty($tt_id) ) + continue; + + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')"); + } + + // < 3570 we used linkcategories. >= 3570 we used categories and link2cat. + if ( $wp_current_db_version < 3570 ) { + // Create link_category terms for link categories. Create a map of link cat IDs + // to link_category terms. + $link_cat_id_map = array(); + $default_link_cat = 0; + $tt_ids = array(); + $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories'); + foreach ( $link_cats as $category) { + $cat_id = (int) $category->cat_id; + $term_id = 0; + $name = $wpdb->escape($category->cat_name); + $slug = sanitize_title($name); + $term_group = 0; + + // Associate terms with the same slug in a term group and make slugs unique. + if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) { + $term_group = $exists[0]->term_group; + $term_id = $exists[0]->term_id; + } + + if ( empty($term_id) ) { + $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')"); + $term_id = (int) $wpdb->insert_id; + } + + $link_cat_id_map[$cat_id] = $term_id; + $default_link_cat = $term_id; + + $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', 'link_category', '', '0', '0')"); + $tt_ids[$term_id] = (int) $wpdb->insert_id; + } + + // Associate links to cats. + $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); + if ( !empty($links) ) foreach ( $links as $link ) { + if ( 0 == $link->link_category ) + continue; + if ( ! isset($link_cat_id_map[$link->link_category]) ) + continue; + $term_id = $link_cat_id_map[$link->link_category]; + $tt_id = $tt_ids[$term_id]; + if ( empty($tt_id) ) + continue; + + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link->link_id', '$tt_id')"); + } + + // Set default to the last category we grabbed during the upgrade loop. + update_option('default_link_category', $default_link_cat); + } else { + $links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id"); + foreach ( $links as $link ) { + $link_id = (int) $link->link_id; + $term_id = (int) $link->category_id; + $taxonomy = 'link_category'; + $tt_id = $tt_ids[$term_id][$taxonomy]; + if ( empty($tt_id) ) + continue; + + $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link_id', '$tt_id')"); + } + } + + if ( $wp_current_db_version < 4772 ) { + // Obsolete linkcategories table + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories'); + } + + // Recalculate all counts + $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy"); + foreach ( (array) $terms as $term ) { + if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = '$term->term_taxonomy_id'"); + else + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term->term_taxonomy_id'"); + $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term->term_taxonomy_id'"); + } +} + +function upgrade_230_options_table() { + global $wpdb; + $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' ); + $wpdb->hide_errors(); + foreach ( $old_options_fields as $old ) + $wpdb->query("ALTER TABLE $wpdb->options DROP $old"); + $wpdb->show_errors(); +} + +function upgrade_230_old_tables() { + global $wpdb; + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat'); + $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat'); +} + +function upgrade_old_slugs() { + // upgrade people who were using the Redirect Old Slugs plugin + global $wpdb; + $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_wp_old_slug' WHERE meta_key = 'old_slug'"); +} + + +// The functions we use to actually do stuff + +// General +function maybe_create_table($table_name, $create_ddl) { + global $wpdb; + foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { + if ($table == $table_name) { + return true; + } + } + //didn't find it try to create it. + $q = $wpdb->query($create_ddl); + // we cannot directly tell that whether this succeeded! + foreach ($wpdb->get_col("SHOW TABLES",0) as $table ) { + if ($table == $table_name) { + return true; + } + } + return false; +} + +function drop_index($table, $index) { + global $wpdb; + $wpdb->hide_errors(); + $wpdb->query("ALTER TABLE `$table` DROP INDEX `$index`"); + // Now we need to take out all the extra ones we may have created + for ($i = 0; $i < 25; $i++) { + $wpdb->query("ALTER TABLE `$table` DROP INDEX `{$index}_$i`"); + } + $wpdb->show_errors(); + return true; +} + +function add_clean_index($table, $index) { + global $wpdb; + drop_index($table, $index); + $wpdb->query("ALTER TABLE `$table` ADD INDEX ( `$index` )"); + return true; +} + +/** + ** maybe_add_column() + ** Add column to db table if it doesn't exist. + ** Returns: true if already exists or on successful completion + ** false on error + */ +function maybe_add_column($table_name, $column_name, $create_ddl) { + global $wpdb, $debug; + foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { + if ($debug) echo("checking $column == $column_name
    "); + if ($column == $column_name) { + return true; + } + } + //didn't find it try to create it. + $q = $wpdb->query($create_ddl); + // we cannot directly tell that whether this succeeded! + foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { + if ($column == $column_name) { + return true; + } + } + return false; +} + + +// get_alloptions as it was for 1.2. +function get_alloptions_110() { + global $wpdb; + if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) { + foreach ($options as $option) { + // "When trying to design a foolproof system, + // never underestimate the ingenuity of the fools :)" -- Dougal + if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); + if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); + if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); + $all_options->{$option->option_name} = stripslashes($option->option_value); + } + } + return $all_options; +} + +// Version of get_option that is private to install/upgrade. +function __get_option($setting) { + global $wpdb; + + if ( $setting == 'home' && defined( 'WP_HOME' ) ) { + return preg_replace( '|/+$|', '', constant( 'WP_HOME' ) ); + } + + if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) { + return preg_replace( '|/+$|', '', constant( 'WP_SITEURL' ) ); + } + + $option = $wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'"); + + if ( 'home' == $setting && '' == $option ) + return __get_option('siteurl'); + + if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting ) + $option = preg_replace('|/+$|', '', $option); + + @ $kellogs = unserialize($option); + if ($kellogs !== FALSE) + return $kellogs; + else + return $option; +} + +function deslash($content) { + // Note: \\\ inside a regex denotes a single backslash. + + // Replace one or more backslashes followed by a single quote with + // a single quote. + $content = preg_replace("/\\\+'/", "'", $content); + + // Replace one or more backslashes followed by a double quote with + // a double quote. + $content = preg_replace('/\\\+"/', '"', $content); + + // Replace one or more backslashes with one backslash. + $content = preg_replace("/\\\+/", "\\", $content); + + return $content; +} + +function dbDelta($queries, $execute = true) { + global $wpdb; + + // Seperate individual queries into an array + if( !is_array($queries) ) { + $queries = explode( ';', $queries ); + if('' == $queries[count($queries) - 1]) array_pop($queries); + } + + $cqueries = array(); // Creation Queries + $iqueries = array(); // Insertion Queries + $for_update = array(); + + // Create a tablename index for an array ($cqueries) of queries + foreach($queries as $qry) { + if(preg_match("|CREATE TABLE ([^ ]*)|", $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 ( (array) $indices as $index ) { + // Push a query line into $cqueries that adds the index to that table + $cqueries[] = "ALTER TABLE {$table} ADD $index"; + $for_update[$table.'.'.$fieldname] = 'Added index '.$table.' '.$index; + } + + // Remove the original table creation query from processing + unset($cqueries[strtolower($table)]); + unset($for_update[strtolower($table)]); + } else { + // This table exists in the database, but not in the creation queries? + } + } + } + + $allqueries = array_merge($cqueries, $iqueries); + if($execute) { + foreach($allqueries as $query) { + //echo "
    ".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 (strpos($index, 'WP_USE_THEMES') !== false) { + if (! @copy(ABSPATH . 'wp-content/themes/default/index.php', "$site_dir/$newfile")) + return false; + continue; // Don't copy anything + } + } + + if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) + return false; + + chmod("$site_dir/$newfile", 0777); + + // Update the blog header include in each file. + $lines = explode("\n", implode('', file("$site_dir/$newfile"))); + if ($lines) { + $f = fopen("$site_dir/$newfile", 'w'); + + foreach ($lines as $line) { + if (preg_match('/require.*wp-blog-header/', $line)) + $line = '//' . $line; + + // Update stylesheet references. + $line = str_replace("/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 = @ opendir("$default_dir"); + if ($theme_dir) { + while(($theme_file = readdir( $theme_dir )) !== false) { + if (is_dir("$default_dir/$theme_file")) + continue; + if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) + return; + chmod("$site_dir/$theme_file", 0777); + } + } + @closedir($theme_dir); + + // Rewrite the theme header. + $stylelines = explode("\n", implode('', file("$site_dir/style.css"))); + if ($stylelines) { + $f = fopen("$site_dir/style.css", 'w'); + + foreach ($stylelines as $line) { + if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; + elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); + elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; + elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; + elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; + fwrite($f, $line . "\n"); + } + fclose($f); + } + + // Copy the images. + umask(0); + if (! mkdir("$site_dir/images", 0777)) { + return false; + } + + $images_dir = @ opendir("$default_dir/images"); + if ($images_dir) { + while(($image = readdir($images_dir)) !== false) { + if (is_dir("$default_dir/images/$image")) + continue; + if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) + return; + chmod("$site_dir/images/$image", 0777); + } + } + @closedir($images_dir); +} + +// Create a site theme from the default theme. +function make_site_theme() { + // Name the theme after the blog. + $theme_name = __get_option('blogname'); + $template = sanitize_title($theme_name); + $site_dir = ABSPATH . "wp-content/themes/$template"; + + // If the theme already exists, nothing to do. + if ( is_dir($site_dir)) { + return false; + } + + // We must be able to write to the themes dir. + if (! is_writable(ABSPATH . "wp-content/themes")) { + return false; + } + + umask(0); + if (! mkdir($site_dir, 0777)) { + return false; + } + + if (file_exists(ABSPATH . 'wp-layout.css')) { + if (! make_site_theme_from_oldschool($theme_name, $template)) { + // TODO: rm -rf the site theme directory. + return false; + } + } else { + if (! make_site_theme_from_default($theme_name, $template)) + // TODO: rm -rf the site theme directory. + return false; + } + + // Make the new site theme active. + $current_template = __get_option('template'); + if ($current_template == 'default') { + update_option('template', $template); + update_option('stylesheet', $template); + } + return $template; +} + +function translate_level_to_role($level) { + switch ($level) { + case 10: + case 9: + case 8: + return 'administrator'; + case 7: + case 6: + case 5: + return 'editor'; + case 4: + case 3: + case 2: + return 'author'; + case 1: + return 'contributor'; + case 0: + return 'subscriber'; + } +} + +function wp_check_mysql_version() { + global $wp_version; + + // Make sure the server has MySQL 4.0 + $mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info()); + if ( version_compare($mysql_version, '4.0.0', '<') ) + die(sprintf(__('ERROR: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version)); +} + +function maybe_disable_automattic_widgets() { + $plugins = __get_option( 'active_plugins' ); + + foreach ( (array) $plugins as $plugin ) { + if ( basename( $plugin ) == 'widgets.php' ) { + array_splice( $plugins, array_search( $plugin, $plugins ), 1 ); + update_option( 'active_plugins', $plugins ); + break; + } + } +} + +?> diff --git a/wp-admin/includes/upload.php b/wp-admin/includes/upload.php new file mode 100644 index 00000000..0f37db78 --- /dev/null +++ b/wp-admin/includes/upload.php @@ -0,0 +1,358 @@ +post_content )); + + $class = 'text'; + $innerHTML = get_attachment_innerHTML( $id, false, $dims ); + if ( $image_src = get_attachment_icon_src() ) { + $image_rel = wp_make_link_relative($image_src); + $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); + $class = 'image'; + } + + $src_base = wp_get_attachment_url(); + $src = wp_make_link_relative( $src_base ); + $src_base = str_replace($src, '', $src_base); + + if ( !trim($post_title) ) + $post_title = basename($src); + + $r = ''; + + if ( $href ) + $r .= "\n"; + if ( $href || $image_src ) + $r .= "\t\t\t$innerHTML"; + if ( $href ) + $r .= "\n"; + $size = @filesize($filesystem_path); + if ( !empty($size) ) + $r .= "\t\t\t\t".size_format($size)."\n"; + $r .= "\n\t\t
    \n\t\t\t

    \n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + + if ( !$thumb_base = wp_get_attachment_thumb_url() ) + $thumb_base = wp_mime_type_icon(); + if ( $thumb_base ) { + $thumb_rel = wp_make_link_relative( $thumb_base ); + $thumb_base = str_replace( $thumb_rel, '', $thumb_base ); + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + } + + $r .= "\t\t\t\t\n"; + + if ( isset($width) ) { + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + } + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t

    \n\t\t
    \n"; + return $r; +} + +function wp_upload_view() { + global $style, $post_id, $style; + $id = get_the_ID(); + $attachment_data = wp_get_attachment_metadata( $id ); +?> +
    +
    +

    "; + the_title(); + if ( !isset($attachment_data['width']) && 'inline' != $style ) + echo ''; + ?>

    + ' . __('view') . ''; + echo ' | '; + echo '' . __('edit') . ''; + echo ' | '; + echo '' . __('cancel') . ''; + echo ' ]'; ?> +
    + +
    +"; + echo wp_upload_display( array(171, 128) ); + if ( isset($attachment_data['width']) && 'inline' != $style ) + echo ''; ?> +
    + +
    +\n"; +} + +function wp_upload_form() { + $id = get_the_ID(); + global $post_id, $tab, $style; + $enctype = $id ? '' : ' enctype="multipart/form-data"'; + $post_id = (int) $post_id; +?> + id="upload-file" method="post" action=""> + +
    +

    "; + the_title(); + if ( !isset($attachment_data['width']) && 'inline' != $style ) + echo ''; + ?>

    + ' . __('view') . ''; + echo ' | '; + echo '' . __('links') . ''; + echo ' | '; + echo '' . __('cancel') . ''; + echo ' ]'; ?> +
    + +
    +"; + echo wp_upload_display( array(171, 128) ); + if ( isset($attachment_data['width']) && 'inline' != $style ) + echo ''; ?> +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
    + +
    +
    + +" + . __('Browse Files') . '' + ); + + $overrides = array('action'=>'upload'); + + $file = wp_handle_upload($_FILES['image'], $overrides); + + if ( isset($file['error']) ) + wp_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' => $post_title, + 'post_content' => $post_content, + 'post_type' => 'attachment', + 'post_parent' => $post_id, + 'post_mime_type' => $type, + 'guid' => $url + ); + + // Save the data + $id = wp_insert_attachment($attachment, $file, $post_id); + + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=browse&action=view&ID=$id&post_id=$post_id"); + die; + break; + + case 'save' : + global $from_tab, $post_id, $style; + if ( !$from_tab ) + $from_tab = 'upload'; + check_admin_referer( 'inlineuploading' ); + + wp_update_post($_POST); + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id"); + die; + break; + + case 'delete' : + global $ID, $post_id, $from_tab, $style; + if ( !$from_tab ) + $from_tab = 'upload'; + + check_admin_referer( 'inlineuploading' ); + + if ( !current_user_can('edit_post', (int) $ID) ) + wp_die( __('You are not allowed to delete this attachment.') + . " " + . __('Go back') . '' + ); + + wp_delete_attachment($ID); + + wp_redirect( get_option('siteurl') . "/wp-admin/upload.php?style=$style&tab=$from_tab&post_id=$post_id" ); + die; + break; + + endswitch; +} + +add_action( 'upload_files_upload', 'wp_upload_tab_upload_action' ); + +function wp_upload_grab_attachments( $obj ) { + $obj->is_attachment = true; +} + +function wp_upload_posts_where( $where ) { + global $post_id; + return $where . " AND post_parent = '" . (int) $post_id . "'"; +} + +function wp_upload_tab_browse() { + global $action, $paged; + $old_vars = compact( 'paged' ); + + switch ( $action ) : + case 'edit' : + case 'view' : + global $ID; + $attachments = query_posts("attachment_id=$ID"); + if ( have_posts() ) : while ( have_posts() ) : the_post(); + 'edit' == $action ? wp_upload_form() : wp_upload_view(); + endwhile; endif; + break; + default : + global $tab, $post_id, $style; + add_action( 'pre_get_posts', 'wp_upload_grab_attachments' ); + if ( 'browse' == $tab && $post_id ) + add_filter( 'posts_where', 'wp_upload_posts_where' ); + $attachments = query_posts("what_to_show=posts&post_status=any&posts_per_page=10&paged=$paged"); + + echo "
      \n"; + if ( have_posts() ) : while ( have_posts() ) : the_post(); + $href = wp_specialchars( add_query_arg( array( + 'action' => 'inline' == $style ? 'view' : 'edit', + 'ID' => get_the_ID()) + ), 1 ); + + echo "\t
    • \n"; + echo wp_upload_display( array(128,128), $href ); + echo "\t
    • \n"; + endwhile; + else : + echo "\t
    • " . __('There are no attachments to show.') . "
    • \n"; + endif; + echo "
    \n\n"; + + echo "
    \n"; + break; + endswitch; + + extract($old_vars); +} + + +function wp_upload_tab_browse_action() { + global $style; + if ( 'inline' == $style ) + wp_enqueue_script('upload'); +} + +add_action( 'upload_files_browse', 'wp_upload_tab_browse_action' ); +add_action( 'upload_files_browse-all', 'wp_upload_tab_browse_action' ); + +function wp_upload_admin_head() { + wp_admin_css( 'css/upload' ); + if ( 'inline' == @$_GET['style'] ) { + echo ""; + } +} + +?> diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php new file mode 100644 index 00000000..ccf1fb09 --- /dev/null +++ b/wp-admin/includes/user.php @@ -0,0 +1,282 @@ +id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) { + $user = new WP_User( $user_id ); + $user->set_role( $_POST['role'] ); + } + } + } else { + add_action( 'user_register', 'add_user' ); // See above + return edit_user(); + } +} + +function edit_user( $user_id = 0 ) { + global $current_user, $wp_roles, $wpdb; + if ( $user_id != 0 ) { + $update = true; + $user->ID = (int) $user_id; + $userdata = get_userdata( $user_id ); + $user->user_login = $wpdb->escape( $userdata->user_login ); + } else { + $update = false; + $user = ''; + } + + if ( isset( $_POST['user_login'] )) + $user->user_login = wp_specialchars( trim( $_POST['user_login'] )); + + $pass1 = $pass2 = ''; + if ( isset( $_POST['pass1'] )) + $pass1 = $_POST['pass1']; + if ( isset( $_POST['pass2'] )) + $pass2 = $_POST['pass2']; + + if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { + if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' )) + $user->role = $_POST['role']; + } + + if ( isset( $_POST['email'] )) + $user->user_email = wp_specialchars( trim( $_POST['email'] )); + if ( isset( $_POST['url'] ) ) { + $user->user_url = clean_url( trim( $_POST['url'] )); + $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; + } + if ( isset( $_POST['first_name'] )) + $user->first_name = wp_specialchars( trim( $_POST['first_name'] )); + if ( isset( $_POST['last_name'] )) + $user->last_name = wp_specialchars( trim( $_POST['last_name'] )); + if ( isset( $_POST['nickname'] )) + $user->nickname = wp_specialchars( trim( $_POST['nickname'] )); + if ( isset( $_POST['display_name'] )) + $user->display_name = wp_specialchars( trim( $_POST['display_name'] )); + if ( isset( $_POST['description'] )) + $user->description = trim( $_POST['description'] ); + if ( isset( $_POST['jabber'] )) + $user->jabber = wp_specialchars( trim( $_POST['jabber'] )); + if ( isset( $_POST['aim'] )) + $user->aim = wp_specialchars( trim( $_POST['aim'] )); + if ( isset( $_POST['yim'] )) + $user->yim = wp_specialchars( trim( $_POST['yim'] )); + if ( !$update ) + $user->rich_editing = 'true'; // Default to true for new users. + else if ( isset( $_POST['rich_editing'] ) ) + $user->rich_editing = $_POST['rich_editing']; + else + $user->rich_editing = 'false'; + + $errors = new WP_Error(); + + /* checking that username has been typed */ + if ( $user->user_login == '' ) + $errors->add( 'user_login', __( 'ERROR: Please enter a username.' )); + + /* checking the password has been typed twice */ + do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); + + if (!$update ) { + if ( $pass1 == '' || $pass2 == '' ) + $errors->add( 'pass', __( '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 ( !$update && !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_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_editable_authors( $user_id ) { + global $wpdb; + + $editable = get_editable_user_ids( $user_id ); + + if( !$editable ) { + return false; + } else { + $editable = join(',', $editable); + $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" ); + } + + return apply_filters('get_editable_authors', $authors); +} + +function get_editable_user_ids( $user_id, $exclude_zeros = true ) { + global $wpdb; + + $user = new WP_User( $user_id ); + + if ( ! $user->has_cap('edit_others_posts') ) { + if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) + return array($user->id); + else + return false; + } + + $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_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 get_others_unpublished_posts($user_id, $type='any') { + global $wpdb; + $user = get_userdata( $user_id ); + $level_key = $wpdb->prefix . 'user_level'; + + $editable = get_editable_user_ids( $user_id ); + + if ( in_array($type, array('draft', 'pending')) ) + $type_sql = " post_status = '$type' "; + else + $type_sql = " ( post_status = 'draft' OR post_status = 'pending' ) "; + + $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC'; + + if( !$editable ) { + $other_unpubs = ''; + } else { + $editable = join(',', $editable); + $other_unpubs = $wpdb->get_results("SELECT ID, post_title, post_author FROM $wpdb->posts WHERE post_type = 'post' AND $type_sql AND post_author IN ($editable) AND post_author != '$user_id' ORDER BY post_modified $dir"); + } + + return apply_filters('get_others_drafts', $other_unpubs); +} + +function get_others_drafts($user_id) { + return get_others_unpublished_posts($user_id, 'draft'); +} + +function get_others_pending($user_id) { + return get_others_unpublished_posts($user_id, 'pending'); +} + +function get_user_to_edit( $user_id ) { + $user = new WP_User( $user_id ); + $user->user_login = attribute_escape($user->user_login); + $user->user_email = attribute_escape($user->user_email); + $user->user_url = clean_url($user->user_url); + $user->first_name = attribute_escape($user->first_name); + $user->last_name = attribute_escape($user->last_name); + $user->display_name = attribute_escape($user->display_name); + $user->nickname = attribute_escape($user->nickname); + $user->aim = attribute_escape($user->aim); + $user->yim = attribute_escape($user->yim); + $user->jabber = attribute_escape($user->jabber); + $user->description = wp_specialchars($user->description); + + return $user; +} + +function get_users_drafts( $user_id ) { + global $wpdb; + $user_id = (int) $user_id; + $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author = $user_id ORDER BY post_modified DESC"; + $query = apply_filters('get_users_drafts', $query); + return $wpdb->get_results( $query ); +} + +function wp_delete_user($id, $reassign = 'novalue') { + global $wpdb; + + $id = (int) $id; + $user = get_userdata($id); + + if ($reassign == 'novalue') { + $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id"); + + if ($post_ids) { + foreach ($post_ids as $post_id) + wp_delete_post($post_id); + } + + // Clean links + $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id"); + } else { + $reassign = (int) $reassign; + $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}"); + $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}"); + } + + // FINALLY, delete user + do_action('delete_user', $id); + + $wpdb->query("DELETE FROM $wpdb->users WHERE ID = $id"); + $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = '$id'"); + + wp_cache_delete($id, 'users'); + wp_cache_delete($user->user_login, 'userlogins'); + + return true; +} + +function wp_revoke_user($id) { + $id = (int) $id; + + $user = new WP_User($id); + $user->remove_all_caps(); +} + +?> \ No newline at end of file diff --git a/wp-admin/index-extra.php b/wp-admin/index-extra.php new file mode 100644 index 00000000..31f2a581 --- /dev/null +++ b/wp-admin/index-extra.php @@ -0,0 +1,73 @@ +items) && 1 < count($rss->items) ) { // Technorati returns a 1-item feed when it has no results +?> +

    +
      +items = array_slice($rss->items, 0, 10); +foreach ($rss->items as $item ) { +?> +
    • + +
    +items) && 0 != count($rss->items) ) { +?> +

    +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 ) { +$title = wp_specialchars($item['title']); +$author = preg_replace( '|(.+?):.+|s', '$1', $item['title'] ); +$post = preg_replace( '|.+?:(.+)|s', '$1', $item['title'] ); +?> +
    • '>
    • + +
    +

    + \ No newline at end of file diff --git a/wp-admin/index.php b/wp-admin/index.php index 734b349e..2447e2fe 100644 --- a/wp-admin/index.php +++ b/wp-admin/index.php @@ -1,35 +1,36 @@ + +
    -

    +

    -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"); @@ -38,18 +39,18 @@ $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE commen if ( $comments || $numcomments ) : ?>
    -

    »

    +

    »' ), 'edit-comments.php' ); ?>

    -

    »

    +

      -' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '' . get_the_title($comment->comment_post_ID) . ''); - edit_comment_link(__("Edit"), ' (', ')'); + edit_comment_link(__("Edit"), ' (', ')'); echo ''; } } @@ -58,12 +59,11 @@ foreach ($comments as $comment) {
    - get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) : +if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql('post') . " AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 5") ) : ?>
    -

    »

    +

    »' ), 'edit.php' ); ?>

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

        @@ -90,7 +90,7 @@ foreach ($scheduled as $post) { $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') )) . "
      • "; } -?> +?>
      @@ -98,70 +98,43 @@ foreach ($scheduled as $post) {

      get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE 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); +$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); +$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); +$numcats = wp_count_terms('category'); +$numtags = wp_count_terms('post_tag'); -$numcats = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->categories"); -if (0 < $numcats) $numcats = number_format($numcats); +$post_str = sprintf(__ngettext('%1$s post', '%1$s posts', $numposts), number_format_i18n($numposts), 'edit.php'); +$comm_str = sprintf(__ngettext('%1$s comment', '%1$s comments', $numcomms), number_format_i18n($numcomms), 'edit-comments.php'); +$cat_str = sprintf(__ngettext('%1$s category', '%1$s categories', $numcats), number_format_i18n($numcats), 'categories.php'); +$tag_str = sprintf(__ngettext('%1$s tag', '%1$s tags', $numtags), number_format_i18n($numtags)); ?> -

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

      + +

    -

    -

      -
    • -
    • -
    • -
    • + +
    • + +
    • + +
    • + + +
    • +
    +

    documentation or visit the support forums."); ?>

    -

    great documentation or if that doesn't help visit the support forums."); ?>

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

    -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 deleted file mode 100644 index 212f1159..00000000 --- a/wp-admin/inline-uploading.php +++ /dev/null @@ -1,724 +0,0 @@ -".__('Go back').''); - -wp_delete_attachment($attachment); - -wp_redirect(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']) ) - 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_status' => '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()); -} - -wp_redirect(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_status = '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_status = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A); - -if ( count($attachments) == 0 ) { - wp_redirect( 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 = attribute_escape($image['post_title']); - $script .= "aa[{$ID}] = ''; -ab[{$ID}] = ''; -imga[{$ID}] = '\"{$title}\"'; -imgb[{$ID}] = '\"{$title}\"'; -"; - $html .= "
    -
    - \"{$title}\" -
    - {$noscript} -
    -"; - $popups .= "
    -"; - } else { - $title = attribute_escape($attachment['post_title']); - $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_status = 'attachment'")) { ?> ->"> - -
    • - - -
    • " title="">|«
    • -
    • ">«
    • - -
    • -
    • «
    • - - -
    • ">
    • -
    • " title="">»|
    • - -
    • »
    • -
    • »|
    • - - -
    - -
    - -
    - - -
    -
    - -
    -
    - - - - - - - - - - - - - - - - - -
    - - - - - -
    - - - - -
    -
    -
    - - - - - diff --git a/wp-admin/install-helper.php b/wp-admin/install-helper.php index 86138db1..ecfc91d5 100644 --- a/wp-admin/install-helper.php +++ b/wp-admin/install-helper.php @@ -9,21 +9,21 @@ $debug = 0; ** false on error */ 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; + 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; } /** @@ -33,22 +33,22 @@ function maybe_create_table($table_name, $create_ddl) { ** 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; + 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; } @@ -59,21 +59,21 @@ function maybe_add_column($table_name, $column_name, $create_ddl) { ** 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; + 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; } @@ -92,45 +92,45 @@ function maybe_drop_column($table_name, $column_name, $drop_ddl) { ** 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; + 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'); 
    +//check_column('wp_links', 'link_description', 'mediumtext');
     //if (check_column($wpdb->comments, 'comment_author', 'tinytext'))
     //    echo "ok\n";
     $error_count = 0;
    @@ -138,14 +138,14 @@ $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);
    +	$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 
    '; + $res .= $tablename . ' - ok
    '; } else { - $res .= 'There was a problem with ' . $tablename . '
    '; - ++$error_count; + $res .= 'There was a problem with ' . $tablename . '
    '; + ++$error_count; } echo "
    "; */ diff --git a/wp-admin/install.php b/wp-admin/install.php index eb635aa2..6f4d7e3e 100644 --- a/wp-admin/install.php +++ b/wp-admin/install.php @@ -1,225 +1,113 @@ wp-config.php file. I need this before we can get started. Need more help? We got it. You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file."); +if (!file_exists('../wp-config.php')) { + require_once('../wp-includes/compat.php'); + require_once('../wp-includes/functions.php'); + wp_die("There doesn't seem to be a wp-config.php file. I need this before we can get started. Need more help? We got it. You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress › Error"); +} require_once('../wp-config.php'); -require_once('./upgrade-functions.php'); - -$schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; -$guessurl = str_replace('/wp-admin/install.php?step=2', '', $schema . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) ); +require_once('./includes/upgrade.php'); if (isset($_GET['step'])) $step = $_GET['step']; else $step = 0; +function display_header(){ header( 'Content-Type: text/html; charset=utf-8' ); ?> - +> - <?php _e('WordPress › Installation'); ?> - + <?php _e('WordPress › Installation'); ?> +

    WordPress

    + hide_errors(); -$installed = $wpdb->get_results("SELECT * FROM $wpdb->users"); -if ($installed) die('

    '.__('Already Installed').'

    '.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'

    '); -$wpdb->show_errors(); +if ( is_blog_installed() ) {display_header(); die('

    '.__('Already Installed').'

    '.__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.').'

    ');} switch($step) { - case 0: + case 1: // in case people are directly linking to this + display_header(); ?> -

    ReadMe documentation at your leisure.'), '../readme.html'); ?>

    -

    - +

    ReadMe documentation at your leisure. Otherwise, just fill in the information below and you\'ll be on your way to using the most extendable and powerful personal publishing platform in the world.'), '../readme.html'); ?>

    + - case 1: - -?> -

    -

    +

    +

    - - - - - - - - - -
    -

    -

    - -

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

    +

    ERROR: please type your e-mail address")); -} else if (!is_email($admin_email)) { - die (__("ERROR: the e-mail address isn't correct")); -} - + if ( !empty($wpdb->error) ) + wp_die($wpdb->error->get_error_message()); + + display_header(); + // Fill in the data we gathered + $weblog_title = stripslashes($_POST['weblog_title']); + $admin_email = stripslashes($_POST['admin_email']); + $public = (int) $_POST['blog_public']; + // check e-mail address + if (empty($admin_email)) { + // TODO: poka-yoke + die(__("ERROR: you must provide an e-mail address")); + } else if (!is_email($admin_email)) { + // TODO: poka-yoke + die(__('ERROR: that isn\'t a valid e-mail address. E-mail addresses look like: username@example.com')); + } + + $wpdb->show_errors(); + $result = wp_install($weblog_title, 'admin', $admin_email, $public); + extract($result, EXTR_SKIP); ?> -

    -

    - - -query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name) VALUES (1, '".$wpdb->escape(__('Blogroll'))."')"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://blogs.linux.ie/xeer/', 'Donncha', 1, 'http://blogs.linux.ie/xeer/feed/', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zengun.org/weblog/', 'Michel', 1, 'http://zengun.org/weblog/feed/', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://boren.nu/', 'Ryan', 1, 'http://boren.nu/feed/', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://photomatt.net/', 'Matt', 1, 'http://xml.photomatt.net/feed/', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://zed1.com/journalized/', 'Mike', 1, 'http://zed1.com/journalized/feed/', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://www.alexking.org/', 'Alex', 1, 'http://www.alexking.org/blog/wp-rss2.php', '');"); -$wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://dougal.gunters.org/', 'Dougal', 1, 'http://dougal.gunters.org/feed/', '');"); +

    -// 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', '')"); +

    log in with the username "admin" and password "%2$s".'), '../wp-login.php', $password); ?>

    +

    Note that password carefully! It is a random password that was generated just for you.'); ?>

    -// 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 ('1', '$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 post's comments. There you will have the option to edit or delete them.'))."')"); - -// First Page -$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('1', '$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', 'static', '', '', '')"); -$wp_rewrite->flush_rules(); - -// Set up admin user -$random_password = substr(md5(uniqid(microtime())), 0, 6); -$display_name_array = explode('@', $admin_email); -$display_name = $display_name_array[0]; -$wpdb->query("INSERT INTO $wpdb->users (ID, user_login, user_pass, user_email, user_registered, display_name, user_nicename) VALUES ( '1', 'admin', MD5('$random_password'), '$admin_email', NOW(), '$display_name', 'admin')"); -$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}user_level', '10');"); -$admin_caps = serialize(array('administrator' => true)); -$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ({$wpdb->insert_id}, '{$table_prefix}capabilities', '{$admin_caps}');"); - -$message_headers = 'From: "' . $weblog_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: admin -Password: %2\$s - -We hope you enjoy your new weblog. Thanks! - ---The WordPress Team -http://wordpress.org/ -"), $guessurl, $random_password); - -@wp_mail($admin_email, __('New WordPress Blog'), $message, $message_headers); - -wp_cache_flush(); -?> - -

    - -

    log in with the username "admin" and password "%2$s".'), '../wp-login.php', $random_password); ?>

    -

    Note that password carefully! It is a random password that was generated just for you. If you lose it, you will have to delete the tables from the database yourself, and re-install WordPress. So to review:'); ?> -

    -
    -
    admin
    -
    -
    +
    +
    admin
    +
    +
    -
    wp-login.php
    +
    wp-login.php
    -

    +

    + + - + \ No newline at end of file diff --git a/wp-admin/js/cat.js b/wp-admin/js/cat.js new file mode 100644 index 00000000..e697e9b4 --- /dev/null +++ b/wp-admin/js/cat.js @@ -0,0 +1,11 @@ +addLoadEvent(function(){catList=new listMan('categorychecklist');catList.ajaxRespEl='jaxcat';catList.topAdder=1;catList.alt=0;catList.showLink=0;}); +addLoadEvent(newCatAddIn); +function newCatAddIn() { + var jaxcat = $('jaxcat'); + if ( !jaxcat ) + return false; + // These multiple blank hidden inputs are needed: https://bugzilla.mozilla.org/show_bug.cgi?id=377815 , #3895 , #4664 + Element.update(jaxcat,'' + catL10n.how + ''); + $('newcat').onkeypress = function(e) { return killSubmit("catList.ajaxAdder('category','jaxcat');", e); }; + $('catadd').onclick = function() { catList.ajaxAdder('category', 'jaxcat'); }; +} diff --git a/wp-admin/js/categories.js b/wp-admin/js/categories.js new file mode 100644 index 00000000..3cee6c68 --- /dev/null +++ b/wp-admin/js/categories.js @@ -0,0 +1,16 @@ +addLoadEvent(function() { + if (!theList.theList) return false; + document.forms.addcat.submit.onclick = function(e) {return killSubmit('theList.ajaxAdder("cat", "addcat");', e); }; + theList.addComplete = function(what, where, update, transport) { + var name = getNodeValue(transport.responseXML, 'name').unescapeHTML(); + var id = transport.responseXML.getElementsByTagName(what)[0].getAttribute('id'); + var options = document.forms['addcat'].category_parent.options; + options[options.length] = new Option(name, id); + }; + theList.delComplete = function(what, id) { + var options = document.forms['addcat'].category_parent.options; + for ( var o = 0; o < options.length; o++ ) + if ( id == options[o].value ) + options[o] = null; + }; +}); diff --git a/wp-admin/js/custom-fields.js b/wp-admin/js/custom-fields.js new file mode 100644 index 00000000..ad7a2db1 --- /dev/null +++ b/wp-admin/js/custom-fields.js @@ -0,0 +1,26 @@ +function customFieldsOnComplete( what, where, update, transport ) { + var pidEl = $('post_ID'); + pidEl.name = 'post_ID'; + pidEl.value = getNodeValue(transport.responseXML, 'postid'); + var aEl = $('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); }; + } + } + + $('metakeyinput').onkeypress = function(e) {return killSubmit('theList.inputData+="&id="+$("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); }; + $('updatemetasub').onclick = function(e) {return killSubmit('theList.inputData+="&id="+$("post_ID").value;theList.ajaxAdder("meta", "newmeta");', e); }; +} diff --git a/wp-admin/js/dbx-admin-key.js b/wp-admin/js/dbx-admin-key.js new file mode 100644 index 00000000..3b3f7af1 --- /dev/null +++ b/wp-admin/js/dbx-admin-key.js @@ -0,0 +1,47 @@ +addLoadEvent( function() {var manager = new dbxManager( dbxL10n.manager );} ); + +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'] + dbxL10n.open, // word for "open", as in "open this box" + dbxL10n.close, // word for "close", as in "close this box" + dbxL10n.moveMouse, // sentence for "move this box" by mouse + dbxL10n.toggleMouse, // pattern-match sentence for "(open|close) this box" by mouse + dbxL10n.moveKey, // sentence for "move this box" by keyboard + dbxL10n.toggleKey, // 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', + 'vertical', + '10', + 'yes', // restrict drag movement to container axis ['yes'|'no'] + '10', + 'yes', + 'closed', + dbxL10n.open, + dbxL10n.close, + dbxL10n.moveMouse, + dbxL10n.toggleMouse, + dbxL10n.moveKey, + dbxL10n.toggleKey, + '%mytitle% [%dbxtitle%]' // pattern-match syntax for title-attribute conflicts + ); +}); diff --git a/wp-admin/js/edit-comments.js b/wp-admin/js/edit-comments.js new file mode 100644 index 00000000..e1fc68fe --- /dev/null +++ b/wp-admin/js/edit-comments.js @@ -0,0 +1,59 @@ +addLoadEvent(function() { + theCommentList = new listMan('the-comment-list'); + if ( !theCommentList ) + return false; + + theExtraCommentList = new listMan('the-extra-comment-list'); + if ( theExtraCommentList ) { + theExtraCommentList.showLink = 0; + theExtraCommentList.altOffset = 1; + if ( theExtraCommentList.theList && theExtraCommentList.theList.childNodes ) + var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length; + else + var commentNum = 0; + var urlQ = document.location.href.split('?'); + var params = urlQ[1] ? urlQ[1].toQueryParams() : []; + var search = params['s'] ? params['s'] : ''; + var page = params['apage'] ? params['apage'] : 1; + } + + 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'); + what = what.split('-')[0]; + if ( document.getElementById(what + '-' + id).className.match('unapproved') ) + m.innerHTML = parseInt(m.innerHTML,10) - 1; + if ( theExtraCommentList && commentNum ) { + var theMover = theExtraCommentList.theList.childNodes[0]; + Element.removeClassName(theMover,'alternate'); + theCommentList.theList.appendChild(theMover); + theExtraCommentList.inputData += '&page=' + page; + if ( search ) + theExtraCommentList.inputData += '&s=' + search; // trust the URL not the search box + theExtraCommentList.addComplete = function() { + if ( theExtraCommentList.theList.childNodes ) + var commentNum = $A(theExtraCommentList.theList.childNodes).findAll( function(i) { return Element.visible(i) } ).length; + else + var commentNum = 0; + } + theExtraCommentList.ajaxAdder( 'comment', 'ajax-response' ); // Dummy Request + } + } + + 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/js/link-cat.js b/wp-admin/js/link-cat.js new file mode 100644 index 00000000..a0775ce1 --- /dev/null +++ b/wp-admin/js/link-cat.js @@ -0,0 +1,10 @@ +addLoadEvent(function(){linkcatList=new listMan('linkcategorychecklist');linkcatList.ajaxRespEl='jaxcat';linkcatList.topAdder=1;linkcatList.alt=0;linkcatList.showLink=0;}); +addLoadEvent(newLinkCatAddIn); +function newLinkCatAddIn() { + var jaxcat = $('jaxcat'); + if ( !jaxcat ) + return false; + Element.update(jaxcat,'' + linkcatL10n.how + ''); + $('newcat').onkeypress = function(e) { return killSubmit("linkcatList.ajaxAdder('link-category','jaxcat');", e); }; + $('catadd').onclick = function() { linkcatList.ajaxAdder('link-category', 'jaxcat'); }; +} diff --git a/wp-admin/js/upload.js b/wp-admin/js/upload.js new file mode 100644 index 00000000..d38cdcb0 --- /dev/null +++ b/wp-admin/js/upload.js @@ -0,0 +1,295 @@ +addLoadEvent( function() { + theFileList = { + currentImage: {ID: 0}, + nonce: '', + tab: '', + postID: 0, + + toQueryParams: function(qryStrOrig) { + var params = new Object(); + var qryStr = qryStrOrig; + var i = 0; + do { + params[qryStr.split("=")[0].replace(/&/, "")] = ( qryStr.split("=")[1] ) ? qryStr.split("=")[1].split(/&|$/)[0] : ''; + qryStr = ( qryStr.split("=")[1] ) ? qryStr.split(qryStr.split("=")[1].split(/&|$/)[0])[1] : ''; + i++; + } + while(i < (qryStrOrig.split("=").length - 1)); + return params; + }, + + toQueryString: function(params) { + var qryStr = ''; + for ( var key in params ) + qryStr += key + '=' + params[key] + '&'; + return qryStr; + }, + + initializeVars: function() { + this.urlData = document.location.href.split('?'); + this.params = this.toQueryParams(this.urlData[1]); + this.postID = this.params['post_id']; + this.tab = this.params['tab']; + this.style = this.params['style']; + this.ID = this.params['ID']; + if ( !this.style ) + this.style = 'default'; + var nonceEl = jQuery('#nonce-value'); + if ( nonceEl ) + this.nonce = jQuery(nonceEl).val(); + if ( this.ID ) { + this.grabImageData( this.ID ); + this.imageView( this.ID ); + } + }, + + initializeLinks: function() { + if ( this.ID ) + return; + jQuery('a.file-link').each(function() { + var id = jQuery(this).attr('id').split('-').pop(); + jQuery(this).attr('href','javascript:void(0)').click(function(e) { + theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e); + }); + }); + }, + + grabImageData: function(id) { + if ( id == this.currentImage.ID ) + return; + var thumbEl = jQuery('#attachment-thumb-url-' + id); + if ( thumbEl ) { + this.currentImage.thumb = ( 0 == id ? '' : jQuery(thumbEl).val() ); + this.currentImage.thumbBase = ( 0 == id ? '' : jQuery('#attachment-thumb-url-base-' + id).val() ); + } else { + this.currentImage.thumb = false; + } + this.currentImage.src = ( 0 == id ? '' : jQuery('#attachment-url-' + id).val() ); + this.currentImage.srcBase = ( 0 == id ? '' : jQuery('#attachment-url-base-' + id).val() ); + this.currentImage.page = ( 0 == id ? '' : jQuery('#attachment-page-url-' + id).val() ); + this.currentImage.title = ( 0 == id ? '' : jQuery('#attachment-title-' + id).val() ); + this.currentImage.description = ( 0 == id ? '' : jQuery('#attachment-description-' + id).val() ); + var widthEl = jQuery('#attachment-width-' + id); + if ( widthEl ) { + this.currentImage.width = ( 0 == id ? '' : jQuery(widthEl).val() ); + this.currentImage.height = ( 0 == id ? '' : jQuery('#attachment-height-' + id).val() ); + } else { + this.currentImage.width = false; + this.currentImage.height = false; + } + this.currentImage.isImage = ( 0 == id ? 0 : jQuery('#attachment-is-image-' + id).val() ); + this.currentImage.ID = id; + }, + + imageView: function(id, e) { + this.prepView(id); + var h = ''; + + h += "
    " + if ( this.ID ) { + var params = this.params; + params.ID = ''; + params.action = ''; + h += "" + this.back + ""; + h += "
    " + if ( 0 == this.currentImage.isImage ) + h += "

    " + this.currentImage.title + "

    "; + else + h += "

    " + this.currentImage.title + "

    "; + h += " — "; + h += "" + this.edit + "" + h += ""; + h += '
    ' + h += "
    "; + if ( 1 == this.currentImage.isImage ) { + h += ""; + h += "" + this.currentImage.title + ""; + h += ""; + } else + h += ' '; + h += "
    "; + + h += "
    "; + h += ""; + var display = []; + var checked = 'display-title'; + if ( 1 == this.currentImage.isImage ) { + checked = 'display-full'; + if ( this.currentImage.thumb ) { + display.push("
    "); + checked = 'display-thumb'; + } + display.push(""); + } else if ( this.currentImage.thumb ) { + display.push(""); + } + if ( display.length ) { + display.push("
    "); + h += ""; + } + + h += ""; + + h += "
    " + this.show + ""; + jQuery(display).each( function() { h += this; } ); + h += "
    " + this.link + ""; + h += "
    "; + h += "
    "; + h += ""; + h += "

    "; + h += ""; + h += "

    "; + h += "
    "; + + h += "
    "; + + jQuery(h).prependTo('#upload-content'); + jQuery('#' + checked).attr('checked','checked'); + if (e) return e.stopPropagation(); + return false; + }, + + editView: function(id, e) { + this.prepView(id); + var h = ''; + + var action = 'upload.php?style=' + this.style + '&tab=upload'; + if ( this.postID ) + action += '&post_id=' + this.postID; + + h += "
    "; + if ( this.ID ) { + var params = this.params; + params.ID = ''; + params.action = ''; + h += "" + this.back + ""; + h += "
    " + if ( 0 == this.currentImage.isImage ) + h += "

    " + this.currentImage.title + "

    "; + else + h += "

    " + this.currentImage.title + "

    "; + h += " — "; + h += "" + this.insert + ""; + h += ""; + h += '
    ' + h += "
    "; + if ( 1 == this.currentImage.isImage ) { + h += ""; + h += "" + this.currentImage.title + ""; + h += ""; + } else + h += ' '; + h += "
    "; + + + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += "
    "; + h += ""; + h += ""; + h += ""; + h += ""; + h += ""; + h += "
    "; + h += "
    "; + + jQuery(h).prependTo('#upload-content'); + if (e) e.stopPropagation(); + return false; + }, + + prepView: function(id) { + this.cancelView( true ); + var filesEl = jQuery('#upload-files'); + if ( filesEl ) + filesEl.hide(); + var navEl = jQuery('#current-tab-nav'); + if ( navEl ) + navEl.hide(); + this.grabImageData(id); + }, + + cancelView: function( prep ) { + if ( !prep ) { + var filesEl = jQuery('#upload-files'); + if ( filesEl ) + jQuery(filesEl).show(); + var navEl = jQuery('#current-tab-nav'); + if ( navEl ) + jQuery(navEl).show(); + } + if ( !this.ID ) + this.grabImageData(0); + var div = jQuery('#upload-file'); + if ( div ) + jQuery(div).remove(); + return false; + }, + + sendToEditor: function(id) { + this.grabImageData(id); + var link = ''; + var display = ''; + var h = ''; + + link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val(); + displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions'); + if ( displayEl ) + display = jQuery(displayEl).val(); + else if ( 1 == this.currentImage.isImage ) + display = 'full'; + + if ( 'none' != link ) + h += ""; + if ( display && 'title' != display ) + h += "" + this.currentImage.title + ""; + else + h += this.currentImage.title; + if ( 'none' != link ) + h += ""; + + var win = window.opener ? window.opener : window.dialogArguments; + if ( !win ) + win = top; + tinyMCE = win.tinyMCE; + if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) { + tinyMCE.selectedInstance.getWin().focus(); + tinyMCE.execCommand('mceInsertContent', false, h); + } else + win.edInsertContent(win.edCanvas, h); + if ( !this.ID ) + this.cancelView(); + return false; + }, + + deleteFile: function(id) { + if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) { + jQuery('#action-value').attr('value','delete'); + jQuery('#upload-file').submit(); + return true; + } + return false; + } + + }; + + for ( var property in uploadL10n ) + theFileList[property] = uploadL10n[property]; + theFileList.initializeVars(); + theFileList.initializeLinks(); +} ); diff --git a/wp-admin/js/users.js b/wp-admin/js/users.js new file mode 100644 index 00000000..f249f65f --- /dev/null +++ b/wp-admin/js/users.js @@ -0,0 +1,21 @@ +addLoadEvent(function() { + theListEls = document.getElementsByTagName('tbody'); + theUserLists = new Array(); + for ( var l = 0; l < theListEls.length; l++ ) { + if ( theListEls[l].id ) + 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/xfn.js b/wp-admin/js/xfn.js similarity index 86% rename from wp-admin/xfn.js rename to wp-admin/js/xfn.js index 54c82fbf..2fe41eb1 100644 --- a/wp-admin/xfn.js +++ b/wp-admin/js/xfn.js @@ -10,10 +10,10 @@ function GetElementsWithClassName(elementName, className) { } function meChecked() { - var undefined; - var eMe = document.getElementById('me'); - if (eMe == undefined) return false; - else return eMe.checked; + var undefined; + var eMe = document.getElementById('me'); + if (eMe == undefined) return false; + else return eMe.checked; } function upit() { @@ -38,7 +38,7 @@ function blurry() { var aInputs = document.getElementsByTagName('input'); - for (var i = 0; i < aInputs.length; i++) { + for (var i = 0; i < aInputs.length; i++) { aInputs[i].onclick = aInputs[i].onkeyup = upit; } } diff --git a/wp-admin/link-add.php b/wp-admin/link-add.php index 8a6553a2..2b06d8ec 100644 --- a/wp-admin/link-add.php +++ b/wp-admin/link-add.php @@ -6,30 +6,18 @@ $this_file = 'link-manager.php'; $parent_file = 'link-manager.php'; -$wpvarstoreset = array('action', 'cat_id', 'linkurl', 'name', 'image', - 'description', 'visible', 'target', 'category', 'link_id', - 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', - 'notes', 'linkcheck[]'); -for ($i=0; $i - +

    @@ -38,8 +26,10 @@ require('admin-header.php'); include('edit-link-form.php'); ?> -
    -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 links! 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();") ?> + query("INSERT INTO $wpdb->linkcategories (cat_id, cat_name, auto_toggle, show_images, show_description, \n" . - " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, text_after_all, list_limit) \n" . - " VALUES ('0', '$cat_name', '$auto_toggle', '$show_images', '$show_description', \n" . - " '$show_rating', '$show_updated', '$sort_order', '$sort_desc', '$text_before_link', '$text_after_link', \n" . - " '$text_after_all', $list_limit)"); - - wp_redirect('link-categories.php'); - break; - } // end addcat - case 'Delete': - { - $cat_id = (int) $_GET['cat_id']; - check_admin_referer('delete-link-category_' . $cat_id); - - $cat_name=get_linkcatname($cat_id); - - if ($cat_id=="1") - die(sprintf(__("Can't delete the %s link category: this is the default one"), $cat_name)); - - if ( !current_user_can('manage_links') ) - die (__("Cheatin' uh ?")); - - $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$cat_id'"); - $wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$cat_id'"); - - wp_redirect('link-categories.php'); - break; - } // end delete - case 'Edit': - { - include_once ('admin-header.php'); - $cat_id = (int) $_GET['cat_id']; - $row = $wpdb->get_row("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, " - . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, " - . " text_after_all, list_limit FROM $wpdb->linkcategories WHERE cat_id=$cat_id"); - if ($row) { - if ($row->list_limit == -1) { - $row->list_limit = ''; - } -?> - -
    -

    cat_name)); ?>

    - -
    - cat_id) ?> - - -
    - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - title regardless)') ?>
    -
    - -title regardless)') ?>
    - - -
    - - -
    -
    -
    - - - - - - - - - - - - - - -
    -
    -

    -
    - -
    -query("UPDATE $wpdb->linkcategories set - cat_name='$cat_name', - auto_toggle='$auto_toggle', - show_images='$show_images', - show_description='$show_description', - show_rating='$show_rating', - show_updated='$show_updated', - sort_order='$sort_order', - sort_desc='$sort_desc', - text_before_link='$text_before_link', - text_after_link='$text_after_link', - text_after_all='$text_after_all', - list_limit=$list_limit - WHERE cat_id=$cat_id - "); - } // end if save - - - wp_redirect("link-categories.php"); - break; - } // end editcat - default: - { - include_once ("admin-header.php"); - if ( !current_user_can('manage_links') ) - die(__("You have do not have sufficient permissions to edit the link categories for this blog. :)")); -?> - -
    -

    - - - - - - - - - - - - - - - - - - - - - -get_results("SELECT cat_id, cat_name, auto_toggle, show_images, show_description, " - . " show_rating, show_updated, sort_order, sort_desc, text_before_link, text_after_link, " - . " text_after_all, list_limit FROM $wpdb->linkcategories ORDER BY cat_id"); -$i = 1; -foreach ( (array) $results as $row) { - if ($row->list_limit == -1) { - $row->list_limit = __('none'); - } - $style = ($i % 2) ? ' class="alternate"' : ''; - /* - Manually internationalize every sort order option. - */ - switch ($row->sort_order) { - case 'name': - $row->sort_order = __('name'); - break; - case 'id': - $row->sort_order = __('id'); - break; - case 'url': - $row->sort_order = __('url'); - break; - case 'rating': - $row->sort_order = __('rating'); - break; - case 'updated': - $row->sort_order = __('updated'); - break; - case 'rand': - $row->sort_order = __('rand'); - break; - case 'length': - $row->sort_order = __('length'); - break; - } -?> - style="border-bottom: 1px dotted #9C9A9C;"> - - - - - - - - - - - - - - - - - -
     
    -

    - -
    - -
    - -
    -
    - - -

    -
    - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - title regardless)') ?>
    -
    - -title regardless)') ?>
    - - -
    - -
    -
    -
    - - - - - - - - - - - - - - -
    -
    -

    -
    -
    -
    -

    -

    It will just set them back to the default category %s.'), get_linkcatname(1)) ?>

    -
    - - diff --git a/wp-admin/link-category.php b/wp-admin/link-category.php new file mode 100644 index 00000000..42058928 --- /dev/null +++ b/wp-admin/link-category.php @@ -0,0 +1,71 @@ +%s category: this is the default one"), $cat_name)); + + wp_delete_term($cat_ID, 'link_category'); + + wp_redirect('edit-link-categories.php?message=2'); + exit; + +break; + +case 'edit': + $title = __('Categories'); + $parent_file = 'link-manager.php'; + $submenu_file = 'edit-link-categories.php'; + require_once ('admin-header.php'); + $cat_ID = (int) $_GET['cat_ID']; + $category = get_term_to_edit($cat_ID, 'link_category'); + include('edit-link-category-form.php'); + include('admin-footer.php'); + exit; +break; + +case 'editedcat': + $cat_ID = (int) $_POST['cat_ID']; + check_admin_referer('update-link-category_' . $cat_ID); + + if ( !current_user_can('manage_categories') ) + wp_die(__('Cheatin’ uh?')); + + if ( wp_update_term($cat_ID, 'link_category', $_POST) ) + wp_redirect('edit-link-categories.php?message=3'); + else + wp_redirect('edit-link-categories.php?message=5'); + + exit; +break; +} + +?> diff --git a/wp-admin/link-import.php b/wp-admin/link-import.php index c6119e6f..92753173 100644 --- a/wp-admin/link-import.php +++ b/wp-admin/link-import.php @@ -12,16 +12,16 @@ if (!$step) $step = 0; ?>
    +

    @@ -40,95 +40,98 @@ switch ($step) {
    -


    -

    +

    -

    +

    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] = ''; - // FIXME: Use wp_insert_link(). - $query = "INSERT INTO $wpdb->links (link_url, link_name, link_target, link_category, link_description, link_owner, link_rss) - VALUES('{$urls[$i]}', '".$wpdb->escape($names[$i])."', '', $cat_id, '".$wpdb->escape($descriptions[$i])."', $user_ID, '{$feeds[$i]}')\n"; - $result = $wpdb->query($query); - echo sprintf('

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

    ', $names[$i]); - } + $cat_id = abs( (int) $_POST['cat_id'] ); + if ( $cat_id < 1 ) + $cat_id = 1; + + $opml_url = $_POST['opml_url']; + if ( isset($opml_url) && $opml_url != '' && $opml_url != 'http://' ) { + $blogrolling = true; + } else { // try to get the upload file. + $overrides = array('test_form' => false, 'test_type' => false); + $file = wp_handle_upload($_FILES['userfile'], $overrides); + + if ( isset($file['error']) ) + wp_die($file['error']); + + $url = $file['url']; + $opml_url = $file['file']; + $blogrolling = false; + } + + if ( isset($opml_url) && $opml_url != '' ) { + if ( $blogrolling === true ) { + $opml = wp_remote_fopen($opml_url); + } else { + $opml = file_get_contents($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 links.'), $link_count, $cat_id, 'link-manager.php') ?>

    + +

    manage those links.'), $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); +} // end if got url +else +{ + echo "

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

    \n"; +} // end else + +if ( ! $blogrolling ) + apply_filters( 'wp_delete_file', $opml_url); + @unlink($opml_url); ?>
    +?> \ No newline at end of file diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php index b859ec9e..ade31431 100644 --- a/wp-admin/link-manager.php +++ b/wp-admin/link-manager.php @@ -1,257 +1,49 @@ = the - //userlevel of the owner of the link then we can proceed. - - if (count($linkcheck) == 0) { - wp_redirect($this_file); - exit; - } - $all_links = join(',', $linkcheck); - $results = $wpdb->get_results("SELECT link_id, link_owner FROM $wpdb->links LEFT JOIN $wpdb->users ON link_owner = ID WHERE link_id in ($all_links)"); - foreach ($results as $row) { - $ids_to_change[] = $row->link_id; - } - - // should now have an array of links we can change - $all_links = join(',', $ids_to_change); - $q = $wpdb->query("update $wpdb->links SET link_owner='$newowner' WHERE link_id IN ($all_links)"); - - wp_redirect($this_file); - exit; - break; - } - case 'visibility': - { - check_admin_referer('bulk-bookmarks'); - - // check the current user's level first. - if ( !current_user_can('manage_links') ) - die (__("Cheatin' uh ?")); - - //for each link id (in $linkcheck[]): toggle the visibility - if (count($linkcheck) == 0) { - wp_redirect($this_file); - exit; - } - $all_links = join(',', $linkcheck); - $results = $wpdb->get_results("SELECT link_id, link_visible FROM $wpdb->links WHERE link_id in ($all_links)"); - foreach ($results as $row) { - if ($row->link_visible == 'Y') { // ok to proceed - $ids_to_turnoff[] = $row->link_id; - } else { - $ids_to_turnon[] = $row->link_id; - } - } - - // should now have two arrays of links to change - if (count($ids_to_turnoff)) { - $all_linksoff = join(',', $ids_to_turnoff); - $q = $wpdb->query("update $wpdb->links SET link_visible='N' WHERE link_id IN ($all_linksoff)"); - } - - if (count($ids_to_turnon)) { - $all_linkson = join(',', $ids_to_turnon); - $q = $wpdb->query("update $wpdb->links SET link_visible='Y' WHERE link_id IN ($all_linkson)"); - } - - wp_redirect($this_file); - exit; - break; - } - case 'move': - { - check_admin_referer('bulk-bookmarks'); - - // check the current user's level first. - if ( !current_user_can('manage_links') ) - die (__("Cheatin' uh ?")); - - //for each link id (in $linkcheck[]) change category to selected value - if (count($linkcheck) == 0) { - wp_redirect($this_file); - exit; - } - $all_links = join(',', $linkcheck); - // should now have an array of links we can change - $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)"); - - wp_redirect($this_file); - exit(); - break; - } - - case 'Add': - { - check_admin_referer('add-bookmark'); - - add_link(); - - wp_redirect(wp_get_referer() . '?added=true'); - exit; - break; - } // end Add - - case 'editlink': - { - $link_id = (int) $_POST['link_id']; - check_admin_referer('update-bookmark_' . $link_id); - - if (isset($links_show_cat_id) && ($links_show_cat_id != '')) - $cat_id = $links_show_cat_id; - - if (!isset($cat_id) || ($cat_id == '')) { - if (!isset($links_show_cat_id) || ($links_show_cat_id == '')) - $cat_id = 'All'; - } - $links_show_cat_id = $cat_id; - - edit_link($link_id); - - setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600); - wp_redirect($this_file); - exit; - break; - } // end Save - - 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); - - if (isset($links_show_cat_id) && ($links_show_cat_id != '')) - $cat_id = $links_show_cat_id; - if (!isset($cat_id) || ($cat_id == '')) { - if (!isset($links_show_cat_id) || ($links_show_cat_id == '')) - $cat_id = 'All'; - } - $links_show_cat_id = $cat_id; - setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600); - wp_redirect($this_file); - exit; - break; - } // end Delete +// Links +// Copyright (C) 2002, 2003 Mike Little -- mike@zed1.com - case 'linkedit': { - $xfn_js = true; - include_once ('admin-header.php'); - if ( !current_user_can('manage_links') ) - die(__('You do not have sufficient permissions to edit the links 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; - } // end linkedit - case __("Show"): - { - if (!isset($cat_id) || ($cat_id == '')) { - if (!isset($links_show_cat_id) || ($links_show_cat_id == '')) - $cat_id = 'All'; - } - $links_show_cat_id = $cat_id; - if (!isset($order_by) || ($order_by == '')) { - if (!isset($links_show_order) || ($links_show_order == '')) - $order_by = 'order_name'; - } - $links_show_order = $order_by; - //break; fall through - } // end Show - case "popup": - { - $link_url = stripslashes($_GET["linkurl"]); - $link_name = stripslashes($_GET["name"]); - //break; fall through - } - default: - { - if (isset($links_show_cat_id) && ($links_show_cat_id != '')) - $cat_id = $links_show_cat_id; +require_once ('admin.php'); - if (!isset($cat_id) || ($cat_id == '')) { - if (!isset($links_show_cat_id) || ($links_show_cat_id == '')) - $cat_id = 'All'; - } - $links_show_cat_id = $cat_id; - if (isset($links_show_order) && ($links_show_order != '')) - $order_by = $links_show_order; +wp_enqueue_script( 'listman' ); - if (!isset($order_by) || ($order_by == '')) - $order_by = 'order_name'; - $links_show_order = $order_by; +wp_reset_vars(array('action', 'cat_id', 'linkurl', 'name', 'image', 'description', 'visible', 'target', 'category', 'link_id', 'submit', 'order_by', 'links_show_cat_id', 'rating', 'rel', 'notes', 'linkcheck[]')); - setcookie('links_show_cat_id_' . COOKIEHASH, $links_show_cat_id, time()+600); - setcookie('links_show_order_' . COOKIEHASH, $links_show_order, time()+600); - include_once ("./admin-header.php"); - if ( !current_user_can('manage_links') ) - die(__("You do not have sufficient permissions to edit the links for this blog.")); +if (empty ($cat_id)) + $cat_id = 'all'; - switch ($order_by) - { - case 'order_id': $sqlorderby = 'id'; break; - case 'order_url': $sqlorderby = 'url'; break; - case 'order_desc': $sqlorderby = 'description'; break; - case 'order_owner': $sqlorderby = 'owner'; break; - case 'order_rating': $sqlorderby = 'rating'; break; - case 'order_name': - default: $sqlorderby = 'name'; break; - } +if (empty ($order_by)) + $order_by = 'order_name'; - if ($action != "popup") { +$title = __('Manage Blogroll'); +$this_file = $parent_file = 'link-manager.php'; +include_once ("./admin-header.php"); + +if (!current_user_can('manage_links')) + wp_die(__("You do not have sufficient permissions to edit the links for this blog.")); + +switch ($order_by) { + case 'order_id' : + $sqlorderby = 'id'; + break; + case 'order_url' : + $sqlorderby = 'url'; + break; + case 'order_desc' : + $sqlorderby = 'description'; + break; + case 'order_owner' : + $sqlorderby = 'owner'; + break; + case 'order_rating' : + $sqlorderby = 'rating'; + break; + case 'order_name' : + default : + $sqlorderby = 'name'; + break; +} ?> -
    -
    - - - - - - - - - - - -
    - Show links in category:'); ?>
    -
    - Order by:');?> -  
    get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id"); - echo " \n"; +if ( isset($_GET['deleted']) ) { + echo '

    '; + $deleted = (int) $_GET['deleted']; + printf(__ngettext('%s link deleted.', '%s links deleted', $deleted), $deleted); + echo '

    '; +} ?> -
    - - - -
    -
    - -
    -
    diff --git a/wp-admin/link-parse-opml.php b/wp-admin/link-parse-opml.php index 196f3cb0..0e5edf0d 100644 --- a/wp-admin/link-parse-opml.php +++ b/wp-admin/link-parse-opml.php @@ -4,12 +4,12 @@ require_once('../wp-config.php'); // columns we wish to find are: link_url, link_name, link_target, link_description // we need to map XML attribute names to our columns $opml_map = array('URL' => 'link_url', - 'HTMLURL' => 'link_url', - 'TEXT' => 'link_name', - 'TITLE' => 'link_name', - 'TARGET' => 'link_target', - 'DESCRIPTION' => 'link_description', - 'XMLURL' => 'link_rss' + 'HTMLURL' => 'link_url', + 'TEXT' => 'link_name', + 'TITLE' => 'link_name', + 'TARGET' => 'link_target', + 'DESCRIPTION' => 'link_description', + 'XMLURL' => 'link_rss' ); $map = $opml_map; @@ -20,24 +20,24 @@ $map = $opml_map; **/ function startElement($parser, $tagName, $attrs) { global $updated_timestamp, $all_links, $map; - global $names, $urls, $targets, $descriptions, $feeds; + global $names, $urls, $targets, $descriptions, $feeds; if ($tagName == 'OUTLINE') { - foreach (array_keys($map) as $key) { - if (isset($attrs[$key])) { - $$map[$key] = $attrs[$key]; - } - } + 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"); + //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; + // save the data away. + $names[] = $link_name; + $urls[] = $link_url; + $targets[] = $link_target; $feeds[] = $link_rss; - $descriptions[] = $link_description; - } // end if outline + $descriptions[] = $link_description; + } // end if outline } /** @@ -55,9 +55,9 @@ $xml_parser = xml_parser_create(); 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))); + 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 diff --git a/wp-admin/link.php b/wp-admin/link.php new file mode 100644 index 00000000..1d7e4d6a --- /dev/null +++ b/wp-admin/link.php @@ -0,0 +1,106 @@ +query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)"); + + wp_redirect($this_file); + exit; + break; + + case 'add' : + check_admin_referer('add-bookmark'); + + add_link(); + + wp_redirect( wp_get_referer() . '?added=true' ); + exit; + 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); + + wp_delete_link($link_id); + + wp_redirect($this_file); + exit; + break; + + case 'edit' : + wp_enqueue_script( array('xfn', 'dbx-admin-key?pagenow=link.php') ); + if ( current_user_can( 'manage_categories' ) ) + wp_enqueue_script( 'ajaxlinkcat' ); + $parent_file = 'link-manager.php'; + $submenu_file = 'link-manager.php'; + $title = __('Edit Link'); + + $link_id = (int) $_GET['link_id']; + + if (!$link = get_link_to_edit($link_id)) + wp_die(__('Link not found.')); + + include_once ('admin-header.php'); + include ('edit-link-form.php'); + include ('admin-footer.php'); + break; + + default : + break; +} +?> \ No newline at end of file diff --git a/wp-admin/list-manipulation.js b/wp-admin/list-manipulation.js deleted file mode 100644 index adf3f4f8..00000000 --- a/wp-admin/list-manipulation.js +++ /dev/null @@ -1,96 +0,0 @@ -var listItems; -var reg_color = '#FFFFFF'; -var alt_color = '#F1F1F1'; - -addLoadEvent(getListItems); - -function deleteSomething( what, id, message ) { - what.replace('-', ' '); - if (!message) message = 'Are you sure you want to delete this ' + what + '?'; - if ( confirm(message) ) { - return ajaxDelete( what.replace(' ', '-'), id ); - } else { - return false; - } -} - -function getResponseElement() { - var p = document.getElementById('ajax-response-p'); - if (!p) { - p = document.createElement('p'); - p.id = 'ajax-response-p'; - document.getElementById('ajax-response').appendChild(p); - return p; - } -} - -function ajaxDelete(what, id) { - ajaxDel = new sack('list-manipulation.php'); - if ( ajaxDel.failed ) return true; - ajaxDel.myResponseElement = getResponseElement(); - ajaxDel.method = 'POST'; - ajaxDel.onLoading = function() { ajaxDel.myResponseElement.innerHTML = 'Sending Data...'; }; - ajaxDel.onLoaded = function() { ajaxDel.myResponseElement.innerHTML = 'Data Sent...'; }; - ajaxDel.onInteractive = function() { ajaxDel.myResponseElement.innerHTML = 'Processing Data...'; }; - ajaxDel.onCompletion = function() { removeThisItem( what + '-' + id ); }; - ajaxDel.runAJAX('action=delete-' + what + '&id=' + id + '&' + ajaxDel.encVar('cookie', document.cookie)); - return false; -} - -function removeThisItem(id) { - var response = ajaxDel.response; - if ( isNaN(response) ) { ajaxDel.myResponseElement.innerHTML = response; return false; } - response = parseInt(response, 10); - if ( -1 == response ) { ajaxDel.myResponseElement.innerHTML = "You don't have permission to do that."; } - else if ( 0 == response ) { ajaxDel.myResponseElement.interHTML = "Something odd happened. Try refreshing the page? Either that or what you tried to delete never existed in the first place."; } - else if ( 1 == response ) { - theItem = document.getElementById(id); - Fat.fade_element(id,null,700,'#FF3333'); - setTimeout('theItem.parentNode.removeChild(theItem)', 705); - var pos = getListPos(id); - listItems.splice(pos,1); - recolorList(pos); - ajaxDel.myResponseElement.parentNode.removeChild(ajaxDel.myResponseElement); - - } -} - -function getListPos(id) { - for (var i = 0; i < listItems.length; i++) { - if (id == listItems[i]) { - var pos = i; - break; - } - } - return pos; -} - -function getListItems() { - if (list) return; - listItems = new Array(); - var extra = false; - var list = document.getElementById('the-list'); - if (!list) { var list = document.getElementById('the-list-x'); extra = true; } - if (list) { - var items = list.getElementsByTagName('tr'); - if (!items[0]) { items = list.getElementsByTagName('li'); } - for (var i=0; icomment_post_ID) ) - die('-1'); - - if ( wp_delete_comment($comment->comment_ID) ) { - die('1'); - } else { - die('0'); - } - break; -case 'delete-link-category' : - $id = (int) $_POST['id']; - if ( 1 == $id ) - die('0'); - if ( !current_user_can('manage_links') ) - die('-1'); - - if ( $wpdb->query("DELETE FROM $wpdb->linkcategories WHERE cat_id='$id'") ) { - $wpdb->query("UPDATE $wpdb->links SET link_category=1 WHERE link_category='$id'"); - die('1'); - } else { - die('0'); - } - break; -endswitch; -?> diff --git a/wp-admin/menu-header.php b/wp-admin/menu-header.php index 352e3458..bbdfe1a7 100644 --- a/wp-admin/menu-header.php +++ b/wp-admin/menu-header.php @@ -10,12 +10,19 @@ foreach ($menu as $item) { // 0 = name, 1 = capability, 2 = file if (( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file))) $class = ' class="current"'; - - if ( current_user_can($item[1]) ) { - if ( file_exists(ABSPATH . "wp-content/plugins/{$item[2]}") ) - echo "\n\t
  • {$item[0]}
  • "; + + if ( !empty($submenu[$item[2]]) ) { + $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index. + $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]); + if ( file_exists(ABSPATH . PLUGINDIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook)) + echo "\n\t
  • {$item[0]}
  • "; + else + echo "\n\t
  • {$item[0]}
  • "; + } else if ( current_user_can($item[1]) ) { + if ( file_exists(ABSPATH . PLUGINDIR . "/{$item[2]}") ) + echo "\n\t
  • {$item[0]}
  • "; else - echo "\n\t
  • {$item[0]}
  • "; + echo "\n\t
  • {$item[0]}
  • "; } } @@ -27,8 +34,8 @@ foreach ($menu as $item) { if ( isset($submenu["$parent_file"]) ) : ?> +
    +get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'"); +$submenu['edit-comments.php'][25] = array(sprintf(__("Awaiting Moderation (%s)"), "$awaiting_mod"), 'edit_posts', 'moderation.php'); + $submenu['edit.php'][5] = array(__('Posts'), 'edit_posts', 'edit.php'); $submenu['edit.php'][10] = array(__('Pages'), 'edit_pages', 'edit-pages.php'); +$submenu['edit.php'][12] = array(__('Uploads'), 'upload_files', 'upload.php'); $submenu['edit.php'][15] = array(__('Categories'), 'manage_categories', 'categories.php'); -$submenu['edit.php'][20] = array(__('Comments'), 'edit_posts', 'edit-comments.php'); -$awaiting_mod = $wpdb->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'); -$submenu['link-manager.php'][5] = array(__('Manage Links'), 'manage_links', 'link-manager.php'); +$submenu['link-manager.php'][5] = array(__('Manage Blogroll'), 'manage_links', 'link-manager.php'); $submenu['link-manager.php'][10] = array(__('Add Link'), 'manage_links', 'link-add.php'); -$submenu['link-manager.php'][15] = array(__('Link Categories'), 'manage_links', 'link-categories.php'); $submenu['link-manager.php'][20] = array(__('Import Links'), 'manage_links', 'link-import.php'); +$submenu['link-manager.php'][30] = array(__('Categories'), 'manage_links', 'edit-link-categories.php'); -$submenu['profile.php'][5] = array(__('Your Profile'), 'read', 'profile.php'); -$submenu['profile.php'][10] = array(__('Authors & Users'), 'edit_users', 'users.php'); +if ( current_user_can('edit_users') ) { + $_wp_real_parent_file['profile.php'] = 'users.php'; // Back-compat for plugins adding submenus to profile.php. + $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(__('Permalinks'), 'manage_options', 'options-permalink.php'); -$submenu['options-general.php'][35] = array(__('Miscellaneous'), 'manage_options', 'options-misc.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'); @@ -49,16 +70,74 @@ $submenu['plugins.php'][10] = array(__('Plugin Editor'), 'edit_plugins', 'plugin $submenu['themes.php'][5] = array(__('Themes'), 'switch_themes', 'themes.php'); $submenu['themes.php'][10] = array(__('Theme Editor'), 'edit_themes', 'theme-editor.php'); +do_action('_admin_menu'); + // Create list of page plugin hook names. foreach ($menu as $menu_page) { $admin_page_hooks[$menu_page[2]] = sanitize_title($menu_page[0]); } +$_wp_submenu_nopriv = array(); +$_wp_menu_nopriv = array(); +// 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]) ) { + unset($submenu[$parent][$index]); + $_wp_submenu_nopriv[$parent][$data[2]] = true; + } + } + + if ( empty($submenu[$parent]) ) + unset($submenu[$parent]); +} + +// Loop over the top-level menu. +// 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 ( empty($submenu[$data[2]]) ) + continue; + $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 ) { + $_wp_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]); + $_wp_submenu_nopriv[$new_parent] = $_wp_submenu_nopriv[$old_parent]; + } +} + do_action('admin_menu', ''); + +// Remove menus that have no accessible submenus and require privs that the user does not have. +// Run re-parent loop again. +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]) ) { + $_wp_menu_nopriv[$data[2]] = true; + unset($menu[$id]); + } + } +} + +unset($id); + uksort($menu, "strnatcasecmp"); // make it all pretty if (! user_can_access_admin_page()) { - die( __('You do not have sufficient permissions to access this page.') ); + wp_die( __('You do not have sufficient permissions to access this page.') ); } ?> diff --git a/wp-admin/moderation.php b/wp-admin/moderation.php index 065f8bdf..fc46917c 100644 --- a/wp-admin/moderation.php +++ b/wp-admin/moderation.php @@ -1,225 +1,226 @@ $v) { - $comment[intval($k)] = $v; + +if ( isset( $_POST['comment'] ) && is_array( $_POST['comment'] ) ) { + foreach ( $_POST['comment'] as $k => $v ) { + $comment[intval( $k )] = $v; } } -switch($action) { +if ( $action == 'update' ) { + check_admin_referer( 'moderate-comments' ); -case 'update': - - check_admin_referer('moderate-comments'); - - if ( ! current_user_can('moderate_comments') ) - die('

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

    '); + if ( !current_user_can( 'moderate_comments' ) ) { + wp_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); + foreach ( $comment as $k => $v ) { + if ( $feelinglucky && $v == 'later' ) { + $v = 'delete'; + } + + switch ( $v ) { + case 'later' : + $item_ignored++; + break; + + case 'delete' : + wp_set_comment_status( $k, 'delete' ); + $item_deleted++; + break; + + case 'spam' : + wp_set_comment_status( $k, 'spam' ); + $item_spam++; + break; + + case 'approve' : + wp_set_comment_status( $k, 'approve' ); + + if ( get_option( 'comments_notify' ) == true ) { + wp_notify_postauthor( $k ); } - ++$item_approved; - break; - } + + $item_approved++; + break; + } } - $file = basename(__FILE__); - wp_redirect("$file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam"); - exit(); + wp_redirect( basename( __FILE__ ) . '?ignored=' . $item_ignored . '&deleted=' . $item_deleted . '&approved=' . $item_approved . '&spam=' . $item_spam ); + exit; +} + +require_once './admin-header.php'; -break; +if ( !current_user_can( 'moderate_comments' ) ) { + echo '

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

    '; + include_once './admin-footer.php'; + exit; +} -default: +if ( isset( $_GET['approved'] ) || isset( $_GET['deleted'] ) || isset( $_GET['spam'] ) ) { + $approved = isset( $_GET['approved'] ) ? (int) $_GET['approved'] : 0; + $deleted = isset( $_GET['deleted'] ) ? (int) $_GET['deleted'] : 0; + $spam = isset( $_GET['ignored'] ) ? (int) $_GET['spam'] : 0; -require_once('admin-header.php'); + if ( $approved > 0 || $deleted > 0 || $spam > 0 ) { + echo '

    '; -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 ( $approved > 0 ) { + printf( __ngettext( '%s comment approved.', '%s comments approved.', $approved ), $approved ); + echo '
    '; } - } - if ($deleted) { - if ('1' == $deleted) { - echo __("1 comment deleted") . "
    \n"; - } else { - echo sprintf(__("%s comments deleted"), $deleted) . "
    \n"; + + if ( $deleted > 0 ) { + printf( __ngettext( '%s comment deleted', '%s comments deleted.', $deleted ), $deleted ); + echo '
    '; } - } - 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"; + + if ( $spam > 0 ) { + printf( __ngettext( '%s comment marked as spam', '%s comments marked as spam', $spam ), $spam ); + echo '
    '; } + + echo '

    '; } - 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 = 'class="alternate"'; - else $class = ''; - echo "\n\t
    1. "; - ?> -

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

      - -

      comment_ID.'">' . __('Edit') . ' | ';?> - | -comment_post_ID."&comment=".$comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment', $comment->comment_ID, '" . __("You are about to delete this comment.\\n"Cancel" to stop, "OK" to delete.") . "' );\">" . __('Delete just this comment') . " | "; ?> - - - - -

      - -
    2. -
    -
    +$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'" ); -

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

    \n"; + $page = 1; } + +$start = ( $page * $per ) - $per; +$stop = $start + $per; + +$page_links = paginate_links( array( + 'base' => add_query_arg( 'paged', '%#%' ), + 'format' => '', + 'total' => ceil( $total / $per ), + 'current' => $page, + 'prev_text' => '«', + 'next_text' => '»' +) ); + +$comments = array_slice( $comments, $start, $stop ); + ?> +

    -
    + ' . $page_links . '

    '; + } + ?> -" method="post"> + + +
      + +
    1. +

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

      + +

      + +

      + +

      + — + [ | + ', theCommentList );"> ] — + comment_post_ID ) ); ?> +

      + +

      + +   +   +   + +

      +
    2. + +
    + + ' . $page_links . '

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

    + +

    + + + + + \ No newline at end of file diff --git a/wp-admin/options-discussion.php b/wp-admin/options-discussion.php index fc0aa741..78deefdd 100644 --- a/wp-admin/options-discussion.php +++ b/wp-admin/options-discussion.php @@ -5,97 +5,82 @@ $title = __('Discussion Options'); $parent_file = 'options-general.php'; include('admin-header.php'); - -if ($action == 'retrospam') { - if ( $_GET['move'] == 'true' ) { - retrospam_mgr::move_spam( $_GET[ids] ); - } - $retrospaminator = new retrospam_mgr(); - $result = $retrospaminator->find_spam(); - echo $retrospaminator->display_edit_form( $result ); - include('./admin-footer.php'); - exit; -} ?> -
    -

    -
    +
    +

    + +

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

    ' ) ?>

    +

    ' ) ?>

    -

    Common spam words.') ?>

    -

    - -

    +

    moderation queue. One word or IP per line. It will match inside words, so "press" will match "WordPress".') ?>

    - -

    + +

    -

    -

    - +

    +

    +

    -

    - - - -

    - + + + +

    +
    + diff --git a/wp-admin/options-general.php b/wp-admin/options-general.php index 00d6cf89..3e6ce862 100644 --- a/wp-admin/options-general.php +++ b/wp-admin/options-general.php @@ -6,81 +6,77 @@ $parent_file = 'options-general.php'; include('./admin-header.php'); ?> - +

    -
    + - - - - - - - +

    +
    + + + + + + - - - - - + + + + + + - - + + - - + + + - - - + + - - - - - -

    -
    " />

    to be different than the directory you installed WordPress in, enter that address here.'); ?>
    " />
    to be different from the directory you installed WordPress.'); ?>

    -

    -
    -
    -
    - - - - - + + + + + +
    UTC time is:') ?>
    +
    +
    + + - - + + + + + + + - + + @@ -90,22 +86,21 @@ foreach($wp_roles->role_names as $role => $name) {
    - UTC time is:') ?>
    + (-6 for Central Time.'); ?>)

    -

    -
      Documentation on date formatting. Click "Update options" to update sample output.') ?>
    -
    +
    -

    - - +

    + +

    -
    +
    - \ No newline at end of file + diff --git a/wp-admin/options-head.php b/wp-admin/options-head.php index 579da0a3..11d82e87 100644 --- a/wp-admin/options-head.php +++ b/wp-admin/options-head.php @@ -1,23 +1,4 @@ - - -
    +

    diff --git a/wp-admin/options-misc.php b/wp-admin/options-misc.php index 2b6e33a5..ec429659 100644 --- a/wp-admin/options-misc.php +++ b/wp-admin/options-misc.php @@ -7,17 +7,18 @@ $parent_file = 'options-general.php'; include('admin-header.php'); ?> - -
    -

    + +
    +

    +

    - @@ -26,7 +27,7 @@ include('admin-header.php'); @@ -34,18 +35,18 @@ include('admin-header.php');
    : +
    wp-content/uploads'); ?>
    -

    /> +

    />

    - +

    - - + +

    -
    +
    \ No newline at end of file diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index 68c44aaa..01919feb 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -41,7 +41,7 @@ structure.onfocus = function () { document.getElementById('custom_selection').ch var aInputs = document.getElementsByTagName('input'); -for (var i = 0; i < aInputs.length; i++) { +for (var i = 0; i < aInputs.length; i++) { aInputs[i].onclick = aInputs[i].onkeyup = upit; } } @@ -66,17 +66,25 @@ if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) { $permalink_structure = preg_replace('#/+#', '/', '/' . $_POST['permalink_structure']); $wp_rewrite->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); } + + if ( isset($_POST['tag_base']) ) { + $tag_base = $_POST['tag_base']; + if (! empty($tag_base) ) + $tag_base = preg_replace('#/+#', '/', '/' . $_POST['tag_base']); + $wp_rewrite->set_tag_base($tag_base); + } } - -$permalink_structure = get_settings('permalink_structure'); -$category_base = get_settings('category_base'); + +$permalink_structure = get_option('permalink_structure'); +$category_base = get_option('category_base'); +$tag_base = get_option( 'tag_base' ); if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) $writable = true; @@ -93,16 +101,19 @@ $wp_rewrite->flush_rules();

    -
    -

    -

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

    +
    +

    +
    + +

    +

    URLs which have question marks and lots of numbers in them, however WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A number of tags are available, and here are some examples to get you started.'); ?>

    - -

    @@ -143,8 +152,8 @@ $structures = array( checked="checked" - /> - + /> +

    @@ -152,25 +161,25 @@ checked="checked"

    -

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

    +

    URLs here. For example, using /topics/ as your category base would make your category links like http://example.org/topics/uncategorized/. If you leave these blank the defaults 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.') ?>

    +

    URLs here. For example, using /topics/ as your category base would make your category links like http://example.org/index.php/topics/uncategorized/. If you leave these blank the defaults 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-privacy.php b/wp-admin/options-privacy.php new file mode 100644 index 00000000..ac6810b3 --- /dev/null +++ b/wp-admin/options-privacy.php @@ -0,0 +1,35 @@ + + +
    +

    +
    + + + + + + +
    +

    /> +

    +

    /> +

    + +
    + +

    + + +

    +
    + +
    + + diff --git a/wp-admin/options-reading.php b/wp-admin/options-reading.php index 1d0fd8aa..3a7f80e7 100644 --- a/wp-admin/options-reading.php +++ b/wp-admin/options-reading.php @@ -7,59 +7,90 @@ $parent_file = 'options-general.php'; include('admin-header.php'); ?> -
    -

    +
    +

    +

    + +
    + + + + + + +
    +

    +

    +

    +

    +
      +
    • +
    • +
    + +
    +

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

    +
    + +
    +
    + -
    - - - - +
    + +
    + + - -
    - - -
    -
    + + + + + -
    - - - - - +
    + +
    + + + - -
    -
    - +


    +

    +

    <!--more--> feature, it will cut off posts in RSS feeds.'); ?>

    -
    - - - + +
    + + + + +recommended)') ?> -

    -recommended)') ?>
    +

    -

    - - - -

    -
    -
    + + + +

    + +
    \ No newline at end of file diff --git a/wp-admin/options-writing.php b/wp-admin/options-writing.php index 96fa30ff..e8979c45 100644 --- a/wp-admin/options-writing.php +++ b/wp-admin/options-writing.php @@ -7,37 +7,50 @@ $parent_file = 'options-general.php'; include('admin-header.php'); ?> -
    -

    -
    +
    +

    + - - - - - +

    +
    -
    + + + + + + + + @@ -45,14 +58,14 @@ endforeach;
    +
    -

    - +
    - +

    %s, %s, %s.'), substr(md5(uniqid(microtime())),0,5), substr(md5(uniqid(microtime())),0,5), substr(md5(uniqid(microtime())),0,5)) ?>

    - +
    @@ -67,12 +80,13 @@ endforeach; - + - - - "; + + + + "; } ?>
    - +
    + + + +

    Update Services because of your blog\'s privacy settings.'), 'options-privacy.php'); ?> + + +

    - - - + + +

    - - + + \ No newline at end of file diff --git a/wp-admin/options.php b/wp-admin/options.php index bd8b2b0d..7fa05bbf 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -5,91 +5,16 @@ $title = __('Options'); $this_file = 'options.php'; $parent_file = 'options-general.php'; -$wpvarstoreset = array('action'); -for ($i=0; $iflush_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' , wp_get_referer()); + $goback = add_query_arg('updated', 'true', wp_get_referer()); - $goback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $goback); wp_redirect($goback); break; @@ -145,6 +48,7 @@ default:
    +

    get_results("SELECT * FROM $wpdb->options ORDER BY option_name"); @@ -177,7 +81,6 @@ foreach ( (array) $options as $option) : else echo ""; echo " - "; endforeach; ?> diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php index 70d76e1d..ff86155b 100644 --- a/wp-admin/page-new.php +++ b/wp-admin/page-new.php @@ -1,20 +1,23 @@ - -

    | »

    + +

    |

    post_status = 'static'; + $post->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 00000000..c6baadde --- /dev/null +++ b/wp-admin/page.php @@ -0,0 +1,160 @@ +ID) ) wp_die( __("You attempted to edit a page that doesn't exist. Perhaps it was deleted?") ); + + if ( 'post' == $post->post_type ) { + wp_redirect("post.php?action=edit&post=$post_ID"); + exit(); + } + + if($post->post_status == 'draft') { + wp_enqueue_script('prototype'); + wp_enqueue_script('interface'); + wp_enqueue_script('autosave'); + } + require_once('admin-header.php'); + + if ( !current_user_can('edit_page', $page_ID) ) + die ( __('You are not allowed to edit this page.') ); + + include('edit-page-form.php'); + break; + +case 'editattachment': + $page_id = $post_ID = (int) $_POST['post_ID']; + check_admin_referer('update-attachment_' . $page_id); + + // Don't let these be changed + unset($_POST['guid']); + $_POST['post_type'] = 'attachment'; + + // Update the thumbnail filename + $newmeta = wp_get_attachment_metadata( $page_id, true ); + $newmeta['thumb'] = $_POST['thumb']; + + wp_update_attachment_metadata( $newmeta ); + +case 'editpost': + $page_ID = (int) $_POST['post_ID']; + check_admin_referer('update-page_' . $page_ID); + + $page_ID = edit_post(); + + if ( 'post' == $_POST['originalaction'] ) { + if (!empty($_POST['mode'])) { + switch($_POST['mode']) { + case 'bookmarklet': + $location = $_POST['referredby']; + break; + case 'sidebar': + $location = 'sidebar.php?a=b'; + break; + default: + $location = 'page-new.php'; + break; + } + } else { + $location = "page-new.php?posted=$page_ID"; + } + + if ( isset($_POST['save']) ) + $location = "page.php?action=edit&post=$page_ID"; + } else { + if ($_POST['save']) { + $location = "page.php?action=edit&post=$page_ID"; + } elseif ($_POST['updatemeta']) { + $location = wp_get_referer() . '&message=2#postcustom'; + } elseif ($_POST['deletemeta']) { + $location = wp_get_referer() . '&message=3#postcustom'; + } elseif (!empty($_POST['referredby']) && $_POST['referredby'] != wp_get_referer()) { + $location = $_POST['referredby']; + if ( $_POST['referredby'] == 'redo' ) + $location = get_permalink( $page_ID ); + } elseif ($action == 'editattachment') { + $location = 'attachments.php'; + } else { + $location = 'page-new.php'; + } + } + wp_redirect($location); // Send user on their way while we keep working + + exit(); + break; + +case 'delete': + $page_id = (isset($_GET['post'])) ? intval($_GET['post']) : intval($_POST['post_ID']); + check_admin_referer('delete-page_' . $page_id); + + $page = & get_post($page_id); + + if ( !current_user_can('delete_page', $page_id) ) + wp_die( __('You are not allowed to delete this page.') ); + + if ( $page->post_type == 'attachment' ) { + if ( ! wp_delete_attachment($page_id) ) + wp_die( __('Error in deleting...') ); + } else { + if ( !wp_delete_post($page_id) ) + wp_die( __('Error in deleting...') ); + } + + $sendback = wp_get_referer(); + if (strpos($sendback, 'page.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/page.php'; + elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php'; + $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); + wp_redirect($sendback); + exit(); + break; + +default: + wp_redirect('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 index 0f9da3b9..b25b3d45 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -4,21 +4,7 @@ require_once('admin.php'); $title = __("Edit Plugins"); $parent_file = 'plugins.php'; -$wpvarstoreset = array('action','redirect','profile','error','warning','a','file'); -for ($i=0; $i'.__('You have do not have sufficient permissions to edit templates for this blog.').'

    '); + wp_die('

    '.__('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+'); fwrite($f, $newcontent); fclose($f); + + // Deactivate so we can test it. + $current = get_option('active_plugins'); + if ( in_array($file, $current) || isset($_POST['phperror']) ) { + if ( in_array($file, $current) ) { + array_splice($current, array_search( $file, $current), 1 ); // Array-fu! + update_option('active_plugins', $current); + } + wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1")); + exit(); + } wp_redirect("plugin-editor.php?file=$file&a=te"); } else { wp_redirect("plugin-editor.php?file=$file"); @@ -54,16 +51,35 @@ case 'update': 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.').'

    '); + wp_die('

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

    '); + + if ( $_GET['liveupdate'] ) { + check_admin_referer('edit-plugin-test_' . $file); + $current = get_option('active_plugins'); + $plugin = $file; + if ( validate_file($plugin) ) + wp_die(__('Invalid plugin.')); + if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) + wp_die(__('Plugin file does not exist.')); + if (!in_array($plugin, $current)) { + wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error + @include(ABSPATH . PLUGINDIR . '/' . $plugin); + $current[] = $plugin; + sort($current); + update_option('active_plugins', $current); + } + wp_redirect("plugin-editor.php?file=$file&a=te"); + } + + require_once('admin-header.php'); + + update_recently_edited(PLUGINDIR . "/$file"); - 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)); @@ -73,13 +89,23 @@ default: ?>

    + +

    fatal error.') ?>

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

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

    '; + } } else { - echo '

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

    '; + if (is_writeable($real_file)) { + echo '

    ' . sprintf(__('Editing %s (inactive)'), $file) . '

    '; + } else { + echo '

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

    '; + } } ?>
    @@ -88,39 +114,45 @@ default: -
      - +
        +
      • ">
      • - -
      + +
    - - - -
    - - + + + +
    + +
    -

    -"; -?> -

    + +

    Warning: Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?>

    + +

    + "; + else + echo ""; + ?> +

    -

    +

    - - +

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

    '; } - ?> +?>
     
    -
    +
    +include("admin-footer.php") ?> diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 21db39d0..b9e6e7b2 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -4,22 +4,49 @@ require_once('admin.php'); if ( isset($_GET['action']) ) { if ('activate' == $_GET['action']) { check_admin_referer('activate-plugin_' . $_GET['plugin']); - $current = get_settings('active_plugins'); - if (!in_array($_GET['plugin'], $current)) { - $current[] = trim( $_GET['plugin'] ); + $current = get_option('active_plugins'); + $plugin = trim($_GET['plugin']); + if ( validate_file($plugin) ) + wp_die(__('Invalid plugin.')); + if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) + wp_die(__('Plugin file does not exist.')); + if (!in_array($plugin, $current)) { + wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), 'plugins.php?error=true&plugin=' . $plugin)); // we'll override this later if the plugin can be included without fatal error + ob_start(); + @include(ABSPATH . PLUGINDIR . '/' . $plugin); + $current[] = $plugin; sort($current); update_option('active_plugins', $current); - include(ABSPATH . 'wp-content/plugins/' . trim( $_GET['plugin'] )); - do_action('activate_' . trim( $_GET['plugin'] )); + do_action('activate_' . $plugin); + ob_end_clean(); } - wp_redirect('plugins.php?activate=true'); - } else if ('deactivate' == $_GET['action']) { + wp_redirect('plugins.php?activate=true'); // overrides the ?error=true one above + } elseif ('error_scrape' == $_GET['action']) { + $plugin = trim($_GET['plugin']); + check_admin_referer('plugin-activation-error_' . $plugin); + if ( validate_file($plugin) ) + wp_die(__('Invalid plugin.')); + if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) + wp_die(__('Plugin file does not exist.')); + include(ABSPATH . PLUGINDIR . '/' . $plugin); + } elseif ('deactivate' == $_GET['action']) { check_admin_referer('deactivate-plugin_' . $_GET['plugin']); - $current = get_settings('active_plugins'); + $current = get_option('active_plugins'); array_splice($current, array_search( $_GET['plugin'], $current), 1 ); // Array-fu! update_option('active_plugins', $current); do_action('deactivate_' . trim( $_GET['plugin'] )); wp_redirect('plugins.php?deactivate=true'); + } elseif ($_GET['action'] == 'deactivate-all') { + check_admin_referer('deactivate-all'); + $current = get_option('active_plugins'); + + foreach ($current as $plugin) { + array_splice($current, array_search($plugin, $current), 1); + do_action('deactivate_' . $plugin); + } + + update_option('active_plugins', array()); + wp_redirect('plugins.php?deactivate-all=true'); } exit; } @@ -30,20 +57,20 @@ require_once('admin-header.php'); // Clean up options // If any plugins don't exist, axe 'em -$check_plugins = get_settings('active_plugins'); +$check_plugins = get_option('active_plugins'); // Sanity check. If the active plugin list is not an array, make it an // empty array. if ( !is_array($check_plugins) ) { $check_plugins = array(); - update_option('active_plugins', $check_plugins); + update_option('active_plugins', $check_plugins); } // If a plugin file does not exist, remove it from the list of active // plugins. foreach ($check_plugins as $check_plugin) { - if (!file_exists(ABSPATH . 'wp-content/plugins/' . $check_plugin)) { - $current = get_settings('active_plugins'); + if (!file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin)) { + $current = get_option('active_plugins'); $key = array_search($check_plugin, $current); if ( false !== $key && NULL !== $key ) { unset($current[$key]); @@ -53,13 +80,22 @@ foreach ($check_plugins as $check_plugin) { } ?> - -

    activated.') ?>

    -
    - - -

    deactivated.') ?>

    -
    + +

    fatal error.') ?>

    + + + +
    + +

    activated.') ?>

    + +

    deactivated.') ?>

    + +

    deactivated.'); ?>

    @@ -67,24 +103,26 @@ foreach ($check_plugins as $check_plugin) {

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

    '; } else { ?> -
    $option->option_description
    +
    + - + - + + ".__('Deactivate').""; + $toggle = "".__('Deactivate').""; $plugin_data['Title'] = "{$plugin_data['Title']}"; $style .= $style == 'alternate' ? ' active' : 'active'; } else { - $action = "".__('Activate').""; + $toggle = "".__('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 . '"'; + + $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); + + // Sanitize all displayed data + $plugin_data['Title'] = wp_kses($plugin_data['Title'], $plugins_allowedtags); + $plugin_data['Version'] = wp_kses($plugin_data['Version'], $plugins_allowedtags); + $plugin_data['Description'] = wp_kses($plugin_data['Description'], $plugins_allowedtags); + $plugin_data['Author'] = wp_kses($plugin_data['Author'], $plugins_allowedtags); + + if ( $style != '' ) + $style = 'class="' . $style . '"'; + if ( is_writable(ABSPATH . PLUGINDIR . '/' . $plugin_file) ) + $edit = "".__('Edit').""; + else + $edit = ''; + + $author = ( empty($plugin_data['Author']) ) ? '' : ' ' . sprintf( __('By %s'), $plugin_data['Author'] ) . '.'; + echo " - - + + "; + if ( current_user_can('edit_plugins') ) + echo " + "; + echo" "; + do_action( 'after_plugin_row', $plugin_file ); } ?> + + + + +
    >
    {$plugin_data['Title']} {$plugin_data['Version']}{$plugin_data['Description']} ".sprintf(__('By %s'), $plugin_data['Author']).".$action

    {$plugin_data['Description']}$author

    $toggle$edit
     
    -

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

    +

    %s directory and it will be automatically deactivated.'), PLUGINDIR); ?>

    -

    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.'); ?>

    +

    WordPress plugin directory.'); ?>

    +

    %s directory. Once a plugin is uploaded, you may activate it here.'), PLUGINDIR); ?>

    diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php new file mode 100644 index 00000000..c6b709b8 --- /dev/null +++ b/wp-admin/post-new.php @@ -0,0 +1,128 @@ + +
    +

    edit_posts capability to your user, in order to be authorized to post.
    +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_option('admin_email')); ?> +

    +
    + +

    + + + +'; + + foreach ( $nag_posts as $nag ) { + if ( ${$nag[0]} ) { + echo '

    ' . wp_specialchars($nag[1]) . ' '; + $i = 0; + foreach ( ${$nag[0]} as $post ) { + $i++; + if ( $i > $nag_posts_limit ) + break; + echo ''; + ( '' == the_title('', '', FALSE) ) ? printf( __('Post #%s'), $post->ID ) : the_title(); + echo ''; + if ( $i < min($nag[3], $nag_posts_limit) ) + echo ', '; + } + if ( $nag[3] > $nag_posts_limit ) + printf(__(', and %d more'), $nag[2], $nag[3] - $nag_posts_limit); + echo '.

    '; + } + } + echo "\n"; +} +?> + + + + + +
    +

    +

    +

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

    +
    + + + diff --git a/wp-admin/post.php b/wp-admin/post.php index 44a3ea2d..680f8abe 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -1,38 +1,22 @@ ID) ) wp_die( __("You attempted to edit a post that doesn't exist. Perhaps it was deleted?") ); - $post_ID = $p = (int) $_GET['post']; + if ( 'page' == $post->post_type ) { + wp_redirect("page.php?action=edit&post=$post_ID"); + exit(); + } + + if($post->post_status == 'draft') { + wp_enqueue_script('prototype'); + wp_enqueue_script('autosave'); + } + 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); - - if ($post->post_status == 'static') - include('edit-page-form.php'); - else - include('edit-form-advanced.php'); - - ?> -
    -

    - -
    - post_status ) - check_admin_referer('delete-page_' . $post_id); - else - check_admin_referer('delete-post_' . $post_id); - if ( !current_user_can('edit_post', $post_id) ) - die( __('You are not allowed to delete this post.') ); + if ( !current_user_can('delete_post', $post_id) ) + wp_die( __('You are not allowed to delete this post.') ); - if ( $post->post_status == 'attachment' ) { + if ( $post->post_type == 'attachment' ) { if ( ! wp_delete_attachment($post_id) ) - die( __('Error in deleting...') ); + wp_die( __('Error in deleting...') ); } else { - if ( !wp_delete_post($post_id) ) - die( __('Error in deleting...') ); + if ( !wp_delete_post($post_id) ) + wp_die( __('Error in deleting...') ); } $sendback = wp_get_referer(); - if ( 'static' == $post->post_status ) - $sendback = get_option('siteurl') . '/wp-admin/edit-pages.php'; - elseif ( strstr($sendback, 'post.php') ) - $sendback = get_option('siteurl') .'/wp-admin/post.php'; - elseif ( strstr($sendback, 'attachments.php') ) - $sendback = get_option('siteurl') .'/wp-admin/attachments.php'; + if (strpos($sendback, 'post.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/post-new.php'; + elseif (strpos($sendback, 'attachments.php') !== false) $sendback = get_option('siteurl') .'/wp-admin/attachments.php'; + $sendback = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $sendback); wp_redirect($sendback); - break; - -case 'editcomment': - $title = __('Edit Comment'); - $parent_file = 'edit.php'; - require_once ('admin-header.php'); - - get_currentuserinfo(); - - $comment = (int) $_GET['comment']; - - if ( ! $comment = get_comment($comment) ) - die(sprintf(__('Oops, no comment with this ID. 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': - - require_once('./admin-header.php'); - - $comment = (int) $_GET['comment']; - $p = (int) $_GET['p']; - - if ( ! $comment = get_comment_to_edit($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 delete comments on this post.') ); - - echo "
    \n"; - echo "

    " . __('Caution: You are about to delete 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"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - wp_nonce_field('delete-comment_' . $comment->comment_ID); - echo ""; - echo "  "; - echo "\n"; - echo "
    \n"; - echo "
    \n"; - - break; - -case 'deletecomment': - $comment = (int) $_GET['comment']; - check_admin_referer('delete-comment_' . $comment); - - $p = (int) $_GET['p']; - if (isset($_GET['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!'), 'post.php')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - die( __('You are not allowed to edit comments on this post.') ); - - wp_set_comment_status($comment->comment_ID, "delete"); - do_action('delete_comment', $comment->comment_ID); - - if ((wp_get_referer() != "") && (false == $noredir)) { - wp_redirect(wp_get_referer()); - } else { - wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); - } - - 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 ((wp_get_referer() != "") && (false == $noredir)) { - wp_redirect(wp_get_referer()); - } else { - wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); - } - - break; - -case 'mailapprovecomment': - $comment = (int) $_GET['comment']; - check_admin_referer('approve-comment_' . $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( __('You are not allowed to edit comments on this post, so you cannot approve this comment.') ); - - if ('1' != $comment->comment_approved) { - wp_set_comment_status($comment->comment_ID, 'approve'); - if (true == get_option('comments_notify')) - wp_notify_postauthor($comment->comment_ID); - } - - wp_redirect(get_option('siteurl') . '/wp-admin/moderation.php?approved=1'); - - 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 ((wp_get_referer() != "") && (false == $noredir)) { - wp_redirect(wp_get_referer()); - } else { - wp_redirect(get_settings('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); - } - - 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(); - - $location = ( empty($_POST['referredby']) ? "edit.php?p=$comment_post_ID&c=1" : $_POST['referredby'] ) . '#comment-' . $comment_ID; - $location = apply_filters('comment_edit_redirect', $location, $comment_ID); - wp_redirect($location); exit(); break; default: - $title = __('Create New Post'); - require_once ('./admin-header.php'); -?> - - - - -
    -

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

    -
    - -
    -'.__('WordPress bookmarklet').' -

    '.__('Right click on the following link and choose "Add to favorites" to create a posting shortcut.').'

    '; ?> -

    - - - - - - -
    -
    -
    - - - - - - -

    -
    - -
    -

    -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')); ?> -

    -
    - */ include('admin-footer.php'); ?> diff --git a/wp-admin/profile-update.php b/wp-admin/profile-update.php index 90913dfb..c74621b4 100644 --- a/wp-admin/profile-update.php +++ b/wp-admin/profile-update.php @@ -1,25 +1,22 @@ $error) { - echo $error . '
    '; - } +if ( is_wp_error( $errors ) ) { + foreach( $errors->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'] ) @@ -30,4 +27,4 @@ else wp_redirect( $to ); exit; -?> \ No newline at end of file +?> diff --git a/wp-admin/profile.php b/wp-admin/profile.php index 9f42bb2b..1759e51a 100644 --- a/wp-admin/profile.php +++ b/wp-admin/profile.php @@ -1,9 +1,12 @@ -" />

    -
    +

    + + +

    + + + + +

    + +

    +

    +

    +

    -
    +

    +

    -

    +


    -
    - -

    -

    +
    + +

    +

    -
    +

    @@ -107,20 +121,13 @@ if ( $show_password_fields ) :
    -

    - -

    - - - - - caps) > count($profileuser->roles)): - ?> - - - + +
    + caps) > count($profileuser->roles)): + ?> +
    caps as $cap => $value) { if(!$wp_roles->is_role($cap)) { @@ -135,9 +142,7 @@ if ( $show_password_fields ) : endif; ?>
    -

    - -

    +

    diff --git a/wp-admin/rtl.css b/wp-admin/rtl.css new file mode 100644 index 00000000..07612a66 --- /dev/null +++ b/wp-admin/rtl.css @@ -0,0 +1,133 @@ +html, +.dbx-handle, +#post_name, +input[name=link_url], +input[name=link_image], +input[name=opml_url], +input[name=file], +input#rss_uri, +#template #newcontent, +#devnews, +#planetnews, +#content, +body.login #login a, +#newcomment_author_url, +#email { + direction: ltr; + } +#adminmenu, +#submenu, +#minisub, +.wrap, +.updated, +.confirm, +#devnews h3, +#planetnews h3, +#wphead, +#user_info, +body.login, +#login_error { + direction: rtl; + } +p.submit, +.dbx-handle { + text-align: left; + } +html *, +select, +input, +table * { + font-family: tahoma, Tahoma, "Times New Roman", Times, serif; + } +#wphead { + padding: .8em 2em .8em 19em; + } +#user_info { + right: auto; + left: 1em; + } +#adminmenu { + padding: .2em 2em .3em .2em; + height: 28px; + } +* html #adminmenu { + padding-bottom: 0; + } +#adminmenu a { + margin: 0 0 0 10px; + display: block; + float: right; + font: 700 16px/130% "Times New Roman", Times, serif; + } +#adminmenu a.current { + border-right: 0; + border-left: 2px solid #4f96c8; + } +#submenu, #minisub { + padding: 1px 3em 0 2em; + } +#submenu { + height: 28px; + } +#submenu a { + margin: 0 0 0 10px; + display: block; + float: right; + line-height: 155%; + } +#submenu .current { + border-right: 0; + border-left: 2px solid #045290; + } +.dbx-content input, .dbx-content select { + margin-right: 8px; + } +#newcat { + width: 100px; + } +.updated, .confirm { + background-position: 98.5%; + padding: 0 3em 0 1em; + } +.page-numbers { + margin-right: auto; + margin-left: 3px; + } +.wrap ul { + margin-right: 45%; + margin-left: 0; + } +* html .wrap ul { + margin-right: 50%; + } +.wrap h2 { + font-family: "Times New Roman", Times, serif; + } +#zeitgeist { + margin-right: 1em; + } +#zeitgeist ul { + margin: 0 .6em .3em 0; + padding: 0 .6em 0 0; + } +#categorydiv ul { + margin-left: auto; + margin-right: 10px; + } +a.view-link { + left: 6%; + right: auto; + margin-right: auto; + } +#postdiv #quicktags { + padding-right: 0; + padding-left: 6px; + margin-right: 0; + } +.options ul { + margin-right: 0; + } +*form#template > div > textarea#newcontent { + margin-right: -300px; + width: 107%; + } \ No newline at end of file diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index c3bc45c9..b4dae209 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -1,19 +1,29 @@ 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.

    "); if (isset($_GET['step'])) $step = $_GET['step']; else $step = 0; -header( 'Content-Type: text/html; charset=utf-8' ); + +function display_header(){ + header( 'Content-Type: text/html; charset=utf-8' ); ?> @@ -76,109 +86,114 @@ header( 'Content-Type: text/html; charset=utf-8' );

    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.

    "); +}//end function display_header(); 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. -
    + display_header(); +?> + +

    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!

    -

    + display_header(); + ?> +

    -

    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.
    -

    - -

    -
    +

    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.
    +

    + +

    + error) ) + wp_die($wpdb->error->get_error_message()); - // We'll fail here if the values are no good. - require_once('../wp-includes/wp-db.php'); $handle = fopen('../wp-config.php', 'w'); - foreach ($configFile as $line_num => $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; + foreach ($configFile as $line_num => $line) { + switch (substr($line,0,16)) { + case "define('DB_NAME'": + fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line)); + break; + case "define('DB_USER'": + fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line)); + break; + case "define('DB_PASSW": + fwrite($handle, str_replace("'yourpasswordhere'", "'$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); + 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!

    + + display_header(); +?> +

    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!

    WordPress › Posted - +

    Posted !

    @@ -28,21 +28,21 @@ if ('b' == $_GET['a']) { WordPress › Sidebar - + @@ -65,9 +65,9 @@ Post:

    - + - +

    diff --git a/wp-admin/templates.php b/wp-admin/templates.php index 5f678046..a061072e 100644 --- a/wp-admin/templates.php +++ b/wp-admin/templates.php @@ -3,21 +3,7 @@ require_once('admin.php'); $title = __('Template & File Editing'); $parent_file = 'edit.php'; -$wpvarstoreset = array('action','redirect','profile','error','warning','a','file'); -for ($i=0; $i'.__('You have do not have sufficient permissions to edit templates for this blog.').'

    '); + wp_die('

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

    '); $newcontent = stripslashes($_POST['newcontent']); if (is_writeable($real_file)) { @@ -62,18 +48,19 @@ 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.').'

    '); + wp_die('

    '.__('You 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!').'

    '); + if (strpos($file, 'wp-config.php') !== false) + wp_die('

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

    '); update_recently_edited($file); - if ( !is_file($real_file) ) { + if (!is_file($real_file)) $error = true; - } else { + + if (!$error) { $f = @ fopen($real_file, 'r'); if ( $f ) { if ( filesize($real_file ) > 0 ) { @@ -93,9 +80,9 @@ default:

    - + -
    +
    ' . sprintf(__('Editing %s'), wp_specialchars($file) ) . ''; @@ -104,8 +91,8 @@ if (is_writeable($real_file)) { } ?>
    -

    -
      - -
    • - -
    +
      + +
    • + +
    -
    - -
    - - -
    + + +
    + + +
    -

    +

    "; + echo ""; ?>

    -
    - +

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

    '; } @@ -156,14 +143,14 @@ endif;

    -

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

    -
    - - -
    +

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

    +
    + + +
    -

    -
    +

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

    '); + wp_die('

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

    '); $newcontent = stripslashes($_POST['newcontent']); $theme = urlencode($theme); @@ -72,16 +58,17 @@ case 'update': 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.').'

    '); + wp_die('

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

    '); + + require_once('admin-header.php'); 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)); @@ -93,7 +80,7 @@ default:

    -
    + - +
    -
    +
    ' . sprintf(__('Editing %s'), $file_show) . ''; @@ -119,47 +106,47 @@ default: } ?>
    -

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

    +

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

    - -
    +
    -
    - -
    - - - + ?> + + +
    + + +
    -

    +

    "; + echo ""; ?>

    - - +

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

    '; } ?>
     
    -
    + +include("admin-footer.php") ?> diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 87678ff3..8aa783aa 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -3,16 +3,16 @@ require_once('admin.php'); if ( isset($_GET['action']) ) { check_admin_referer('switch-theme_' . $_GET['template']); - + if ('activate' == $_GET['action']) { if ( isset($_GET['template']) ) update_option('template', $_GET['template']); - + if ( isset($_GET['stylesheet']) ) update_option('stylesheet', $_GET['stylesheet']); - + do_action('switch_theme', get_current_theme()); - + wp_redirect('themes.php?activated=true'); exit; } @@ -26,7 +26,7 @@ require_once('admin-header.php');

    -

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

    +

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

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

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

    +

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

    description; ?>

    parent_theme) { ?>

    %2$s. The stylesheet files are located in %3$s. %4$s uses templates from %5$s. Changes made to the templates will affect both themes.'), $ct->title, $ct->template_dir, $ct->stylesheet_dir, $ct->title, $ct->parent_theme); ?>

    @@ -69,10 +69,10 @@ foreach ($theme_names as $theme_name) { $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); + $activate_link = wp_nonce_url("themes.php?action=activate&template=".urlencode($template)."&stylesheet=".urlencode($stylesheet), 'switch-theme_' . $template); ?>
    $title$description
    $title$description
    diff --git a/wp-admin/update-links.php b/wp-admin/update-links.php index eff00db0..66412798 100644 --- a/wp-admin/update-links.php +++ b/wp-admin/update-links.php @@ -1,14 +1,14 @@ get_col("SELECT link_url FROM $wpdb->links"); if ( !$link_uris ) - die('No links'); + wp_die(__('No links')); $link_uris = urlencode( join( $link_uris, "\n" ) ); @@ -16,7 +16,7 @@ $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-Type: application/x-www-form-urlencoded; charset='.get_option('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"; @@ -28,13 +28,13 @@ if ( false !== ( $fs = @fsockopen('api.pingomatic.com', 80, $errno, $errstr, 5) 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) ); diff --git a/wp-admin/upgrade-functions.php b/wp-admin/upgrade-functions.php index 37112769..f78602de 100644 --- a/wp-admin/upgrade-functions.php +++ b/wp-admin/upgrade-functions.php @@ -1,847 +1,4 @@ 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, $table_prefix; - - // 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 ' . $table_prefix . 'optionvalues'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiontypes'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_prefix . 'optiongroups'); - $wpdb->query('DROP TABLE IF EXISTS ' . $table_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() { - global $wpdb, $table_prefix, $wp_current_db_version; - - populate_roles_160(); - - $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); - foreach ( $users as $user ) : - 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, $table_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, $table_prefix . 'capabilities'); - if ( empty($caps) || defined('RESET_CAPS') ) { - $level = get_usermeta($user->ID, $table_prefix . 'user_level'); - $role = translate_level_to_role($level); - update_usermeta( $user->ID, $table_prefix . 'capabilities', array($role => true) ); - } - - endforeach; - $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_status='publish' AND category_id = '$cat_id'"); - $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'"); - } - } - - // 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']); - } - } -} - -// 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() { - // 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'; - } -} - -?> +// Deprecated. Use includes/upgrade.php. +require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); +?> \ No newline at end of file diff --git a/wp-admin/upgrade.php b/wp-admin/upgrade.php index aa459514..1758d4c9 100644 --- a/wp-admin/upgrade.php +++ b/wp-admin/upgrade.php @@ -1,95 +1,56 @@ wp-config.php file. I need this before we can get started. Need more help? We got it. You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file."); + require('../wp-config.php'); timer_start(); -require_once(ABSPATH . '/wp-admin/upgrade-functions.php'); +require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); -$step = $_GET['step']; -if (!$step) $step = 0; -header( 'Content-Type: text/html; charset=utf-8' ); +if (isset($_GET['step'])) + $step = (int) $_GET['step']; +else + $step = 0; +@header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset')); ?> - +> - WordPress › Upgrade - - + + <?php _e('WordPress › Upgrade'); ?> +

    WordPress

    - + +

    +

    +

    + + -

    -

    + $goback = clean_url(stripslashes(wp_get_referer())); +?> +

    +

    +

    +

    -

    -

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

    + if ( empty( $_GET['backto'] ) ) + $backto = __get_option('home') . '/'; + else + $backto = clean_url(stripslashes($_GET['backto'])); +?> +

    +

    +

    + break; +endswitch; +endif; +?> - + \ No newline at end of file diff --git a/wp-admin/upload.php b/wp-admin/upload.php new file mode 100644 index 00000000..bfbd9fc6 --- /dev/null +++ b/wp-admin/upload.php @@ -0,0 +1,135 @@ +get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'"); +$post_atts = 0; + +if ( $pid ) { + // 0 => tab display name, 1 => required cap, 2 => function that produces tab content, 3 => total number objects OR array(total, objects per page), 4 => add_query_args + $wp_upload_tabs['upload'] = array(__('Upload'), 'upload_files', 'wp_upload_tab_upload', 0); + if ( $all_atts && $post_atts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = '$post_id'") ) + $wp_upload_tabs['browse'] = array(__('Browse'), 'upload_files', "wp_upload_tab_browse", $action ? 0 : $post_atts); + if ( $post_atts < $all_atts ) + $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts); +} else + $wp_upload_tabs['browse-all'] = array(__('Browse All'), 'upload_files', 'wp_upload_tab_browse', $action ? 0 : $all_atts); + + $wp_upload_tabs = array_merge($wp_upload_tabs, apply_filters( 'wp_upload_tabs', array() )); + +if ( !is_callable($wp_upload_tabs[$tab][2]) ) { + $to_tab = isset($wp_upload_tabs['upload']) ? 'upload' : 'browse-all'; + wp_redirect( add_query_arg( 'tab', $to_tab ) ); + exit; +} + +foreach ( $wp_upload_tabs as $t => $tab_array ) { + if ( !current_user_can( $tab_array[1] ) ) { + unset($wp_upload_tabs[$t]); + if ( $tab == $t ) + wp_die(__("You are not allowed to be here")); + } +} + +if ( 'inline' == $style ) : ?> + + > + + +<?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — WordPress + + + + + + +
    +

    +\n"; +foreach ( $wp_upload_tabs as $t => $tab_array ) { // We've already done the current_user_can check + $href = add_query_arg( array('tab' => $t, 'ID' => '', 'action' => '', 'paged' => '') ); + if ( isset($tab_array[4]) && is_array($tab_array[4]) ) + $href = add_query_arg( $tab_array[4], $href ); + $_href = clean_url( $href); + $page_links = ''; + $class = 'upload-tab alignleft'; + if ( $tab == $t ) { + $class .= ' current'; + if ( $tab_array[3] ) { + if ( is_array($tab_array[3]) ) { + $total = $tab_array[3][0]; + $per = $tab_array[3][1]; + } else { + $total = $tab_array[3]; + $per = 10; + } + $page_links = paginate_links( array( + 'base' => add_query_arg( 'paged', '%#%' ), + 'format' => '', + 'total' => ceil($total / $per), + 'current' => $paged ? $paged : 1, + 'prev_text' => '«', + 'next_text' => '»' + )); + if ( $page_links ) + $page_links = ": $page_links"; + } + } + + echo "\t
  • {$tab_array[0]}$page_links
  • \n"; +} +unset($t, $tab_array, $href, $_href, $page_links, $total, $per, $class); +echo "\n\n"; + +echo "
    \n"; + +call_user_func( $wp_upload_tabs[$tab][2] ); + +echo "
    \n"; + +if ( 'inline' != $style ) : + echo "
    "; + include_once('admin-footer.php'); +else : ?> + + + + + diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php index 1d597587..f18807ce 100644 --- a/wp-admin/user-edit.php +++ b/wp-admin/user-edit.php @@ -2,29 +2,20 @@ require_once('admin.php'); $title = __('Edit User'); -$parent_file = 'profile.php'; +if ( current_user_can('edit_users') ) + $parent_file = 'users.php'; +else + $parent_file = 'profile.php'; $submenu_file = 'users.php'; -$wpvarstoreset = array('action', 'redirect', 'profile', 'user_id'); -for ($i=0; $i

    + +

    +
    - +
      $error"; + foreach( $errors->get_error_messages() as $message ) + echo "
    • $message
    • "; ?>
    @@ -81,11 +75,18 @@ if (!current_user_can('edit_users'))
    + + +

    +

    + +

    +

    -

    @@ -178,13 +190,13 @@ if ( $show_password_fields ) :
    - - caps) > count($profileuser->roles)): - ?> - - - + + - - -
    + caps) > count($profileuser->roles)): + ?> +
    caps as $cap => $value) { if(!$wp_roles->is_role($cap)) { @@ -194,15 +206,15 @@ if ( $show_password_fields ) : } echo $output; ?>
    + + +

    - +

    diff --git a/wp-admin/users.php b/wp-admin/users.php index fcd4fe03..7797b2ce 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -1,40 +1,150 @@ '; +} elseif ( isset($_POST['wp_http_referer']) ) { + $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), 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 WHERE 1=1 $search_sql"; + + } + + 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 + $this->paging_text = paginate_links( array( + 'total' => ceil($this->total_users_for_query / $this->users_per_page), + 'current' => $this->page, + 'prev_text' => __('« Previous Page'), + 'next_text' => __('Next Page »'), + 'base' => 'users.php?%_%', + 'format' => 'userspage=%#%', + 'add_args' => array( 'usersearch' => urlencode($this->search_term) ) + ) ); + } + } + + function get_results() { + return (array) $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'])) { - wp_redirect('users.php'); + wp_redirect($redirect); exit(); } if ( !current_user_can('edit_users') ) - die(__('You can’t edit users.')); + wp_die(__('You can’t edit users.')); - $userids = $_POST['users']; + $userids = $_POST['users']; $update = 'promote'; - foreach($userids as $id) { + foreach($userids as $id) { + if ( ! current_user_can('edit_user', $id) ) + wp_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')) { + 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']); - } - - wp_redirect('users.php?update=' . $update); + $user = new WP_User($id); + $user->set_role($_POST['new_role']); + } + + wp_redirect(add_query_arg('update', $update, $redirect)); exit(); break; @@ -44,22 +154,26 @@ case 'dodelete': check_admin_referer('delete-users'); if ( empty($_POST['users']) ) { - wp_redirect('users.php'); + wp_redirect($redirect); exit(); } - if ( !current_user_can('edit_users') ) - die(__('You can’t delete users.')); + if ( !current_user_can('delete_users') ) + wp_die(__('You can’t delete users.')); $userids = $_POST['users']; - $update = 'del'; - foreach ($userids as $id) { - if($id == $current_user->id) { + $delete_count = 0; + + foreach ( (array) $userids as $id) { + if ( ! current_user_can('delete_user', $id) ) + wp_die(__('You can’t delete that user.')); + + if($id == $current_user->ID) { $update = 'err_admin_del'; continue; } - switch($_POST['delete_option']) { + switch($_POST['delete_option']) { case 'delete': wp_delete_user($id); break; @@ -67,10 +181,13 @@ case 'dodelete': wp_delete_user($id, $_POST['reassign_user']); break; } + ++$delete_count; } - wp_redirect('users.php?update=' . $update); + $redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect); + wp_redirect($redirect); exit(); + break; case 'delete': @@ -78,12 +195,12 @@ case 'delete': check_admin_referer('bulk-users'); if ( empty($_POST['users']) ) { - wp_redirect('users.php'); + wp_redirect($redirect); exit(); } - if ( !current_user_can('edit_users') ) - $error['edit_users'] = __('You can’t delete users.'); + if ( !current_user_can('delete_users') ) + $errors = new WP_Error('edit_users', __('You can’t delete users.')); $userids = $_POST['users']; @@ -91,33 +208,32 @@ case 'delete': ?>
    +

      id) { + foreach ( (array) $userids as $id ) { + $user = new WP_User($id); + if ( $id == $current_user->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 ORDER BY user_login"); - $user_dropdown = ''; - ?> -
    - -

    + } + $all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login"); + $user_dropdown = ''; + ?> + + +

    • @@ -137,35 +253,44 @@ break; case 'adduser': check_admin_referer('add-user'); - - $errors = add_user(); - - if ( count($errors) == 0 ) { - wp_redirect('users.php?update=add'); - exit(); + + if ( ! current_user_can('create_users') ) + wp_die(__('You can’t create users.')); + + $user_id = add_user(); + $update = 'add'; + if ( is_wp_error( $user_id ) ) + $add_user_errors = $user_id; + else { + $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_POST['user_login']), true)); + $redirect = add_query_arg( array('usersearch' => urlencode($new_user_login), 'update' => $update), $redirect ); + wp_redirect( $redirect . '#user-' . $user_id ); + die(); } default: - - include ('admin-header.php'); - - $userids = $wpdb->get_col("SELECT ID FROM $wpdb->users;"); - - foreach($userids as $userid) { + wp_enqueue_script('admin-users'); + + include('admin-header.php'); + + // Query the users + $wp_user_search = new WP_User_Search($_GET['usersearch'], $_GET['userspage']); + + // Make the user objects + foreach ( $wp_user_search->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; - } - - ?> + } - -

      + +

      + endif; ?> + +
        $error"; + foreach ( $errors->get_error_messages() as $message ) + echo "
      • $message
      • "; ?>
      - - - - + +
      -

      - - $roleclass) { - uksort($roleclass, "strnatcasecmp"); - ?> - - + is_search() ) : ?> +

      search_term)); ?>

      + +

      + - + +

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

      + + +

      first_user && $wp_user_search->total_users_for_query <= 50 ) + printf(__('%3$s shown below'), $wp_user_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); + else + printf(__('%1$s – %2$s of %3$s shown below'), $wp_user_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(); ?>

      + + + + +
      -

      role_names[$role]; ?>

      -
      + $roleclass) { + uksort($roleclass, "strnatcasecmp"); +?> + + + + + + + + + - - - - user_email; - $url = $user_object->user_url; - $short_url = str_replace('http://', '', $url); - $short_url = str_replace('www.', '', $short_url); - if ('/' == substr($short_url, -1)) - $short_url = substr($short_url, 0, -1); - if (strlen($short_url) > 35) - $short_url = substr($short_url, 0, 32).'...'; - $style = ('class="alternate"' == $style) ? '' : 'class="alternate"'; - $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$user_object->ID' and post_status = 'publish'"); - if (0 < $numposts) $numposts = "$numposts"; - echo " - - - - - - "; - echo ""; - echo ''; - echo ''; - } - - ?> - + + + + + + + +

      role_names[$role]; ?>

       
      $email$short_url$numposts'; - if (current_user_can('edit_users')) - echo "".__('Edit').""; - echo '
      + +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 = attribute_escape(stripslashes($_POST[$formpost])); + } + unset($name); } ?> - +
      +

      -

      -'; -foreach($wp_roles->role_names as $role => $name) { - $role_select .= ""; -} -$role_select .= ''; -?> -
        -
      • -
      • '.__('Set the Role of checked users to:')." $role_select"; ?>
      • -
      -

      -
      - + +
      + get_error_messages() as $message ) + echo "

      $message

      "; + ?> +
      + +
      + +
      -
      -

      -'.sprintf(__('Users can register themselves or you can manually create users here.'), get_settings('siteurl').'/wp-register.php').'

      '; ?> -
      - - - - - - - - - - - - - - - - - - - - - - ' . sprintf(__('Users can register themselves or you can manually create users here.'), get_option('siteurl').'/wp-register.php') . '

      '; + else + echo '

      ' . sprintf(__('Users cannot currently register themselves, but you can manually create users here.'), get_option('siteurl').'/wp-admin/options-general.php#users_can_register') . '

      '; ?> - - - - + + +
      -
      -
      -
      + + + + + + + + + + + + + + + + + + + + + + + + + + -
      +
      +
      -

      - -

      -
      + + + + + + + +

      + + +

      + + +
      - diff --git a/wp-admin/widgets.php b/wp-admin/widgets.php new file mode 100644 index 00000000..a33dc846 --- /dev/null +++ b/wp-admin/widgets.php @@ -0,0 +1,360 @@ + + + + $sidebar ) { + $cols[] = '\'' . $index . '\''; + } + $cols = implode( ', ', $cols ); + + $widgets = array(); + foreach ( $wp_registered_widgets as $name => $widget ) { + $widgets[] = '\'' . $widget['id'] . '\''; + } + $widgets = implode( ', ', $widgets ); +?> + +
    ' + : ''; + + $output = '
  • %2$s
  • '; + + printf( $output, $sanitized_name, $wp_registered_widgets[$name]['name'] . $popper ); +} + +$title = __( 'Widgets' ); +$parent_file = 'themes.php'; + +require_once 'admin-header.php'; + +if ( count( $wp_registered_sidebars ) < 1 ) { +?> +
    +

    + +

    follow these instructions.' ); /* TODO: article on codex */; ?>

    +
    + $sidebar ) { + $postindex = $index . 'order'; + + parse_str( $_POST[$postindex], $order ); + + $new_order = $order[$index]; + + if ( is_array( $new_order ) ) { + foreach ( $new_order as $sanitized_name ) { + foreach ( $wp_registered_widgets as $name => $widget ) { + if ( $sanitized_name == $widget['id'] ) { + $sidebars_widgets[$index][] = $name; + } + } + } + } + } + + wp_set_sidebars_widgets( $sidebars_widgets ); + break; + } +} + +ksort( $wp_registered_widgets ); + +$inactive_widgets = array(); + +foreach ( $wp_registered_widgets as $name => $widget ) { + $is_active = false; + + foreach ( $wp_registered_sidebars as $index => $sidebar ) { + if ( is_array( $sidebars_widgets[$index] ) && in_array( $name, $sidebars_widgets[$index] ) ) { + $is_active = true; + break; + } + } + + if ( !$is_active ) { + $inactive_widgets[] = $name; + } +} + +$containers = array( 'palette' ); + +foreach ( $wp_registered_sidebars as $index => $sidebar ) { + $containers[] = $index; +} + +$c_string = ''; + +foreach ( $containers as $container ) { + $c_string .= '"' . $container . '",'; +} + +$c_string = substr( $c_string, 0, -1 ); + +if ( isset( $_POST['action'] ) ) { +?> +
    +

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

    +
    + +
    +

    + +

    + +
    +

    + +

    +
    + $sidebar ) { + ?> + + +
    +

    + +
    + +

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

    + +
      + +
    +
    + + + +

    + + + +

    + +
    + $widget ) { ?> + + +
    +
    + +
    +
    + +
    + + + + diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index fcfdbdff..a3ecba2a 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -20,6 +20,12 @@ a.delete:hover { color: #fff; } +#devnews h4 { + font-family: Georgia, "Times New Roman", Times, serif; + font-size: 18px; + font-weight: normal; +} + #planetnews ul { list-style: none; margin: 0; @@ -40,24 +46,80 @@ a.delete:hover { overflow: hidden; } -a.edit, a.delete, a.edit:hover, a.delete:hover { +#planetnews cite { + font-size: 11px; +} + +#planetnews li .post { + font-family: Georgia, "Times New Roman", Times, serif; + font-size: 18px; + display: block; + height: 60px; + overflow: hidden; +} + +#planetnews .hidden { + display: none; +} + +.readmore { + clear: both; + text-align: right; + margin-right: 5em; +} + +.widefat { + width: 100%; +} + +.widefat td, .widefat th { + padding: 5px 6px; +} + +.widefat th { + text-align: left; +} + +.plugins p { + margin: 4px; + padding: 0; +} + +.plugins .name { + font-size: 16px; +} + +.import-system { + font-size: 16px; +} + +thead, .thead { + background: #dfdfdf +} + +#import-upload-form { + margin: auto; + background: #eee; + padding: 1em; +} + +a.view, a.edit, a.delete, a.view:hover, a.edit:hover, a.delete:hover { border-bottom: none; display: block; padding: 5px 0; text-align: center; } -a.edit:hover { +a.view:hover, a.edit:hover { background: #ccc; color: #036; } a:visited { - color: #006; + color: #004; } a:hover { -/* border-bottom: 1px solid #3a75ae;*/ color: #069; } @@ -69,7 +131,7 @@ body { } body, td { - font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana; + font: 13px "Lucida Grande", "Lucida Sans Unicode", Tahoma, Verdana, sans-serif; } fieldset { @@ -91,17 +153,14 @@ fieldset legend { padding: .1em .3em; } -fieldset span.cat-nest { - display: block; - margin-left: 10px; -} - fieldset.options { padding: 1em; } fieldset.options legend { - font-size: 16px; + font-size: 1.5em; + font-weight: bold; + font-family: Georgia, "Times New Roman", Times, serif; } form, label input { @@ -110,26 +169,13 @@ form, label input { } h2 { - border-bottom: .5em solid #f0f8ff; color: #333; - font: normal 30px/5px serif; + font: normal 32px Georgia, "Times New Roman", Times, serif; margin: 5px 10px; + background: url( images/heading-bg.gif ) repeat-x bottom; } -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 { +img { border: 0; } @@ -147,25 +193,24 @@ li, dd { } p, li, dl, dd, dt { - line-height: 130%; + line-height: 140%; } textarea, input, select { background: #f4f4f4; border: 1px solid #b2b2b2; color: #000; - font: 13px Verdana, Arial, Helvetica, sans-serif; + font: 13px Verdana, Arial, Helvetica, sans-serif; margin: 1px; padding: 3px; } #uploading { border-style: none; - padding: 0px; + padding: 0; margin-bottom: 16px; - height: 15em; + height: 18em; width: 100%; -/* overflow-y: hidden;*/ } form#upload th { @@ -241,8 +286,19 @@ form#upload #post_content { } .commentlist li { - border-bottom: 1px solid #369; - padding: .3em 1em; + border-bottom: 1px solid #ccc; + padding: 1em 1em .2em; + margin: 0; +} + +.commentlist li li { + border-bottom: 0px; + padding: 0; +} + +.commentlist p { + padding: 0; + margin: 0 0 .8em; } .clear { @@ -277,7 +333,7 @@ form#upload #post_content { font: 12px Georgia, "Times New Roman", Times, serif; } -.submit input, .submit input:focus, .button { +.submit input, .submit input:focus, .button, .button:focus { background: url( images/fade-butt.png ); border: 3px double #999; border-left-color: #ccc; @@ -293,6 +349,14 @@ form#upload #post_content { border-top-color: #999; } +.button, .button:focus { + padding: 0.15em; +} + +* html .button { + padding: 0; +} + .submit, .editform th, #postcustomsubmit { text-align: right; } @@ -308,6 +372,8 @@ form#upload #post_content { .optiontable th { width: 33%; text-align: right; + font-size: 1.3em; + font-weight: normal; } .unapproved { @@ -326,8 +392,20 @@ form#upload #post_content { color: #009ef0; } -.updated { - background: #CFEBF7 url(images/notice.gif) no-repeat 1em ; +.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; @@ -345,15 +423,28 @@ form#upload #post_content { border: 1px solid #ccc; clear: both; margin: 15px 5%; - padding: .5em 1em; + padding: 1em; +} + +.narrow { + width: 450px; + margin: auto; +} + +.narrow p { + line-height: 150%; } .wrap h2 { - margin: .8em 0 .5em; + margin: 0 0 .5em; clear: both; } -table .vers, table .name { +* html .wrap h2 { + margin-top: 1em; +} + +table .vers { text-align: center; } @@ -366,14 +457,15 @@ input.disabled, textarea.disabled { } #adminmenu { - background: #6da6d1; + background: #83B4D8; border-top: 3px solid #448abd; margin: 0; - padding: .2em .2em .2em 2em; + padding: .2em .2em .3em 2em; } #adminmenu .current, #submenu .current { font-weight: bold; + text-decoration: none; } #adminmenu a { @@ -382,10 +474,10 @@ input.disabled, textarea.disabled { font-weight: normal; margin: 0; padding: 3px 5px; - text-decoration: none; + border-bottom: none; } -#adminmenu a:hover, .current { +#adminmenu a:hover, #adminmenu a.current { background: #ddeaf4; color: #333; } @@ -395,15 +487,28 @@ input.disabled, textarea.disabled { line-height: 200%; list-style: none; text-align: center; + white-space: nowrap; } -#submenu { +#adminmenu a.current { + background: #0d324f; + border-right: 2px solid #4f96c8; + border-top: 1px solid #96c0de; + color: #fff; + padding-bottom: 8px; +} + +#submenu, #minisub { background: #0d324f; border-bottom: none; margin: 0; padding: 3px 2em 0 3em; } +#minisub { + height: 6px; +} + #submenu .current { background: #f9fcfe; border-top: 1px solid #045290; @@ -415,7 +520,7 @@ input.disabled, textarea.disabled { border: none; color: #fff; font-size: 12px; - padding: .3em .4em .33em; + padding: .3em .4em .4em; } #submenu a:hover { @@ -424,41 +529,37 @@ input.disabled, textarea.disabled { } #submenu li { - line-height: 170%; + line-height: 180%; + height: 25px; } - #categorydiv input, #poststatusdiv input, #commentstatusdiv input, #pingstatusdiv input { border: none; } -#titlediv, #guiddiv { +#postdiv, #titlediv, #guiddiv, #tagdiv { margin: 0 8px 0 0; - padding: 0px; -} - -#postdiv { - margin: 0 8px 0 0; - padding: 0px; + padding: 0; } #postdivrich { - margin: 0px; - padding: 0px; + margin: 0; + padding: 0; } #content { - margin: 0 0 0 0; + margin: 0; width: 100%; } -#titlediv input, #guiddiv input { - margin: 0px; - width: 100%; +#postdivrich #content { + padding: 5px; + line-height: 140%; } -#quicktags { - margin-left: -1px; +#titlediv input, #guiddiv input, #tagdiv input { + margin: 0; + width: 100%; } #currenttheme img { @@ -469,11 +570,40 @@ input.disabled, textarea.disabled { width: 300px; } -#deletepost:hover { +input.delete:hover { background: #ce0000; color: #fff; } +#deletebookmarks:hover { + background: #ce0000; + color: #fff; +} + +#postdivrich #quicktags { + background: #f0f0ee; + padding: 0; + border: 1px solid #ccc; + border-bottom: none; +} + +#postdiv #quicktags { + padding-right: 6px; +} + +#postdivrich #quicktags { + display: none; +} + +#quicktags #ed_toolbar { + padding: 0 2px; +} + +#ed_toolbar input { + background: #fff url( images/fade-butt.png ) repeat-x 0 -2px; + margin: 3px 2px 2px; +} + #quicktags #ed_strong { font-weight: bold; } @@ -493,10 +623,12 @@ input.disabled, textarea.disabled { #quicktags #ed_code { font-family: "Courier New", Courier, mono; + margin-bottom: 3px; } #title { - font-size: 1.5em; + font-size: 1.7em; + padding: 4px 3px; } #postexcerpt div, #attachmentlinks div { @@ -514,69 +646,163 @@ input.disabled, textarea.disabled { } #excerpt, .attachmentlinks { - margin: 0px; + margin: 0; height: 4em; width: 100%; } #footer { clear: both; - text-align: center; + height: 35px; + padding-left: 40px; + margin: 15px 5%; + background: url('images/logo-ghost.png') no-repeat top left; +} + +#footer p { + margin: 0; + padding: 5px 0; } #login { - background: #fff; - border: 1px solid #a2a2a2; - margin: 5em auto; - padding: 1.5em; - width: 25em; + position: relative; + background: url('images/login-bkg-tile.gif') no-repeat top center; + color: #fff; + margin: 5em auto 1em; + padding: 20px 0 0; + width: 425px; + _width: 390px; +} + +#login form { + background: url('images/login-bkg-bottom.gif') no-repeat bottom center; + padding: 0 50px 25px; + _width: 325px; + _margin: 0 auto; + min-height: 200px; + height: auto !important; /* min-height fast hack */ + height: 200px; } #login #login_error { - background: #c00; - border: 1px solid #a40000; - color: #fff; - font-size: 16px; + background: #0e3350; + border: 1px solid #2571ab; + color: #ebcd4e; + font-size: 11px; font-weight: bold; - padding: .5em; + padding: .6em; + width: 310px; + margin: 0 50px; text-align: center; } -#login h1 { - background: url(images/wordpress-logo.png) no-repeat top left; - margin-top: 0; +#login p { + font-size: 12px; +} + +#login p.message { + width: 310px; + margin: 0 auto 1em; +} + +#login #login_error a { + color: #ebcd4e; + border-color: #ebcd4e; +} + +#login #send { + color: #fff; + text-align: left; + font-weight: normal; + font-size: 1.1em; + _width: 325px; + _margin: 0 auto 15px; } #login h1 a { + margin: 0 auto; + height: 88px; + width: 320px; display: block; - text-indent: -1000px; - height: 66px; border-bottom: none; + text-indent: -9999px; +} + +#login .message { + font-size: 10pt; + text-align: center; +} + +#login .register { + font-size: 20px; } #login input { - padding: 3px; + padding: 4px; } -#login ul { +.login ul, #protected #login .bottom { list-style: none; - margin: 0; + width: 325px; + margin: 0 auto; padding: 0; + line-height: 1.2; } -#login ul li { - display: inline; - margin-left: 1.4em; - text-align: center; +.login ul li { + font-size: 11px; } -#login #log, #pwd { - font-size: 1.7em; - width: 80%; +.login ul li a { + color: #0d324f; + border: none; +} + +#login ul li a:hover { + color: #fff; +} + +#login .input { + font-size: 1.8em; + margin-top: 3px; + width: 97%; +} + +#login p label { + font-size: 11px; } #login #submit { - font-size: 1.7em; + margin: 0; + font-size: 15px; +} + +.plugins p { +} + +#login .fullwidth { + width: 320px; +} + +#searchform fieldset { + float: left; + margin: 0 1.5ex 1em 0; + padding: 0; +} + +#searchform fieldset legend { + padding: 0 0 .2em 1px; +} + +#searchform #s { + padding: 4px 3px; +} + +#searchform #post-query-submit { + float: left; + margin: 14px 0 1em; + position: relative; + top: .35em; } #postcustom .updatemeta, #postcustom .deletemeta { @@ -585,7 +811,7 @@ input.disabled, textarea.disabled { #postcustom table { border: 1px solid #ccc; - margin: 0px; + margin: 0; width: 100%; } @@ -606,7 +832,7 @@ input.disabled, textarea.disabled { } * html #template div { - margin-right: 0px; + margin-right: 0; } #template, #template div, #editcat, #addcat { @@ -621,9 +847,10 @@ input.disabled, textarea.disabled { #templateside { float: right; width: 170px; + overflow: hidden; } -#templateside h3, #postcustom p { +#templateside h3, #postcustom p.submit { margin: 0; } @@ -660,17 +887,17 @@ input.disabled, textarea.disabled { font-weight: normal; letter-spacing: -.05em; margin: 0; - font-family: Georgia, "Times New Roman", Times, serif + font-family: Georgia, "Times New Roman", Times, serif; } -#wphead h1 span { +#wphead h1 span#viewsite { font-size: .4em; letter-spacing: 0; } #zeitgeist { background: #eee; - border: 1px solid #69c; + border: 1px solid #c5c5c5; float: right; font-size: 90%; margin-bottom: .5em; @@ -681,11 +908,11 @@ input.disabled, textarea.disabled { } #zeitgeist h2, fieldset legend a { - border-bottom: none; + background: none; } -#zeitgeist h2 { - margin-top: .4em; +* html #zeitgeist h2 { + padding-top: 10px; } #zeitgeist h3 { @@ -721,36 +948,44 @@ input.disabled, textarea.disabled { 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; */ +Some browsers will disable them when you +set display:none; */ .zerosize { - height: 0px; - width: 0px; - margin: 0px; - border: 0px; - padding: 0px; + height: 0; + width: 0; + margin: 0; + border: 0; + padding: 0; overflow: hidden; position: absolute; } /* Box stuff */ .dbx-clone { - position:absolute; - visibility:hidden; + position: absolute; + visibility: hidden; } .dbx-clone, .dbx-clone .dbx-handle-cursor { - cursor:move !important; + cursor: move !important; } .dbx-dummy { - display:block; - width:0; - height:0; - overflow:hidden; + display: block; + width: 0; + height: 0; + overflow: hidden; } .dbx-group, .dbx-box, .dbx-handle { - position:relative; - display:block; + position: relative; + display: block; } #grabit { @@ -758,19 +993,19 @@ input.disabled, textarea.disabled { } * html #themeselect { - padding: 0px 3px; + padding: 0 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 +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; + margin: 0; + padding: 0; + border: none; } /* Can change this */ @@ -778,7 +1013,7 @@ input.disabled, textarea.disabled { margin-bottom: 1em; } #moremeta fieldset div { - margin: 2px 0 0 0px; + margin: 2px 0 0 0; padding: 7px; } #moremeta { @@ -807,24 +1042,41 @@ input.disabled, textarea.disabled { margin-top: .5em; } -#categorydiv div div { +#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 #rich_editing { + border: none; + background: #fff; +} + #your-profile fieldset { border: 1px solid #ccc; float: left; width: 40%; - padding: .5em 2em; - margin: 1em; + padding: .5em 2em 1em; + margin: 1em 1em 1em 0; } -#your-profile fieldset input { +#your-profile fieldset input { width: 100%; font-size: 20px; padding: 2px; @@ -863,7 +1115,7 @@ input.disabled, textarea.disabled { /* handles */ -.dbx-handle { +.dbx-handle { background: #2685af; padding: 6px 1em 2px; font-size: 12px; @@ -885,6 +1137,8 @@ input.disabled, textarea.disabled { margin-left: 7px; margin-bottom: -7px; padding: 6px 1em 0 3px; + height: 19px; + font-size: 12px; background: #2685af url(images/box-head-right.gif) no-repeat top right; } @@ -896,7 +1150,7 @@ input.disabled, textarea.disabled { #advancedstuff div.dbx-content { margin-left: 8px; background: url(images/box-bg-right.gif) repeat-y right; - padding: 10px 10px 15px 0px; + padding: 10px 10px 15px 0; } #postexcerpt div.dbx-content { @@ -929,30 +1183,29 @@ input.disabled, textarea.disabled { background: url(images/box-butt-right.gif) no-repeat bottom right; } - /* handle cursors */ .dbx-handle-cursor { cursor: move; } - + /* toggle images */ a.dbx-toggle, a.dbx-toggle:visited { - display:block; + display: block; overflow: hidden; background-image: url( images/toggle.gif ); position: absolute; - top: 0px; - right: 0px; + top: 0; + right: 0; background-repeat: no-repeat; - border: 0px; - margin: 0px; - padding: 0px; + border: 0; + margin: 0; + padding: 0; } #moremeta a.dbx-toggle, #moremeta a.dbx-toggle-open:visited { height: 25px; width: 27px; - background-position: 0 0px; + background-position: 0 0; } #moremeta a.dbx-toggle-open, #moremeta a.dbx-toggle-open:visited { @@ -989,8 +1242,13 @@ a.dbx-toggle, a.dbx-toggle:visited { filter: alpha(opacity=80); } -#newcat { width: 120px; margin-right: 5px; } -input#catadd { background: #a4a4a4; +#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; @@ -1003,13 +1261,90 @@ input#catadd { background: #a4a4a4; height: 20px; margin-bottom: 2px; text-align: center; - width: 37px; } + width: 37px; +} + #howto { font-size: 11px; margin: 0 5px; display: block; } + #jaxcat { margin: 0; padding: 0; +} + +#ajax-response.alignleft { + margin-left: 2em; +} + +#postdivrich #edButtons { + padding-left: 3px; +} + +#postdivrich #content, #postdivrich #content:active { + border: 1px solid #ccc; +} + +#edButtons input, #edButtons input:active { + margin: 0 2px -1px; +} + +#edButtons input.edButtonFore, #edButtons input.edButtonFore:active { + background: #f0f0ee; + border-bottom: 1px solid #f0f0ee; +} + +#edButtons input.edButtonBack, #edButtons input.edButtonBack:active { + background: #fff url( images/fade-butt.png ) repeat-x 0 15px; + border-bottom: 1px solid #ccc; +} + +.page-numbers { + padding: 4px 7px; + border: 1px solid #fff; + margin-right: 3px; +} + +a.page-numbers { + border: 1px solid #ccc; +} + +a.page-numbers:hover { + border: 1px solid #999; +} + +.page-numbers.current { + border: 1px solid #999; + font-weight: bold; +} + +.pagenav span { + font-weight: bold; + margin: 0 6px; +} + +a.view-link { + position: absolute; + right: 5%; + margin-right: 220px; + text-decoration:underline; +} + +#update-nag, .plugin-update { + border-bottom: 1px solid #ccc; + border-top: 1px solid #ccc; + background: #fffeeb; + line-height: 29px; + font-size: 12px; + color: #555; + text-align: center; +} + +#update-nag a, .plugin-update a { + font-size: 1.1em; +} +#update-nag a:link, .plugin-update a:link { + color: #036; } \ No newline at end of file diff --git a/wp-app.php b/wp-app.php new file mode 100644 index 00000000..e0fdaf32 --- /dev/null +++ b/wp-app.php @@ -0,0 +1,1159 @@ +ID) ) + return $current_user; + + $current_user = new WP_User($id, $name); + + return $current_user; +} +endif; + +function wa_posts_where_include_drafts_filter($where) { + $where = str_replace("post_status = 'publish'","post_status = 'publish' OR post_status = 'future' OR post_status = 'draft' OR post_status = 'inherit'", $where); + return $where; + +} +add_filter('posts_where', 'wa_posts_where_include_drafts_filter'); + +class AtomServer { + + var $ATOM_CONTENT_TYPE = 'application/atom+xml'; + var $CATEGORIES_CONTENT_TYPE = 'application/atomcat+xml'; + var $SERVICE_CONTENT_TYPE = 'application/atomsvc+xml'; + + var $ATOM_NS = 'http://www.w3.org/2005/Atom'; + var $ATOMPUB_NS = 'http://www.w3.org/2007/app'; + + var $ENTRIES_PATH = "posts"; + var $CATEGORIES_PATH = "categories"; + var $MEDIA_PATH = "attachments"; + var $ENTRY_PATH = "post"; + var $SERVICE_PATH = "service"; + var $MEDIA_SINGLE_PATH = "attachment"; + + var $params = array(); + var $script_name = "wp-app.php"; + var $media_content_types = array('image/*','audio/*','video/*'); + var $atom_content_types = array('application/atom+xml'); + + var $selectors = array(); + + // support for head + var $do_output = true; + + function AtomServer() { + + $this->script_name = array_pop(explode('/',$_SERVER['SCRIPT_NAME'])); + + $this->selectors = array( + '@/service$@' => + array('GET' => 'get_service'), + '@/categories$@' => + array('GET' => 'get_categories_xml'), + '@/post/(\d+)$@' => + array('GET' => 'get_post', + 'PUT' => 'put_post', + 'DELETE' => 'delete_post'), + '@/posts/?(\d+)?$@' => + array('GET' => 'get_posts', + 'POST' => 'create_post'), + '@/attachments/?(\d+)?$@' => + array('GET' => 'get_attachment', + 'POST' => 'create_attachment'), + '@/attachment/file/(\d+)$@' => + array('GET' => 'get_file', + 'PUT' => 'put_file', + 'DELETE' => 'delete_file'), + '@/attachment/(\d+)$@' => + array('GET' => 'get_attachment', + 'PUT' => 'put_attachment', + 'DELETE' => 'delete_attachment'), + ); + } + + function handle_request() { + global $always_authenticate; + + $path = $_SERVER['PATH_INFO']; + $method = $_SERVER['REQUEST_METHOD']; + + log_app('REQUEST',"$method $path\n================"); + + $this->process_conditionals(); + //$this->process_conditionals(); + + // exception case for HEAD (treat exactly as GET, but don't output) + if($method == 'HEAD') { + $this->do_output = false; + $method = 'GET'; + } + + // redirect to /service in case no path is found. + if(strlen($path) == 0 || $path == '/') { + $this->redirect($this->get_service_url()); + } + + // dispatch + foreach($this->selectors as $regex => $funcs) { + if(preg_match($regex, $path, $matches)) { + if(isset($funcs[$method])) { + + // authenticate regardless of the operation and set the current + // user. each handler will decide if auth is required or not. + $this->authenticate(); + $u = wp_get_current_user(); + if(!isset($u) || $u->ID == 0) { + if ($always_authenticate) { + $this->auth_required('Credentials required.'); + } + } + + array_shift($matches); + call_user_func_array(array(&$this,$funcs[$method]), $matches); + exit(); + } else { + // only allow what we have handlers for... + $this->not_allowed(array_keys($funcs)); + } + } + } + + // oops, nothing found + $this->not_found(); + } + + function get_service() { + log_app('function','get_service()'); + + if( !current_user_can( 'edit_posts' ) ) + $this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) ); + + $entries_url = attribute_escape($this->get_entries_url()); + $categories_url = attribute_escape($this->get_categories_url()); + $media_url = attribute_escape($this->get_attachments_url()); + foreach ($this->media_content_types as $med) { + $accepted_media_types = $accepted_media_types . "" . $med . ""; + } + $atom_prefix="atom"; + $service_doc = << + + <$atom_prefix:title>WordPress Workspace + + <$atom_prefix:title>WordPress Posts + $this->ATOM_CONTENT_TYPE;type=entry + + + + <$atom_prefix:title>WordPress Media + $accepted_media_types + + + + +EOD; + + $this->output($service_doc, $this->SERVICE_CONTENT_TYPE); + } + + function get_categories_xml() { + log_app('function','get_categories_xml()'); + + if( !current_user_can( 'edit_posts' ) ) + $this->auth_required( __( 'Sorry, you do not have the right to access this blog.' ) ); + + $home = attribute_escape(get_bloginfo_rss('home')); + + $categories = ""; + $cats = get_categories("hierarchical=0&hide_empty=0"); + foreach ((array) $cats as $cat) { + $categories .= " name) . "\" />\n"; +} + $output = << + $categories + +EOD; + $this->output($output, $this->CATEGORIES_CONTENT_TYPE); +} + + /* + * Create Post (No arguments) + */ + function create_post() { + global $blog_id, $wpdb; + $this->get_accepted_content_type($this->atom_content_types); + + $parser = new AtomParser(); + if(!$parser->parse()) { + $this->client_error(); + } + + $entry = array_pop($parser->feed->entries); + + log_app('Received entry:', print_r($entry,true)); + + $catnames = array(); + foreach($entry->categories as $cat) + array_push($catnames, $cat["term"]); + + $wp_cats = get_categories(array('hide_empty' => false)); + + $post_category = array(); + + foreach($wp_cats as $cat) { + if(in_array($cat->name, $catnames)) + array_push($post_category, $cat->term_id); + } + + $publish = (isset($entry->draft) && trim($entry->draft) == 'yes') ? false : true; + + $cap = ($publish) ? 'publish_posts' : 'edit_posts'; + + if(!current_user_can($cap)) + $this->auth_required(__('Sorry, you do not have the right to edit/publish new posts.')); + + $blog_ID = (int ) $blog_id; + $post_status = ($publish) ? 'publish' : 'draft'; + $post_author = (int) $user->ID; + $post_title = $entry->title[1]; + $post_content = $entry->content[1]; + $post_excerpt = $entry->summary[1]; + $pubtimes = $this->get_publish_time($entry); + $post_date = $pubtimes[0]; + $post_date_gmt = $pubtimes[1]; + + if ( isset( $_SERVER['HTTP_SLUG'] ) ) + $post_name = $_SERVER['HTTP_SLUG']; + + $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_name'); + + $this->escape($post_data); + log_app('Inserting Post. Data:', print_r($post_data,true)); + + $postID = wp_insert_post($post_data); + if ( is_wp_error( $postID ) ) + $this->internal_error($postID->get_error_message()); + + if (!$postID) { + $this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.')); + } + + // getting warning here about unable to set headers + // because something in the cache is printing to the buffer + // could we clean up wp_set_post_categories or cache to not print + // this could affect our ability to send back the right headers + @wp_set_post_categories($postID, $post_category); + + $output = $this->get_entry($postID); + + log_app('function',"create_post($postID)"); + $this->created($postID, $output); + } + + function get_post($postID) { + global $entry; + + if( !current_user_can( 'edit_post', $postID ) ) + $this->auth_required( __( 'Sorry, you do not have the right to access this post.' ) ); + + $this->set_current_entry($postID); + $output = $this->get_entry($postID); + log_app('function',"get_post($postID)"); + $this->output($output); + + } + + function put_post($postID) { + global $wpdb; + + // checked for valid content-types (atom+xml) + // quick check and exit + $this->get_accepted_content_type($this->atom_content_types); + + $parser = new AtomParser(); + if(!$parser->parse()) { + $this->bad_request(); + } + + $parsed = array_pop($parser->feed->entries); + + log_app('Received UPDATED entry:', print_r($parsed,true)); + + // check for not found + global $entry; + $entry = $GLOBALS['entry']; + $this->set_current_entry($postID); + + if(!current_user_can('edit_post', $entry['ID'])) + $this->auth_required(__('Sorry, you do not have the right to edit this post.')); + + $publish = (isset($parsed->draft) && trim($parsed->draft) == 'yes') ? false : true; + + extract($entry); + + $post_title = $parsed->title[1]; + $post_content = $parsed->content[1]; + $post_excerpt = $parsed->summary[1]; + $pubtimes = $this->get_publish_time($entry); + $post_date = $pubtimes[0]; + $post_date_gmt = $pubtimes[1]; + + // let's not go backwards and make something draft again. + if(!$publish && $post_status == 'draft') { + $post_status = ($publish) ? 'publish' : 'draft'; + } elseif($publish) { + $post_status = 'publish'; + } + + $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'post_date', 'post_date_gmt'); + $this->escape($postdata); + + $result = wp_update_post($postdata); + + if (!$result) { + $this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.')); + } + + log_app('function',"put_post($postID)"); + $this->ok(); + } + + function delete_post($postID) { + + // check for not found + global $entry; + $this->set_current_entry($postID); + + if(!current_user_can('edit_post', $postID)) { + $this->auth_required(__('Sorry, you do not have the right to delete this post.')); + } + + if ($entry['post_type'] == 'attachment') { + $this->delete_attachment($postID); + } else { + $result = wp_delete_post($postID); + + if (!$result) { + $this->internal_error(__('For some strange yet very annoying reason, this post could not be deleted.')); + } + + log_app('function',"delete_post($postID)"); + $this->ok(); + } + + } + + function get_attachment($postID = NULL) { + if( !current_user_can( 'upload_files' ) ) + $this->auth_required( __( 'Sorry, you do not have the right to file uploads on this blog.' ) ); + + if (!isset($postID)) { + $this->get_attachments(); + } else { + $this->set_current_entry($postID); + $output = $this->get_entry($postID, 'attachment'); + log_app('function',"get_attachment($postID)"); + $this->output($output); + } + } + + function create_attachment() { + global $wp, $wpdb, $wp_query, $blog_id; + + $type = $this->get_accepted_content_type(); + + if(!current_user_can('upload_files')) + $this->auth_required(__('You do not have permission to upload files.')); + + $fp = fopen("php://input", "rb"); + $bits = NULL; + while(!feof($fp)) { + $bits .= fread($fp, 4096); + } + fclose($fp); + + $slug = ''; + if ( isset( $_SERVER['HTTP_SLUG'] ) ) + $slug = sanitize_file_name( $_SERVER['HTTP_SLUG'] ); + elseif ( isset( $_SERVER['HTTP_TITLE'] ) ) + $slug = sanitize_file_name( $_SERVER['HTTP_TITLE'] ); + elseif ( empty( $slug ) ) // just make a random name + $slug = substr( md5( uniqid( microtime() ) ), 0, 7); + $ext = preg_replace( '|.*/([a-z]+)|', '$1', $_SERVER['CONTENT_TYPE'] ); + $slug = "$slug.$ext"; + $file = wp_upload_bits( $slug, NULL, $bits); + + log_app('wp_upload_bits returns:',print_r($file,true)); + + $url = $file['url']; + $file = $file['file']; + $filename = basename($file); + + $header = apply_filters('wp_create_file_in_uploads', $file); // replicate + + // Construct the attachment array + $attachment = array( + 'post_title' => $slug, + 'post_content' => $slug, + 'post_status' => 'attachment', + 'post_parent' => 0, + 'post_mime_type' => $type, + 'guid' => $url + ); + + // Save the data + $postID = wp_insert_attachment($attachment, $file, $post); + + if (!$postID) { + $this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.')); + } + + $output = $this->get_entry($postID, 'attachment'); + + $this->created($postID, $output, 'attachment'); + log_app('function',"create_attachment($postID)"); + } + + function put_attachment($postID) { + global $wpdb; + + // checked for valid content-types (atom+xml) + // quick check and exit + $this->get_accepted_content_type($this->atom_content_types); + + $parser = new AtomParser(); + if(!$parser->parse()) { + $this->bad_request(); + } + + $parsed = array_pop($parser->feed->entries); + + // check for not found + global $entry; + $this->set_current_entry($postID); + + if(!current_user_can('edit_post', $entry['ID'])) + $this->auth_required(__('Sorry, you do not have the right to edit this post.')); + + $publish = (isset($parsed->draft) && trim($parsed->draft) == 'yes') ? false : true; + + extract($entry); + + $post_title = $parsed->title[1]; + $post_content = $parsed->content[1]; + + $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); + $this->escape($postdata); + + $result = wp_update_post($postdata); + + if (!$result) { + $this->internal_error(__('For some strange yet very annoying reason, this post could not be edited.')); + } + + log_app('function',"put_attachment($postID)"); + $this->ok(); + } + + function delete_attachment($postID) { + log_app('function',"delete_attachment($postID). File '$location' deleted."); + + // check for not found + global $entry; + $this->set_current_entry($postID); + + if(!current_user_can('edit_post', $postID)) { + $this->auth_required(__('Sorry, you do not have the right to delete this post.')); + } + + $location = get_post_meta($entry['ID'], '_wp_attached_file', true); + $filetype = wp_check_filetype($location); + + if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext'])) + $this->internal_error(__('Error ocurred while accessing post metadata for file location.')); + + // delete file + @unlink($location); + + // delete attachment + $result = wp_delete_post($postID); + + if (!$result) { + $this->internal_error(__('For some strange yet very annoying reason, this post could not be deleted.')); + } + + log_app('function',"delete_attachment($postID). File '$location' deleted."); + $this->ok(); + } + + function get_file($postID) { + + // check for not found + global $entry; + $this->set_current_entry($postID); + + // then whether user can edit the specific post + if(!current_user_can('edit_post', $postID)) { + $this->auth_required(__('Sorry, you do not have the right to edit this post.')); + } + + $location = get_post_meta($entry['ID'], '_wp_attached_file', true); + $filetype = wp_check_filetype($location); + + if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext'])) + $this->internal_error(__('Error ocurred while accessing post metadata for file location.')); + + status_header('200'); + header('Content-Type: ' . $entry['post_mime_type']); + header('Connection: close'); + + $fp = fopen($location, "rb"); + while(!feof($fp)) { + echo fread($fp, 4096); + } + fclose($fp); + + log_app('function',"get_file($postID)"); + exit; + } + + function put_file($postID) { + + $type = $this->get_accepted_content_type(); + + // first check if user can upload + if(!current_user_can('upload_files')) + $this->auth_required(__('You do not have permission to upload files.')); + + // check for not found + global $entry; + $this->set_current_entry($postID); + + // then whether user can edit the specific post + if(!current_user_can('edit_post', $postID)) { + $this->auth_required(__('Sorry, you do not have the right to edit this post.')); + } + + $location = get_post_meta($entry['ID'], '_wp_attached_file', true); + $filetype = wp_check_filetype($location); + + if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext'])) + $this->internal_error(__('Error ocurred while accessing post metadata for file location.')); + + $fp = fopen("php://input", "rb"); + $localfp = fopen($location, "w+"); + while(!feof($fp)) { + fwrite($localfp,fread($fp, 4096)); + } + fclose($fp); + fclose($localfp); + + $ID = $entry['ID']; + $pubtimes = $this->get_publish_time($entry); + $post_date = $pubtimes[0]; + $post_date_gmt = $pubtimes[1]; + + $post_data = compact('ID', 'post_date', 'post_date_gmt'); + $result = wp_update_post($post_data); + + if (!$result) { + $this->internal_error(__('Sorry, your entry could not be posted. Something wrong happened.')); + } + + log_app('function',"put_file($postID)"); + $this->ok(); + } + + function get_entries_url($page = NULL) { + if($GLOBALS['post_type'] == 'attachment') { + $path = $this->MEDIA_PATH; + } else { + $path = $this->ENTRIES_PATH; + } + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $path; + if(isset($page) && is_int($page)) { + $url .= "/$page"; + } + return $url; + } + + function the_entries_url($page = NULL) { + $url = $this->get_entries_url($page); + echo $url; + } + + function get_categories_url($page = NULL) { + return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->CATEGORIES_PATH; + } + + function the_categories_url() { + $url = $this->get_categories_url(); + echo $url; + } + + function get_attachments_url($page = NULL) { + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_PATH; + if(isset($page) && is_int($page)) { + $url .= "/$page"; + } + return $url; + } + + function the_attachments_url($page = NULL) { + $url = $this->get_attachments_url($page); + echo $url; + } + + function get_service_url() { + return get_bloginfo('url') . '/' . $this->script_name . '/' . $this->SERVICE_PATH; + } + + function get_entry_url($postID = NULL) { + if(!isset($postID)) { + global $post; + $postID = (int) $GLOBALS['post']->ID; + } + + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->ENTRY_PATH . "/$postID"; + + log_app('function',"get_entry_url() = $url"); + return $url; + } + + function the_entry_url($postID = NULL) { + $url = $this->get_entry_url($postID); + echo $url; + } + + function get_media_url($postID = NULL) { + if(!isset($postID)) { + global $post; + $postID = (int) $GLOBALS['post']->ID; + } + + $url = get_bloginfo('url') . '/' . $this->script_name . '/' . $this->MEDIA_SINGLE_PATH ."/file/$postID"; + + log_app('function',"get_media_url() = $url"); + return $url; + } + + function the_media_url($postID = NULL) { + $url = $this->get_media_url($postID); + echo $url; + } + + function set_current_entry($postID) { + global $entry; + log_app('function',"set_current_entry($postID)"); + + if(!isset($postID)) { + // $this->bad_request(); + $this->not_found(); + } + + $entry = wp_get_single_post($postID,ARRAY_A); + + if(!isset($entry) || !isset($entry['ID'])) + $this->not_found(); + + return; + } + + function get_posts($page = 1, $post_type = 'post') { + log_app('function',"get_posts($page, '$post_type')"); + $feed = $this->get_feed($page, $post_type); + $this->output($feed); + } + + function get_attachments($page = 1, $post_type = 'attachment') { + log_app('function',"get_attachments($page, '$post_type')"); + $GLOBALS['post_type'] = $post_type; + $feed = $this->get_feed($page, $post_type); + $this->output($feed); + } + + function get_feed($page = 1, $post_type = 'post') { + global $post, $wp, $wp_query, $posts, $wpdb, $blog_id, $post_cache; + log_app('function',"get_feed($page, '$post_type')"); + ob_start(); + + if(!isset($page)) { + $page = 1; + } + $page = (int) $page; + + $count = get_option('posts_per_rss'); + + wp('what_to_show=posts&posts_per_page=' . $count . '&offset=' . ($count * ($page-1) )); + + $post = $GLOBALS['post']; + $posts = $GLOBALS['posts']; + $wp = $GLOBALS['wp']; + $wp_query = $GLOBALS['wp_query']; + $wpdb = $GLOBALS['wpdb']; + $blog_id = (int) $GLOBALS['blog_id']; + $post_cache = $GLOBALS['post_cache']; + log_app('function',"query_posts(# " . print_r($wp_query, true) . "#)"); + + log_app('function',"total_count(# $wp_query->max_num_pages #)"); + $last_page = $wp_query->max_num_pages; + $next_page = (($page + 1) > $last_page) ? NULL : $page + 1; + $prev_page = ($page - 1) < 1 ? NULL : $page - 1; + $last_page = ((int)$last_page == 1 || (int)$last_page == 0) ? NULL : (int) $last_page; + $self_page = $page > 1 ? $page : NULL; +?> +the_entries_url() ?> + +<?php bloginfo_rss('name') ?> + + + + + + + + + + +Copyright +WordPress.com Atom API +echo_entry(); + } + } +?> +echo_entry(); + log_app('$post',print_r($GLOBALS['post'],true)); + $entry = ob_get_contents(); + break; + } + } + ob_end_clean(); + + log_app('get_entry returning:',$entry); + return $entry; + } + + function echo_entry() { ?> + + ID); ?> +prep_content(get_the_title()); ?> + <?php echo $content ?> + + + + + post_status == 'draft' ? 'yes' : 'no') ?> + + + + + + + +post_type == 'attachment') { ?> + + + + +post_content ) ) : +list($content_type, $content) = $this->prep_content(get_the_content()); ?> + + + + + + + +prep_content(get_the_excerpt()); ?> + + +' . $data . '
    ', true); + $code = xml_get_error_code($parser); + xml_parser_free($parser); + + if (!$code) { + if (strpos($data, '<') === false) { + return array('text', $data); + } else { + $data = "
    $data
    "; + return array('xhtml', $data); + } + } + + if (strpos($data, ']]>') == false) { + return array('html', ""); + } else { + return array('html', htmlspecialchars($data)); + } + } + + function ok() { + log_app('Status','200: OK'); + header('Content-Type: text/plain'); + status_header('200'); + exit; + } + + function no_content() { + log_app('Status','204: No Content'); + header('Content-Type: text/plain'); + status_header('204'); + echo "Deleted."; + exit; + } + + function internal_error($msg = 'Internal Server Error') { + log_app('Status','500: Server Error'); + header('Content-Type: text/plain'); + status_header('500'); + echo $msg; + exit; + } + + function bad_request() { + log_app('Status','400: Bad Request'); + header('Content-Type: text/plain'); + status_header('400'); + exit; + } + + function length_required() { + log_app('Status','411: Length Required'); + header("HTTP/1.1 411 Length Required"); + header('Content-Type: text/plain'); + status_header('411'); + exit; + } + + function invalid_media() { + log_app('Status','415: Unsupported Media Type'); + header("HTTP/1.1 415 Unsupported Media Type"); + header('Content-Type: text/plain'); + exit; + } + + function not_found() { + log_app('Status','404: Not Found'); + header('Content-Type: text/plain'); + status_header('404'); + exit; + } + + function not_allowed($allow) { + log_app('Status','405: Not Allowed'); + header('Allow: ' . join(',', $allow)); + status_header('405'); + exit; + } + + function redirect($url) { + + log_app('Status','302: Redirect'); + $escaped_url = attribute_escape($url); + $content = << + + + 302 Found + + +

    Found

    +

    The document has moved here.

    + + + +EOD; + header('HTTP/1.1 302 Moved'); + header('Content-Type: text/html'); + header('Location: ' . $url); + echo $content; + exit; + + } + + + function client_error($msg = 'Client Error') { + log_app('Status','400: Client Error'); + header('Content-Type: text/plain'); + status_header('400'); + exit; + } + + function created($post_ID, $content, $post_type = 'post') { + log_app('created()::$post_ID',"$post_ID, $post_type"); + $edit = $this->get_entry_url($post_ID); + switch($post_type) { + case 'post': + $ctloc = $this->get_entry_url($post_ID); + break; + case 'attachment': + $edit = get_bloginfo('url') . '/' . $this->script_name . "/attachments/$post_ID"; + break; + } + header("Content-Type: $this->ATOM_CONTENT_TYPE"); + if(isset($ctloc)) + header('Content-Location: ' . $ctloc); + header('Location: ' . $edit); + status_header('201'); + echo $content; + exit; + } + + function auth_required($msg) { + log_app('Status','401: Auth Required'); + nocache_headers(); + header('WWW-Authenticate: Basic realm="WordPress Atom Protocol"'); + header("HTTP/1.1 401 $msg"); + header('Status: ' . $msg); + header('Content-Type: text/html'); + $content = << + + + 401 Unauthorized + + +

    401 Unauthorized

    +

    $msg

    + + + +EOD; + echo $content; + exit; + } + + function output($xml, $ctype = 'application/atom+xml') { + status_header('200'); + $xml = ''."\n".$xml; + header('Connection: close'); + header('Content-Length: '. strlen($xml)); + header('Content-Type: ' . $ctype); + header('Content-Disposition: attachment; filename=atom.xml'); + header('Date: '. date('r')); + if($this->do_output) + echo $xml; + log_app('function', "output:\n$xml"); + exit; + } + + function escape(&$array) { + global $wpdb; + + foreach ($array as $k => $v) { + if (is_array($v)) { + $this->escape($array[$k]); + } else if (is_object($v)) { + //skip + } else { + $array[$k] = $wpdb->escape($v); + } + } + } + + /* + * Access credential through various methods and perform login + */ + function authenticate() { + $login_data = array(); + $already_md5 = false; + + log_app("authenticate()",print_r($_ENV, true)); + + // if using mod_rewrite/ENV hack + // http://www.besthostratings.com/articles/http-auth-php-cgi.html + if(isset($_SERVER['HTTP_AUTHORIZATION'])) { + list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = + explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6))); + } + + // If Basic Auth is working... + if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { + $login_data = array('login' => $_SERVER['PHP_AUTH_USER'], 'password' => $_SERVER['PHP_AUTH_PW']); + log_app("Basic Auth",$login_data['login']); + } else { + // else, do cookie-based authentication + if (function_exists('wp_get_cookie_login')) { + $login_data = wp_get_cookie_login(); + $already_md5 = true; + } + } + + // call wp_login and set current user + if (!empty($login_data) && wp_login($login_data['login'], $login_data['password'], $already_md5)) { + $current_user = new WP_User(0, $login_data['login']); + wp_set_current_user($current_user->ID); + log_app("authenticate()",$login_data['login']); + } + } + + function get_accepted_content_type($types = NULL) { + + if(!isset($types)) { + $types = $this->media_content_types; + } + + if(!isset($_SERVER['CONTENT_LENGTH']) || !isset($_SERVER['CONTENT_TYPE'])) { + $this->length_required(); + } + + $type = $_SERVER['CONTENT_TYPE']; + list($type,$subtype) = explode('/',$type); + list($subtype) = explode(";",$subtype); // strip MIME parameters + log_app("get_accepted_content_type", "type=$type, subtype=$subtype"); + + foreach($types as $t) { + list($acceptedType,$acceptedSubtype) = explode('/',$t); + if($acceptedType == '*' || $acceptedType == $type) { + if($acceptedSubtype == '*' || $acceptedSubtype == $subtype) + return $type . "/" . $subtype; + } + } + + $this->invalid_media(); + } + + function process_conditionals() { + + if(empty($this->params)) return; + if($_SERVER['REQUEST_METHOD'] == 'DELETE') return; + + switch($this->params[0]) { + case $this->ENTRY_PATH: + global $post; + $post = wp_get_single_post($this->params[1]); + $wp_last_modified = get_post_modified_time('D, d M Y H:i:s', true); + $post = NULL; + break; + case $this->ENTRIES_PATH: + $wp_last_modified = mysql2date('D, d M Y H:i:s', get_lastpostmodified('GMT'), 0).' GMT'; + break; + default: + return; + } + $wp_etag = md5($wp_last_modified); + @header("Last-Modified: $wp_last_modified"); + @header("ETag: $wp_etag"); + + // Support for Conditional GET + if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) + $client_etag = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); + else + $client_etag = false; + + $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE']); + // If string is empty, return 0. If not, attempt to parse into a timestamp + $client_modified_timestamp = $client_last_modified ? strtotime($client_last_modified) : 0; + + // Make a timestamp for our most recent modification... + $wp_modified_timestamp = strtotime($wp_last_modified); + + if ( ($client_last_modified && $client_etag) ? + (($client_modified_timestamp >= $wp_modified_timestamp) && ($client_etag == $wp_etag)) : + (($client_modified_timestamp >= $wp_modified_timestamp) || ($client_etag == $wp_etag)) ) { + status_header( 304 ); + exit; + } + } + + function rfc3339_str2time($str) { + + $match = false; + if(!preg_match("/(\d{4}-\d{2}-\d{2})T(\d{2}\:\d{2}\:\d{2})\.?\d{0,3}(Z|[+-]+\d{2}\:\d{2})/", $str, $match)) + return false; + + if($match[3] == 'Z') + $match[3] == '+0000'; + + return strtotime($match[1] . " " . $match[2] . " " . $match[3]); + } + + function get_publish_time($entry) { + + $pubtime = $this->rfc3339_str2time($entry->published); + + if(!$pubtime) { + return array(current_time('mysql'),current_time('mysql',1)); + } else { + return array(date("Y-m-d H:i:s", $pubtime), gmdate("Y-m-d H:i:s", $pubtime)); + } + } + +} + +$server = new AtomServer(); +$server->handle_request(); + +?> diff --git a/wp-atom.php b/wp-atom.php index feb2845b..4c52b97f 100644 --- a/wp-atom.php +++ b/wp-atom.php @@ -1,45 +1,10 @@ -'; ?> - - > - <?php bloginfo_rss('name') ?> - - - - Copyright - WordPress - - - - - - - <![CDATA[<?php the_title_rss() ?>]]> - - - - - - ]]> - - ]]> - - - - - - +?> \ No newline at end of file diff --git a/wp-blog-header.php b/wp-blog-header.php index c087324f..00d3ccd5 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -2,9 +2,13 @@ if (! isset($wp_did_header)): if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) { - if ( strstr( $_SERVER['PHP_SELF'], 'wp-admin') ) $path = ''; + if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = ''; else $path = 'wp-admin/'; - die("There doesn't seem to be a wp-config.php file. I need this before we can get started. Need more help? We got it. You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file."); + + require_once( dirname(__FILE__) . '/wp-includes/classes.php'); + require_once( dirname(__FILE__) . '/wp-includes/functions.php'); + require_once( dirname(__FILE__) . '/wp-includes/plugin.php'); + wp_die("There doesn't seem to be a wp-config.php file. I need this before we can get started. Need more help? We got it. You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.", "WordPress › Error"); } $wp_did_header = true; @@ -18,4 +22,4 @@ require_once(ABSPATH . WPINC . '/template-loader.php'); endif; -?> \ No newline at end of file +?> diff --git a/wp-comments-post.php b/wp-comments-post.php index 47926c12..56374595 100644 --- a/wp-comments-post.php +++ b/wp-comments-post.php @@ -1,4 +1,10 @@ comment_status) ) { exit; } elseif ( 'closed' == $status->comment_status ) { do_action('comment_closed', $comment_post_ID); - die( __('Sorry, comments are closed for this item.') ); -} elseif ( 'draft' == $status->post_status ) { + wp_die( __('Sorry, comments are closed for this item.') ); +} elseif ( in_array($status->post_status, array('draft', 'pending') ) ) { do_action('comment_on_draft', $comment_post_ID); exit; } -$comment_author = trim($_POST['author']); +$comment_author = trim(strip_tags($_POST['author'])); $comment_author_email = trim($_POST['email']); $comment_author_url = trim($_POST['url']); $comment_content = trim($_POST['comment']); @@ -37,31 +43,31 @@ if ( $user->ID ) { } } else { if ( get_option('comment_registration') ) - die( __('Sorry, you must be logged in to post a comment.') ); + wp_die( __('Sorry, you must be logged in to post a comment.') ); } $comment_type = ''; -if ( get_settings('require_name_email') && !$user->ID ) { +if ( get_option('require_name_email') && !$user->ID ) { if ( 6 > strlen($comment_author_email) || '' == $comment_author ) - die( __('Error: please fill the required fields (name, email).') ); + wp_die( __('Error: please fill the required fields (name, email).') ); elseif ( !is_email($comment_author_email)) - die( __('Error: please enter a valid email address.') ); + wp_die( __('Error: please enter a valid email address.') ); } if ( '' == $comment_content ) - die( __('Error: please type a comment.') ); + wp_die( __('Error: please type a comment.') ); $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID'); $comment_id = wp_new_comment( $commentdata ); -if ( !$user->ID ) : - $comment = get_comment($comment_id); +$comment = get_comment($comment_id); +if ( !$user->ID ) { setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); -endif; +} $location = ( empty($_POST['redirect_to']) ? get_permalink($comment_post_ID) : $_POST['redirect_to'] ) . '#comment-' . $comment_id; $location = apply_filters('comment_post_redirect', $location, $comment); diff --git a/wp-commentsrss2.php b/wp-commentsrss2.php index caddaa05..5c3f169f 100644 --- a/wp-commentsrss2.php +++ b/wp-commentsrss2.php @@ -1,86 +1,10 @@ -'; -?> - - - - - <?php if (is_single() || is_page() ) { printf(__('Comments on: %s'), get_the_title_rss()); } else { printf(__('Comments for %s'), get_bloginfo_rss("name")); } ?> - - - - http://wordpress.org/?v= +require (ABSPATH . WPINC . '/feed-rss2-comments.php'); -get_results("SELECT comment_ID, comment_author, comment_author_email, - comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, - $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments - LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE comment_post_ID = '$id' - AND $wpdb->comments.comment_approved = '1' AND $wpdb->posts.post_status IN ('publish', 'static', 'object') - AND post_date_gmt < '" . gmdate("Y-m-d H:i:59") . "' - ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') ); - } else { // if no post id passed in, we'll just ue the last 10 comments. - $comments = $wpdb->get_results("SELECT comment_ID, comment_author, comment_author_email, - comment_author_url, comment_date, comment_date_gmt, comment_content, comment_post_ID, - $wpdb->posts.ID, $wpdb->posts.post_password FROM $wpdb->comments - LEFT JOIN $wpdb->posts ON comment_post_id = id WHERE $wpdb->posts.post_status IN ('publish', 'static', 'object') - AND $wpdb->comments.comment_approved = '1' AND post_date_gmt < '" . gmdate("Y-m-d H:i:s") . "' - ORDER BY comment_date_gmt DESC LIMIT " . get_settings('posts_per_rss') ); - } - // this line is WordPress' motor, do not delete it. - if ($comments) { - foreach ($comments as $comment) { - // Some plugins may need to know the metadata - // associated with this comment's post: - get_post_custom($comment->comment_post_ID); -?> - - <?php if ( ! (is_single() || is_page()) ) { - $title = get_the_title($comment->comment_post_ID); - $title = apply_filters('the_title', $title); - $title = apply_filters('the_title_rss', $title); - printf(__('Comment on %1$s by %2$s'), $title, get_comment_author_rss()); - } else { - printf(__('by: %s'), get_comment_author_rss()); - } ?> - - - - post_password) && $_COOKIE['wp-postpass'] != $comment->post_password) { - ?> - - ]]> - - - ]]> - - - - - +?> \ No newline at end of file diff --git a/wp-config-sample.php b/wp-config-sample.php index 5cc89738..26bf086f 100644 --- a/wp-config-sample.php +++ b/wp-config-sample.php @@ -1,16 +1,18 @@ \ No newline at end of file +?> diff --git a/wp-content/index.php b/wp-content/index.php index 3d5acf05..4e6c07c7 100644 --- a/wp-content/index.php +++ b/wp-content/index.php @@ -1,3 +1,3 @@ - \ No newline at end of file diff --git a/wp-content/plugins/akismet/akismet.php b/wp-content/plugins/akismet/akismet.php index 53e9a9ff..eac40559 100644 --- a/wp-content/plugins/akismet/akismet.php +++ b/wp-content/plugins/akismet/akismet.php @@ -2,8 +2,8 @@ /* Plugin Name: Akismet Plugin URI: http://akismet.com/ -Description: Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a WordPress.com API key to use it. You can review the spam it catches under "Comments." To show off your Akismet stats just put <?php akismet_counter(); ?> in your template. -Version: 2.0.2 +Description: Akismet checks your comments against the Akismet web service to see if they look like spam or not. You need a WordPress.com API key to use it. You can review the spam it catches under "Comments." To show off your Akismet stats just put <?php akismet_counter(); ?> in your template. See also: WP Stats plugin. +Version: 2.1.3 Author: Matt Mullenweg Author URI: http://photomatt.net/ */ @@ -35,6 +35,7 @@ if ( !function_exists('wp_nonce_field') ) { function akismet_config_page() { if ( function_exists('add_submenu_page') ) add_submenu_page('plugins.php', __('Akismet Configuration'), __('Akismet Configuration'), 'manage_options', 'akismet-key-config', 'akismet_conf'); + } function akismet_conf() { @@ -146,14 +147,10 @@ function akismet_verify_key( $key ) { if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) { function akismet_warning() { echo " -

    ".__('Akismet is not active.')." ".sprintf(__('You must enter your WordPress.com API key for it to work.'), "plugins.php?page=akismet-key-config")."

    - +

    ".__('Akismet is almost ready.')." ".sprintf(__('You must enter your WordPress.com API key for it to work.'), "plugins.php?page=akismet-key-config")."

    "; } - add_action('admin_footer', 'akismet_warning'); + add_action('admin_notices', 'akismet_warning'); return; } @@ -204,6 +201,8 @@ function akismet_auto_check_comment( $comment ) { add_filter('pre_comment_approved', create_function('$a', 'return \'spam\';')); update_option( 'akismet_spam_count', get_option('akismet_spam_count') + 1 ); + do_action( 'akismet_spam_caught' ); + $post = get_post( $comment['comment_post_ID'] ); $last_updated = strtotime( $post->post_modified_gmt ); $diff = time() - $last_updated; @@ -325,17 +324,60 @@ if ( isset( $GLOBALS['submenu']['edit-comments.php'] ) ) else $link = 'edit.php'; ?> +

    %1$s spam for you since you first installed it.'), number_format($count) ); ?>

    get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'" ); + + +if ( 0 == $gotspam ) { echo '

    '.__('You have no spam currently in the queue. Must be your lucky day. :)').'

    '; echo '
    '; } else { @@ -345,7 +387,7 @@ if (0 == $spam_count) {
    -    +   
    @@ -354,7 +396,6 @@ if (0 == $spam_count) {

    -

    '.__('These are the latest comments identified as spam by Akismet. If you see any mistakes, simply mark the comment as "not spam" and Akismet will learn from the submission. If you wish to recover a comment from spam, simply select the comment, and click Not Spam. After 15 days we clean out the junk for you.').'

    '; ?> get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' ORDER BY comment_date DESC LIMIT $start, $end"); - $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam'" ); + $where = ''; + if ( isset( $_GET['ctype'] ) ) { + $type = preg_replace( '|[^a-z]|', '', $_GET['ctype'] ); + if ( 'comments' == $type ) + $type = ''; + $where = " AND comment_type = '$type' "; + } + + $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = 'spam' $where ORDER BY comment_date DESC LIMIT $start, $end"); + $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = 'spam' $where" ); + + $totals = $wpdb->get_results( "SELECT comment_type, COUNT(*) AS cc FROM $wpdb->comments WHERE comment_approved = 'spam' GROUP BY comment_type" ); +?> +
      +
    • >
    • +comment_type ) $type->comment_type = 'comments'; + $show = ucwords( $type->comment_type ); + $type->cc = number_format( $type->cc ); + $extra = ( $_GET['ctype'] == $type->comment_type ) ? ' class="active"' : ''; + echo "
    • $show ($type->cc)
    • "; +} +do_action( 'akismet_tabs' ); // so plugins can add more tabs easily +?> +
    + - +
    " id="akismetsearch"> +

    +

    +
    50 ) { $total_pages = ceil( $total / 50 ); $r = ''; if ( 1 < $page ) { $args['apage'] = ( 1 == $page - 1 ) ? '' : $page - 1; - $r .= '' . "\n"; + $r .= '' . "\n"; } if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) { for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) : @@ -413,17 +482,13 @@ if ( ( $total_pages = ceil( $total / 50 ) ) > 1 ) { } if ( ( $page ) * 50 < $total || -1 == $total ) { $args['apage'] = $page + 1; - $r .= '' . "\n"; + $r .= '' . "\n"; } echo "

    $r

    "; ?> -
    " id="akismetsearch"> -

    -

    -
    -
    +