diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-11-29 14:36:34 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2005-11-29 14:36:34 +0000 |
commit | fef18a3dfb388c79cb8aa60832ea4a01f68718ab (patch) | |
tree | 989a39736de98c99903236649b1d1b0358ccc6d9 | |
parent | 4bfcc23eea03bb1e51fcac429c336265efb66b57 (diff) | |
download | wordpress-mu-fef18a3dfb388c79cb8aa60832ea4a01f68718ab.tar.gz wordpress-mu-fef18a3dfb388c79cb8aa60832ea4a01f68718ab.tar.xz wordpress-mu-fef18a3dfb388c79cb8aa60832ea4a01f68718ab.zip |
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@450 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r-- | wp-inst/wp-admin/admin-functions.php | 6 | ||||
-rw-r--r-- | wp-inst/wp-admin/edit-form-advanced.php | 2 | ||||
-rw-r--r-- | wp-inst/wp-admin/import/textpattern.php | 653 | ||||
-rw-r--r-- | wp-inst/wp-admin/index.php | 9 | ||||
-rw-r--r-- | wp-inst/wp-admin/inline-uploading.php | 353 | ||||
-rw-r--r-- | wp-inst/wp-admin/install.php | 1 | ||||
-rw-r--r-- | wp-inst/wp-admin/options-writing.php | 5 | ||||
-rw-r--r-- | wp-inst/wp-admin/profile.php | 2 | ||||
-rw-r--r-- | wp-inst/wp-admin/upgrade-schema.php | 2 | ||||
-rw-r--r-- | wp-inst/wp-admin/wp-admin.css | 2 | ||||
-rw-r--r-- | wp-inst/wp-includes/class-snoopy.php | 2 | ||||
-rw-r--r-- | wp-inst/wp-includes/classes.php | 47 | ||||
-rw-r--r-- | wp-inst/wp-includes/functions-formatting.php | 3 | ||||
-rw-r--r-- | wp-inst/wp-includes/functions.php | 87 | ||||
-rw-r--r-- | wp-inst/wp-includes/template-functions-post.php | 4 | ||||
-rw-r--r-- | wp-inst/wp-includes/vars.php | 3 | ||||
-rw-r--r-- | wp-inst/wp-includes/wpmu-functions.php | 302 | ||||
-rw-r--r-- | wp-inst/wp-rss2.php | 2 |
18 files changed, 1152 insertions, 333 deletions
diff --git a/wp-inst/wp-admin/admin-functions.php b/wp-inst/wp-admin/admin-functions.php index 946aaa4..cfce700 100644 --- a/wp-inst/wp-admin/admin-functions.php +++ b/wp-inst/wp-admin/admin-functions.php @@ -81,10 +81,6 @@ function relocate_children($old_ID, $new_ID) { function fix_attachment_links($post_ID) { global $wp_rewrite; - // Relevance check. - if ( false == $wp_rewrite->using_permalinks() ) - return; - $post = & get_post($post_ID); $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; @@ -869,7 +865,7 @@ function add_meta($post_ID) { $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput']))); $metavalue = $wpdb->escape(stripslashes(trim($_POST['metavalue']))); - if (!empty ($metavalue) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput))) { + if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) { // We have a key/value pair. If both the select and the // input for the key have data, the input takes precedence: diff --git a/wp-inst/wp-admin/edit-form-advanced.php b/wp-inst/wp-admin/edit-form-advanced.php index c8db328..2f15d25 100644 --- a/wp-inst/wp-admin/edit-form-advanced.php +++ b/wp-inst/wp-admin/edit-form-advanced.php @@ -153,7 +153,7 @@ endforeach; ?> <?php if ( !$richedit ) the_quicktags(); ?> -<div><textarea title="true" rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="2" id="content"><?php echo $richedit ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div> +<div><textarea <?php if ( $richedit ) echo 'title="true"'; ?> rows="<?php echo $rows; ?>" cols="40" name="content" tabindex="2" id="content"><?php echo $richedit ? wp_richedit_pre($post->post_content) : $post->post_content; ?></textarea></div> </fieldset> <?php if ( !$richedit ) : ?> diff --git a/wp-inst/wp-admin/import/textpattern.php b/wp-inst/wp-admin/import/textpattern.php index e69de29..9c908bb 100644 --- a/wp-inst/wp-admin/import/textpattern.php +++ b/wp-inst/wp-admin/import/textpattern.php @@ -0,0 +1,653 @@ +<?php + +/* +This Import Script is written by Aaron Brazell of Technosailor.com + +It was developed using a large blog running Textpattern 4.0.2 and + successfully imported nearly 3000 records at a time. Higher + scalability is uncertain. + + BACKUP YOUR DATABASE PRIOR TO RUNNING THIS IMPORT SCRIPT +*/ + +// BEGIN EDITING + +// $txpconfig options can be found in the Textpattern %textpattern%/config.php file +$txpcfg['db'] = 'textpattern'; +$txpcfg['user'] = 'root'; +$txpcfg['pass'] = ''; +$txpcfg['host'] = 'localhost'; +$txpcfg['table_prefix'] = ''; + +// STOP EDITING + +add_option('tpre',$txpcfg['table_prefix']); + + +/** + Add These Functions to make our lives easier +**/ +if(!function_exists('get_cat_nicename')) +{ + function get_catbynicename($category_nicename) + { + global $wpdb; + + $cat_id -= 0; // force numeric + $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); + + return $name; + } +} + +if(!function_exists('get_comment_count')) +{ + function get_comment_count($post_ID) + { + global $wpdb; + return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); + } +} + +if(!function_exists('link_exists')) +{ + function link_exists($linkname) + { + global $wpdb; + return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"'); + } +} + +/** + The Main Importer Class +**/ +class Textpattern_Import { + + var $posts = array (); + var $file; + + function header() + { + echo '<div class="wrap">'; + echo '<h2>'.__('Import Textpattern').'</h2>'; + } + + function footer() + { + echo '</div>'; + } + + function greet() + { + global $txpcfg; + + _e('<p>Howdy! This importer allows you to extract posts from any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern. Mileage may vary.</p>'); + _e('<p>Your Textpattern Configuration settings are as follows:</p>'); + _e('<ul><li><strong>Textpattern Database Name:</strong> '.$txpcfg['db'].'</li>'); + _e('<li><strong>Textpattern Database User:</strong> '.$txpcfg['user'].'</li>'); + _e('<li><strong>Textpattern Database Password:</strong> '.$txpcfg['pass'].'</li>'); + _e('<li><strong>Textpattern Database Host:</strong> '.$txpcfg['host'].'</li>'); + _e('</ul>'); + _e('<p>If this is incorrect, please modify settings in wp-admin/import/textpattern.php</p>'); + _e('<form action="admin.php?import=textpattern&step=1" method="post">'); + _e('<input type="submit" name="submit" value="Import Categories" />'); + _e('</form>'); + } + + function get_txp_links() + { + //General Housekeeping + global $txpdb; + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + return $txpdb->get_results('SELECT + id, + date, + category, + url, + linkname, + description + FROM '.$prefix.'txp_link', + ARRAY_A); + echo'SELECT + id, + date, + category, + url, + linkname, + description + FROM '.$prefix.'txp_link'; + } + + function get_txp_cats() + { + + // General Housekeeping + global $txpdb; + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Categories + return $txpdb->get_results('SELECT + id, + name, + title + FROM '.$prefix.'txp_category + WHERE type = "article"', + ARRAY_A); + } + + function get_txp_posts() + { + // General Housekeeping + global $txpdb; + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Posts + return $txpdb->get_results('SELECT + ID, + Posted, + AuthorID, + LastMod, + Title, + Body, + Excerpt, + Category1, + Category2, + Status, + Keywords, + url_title, + comments_count, + ADDDATE(Posted, "INTERVAL '.get_settings('gmt_offset').' HOURS") AS post_date_gmt, + ADDDATE(LastMod, "INTERVAL '.get_settings('gmt_offset').' HOURS") AS post_modified_gmt + FROM '.$prefix.'textpattern + ', ARRAY_A); + } + + function get_txp_comments() + { + // General Housekeeping + global $txpdb; + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Comments + return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); + } + + function get_txp_users() + { + // General Housekeeping + global $txpdb; + set_magic_quotes_runtime(0); + $prefix = get_option('tpre'); + + // Get Users + $users = $txpdb->get_results('SELECT + user_id, + name, + RealName, + email, + privs + FROM '.$prefix.'txp_users', ARRAY_A); + return $users; + } + + function links2wp($links='') + { + // General Housekeeping + global $wpdb; + $count = 0; + + // Deal with the links + if(is_array($links)) + { + echo __('<p>Importing Links...<br /><br /></p>'); + foreach($links as $link) + { + $count++; + extract($link); + + // Make nice vars + $category = $wpdb->escape($category); + $linkname = $wpdb->escape($linkname); + $description = $wpdb->escape($description); + + if($linfo = link_exists($linkname)) + { + $ret_id = wp_insert_link(array( + 'link_id' => $linfo, + 'link_url' => $url, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description, + 'link_updated' => $date) + ); + } + else + { + $ret_id = wp_insert_link(array( + 'link_url' => $url, + 'link_name' => $linkname, + 'link_category' => $category, + 'link_description' => $description, + 'link_updated' => $date) + ); + } + $txplinks2wplinks[$link_id] = $ret_id; + } + add_option('txplinks2wplinks',$txplinks2wplinks); + echo __('<p>Done! <strong>'.$count.'</strong> Links imported.<br /><br /></p>'); + return true; + } + echo 'No Links to Import!'; + return false; + } + + function users2wp($users='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpid2wpid = array(); + + // Midnight Mojo + if(is_array($users)) + { + echo __('<p>Importing Users...<br /><br /></p>'); + foreach($users as $user) + { + $count++; + extract($user); + + // Make Nice Variables + $name = $wpdb->escape($name); + $RealName = $wpdb->escape($RealName); + + if($uinfo = get_userdatabylogin($name)) + { + + $ret_id = wp_insert_user(array( + 'ID' => $uinfo->ID, + 'user_login' => $name, + 'user_nicename' => $RealName, + 'user_email' => $email, + 'user_url' => 'http://', + 'display_name' => $name) + ); + } + else + { + $ret_id = wp_insert_user(array( + 'user_login' => $name, + 'user_nicename' => $RealName, + 'user_email' => $email, + 'user_url' => 'http://', + 'display_name' => $name) + ); + } + $txpid2wpid[$user_id] = $ret_id; + + // Set Textpattern-to-WordPress permissions translation + $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); + + // Update Usermeta Data + $user = new WP_User($ret_id); + if('10' == $transperms[$privs]) { $user->set_role('administrator'); } + if('9' == $transperms[$privs]) { $user->set_role('editor'); } + if('5' == $transperms[$privs]) { $user->set_role('editor'); } + if('4' == $transperms[$privs]) { $user->set_role('author'); } + if('3' == $transperms[$privs]) { $user->set_role('contributor'); } + if('2' == $transperms[$privs]) { $user->set_role('contributor'); } + if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } + + update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] ); + update_usermeta( $ret_id, 'rich_editing', 'false'); + }// End foreach($users as $user) + + // Store id translation array for future use + add_option('txpid2wpid',$txpid2wpid); + + + echo __('<p>Done! <strong>'.$count.'</strong> users imported.<br /><br /></p>'); + return true; + }// End if(is_array($users) + + echo 'No Users to Import!'; + return false; + + }// End function user2wp() + + function cat2wp($categories='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpcat2wpcat = array(); + + // Do the Magic + if(is_array($categories)) + { + echo __('<p>Importing Categories...<br /><br /></p>'); + foreach ($categories as $category) + { + $count++; + extract($category); + + + // Make Nice Variables + $name = $wpdb->escape($name); + $title = $wpdb->escape($title); + + if($cinfo = category_exists($name)) + { + $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); + } + else + { + $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); + } + $txpcat2wpcat[$id] = $ret_id; + } + + // Store category translation for future use + add_option('txpcat2wpcat',$txpcat2wpcat); + echo __('<p>Done! <strong>'.$count.'</strong> categories imported.<br /><br /></p>'); + return true; + } + echo 'No Categories to Import!'; + return false; + + } + + function posts2wp($posts='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpposts2wpposts = array(); + $cats = array(); + + // Do the Magic + if(is_array($posts)) + { + echo __('<p>Importing Posts...<br /><br /></p>'); + foreach($posts as $post) + { + $count++; + extract($post); + + // Set Textpattern-to-WordPress status translation + $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); + + //Can we do this more efficiently? + $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1; + $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; + + $Title = $wpdb->escape($Title); + $Body = $wpdb->escape($Body); + $Excerpt = $wpdb->escape($Excerpt); + $post_status = $stattrans[$Status]; + + // Import Post data into WordPress + + if($pinfo = post_exists($Title,$Body)) + { + $ret_id = wp_insert_post(array( + 'ID' => $pinfo, + 'post_date' => $Posted, + 'post_date_gmt' => $post_date_gmt, + 'post_author' => $authorid, + 'post_modified' => $LastMod, + 'post_modified_gmt' => $post_modified_gmt, + 'post_title' => $Title, + 'post_content' => $Body, + 'post_excerpt' => $Excerpt, + 'post_status' => $post_status, + 'post_name' => $url_title, + 'comment_count' => $comments_count) + ); + } + else + { + $ret_id = wp_insert_post(array( + 'post_date' => $Posted, + 'post_date_gmt' => $post_date_gmt, + 'post_author' => $authorid, + 'post_modified' => $LastMod, + 'post_modified_gmt' => $post_modified_gmt, + 'post_title' => $Title, + 'post_content' => $Body, + 'post_excerpt' => $Excerpt, + 'post_status' => $post_status, + 'post_name' => $url_title, + 'comment_count' => $comments_count) + ); + } + $txpposts2wpposts[$ID] = $ret_id; + + // Make Post-to-Category associations + $cats = array(); + if($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; } + if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; } + + if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + } + } + // Store ID translation for later use + add_option('txpposts2wpposts',$txpposts2wpposts); + + echo __('<p>Done! <strong>'.$count.'</strong> posts imported.<br /><br /></p>'); + return true; + } + + function comments2wp($comments='') + { + // General Housekeeping + global $wpdb; + $count = 0; + $txpcm2wpcm = array(); + $postarr = get_option('txpposts2wpposts'); + + // Magic Mojo + if(is_array($comments)) + { + echo __('<p>Importing Comments...<br /><br /></p>'); + foreach($comments as $comment) + { + $count++; + extract($comment); + + // WordPressify Data + $comment_ID = ltrim($discussid, '0'); + $comment_approved = (1 == $visible) ? 1 : 0; + $name = $wpdb->escape($name); + $email = $wpdb->escape($email); + $web = $wpdb->escape($web); + $message = $wpdb->escape($message); + + if($cinfo = comment_exists($name, $posted)) + { + // Update comments + $ret_id = wp_update_comment(array( + 'comment_ID' => $cinfo, + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + else + { + // Insert comments + $ret_id = wp_insert_comment(array( + 'comment_post_ID' => $postarr[$parentid], + 'comment_author' => $name, + 'comment_author_email' => $email, + 'comment_author_url' => $web, + 'comment_author_IP' => $ip, + 'comment_date' => $posted, + 'comment_content' => $message, + 'comment_approved' => $comment_approved) + ); + } + $txpcm2wpcm[$comment_ID] = $ret_id; + } + // Store Comment ID translation for future use + add_option('txpcm2wpcm', $txpcm2wpcm); + + // Associate newly formed categories with posts + get_comment_count($ret_id); + + + echo __('<p>Done! <strong>'.$count.'</strong> comments imported.<br /><br /></p>'); + return true; + } + echo 'No Comments to Import!'; + return false; + } + + function import_categories() + { + // Category Import + $cats = $this->get_txp_cats(); + $this->cat2wp($cats); + add_option('txp_cats', $cats); + + + + _e('<form action="admin.php?import=textpattern&step=2" method="post">'); + _e('<input type="submit" name="submit" value="Import Users" />'); + _e('</form>'); + + } + + function import_users() + { + // User Import + $users = $this->get_txp_users(); + $this->users2wp($users); + + _e('<form action="admin.php?import=textpattern&step=3" method="post">'); + _e('<input type="submit" name="submit" value="Import Posts" />'); + _e('</form>'); + } + + function import_posts() + { + // Post Import + $posts = $this->get_txp_posts(); + $this->posts2wp($posts); + + _e('<form action="admin.php?import=textpattern&step=4" method="post">'); + _e('<input type="submit" name="submit" value="Import Comments" />'); + _e('</form>'); + } + + function import_comments() + { + // Comment Import + $comments = $this->get_txp_comments(); + $this->comments2wp($comments); + + _e('<form action="admin.php?import=textpattern&step=5" method="post">'); + _e('<input type="submit" name="submit" value="Import Links" />'); + _e('</form>'); + } + + function import_links() + { + //Link Import + $links = $this->get_txp_links(); + $this->links2wp($links); + add_option('txp_links', $links); + + _e('<form action="admin.php?import=textpattern&step=6" method="post">'); + _e('<input type="submit" name="submit" value="Finish" />'); + _e('</form>'); + } + + function cleanup_txpimport() + { + delete_option('tpre'); + delete_option('txp_cats'); + delete_option('txpid2wpid'); + delete_option('txpcat2wpcat'); + delete_option('txpposts2wpposts'); + delete_option('txpcm2wpcm'); + delete_option('txplinks2wplinks'); + $this->tips(); + } + + function tips() + { + echo'<p>Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.</p>'; + echo'<h3>Users</h3>'; + echo'<p>You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. <strong>Every user has the same username, but their passwords are reset to password123.</strong> This includes you. So <a href="/wp-login.php">Login</a> and change it.</p>'; + echo'<h3>Preserving Authors</h3>'; + echo'<p>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.</p>'; + echo'<h3>Textile</h3>'; + echo'<p>Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/">Textile for WordPress</a>. Trust me... You\'ll want it.</p>'; + echo'<h3>WordPress Resources</h3>'; + echo'<p>Finally, there are numerous WordPress resources around the internet. Some of them are:</p>'; + echo'<ul>'; + echo'<li><a href="http://www.wordpress.org">The official WordPress site</a></li>'; + echo'<li><a href="http://wordpress.org/support/">The WordPress support forums</li>'; + echo'<li><a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a></li>'; + echo'</ul>'; + echo'<p>That\'s it! What are you waiting for? Go <a href="/wp-login.php">login</a>!</p>'; + } + + function dispatch() + { + if (empty ($_GET['step'])) + $step = 0; + else + $step = (int) $_GET['step']; + + $this->header(); + + switch ($step) + { + default: + case 0 : + $this->greet(); + break; + case 1 : + $this->import_categories(); + break; + case 2 : + $this->import_users(); + break; + case 3 : + $this->import_posts(); + break; + case 4 : + $this->import_comments(); + break; + case 5 : + $this->import_links(); + break; + case 6 : + $this->cleanup_txpimport(); + break; + } + + $this->footer(); + } + + function Textpattern_Import() + { + // Nothing. + } +} + +$txpdb = new wpdb($txpcfg['user'], $txpcfg['pass'], $txpcfg['db'], $txpcfg['host']); + +$txp_import = new Textpattern_Import(); +register_importer('textpattern', 'Textpattern', __('Import posts from a Textpattern Blog'), array ($txp_import, 'dispatch')); +?> diff --git a/wp-inst/wp-admin/index.php b/wp-inst/wp-admin/index.php index 900f72d..3a4e552 100644 --- a/wp-inst/wp-admin/index.php +++ b/wp-inst/wp-admin/index.php @@ -32,14 +32,15 @@ foreach ($rss->items as $item ) { <?php } ?> <?php -if ( $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5") ) : +$comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 5"); +$numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_approved = '0'"); + +if ( $comments || $numcomments ) : ?> <div> <h3><?php _e('Comments'); ?> <a href="edit-comments.php" title="<?php _e('More comments...'); ?>">»</a></h3> -<?php -if ( $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_approved = '0'") ) : -?> +<?php if ( $numcomments ) : ?> <p><strong><a href="moderation.php"><?php echo sprintf(__('Comments in moderation (%s)'), number_format($numcomments) ); ?> »</a></strong></p> <?php endif; ?> </div> diff --git a/wp-inst/wp-admin/inline-uploading.php b/wp-inst/wp-admin/inline-uploading.php index d2b2a61..0458dd6 100644 --- a/wp-inst/wp-admin/inline-uploading.php +++ b/wp-inst/wp-admin/inline-uploading.php @@ -5,7 +5,7 @@ require_once('admin.php'); if (!current_user_can('edit_posts'))
die(__('You do not have permission to edit posts.'));
-$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment', 'flickrtag');
+$wpvarstoreset = array('action', 'post', 'all', 'last', 'link', 'sort', 'start', 'imgtitle', 'descr', 'attachment');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
@@ -37,6 +37,9 @@ function get_udims($width, $height) { switch($action) {
case 'delete':
+if ( !current_user_can('edit_post', (int) $attachment) )
+ die(printf(__('You are not allowed to delete this attachment. %sGo back</a>'), '<a href="'.basename(__FILE__)."?post=$post&all=$all&action=upload\">") );
+
wp_delete_attachment($attachment);
header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&start=$start");
@@ -71,22 +74,26 @@ $attachment = array( // Save the data
$id = wp_insert_attachment($attachment, $file, $post);
-// 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;
-$imagedata['thumb'] = "thumb-$filename";
-
-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 )
- $error = wp_create_thumbnail($file, 128);
- elseif ( $imagedata['height'] > 96 )
- $error = wp_create_thumbnail($file, 96);
+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;
+ $imagedata['thumb'] = "thumb-$filename";
+
+ 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 )
+ $error = wp_create_thumbnail($file, 128);
+ elseif ( $imagedata['height'] > 96 )
+ $error = wp_create_thumbnail($file, 96);
+ }
+} else {
+ add_post_meta($id, '_wp_attachment_metadata', array());
}
header("Location: ".basename(__FILE__)."?post=$post&all=$all&action=view&last=true");
@@ -111,8 +118,11 @@ if ( $post && empty($all) ) { $current_3 = ' class="current"';
}
+if (! current_user_can('edit_others_posts') )
+ $and_user = "AND post_author = " . $user_ID;
+
if ( $last )
- $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post") - $num;
+ $start = $wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' $and_user $and_post") - $num;
else
$start = (int) $start;
@@ -122,13 +132,13 @@ if ( $start < 0 ) if ( '' == $sort )
$sort = "post_date_gmt DESC";
-$images = $wpdb->get_results("SELECT ID, post_date, post_title, guid FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image' $and_post ORDER BY $sort LIMIT $start, $double", ARRAY_A);
+$attachments = $wpdb->get_results("SELECT ID, post_date, post_title, post_mime_type, guid FROM $wpdb->posts WHERE post_status = 'attachment' $and_type $and_post $and_user ORDER BY $sort LIMIT $start, $double", ARRAY_A);
-if ( count($images) == 0 ) {
+if ( count($attachments) == 0 ) {
header("Location: ".basename(__FILE__)."?post=$post&action=upload");
die;
-} elseif ( count($images) > $num ) {
- $next = $start + count($images) - $num;
+} elseif ( count($attachments) > $num ) {
+ $next = $start + count($attachments) - $num;
} else {
$next = false;
}
@@ -142,69 +152,94 @@ if ( $start > 0 ) { }
$uwidth_sum = 0;
-$images_html = '';
-$images_style = '';
-$images_script = '';
-if ( count($images) > 0 ) {
- $images = array_slice( $images, 0, $num );
+$html = '';
+$style = '';
+$script = '';
+if ( count($attachments) > 0 ) {
+ $attachments = array_slice( $attachments, 0, $num );
$__delete = __('Delete');
- $__attachment_on = __('Link to Page');
- $__attachment_off = __('Link to Image');
- $__thumbnail_on = __('Use Thumbnail');
- $__thumbnail_off = __('Use Full Image');
+ $__not_linked = __('Not Linked');
+ $__linked_to_page = __('Linked to Page');
+ $__linked_to_image = __('Linked to Image');
+ $__using_thumbnail = __('Using Thumbnail');
+ $__using_original = __('Using Original');
$__no_thumbnail = __('<del>No Thumbnail</del>');
$__close = __('Close Options');
- $__confirmdelete = __('Delete this photo from the server?');
+ $__confirmdelete = __('Delete this file from the server?');
$__nothumb = __('There is no thumbnail associated with this photo.');
- $images_script .= "attachmenton = '$__attachment_on';\nattachmentoff = '$__attachment_off';\n";
- $images_script .= "thumbnailon = '$__thumbnail_on';\nthumbnailoff = '$__thumbnail_off';\n";
- foreach ( $images as $key => $image ) {
- $attachment_ID = $image['ID'];
- $meta = get_post_meta($attachment_ID, '_wp_attachment_metadata', true);
+ $script .= "notlinked = '$__not_linked';
+linkedtoimage = '$__linked_to_image';
+linkedtopage = '$__linked_to_page';
+usingthumbnail = '$__using_thumbnail';
+usingoriginal = '$__using_original';
+";
+ foreach ( $attachments as $key => $attachment ) {
+ $ID = $attachment['ID'];
+ $meta = get_post_meta($ID, '_wp_attachment_metadata', true);
if (!is_array($meta)) {
- $meta = get_post_meta($attachment_ID, 'imagedata', true); // Try 1.6 Alpha meta key
+ $meta = get_post_meta($ID, 'imagedata', true); // Try 1.6 Alpha meta key
if (!is_array($meta)) {
- continue;
- } else {
- add_post_meta($attachment_ID, '_wp_attachment_metadata', $meta);
+ $meta = array();
}
+ add_post_meta($ID, '_wp_attachment_metadata', $meta);
}
- $image = array_merge($image, $meta);
- if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
- $src = str_replace(basename($image['guid']), '', $image['guid']) . $image['thumb'];
- $images_script .= "src".$attachment_ID."a = '$src';\nsrc".$attachment_ID."b = '".$image['guid']."';\n";
- $thumb = 'true';
- $thumbtext = $__thumbnail_on;
- } else {
- $src = $image['guid'];
- $thumb = 'false';
- $thumbtext = $__no_thumbnail;
- }
- list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
- $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
- $uwidth_sum += 128;
- $xpadding = (128 - $image['uwidth']) / 2;
- $ypadding = (96 - $image['uheight']) / 2;
- $images_style .= "#target{$attachment_ID} img { padding: {$ypadding}px {$xpadding}px; }\n";
- $href = get_attachment_link($attachment_ID);
- $images_script .= "href{$attachment_ID}a = '$href';\nhref{$attachment_ID}b = '{$image['guid']}';\n";
- $images_html .= "
-<div id='target{$attachment_ID}' class='imagewrap left'>
- <div id='popup{$attachment_ID}' class='popup'>
- <a id=\"L{$attachment_ID}\" onclick=\"toggleLink({$attachment_ID});return false;\" href=\"javascript:void();\">$__attachment_on</a>
- <a id=\"I{$attachment_ID}\" onclick=\"if($thumb)toggleImage({$attachment_ID});else alert('$__nothumb');return false;\" href=\"javascript:void();\">$thumbtext</a>
- <a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&attachment={$attachment_ID}&all=$all&start=$start&post=$post\">$__delete</a>
+ $attachment = array_merge($attachment, $meta);
+ $delete_cancel = "<a onclick=\"return confirm('$__confirmdelete')\" href=\"".basename(__FILE__)."?action=delete&attachment={$ID}&all=$all&start=$start&post=$post\">$__delete</a>
<a onclick=\"popup.style.display='none';return false;\" href=\"javascript:void()\">$__close</a>
+";
+ $uwidth_sum += 128;
+ if ( preg_match('!^image/!', $attachment['post_mime_type'] ) ) {
+ $image = & $attachment;
+ if ( ($image['width'] > 128 || $image['height'] > 96) && !empty($image['thumb']) && file_exists(dirname($image['file']).'/'.$image['thumb']) ) {
+ $src = str_replace(basename($image['guid']), $image['thumb'], $image['guid']);
+ $script .= "src{$ID}a = '$src';
+src{$ID}b = '{$image['guid']}';
+";
+ $thumb = 'true';
+ $thumbtext = $__using_thumbnail;
+ } else {
+ $src = $image['guid'];
+ $thumb = 'false';
+ $thumbtext = $__no_thumbnail;
+ }
+ list($image['uwidth'], $image['uheight']) = get_udims($image['width'], $image['height']);
+ $height_width = 'height="'.$image['uheight'].'" width="'.$image['uwidth'].'"';
+ $xpadding = (128 - $image['uwidth']) / 2;
+ $ypadding = (96 - $image['uheight']) / 2;
+ $style .= "#target{$ID} img { padding: {$ypadding}px {$xpadding}px; }\n";
+ $href = get_attachment_link($ID);
+ $script .= "a{$ID}a = '<a id=\"{$ID}\" rel=\"attachment\" class=\"imagelink\" href=\"$href\" onclick=\"doPopup({$ID});return false;\" title=\"{$image['post_title']}\">';
+a{$ID}b = '<a class=\"imagelink\" href=\"{$image['guid']}\" onclick=\"doPopup({$ID});return false;\" title=\"{$image['post_title']}\">';
+img{$ID}a = '<img id=\"image{$ID}\" src=\"$src\" alt=\"{$image['post_title']}\" $height_width />';
+img{$ID}b = '<img id=\"image{$ID}\" src=\"{$image['guid']}\" alt=\"{$image['post_title']}\" $height_width />';
+";
+ $html .= "<div id='target{$ID}' class='attwrap left'>
+ <div id='popup{$ID}' class='popup'>
+ <a id=\"I{$ID}\" onclick=\"if($thumb)toggleImage({$ID});else alert('$__nothumb');return false;\" href=\"javascript:void()\">$thumbtext</a>
+ <a id=\"L{$ID}\" onclick=\"toggleLink({$ID});return false;\" href=\"javascript:void()\">$__not_linked</a>
+ {$delete_cancel}
+ </div>
+ <div id='div{$ID}' class='imagewrap' onclick=\"doPopup({$ID});\">
+ <img id=\"image{$ID}\" src=\"$src\" alt=\"{$image['post_title']}\" $height_width />
+ </div>
+</div>
+";
+ } else {
+ $html .= "<div id='target{$ID}' class='attwrap left'>
+ <div id='popup{$ID}' class='popup'>
+ <div class='filetype'>File Type: ".str_replace('/',"/\n",$attachment['post_mime_type'])."</div>
+ {$delete_cancel}
+ </div>
+ <div id='div{$ID}' class='otherwrap' onmousedown=\"selectLink({$ID})\" onclick=\"doPopup({$ID});return false;\">
+ <a id=\"{$ID}\" href=\"{$attachment['guid']}\" onmousedown=\"selectLink({$ID});\" onclick=\"return false;\">{$attachment['post_title']}</a>
</div>
- <a id=\"{$attachment_ID}\" rel=\"attachment\" class=\"imagelink\" href=\"$href\" onclick=\"imagePopup({$attachment_ID});return false;\" title=\"{$image['post_title']}\">
- <img id=\"image{$attachment_ID}\" src=\"$src\" alt=\"{$attachment_ID}\" $height_width />
- </a>
</div>
";
+ }
}
}
-$images_width = $uwidth_sum + ( count($images) * 5 ) + 30;
+$images_width = $uwidth_sum + ( count($images) * 6 ) + 35;
break;
@@ -220,55 +255,62 @@ die('This script was not meant to be called directly.'); <meta http-equiv="imagetoolbar" content="no" />
<script type="text/javascript">
/* Define any variables we'll need, such as alternate URLs. */
-<?php echo $images_script; ?>
+<?php echo $script; ?>
-function validateImageName() {
-/* This is more for convenience than security. Server-side validation is very thorough.*/
-obj = document.getElementById('upload');
-r = /.jpg$|.gif$|.png$/i;
-if ( obj.value.match(r) )
-return true;
-alert('Please select a JPG, PNG or GIF file.');
-return false;
-}
function cancelUpload() {
-o = document.getElementById('uploadForm');
-o.method = 'GET';
-o.action.value = 'view';
-o.submit();
-}
-function imagePopup(i) {
-if ( popup )
-popup.style.display = 'none';
-target = document.getElementById('target'+i);
-popup = document.getElementById('popup'+i);
-//popup.style.top = (target.offsetTop + 3) + 'px';
-popup.style.left = (target.offsetLeft) + 'px';
-popup.style.display = 'block';
+ o = document.getElementById('uploadForm');
+ o.method = 'GET';
+ o.action.value = 'view';
+ o.submit();
+}
+function doPopup(i) {
+ if ( popup )
+ popup.style.display = 'none';
+ target = document.getElementById('target'+i);
+ popup = document.getElementById('popup'+i);
+ popup.style.left = (target.offsetLeft) + 'px';
+ popup.style.display = 'block';
}
function init() {
-popup = false;
+ popup = false;
+}
+function selectLink(n) {
+ o=document.getElementById('div'+n);
+ r = document.body.createTextRange();
+ if ( typeof r != 'undefined' ) {
+ r.moveToElementText(o);
+ r.select();
+ }
}
function toggleLink(n) {
- o=document.getElementById(n);
- oi=document.getElementById('L'+n);
- if ( oi.innerHTML == attachmenton ) {
- o.href = eval('href'+n+'b');
- oi.innerHTML = attachmentoff;
+ od=document.getElementById('div'+n);
+ ol=document.getElementById('L'+n);
+ oi=document.getElementById('I'+n);
+ if ( oi.innerHTML == usingthumbnail ) {
+ img = eval('img'+n+'a');
} else {
- o.href = eval('href'+n+'a');
- oi.innerHTML = attachmenton;
+ img = eval('img'+n+'b');
+ }
+ if ( ol.innerHTML == notlinked ) {
+ od.innerHTML = eval('a'+n+'b')+img+'</a>';
+ ol.innerHTML = linkedtoimage;
+ } else if ( ol.innerHTML == linkedtoimage ) {
+ od.innerHTML = eval('a'+n+'a')+img+'</a>';
+ ol.innerHTML = linkedtopage;
+ } else {
+ od.innerHTML = img;
+ ol.innerHTML = notlinked;
}
}
function toggleImage(n) {
o = document.getElementById('image'+n);
oi = document.getElementById('I'+n);
- if ( oi.innerHTML == thumbnailon ) {
+ if ( oi.innerHTML == usingthumbnail ) {
o.src = eval('src'+n+'b');
- oi.innerHTML = thumbnailoff;
+ oi.innerHTML = usingoriginal;
} else {
o.src = eval('src'+n+'a');
- oi.innerHTML = thumbnailon;
+ oi.innerHTML = usingthumbnail;
}
}
</script>
@@ -281,56 +323,73 @@ body { background: #dfe8f1;
}
form {
- margin: 6px 2px 0px 6px;
+ margin: 3px 2px 0px 6px;
}
#wrap {
clear: both;
- margin: 0px;
padding: 0px;
- height: 133px;
width: 100%;
- overflow: auto;
}
#images {
clear: both;
margin: 0px;
- padding: 5px 15px;
+ padding: 3px 15px;
height: 96px;
- white-space: nowrap;
+/* white-space: nowrap;*/
width: <?php echo $images_width; ?>px;
}
#images img {
background-color: rgb(209, 226, 239);
}
-<?php echo $images_style; ?>
+<?php echo $style; ?>
+.attwrap, .attwrap * {
+ overflow: none;
+ margin: 0px;
+ padding: 0px;
+ border: 0px;
+}
.imagewrap {
margin-right: 5px;
height: 96px;
overflow: hidden;
+ float: left;
}
-.imagewrap * {
- margin: 0px;
- padding: 0px;
- border: 0px;
+.otherwrap {
+ margin-right: 5px;
+ height: 90px;
+ overflow: hidden;
+ background-color: #f9fcfe;
+ float: left;
+ padding: 3px;
+}
+.otherwrap a {
+ display: block;
+ width: 122px;
+}
+.otherwrap a, .otherwrap a:hover, .otherwrap a:active, .otherwrap a:visited {
+ color: blue;
+}
+.filetype {
+ font-size: 80%;
+ border-bottom: 3px double #89a
}
-.imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img {
+.imagewrap, .imagewrap img, .imagewrap a, .imagewrap a img, .imagewrap a:hover img, .imagewrap a:visited img, .imagewrap a:active img {
text-decoration: none;
- float: left;
- text-align: center;
}
#upload-menu {
background: #fff;
- margin: 0;
+ margin: 0px;
padding: 0;
list-style: none;
height: 2em;
border-bottom: 1px solid #448abd;
+ width: 100%;
}
#upload-menu li {
float: left;
- margin: 0 0 0 1em;
+ margin: 0 0 0 .75em;
}
#upload-menu a {
@@ -344,7 +403,6 @@ form { #upload-menu .current a {
background: #dfe8f1;
border-right: 2px solid #448abd;
-
}
#upload-menu a:hover {
@@ -373,16 +431,14 @@ form { #upload-menu li.spacer {
margin-left: 40px;
}
-
#title, #descr {
- width: 80%;
- margin-top: 2px;
+ width: 100%;
+ margin-top: 1px;
}
#descr {
- height: 35px;
+ height: 36px;
}
#buttons {
- width: 98%;
margin-top: 2px;
text-align: right;
}
@@ -394,9 +450,14 @@ form { height: 82px;
display: none;
background-color: rgb(223, 232, 241);
+ text-align: center;
+}
+.imagewrap .popup {
opacity: .90;
filter:alpha(opacity=90);
- text-align: center;
+}
+.otherwrap .popup {
+ padding-top: 20px;
}
.popup a, .popup a:visited, .popup a:active {
background-color: transparent;
@@ -413,12 +474,12 @@ form { </head>
<body onload="init()">
<ul id="upload-menu">
-<li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__); ?>?action=upload&post=<?php echo $post; ?>&all=<?php echo $all; ?>"><?php _e('Upload Image'); ?></a></li>
+<li<?php echo $current_1; ?>><a href="<?php echo basename(__FILE__); ?>?action=upload&post=<?php echo $post; ?>&all=<?php echo $all; ?>"><?php _e('Upload'); ?></a></li>
<?php if ( $attachments = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_parent = '$post'") ) { ?>
-<li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&post=<?php echo $post; ?>"><?php _e('Attached Images'); ?></a></li>
+<li<?php echo $current_2; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&post=<?php echo $post; ?>"><?php _e('Browse'); ?></a></li>
<?php } ?>
-<?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment' AND left(post_mime_type, 5) = 'image'")) { ?>
-<li<?php echo $current_3; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&post=<?php echo $post; ?>&all=true"><?php _e('All Images'); ?></a></li>
+<?php if ($wpdb->get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_status = 'attachment'")) { ?>
+<li<?php echo $current_3; ?>><a href="<?php echo basename(__FILE__); ?>?action=view&post=<?php echo $post; ?>&all=true"><?php _e('Browse All'); ?></a></li>
<?php } ?>
<li> </li>
<?php if ( $action != 'upload' ) { ?>
@@ -426,24 +487,23 @@ form { <li class="spacer"><a href="<?php echo basename(__FILE__); ?>?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=0" title="<?php _e('First'); ?>">|«</a></li>
<li><a href="<?php echo basename(__FILE__); ?>?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $back; ?>"">« <?php _e('Back'); ?></a></li>
<?php else : ?>
-<li class="inactive spacer">|<</li>
-<li class="inactive"><<</li>
+<li class="inactive spacer">|«</li>
+<li class="inactive">« <?php _e('Back'); ?></li>
<?php endif; ?>
<?php if ( false !== $next ) : ?>
<li><a href="<?php echo basename(__FILE__); ?>?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&start=<?php echo $next; ?>"><?php _e('Next'); ?> »</a></li>
<li><a href="<?php echo basename(__FILE__); ?>?action=<?php echo $action; ?>&post=<?php echo $post; ?>&all=<?php echo $all; ?>&last=true" title="<?php _e('Last'); ?>">»|</a></li>
<?php else : ?>
-<li class="inactive">>></li>
-<li class="inactive">>|</li>
+<li class="inactive"><?php _e('Next'); ?> »</li>
+<li class="inactive">»|</li>
<?php endif; ?>
<?php } // endif not upload?>
</ul>
<?php if ( $action == 'view' ) : ?>
-<span class="left tip"><?php _e('You can drag and drop these photos into your post. Click on the thumbnail for more options.'); ?></span>
-<span class="right tip"></span>
<div id="wrap">
+<div class="tip"><?php _e('You can drag and drop these items into your post. Click on one for more options.'); ?></div>
<div id="images">
-<?php echo $images_html; ?>
+<?php echo $html; ?>
</div>
</div>
<?php elseif ( $action == 'upload' ) : ?>
@@ -451,11 +511,11 @@ form { ?><div class="center tip">Sorry, you have used your space allocation. Please delete some files to upload more files.</div><?php
} else { ?>
<div class="tip"></div>
-<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo basename(__FILE__); ?>" onsubmit="return validateImageName()">
-<table style="width: 100%">
+<form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo basename(__FILE__); ?>">
+<table style="width:99%;">
<tr>
-<th scope="row" style="width: 6em; text-align: right;"><label for="upload"><?php _e('Image:'); ?></label></th>
-<td><input type="file" id="upload" name="image" onchange="validateImageName()" /></td>
+<th scope="row" style="width: 4.5em;text-align: right;"><label for="upload"><?php _e('File:'); ?></label></th>
+<td><input type="file" id="upload" name="image" /></td>
</tr>
<tr>
<th scope="row" style="text-align: right;"><label for="title"><?php _e('Title:'); ?></label></th>
@@ -465,14 +525,17 @@ form { <th scope="row" style="text-align: right;"><label for="descr"><?php _e('Description:'); ?></label></th>
<td><input type="textarea" name="descr" id="descr" value="" /></td>
</tr>
-</table>
-<p class="submit">
+<tr id="buttons">
+<th></th>
+<td>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="post" value="<?php echo $post; ?>" />
<input type="hidden" name="all" value="<?php echo $all; ?>" />
<input type="submit" value="<?php _e('Upload'); ?>" />
<input type="button" value="<?php _e('Cancel'); ?>" onclick="cancelUpload()" />
-</p>
+</td>
+</tr>
+</table>
</div>
</form>
<?php } ?>
diff --git a/wp-inst/wp-admin/install.php b/wp-inst/wp-admin/install.php index dddb9be..33dd4e3 100644 --- a/wp-inst/wp-admin/install.php +++ b/wp-inst/wp-admin/install.php @@ -171,6 +171,7 @@ $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comm // First Page $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static')"); +generate_page_rewrite_rules(); // Set up admin user $random_password = substr(md5(uniqid(microtime())), 0, 6); diff --git a/wp-inst/wp-admin/options-writing.php b/wp-inst/wp-admin/options-writing.php index d41ad6d..fd14016 100644 --- a/wp-inst/wp-admin/options-writing.php +++ b/wp-inst/wp-admin/options-writing.php @@ -21,7 +21,8 @@ include('admin-header.php'); <td> <label for="use_smilies"> <input name="use_smilies" type="checkbox" id="use_smilies" value="1" <?php checked('1', get_settings('use_smilies')); ?> /> -<?php _e('Convert emoticons like <code>:-)</code> and <code>:-P</code> to graphics on display') ?></label> +<?php _e('Convert emoticons like <code>:-)</code> and <code>:-P</code> to graphics on display') ?></label><br /> +<label for="use_balanceTags"><input name="use_balanceTags" type="checkbox" id="use_balanceTags" value="1" <?php checked('1', get_settings('use_balanceTags')); ?> /> <?php _e('WordPress should correct invalidly nested XHTML automatically') ?></label> </td> </tr> <tr valign="top"> @@ -43,7 +44,7 @@ endforeach; <p class="submit"> <input type="hidden" name="action" value="update" /> -<input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category" /> +<input type="hidden" name="page_options" value="default_post_edit_rows,use_smilies,ping_sites,mailserver_url,mailserver_port,mailserver_login,mailserver_pass,default_category,default_email_category,use_balanceTags" /> <input type="submit" name="Submit" value="<?php _e('Update Options') ?> »" /> </p> </form> diff --git a/wp-inst/wp-admin/profile.php b/wp-inst/wp-admin/profile.php index a243d49..f612c3a 100644 --- a/wp-inst/wp-admin/profile.php +++ b/wp-inst/wp-admin/profile.php @@ -17,7 +17,7 @@ $bookmarklet_height= 440; <?php } ?> <div class="wrap"> -<h2><?php _e('Your Profile'); ?></h2> +<h2><?php _e('Your Profile and Personal Options'); ?></h2> <form name="profile" id="your-profile" action="profile-update.php" method="post"> <p> <input type="hidden" name="from" value="profile" /> diff --git a/wp-inst/wp-admin/upgrade-schema.php b/wp-inst/wp-admin/upgrade-schema.php index aa71c32..0751f17 100644 --- a/wp-inst/wp-admin/upgrade-schema.php +++ b/wp-inst/wp-admin/upgrade-schema.php @@ -200,7 +200,7 @@ function populate_options() { add_option('users_can_register', 0); add_option('admin_email', 'you@example.com'); add_option('start_of_week', 1); - add_option('use_balanceTags', 1); + add_option('use_balanceTags', 0); add_option('use_smilies', 1); add_option('require_name_email', 1); add_option('comments_notify', 1); diff --git a/wp-inst/wp-admin/wp-admin.css b/wp-inst/wp-admin/wp-admin.css index c068fe2..0a030e5 100644 --- a/wp-inst/wp-admin/wp-admin.css +++ b/wp-inst/wp-admin/wp-admin.css @@ -709,7 +709,7 @@ table .vers, table .name { } #moremeta fieldset div { margin: 2px 0 0 0px; - padding-left: 7px; + padding: 7px; } #moremeta { line-height: 130%; diff --git a/wp-inst/wp-includes/class-snoopy.php b/wp-inst/wp-includes/class-snoopy.php index 2dbf170..9b8a1d3 100644 --- a/wp-inst/wp-includes/class-snoopy.php +++ b/wp-inst/wp-includes/class-snoopy.php @@ -1014,7 +1014,7 @@ class Snoopy $headerfile = tempnam($temp_dir, "sno"); $safer_URI = strtr( $URI, "\"", " " ); // strip quotes from the URI to avoid shell access - exec($this->curl_path." -D \"$headerfile\"".$cmdline_params." \"".$safer_URI."\"",$results,$return); + exec(escapeshellcmd($this->curl_path." -D \"$headerfile\"".$cmdline_params." \"".$safer_URI."\""),$results,$return); if($return) { diff --git a/wp-inst/wp-includes/classes.php b/wp-inst/wp-includes/classes.php index c7bf1e4..59de66d 100644 --- a/wp-inst/wp-includes/classes.php +++ b/wp-inst/wp-includes/classes.php @@ -257,6 +257,7 @@ class WP_Query { // First let's clear some variables $whichcat = ''; $whichauthor = ''; + $whichpage = ''; $result = ''; $where = ''; $limits = ''; @@ -350,9 +351,25 @@ class WP_Query { $q['name'] = sanitize_title($q['name']); $where .= " AND post_name = '" . $q['name'] . "'"; } else if ('' != $q['pagename']) { - $q['pagename'] = sanitize_title(basename(str_replace('%2F', '/', urlencode($q['pagename'])))); + $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); + $page_paths = '/' . trim($q['pagename'], '/'); + $q['pagename'] = sanitize_title(basename($page_paths)); $q['name'] = $q['pagename']; - $where .= " AND post_name = '" . $q['pagename'] . "'"; + $page_paths = explode('/', $page_paths); + foreach($page_paths as $pathdir) + $page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir); + + $all_page_ids = get_all_page_ids(); + $reqpage = 0; + foreach ( $all_page_ids as $page_id ) { + $page = get_page($page_id); + if ( $page->fullpath == $page_path ) { + $reqpage = $page_id; + break; + } + } + + $where .= " AND (ID = '$reqpage')"; } elseif ('' != $q['attachment']) { $q['attachment'] = sanitize_title($q['attachment']); $q['name'] = $q['attachment']; @@ -511,7 +528,7 @@ class WP_Query { $q['author'] = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_nicename='".$q['author_name']."'"); $whichauthor .= ' AND (post_author = '.intval($q['author']).')'; } - + $where .= $search.$whichcat.$whichauthor; if ((empty($q['order'])) || ((strtoupper($q['order']) != 'ASC') && (strtoupper($q['order']) != 'DESC'))) { @@ -1466,7 +1483,8 @@ class WP { $request_match = $req_uri . '/' . $request; } - if (preg_match("!^$match!", $request_match, $matches)) { + if (preg_match("!^$match!", $request_match, $matches) || + preg_match("!^$match!", urldecode($request_match), $matches)) { // Got a match. $this->matched_rule = $match; @@ -1482,27 +1500,28 @@ class WP { // If we're processing a 404 request, clear the error var // since we found something. - if (isset($_GET['error'])) { + if (isset($_GET['error'])) unset($_GET['error']); - } - if (isset($error)) { + if (isset($error)) unset($error); - } break; } } // If req_uri is empty or if it is a request for ourself, unset error. - if ( empty($request) || $req_uri == $self ) { - if (isset($_GET['error'])) { + if ( empty($request) || $req_uri == $self || strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) { + if (isset($_GET['error'])) unset($_GET['error']); - } - if (isset($error)) { + if (isset($error)) unset($error); - } + + if ( isset($query_vars) && strstr($_SERVER['PHP_SELF'], 'wp-admin/') ) + unset($query_vars); + + $this->did_permalink = false; } } @@ -1620,7 +1639,7 @@ class WP { // issue a 404 if one was already issued, if the request was a search, // or if the request was a regular query string request rather than a // permalink request. - if ( (0 == count($wp_query->posts)) && !is_404() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) { + if ( (0 == count($wp_query->posts)) && !is_404() && !is_category() && !is_search() && ( $this->did_permalink || (!empty($_SERVER['QUERY_STRING']) && (false === strpos($_SERVER['REQUEST_URI'], '?'))) ) ) { $wp_query->set_404(); status_header( 404 ); } elseif( is_404() != true ) { diff --git a/wp-inst/wp-includes/functions-formatting.php b/wp-inst/wp-includes/functions-formatting.php index 1352eeb..c179df2 100644 --- a/wp-inst/wp-includes/functions-formatting.php +++ b/wp-inst/wp-includes/functions-formatting.php @@ -392,9 +392,8 @@ function funky_javascript_fix($text) { */ function balanceTags($text, $is_comment = 0) { - if (get_settings('use_balanceTags') == 0) { + if ( get_option('use_balanceTags') == 0) return $text; - } $tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = ''; diff --git a/wp-inst/wp-includes/functions.php b/wp-inst/wp-includes/functions.php index aa2150f..a5ba06d 100644 --- a/wp-inst/wp-includes/functions.php +++ b/wp-inst/wp-includes/functions.php @@ -257,12 +257,19 @@ function url_to_postid($url) { } +function maybe_unserialize($original) { + if ( $gm = @ unserialize($original) ) + return $gm; + else + return $original; +} + /* Options functions */ function get_settings($setting) { - global $wpdb; + global $wpdb, $switched; - if ( defined('WP_INSTALLING') == false ) { + if ( $switched == false && defined('WP_INSTALLING') == false ) { $value = wp_cache_get($setting, 'options'); } else { $value = false; @@ -290,11 +297,8 @@ function get_settings($setting) { if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting ) $value = preg_replace('|/+$|', '', $value); - @ $kellogs = unserialize($value); - if ( $kellogs !== FALSE ) - return apply_filters('option_' . $setting, $kellogs); - else - return apply_filters('option_' . $setting, $value); + $value = stripslashes( $value ); + return apply_filters( 'option_' . $setting, maybe_unserialize($value) ); } function get_option($option) { @@ -332,9 +336,7 @@ function get_alloptions() { $option->option_value = preg_replace('|/+$|', '', $option->option_value); if ( 'category_base' == $option->option_name ) $option->option_value = preg_replace('|/+$|', '', $option->option_value); - @ $value = unserialize($option->option_value); - if ( $value === FALSE ) - $value = $option->option_value; + $value = maybe_unserialize($option->option_value); $all_options->{$option->option_name} = apply_filters('pre_option_' . $option->option_name, $value); } return apply_filters('all_options', $all_options); @@ -463,9 +465,9 @@ function get_post_meta($post_id, $key, $single = false) { if ( isset($post_meta_cache[$post_id][$key]) ) { if ( $single ) { - return $post_meta_cache[$post_id][$key][0]; + return maybe_unserialize( $post_meta_cache[$post_id][$key][0] ); } else { - return $post_meta_cache[$post_id][$key]; + return maybe_unserialize( $post_meta_cache[$post_id][$key][0] ); } } @@ -480,7 +482,7 @@ function get_post_meta($post_id, $key, $single = false) { if ( $single ) { if ( count($values) ) { - $return = $values[0]; + $return = maybe_unserialize( $values[0] ); } else { return ''; } @@ -488,10 +490,7 @@ function get_post_meta($post_id, $key, $single = false) { $return = $values; } - @ $kellogs = unserialize($return); - if ( $kellogs !== FALSE ) - return $kellogs; - else return $return; + return maybe_unserialize($return); } function update_post_meta($post_id, $key, $value, $prev_value = '') { @@ -589,6 +588,20 @@ function &get_post(&$post, $output = OBJECT) { } } +function set_page_path($page) { + $page->fullpath = '/' . $page->post_name; + $path = $page->fullpath; + $curpage = $page; + while ($curpage->post_parent != 0) { + $curpage = get_page($curpage->post_parent); + $path = '/' . $curpage->post_name . $path; + } + + $page->fullpath = $path; + + return $page; +} + // Retrieves page data given a page ID or page object. // Handles page caching. function &get_page(&$page, $output = OBJECT) { @@ -616,6 +629,11 @@ function &get_page(&$page, $output = OBJECT) { wp_cache_add($_page->ID, $_page, 'pages'); } } + + if (!isset($_page->fullpath)) { + $_page = set_page_path($_page); + wp_cache_replace($_page->cat_ID, $_page, 'pages'); + } if ( $output == OBJECT ) { return $_page; @@ -724,6 +742,17 @@ function get_all_category_ids() { return $cat_ids; } +function get_all_page_ids() { + global $wpdb; + + if ( ! $page_ids = wp_cache_get('all_page_ids', 'posts') ) { + $page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_status='static'"); + wp_cache_add('all_page_ids', $page_ids, 'pages'); + } + + return $page_ids; +} + function gzip_compression() { if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') ) return false; if ( !get_settings('gzipcompression') ) return false; @@ -1281,15 +1310,13 @@ function update_post_category_cache($post_ids) { if ( is_array($post_ids) ) $post_ids = implode(',', $post_ids); - $dogs = $wpdb->get_results("SELECT DISTINCT - post_id, cat_ID FROM $wpdb->categories, $wpdb->post2cat - WHERE category_id = cat_ID AND post_id IN ($post_ids)"); + $dogs = $wpdb->get_results("SELECT post_id, category_id FROM $wpdb->post2cat WHERE post_id IN ($post_ids)"); if ( empty($dogs) ) return; foreach ($dogs as $catt) - $category_cache[$catt->post_id][$catt->cat_ID] = &get_category($catt->cat_ID); + $category_cache[$catt->post_id][$catt->category_id] = &get_category($catt->category_id); } function update_post_caches(&$posts) { @@ -1304,25 +1331,13 @@ function update_post_caches(&$posts) { for ($i = 0; $i < count($posts); $i++) { $post_id_array[] = $posts[$i]->ID; $post_cache[$posts[$i]->ID] = &$posts[$i]; + $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count; } $post_id_list = implode(',', $post_id_array); update_post_category_cache($post_id_list); - // Do the same for comment numbers - $comment_counts = $wpdb->get_results( "SELECT ID as comment_post_ID, comment_count as ccount FROM $wpdb->posts WHERE ID in ($post_id_list)" ); - - if ( $comment_counts ) { - foreach ($comment_counts as $comment_count) { - $comment_count_cache["$comment_count->comment_post_ID"] = $comment_count->ccount; - $has_comments[] = $comment_count->comment_post_ID; - } - $no_comments = array_diff( $post_id_array, $has_comments ); - foreach ( $no_comments as $id ) - $comment_count_cache["$id"] = 0; - } - // Get post-meta info if ( $meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id IN($post_id_list) ORDER BY post_id, meta_key", ARRAY_A) ) { // Change from flat structure to hierarchical: @@ -2120,6 +2135,10 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) { if ( is_array($meta_value) || is_object($meta_value) ) $meta_value = serialize($meta_value); + $meta_value = trim( $meta_value ); + + if ( '' == $meta_value ) + return false; $cur = $wpdb->get_row("SELECT * FROM $wpdb->usermeta WHERE user_id = '$user_id' AND meta_key = '$meta_key'"); if ( !$cur ) { diff --git a/wp-inst/wp-includes/template-functions-post.php b/wp-inst/wp-includes/template-functions-post.php index e356aeb..be4d977 100644 --- a/wp-inst/wp-includes/template-functions-post.php +++ b/wp-inst/wp-includes/template-functions-post.php @@ -283,7 +283,6 @@ function &get_page_children($page_id, $pages) { $page_list = array_merge($page_list, $children); } } - return $page_list; } @@ -403,6 +402,9 @@ function _page_level_out($parent, $page_tree, $args, $depth = 0, $echo = true) { $indent = str_repeat("\t", $depth); //$indent = join('', array_fill(0,$depth,"\t")); + if ( !is_array($page_tree[$parent]['children']) ) + return false; + foreach ( $page_tree[$parent]['children'] as $page_id ) { $cur_page = $page_tree[$page_id]; $title = $cur_page['title']; diff --git a/wp-inst/wp-includes/vars.php b/wp-inst/wp-includes/vars.php index f61b969..53b8d4d 100644 --- a/wp-inst/wp-includes/vars.php +++ b/wp-inst/wp-includes/vars.php @@ -2,6 +2,9 @@ // On which page are we ? $PHP_SELF = $_SERVER['PHP_SELF']; +if ( empty($PHP_SELF) ) + $PHP_SELF = $_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-includes/wpmu-functions.php b/wp-inst/wp-includes/wpmu-functions.php index 88ea1e6..174e2c1 100644 --- a/wp-inst/wp-includes/wpmu-functions.php +++ b/wp-inst/wp-includes/wpmu-functions.php @@ -71,7 +71,7 @@ function wpmu_checkAvailableSpace($action) { add_filter('fileupload_init','wpmu_checkAvailableSpace'); function createBlog( $domain, $path, $username, $weblog_title, $admin_email, $source = 'regpage', $site_id = 1 ) { - global $wpdb, $table_prefix, $wp_queries, $wpmuBaseTablePrefix, $current_site, $wp_roles; + global $wpdb, $table_prefix, $wp_queries, $wpmuBaseTablePrefix, $current_site, $wp_roles, $new_user_id, $new_blog_id; $domain = addslashes( $domain ); $weblog_title = addslashes( $weblog_title ); @@ -81,7 +81,7 @@ function createBlog( $domain, $path, $username, $weblog_title, $admin_email, $so if( empty($path) ) $path = '/'; - $limited_email_domains = get_site_settings( 'limited_email_domains' ); + $limited_email_domains = get_site_option( 'limited_email_domains' ); if( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { $emaildomain = substr( $admin_email, 1 + strpos( $admin_email, '@' ) ); if( in_array( $emaildomain, $limited_email_domains ) == false ) { @@ -151,6 +151,7 @@ function createBlog( $domain, $path, $username, $weblog_title, $admin_email, $so $wpdb->options = $table_prefix . 'options'; $wpdb->postmeta = $table_prefix . 'postmeta'; $wp_roles->role_key = $table_prefix . 'user_roles'; + wp_cache_flush(); @mkdir( ABSPATH . "wp-content/blogs.dir/".$blog_id, 0777 ); @mkdir( ABSPATH . "wp-content/blogs.dir/".$blog_id."/files", 0777 ); @@ -200,6 +201,8 @@ function createBlog( $domain, $path, $username, $weblog_title, $admin_email, $so $GLOBALS['random_password'] = $random_password; $wpdb->query("INSERT INTO $wpdb->users (ID, user_login, user_pass, user_email, user_url, user_registered, display_name) VALUES ( NULL, '".$username."', MD5('$random_password'), '$admin_email', '$url', '$now_gmt', '$username' )"); $userID = $wpdb->insert_id; + $new_user_id = $userID; + $new_blog_id = $blog_id; $metavalues = array( 'user_nickname' => addslashes($username), $table_prefix . 'user_level' => 10, @@ -271,11 +274,6 @@ SITE_NAME" ) ); // Default comment $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) VALUES ('1', '".addslashes(__('Mr WordPress'))."', '', 'http://" . $current_site->domain . $current_site->path . "', '127.0.0.1', '$now', '$now_gmt', '".addslashes(__('Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.'))."')"); - $message_headers = 'From: ' . stripslashes($weblog_title) . ' <wordpress@' . $_SERVER[ 'SERVER_NAME' ] . '>'; - $message = $welcome_email; - if( empty( $current_site->site_name ) ) - $current_site->site_name = "WordPress MU"; - @mail($admin_email, __('New ' . $current_site->site_name . ' Blog').": ".stripslashes( $weblog_title ), $message, $message_headers); // remove all perms except for the login user. $wpdb->query( "DELETE FROM ".$wpdb->usermeta." WHERE user_id != '".$userID."' AND meta_key = '".$table_prefix."user_level'" ); @@ -285,6 +283,13 @@ SITE_NAME" ) ); do_action( "wpmu_new_blog", $blog_id, $userID ); + $welcome_email = apply_filters( "update_welcome_email", $welcome_email ); + $message_headers = 'From: ' . stripslashes($weblog_title) . ' <wordpress@' . $_SERVER[ 'SERVER_NAME' ] . '>'; + $message = $welcome_email; + if( empty( $current_site->site_name ) ) + $current_site->site_name = "WordPress MU"; + @mail($admin_email, __('New ' . $current_site->site_name . ' Blog').": ".stripslashes( $weblog_title ), $message, $message_headers); + // restore wpdb variables reset( $tmp ); while( list( $key, $val ) = each( $tmp ) ) @@ -295,6 +300,7 @@ SITE_NAME" ) ); $wp_roles->role_key = $tmprolekey; $wpdb->show_errors(); + wp_cache_flush(); return "ok"; } @@ -389,142 +395,129 @@ function get_user_details( $username ) { function get_blog_details( $id ) { global $wpdb, $wpmuBaseTablePrefix; + $cache = wpmu_get_cache( $id, "blog-details" ); + if( is_array( $cache ) && ( time() - $cache[ 'time' ] ) < 300 ) { // cache for 300 seconds + $row = $cache[ 'value' ]; + } else { + $row = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE blog_id = '$id'" ); + $name = $wpdb->get_row( "SELECT * FROM {$wpmuBaseTablePrefix}{$id}_options WHERE option_name = 'blogname'" ); + $row->blogname = $name->option_value; + $row->siteurl = $wpdb->get_var( "SELECT option_value FROM {$wpmuBaseTablePrefix}{$id}_options WHERE option_name = 'siteurl'" ); + wpmu_update_cache( $id, $row, "blog-details" ); + } - $row = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE blog_id = '$id'" ); - $name = $wpdb->get_row( "SELECT * FROM {$wpmuBaseTablePrefix}{$id}_options WHERE option_name = 'blogname'" ); - $row->blogname = $name->option_value; - $row->siteurl = $wpdb->get_var( "SELECT option_value FROM {$wpmuBaseTablePrefix}{$id}_options WHERE option_name = 'siteurl'" ); return $row; } function get_current_user_id() { - global $wpdb; - - $cookie_user_login = $_COOKIE[USER_COOKIE]; - $user_login = sanitize_user( $cookie_user_login ); - return $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_login = '$user_login'" ); + global $current_user; + return $current_user->data->ID; } -function is_site_admin( $user_login = '0' ) { +function is_site_admin( $user_login = false ) { global $wpdb, $current_user; - if( is_object( $current_user ) == false && $user_login == 0 ) { - $cookie_user_login = $_COOKIE[USER_COOKIE]; - $user_login = sanitize_user( $cookie_user_login ); - } elseif( $user_login == '0' ) { - $user_id = $current_user->data->ID; - $user_login = $wpdb->get_var( "SELECT user_login FROM " . $wpdb->users . " WHERE ID = '" . $user_id . "'" ); - } else { - $user_id = $wpdb->get_var( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = '" . $user_login . "'" ); - } + if ( !$current_user && !$user_login ) + return false; - $ret = true; + if ( $user_login ) + $user_login = sanitize_user( $user_login ); + else + $user_login = $current_user->data->user_login; - $super_users = get_site_option( "super_users", "admin" ); - $t = split( " ", $super_users ); - if( is_array( $t ) ) { - if( in_array( $user_login, $t ) == false ) { - if( $wpdb->get_var( "SELECT site_id FROM $wpdb->sitemeta WHERE site_id = '$wpdb->siteid' AND meta_key = 'admin_user_id' AND meta_value = '$user_id'" ) == false ) { - $ret = false; - } - } - } + $site_admins = get_site_option( 'site_admins', array('admin') ); + if( in_array( $user_login, $site_admins ) ) + return true; - return $ret; + return false; } -function get_site_settings( $option, $default='na' ) { - global $wpdb; +function get_site_option( $option, $default = false ) { + global $wpdb; - $query = "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key = '$option' AND site_id = '".$wpdb->siteid."'"; - $option = $wpdb->get_row( $query ); - if( $option == false ) { - if( $default != 'na' ) { - return $default; - } else { - return false; - } - } else { - @ $kellogs = unserialize($option->meta_value); - if ($kellogs !== FALSE) { - $meta_value = $kellogs; - } else { - $meta_value = $option->meta_value; - } - return $meta_value; - } -} + $value = wp_cache_get($option, 'site-options'); -function get_site_option( $option, $default='na' ) { - return get_site_settings( $option, $default ); -} + if ( false === $value ) { + $cache = wpmu_get_cache( $option, "site_options" ); + if( is_array( $cache ) && ( time() - $cache[ 'time' ] ) < 300 ) { // cache for 300 seconds + $value = $cache[ 'value' ]; + } else { + $value = $wpdb->get_var("SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = '$option' AND site_id = '$wpdb->siteid'"); + } + if ( $value ) { + wpmu_update_cache( $option, $value, "site_options" ); + wp_cache_set($option, $value, 'site-options'); + } else { + if ( $default ) + return $default; + return false; + } + } -function add_site_settings( $key, $value ) { - global $wpdb; - if( $value != get_site_settings( $key ) ) { - if ( is_array($value) || is_object($value) ) - $value = serialize($value); - $query = "SELECT meta_value - FROM ".$wpdb->sitemeta." - WHERE meta_key = '$key' - AND site_id = '".$wpdb->siteid."'"; - if( $wpdb->get_row( $query ) == false ) { - $query = "INSERT INTO $wpdb->sitemeta ( meta_id , site_id , meta_key , meta_value ) - VALUES ( NULL, '".$wpdb->siteid."', '".$key."', '".$wpdb->escape( $value )."')"; - $wpdb->query( $query ); - } - } + $value = stripslashes( $value ); + @ $kellogs = unserialize($value); + if ( $kellogs !== FALSE ) + return $kellogs; + else + return $value; } function add_site_option( $key, $value ) { - return add_site_settings( $key, $value ); -} + global $wpdb; -function update_site_settings( $key, $value ) { - global $wpdb; - if( $value != get_site_settings( $key ) ) { - if ( is_array($value) || is_object($value) ) - $value = serialize($value); + if ( get_site_option( $key ) ) // If we already have it + return false; - $value = trim($value); // I can't think of any situation we wouldn't want to trim - $query = "SELECT meta_key, meta_value - FROM ".$wpdb->sitemeta." - WHERE meta_key = '$key' - AND site_id = '".$wpdb->siteid."'"; - if( $wpdb->get_row( $query ) == false ) { - add_site_option( $key, $value ); - } else { - $query = "UPDATE ".$wpdb->sitemeta." - SET meta_value = '".$wpdb->escape( $value )."' - WHERE meta_key = '".$key."'"; - $wpdb->query( $query ); - } - } + if ( is_array($value) || is_object($value) ) + $value = serialize($value); + $value = $wpdb->escape( $value ); + $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id , meta_key , meta_value ) VALUES ( '$wpdb->siteid', '$key', '$value')" ); + return $wpdb->insert_id; } function update_site_option( $key, $value ) { - return update_site_settings( $key, $value ); + global $wpdb; + + if ( $value == get_site_option( $key ) ) + return; + + if ( is_array($value) || is_object($value) ) + $value = serialize($value); + $value = $wpdb->escape( $value ); + + if ( !get_site_option( $key ) ) + add_site_option( $key, $value ); + + $wpdb->query( "UPDATE $wpdb->sitemeta SET meta_value = '".$wpdb->escape( $value )."' WHERE meta_key = '$key'" ); + wpmu_update_cache( $key, $value, "site_options" ); } function get_blog_option( $blog_id, $key, $default='na' ) { global $wpdb, $wpmuBaseTablePrefix; - - $option = $wpdb->get_row( "SELECT option_value FROM {$wpmuBaseTablePrefix}{$blog_id}_options WHERE option_name = '$key'" ); - if( $option == false ) { - if( $default != 'na' ) { - return $default; - } else { - return false; - } + $cache = wpmu_get_cache( $blog_id."-".$key, "get_blog_option" ); + if( is_array( $cache ) && ( time() - $cache[ 'time' ] ) < 30 ) { + $opt = $cache[ 'value' ]; } else { - @ $kellogs = unserialize($option->option_value); - if ($kellogs !== FALSE) { - $option_value = $kellogs; + $option = $wpdb->get_row( "SELECT option_value FROM {$wpmuBaseTablePrefix}{$blog_id}_options WHERE option_name = '$key'" ); + if( $option == false ) { + if( $default != 'na' ) { + $opt = $default; + } else { + $opt = false; + } } else { - $option_value = $option->option_value; + @ $kellogs = unserialize($option->option_value); + if ($kellogs !== FALSE) { + $option_value = $kellogs; + } else { + $option_value = $option->option_value; + } + $opt = $option_value; } - return $option_value; + wpmu_update_cache( $blog_id."-".$key, $opt, "get_blog_option" ); } + + return $opt; } function add_blog_option( $blog_id, $key, $value ) { @@ -560,8 +553,8 @@ function update_blog_option( $blog_id, $key, $value ) { } } -function switch_to_blog( $blog_id ) { - global $tmpoldblogdetails, $wpdb, $wpmuBaseTablePrefix, $cache_settings, $category_cache, $cache_categories, $post_cache; +function switch_to_blog( $new_blog ) { + global $tmpoldblogdetails, $wpdb, $wpmuBaseTablePrefix, $cache_settings, $category_cache, $cache_categories, $post_cache, $wp_object_cache, $blog_id, $switched; // FIXME @@ -581,10 +574,12 @@ function switch_to_blog( $blog_id ) { $tmpoldblogdetails[ 'cache_categories' ] = $cache_categories; $tmpoldblogdetails[ 'table_prefix' ] = $table_prefix; $tmpoldblogdetails[ 'post_cache' ] = $post_cache; + $tmpoldblogdetails[ 'wp_object_cache' ] = $wp_object_cache; + $tmpoldblogdetails[ 'blog_id' ] = $blog_id; // fix the new prefix. - $table_prefix = $wpmuBaseTablePrefix . $blog_id . "_"; - $wpdb->blogid = $blog_id; + $table_prefix = $wpmuBaseTablePrefix . $new_blog . "_"; + $wpdb->blogid = $new_blog; $wpdb->posts = $table_prefix . 'posts'; $wpdb->categories = $table_prefix . 'categories'; $wpdb->post2cat = $table_prefix . 'post2cat'; @@ -593,16 +588,21 @@ function switch_to_blog( $blog_id ) { $wpdb->linkcategories = $table_prefix . 'linkcategories'; $wpdb->options = $table_prefix . 'options'; $wpdb->postmeta = $table_prefix . 'postmeta'; + $blog_id = $new_blog; $cache_settings = array(); unset( $cache_settings ); unset( $category_cache ); unset( $cache_categories ); unset( $post_cache ); + unset( $wp_object_cache ); + $wp_object_cache = new WP_Object_Cache(); + $wp_object_cache->cache_enabled = false; + $switched = true; } function restore_current_blog() { - global $table_prefix, $tmpoldblogdetails, $wpdb, $wpmuBaseTablePrefix, $cache_settings, $category_cache, $cache_categories, $post_cache; + global $table_prefix, $tmpoldblogdetails, $wpdb, $wpmuBaseTablePrefix, $cache_settings, $category_cache, $cache_categories, $post_cache, $wp_object_cache, $blog_id, $switched; // backup $wpdb->blogid = $tmpoldblogdetails[ 'blogid' ]; $wpdb->posts = $tmpoldblogdetails[ 'posts' ]; @@ -618,7 +618,12 @@ function restore_current_blog() { $category_cache = $tmpoldblogdetails[ 'category_cache' ]; $cache_categories = $tmpoldblogdetails[ 'cache_categories' ]; $table_prefix = $tmpoldblogdetails[ 'table_prefix' ]; - $post_cache = $tmpoldblogdetails[ 'post_cache' ]; + $post_cache = $tmpoldblogdetails[ 'post_cache' ]; + $wp_object_cache = $tmpoldblogdetails[ 'wp_object_cache' ]; + $blog_id = $tmpoldblogdetails[ 'blog_id' ]; + unset( $tmpoldblogdetails ); + $wp_object_cache->cache_enabled = true; + $switched = false; } function get_users_of_blog( $id ) { @@ -648,6 +653,18 @@ function update_archived( $id, $archived ) { return $archived; } +function update_blog_status( $id, $pref, $value ) { + global $wpdb; + $wpdb->query( "UPDATE {$wpdb->blogs} SET {$pref} = '{$value}' WHERE blog_id = '$id'" ); + + return $value; +} + +function get_blog_status( $id, $pref ) { + global $wpdb; + return $wpdb->get_var( "SELECT $pref FROM {$wpdb->blogs} WHERE blog_id = '$id'" ); +} + function get_last_updated( $display = false ) { global $wpdb; $blogs = $wpdb->get_results( "SELECT blog_id domain, path FROM $wpdb->blogs WHERE site_id = '$wpdb->siteid' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit 0,40", ARRAY_A ); @@ -762,8 +779,17 @@ function get_blog_count( $id = 0 ) { function get_blog_post( $blog_id, $post_id ) { global $wpdb, $wpmuBaseTablePrefix; + + $cache = wpmu_get_cache( $blog_id."-".$post_id, "get_blog_post" ); + if( is_array( $cache ) && ( time() - $cache[ 'time' ] ) < 10 ) { + $post = $cache[ 'value' ]; + } else { + $post = $wpdb->get_row( "SELECT * FROM {$wpmuBaseTablePrefix}{$blog_id}_posts WHERE ID = '{$post_id}'" ); + wpmu_update_cache( $blog_id."-".$post_id, $post, "get_blog_post" ); + } + + return $post; - return $wpdb->get_row( "SELECT * FROM {$wpmuBaseTablePrefix}{$blog_id}_posts WHERE ID = '{$post_id}'" ); } function add_user_to_blog( $blog_id, $user_id, $role ) { @@ -776,9 +802,45 @@ function add_user_to_blog( $blog_id, $user_id, $role ) { function get_blog_permalink( $blog_id, $post_id ) { global $wpdb, $cache_settings; - switch_to_blog( $blog_id ); - $link = get_permalink( $post_id ); - restore_current_blog(); + + $cache = wpmu_get_cache( $blog_id."-".$post_id, "permalink" ); + if( is_array( $cache ) && ( time() - $cache[ 'time' ] ) < 30 ) { // cache for 30 seconds + $link = $cache[ 'value' ]; + } else { + switch_to_blog( $blog_id ); + $link = get_permalink( $post_id ); + restore_current_blog(); + wpmu_update_cache( $blog_id."-".$post_id, $link, "permalink" ); + } return $link; } +function wpmu_update_cache( $key, $value, $path ) { + if( defined( "WPMU_CACHE_PATH" ) ) { + @mkdir( CONSTANT( "WPMU_CACHE_PATH" ) . "/$path/", 0700 ); + @mkdir( CONSTANT( "WPMU_CACHE_PATH" ) . "/$path/temp/", 0700 ); + $cache_path = CONSTANT( "WPMU_CACHE_PATH" ) . "/$path/" . md5( $key ); + $tmpfname = tempnam( CONSTANT( "WPMU_CACHE_PATH" ) . "/$path/temp/", "tempname"); + $handle = fopen($tmpfname, "w"); + $cache = array( "value" => $value, "time" => time() ); + fwrite( $handle, serialize( $cache ) ); + fclose($handle); + if( file_exists( $cache_path ) ) + @unlink( $cache_path ); + rename( $tmpfname, $cache_path ); + } +} + +function wpmu_get_cache( $key, $path ) { + if( defined( "WPMU_CACHE_PATH" ) ) { + $cache_path = CONSTANT( "WPMU_CACHE_PATH" ) . "/$path/" . md5( $key ); + if ( @file_exists( $cache_path ) ) { + $cache = unserialize( @file_get_contents( $cache_path ) ); + return $cache; + } else { + return false; + } + } else { + return false; + } +} ?> diff --git a/wp-inst/wp-rss2.php b/wp-inst/wp-rss2.php index 4fc9150..8f42aca 100644 --- a/wp-inst/wp-rss2.php +++ b/wp-inst/wp-rss2.php @@ -36,7 +36,7 @@ $more = 1; <dc:creator><?php the_author() ?></dc:creator> <?php the_category_rss() ?> - <guid><?php the_permalink($id); ?></guid> + <guid isPermaLink="false"><?php the_guid(); ?></guid> <?php if (get_settings('rss_use_excerpt')) : ?> <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> <?php else : ?> |