diff --git a/wp-admin/comment.php b/wp-admin/comment.php index c4e87a2ce2..2ee54b28cd 100644 --- a/wp-admin/comment.php +++ b/wp-admin/comment.php @@ -1,220 +1,220 @@ -Go back!'), 'javascript:history.go(-1)')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - wp_die( __('You are not allowed to edit comments on this post.') ); - - $comment = get_comment_to_edit($comment); - - include('edit-form-comment.php'); - - break; - -case 'confirmdeletecomment': -case 'mailapprovecomment': - - require_once('./admin-header.php'); - - $comment = (int) $_GET['comment']; - $p = (int) $_GET['p']; - $formaction = 'confirmdeletecomment' == $action ? 'deletecomment' : 'approvecomment'; - $nonce_action = 'confirmdeletecomment' == $action ? 'delete-comment_' : 'approve-comment_'; - $nonce_action .= $comment; - - if ( ! $comment = get_comment($comment) ) - wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - wp_die( 'confirmdeletecomment' == $action ? __('You are not allowed to delete comments on this post.') : __('You are not allowed to edit comments on this post, so you cannot approve this comment.') ); -?> -
- -
- -

Caution: You are about to mark the following comment as spam:'); ?>

- -

Caution: You are about to delete the following comment:'); ?>

- -

Caution: You are about to approve the following comment:'); ?>

- - -

- -
/wp-admin/comment.php' method='get'> - - - - - - -
' onclick="self.location='/wp-admin/edit-comments.php';" />' />
- - - - - - - - - -
- - - - - - -comment_author_email ) { ?> - - - - - -comment_author_url ) { ?> - - - - - - - - - -
comment_author; ?>
comment_author_email; ?>
comment_author_url; ?>

comment_content ); ?>
- -
-
-Go back!'), 'edit.php')); - - if ( ! $comment = get_comment($comment) ) - wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit-comments.php')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - wp_die( __('You are not allowed to edit comments on this post.') ); - - if ( 'spam' == $_REQUEST['delete_type'] ) - wp_set_comment_status($comment->comment_ID, 'spam'); - else - wp_delete_comment($comment->comment_ID); - - if ((wp_get_referer() != '') && (false == $noredir)) { - wp_redirect(wp_get_referer()); - } else { - wp_redirect(get_option('siteurl') .'/wp-admin/edit-comments.php'); - } - exit(); - break; - -case 'unapprovecomment': - $comment = (int) $_GET['comment']; - check_admin_referer('unapprove-comment_' . $comment); - - $p = (int) $_GET['p']; - if (isset($_GET['noredir'])) { - $noredir = true; - } else { - $noredir = false; - } - - if ( ! $comment = get_comment($comment) ) - wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - wp_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_option('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); - } - exit(); - break; - -case 'approvecomment': - $comment = (int) $_GET['comment']; - check_admin_referer('approve-comment_' . $comment); - - $p = (int) $_GET['p']; - if (isset($_GET['noredir'])) { - $noredir = true; - } else { - $noredir = false; - } - - if ( ! $comment = get_comment($comment) ) - wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); - - if ( !current_user_can('edit_post', $comment->comment_post_ID) ) - wp_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_option("comments_notify") == true) { - wp_notify_postauthor($comment->comment_ID); - } - - - if ((wp_get_referer() != "") && (false == $noredir)) { - wp_redirect(wp_get_referer()); - } else { - wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); - } - exit(); - break; - -case 'editedcomment': - - $comment_ID = (int) $_POST['comment_ID']; - $comment_post_ID = (int) $_POST['comment_post_id']; - - check_admin_referer('update-comment_' . $comment_ID); - - edit_comment(); - - $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); - - break; -default: - break; -} // end switch - -include('admin-footer.php'); - -?> +Go back!'), 'javascript:history.go(-1)')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + wp_die( __('You are not allowed to edit comments on this post.') ); + + $comment = get_comment_to_edit($comment); + + include('edit-form-comment.php'); + + break; + +case 'confirmdeletecomment': +case 'mailapprovecomment': + + require_once('./admin-header.php'); + + $comment = (int) $_GET['comment']; + $p = (int) $_GET['p']; + $formaction = 'confirmdeletecomment' == $action ? 'deletecomment' : 'approvecomment'; + $nonce_action = 'confirmdeletecomment' == $action ? 'delete-comment_' : 'approve-comment_'; + $nonce_action .= $comment; + + if ( ! $comment = get_comment($comment) ) + wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + wp_die( 'confirmdeletecomment' == $action ? __('You are not allowed to delete comments on this post.') : __('You are not allowed to edit comments on this post, so you cannot approve this comment.') ); +?> +
+ +
+ +

Caution: You are about to mark the following comment as spam:'); ?>

+ +

Caution: You are about to delete the following comment:'); ?>

+ +

Caution: You are about to approve the following comment:'); ?>

+ + +

