diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-01-02 17:10:03 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-01-02 17:10:03 +0000 |
commit | 4a7ec3a72a69e8f66dce65590900d59978798384 (patch) | |
tree | 23037940fad9aa64644958ac91e7fdadf8cd0f5d | |
parent | ed4930953197324008fe13ae2eee874bbcbc48fd (diff) | |
download | wordpress-mu-4a7ec3a72a69e8f66dce65590900d59978798384.tar.gz wordpress-mu-4a7ec3a72a69e8f66dce65590900d59978798384.tar.xz wordpress-mu-4a7ec3a72a69e8f66dce65590900d59978798384.zip |
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@489 7be80a69-a1ef-0310-a953-fb0f7c49ff36
24 files changed, 400 insertions, 128 deletions
diff --git a/wp-inst/wp-admin/admin-functions.php b/wp-inst/wp-admin/admin-functions.php index d0d08d2..fb46e32 100644 --- a/wp-inst/wp-admin/admin-functions.php +++ b/wp-inst/wp-admin/admin-functions.php @@ -1249,7 +1249,9 @@ function get_admin_page_title() { return $title; } - $parent = get_admin_page_parent(); + $hook = get_plugin_page_hook($plugin_page, $pagenow); + + $parent = $parent1 = get_admin_page_parent(); if (empty ($parent)) { foreach ($menu as $menu_array) { if (isset ($menu_array[3])) { @@ -1257,7 +1259,7 @@ function get_admin_page_title() { $title = $menu_array[3]; return $menu_array[3]; } else - if (isset ($plugin_page) && ($plugin_page == $menu_array[2])) { + if (isset ($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) { $title = $menu_array[3]; return $menu_array[3]; } @@ -1271,7 +1273,7 @@ function get_admin_page_title() { $title = $submenu_array[3]; return $submenu_array[3]; } else - if (isset ($plugin_page) && ($plugin_page == $submenu_array[2])) { + if (isset ($plugin_page) && ($plugin_page == $submenu_array[2]) && (($parent == $pagenow) || ($parent == $plugin_page) || ($plugin_page == $hook) || (($pagenow == 'admin.php') && ($parent1 != $submenu_array[2])))) { $title = $submenu_array[3]; return $submenu_array[3]; } @@ -1719,7 +1721,7 @@ function wp_handle_upload(&$file, $overrides = false) { return $upload_error_handler($file, __('File is empty. Please upload something more substantial.')); // A properly uploaded file will pass this test. There should be no reason to override this one. - if (! is_uploaded_file($file['tmp_name']) ) + if (! @ is_uploaded_file($file['tmp_name']) ) return $upload_error_handler($file, __('Specified file failed upload test.')); // A correct MIME type will pass this test. @@ -1748,13 +1750,21 @@ function wp_handle_upload(&$file, $overrides = false) { } else { $number = ''; $filename = $file['name']; - while ( file_exists($uploads['path'] . "/$filename") ) - $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename); + if ( empty($ext) ) + $ext = ''; + else + $ext = ".$ext"; + while ( file_exists($uploads['path'] . "/$filename") ) { + if ( '' == "$number$ext" ) + $filename = $filename . ++$number . $ext; + else + $filename = str_replace("$number$ext", ++$number . $ext, $filename); + } } // Move the file to the uploads dir $new_file = $uploads['path'] . "/$filename"; - if ( false === move_uploaded_file($file['tmp_name'], $new_file) ) + if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) ) die(printf(__('The uploaded file could not be moved to %s.'), $file['path'])); // Set correct file permissions diff --git a/wp-inst/wp-admin/admin-header.php b/wp-inst/wp-admin/admin-header.php index 5b96d78..c340b5d 100644 --- a/wp-inst/wp-admin/admin-header.php +++ b/wp-inst/wp-admin/admin-header.php @@ -130,7 +130,7 @@ var newcat; function newCatAddIn() { if ( !document.getElementById('jaxcat') ) return false; - var ajaxcat = document.createElement('p'); + var ajaxcat = document.createElement('span'); ajaxcat.id = 'ajaxcat'; newcat = document.createElement('input'); @@ -204,7 +204,7 @@ function newCatCompletion() { ids = myPload( ajaxCat.response ); names = myPload( newcat.value ); for ( i = 0; i < ids.length; i++ ) { - id = ids[i].replace(/[\n\r\l]+/g, ""); + id = ids[i].replace(/[\n\r]+/g, ""); if ( id == '-1' ) { p.innerHTML = "<?php echo addslashes(__("You don't have permission to do that.")); ?>"; return; diff --git a/wp-inst/wp-admin/edit-comments.php b/wp-inst/wp-admin/edit-comments.php index b13c7f1..74c4aee 100644 --- a/wp-inst/wp-admin/edit-comments.php +++ b/wp-inst/wp-admin/edit-comments.php @@ -44,7 +44,7 @@ if ( !empty( $_POST['delete_comments'] ) ) : $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $comment"); $authordata = get_userdata( $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $post_id") ); if ( current_user_can('edit_post', $post_id) ) : - $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_ID = $comment"); + wp_set_comment_status($comment, "delete"); ++$i; endif; endforeach; diff --git a/wp-inst/wp-admin/execute-pings.php b/wp-inst/wp-admin/execute-pings.php index e68f76c..d6b0880 100644 --- a/wp-inst/wp-admin/execute-pings.php +++ b/wp-inst/wp-admin/execute-pings.php @@ -19,9 +19,13 @@ function execute_all_pings() { echo "Enclosure: $enclosure->post_title : $enclosure->ID<br/>"; } // Do Trackbacks - while ($trackback = $wpdb->get_row("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft' LIMIT 1")) { - echo "Trackback : $trackback->ID<br/>"; - do_trackbacks($trackback->ID); + $trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE TRIM(to_ping) != '' AND post_status != 'draft'"); + + if (is_array($trackbacks) && count($trackbacks)) { + foreach ($trackbacks as $trackback ) { + echo "Trackback : $trackback->ID<br/>"; + do_trackbacks($trackback->ID); + } } } diff --git a/wp-inst/wp-admin/import/livejournal.php b/wp-inst/wp-admin/import/livejournal.php index e69de29..bc6bb91 100644 --- a/wp-inst/wp-admin/import/livejournal.php +++ b/wp-inst/wp-admin/import/livejournal.php @@ -0,0 +1,170 @@ +<?php + +class LJ_Import { + + var $file; + + function header() { + echo '<div class="wrap">'; + echo '<h2>'.__('Import LiveJournal').'</h2>'; + } + + function footer() { + echo '</div>'; + } + + 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 '<p>'.__('Howdy! This importer allows you to extract posts from LiveJournal XML export file into your blog. Pick a LiveJournal file to upload and click Import.').'</p>'; + wp_import_upload_form("admin.php?import=livejournal&step=1"); + } + + function import_posts() { + global $wpdb, $current_user; + + set_magic_quotes_runtime(0); + $importdata = file($this->file); // Read the file into an array + $importdata = implode('', $importdata); // squish it + $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); + + preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts); + $posts = $posts[1]; + unset($importdata); + echo '<ol>'; + foreach ($posts as $post) { + flush(); + preg_match('|<subject>(.*?)</subject>|is', $post, $post_title); + $post_title = $wpdb->escape(trim($post_title[1])); + if ( empty($post_title) ) { + preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title); + $post_title = $wpdb->escape(trim($post_title[1])); + } + + preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date); + $post_date = strtotime($post_date[1]); + $post_date = gmdate('Y-m-d H:i:s', $post_date); + + preg_match('|<event>(.*?)</event>|is', $post, $post_content); + $post_content = str_replace(array ('<![CDATA[', ']]>'), '', 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('<br>', '<br />', $post_content); + $post_content = str_replace('<hr>', '<hr />', $post_content); + $post_content = $wpdb->escape($post_content); + + $post_author = $current_user->ID; + $post_status = 'publish'; + + echo '<li>'; + if ($post_id = post_exists($post_title, $post_content, $post_date)) { + printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); + } else { + printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); + $post = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status'); + $post_id = wp_insert_post($post); + if (!$post_id) { + _e("Couldn't get post ID"); + echo '</li>'; + break; + } + } + + preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments); + $comments = $comments[1]; + + if ( $comments ) { + $comment_post_ID = $post_id; + $num_comments = 0; + foreach ($comments as $comment) { + preg_match('|<event>(.*?)</event>|is', $comment, $comment_content); + $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', 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('<br>', '<br />', $comment_content); + $comment_content = str_replace('<hr>', '<hr />', $comment_content); + $comment_content = $wpdb->escape($comment_content); + + preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date); + $comment_date = trim($comment_date[1]); + $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); + + preg_match('|<name>(.*?)</name>|is', $comment, $comment_author); + $comment_author = $wpdb->escape(trim($comment_author[1])); + + preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email); + $comment_author_email = $wpdb->escape(trim($comment_author_email[1])); + + $comment_approved = 1; + // Check if it's already there + if (!comment_exists($comment_author, $comment_date)) { + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + wp_insert_comment($commentdata); + $num_comments++; + } + } + } + if ( $num_comments ) + printf(__('(%s comments)'), $num_comments); + + echo '</li>'; + flush(); + ob_flush(); + } + echo '</ol>'; + } + + 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 '<h3>'; + printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')); + echo '</h3>'; + } + + function dispatch() { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + + switch ($step) { + case 0 : + $this->greet(); + break; + case 1 : + $this->import(); + break; + } + + $this->footer(); + } + + function LJ_Import() { + // Nothing. + } +} + +$livejournal_import = new LJ_Import(); + +register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch')); +?> diff --git a/wp-inst/wp-admin/import/mt.php b/wp-inst/wp-admin/import/mt.php index c880544..3281f08 100644 --- a/wp-inst/wp-admin/import/mt.php +++ b/wp-inst/wp-admin/import/mt.php @@ -54,7 +54,7 @@ class MT_Import { if (!(in_array($author, $this->mtnames))) { //a new mt author name is found ++ $this->j; $this->mtnames[$this->j] = $author; //add that new mt author name to an array - $user_id = username_exists($this->newauthornames[$j]); //check if the new author name defined by the user is a pre-existing wp user + $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); @@ -243,11 +243,11 @@ class MT_Import { $post_convert_breaks = $value; break; case 'ALLOW PINGS' : - $post_allow_pings = trim($meta[2][0]); - if ($post_allow_pings == 1) { - $post_allow_pings = 'open'; + $ping_status = trim($meta[2][0]); + if ($ping_status == 1) { + $ping_status = 'open'; } else { - $post_allow_pings = 'closed'; + $ping_status = 'closed'; } break; case 'PRIMARY CATEGORY' : @@ -290,6 +290,7 @@ class MT_Import { } $comment_post_ID = $post_id; + $comment_approved = 1; // Now for comments $comments = explode("-----\nCOMMENT:", $comments[0]); @@ -321,7 +322,7 @@ class MT_Import { $comment_content = str_replace('-----', '', $comment_content); // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content'); + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_comments++; @@ -369,7 +370,7 @@ class MT_Import { // Check if it's already there if (!comment_exists($comment_author, $comment_date)) { - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type'); + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); $num_pings++; diff --git a/wp-inst/wp-admin/import/rss.php b/wp-inst/wp-admin/import/rss.php index c79bf99..e4a8167 100644 --- a/wp-inst/wp-admin/import/rss.php +++ b/wp-inst/wp-admin/import/rss.php @@ -1,9 +1,5 @@ <?php -// Example: -// define('RSSFILE', '/home/example/public_html/rss.xml'); -define('RSSFILE', 'rss.xml'); - class RSS_Import { var $posts = array (); diff --git a/wp-inst/wp-admin/link-import.php b/wp-inst/wp-admin/link-import.php index a5f2208..817d48f 100644 --- a/wp-inst/wp-admin/link-import.php +++ b/wp-inst/wp-admin/link-import.php @@ -126,6 +126,7 @@ foreach ($categories as $category) { break; } // end case 1 } // end switch + +include('admin-footer.php'); + ?> -</body> -</html> diff --git a/wp-inst/wp-admin/list-manipulation.php b/wp-inst/wp-admin/list-manipulation.php index 63ff21b..308089f 100644 --- a/wp-inst/wp-admin/list-manipulation.php +++ b/wp-inst/wp-admin/list-manipulation.php @@ -30,12 +30,13 @@ case 'delete-link' : case 'delete-post' : case 'delete-page' : $id = (int) $_POST['id']; - if ( !current_user_can('edit_post', $post_id) ) + if ( !current_user_can('edit_post', $id) ) { die('-1'); + } - if ( wp_delete_post($id) ) + if ( wp_delete_post($id) ) { die('1'); - else die('0'); + } else die('0'); break; case 'delete-cat' : if ( !current_user_can('manage_categories') ) diff --git a/wp-inst/wp-admin/options-permalink.php b/wp-inst/wp-admin/options-permalink.php index 3af4ec3..3d953f0 100644 --- a/wp-inst/wp-admin/options-permalink.php +++ b/wp-inst/wp-admin/options-permalink.php @@ -77,8 +77,6 @@ if ( isset($_POST) ) { $permalink_structure = get_settings('permalink_structure'); $category_base = get_settings('category_base'); -generate_page_rewrite_rules(); - if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') ) $writable = true; else @@ -89,7 +87,7 @@ if ($wp_rewrite->using_index_permalinks()) else $usingpi = false; -save_mod_rewrite_rules(); +$wp_rewrite->flush_rules(); ?> <?php if (isset($_POST['submit'])) : ?> diff --git a/wp-inst/wp-admin/options.php b/wp-inst/wp-admin/options.php index d6ed40a..9fb0532 100644 --- a/wp-inst/wp-admin/options.php +++ b/wp-inst/wp-admin/options.php @@ -30,10 +30,10 @@ case 'update': $any_changed = 0; check_admin_referer(); - + if (!$_POST['page_options']) { foreach ($_POST as $key => $value) { - $options[] = "$key"; + $options[] = $key; } } else { $options = explode(',', stripslashes($_POST['page_options'])); @@ -54,7 +54,8 @@ case 'update': $value = 'closed'; if( $option == 'blogdescription' || $option == 'blogname' ) - $value = wp_filter_post_kses( $value ); + if (current_user_can('unfiltered_html') == false) + $value = wp_filter_post_kses( $value ); if ( update_option($option, $value) ) $any_changed++; @@ -65,7 +66,7 @@ case 'update': // If siteurl or home changed, reset cookies. if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) { // If home changed, write rewrite rules to new location. - save_mod_rewrite_rules(); + $wp_rewrite->flush_rules(); // Get currently logged in user and password. get_currentuserinfo(); // Clear cookies for old paths. diff --git a/wp-inst/wp-admin/plugins.php b/wp-inst/wp-admin/plugins.php index 8d5f539..daf4de5 100644 --- a/wp-inst/wp-admin/plugins.php +++ b/wp-inst/wp-admin/plugins.php @@ -28,6 +28,7 @@ if ( isset($_GET['action']) ) { do_action('deactivate_' . trim( $_GET['plugin'] )); header('Location: plugins.php?deactivate=true'); } + exit; } $title = __('Manage Plugins'); diff --git a/wp-inst/wp-admin/post.php b/wp-inst/wp-admin/post.php index e3456b6..3ff15a3 100644 --- a/wp-inst/wp-admin/post.php +++ b/wp-inst/wp-admin/post.php @@ -241,8 +241,6 @@ case 'deletecomment': case 'unapprovecomment': - require_once('./admin-header.php'); - check_admin_referer(); $comment = (int) $_GET['comment']; diff --git a/wp-inst/wp-admin/templates.php b/wp-inst/wp-admin/templates.php index f1c2124..deb79f4 100644 --- a/wp-inst/wp-admin/templates.php +++ b/wp-inst/wp-admin/templates.php @@ -87,9 +87,9 @@ default: <?php if (isset($_GET['a'])) : ?> <?php if ( 'err' == $_GET['a'] ) : ?> <div id="message" class="error"><p><?php _e('Could not save file.') ?></p></div> - <? else: ?> + <?php else: ?> <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div> - <?endif; ?> + <?php endif; ?> <?php endif; ?> <div class="wrap"> <?php diff --git a/wp-inst/wp-admin/upgrade-functions.php b/wp-inst/wp-admin/upgrade-functions.php index f62290f..a00e52e 100644 --- a/wp-inst/wp-admin/upgrade-functions.php +++ b/wp-inst/wp-admin/upgrade-functions.php @@ -5,7 +5,7 @@ require_once(ABSPATH . '/wp-admin/upgrade-schema.php'); define( "RESET_CAPS", true ); // Functions to be called in install and upgrade scripts function upgrade_all() { - global $wp_current_db_version, $wp_db_version; + global $wp_current_db_version, $wp_db_version, $wp_rewrite; $wp_current_db_version = __get_option('db_version'); // We are up-to-date. Nothing to do. @@ -34,7 +34,7 @@ function upgrade_all() { if ( $wp_current_db_version < 3308 ) upgrade_160(); - save_mod_rewrite_rules(); + $wp_rewrite->flush_rules(); update_option('db_version', $wp_db_version); } diff --git a/wp-inst/wp-includes/cache.php b/wp-inst/wp-includes/cache.php index ffb6756..af932a7 100644 --- a/wp-inst/wp-includes/cache.php +++ b/wp-inst/wp-includes/cache.php @@ -53,7 +53,7 @@ define('CACHE_SERIAL_FOOTER', "\n?".">"); class WP_Object_Cache { var $cache_dir; var $cache_enabled = false; - var $expiration_time = 86400; + var $expiration_time = 900; var $flock_filename = 'wp_object_cache.lock'; var $cache = array (); var $dirty_objects = array (); @@ -205,7 +205,9 @@ class WP_Object_Cache { } if (!file_exists($this->cache_dir.$make_dir."index.php")) { + $file_perms = $perms & 0000666; @ touch($this->cache_dir.$make_dir."index.php"); + @ chmod($this->cache_dir.$make_dir."index.php", $file_perms); } } @@ -268,7 +270,8 @@ class WP_Object_Cache { // Give the new dirs the same perms as wp-content. $stat = stat(ABSPATH.'wp-content'); - $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. + $dir_perms = $stat['mode'] & 0007777; // Get the permission bits. + $file_perms = $dir_perms & 0000666; // Remove execute bits for files. // Make the base cache dir. if (!file_exists($this->cache_dir)) { @@ -279,6 +282,7 @@ class WP_Object_Cache { if (!file_exists($this->cache_dir."index.php")) { @ touch($this->cache_dir."index.php"); + @ chmod($this->cache_dir."index.php", $file_perms); } // Acquire a write lock. @@ -314,6 +318,7 @@ class WP_Object_Cache { @ unlink($temp_file); } } + @ chmod($cache_file, $file_perms); } } diff --git a/wp-inst/wp-includes/classes.php b/wp-inst/wp-includes/classes.php index c057693..7713456 100644 --- a/wp-inst/wp-includes/classes.php +++ b/wp-inst/wp-includes/classes.php @@ -381,7 +381,9 @@ class WP_Query { $where .= " AND (ID = '$reqpage')"; } elseif ('' != $q['attachment']) { - $q['attachment'] = sanitize_title($q['attachment']); + $q['attachment'] = str_replace('%2F', '/', urlencode(urldecode($q['attachment']))); + $attach_paths = '/' . trim($q['attachment'], '/'); + $q['attachment'] = sanitize_title(basename($attach_paths)); $q['name'] = $q['attachment']; $where .= " AND post_name = '" . $q['attachment'] . "'"; } @@ -483,14 +485,21 @@ class WP_Query { $cat_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); $all_cat_ids = get_all_category_ids(); - $q['cat'] = 0; + $q['cat'] = 0; $partial_match = 0; foreach ( $all_cat_ids as $cat_id ) { $cat = get_category($cat_id); if ( $cat->fullpath == $cat_path ) { $q['cat'] = $cat_id; break; + } elseif ( $cat->category_nicename == $q['category_name'] ) { + $partial_match = $cat_id; } } + + //if we don't match the entire hierarchy fallback on just matching the nicename + if (!$q['cat'] && $partial_match) { + $q['cat'] = $partial_match; + } $tables = ", $wpdb->post2cat, $wpdb->categories"; $join = " LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) LEFT JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID) "; @@ -953,16 +962,22 @@ class WP_Rewrite { function page_rewrite_rules() { $uris = get_settings('page_uris'); + $attachment_uris = get_settings('page_attachment_uris'); $rewrite_rules = array(); $page_structure = $this->get_page_permastruct(); - if( is_array( $uris ) ) - { - foreach ($uris as $uri => $pagename) { - $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename='); - $rewrite_rules += $this->generate_rewrite_rules($page_structure); - } + if( is_array( $attachment_uris ) ) { + foreach ($attachment_uris as $uri => $pagename) { + $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment='); + $rewrite_rules += $this->generate_rewrite_rules($page_structure); + } + } + if( is_array( $uris ) ) { + foreach ($uris as $uri => $pagename) { + $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename='); + $rewrite_rules += $this->generate_rewrite_rules($page_structure); } + } return $rewrite_rules; } @@ -1225,11 +1240,14 @@ class WP_Rewrite { $rewrite = $rewrite + array($pagematch => $pagequery); if ($num_toks) { - $post = 0; + $post = false; + $page = false; if (strstr($struct, '%postname%') || strstr($struct, '%post_id%') || strstr($struct, '%pagename%') || (strstr($struct, '%year%') && strstr($struct, '%monthnum%') && strstr($struct, '%day%') && strstr($struct, '%hour%') && strstr($struct, '%minute') && strstr($struct, '%second%'))) { - $post = 1; + $post = true; + if ( strstr($struct, '%pagename%') ) + $page = true; $trackbackmatch = $match . $trackbackregex; $trackbackquery = $trackbackindex . '?' . $query . '&tb=1'; $match = rtrim($match, '/'); @@ -1257,9 +1275,10 @@ class WP_Rewrite { $rewrite = $rewrite + array($match => $query); if ($post) { - $rewrite = array($trackbackmatch => $trackbackquery) + $rewrite + - array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery) + - array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery); + $rewrite = array($trackbackmatch => $trackbackquery) + $rewrite; + if ( ! $page ) + $rewrite = $rewrite + array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery); + $rewrite = $rewrite + array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery); } } @@ -1327,8 +1346,14 @@ class WP_Rewrite { } function wp_rewrite_rules() { - $this->matches = 'matches'; - return $this->rewrite_rules(); + $this->rules = get_option('rewrite_rules'); + if ( empty($this->rules) ) { + $this->matches = 'matches'; + $this->rewrite_rules(); + update_option('rewrite_rules', $this->rules); + } + + return $this->rules; } function mod_rewrite_rules() { @@ -1384,6 +1409,14 @@ class WP_Rewrite { return $rules; } + function flush_rules() { + generate_page_rewrite_rules(); + delete_option('rewrite_rules'); + $this->wp_rewrite_rules(); + if ( function_exists('save_mod_rewrite_rules') ) + save_mod_rewrite_rules(); + } + function init() { $this->permalink_structure = get_settings('permalink_structure'); $this->front = substr($this->permalink_structure, 0, strpos($this->permalink_structure, '%')); @@ -1461,16 +1494,21 @@ class WP { $self = $_SERVER['PHP_SELF']; $home_path = parse_url(get_settings('home')); $home_path = $home_path['path']; + $home_path = trim($home_path, '/'); // Trim path info from the end and the leading home path from the // front. For path info requests, this leaves us with the requesting // filename, if any. For 404 requests, this leaves us with the // requested permalink. $req_uri = str_replace($pathinfo, '', $req_uri); - $req_uri = str_replace($home_path, '', $req_uri); $req_uri = trim($req_uri, '/'); - $pathinfo = str_replace($home_path, '', $pathinfo); + $req_uri = preg_replace("|^$home_path|", '', $req_uri); + $req_uri = trim($req_uri, '/'); + $pathinfo = trim($pathinfo, '/'); + $pathinfo = preg_replace("|^$home_path|", '', $pathinfo); $pathinfo = trim($pathinfo, '/'); + $self = trim($self, '/'); + $self = preg_replace("|^$home_path|", '', $self); $self = str_replace($home_path, '', $self); $self = trim($self, '/'); diff --git a/wp-inst/wp-includes/comment-functions.php b/wp-inst/wp-includes/comment-functions.php index 21b9a99..af2d53a 100644 --- a/wp-inst/wp-includes/comment-functions.php +++ b/wp-inst/wp-includes/comment-functions.php @@ -76,6 +76,8 @@ function wp_insert_comment($commentdata) { $comment_date_gmt = gmdate('Y-m-d H:i:s', strtotime($comment_date) ); if ( ! isset($comment_parent) ) $comment_parent = 0; + if ( ! isset($comment_approved) ) + $comment_approved = 1; $result = $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_approved, comment_agent, comment_type, comment_parent, user_id) diff --git a/wp-inst/wp-includes/functions-post.php b/wp-inst/wp-includes/functions-post.php index eaaab76..12b2d68 100644 --- a/wp-inst/wp-includes/functions-post.php +++ b/wp-inst/wp-includes/functions-post.php @@ -6,7 +6,7 @@ * generic function for inserting data into the posts table. */ function wp_insert_post($postarr = array()) { - global $wpdb, $allowedtags, $user_ID; + global $wpdb, $wp_rewrite, $allowedtags, $user_ID; if ( is_object($postarr) ) $postarr = get_object_vars($postarr); @@ -121,7 +121,7 @@ function wp_insert_post($postarr = array()) { if ($update) { $wpdb->query( - "UPDATE $wpdb->posts SET + "UPDATE IGNORE $wpdb->posts SET post_author = '$post_author', post_date = '$post_date', post_date_gmt = '$post_date_gmt', @@ -143,7 +143,7 @@ function wp_insert_post($postarr = array()) { WHERE ID = $post_ID"); } else { $wpdb->query( - "INSERT INTO $wpdb->posts + "INSERT IGNORE INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type) VALUES ('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_content_filtered', '$post_title', '$post_excerpt', '$post_status', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type')"); @@ -196,7 +196,7 @@ function wp_insert_post($postarr = array()) { spawn_pinger(); } } else if ($post_status == 'static') { - generate_page_rewrite_rules(); + $wp_rewrite->flush_rules(); if ( !empty($page_template) ) if ( ! update_post_meta($post_ID, '_wp_page_template', $page_template)) @@ -526,7 +526,7 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array( } // wp_set_post_cats() function wp_delete_post($postid = 0) { - global $wpdb; + global $wpdb, $wp_rewrite; $postid = (int) $postid; if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") ) @@ -559,8 +559,8 @@ function wp_delete_post($postid = 0) { $wpdb->query("DELETE FROM $wpdb->postmeta WHERE post_id = $postid"); if ( 'static' == $post->post_status ) - generate_page_rewrite_rules(); - + $wp_rewrite->flush_rules(); + return $post; } @@ -697,15 +697,21 @@ function do_trackbacks($post_id) { $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $post_id"); $to_ping = get_to_ping($post_id); $pinged = get_pung($post_id); - if ( empty($to_ping) ) + if ( empty($to_ping) ) { + $wpdb->query("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = '$post_id'"); return; + } + if (empty($post->post_excerpt)) $excerpt = apply_filters('the_content', $post->post_content); else $excerpt = apply_filters('the_excerpt', $post->post_excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); $excerpt = strip_tags($excerpt); - $excerpt = substr($excerpt, 0, 252) . '...'; + if ( function_exists('mb_strcut') ) // For international trackbacks + $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...'; + else + $excerpt = substr($excerpt, 0, 252) . '...'; $post_title = apply_filters('the_title', $post->post_title); $post_title = strip_tags($post_title); @@ -792,19 +798,29 @@ function generate_page_rewrite_rules() { $posts = array_reverse($posts, true); $page_rewrite_rules = array(); - + $page_attachment_rewrite_rules = array(); + if ($posts) { foreach ($posts as $id => $post) { + // URI => page name $uri = get_page_uri($id); - + $attachments = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'attachment' AND post_parent = '$id'"); + if ( $attachments ) { + foreach ( $attachments as $attachment ) { + $attach_uri = get_page_uri($attachment->ID); + $page_attachment_rewrite_rules[$attach_uri] = $attachment->post_name; + } + } + $page_rewrite_rules[$uri] = $post; } - + update_option('page_uris', $page_rewrite_rules); - save_mod_rewrite_rules(); + if ( $page_attachment_rewrite_rules ) + update_option('page_attachment_uris', $page_attachment_rewrite_rules); } } @@ -835,48 +851,67 @@ function get_attached_file($attachment_id) { return get_post_meta($attachment_id, '_wp_attached_file', true); } +function wp_mkdir_p($target) { + // from php.net/mkdir user contributed notes + if (file_exists($target)) { + if (! @ is_dir($target)) + return false; + else + return true; + } + + // Attempting to create the directory may clutter up our display. + if (@ mkdir($target)) { + $stat = @ stat(dirname($target)); + $dir_perms = $stat['mode'] & 0007777; // Get the permission bits. + @ chmod($target, $dir_perms); + return true; + } else { + if ( is_dir(dirname($target)) ) + return false; + } + + // If the above failed, attempt to create the parent node, then try again. + if (wp_mkdir_p(dirname($target))) + return wp_mkdir_p($target); + + return false; +} + // Returns an array containing the current upload directory's path and url, or an error message. function wp_upload_dir() { - if ( defined('UPLOADS') ) - $dir = UPLOADS; - else - $dir = 'wp-content/uploads'; + $dir = trim(get_settings('fileupload_realpath')); + $url = trim(get_settings('fileupload_url')); - $path = ABSPATH . $dir; - - // Give the new dirs the same perms as wp-content. - $stat = stat(ABSPATH . 'wp-content'); - $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. - - // Make sure we have an uploads dir - if ( ! file_exists( $path ) ) { - if ( ! @ mkdir( $path ) ) - return array('error' => "Unable to create directory $path. Is its parent directory writable by the server?"); - @ chmod( $path, $dir_perms ); + $custom = true; + if ( empty($dir) || empty($url) ) { + $dir = ABSPATH . 'wp-content/uploads'; + $url = get_option('siteurl') . '/wp-content/uploads'; + $custom = false; } - // Generate the yearly and monthly dirs - $time = current_time( 'mysql' ); - $y = substr( $time, 0, 4 ); - $m = substr( $time, 5, 2 ); - $pathy = "$path/$y"; - $pathym = "$path/$y/$m"; + if ( defined('UPLOADS') ) { + $dir = ABSPATH . UPLOADS; + $url = get_option('siteurl') . '/' . UPLOADS; + $custom = false; + } - // Make sure we have a yearly dir - if ( ! file_exists( $pathy ) ) { - if ( ! @ mkdir( $pathy ) ) - return array('error' => "Unable to create directory $pathy. Is $path writable?"); - @ chmod( $pathy, $dir_perms ); + if ( ! $custom) { + // Generate the yearly and monthly dirs + $time = current_time( 'mysql' ); + $y = substr( $time, 0, 4 ); + $m = substr( $time, 5, 2 ); + $dir = $dir . "/$y/$m"; + $url = $url . "/$y/$m"; } - // Make sure we have a monthly dir - if ( ! file_exists( $pathym ) ) { - if ( ! @ mkdir( $pathym ) ) - return array('error' => "Unable to create directory $pathym. Is $pathy writable?"); - @ chmod( $pathym, $dir_perms ); + // Make sure we have an uploads dir + if ( ! wp_mkdir_p( $dir ) ) { + $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir); + return array('error' => $message); } - $uploads = array('path' => $pathym, 'url' => get_option('siteurl') . "/$dir/$y/$m", 'error' => false); + $uploads = array('path' => $dir, 'url' => $url, 'error' => false); return apply_filters('upload_dir', $uploads); } @@ -891,10 +926,25 @@ function wp_upload_bits($name, $type, $bits) { $number = ''; $filename = $name; - while ( file_exists($upload['path'] . "/$filename") ) - $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename); + $path_parts = pathinfo($filename); + $ext = $path_parts['extension']; + if ( empty($ext) ) + $ext = ''; + else + $ext = ".$ext"; + while ( file_exists($upload['path'] . "/$filename") ) { + if ( '' == "$number$ext" ) + $filename = $filename . ++$number . $ext; + else + $filename = str_replace("$number$ext", ++$number . $ext, $filename); + } + + $new_file = $upload['path'] . "/$filename"; + if ( ! wp_mkdir_p( dirname($new_file) ) ) { + $message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), dirname($new_file)); + return array('error' => $message); + } - $new_file = $uploads['path'] . "/$filename"; $ifp = @ fopen($new_file, 'wb'); if ( ! $ifp ) return array('error' => "Could not write file $new_file."); @@ -903,13 +953,14 @@ function wp_upload_bits($name, $type, $bits) { fclose($ifp); // Set correct file permissions $stat = @ stat(dirname($new_file)); - $perms = $stat['mode'] & 0000777; + $perms = $stat['mode'] & 0007777; + $perms = $perms & 0000666; @ chmod($new_file, $perms); // Compute the URL $url = $upload['url'] . "/$filename"; - return array('file' => $new_file, 'url' => $url); + return array('file' => $new_file, 'url' => $url, 'error' => false); } ?> diff --git a/wp-inst/wp-includes/vars.php b/wp-inst/wp-includes/vars.php index d80cb99..705d8b2 100644 --- a/wp-inst/wp-includes/vars.php +++ b/wp-inst/wp-includes/vars.php @@ -1,10 +1,6 @@ <?php // On which page are we ? -$PHP_SELF = $_SERVER['PHP_SELF']; -if ( empty($PHP_SELF) ) - $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); - if (preg_match('#([^/]+.php)#', $PHP_SELF, $self_matches)) { $pagenow = $self_matches[1]; } else if (strstr($PHP_SELF, '?')) { diff --git a/wp-inst/wp-login.php b/wp-inst/wp-login.php index 4c2a4f7..ee9246b 100644 --- a/wp-inst/wp-login.php +++ b/wp-inst/wp-login.php @@ -188,7 +188,7 @@ default: do_action('wp_authenticate', array(&$user_login, &$user_pass)); - if ( $_POST ) { + if ( $user_login && $user_pass ) { $user = new WP_User(0, $user_login); // If the user can't edit posts, send them to their profile. diff --git a/wp-inst/wp-settings.php b/wp-inst/wp-settings.php index 0c4a59b..48e9b8e 100644 --- a/wp-inst/wp-settings.php +++ b/wp-inst/wp-settings.php @@ -42,6 +42,10 @@ if ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_F if ( strstr( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) ) unset($_SERVER['PATH_INFO']); +// Fix empty PHP_SELF +$PHP_SELF = $_SERVER['PHP_SELF']; +if ( empty($PHP_SELF) ) + $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); if ( !(phpversion() >= '4.1') ) die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' ); @@ -169,15 +173,13 @@ if( $blog_id == false ) { } } -if( $public == '0' ) { - // need to put checks in here? - // A hook? - die( "This blog is private." ); +if( '0' == $current_blog->public ) { + // This just means the blog shouldn't show up in google, etc. Only to registered members } $wpdb->show_errors(); -$table_prefix = $table_prefix.$blog_id."_"; +$table_prefix = $table_prefix . $blog_id . '_'; // Table names $wpdb->siteid = $site_id; @@ -313,19 +315,16 @@ if ( !defined('SITECOOKIEPATH') ) if ( !defined('COOKIE_DOMAIN') ) define('COOKIE_DOMAIN', false); - require (ABSPATH . WPINC . '/vars.php'); do_action('core_files_loaded'); /* - // Check for hacks file if the option is enabled if (get_settings('hack_file')) { if (file_exists(ABSPATH . '/my-hacks.php')) require(ABSPATH . '/my-hacks.php'); } - */ if ( get_settings('active_plugins') ) { diff --git a/wp-inst/wp-trackback.php b/wp-inst/wp-trackback.php index 1a1d826..00eabeb 100644 --- a/wp-inst/wp-trackback.php +++ b/wp-inst/wp-trackback.php @@ -69,9 +69,9 @@ if ( !empty($tb_url) && !empty($title) && !empty($tb_url) ) { $title = wp_specialchars( strip_tags( $title ) ); $excerpt = strip_tags($excerpt); - if ( function_exists('mb_substr') ) { // For international trackbacks - $excerpt = mb_substr($excerpt, 0, 252, get_settings('blog_charset')) . '...'; - $title = mb_substr($title, 0, 250, get_settings('blog_charset')) . '...'; + if ( function_exists('mb_strcut') ) { // For international trackbacks + $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...'; + $title = mb_strcut($title, 0, 250, get_settings('blog_charset')) . '...'; } else { $excerpt = (strlen($excerpt) > 255) ? substr($excerpt, 0, 252) . '...' : $excerpt; $title = (strlen($title) > 250) ? substr($title, 0, 250) . '...' : $title; diff --git a/wp-inst/xmlrpc.php b/wp-inst/xmlrpc.php index 9c4d0d7..c4cdbaf 100644 --- a/wp-inst/xmlrpc.php +++ b/wp-inst/xmlrpc.php @@ -853,7 +853,7 @@ class wp_xmlrpc_server extends IXR_Server { } $upload = wp_upload_bits($name, $type, $bits); - if ( $upload['error'] !== false ) { + if ( ! empty($upload['error']) ) { logIO('O', '(MW) Could not write file '.$name); return new IXR_Error(500, 'Could not write file '.$name); } |