+ +
/wp-admin/comment.php' method='get'> + + + + + + +
' onclick="self.location='/wp-admin/edit-comments.php';" />' />
+ + + + + + + + + +
+ + + + + + +comment_author_email ) { ?> + + + + + +comment_author_url ) { ?> + + + + + + + + + +
comment_author; ?>
comment_author_email; ?>
comment_author_url; ?>

comment_content ); ?>
+ +
+
+Go back!'), 'edit.php')); + + if ( ! $comment = get_comment($comment) ) + wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit-comments.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + wp_die( __('You are not allowed to edit comments on this post.') ); + + if ( 'spam' == $_REQUEST['delete_type'] ) + wp_set_comment_status($comment->comment_ID, 'spam'); + else + wp_delete_comment($comment->comment_ID); + + if ((wp_get_referer() != '') && (false == $noredir)) { + wp_redirect(wp_get_referer()); + } else { + wp_redirect(get_option('siteurl') .'/wp-admin/edit-comments.php'); + } + exit(); + break; + +case 'unapprovecomment': + $comment = (int) $_GET['comment']; + check_admin_referer('unapprove-comment_' . $comment); + + $p = (int) $_GET['p']; + if (isset($_GET['noredir'])) { + $noredir = true; + } else { + $noredir = false; + } + + if ( ! $comment = get_comment($comment) ) + wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + wp_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_option('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); + } + exit(); + break; + +case 'approvecomment': + $comment = (int) $_GET['comment']; + check_admin_referer('approve-comment_' . $comment); + + $p = (int) $_GET['p']; + if (isset($_GET['noredir'])) { + $noredir = true; + } else { + $noredir = false; + } + + if ( ! $comment = get_comment($comment) ) + wp_die(sprintf(__('Oops, no comment with this ID. Go back!'), 'edit.php')); + + if ( !current_user_can('edit_post', $comment->comment_post_ID) ) + wp_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_option("comments_notify") == true) { + wp_notify_postauthor($comment->comment_ID); + } + + + if ((wp_get_referer() != "") && (false == $noredir)) { + wp_redirect(wp_get_referer()); + } else { + wp_redirect(get_option('siteurl') .'/wp-admin/edit.php?p='.$p.'&c=1#comments'); + } + exit(); + break; + +case 'editedcomment': + + $comment_ID = (int) $_POST['comment_ID']; + $comment_post_ID = (int) $_POST['comment_post_id']; + + check_admin_referer('update-comment_' . $comment_ID); + + edit_comment(); + + $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); + + break; +default: + break; +} // end switch + +include('admin-footer.php'); + +?> diff --git a/wp-admin/export.php b/wp-admin/export.php index 6dd953fa5d..3942aba895 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -1,108 +1,108 @@ - - -
-

-
-

-

-
-

- -

-
-
-
- -get_results("SELECT * FROM $wpdb->posts ORDER BY post_date_gmt ASC"); -?> - - - - - <?php bloginfo_rss('name'); ?> - - - - http://wordpress.org/?v= - - - - -<?php the_title_rss() ?> - - - - - - - -post_content ?>]]> -post_date; ?> -post_date_gmt; ?> -comment_status; ?> -ping_status; ?> -post_name; ?> -post_status; ?> -post_parent; ?> -post_type; ?> -get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID"); -if ( $postmeta ) { -?> - - -meta_key; ?> -meta_value; ?> - - - -get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID"); -if ( $comments ) { foreach ( $comments as $c ) { ?> - -comment_author; ?> -comment_author_email; ?> -comment_author_url; ?> -comment_author_IP; ?> -comment_date; ?> -comment_date_gmt; ?> -comment_content; ?> -comment_approved; ?> -comment_type; ?> -comment_parent; ?> - - - - - - - + +
+

+
+

+

+
+

+ +

+
+
+
+ +get_results("SELECT * FROM $wpdb->posts ORDER BY post_date_gmt ASC"); +?> + + + + + <?php bloginfo_rss('name'); ?> + + + + http://wordpress.org/?v= + + + + +<?php the_title_rss() ?> + + + + + + + +post_content ?>]]> +post_date; ?> +post_date_gmt; ?> +comment_status; ?> +ping_status; ?> +post_name; ?> +post_status; ?> +post_parent; ?> +post_type; ?> +get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID"); +if ( $postmeta ) { +?> + + +meta_key; ?> +meta_value; ?> + + + +get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID"); +if ( $comments ) { foreach ( $comments as $c ) { ?> + +comment_author; ?> +comment_author_email; ?> +comment_author_url; ?> +comment_author_IP; ?> +comment_date; ?> +comment_date_gmt; ?> +comment_content; ?> +comment_approved; ?> +comment_type; ?> +comment_parent; ?> + + + + + + + \ No newline at end of file diff --git a/wp-admin/import/blogware.php b/wp-admin/import/blogware.php index 780e45d062..7d2612f2ce 100644 --- a/wp-admin/import/blogware.php +++ b/wp-admin/import/blogware.php @@ -1,194 +1,194 @@ -'; - echo '

'.__('Import Blogware').'

'; - } - - function footer() { - echo ''; - } - - function unhtmlentities($string) { // From php.net for < 4.3 compat - $trans_tbl = get_html_translation_table(HTML_ENTITIES); - $trans_tbl = array_flip($trans_tbl); - return strtr($string, $trans_tbl); - } - - function greet() { - echo '
'; - 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 (!$post_id) { - _e("Couldn't get post ID"); - echo '
  2. '; - break; - } - if(0 != count($categories)) - wp_create_categories($categories, $post_id); - } - - preg_match_all('|(.*?)|is', $post, $comments); - $comments = $comments[1]; - - if ( $comments ) { - $comment_post_ID = $post_id; - $num_comments = 0; - foreach ($comments as $comment) { - preg_match('|(.*?)|is', $comment, $comment_content); - $comment_content = str_replace(array (''), '', trim($comment_content[1])); - $comment_content = $this->unhtmlentities($comment_content); - - // Clean up content - $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content); - $comment_content = str_replace('
    ', '
    ', $comment_content); - $comment_content = str_replace('
    ', '
    ', $comment_content); - $comment_content = $wpdb->escape($comment_content); - - preg_match('|(.*?)|is', $comment, $comment_date); - $comment_date = trim($comment_date[1]); - $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); - - preg_match('|(.*?)|is', $comment, $comment_author); - $comment_author = $wpdb->escape(trim($comment_author[1])); - - $comment_author_email = NULL; - - $comment_approved = 1; - // Check if it's already there - if (!comment_exists($comment_author, $comment_date)) { - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); - $commentdata = wp_filter_comment($commentdata); - wp_insert_comment($commentdata); - $num_comments++; - } - } - } - if ( $num_comments ) { - echo ' '; - printf(__('(%s comments)'), $num_comments); - } - echo ''; - flush(); - ob_flush(); - } - echo '
'; - } - - function import() { - $file = wp_import_handle_upload(); - if ( isset($file['error']) ) { - echo $file['error']; - return; - } - - $this->file = $file['file']; - $this->import_posts(); - wp_import_cleanup($file['id']); - - echo '

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

'; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - $this->header(); - - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - $this->import(); - break; - } - - $this->footer(); - } - - function BW_Import() { - // Nothing. - } -} - -$blogware_import = new BW_Import(); - -register_importer('blogware', __('Blogware'), __('Import posts from Blogware'), array ($blogware_import, 'dispatch')); -?> +'; + echo '

'.__('Import Blogware').'

'; + } + + function footer() { + echo ''; + } + + function unhtmlentities($string) { // From php.net for < 4.3 compat + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + return strtr($string, $trans_tbl); + } + + function greet() { + echo '
'; + 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 (!$post_id) { + _e("Couldn't get post ID"); + echo '
  2. '; + break; + } + if(0 != count($categories)) + wp_create_categories($categories, $post_id); + } + + preg_match_all('|(.*?)|is', $post, $comments); + $comments = $comments[1]; + + if ( $comments ) { + $comment_post_ID = $post_id; + $num_comments = 0; + foreach ($comments as $comment) { + preg_match('|(.*?)|is', $comment, $comment_content); + $comment_content = str_replace(array (''), '', trim($comment_content[1])); + $comment_content = $this->unhtmlentities($comment_content); + + // Clean up content + $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content); + $comment_content = str_replace('
    ', '
    ', $comment_content); + $comment_content = str_replace('
    ', '
    ', $comment_content); + $comment_content = $wpdb->escape($comment_content); + + preg_match('|(.*?)|is', $comment, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + + preg_match('|(.*?)|is', $comment, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + + $comment_author_email = NULL; + + $comment_approved = 1; + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_comments++; + } + } + } + if ( $num_comments ) { + echo ' '; + printf(__('(%s comments)'), $num_comments); + } + echo ''; + flush(); + ob_flush(); + } + echo '
'; + } + + function import() { + $file = wp_import_handle_upload(); + if ( isset($file['error']) ) { + echo $file['error']; + return; + } + + $this->file = $file['file']; + $this->import_posts(); + wp_import_cleanup($file['id']); + + echo '

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

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

'.__('Import DotClear').'

'; - echo '

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

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

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

'; - echo '

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

'; - echo '
'; - $this->db_form(); - echo '

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

'; - echo '

'.__('Users').'

'; - echo '

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

'; - echo '

'.__('Preserving Authors').'

'; - echo '

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

'; - echo '

'.__('Textile').'

'; - echo '

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

'; - echo '

'.__('WordPress Resources').'

'; - echo '

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

'; - echo ''; - echo '

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

'; - } - - function db_form() - { - echo ''; - printf('', __('Dotclear Database User:')); - printf('', __('DotClear Database Password:')); - printf('', __('Dotclear Database Name:')); - printf('', __('DotClear Database Host:')); - printf('', __('DotClear Table prefix:')); - printf('', __('Originating character set:')); - echo '
'; - } - - function dispatch() - { - - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - $this->header(); - - if ( $step > 0 ) - { - if($_POST['dbuser']) - { - if(get_option('dcuser')) - delete_option('dcuser'); - add_option('dcuser',$_POST['dbuser']); - } - if($_POST['dbpass']) - { - if(get_option('dcpass')) - delete_option('dcpass'); - add_option('dcpass',$_POST['dbpass']); - } - - if($_POST['dbname']) - { - if(get_option('dcname')) - delete_option('dcname'); - add_option('dcname',$_POST['dbname']); - } - if($_POST['dbhost']) - { - if(get_option('dchost')) - delete_option('dchost'); - add_option('dchost',$_POST['dbhost']); - } - if($_POST['dccharset']) - { - if(get_option('dccharset')) - delete_option('dccharset'); - add_option('dccharset',$_POST['dccharset']); - } - if($_POST['dbprefix']) - { - if(get_option('dcdbprefix')) - delete_option('dcdbprefix'); - add_option('dcdbprefix',$_POST['dbprefix']); - } - - - } - - switch ($step) - { - default: - case 0 : - $this->greet(); - break; - case 1 : - $this->import_categories(); - break; - case 2 : - $this->import_users(); - break; - case 3 : - $this->import_posts(); - break; - case 4 : - $this->import_comments(); - break; - case 5 : - $this->import_links(); - break; - case 6 : - $this->cleanup_dcimport(); - break; - } - - $this->footer(); - } - - function Dotclear_Import() - { - // Nothing. - } -} - -$dc_import = new Dotclear_Import(); -register_importer('dotclear', __('DotClear'), __('Import posts from a DotClear Blog'), array ($dc_import, 'dispatch')); -?> +get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); + + return $name; + } +} + +if(!function_exists('get_comment_count')) +{ + function get_comment_count($post_ID) + { + global $wpdb; + return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + } +} + +if(!function_exists('link_cat_exists')) +{ + function link_cat_exists($catname) + { + global $wpdb; + return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"'); + } +} + +if(!function_exists('link_exists')) +{ + function link_exists($linkname) + { + global $wpdb; + return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"'); + } +} + +/* + Identify UTF-8 text + Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087 +*/ +// +// utf8 encoding validation developed based on Wikipedia entry at: +// http://en.wikipedia.org/wiki/UTF-8 +// +// Implemented as a recursive descent parser based on a simple state machine +// copyright 2005 Maarten Meijer +// +// This cries out for a C-implementation to be included in PHP core +// + function valid_1byte($char) { + if(!is_int($char)) return false; + return ($char & 0x80) == 0x00; + } + + function valid_2byte($char) { + if(!is_int($char)) return false; + return ($char & 0xE0) == 0xC0; + } + + function valid_3byte($char) { + if(!is_int($char)) return false; + return ($char & 0xF0) == 0xE0; + } + + function valid_4byte($char) { + if(!is_int($char)) return false; + return ($char & 0xF8) == 0xF0; + } + + function valid_nextbyte($char) { + if(!is_int($char)) return false; + return ($char & 0xC0) == 0x80; + } + + function valid_utf8($string) { + $len = strlen($string); + $i = 0; + while( $i < $len ) { + $char = ord(substr($string, $i++, 1)); + if(valid_1byte($char)) { // continue + continue; + } else if(valid_2byte($char)) { // check 1 byte + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } else if(valid_3byte($char)) { // check 2 bytes + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } else if(valid_4byte($char)) { // check 3 bytes + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + if(!valid_nextbyte(ord(substr($string, $i++, 1)))) + return false; + } // goto next char + } + return true; // done + } + +function csc ($s) { + if (valid_utf8 ($s)) { + return $s; + } else { + return iconv(get_option ("dccharset"),"UTF-8",$s); + } +} + +function textconv ($s) { + return csc (preg_replace ('|(?)\s*\n|', ' ', $s)); +} + +/** + The Main Importer Class +**/ +class Dotclear_Import { + + function header() + { + echo '
'; + echo '

'.__('Import DotClear').'

'; + echo '

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

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

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

'; + echo '

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

'; + echo '
'; + $this->db_form(); + echo '

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

'; + echo '

'.__('Users').'

'; + echo '

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

'; + echo '

'.__('Preserving Authors').'

'; + echo '

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

'; + echo '

'.__('Textile').'

'; + echo '

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

'; + echo '

'.__('WordPress Resources').'

'; + echo '

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

'; + echo ''; + echo '

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

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

'; - wp_import_upload_form("admin.php?import=wordpress&step=1"); - echo '
'; - } - - function get_tag( $string, $tag ) { - preg_match("|<$tag.*?>(.*?)|is", $string, $return); - $return = addslashes( trim( $return[1] ) ); - return $return; - } - - function users_form($n) { - global $wpdb, $testing; - $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID"); -?> - 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 ($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); - $importdata = file($this->file); // Read the file into an array - $importdata = implode('', $importdata); // squish it - $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata); - preg_match_all('|(.*?)|is', $importdata, $this->posts); - $this->posts = $this->posts[1]; - } - - function get_wp_authors() { - $temp = array (); - $i = -1; - foreach ($this->posts as $post) { - if ('' != trim($post)) { - ++ $i; - $author = $this->get_tag( $post, 'dc:creator' ); - array_push($temp, "$author"); //store the extracted author names in a temporary array - } - } - - // We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. - $authors[0] = array_shift($temp); - $y = count($temp) + 1; - for ($x = 1; $x < $y; $x ++) { - $next = array_shift($temp); - if (!(in_array($next, $authors))) - array_push($authors, "$next"); - } - - return $authors; - } - - function get_authors_from_post() { - $formnames = array (); - $selectnames = array (); - - foreach ($_POST['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 '
    '; - $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']) ) { - $this->header(); - echo '

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

'; - echo '

' . $file['error'] . '

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

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

'; - } - - function import() { - $this->id = (int) $_GET['id']; - - $this->file = get_attached_file($this->id); - $this->get_authors_from_post(); - $this->get_entries(); - $this->process_posts(); - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - $this->header(); - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - $this->select_authors(); - break; - case 2: - $this->import(); - break; - } - $this->footer(); - } - - function WP_Import() { - // Nothing. - } -} - -$wp_import = new WP_Import(); - -register_importer('wordpress', 'WordPress', __('Import posts, comments, custom fields, and categories from a WordPress export file'), array ($wp_import, 'dispatch')); - -?> +'; + 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.').'

'; + wp_import_upload_form("admin.php?import=wordpress&step=1"); + echo '
'; + } + + function get_tag( $string, $tag ) { + preg_match("|<$tag.*?>(.*?)|is", $string, $return); + $return = addslashes( trim( $return[1] ) ); + return $return; + } + + function users_form($n) { + global $wpdb, $testing; + $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID"); +?> + 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 ($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); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata); + preg_match_all('|(.*?)|is', $importdata, $this->posts); + $this->posts = $this->posts[1]; + } + + function get_wp_authors() { + $temp = array (); + $i = -1; + foreach ($this->posts as $post) { + if ('' != trim($post)) { + ++ $i; + $author = $this->get_tag( $post, 'dc:creator' ); + array_push($temp, "$author"); //store the extracted author names in a temporary array + } + } + + // We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. + $authors[0] = array_shift($temp); + $y = count($temp) + 1; + for ($x = 1; $x < $y; $x ++) { + $next = array_shift($temp); + if (!(in_array($next, $authors))) + array_push($authors, "$next"); + } + + return $authors; + } + + function get_authors_from_post() { + $formnames = array (); + $selectnames = array (); + + foreach ($_POST['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 '
    '; + $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']) ) { + $this->header(); + echo '

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

'; + echo '

' . $file['error'] . '

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

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

'; + } + + function import() { + $this->id = (int) $_GET['id']; + + $this->file = get_attached_file($this->id); + $this->get_authors_from_post(); + $this->get_entries(); + $this->process_posts(); + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->select_authors(); + break; + case 2: + $this->import(); + break; + } + $this->footer(); + } + + function WP_Import() { + // Nothing. + } +} + +$wp_import = new WP_Import(); + +register_importer('wordpress', 'WordPress', __('Import posts, comments, custom fields, and categories from a WordPress export file'), array ($wp_import, 'dispatch')); + +?> diff --git a/wp-admin/options-privacy.php b/wp-admin/options-privacy.php index 28e7ecd306..61fc6becbc 100644 --- a/wp-admin/options-privacy.php +++ b/wp-admin/options-privacy.php @@ -1,35 +1,35 @@ - - -
-

-
- - - - - - -
-

/> -

-

/> -

- -
- -

- - -

-
- -
- - + + +
+

+
+ + + + + + +
+

/> +

+

/> +

+ +
+ +

+ + +

+
+ +
+ + diff --git a/wp-admin/page.php b/wp-admin/page.php index 2a7dace62a..9893b0b389 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -1,160 +1,160 @@ -post_status == 'draft') { - wp_enqueue_script('prototype'); - 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'); - ?> -
-

- -
- 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 (strstr($sendback, 'page.php')) $sendback = get_option('siteurl') .'/wp-admin/page.php'; - elseif (strstr($sendback, 'attachments.php')) $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'); -?> +post_status == 'draft') { + wp_enqueue_script('prototype'); + 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'); + ?> +
+

+ +
+ 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 (strstr($sendback, 'page.php')) $sendback = get_option('siteurl') .'/wp-admin/page.php'; + elseif (strstr($sendback, 'attachments.php')) $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/post-new.php b/wp-admin/post-new.php index 535c3fbfc2..4ecc804a6c 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -1,96 +1,96 @@ - -
-

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

-
- - - -
-

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

-
- - - -
-

-

-

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

-
- - - + +
+

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

+
+ + + +
+

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

+
+ + + +
+

+

+

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

+
+ + + diff --git a/wp-admin/upload-functions.php b/wp-admin/upload-functions.php index d0fb32cdf7..623daeb5d6 100644 --- a/wp-admin/upload-functions.php +++ b/wp-admin/upload-functions.php @@ -1,372 +1,372 @@ -post_content ); - - $class = 'text'; - $innerHTML = get_attachment_innerHTML( $id, false, $dims ); - if ( $image_src = strstr($innerHTML, 'src="') ) { - $image_src = explode('"', $image_src); - $image_src = $image_src[1]; - $image_rel = wp_make_link_relative($image_src); - $class = 'image'; - $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); - $image_base = str_replace($image_rel, '', $image_src); - } - - $src_base = get_the_guid(); - $src = wp_make_link_relative( $src_base ); - $src_base = str_replace($src, '', $src_base); - - $r = ''; - - if ( $href ) - $r .= "\n"; - if ( $href || $image_src ) - $r .= "\t\t\t$innerHTML"; - if ( $href ) - $r .= "\n"; - $r .= "\n\t\t
\n\t\t\t

\n"; - $r .= "\t\t\t\t\n"; - $r .= "\t\t\t\t\n"; - - if ( isset($attachment_data['thumb']) ) { - $r .= "\t\t\t\t\n"; - $r .= "\t\t\t\t\n"; - } elseif ( $image_rel ) - $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 = get_post_meta( $id, '_wp_attachment_metadata', true ); -?> -
-
-

"; - 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"'; -?> - 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_title : $filename, - '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); - - 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( 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 $wpdb, $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&posts_per_page=10&paged=$paged"); - $count_query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'"; - if ( $post_id ) - $count_query .= " AND post_parent = '$post_id'"; - $total = $wpdb->get_var($count_query); - - 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() { - global $wp_locale; - echo "\n"; - if ( 'rtl' == $wp_locale->text_direction ) - echo "\n"; - if ( 'inline' == @$_GET['style'] ) { - echo ""; - } -} - +post_content ); + + $class = 'text'; + $innerHTML = get_attachment_innerHTML( $id, false, $dims ); + if ( $image_src = strstr($innerHTML, 'src="') ) { + $image_src = explode('"', $image_src); + $image_src = $image_src[1]; + $image_rel = wp_make_link_relative($image_src); + $class = 'image'; + $innerHTML = ' ' . str_replace($image_src, $image_rel, $innerHTML); + $image_base = str_replace($image_rel, '', $image_src); + } + + $src_base = get_the_guid(); + $src = wp_make_link_relative( $src_base ); + $src_base = str_replace($src, '', $src_base); + + $r = ''; + + if ( $href ) + $r .= "\n"; + if ( $href || $image_src ) + $r .= "\t\t\t$innerHTML"; + if ( $href ) + $r .= "\n"; + $r .= "\n\t\t
\n\t\t\t

\n"; + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + + if ( isset($attachment_data['thumb']) ) { + $r .= "\t\t\t\t\n"; + $r .= "\t\t\t\t\n"; + } elseif ( $image_rel ) + $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 = get_post_meta( $id, '_wp_attachment_metadata', true ); +?> +
+
+

"; + 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"'; +?> + 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_title : $filename, + '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); + + 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( 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 $wpdb, $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&posts_per_page=10&paged=$paged"); + $count_query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'attachment'"; + if ( $post_id ) + $count_query .= " AND post_parent = '$post_id'"; + $total = $wpdb->get_var($count_query); + + 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() { + global $wp_locale; + echo "\n"; + if ( 'rtl' == $wp_locale->text_direction ) + echo "\n"; + if ( 'inline' == @$_GET['style'] ) { + echo ""; + } +} + diff --git a/wp-admin/upload-js.php b/wp-admin/upload-js.php index bab889e811..c92439ff53 100644 --- a/wp-admin/upload-js.php +++ b/wp-admin/upload-js.php @@ -1,257 +1,257 @@ - -addLoadEvent( function() { - theFileList = { - currentImage: {ID: 0}, - nonce: '', - tab: '', - postID: 0, - - initializeVars: function() { - this.urlData = document.location.href.split('?'); - this.params = this.urlData[1].toQueryParams(); - 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 = $('nonce-value'); - if ( nonceEl ) - this.nonce = nonceEl.value; - if ( this.ID ) { - this.grabImageData( this.ID ); - this.imageView( this.ID ); - } - }, - - initializeLinks: function() { - if ( this.ID ) - return; - $$('a.file-link').each( function(i) { - var id = i.id.split('-').pop(); - i.onclick = function(e) { theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e); } - } ); - }, - - grabImageData: function(id) { - if ( id == this.currentImage.ID ) - return; - var thumbEl = $('attachment-thumb-url-' + id); - this.currentImage.isImage = true; - if ( thumbEl ) { - this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value ); - this.currentImage.thumbBase = ( 0 == id ? '' : $('attachment-thumb-url-base-' + id).value ); - } else { - this.currentImage.thumb = false; - var isImageEl = $('attachment-is-image-' + id); - if ( !isImageEl ) - this.currentImage.isImage = false; - } - this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value ); - this.currentImage.srcBase = ( 0 == id ? '' : $('attachment-url-base-' + id).value ); - this.currentImage.page = ( 0 == id ? '' : $('attachment-page-url-' + id).value ); - this.currentImage.title = ( 0 == id ? '' : $('attachment-title-' + id).value ); - this.currentImage.description = ( 0 == id ? '' : $('attachment-description-' + id).value ); - var widthEl = $('attachment-width-' + id); - if ( widthEl ) { - this.currentImage.width = ( 0 == id ? '' : widthEl.value ); - this.currentImage.height = ( 0 == id ? '' : $('attachment-height-' + id).value ); - } else { - this.currentImage.width = false; - this.currentImage.height = false; - } - this.currentImage.ID = id; - }, - - imageView: function(id, e) { - this.prepView(id); - var h = ''; - - h += "
" - if ( this.ID ) { - var params = $H(this.params); - params.ID = ''; - params.action = ''; - h += "« Back"; - } else { - h += "« Back"; - } - h += "
" - if ( !this.currentImage.isImage ) - h += "

" + this.currentImage.title + "

"; - else - h += "

" + this.currentImage.title + "

"; - h += " — "; - h += "Edit" - h += ""; - h += '
' - h += "
"; - if ( this.currentImage.isImage ) { - h += ""; - h += "" + this.currentImage.title + ""; - h += ""; - } else - h += ' '; - h += "
"; - - h += "
"; - h += ""; - if ( this.currentImage.thumb ) { - h += ""; - } - - h += ""; - - h += "
Show:"; - h += "
"; - h += ""; - h += "
Link to:"; - h += "
"; - h += "
"; - h += ""; - h += "

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

"; - h += "
"; - - h += "
"; - - new Insertion.Top('upload-content', h); - if (e) Event.stop(e); - 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 = $H(this.params); - params.ID = ''; - params.action = ''; - h += "« Back"; - } else { - h += "« Back"; - } - h += "
" - if ( !this.currentImage.isImage ) - h += "

" + this.currentImage.title + "

"; - else - h += "

" + this.currentImage.title + "

"; - h += " — "; - h += "Insert" - h += ""; - h += '
' - h += "
"; - if ( 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 += "
"; - - new Insertion.Top('upload-content', h); - if (e) Event.stop(e); - return false; - }, - - prepView: function(id) { - this.cancelView( true ); - var filesEl = $('upload-files'); - if ( filesEl ) - filesEl.hide(); - var navEl = $('current-tab-nav'); - if ( navEl ) - navEl.hide(); - this.grabImageData(id); - }, - - cancelView: function( prep ) { - if ( !prep ) { - var filesEl = $('upload-files'); - if ( filesEl ) - filesEl.show(); - var navEl = $('current-tab-nav'); - if ( navEl ) - navEl.show(); - } - if ( !this.ID ) - this.grabImageData(0); - var div = $('upload-file'); - if ( div ) - div.remove(); - return false; - }, - - sendToEditor: function(id) { - this.grabImageData(id); - var link = ''; - var display = ''; - var h = ''; - - link = $A(document.forms.uploadoptions.elements.link).detect( function(i) { return i.checked; } ).value; - displayEl = $A(document.forms.uploadoptions.elements.display).detect( function(i) { return i.checked; } ) - if ( displayEl ) - display = displayEl.value; - else if ( this.currentImage.isImage ) - display = 'full'; - - if ( 'none' != link ) - h += ""; - if ( 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') ) - win.tinyMCE.execCommand('mceInsertContent', false, h); - else - win.edInsertContent(win.edCanvas, h); - if ( !this.ID ) - this.cancelView(); - return false; - }, - - deleteFile: function(id) { - if ( confirm("Are you sure you want to delete the file '" + this.currentImage.title + "'?\nClick ok to delete or cancel to go back.") ) { - $('action-value').value = 'delete'; - $('upload-file').submit(); - return true; - } - return false; - } - - }; - theFileList.initializeVars(); - theFileList.initializeLinks(); -} ); + +addLoadEvent( function() { + theFileList = { + currentImage: {ID: 0}, + nonce: '', + tab: '', + postID: 0, + + initializeVars: function() { + this.urlData = document.location.href.split('?'); + this.params = this.urlData[1].toQueryParams(); + 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 = $('nonce-value'); + if ( nonceEl ) + this.nonce = nonceEl.value; + if ( this.ID ) { + this.grabImageData( this.ID ); + this.imageView( this.ID ); + } + }, + + initializeLinks: function() { + if ( this.ID ) + return; + $$('a.file-link').each( function(i) { + var id = i.id.split('-').pop(); + i.onclick = function(e) { theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e); } + } ); + }, + + grabImageData: function(id) { + if ( id == this.currentImage.ID ) + return; + var thumbEl = $('attachment-thumb-url-' + id); + this.currentImage.isImage = true; + if ( thumbEl ) { + this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value ); + this.currentImage.thumbBase = ( 0 == id ? '' : $('attachment-thumb-url-base-' + id).value ); + } else { + this.currentImage.thumb = false; + var isImageEl = $('attachment-is-image-' + id); + if ( !isImageEl ) + this.currentImage.isImage = false; + } + this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value ); + this.currentImage.srcBase = ( 0 == id ? '' : $('attachment-url-base-' + id).value ); + this.currentImage.page = ( 0 == id ? '' : $('attachment-page-url-' + id).value ); + this.currentImage.title = ( 0 == id ? '' : $('attachment-title-' + id).value ); + this.currentImage.description = ( 0 == id ? '' : $('attachment-description-' + id).value ); + var widthEl = $('attachment-width-' + id); + if ( widthEl ) { + this.currentImage.width = ( 0 == id ? '' : widthEl.value ); + this.currentImage.height = ( 0 == id ? '' : $('attachment-height-' + id).value ); + } else { + this.currentImage.width = false; + this.currentImage.height = false; + } + this.currentImage.ID = id; + }, + + imageView: function(id, e) { + this.prepView(id); + var h = ''; + + h += "
" + if ( this.ID ) { + var params = $H(this.params); + params.ID = ''; + params.action = ''; + h += "« Back"; + } else { + h += "« Back"; + } + h += "
" + if ( !this.currentImage.isImage ) + h += "

" + this.currentImage.title + "

"; + else + h += "

" + this.currentImage.title + "

"; + h += " — "; + h += "Edit" + h += ""; + h += '
' + h += "
"; + if ( this.currentImage.isImage ) { + h += ""; + h += "" + this.currentImage.title + ""; + h += ""; + } else + h += ' '; + h += "
"; + + h += "
"; + h += ""; + if ( this.currentImage.thumb ) { + h += ""; + } + + h += ""; + + h += "
Show:"; + h += "
"; + h += ""; + h += "
Link to:"; + h += "
"; + h += "
"; + h += ""; + h += "

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

"; + h += "
"; + + h += "
"; + + new Insertion.Top('upload-content', h); + if (e) Event.stop(e); + 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 = $H(this.params); + params.ID = ''; + params.action = ''; + h += "« Back"; + } else { + h += "« Back"; + } + h += "
" + if ( !this.currentImage.isImage ) + h += "

" + this.currentImage.title + "

"; + else + h += "

" + this.currentImage.title + "

"; + h += " — "; + h += "Insert" + h += ""; + h += '
' + h += "
"; + if ( 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 += "
"; + + new Insertion.Top('upload-content', h); + if (e) Event.stop(e); + return false; + }, + + prepView: function(id) { + this.cancelView( true ); + var filesEl = $('upload-files'); + if ( filesEl ) + filesEl.hide(); + var navEl = $('current-tab-nav'); + if ( navEl ) + navEl.hide(); + this.grabImageData(id); + }, + + cancelView: function( prep ) { + if ( !prep ) { + var filesEl = $('upload-files'); + if ( filesEl ) + filesEl.show(); + var navEl = $('current-tab-nav'); + if ( navEl ) + navEl.show(); + } + if ( !this.ID ) + this.grabImageData(0); + var div = $('upload-file'); + if ( div ) + div.remove(); + return false; + }, + + sendToEditor: function(id) { + this.grabImageData(id); + var link = ''; + var display = ''; + var h = ''; + + link = $A(document.forms.uploadoptions.elements.link).detect( function(i) { return i.checked; } ).value; + displayEl = $A(document.forms.uploadoptions.elements.display).detect( function(i) { return i.checked; } ) + if ( displayEl ) + display = displayEl.value; + else if ( this.currentImage.isImage ) + display = 'full'; + + if ( 'none' != link ) + h += ""; + if ( 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') ) + win.tinyMCE.execCommand('mceInsertContent', false, h); + else + win.edInsertContent(win.edCanvas, h); + if ( !this.ID ) + this.cancelView(); + return false; + }, + + deleteFile: function(id) { + if ( confirm("Are you sure you want to delete the file '" + this.currentImage.title + "'?\nClick ok to delete or cancel to go back.") ) { + $('action-value').value = 'delete'; + $('upload-file').submit(); + return true; + } + return false; + } + + }; + theFileList.initializeVars(); + theFileList.initializeLinks(); +} ); diff --git a/wp-config-sample.php b/wp-config-sample.php index 5cc89738ed..8099ce9e9b 100644 --- a/wp-config-sample.php +++ b/wp-config-sample.php @@ -1,21 +1,21 @@ - \ No newline at end of file