summaryrefslogtreecommitdiffstats
path: root/wp-admin/includes
diff options
context:
space:
mode:
Diffstat (limited to 'wp-admin/includes')
-rw-r--r--wp-admin/includes/admin.php4
-rw-r--r--wp-admin/includes/bookmark.php8
-rw-r--r--wp-admin/includes/class-ftp.php2
-rw-r--r--wp-admin/includes/class-pclzip.php4
-rw-r--r--wp-admin/includes/class-wp-filesystem-direct.php4
-rw-r--r--wp-admin/includes/class-wp-filesystem-ftpext.php103
-rw-r--r--wp-admin/includes/class-wp-filesystem-ftpsockets.php90
-rw-r--r--wp-admin/includes/comment.php34
-rw-r--r--wp-admin/includes/dashboard.php30
-rw-r--r--wp-admin/includes/export.php8
-rw-r--r--wp-admin/includes/file.php185
-rw-r--r--wp-admin/includes/image.php346
-rw-r--r--wp-admin/includes/import.php4
-rw-r--r--wp-admin/includes/media.php186
-rw-r--r--wp-admin/includes/misc.php80
-rw-r--r--wp-admin/includes/mu.php174
-rw-r--r--wp-admin/includes/plugin.php120
-rw-r--r--wp-admin/includes/post.php270
-rw-r--r--wp-admin/includes/schema.php66
-rw-r--r--wp-admin/includes/taxonomy.php37
-rw-r--r--wp-admin/includes/template.php804
-rw-r--r--wp-admin/includes/theme.php1
-rw-r--r--wp-admin/includes/update.php148
-rw-r--r--wp-admin/includes/upgrade.php29
-rw-r--r--wp-admin/includes/user.php141
-rw-r--r--wp-admin/includes/widgets.php39
26 files changed, 2206 insertions, 711 deletions
diff --git a/wp-admin/includes/admin.php b/wp-admin/includes/admin.php
index 04a4bc1..7f1c12c 100644
--- a/wp-admin/includes/admin.php
+++ b/wp-admin/includes/admin.php
@@ -1,9 +1,13 @@
<?php
+if ( !defined( 'AUTOSAVE_INTERVAL' ) )
+ define( 'AUTOSAVE_INTERVAL', 60 );
+
require_once(ABSPATH . 'wp-admin/includes/bookmark.php');
require_once(ABSPATH . 'wp-admin/includes/comment.php');
require_once(ABSPATH . 'wp-admin/includes/file.php');
require_once(ABSPATH . 'wp-admin/includes/image.php');
+require_once(ABSPATH . 'wp-admin/includes/media.php');
require_once(ABSPATH . 'wp-admin/includes/import.php');
require_once(ABSPATH . 'wp-admin/includes/misc.php');
require_once(ABSPATH . 'wp-admin/includes/plugin.php');
diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php
index 35cc9c9..2cae3b5 100644
--- a/wp-admin/includes/bookmark.php
+++ b/wp-admin/includes/bookmark.php
@@ -13,6 +13,8 @@ function edit_link( $link_id = '' ) {
$_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
$_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
$_POST['link_rss'] = clean_url($_POST['link_rss']);
+ if ( 'N' != $_POST['link_visible'] )
+ $_POST['link_visible'] = 'Y';
if ( !empty( $link_id ) ) {
$_POST['link_id'] = $link_id;
@@ -60,7 +62,7 @@ function wp_get_link_cats($link_id = 0) {
}
function get_link_to_edit( $link_id ) {
- return get_link( $link_id, OBJECT, 'edit' );
+ return get_bookmark( $link_id, OBJECT, 'edit' );
}
function wp_insert_link($linkdata) {
@@ -151,8 +153,6 @@ function wp_set_link_cats($link_id = 0, $link_categories = array()) {
} // wp_set_link_cats()
function wp_update_link($linkdata) {
- global $wpdb;
-
$link_id = (int) $linkdata['link_id'];
$link = get_link($link_id, ARRAY_A);
@@ -174,4 +174,4 @@ function wp_update_link($linkdata) {
return wp_insert_link($linkdata);
}
-?> \ No newline at end of file
+?>
diff --git a/wp-admin/includes/class-ftp.php b/wp-admin/includes/class-ftp.php
index bc2720a..c10526b 100644
--- a/wp-admin/includes/class-ftp.php
+++ b/wp-admin/includes/class-ftp.php
@@ -317,7 +317,7 @@ class ftp_base {
function pwd() {
if(!$this->_exec("PWD", "pwd")) return FALSE;
if(!$this->_checkCode()) return FALSE;
- return ereg_replace("^[0-9]{3} \"(.+)\" .+".CRLF, "\\1", $this->_message);
+ return ereg_replace("^[0-9]{3} \"(.+)\".+", "\\1", $this->_message);
}
function cdup() {
diff --git a/wp-admin/includes/class-pclzip.php b/wp-admin/includes/class-pclzip.php
index d387f00..b490744 100644
--- a/wp-admin/includes/class-pclzip.php
+++ b/wp-admin/includes/class-pclzip.php
@@ -4470,7 +4470,9 @@
$v_byte = @fread($this->zip_fd, 1);
// ----- Add the byte
- $v_bytes = ($v_bytes << 8) | Ord($v_byte);
+ // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
+ // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
+ $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
// ----- Compare the bytes
if ($v_bytes == 0x504b0506)
diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php
index d698b20..dc74f52 100644
--- a/wp-admin/includes/class-wp-filesystem-direct.php
+++ b/wp-admin/includes/class-wp-filesystem-direct.php
@@ -8,7 +8,7 @@ class WP_Filesystem_Direct{
$this->permission = umask();
}
function connect(){
- return;
+ return true;
}
function setDefaultPermissions($perm){
$this->permission = $perm;
@@ -17,7 +17,7 @@ class WP_Filesystem_Direct{
return str_replace('\\','/',ABSPATH);
}
function get_base_dir($base = '.', $echo = false){
- return find_base_dir($base, $echo);
+ return $this->find_base_dir($base, $echo);
}
function get_contents($file){
return @file_get_contents($file);
diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php
index a8a3585..32ccd07 100644
--- a/wp-admin/includes/class-wp-filesystem-ftpext.php
+++ b/wp-admin/includes/class-wp-filesystem-ftpext.php
@@ -84,48 +84,67 @@ class WP_Filesystem_FTPext{
$this->permission = $perm;
}
- function find_base_dir($base = '.',$echo = false){
+ function find_base_dir($base = '.',$echo = false, $loop = false) {
+ //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
$abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..
if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )
$abspath = $mat[1];
}
+ //Set up the base directory (Which unless specified, is the current one)
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
- if( empty( $base ) ) $base = '/';
- if( '/' != substr($base, -1) ) $base .= '/';
-
- if($echo) echo __('Changing to ') . $base .'<br>';
- if( false === $this->chdir($base) )
- return false;
-
- if( $this->exists($base . 'wp-settings.php') ){
- if($echo) echo __('Found ') . $base . 'wp-settings.php<br>';
- $this->wp_base = $base;
- return $this->wp_base;
+ $base = trailingslashit($base);
+
+ //Can we see the Current directory as part of the ABSPATH?
+ $location = strpos($abspath, $base);
+ if( false !== $location ) {
+ $newbase = path_join($base, substr($abspath, $location + strlen($base)));
+
+ if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
+ if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
+ //Check to see if it exists in that folder.
+ if( $this->exists($newbase . 'wp-settings.php') ){
+ if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
+ return $newbase;
+ }
+ }
}
-
- if( strpos($abspath, $base) > 0)
- $arrPath = split('/',substr($abspath,strpos($abspath, $base)));
- else
- $arrPath = split('/',$abspath);
-
- for($i = 0; $i <= count($arrPath); $i++)
- if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] );
-
- foreach($arrPath as $key=>$folder){
- if( $this->is_dir($base . $folder) ){
- if($echo) echo __('Found ') . $folder . ' ' . __('Changing to') . ' ' . $base . $folder . '/<br>';
- return $this->find_base_dir($base . $folder . '/',$echo);
+
+ //Ok, Couldnt do a magic location from that particular folder level
+
+ //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
+ $files = $this->dirlist($base);
+
+ $arrPath = explode('/', $abspath);
+ foreach($arrPath as $key){
+ //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
+ // If its found, change into it and follow through looking for it.
+ // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
+ // If it reaches the end, and still cant find it, it'll return false for the entire function.
+ if( isset($files[ $key ]) ){
+ //Lets try that folder:
+ $folder = path_join($base, $key);
+ if($echo) printf( __('Changing to %s') . '<br/>', $folder );
+ $ret = $this->find_base_dir( $folder, $echo, $loop);
+ if( $ret )
+ return $ret;
}
}
-
- if( $base == '/' )
- return false;
- //If we get this far, somethings gone wrong, change to / and restart the process.
- return $this->find_base_dir('/',$echo);
+ //Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
+ if(isset( $files[ 'wp-settings.php' ]) ){
+ if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
+ return $base;
+ }
+ if( $loop )
+ return false;//Prevent tihs function looping again.
+ //As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
+ return $this->find_base_dir('/', $echo, true);
}
- function get_base_dir($base = '.', $echo=false){
+
+ function get_base_dir($base = '.', $echo = false){
+ if( defined('FTP_BASE') )
+ $this->wp_base = FTP_BASE;
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base,$echo);
return $this->wp_base;
@@ -136,6 +155,8 @@ class WP_Filesystem_FTPext{
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
}
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
if( ! @ftp_fget($this->link,$temp,$file,$type,$resumepos) )
return false;
fseek($temp, 0); //Skip back to the start of the file being written to
@@ -151,10 +172,12 @@ class WP_Filesystem_FTPext{
}
function put_contents($file,$contents,$type=''){
if( empty($type) ){
- $extension = substr(strrchr($filename, "."), 1);
+ $extension = substr(strrchr($file, "."), 1);
$type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII;
}
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
fwrite($temp,$contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$ret = @ftp_fput($this->link,$file,$temp,$type);
@@ -162,7 +185,10 @@ class WP_Filesystem_FTPext{
return $ret;
}
function cwd(){
- return ftp_pwd($this->link);
+ $cwd = ftp_pwd($this->link);
+ if( $cwd )
+ $cwd = trailingslashit($cwd);
+ return $cwd;
}
function chdir($dir){
return @ftp_chdir($dir);
@@ -308,8 +334,9 @@ class WP_Filesystem_FTPext{
}
function is_dir($path){
$cwd = $this->cwd();
- @ftp_chdir($this->link, $path);
- if ( $this->cwd() != $cwd ) {
+ $result = @ftp_chdir($this->link, $path);
+ if( $result && $path == $this->cwd() ||
+ $this->cwd() != $cwd ) {
@ftp_chdir($this->link, $cwd);
return true;
}
@@ -425,9 +452,9 @@ class WP_Filesystem_FTPext{
} else {
$limitFile = false;
}
- //if( ! $this->is_dir($path) )
- // return false;
- $list = ftp_rawlist($this->link , '-a ' . $path, false);
+
+ $list = @ftp_rawlist($this->link , '-a ' . $path, false);
+
if ( $list === false )
return false;
diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php
index 15ab390..5365623 100644
--- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php
+++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php
@@ -86,49 +86,67 @@ class WP_Filesystem_ftpsockets{
$this->permission = $perm;
}
- function find_base_dir($base = '.',$echo = false) {
+ function find_base_dir($base = '.',$echo = false, $loop = false) {
+ //Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
$abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..
if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter
if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )
$abspath = $mat[1];
}
+ //Set up the base directory (Which unless specified, is the current one)
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
- if( empty( $base ) ) $base = '/';
- if( '/' != substr($base, -1) ) $base .= '/';
-
- if($echo) echo __('Changing to ') . $base .'<br>';
- if( false === $this->chdir($base) )
- return false;
-
- if( $this->exists($base . 'wp-settings.php') ){
- if($echo) echo __('Found ') . $base . 'wp-settings.php<br>';
- $this->wp_base = $base;
- return $this->wp_base;
+ $base = trailingslashit($base);
+
+ //Can we see the Current directory as part of the ABSPATH?
+ $location = strpos($abspath, $base);
+ if( false !== $location ) {
+ $newbase = path_join($base, substr($abspath, $location + strlen($base)));
+
+ if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
+ if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
+ //Check to see if it exists in that folder.
+ if( $this->exists($newbase . 'wp-settings.php') ){
+ if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
+ return $newbase;
+ }
+ }
}
-
- if( strpos($abspath, $base) > 0)
- $arrPath = split('/',substr($abspath,strpos($abspath, $base)));
- else
- $arrPath = split('/',$abspath);
-
- for($i = 0; $i <= count($arrPath); $i++)
- if( $arrPath[ $i ] == '' ) unset( $arrPath[ $i ] );
-
- foreach($arrPath as $key=>$folder){
- if( $this->is_dir($base . $folder) ){
- if($echo) echo __('Found ') . $folder . ' ' . __('Changing to') . ' ' . $base . $folder . '/<br>';
- return $this->find_base_dir($base . $folder . '/',$echo);
+
+ //Ok, Couldnt do a magic location from that particular folder level
+
+ //Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
+ $files = $this->dirlist($base);
+
+ $arrPath = explode('/', $abspath);
+ foreach($arrPath as $key){
+ //Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
+ // If its found, change into it and follow through looking for it.
+ // If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
+ // If it reaches the end, and still cant find it, it'll return false for the entire function.
+ if( isset($files[ $key ]) ){
+ //Lets try that folder:
+ $folder = path_join($base, $key);
+ if($echo) printf( __('Changing to %s') . '<br/>', $folder );
+ $ret = $this->find_base_dir( $folder, $echo, $loop);
+ if( $ret )
+ return $ret;
}
}
-
- if( $base == '/' )
- return false;
- //If we get this far, somethings gone wrong, change to / and restart the process.
- return $this->find_base_dir('/',$echo);
+ //Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
+ if(isset( $files[ 'wp-settings.php' ]) ){
+ if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
+ return $base;
+ }
+ if( $loop )
+ return false;//Prevent tihs function looping again.
+ //As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
+ return $this->find_base_dir('/', $echo, true);
}
function get_base_dir($base = '.', $echo = false){
+ if( defined('FTP_BASE') )
+ $this->wp_base = FTP_BASE;
if( empty($this->wp_base) )
$this->wp_base = $this->find_base_dir($base, $echo);
return $this->wp_base;
@@ -144,6 +162,8 @@ class WP_Filesystem_ftpsockets{
}
$this->ftp->SetType($type);
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
if ( ! $this->ftp->fget($temp, $file) ) {
fclose($temp);
return ''; //Blank document, File does exist, Its just blank.
@@ -168,6 +188,8 @@ class WP_Filesystem_ftpsockets{
$this->ftp->SetType($type);
$temp = tmpfile();
+ if ( ! $temp )
+ return false;
fwrite($temp,$contents);
fseek($temp, 0); //Skip back to the start of the file being written to
$ret = $this->ftp->fput($file, $temp);
@@ -176,7 +198,10 @@ class WP_Filesystem_ftpsockets{
}
function cwd(){
- return $this->ftp->pwd();
+ $cwd = $this->ftp->pwd();
+ if( $cwd )
+ $cwd = trailingslashit($cwd);
+ return $cwd;
}
function chdir($file){
@@ -388,8 +413,7 @@ class WP_Filesystem_ftpsockets{
} else {
$limitFile = false;
}
- //if( ! $this->is_dir($path) )
- // return false;
+
$list = $this->ftp->dirlist($path);
if( ! $list )
return false;
diff --git a/wp-admin/includes/comment.php b/wp-admin/includes/comment.php
index ae0d1d9..e08ae4d 100644
--- a/wp-admin/includes/comment.php
+++ b/wp-admin/includes/comment.php
@@ -8,9 +8,7 @@ function comment_exists($comment_author, $comment_date) {
}
function edit_comment() {
- global $user_ID;
- $comment_ID = (int) $_POST['comment_ID'];
$comment_post_ID = (int) $_POST['comment_post_ID'];
if (!current_user_can( 'edit_post', $comment_post_ID ))
@@ -23,6 +21,14 @@ function edit_comment() {
$_POST['comment_content'] = $_POST['content'];
$_POST['comment_ID'] = (int) $_POST['comment_ID'];
+ foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
+ if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
+ $_POST['edit_date'] = '1';
+ break;
+ }
+ }
+
+
if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
@@ -65,4 +71,26 @@ function get_pending_comments_num( $post_id ) {
return $pending;
}
-?> \ No newline at end of file
+// Add avatars to relevant places in admin, or try to
+
+function floated_admin_avatar( $name ) {
+ global $comment;
+
+ $id = $avatar = false;
+ if ( $comment->comment_author_email )
+ $id = $comment->comment_author_email;
+ if ( $comment->user_id )
+ $id = $comment->user_id;
+
+ if ( $id )
+ $avatar = get_avatar( $id, 32 );
+
+ return "$avatar $name";
+}
+
+if ( is_admin() && ('edit-comments.php' == $pagenow || 'edit.php' == $pagenow) ) {
+ if ( get_option('show_avatars') )
+ add_filter( 'comment_author', 'floated_admin_avatar' );
+}
+
+?>
diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php
index c675c4d..72a6dbc 100644
--- a/wp-admin/includes/dashboard.php
+++ b/wp-admin/includes/dashboard.php
@@ -24,7 +24,7 @@ function wp_dashboard_setup() {
// Recent Comments Widget
if ( current_user_can( 'moderate_comments' ) && $mod_comments = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'") ) {
$notice = sprintf( __ngettext( '%d comment awaiting moderation', '%d comments awaiting moderation', $mod_comments ), $mod_comments );
- $notice = "<a href='moderation.php'>$notice</a>";
+ $notice = "<a href='edit-comments.php?comment_status=moderated'>$notice</a>";
} else {
$notice = '';
}
@@ -62,8 +62,8 @@ function wp_dashboard_setup() {
if ( !isset( $widget_options['dashboard_primary'] ) ) {
$update = true;
$widget_options['dashboard_primary'] = array(
- 'link' => apply_filters( 'dashboard_primary_link', 'http://wordpress.org/development/' ),
- 'url' => apply_filters( 'dashboard_primary_feed', 'http://wordpress.org/development/feed/' ),
+ 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/development/' ) ),
+ 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/development/feed/' ) ),
'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Development Blog' ) ),
'items' => 2,
'show_summary' => 1,
@@ -84,8 +84,8 @@ function wp_dashboard_setup() {
if ( !isset( $widget_options['dashboard_secondary'] ) ) {
$update = true;
$widget_options['dashboard_secondary'] = array(
- 'link' => apply_filters( 'dashboard_secondary_link', 'http://planet.wordpress.org/' ),
- 'url' => apply_filters( 'dashboard_secondary_feed', 'http://planet.wordpress.org/feed/' ),
+ 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
+ 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
'items' => 15
);
@@ -144,7 +144,7 @@ function wp_dashboard_setup() {
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
ob_start(); // hack - but the same hack wp-admin/widgets.php uses
- wp_dashbaord_trigger_widget_control( $_POST['widget_id'] );
+ wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
ob_end_clean();
wp_redirect( remove_query_arg( 'edit' ) );
exit;
@@ -212,7 +212,7 @@ function wp_dashboard_dynamic_sidebar_params( $params ) {
$content_class .= ' dashboard-widget-control';
$wp_registered_widgets[$widget_id]['callback'] = 'wp_dashboard_empty';
$sidebar_widget_name = $wp_registered_widget_controls[$widget_id]['name'];
- $params[1] = 'wp_dashbaord_trigger_widget_control';
+ $params[1] = 'wp_dashboard_trigger_widget_control';
$sidebar_before_widget .= '<form action="' . remove_query_arg( 'edit' ) . '" method="post">';
$sidebar_after_widget = "<div class='dashboard-widget-submit'><input type='hidden' name='sidebar' value='wp_dashboard' /><input type='hidden' name='widget_id' value='$widget_id' /><input type='submit' value='" . __( 'Save' ) . "' /></div></form>$sidebar_after_widget";
$links[] = '<a href="' . remove_query_arg( 'edit' ) . '">' . __( 'Cancel' ) . '</a>';
@@ -284,21 +284,23 @@ function wp_dashboard_recent_comments( $sidebar_args ) {
?>
<blockquote><p>&#8220;<?php comment_excerpt(); ?>&#8221;</p></blockquote>
<p class='comment-meta'><?php echo $comment_meta; ?></p>
-
+<?php
+ if ( $comments_query->comment_count > 1 ) : ?>
<ul id="dashboard-comments-list">
<?php
- else :
+ endif; // comment_count
+ else : // is_first
?>
<li class='comment-meta'><?php echo $comment_meta; ?></li>
<?php
- endif;
+ endif; // is_first
}
-?>
+ if ( $comments_query->comment_count > 1 ) : ?>
</ul>
-
<?php
+ endif; // comment_count;
}
@@ -361,7 +363,7 @@ function wp_dashboard_incoming_links_output() {
echo "</ul>\n";
} else {
- echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. They have found no incoming links found&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\n";
+ echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\n";
}
}
@@ -499,7 +501,7 @@ function wp_dashboard_empty( $sidebar_args, $callback = false ) {
/* Dashboard Widgets Controls. Ssee also wp_dashboard_empty() */
// Calls widget_control callback
-function wp_dashbaord_trigger_widget_control( $widget_control_id = false ) {
+function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
global $wp_registered_widget_controls;
if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_registered_widget_controls[$widget_control_id]) && is_callable($wp_registered_widget_controls[$widget_control_id]['callback']) )
call_user_func_array( $wp_registered_widget_controls[$widget_control_id]['callback'], $wp_registered_widget_controls[$widget_control_id]['params'] );
diff --git a/wp-admin/includes/export.php b/wp-admin/includes/export.php
index a712177..5590826 100644
--- a/wp-admin/includes/export.php
+++ b/wp-admin/includes/export.php
@@ -195,12 +195,12 @@ echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
<title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
<link><?php the_permalink_rss() ?></link>
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
-<dc:creator><?php the_author() ?></dc:creator>
+<dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
<?php wxr_post_taxonomy() ?>
<guid isPermaLink="false"><?php the_guid(); ?></guid>
<description></description>
-<content:encoded><![CDATA[<?php echo apply_filters('the_content_export', $post->post_content); ?>]]></content:encoded>
+<content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
<wp:post_id><?php echo $post->ID; ?></wp:post_id>
<wp:post_date><?php echo $post->post_date; ?></wp:post_date>
<wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
@@ -238,7 +238,7 @@ if ( $comments ) { foreach ( $comments as $c ) { ?>
<wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
<wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
<wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
-<wp:comment_content><?php echo $c->comment_content; ?></wp:comment_content>
+<wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
<wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
<wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
<wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
@@ -252,4 +252,4 @@ if ( $comments ) { foreach ( $comments as $c ) { ?>
<?php
}
-?> \ No newline at end of file
+?>
diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php
index 45c05e5..75ef4e3 100644
--- a/wp-admin/includes/file.php
+++ b/wp-admin/includes/file.php
@@ -1,6 +1,6 @@
<?php
-$wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ),
+$wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'rtl.css' => __( 'RTL Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'searchform.php' => __( 'Search Form' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'link.php' => __( 'Links Template' ), 'functions.php' => __( 'Theme Functions' ), 'attachment.php' => __( 'Attachment Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ),
// Deprecated files
'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' ));
function get_file_description( $file ) {
@@ -42,6 +42,20 @@ function get_real_file_to_edit( $file ) {
return $real_file;
}
+function get_temp_dir() {
+ if ( defined('WP_TEMP_DIR') )
+ return trailingslashit(WP_TEMP_DIR);
+
+ $temp = ABSPATH . 'wp-content/';
+ if ( is_dir($temp) && is_writable($temp) )
+ return $temp;
+
+ if ( function_exists('sys_get_temp_dir') )
+ return trailingslashit(sys_get_temp_dir());
+
+ return '/tmp/';
+}
+
function validate_file( $file, $allowed_files = '' ) {
if ( false !== strpos( $file, '..' ))
return 1;
@@ -114,6 +128,7 @@ function wp_handle_upload( &$file, $overrides = false ) {
// If you override this, you must provide $ext and $type!!!!
$test_type = true;
+ $mimes = false;
// Install user overrides. Did we mention that this voids your warranty?
if ( is_array( $overrides ) )
@@ -146,32 +161,16 @@ function wp_handle_upload( &$file, $overrides = false ) {
if ( !$ext )
$ext = ltrim(strrchr($file['name'], '.'), '.');
+
+ if ( !$type )
+ $type = $file['type'];
}
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
return $upload_error_handler( $file, $uploads['error'] );
- // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
- if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) {
- $filename = $unique_filename_callback( $uploads['path'], $file['name'] );
- } else {
- $number = '';
- $filename = str_replace( '#', '_', $file['name'] );
- $filename = str_replace( array( '\\', "'" ), '', $filename );
- if ( empty( $ext) )
- $ext = '';
- else
- $ext = ".$ext";
- while ( file_exists( $uploads['path'] . "/$filename" ) ) {
- if ( '' == "$number$ext" )
- $filename = $filename . ++$number . $ext;
- else
- $filename = str_replace( "$number$ext", ++$number . $ext, $filename );
- }
- $filename = str_replace( $ext, '', $filename );
- $filename = sanitize_title_with_dashes( $filename ) . $ext;
- }
+ $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/$filename";
@@ -191,4 +190,148 @@ function wp_handle_upload( &$file, $overrides = false ) {
return $return;
}
+/**
+* Downloads a url to a local file using the Snoopy HTTP Class
+*
+* @param string $url the URL of the file to download
+* @return mixed WP_Error on failure, string Filename on success.
+*/
+function download_url( $url ) {
+ //WARNING: The file is not automatically deleted, The script must unlink() the file.
+ if( ! $url )
+ return new WP_Error('http_no_url', __('Invalid URL Provided'));
+
+ $tmpfname = tempnam(get_temp_dir(), 'wpupdate');
+ if( ! $tmpfname )
+ return new WP_Error('http_no_file', __('Could not create Temporary file'));
+
+ $handle = @fopen($tmpfname, 'w');
+ if( ! $handle )
+ return new WP_Error('http_no_file', __('Could not create Temporary file'));
+
+ require_once( ABSPATH . 'wp-includes/class-snoopy.php' );
+ $snoopy = new Snoopy();
+ $snoopy->fetch($url);
+
+ if( $snoopy->status != '200' ){
+ fclose($handle);
+ unlink($tmpfname);
+ return new WP_Error('http_404', trim($snoopy->response_code));
+ }
+ fwrite($handle, $snoopy->results);
+ fclose($handle);
+
+ return $tmpfname;
+}
+
+function unzip_file($file, $to) {
+ global $wp_filesystem;
+
+ if ( ! $wp_filesystem || !is_object($wp_filesystem) )
+ return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
+
+ $fs =& $wp_filesystem;
+
+ require_once(ABSPATH . 'wp-admin/includes/class-pclzip.php');
+
+ $archive = new PclZip($file);
+
+ // Is the archive valid?
+ if ( false == ($archive_files = $archive->extract(PCLZIP_OPT_EXTRACT_AS_STRING)) )
+ return new WP_Error('incompatible_archive', __('Incompatible archive'), $archive->errorInfo(true));
+
+ if ( 0 == count($archive_files) )
+ return new WP_Error('empty_archive', __('Empty archive'));
+
+ $to = trailingslashit($to);
+ $path = explode('/', $to);
+ $tmppath = '';
+ for ( $j = 0; $j < count($path) - 1; $j++ ) {
+ $tmppath .= $path[$j] . '/';
+ if ( ! $fs->is_dir($tmppath) )
+ $fs->mkdir($tmppath, 0755);
+ }
+
+ foreach ($archive_files as $file) {
+ $path = explode('/', $file['filename']);
+ $tmppath = '';
+
+ // Loop through each of the items and check that the folder exists.
+ for ( $j = 0; $j < count($path) - 1; $j++ ) {
+ $tmppath .= $path[$j] . '/';
+ if ( ! $fs->is_dir($to . $tmppath) )
+ if ( !$fs->mkdir($to . $tmppath, 0755) )
+ return new WP_Error('mkdir_failed', __('Could not create directory'));
+ }
+
+ // We've made sure the folders are there, so let's extract the file now:
+ if ( ! $file['folder'] )
+ if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
+ return new WP_Error('copy_failed', __('Could not copy file'));
+ $fs->chmod($to . $file['filename'], 0644);
+ }
+
+ return true;
+}
+
+function copy_dir($from, $to) {
+ global $wp_filesystem;
+
+ $dirlist = $wp_filesystem->dirlist($from);
+
+ $from = trailingslashit($from);
+ $to = trailingslashit($to);
+
+ foreach ( (array) $dirlist as $filename => $fileinfo ) {
+ if ( 'f' == $fileinfo['type'] ) {
+ if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
+ return false;
+ $wp_filesystem->chmod($to . $filename, 0644);
+ } elseif ( 'd' == $fileinfo['type'] ) {
+ if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
+ return false;
+ if ( !copy_dir($from . $filename, $to . $filename) )
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function WP_Filesystem( $args = false, $preference = false ) {
+ global $wp_filesystem;
+
+ $method = get_filesystem_method($preference);
+ if ( ! $method )
+ return false;
+
+ require_once('class-wp-filesystem-'.$method.'.php');
+ $method = "WP_Filesystem_$method";
+
+ $wp_filesystem = new $method($args);
+
+ if ( $wp_filesystem->errors->get_error_code() )
+ return false;
+
+ if ( !$wp_filesystem->connect() )
+ return false; //There was an erorr connecting to the server.
+
+ return true;
+}
+
+function get_filesystem_method() {
+ $tempFile = tempnam(get_temp_dir(), 'WPU');
+
+ if ( getmyuid() == fileowner($tempFile) ) {
+ unlink($tempFile);
+ return 'direct';
+ } else {
+ unlink($tempFile);
+ }
+
+ if ( extension_loaded('ftp') ) return 'ftpext';
+ if ( extension_loaded('sockets') || function_exists('fsockopen') ) return 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
+ return false;
+}
+
?>
diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php
index ec4466e..2af026d 100644
--- a/wp-admin/includes/image.php
+++ b/wp-admin/includes/image.php
@@ -1,110 +1,46 @@
<?php
-
-function get_udims( $width, $height) {
- if ( $height <= 96 && $width <= 128 )
- return array( $width, $height);
- elseif ( $width / $height > 4 / 3 )
- return array( 128, (int) ($height / $width * 128 ));
- else
- return array( (int) ($width / $height * 96 ), 96 );
-}
-
-function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
-
- // 1 = GIF, 2 = JPEG, 3 = PNG
-
- if ( file_exists( $file ) ) {
- $type = getimagesize( $file );
-
- // if the associated function doesn't exist - then it's not
- // handle. duh. i hope.
-
- if (!function_exists( 'imagegif' ) && $type[2] == 1 ) {
- $error = __( 'Filetype not supported. Thumbnail not created.' );
- }
- elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) {
- $error = __( 'Filetype not supported. Thumbnail not created.' );
- }
- elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) {
- $error = __( 'Filetype not supported. Thumbnail not created.' );
- } else {
-
- // create the initial copy from the original file
- if ( $type[2] == 1 ) {
- $image = imagecreatefromgif( $file );
- }
- elseif ( $type[2] == 2 ) {
- $image = imagecreatefromjpeg( $file );
- }
- elseif ( $type[2] == 3 ) {
- $image = imagecreatefrompng( $file );
- }
-
- if ( function_exists( 'imageantialias' ))
- imageantialias( $image, TRUE );
-
- $image_attr = getimagesize( $file );
-
- // figure out the longest side
-
- if ( $image_attr[0] > $image_attr[1] ) {
- $image_width = $image_attr[0];
- $image_height = $image_attr[1];
- $image_new_width = $max_side;
-
- $image_ratio = $image_width / $image_new_width;
- $image_new_height = $image_height / $image_ratio;
- //width is > height
- } else {
- $image_width = $image_attr[0];
- $image_height = $image_attr[1];
- $image_new_height = $max_side;
-
- $image_ratio = $image_height / $image_new_height;
- $image_new_width = $image_width / $image_ratio;
- //height > width
- }
-
- $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);
- @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] );
-
- // If no filters change the filename, we'll do a default transformation.
- if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) )
- $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail' . '$1', basename( $file ), 1 );
-
- $thumbpath = str_replace( basename( $file ), $thumb, $file );
-
- // move the thumbnail to its final destination
- if ( $type[2] == 1 ) {
- if (!imagegif( $thumbnail, $thumbpath ) ) {
- $error = __( "Thumbnail path invalid" );
- }
- }
- elseif ( $type[2] == 2 ) {
- if (!imagejpeg( $thumbnail, $thumbpath ) ) {
- $error = __( "Thumbnail path invalid" );
- }
- }
- elseif ( $type[2] == 3 ) {
- if (!imagepng( $thumbnail, $thumbpath ) ) {
- $error = __( "Thumbnail path invalid" );
- }
- }
-
- }
- } else {
- $error = __( 'File not found' );
- }
-
- if (!empty ( $error ) ) {
- return $error;
- } else {
- return apply_filters( 'wp_create_thumbnail', $thumbpath );
- }
+/**
+ * File contains all the administration image manipulation functions.
+ *
+ * @package WordPress
+ */
+
+/**
+ * wp_create_thumbnail() - Create a thumbnail from an Image given a maximum side size.
+ *
+ * @package WordPress
+ * @param mixed $file Filename of the original image, Or attachment id
+ * @param int $max_side Maximum length of a single side for the thumbnail
+ * @return string Thumbnail path on success, Error string on failure
+ *
+ * This function can handle most image file formats which PHP supports.
+ * If PHP does not have the functionality to save in a file of the same format, the thumbnail will be created as a jpeg.
+ */
+function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
+
+ $thumbpath = image_resize( $file, $max_side, $max_side );
+ return apply_filters( 'wp_create_thumbnail', $thumbpath );
}
+/**
+ * wp_crop_image() - Crop an Image to a given size.
+ *
+ * @package WordPress
+ * @internal Missing Long Description
+ * @param int $src_file The source file
+ * @param int $src_x The start x position to crop from
+ * @param int $src_y The start y position to crop from
+ * @param int $src_w The width to crop
+ * @param int $src_h The height to crop
+ * @param int $dst_w The destination width
+ * @param int $dst_h The destination height
+ * @param int $src_abs If the source crop points are absolute
+ * @param int $dst_file The destination file to write to
+ * @return string New filepath on success, String error message on failure
+ *
+ */
function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
- if ( ctype_digit( $src_file ) ) // Handle int as attachment ID
+ if ( is_numeric( $src_file ) ) // Handle int as attachment ID
$src_file = get_attached_file( $src_file );
$src = wp_load_image( $src_file );
@@ -124,8 +60,10 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
- if ( !$dst_file )
- $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file );
+ imagedestroy( $src ); // Free up memory
+
+ if ( ! $dst_file )
+ $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
@@ -135,44 +73,69 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
return false;
}
+/**
+ * wp_generate_attachment_metadata() - Generate post Image attachment Metadata
+ *
+ * @package WordPress
+ * @internal Missing Long Description
+ * @param int $attachment_id Attachment Id to process
+ * @param string $file Filepath of the Attached image
+ * @return mixed Metadata for attachment
+ *
+ */
function wp_generate_attachment_metadata( $attachment_id, $file ) {
$attachment = get_post( $attachment_id );
$metadata = array();
- if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) {
- $imagesize = getimagesize($file);
- $metadata['width'] = $imagesize['0'];
- $metadata['height'] = $imagesize['1'];
- list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']);
+ if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
+ $imagesize = getimagesize( $file );
+ $metadata['width'] = $imagesize[0];
+ $metadata['height'] = $imagesize[1];
+ list($uwidth, $uheight) = wp_shrink_dimensions($metadata['width'], $metadata['height']);
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
$metadata['file'] = $file;
- $max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file );
-
- if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) {
- $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file );
- $thumb = wp_create_thumbnail( $file, $max_side );
-
- if ( @file_exists($thumb) )
- $metadata['thumb'] = basename($thumb);
+ // make thumbnails and other intermediate sizes
+ $sizes = array('thumbnail', 'medium');
+ $sizes = apply_filters('intermediate_image_sizes', $sizes);
+
+ foreach ($sizes as $size) {
+ $resized = image_make_intermediate_size( $file, get_option("{$size}_size_w"), get_option("{$size}_size_h"), get_option("{$size}_crop") );
+ if ( $resized )
+ $metadata['sizes'][$size] = $resized;
}
+
+ // fetch additional metadata from exif/iptc
+ $image_meta = wp_read_image_metadata( $file );
+ if ($image_meta)
+ $metadata['image_meta'] = $image_meta;
+
}
return apply_filters( 'wp_generate_attachment_metadata', $metadata );
}
+/**
+ * wp_load_image() - Load an image which PHP Supports.
+ *
+ * @package WordPress
+ * @internal Missing Long Description
+ * @param string $file Filename of the image to load
+ * @return resource The resulting image resource on success, Error string on failure.
+ *
+ */
function wp_load_image( $file ) {
- if ( ctype_digit( $file ) )
+ if ( is_numeric( $file ) )
$file = get_attached_file( $file );
- if ( !file_exists( $file ) )
+ if ( ! file_exists( $file ) )
return sprintf(__("File '%s' doesn't exist?"), $file);
if ( ! function_exists('imagecreatefromstring') )
return __('The GD image library is not installed.');
- $contents = file_get_contents( $file );
-
- $image = imagecreatefromstring( $contents );
+ // Set artificially high because GD uses uncompressed images in memory
+ @ini_set('memory_limit', '256M');
+ $image = imagecreatefromstring( file_get_contents( $file ) );
if ( !is_resource( $image ) )
return sprintf(__("File '%s' is not an image."), $file);
@@ -180,13 +143,140 @@ function wp_load_image( $file ) {
return $image;
}
+/**
+ * get_udims() - Calculated the new dimentions for downsampled images
+ *
+ * @package WordPress
+ * @internal Missing Description
+ * @see wp_shrink_dimensions()
+ * @param int $width Current width of the image
+ * @param int $height Current height of the image
+ * @return mixed Array(height,width) of shrunk dimensions.
+ *
+ */
+function get_udims( $width, $height) {
+ return wp_shrink_dimensions( $width, $height );
+}
+/**
+ * wp_shrink_dimensions() - Calculates the new dimentions for a downsampled image.
+ *
+ * @package WordPress
+ * @internal Missing Long Description
+ * @param int $width Current width of the image
+ * @param int $height Current height of the image
+ * @param int $wmax Maximum wanted width
+ * @param int $hmax Maximum wanted height
+ * @return mixed Array(height,width) of shrunk dimensions.
+ *
+ */
function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
- if ( $height <= $hmax && $width <= $wmax )
- return array( $width, $height);
- elseif ( $width / $height > $wmax / $hmax )
- return array( $wmax, (int) ($height / $width * $wmax ));
+ return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
+}
+
+// convert a fraction string to a decimal
+function wp_exif_frac2dec($str) {
+ @list( $n, $d ) = explode( '/', $str );
+ if ( !empty($d) )
+ return $n / $d;
+ return $str;
+}
+
+// convert the exif date format to a unix timestamp
+function wp_exif_date2ts($str) {
+ // seriously, who formats a date like 'YYYY:MM:DD hh:mm:ss'?
+ @list( $date, $time ) = explode( ' ', trim($str) );
+ @list( $y, $m, $d ) = explode( ':', $date );
+
+ return strtotime( "{$y}-{$m}-{$d} {$time}" );
+}
+
+// get extended image metadata, exif or iptc as available
+function wp_read_image_metadata( $file ) {
+ if ( !file_exists( $file ) )
+ return false;
+
+ list(,,$sourceImageType) = getimagesize( $file );
+
+ // exif contains a bunch of data we'll probably never need formatted in ways that are difficult to use.
+ // We'll normalize it and just extract the fields that are likely to be useful. Fractions and numbers
+ // are converted to floats, dates to unix timestamps, and everything else to strings.
+ $meta = array(
+ 'aperture' => 0,
+ 'credit' => '',
+ 'camera' => '',
+ 'caption' => '',
+ 'created_timestamp' => 0,
+ 'copyright' => '',
+ 'focal_length' => 0,
+ 'iso' => 0,
+ 'shutter_speed' => 0,
+ 'title' => '',
+ );
+
+ // read iptc first, since it might contain data not available in exif such as caption, description etc
+ if ( is_callable('iptcparse') ) {
+ getimagesize($file, $info);
+ if ( !empty($info['APP13']) ) {
+ $iptc = iptcparse($info['APP13']);
+ if ( !empty($iptc['2#110'][0]) ) // credit
+ $meta['credit'] = trim( $iptc['2#110'][0] );
+ elseif ( !empty($iptc['2#080'][0]) ) // byline
+ $meta['credit'] = trim( $iptc['2#080'][0] );
+ if ( !empty($iptc['2#055'][0]) and !empty($iptc['2#060'][0]) ) // created datee and time
+ $meta['created_timestamp'] = strtotime($iptc['2#055'][0] . ' ' . $iptc['2#060'][0]);
+ if ( !empty($iptc['2#120'][0]) ) // caption
+ $meta['caption'] = trim( $iptc['2#120'][0] );
+ if ( !empty($iptc['2#116'][0]) ) // copyright
+ $meta['copyright'] = trim( $iptc['2#116'][0] );
+ if ( !empty($iptc['2#005'][0]) ) // title
+ $meta['title'] = trim( $iptc['2#005'][0] );
+ }
+ }
+
+ // fetch additional info from exif if available
+ if ( is_callable('exif_read_data') && in_array($sourceImageType, apply_filters('wp_read_image_metadata_types', array(IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM)) ) ) {
+ $exif = exif_read_data( $file );
+ if (!empty($exif['FNumber']))
+ $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 );
+ if (!empty($exif['Model']))
+ $meta['camera'] = trim( $exif['Model'] );
+ if (!empty($exif['DateTimeDigitized']))
+ $meta['created_timestamp'] = wp_exif_date2ts($exif['DateTimeDigitized']);
+ if (!empty($exif['FocalLength']))
+ $meta['focal_length'] = wp_exif_frac2dec( $exif['FocalLength'] );
+ if (!empty($exif['ISOSpeedRatings']))
+ $meta['iso'] = $exif['ISOSpeedRatings'];
+ if (!empty($exif['ExposureTime']))
+ $meta['shutter_speed'] = wp_exif_frac2dec( $exif['ExposureTime'] );
+ }
+ // FIXME: try other exif libraries if available
+
+ return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType );
+
+}
+
+// is the file a real image file?
+function file_is_valid_image($path) {
+ $size = @getimagesize($path);
+ return !empty($size);
+}
+
+// is the file an image suitable for displaying within a web page?
+function file_is_displayable_image($path) {
+ $info = @getimagesize($path);
+ if ( empty($info) )
+ $result = false;
+ elseif ( !in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) )
+ // only gif, jpeg and png images can reliably be displayed
+ $result = false;
+ elseif ( $info['channels'] > 0 && $info['channels'] != 3 ) {
+ // some web browsers can't display cmyk or grayscale jpegs
+ $result = false;
+ }
else
- return array( (int) ($width / $height * $hmax ), $hmax );
+ $result = true;
+
+ return apply_filters('file_is_displayable_image', $result, $path);
}
?>
diff --git a/wp-admin/includes/import.php b/wp-admin/includes/import.php
index 9835bb1..35fd141 100644
--- a/wp-admin/includes/import.php
+++ b/wp-admin/includes/import.php
@@ -2,7 +2,8 @@
function get_importers() {
global $wp_importers;
- uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
+ if ( is_array($wp_importers) )
+ uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
return $wp_importers;
}
@@ -19,6 +20,7 @@ function wp_import_cleanup( $id ) {
function wp_import_handle_upload() {
$overrides = array( 'test_form' => false, 'test_type' => false );
+ $_FILES['import']['name'] .= '.import';
$file = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $file['error'] ) )
diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index b43c2da..5803e3f 100644
--- a/wp-admin/includes/media.php
+++ b/wp-admin/includes/media.php
@@ -50,7 +50,7 @@ function the_media_upload_tabs() {
function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
- $html = get_image_tag($id, $alt, $title, $align, $rel, $size);
+ $html = get_image_tag($id, $alt, $title, $align, $size);
$rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
@@ -124,7 +124,7 @@ function wp_iframe($content_func /* ... */) {
<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
-<title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; WordPress</title>
+<title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
<?php
wp_admin_css( 'css/global' );
wp_admin_css();
@@ -203,7 +203,7 @@ function media_upload_form_handler() {
check_admin_referer('media-form');
// Insert media button was clicked
- if ( !empty($_FILES) ) {
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
@@ -246,8 +246,11 @@ function media_upload_form_handler() {
$send_id = (int) array_shift($keys);
$attachment = $_POST['attachments'][$send_id];
$html = $attachment['post_title'];
- if ( !empty($attachment['url']) )
- $html = "<a href='{$attachment['url']}'>$html</a>";
+ if ( !empty($attachment['url']) ) {
+ if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
+ $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
+ $html = "<a href='{$attachment['url']}'$rel>$html</a>";
+ }
$html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
return media_send_to_editor($html);
}
@@ -256,7 +259,7 @@ function media_upload_form_handler() {
}
function media_upload_image() {
- if ( !empty($_FILES) ) {
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
@@ -268,14 +271,15 @@ function media_upload_image() {
if ( !empty($_POST['insertonlybutton']) ) {
$src = $_POST['insertonly']['src'];
- if ( !strpos($src, '://') )
+ if ( !empty($src) && !strpos($src, '://') )
$src = "http://$src";
$alt = attribute_escape($_POST['insertonly']['alt']);
if ( isset($_POST['insertonly']['align']) ) {
$align = attribute_escape($_POST['insertonly']['align']);
$class = " class='align$align'";
}
- $html = "<img src='$src' alt='$alt'$class />";
+ if ( !empty($src) )
+ $html = "<img src='$src' alt='$alt'$class />";
return media_send_to_editor($html);
}
@@ -288,11 +292,14 @@ function media_upload_image() {
$errors = $return;
}
+ if ( isset($_POST['save']) )
+ $errors['upload_notice'] = __('Saved.');
+
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
}
function media_upload_audio() {
- if ( !empty($_FILES) ) {
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
@@ -304,10 +311,13 @@ function media_upload_audio() {
if ( !empty($_POST['insertonlybutton']) ) {
$href = $_POST['insertonly']['href'];
- if ( !strpos($href, '://') )
+ if ( !empty($href) && !strpos($href, '://') )
$href = "http://$href";
$title = attribute_escape($_POST['insertonly']['title']);
- $html = "<a href='$href' >$title</a>";
+ if ( empty($title) )
+ $title = basename($href);
+ if ( !empty($title) && !empty($href) )
+ $html = "<a href='$href' >$title</a>";
return media_send_to_editor($html);
}
@@ -320,11 +330,14 @@ function media_upload_audio() {
$errors = $return;
}
+ if ( isset($_POST['save']) )
+ $errors['upload_notice'] = __('Saved.');
+
return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
}
function media_upload_video() {
- if ( !empty($_FILES) ) {
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
@@ -336,10 +349,13 @@ function media_upload_video() {
if ( !empty($_POST['insertonlybutton']) ) {
$href = $_POST['insertonly']['href'];
- if ( !strpos($href, '://') )
+ if ( !empty($href) && !strpos($href, '://') )
$href = "http://$href";
$title = attribute_escape($_POST['insertonly']['title']);
- $html = "<a href='$href' >$title</a>";
+ if ( empty($title) )
+ $title = basename($href);
+ if ( !empty($title) && !empty($href) )
+ $html = "<a href='$href' >$title</a>";
return media_send_to_editor($html);
}
@@ -352,11 +368,14 @@ function media_upload_video() {
$errors = $return;
}
+ if ( isset($_POST['save']) )
+ $errors['upload_notice'] = __('Saved.');
+
return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
}
function media_upload_file() {
- if ( !empty($_FILES) ) {
+ if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
// Upload File button was clicked
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
unset($_FILES);
@@ -368,10 +387,13 @@ function media_upload_file() {
if ( !empty($_POST['insertonlybutton']) ) {
$href = $_POST['insertonly']['href'];
- if ( !strpos($href, '://') )
+ if ( !empty($href) && !strpos($href, '://') )
$href = "http://$href";
$title = attribute_escape($_POST['insertonly']['title']);
- $html = "<a href='$href' >$title</a>";
+ if ( empty($title) )
+ $title = basename($href);
+ if ( !empty($title) && !empty($href) )
+ $html = "<a href='$href' >$title</a>";
return media_send_to_editor($html);
}
@@ -384,6 +406,9 @@ function media_upload_file() {
$errors = $return;
}
+ if ( isset($_POST['save']) )
+ $errors['upload_notice'] = __('Saved.');
+
return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
}
@@ -413,44 +438,13 @@ function media_upload_library() {
return wp_iframe( 'media_upload_library_form', $errors );
}
-function get_attachment_taxonomies($attachment) {
- if ( is_int( $attachment ) )
- $attachment = get_post($attachment);
- else if ( is_array($attachment) )
- $attachment = (object) $attachment;
-
- if ( ! is_object($attachment) )
- return array();
-
- $filename = basename($attachment->guid);
-
- $objects = array('attachment');
-
- if ( false !== strpos($filename, '.') )
- $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1);
- if ( !empty($attachment->post_mime_type) ) {
- $objects[] = 'attachment:' . $attachment->post_mime_type;
- if ( false !== strpos($attachment->post_mime_type, '/') )
- foreach ( explode('/', $attachment->post_mime_type) as $token )
- if ( !empty($token) )
- $objects[] = "attachment:$token";
- }
-
- $taxonomies = array();
- foreach ( $objects as $object )
- if ( $taxes = get_object_taxonomies($object) )
- $taxonomies = array_merge($taxonomies, $taxes);
-
- return array_unique($taxonomies);
-}
-
function image_attachment_fields_to_edit($form_fields, $post) {
if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
$form_fields['post_title']['required'] = true;
- $form_fields['post_excerpt']['label'] = __('Description');
+ $form_fields['post_excerpt']['label'] = __('Caption');
$form_fields['post_excerpt']['helps'][] = __('Alternate text, e.g. "The Mona Lisa"');
- $form_fields['post_content']['label'] = __('Long Description');
+ $form_fields['post_content']['label'] = __('Description');
$thumb = wp_get_attachment_thumb_url($post->ID);
@@ -458,7 +452,7 @@ function image_attachment_fields_to_edit($form_fields, $post) {
'label' => __('Alignment'),
'input' => 'html',
'html' => "
- <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' />
+ <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
<label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
<input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
<label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
@@ -517,6 +511,8 @@ function image_media_send_to_editor($html, $attachment_id, $attachment) {
else
$size = 'medium';
+ $rel = ( $url == get_attachment_link($attachment_id) );
+
return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
}
@@ -541,11 +537,11 @@ function get_attachment_fields_to_edit($post, $errors = null) {
'value' => $edit_post->post_title,
),
'post_excerpt' => array(
- 'label' => __('Description'),
+ 'label' => __('Caption'),
'value' => $edit_post->post_excerpt,
),
'post_content' => array(
- 'label' => __('Long description'),
+ 'label' => __('Description'),
'value' => $edit_post->post_content,
'input' => 'textarea',
),
@@ -662,10 +658,12 @@ function get_media_item( $attachment_id, $args = null ) {
$toggle_links = '';
}
+ $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
+
$item = "
$type
$toggle_links
- <div class='filename new'>$filename</div>
+ <div class='filename new'>$display_title</div>
<table class='slidetoggle describe $class'>
<tbody class='media-item-info'>
<tr>
@@ -768,15 +766,27 @@ function media_upload_form( $errors = null ) {
$flash_action_url = get_option('siteurl') . "/wp-admin/async-upload.php";
+ // If Mac and mod_security, no Flash. :(
+ $flash = true;
+ if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
+ $flash = false;
+
+ $flash = apply_filters('flash_uploader', $flash);
$post_id = intval($_REQUEST['post_id']);
?>
<input type='hidden' name='post_id' value='<?php echo $post_id; ?>' />
+<div id="media-upload-notice">
+<?php if (isset($errors['upload_notice']) ) { ?>
+ <?php echo $errors['upload_notice']; ?>
+<?php } ?>
+</div>
<div id="media-upload-error">
<?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
<?php echo $errors['upload_error']->get_error_message(); ?>
<?php } ?>
</div>
+<?php if ( $flash ) : ?>
<script type="text/javascript">
<!--
jQuery(function($){
@@ -794,7 +804,6 @@ jQuery(function($){
file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available
degraded_element_id : "html-upload-ui", // when swfupload is unavailable
- swfupload_loaded_handler : uploadLoaded,
file_dialog_start_handler : fileDialogStart,
file_queued_handler : fileQueued,
upload_start_handler : uploadStart,
@@ -818,12 +827,17 @@ jQuery(function($){
<p><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
</div>
+<?php endif; // $flash ?>
+
<div id="html-upload-ui">
<p>
- <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onClick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
+ <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onClick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
</p>
<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
- <br style="clear:both" />
+ <br class="clear" />
+ <?php if ( is_lighttpd_before_150() ): ?>
+ <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please upgrade to lighttpd 1.5.'); ?></p>
+ <?php endif;?>
</div>
<?php
}
@@ -838,7 +852,7 @@ function media_upload_type_form($type = 'file', $errors = null, $id = null) {
$callback = "type_form_$type";
?>
-<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form" id="<?php echo $type; ?>-form">
+<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
<input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" />
<?php wp_nonce_field('media-form'); ?>
<h3><?php _e('From Computer'); ?></h3>
@@ -899,7 +913,7 @@ jQuery(function($){
-->
</script>
-<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="gallery-form">
+<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
<?php wp_nonce_field('media-form'); ?>
<?php //media_upload_form( $errors ); ?>
@@ -956,8 +970,14 @@ $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_po
foreach ( $matches as $_type => $reals )
foreach ( $reals as $real )
$num_posts[$_type] += $_num_posts[$real];
-$class = empty($_GET['post_mime_type']) ? ' class="current"' : '';
-$type_links[] = "<li><a href='" . remove_query_arg(array('post_mime_type', 'paged', 'm')) . "'$class>".__('All Types')."</a>";
+// If available type specified by media button clicked, filter by that type
+if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
+ $_GET['post_mime_type'] = $type;
+ list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
+}
+if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
+ $class = ' class="current"';
+$type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false)) . "'$class>".__('All Types')."</a>";
foreach ( $post_mime_types as $mime_type => $label ) {
$class = '';
@@ -967,7 +987,7 @@ foreach ( $post_mime_types as $mime_type => $label ) {
if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
$class = ' class="current"';
- $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf($label[2], "<span id='$mime_type-counter'>{$num_posts[$mime_type]}</span>") . '</a>';
+ $type_links[] = "<li><a href='" . add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false)) . "'$class>" . sprintf(__ngettext($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
}
echo implode(' | </li>', $type_links) . '</li>';
unset($type_links);
@@ -989,7 +1009,7 @@ if ( $page_links )
echo "<div class='tablenav-pages'>$page_links</div>";
?>
-<div style="float: left">
+<div class="alignleft">
<?php
$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
@@ -1024,11 +1044,11 @@ foreach ($arc_result as $arc_row) {
</div>
-<br style="clear:both;" />
+<br class="clear" />
</div>
</form>
-<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form" id="library-form">
+<form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
<?php wp_nonce_field('media-form'); ?>
<?php //media_upload_form( $errors ); ?>
@@ -1067,7 +1087,7 @@ function type_form_image() {
<tr>
<th valign="top" scope="row" class="label">
<span class="alignleft"><label for="insertonly[alt]">' . __('Description') . '</label></span>
- <span class="alignright"><abbr title="required">*</abbr></span>
+ <span class="alignright"><abbr title="required" class="required">*</abbr></span>
</th>
<td class="field"><input id="insertonly[alt]" name="insertonly[alt]" value="" type="text"></td>
</tr>
@@ -1075,13 +1095,13 @@ function type_form_image() {
<tr class="align">
<th valign="top" scope="row" class="label"><label for="insertonly[align]">' . __('Alignment') . '</label></th>
<td class="field">
- <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio">
+ <input name="insertonly[align]" id="image-align-none-0" value="none" type="radio" checked="checked" />
<label for="image-align-none-0" class="align image-align-none-label">' . __('None') . '</label>
- <input name="insertonly[align]" id="image-align-left-0" value="left" type="radio">
+ <input name="insertonly[align]" id="image-align-left-0" value="left" type="radio" />
<label for="image-align-left-0" class="align image-align-left-label">' . __('Left') . '</label>
- <input name="insertonly[align]" id="image-align-center-0" value="center" type="radio">
+ <input name="insertonly[align]" id="image-align-center-0" value="center" type="radio" />
<label for="image-align-center-0" class="align image-align-center-label">' . __('Center') . '</label>
- <input name="insertonly[align]" id="image-align-right-0" value="right" type="radio">
+ <input name="insertonly[align]" id="image-align-right-0" value="right" type="radio" />
<label for="image-align-right-0" class="align image-align-right-label">' . __('Right') . '</label>
</td>
</tr>
@@ -1196,30 +1216,4 @@ add_action('admin_head_media_upload_gallery_form', 'media_admin_css');
add_filter('media_upload_library', 'media_upload_library');
add_action('admin_head_media_upload_library_form', 'media_admin_css');
-
-// Any 'attachment' taxonomy will be included in the description input form for the multi uploader
-// Example:
-/*
-register_taxonomy(
- 'image_people',
- 'attachment:image',
- array(
- 'label' => __('People'),
- 'template' => __('People: %l'),
- 'helps' => __('Left to right, top to bottom.'),
- 'sort' => true,
- 'args' => array(
- 'orderby' => 'term_order'
- )
- )
-);
-*/
-/*
-register_taxonomy('movie_director', 'attachment:video', array('label'=>__('Directors'), 'template'=>__('Directed by %l.')));
-register_taxonomy('movie_producer', 'attachment:video', array('label'=>__('Producers'), 'template'=>__('Produced by %l.')));
-register_taxonomy('movie_screenwriter', 'attachment:video', array('label'=>__('Screenwriter'), 'template'=>__('Screenplay by %l.')));
-register_taxonomy('movie_actor', 'attachment:video', array('label'=>__('Cast'), 'template'=>array(__('Cast: %l.')));
-register_taxonomy('movie_crew', 'attachment:video', array('label'=>__('Crew'), 'template'=>array(__('Crew: %l.')));
-*/
-
?>
diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php
index 23f998f..d38f308 100644
--- a/wp-admin/includes/misc.php
+++ b/wp-admin/includes/misc.php
@@ -1,18 +1,8 @@
<?php
function got_mod_rewrite() {
- global $is_apache;
-
- // take 3 educated guesses as to whether or not mod_rewrite is available
- if ( !$is_apache )
- return false;
-
- if ( function_exists( 'apache_get_modules' ) ) {
- if ( !in_array( 'mod_rewrite', apache_get_modules() ) )
- return false;
- }
-
- return true;
+ $got_rewrite = apache_mod_loaded('mod_rewrite', true);
+ return apply_filters('got_rewrite', $got_rewrite);
}
// Returns an array of strings from a file (.htaccess ) from between BEGIN
@@ -129,19 +119,15 @@ function update_recently_edited( $file ) {
update_option( 'recently_edited', $oldfiles );
}
-// If siteurl or home changed, reset cookies and flush rewrite rules.
+// If siteurl or home changed, flush rewrite rules.
function update_home_siteurl( $old_value, $value ) {
- global $wp_rewrite, $user_login, $user_pass_md5;
+ global $wp_rewrite;
if ( defined( "WP_INSTALLING" ) )
return;
// If home changed, write rewrite rules to new location.
$wp_rewrite->flush_rules();
- // Clear cookies for old paths.
- wp_clearcookie();
- // Set cookies for new paths.
- wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' ));
}
add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
@@ -174,62 +160,4 @@ function wp_reset_vars( $vars ) {
}
}
}
-
-function add_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
- global $new_whitelist_options, $sanitize_callbacks;
- $new_whitelist_options[ $option_group ][] = $option_name;
- if( $sanitize_callback != '' )
- add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
-}
-
-function remove_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
- global $new_whitelist_options, $sanitize_callbacks;
- $pos = array_search( $option_name, $new_whitelist_options );
- if( $pos !== false )
- unset( $new_whitelist_options[ $option_group ][ $pos ] );
- if( $sanitize_callback != '' )
- remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
-}
-
-function option_update_filter( $options ) {
- global $new_whitelist_options;
-
- if( is_array( $new_whitelist_options ) )
- $options = add_option_whitelist( $new_whitelist_options, $options );
-
- return $options;
-}
-add_filter( 'whitelist_options', 'option_update_filter' );
-
-function add_option_whitelist( $new_options, $options = '' ) {
- if( $options == '' ) {
- global $whitelist_options;
- } else {
- $whitelist_options = $options;
- }
- foreach( $new_options as $page => $keys ) {
- foreach( $keys as $key ) {
- $pos = array_search( $key, $whitelist_options[ $page ] );
- if( $pos === false )
- $whitelist_options[ $page ][] = $key;
- }
- }
- return $whitelist_options;
-}
-
-function remove_option_whitelist( $del_options, $options = '' ) {
- if( $options == '' ) {
- global $whitelist_options;
- } else {
- $whitelist_options = $options;
- }
- foreach( $del_options as $page => $keys ) {
- foreach( $keys as $key ) {
- $pos = array_search( $key, $whitelist_options[ $page ] );
- if( $pos !== false )
- unset( $whitelist_options[ $page ][ $pos ] );
- }
- }
- return $whitelist_options;
-}
?>
diff --git a/wp-admin/includes/mu.php b/wp-admin/includes/mu.php
index a8a4344..7dc677f 100644
--- a/wp-admin/includes/mu.php
+++ b/wp-admin/includes/mu.php
@@ -382,13 +382,13 @@ function redirect_user_to_blog() {
exit();
}
}
-add_action( 'admin_menu_permission', 'redirect_user_to_blog' );
+add_action( 'admin_page_access_denied', 'redirect_user_to_blog' );
function wpmu_menu() {
global $menu, $submenu;
if( is_site_admin() ) {
- $menu[1] = array(__('Site Admin'), '10', 'wpmu-admin.php' );
+ $menu[29] = array(__('Site Admin'), '10', 'wpmu-admin.php' );
$submenu[ 'wpmu-admin.php' ][1] = array( __('Admin'), '10', 'wpmu-admin.php' );
$submenu[ 'wpmu-admin.php' ][5] = array( __('Blogs'), '10', 'wpmu-blogs.php' );
$submenu[ 'wpmu-admin.php' ][10] = array( __('Users'), '10', 'wpmu-users.php' );
@@ -401,7 +401,7 @@ function wpmu_menu() {
unset( $submenu['plugins.php'][10] );
unset( $submenu['options-general.php'][40] );
unset( $submenu['edit.php'][30] );
- unset( $menu['30'] );
+ unset( $menu['35'] ); // Plugins
$menu_perms = get_site_option( "menu_items" );
if( is_array( $menu_perms ) == false )
@@ -418,8 +418,6 @@ function mu_options( $options ) {
$added = array( 'general' => array( 'new_admin_email', 'WPLANG', 'language' ) );
- unset( $options[ 'misc' ] );
-
$options = remove_option_whitelist( $removed, $options );
$options = add_option_whitelist( $added, $options );
@@ -427,4 +425,170 @@ function mu_options( $options ) {
}
add_filter( 'whitelist_options', 'mu_options' );
+function import_no_new_users( $permission ) {
+ return false;
+}
+add_filter( 'import_allow_create_users', 'import_no_new_users' );
+// See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
+
+function add_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
+ global $new_whitelist_options, $sanitize_callbacks;
+ $new_whitelist_options[ $option_group ][] = $option_name;
+ if( $sanitize_callback != '' )
+ add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
+}
+
+function remove_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
+ global $new_whitelist_options, $sanitize_callbacks;
+ $pos = array_search( $option_name, $new_whitelist_options );
+ if( $pos !== false )
+ unset( $new_whitelist_options[ $option_group ][ $pos ] );
+ if( $sanitize_callback != '' )
+ remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
+}
+
+function option_update_filter( $options ) {
+ global $new_whitelist_options;
+
+ if( is_array( $new_whitelist_options ) )
+ $options = add_option_whitelist( $new_whitelist_options, $options );
+
+ return $options;
+}
+add_filter( 'whitelist_options', 'option_update_filter' );
+
+function add_option_whitelist( $new_options, $options = '' ) {
+ if( $options == '' ) {
+ global $whitelist_options;
+ } else {
+ $whitelist_options = $options;
+ }
+ foreach( $new_options as $page => $keys ) {
+ foreach( $keys as $key ) {
+ $pos = array_search( $key, $whitelist_options[ $page ] );
+ if( $pos === false )
+ $whitelist_options[ $page ][] = $key;
+ }
+ }
+ return $whitelist_options;
+}
+
+function remove_option_whitelist( $del_options, $options = '' ) {
+ if( $options == '' ) {
+ global $whitelist_options;
+ } else {
+ $whitelist_options = $options;
+ }
+ foreach( $del_options as $page => $keys ) {
+ foreach( $keys as $key ) {
+ $pos = array_search( $key, $whitelist_options[ $page ] );
+ if( $pos !== false )
+ unset( $whitelist_options[ $page ][ $pos ] );
+ }
+ }
+ return $whitelist_options;
+}
+
+/* Blogswitcher */
+function blogswitch_init() {
+ global $current_user, $current_blog;
+ $blogs = get_blogs_of_user( $current_user->ID );
+ if ( !$blogs )
+ return;
+ add_action( 'admin_menu', 'blogswitch_ob_start' );
+ add_action( 'dashmenu', 'blogswitch_markup' );
+}
+
+
+function blogswitch_ob_start() {
+ wp_enqueue_script( 'blog-switch', '/wp-admin/js/blog-switch.js', array( 'jquery' ), 2 );
+ ob_start( 'blogswitch_ob_content' );
+}
+
+function blogswitch_ob_content( $content ) {
+ $content = preg_replace( '#<ul id="dashmenu">.*?%%REAL_DASH_MENU%%#s', '<ul id="dashmenu">', $content );
+ return str_replace( '%%END_REAL_DASH_MENU%%</ul>', '', $content );
+}
+
+function blogswitch_markup() {
+ global $current_user, $blog_id; // current blog
+ $list = array();
+ $options = array();
+
+
+ $primary_blog = get_usermeta( $current_user->ID, 'primary_blog' );
+
+ foreach ( $blogs = get_blogs_of_user( $current_user->ID ) as $blog ) {
+ if ( !$blog->blogname )
+ continue;
+
+ // Use siteurl for this in case of mapping
+ $parsed = parse_url( $blog->siteurl );
+ $domain = $parsed['host'];
+
+ if ( $_SERVER['HTTP_HOST'] === $domain ) {
+ $current = ' class="current"';
+ $selected = ' selected="selected"';
+ } else {
+ $current = '';
+ $selected = '';
+ }
+
+ $url = clean_url( $blog->siteurl ) . '/wp-admin/';
+ $name = wp_specialchars( strip_tags( $blog->blogname ) );
+ $list_item = "<li><a href='$url'$current>$name</a></li>";
+ $option_item = "<option value='$url'$selected>$name</option>";
+
+ if ( $blog_id == $blog->userblog_id ) {
+ $list[-2] = $list_item;
+ $options[] = $option_item; // [sic] don't reorder dropdown based on current blog
+ } elseif ( $primary_blog == $blog->userblog_id ) {
+ $list[-1] = $list_item;
+ $options[-1] = $option_item;
+ } else {
+ $list[] = $list_item;
+ $options[] = $option_item;
+ }
+ }
+ ksort($list);
+ ksort($options);
+
+ $list = array_slice( $list, 0, 4 ); // First 4
+
+ $select = "\n\t\t<select>\n\t\t\t" . join( "\n\t\t\t", $options ) . "\n\t\t</select>";
+
+ echo "%%REAL_DASH_MENU%%\n\t" . join( "\n\t", $list );
+
+ if ( count($list) < count($options) ) :
+?>
+
+ <li id="all-my-blogs-tab" class="wp-no-js-hidden"><a href="#" class="blog-picker-toggle"><?php _e( 'All my blogs' ); ?></a></li>
+
+ </ul>
+
+ <form id="all-my-blogs" action="" method="get" style="display: none">
+ <p>
+ <?php printf( __( 'Choose a blog: %s' ), $select ); ?>
+
+ <input type="submit" class="button" value="<?php _e( 'Go' ); ?>" />
+ <a href="#" class="blog-picker-toggle"><?php _e( 'Cancel' ); ?></a>
+ </p>
+ </form>
+
+<?php else : // counts ?>
+
+ </ul>
+
+<?php
+ endif; // counts
+
+ echo '%%END_REAL_DASH_MENU%%';
+}
+
+add_action( '_admin_menu', 'blogswitch_init' );
+
+function mu_css() {
+ wp_admin_css( 'css/mu' );
+}
+add_action( 'admin_head', 'mu_css' );
?>
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php
index e5911bd..a862c51 100644
--- a/wp-admin/includes/plugin.php
+++ b/wp-admin/includes/plugin.php
@@ -31,7 +31,7 @@ function get_plugin_data( $plugin_file ) {
return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version);
}
-function get_plugins() {
+function get_plugins($plugin_folder = '') {
global $wp_plugins;
if ( isset( $wp_plugins ) ) {
@@ -40,6 +40,8 @@ function get_plugins() {
$wp_plugins = array ();
$plugin_root = ABSPATH . PLUGINDIR;
+ if( !empty($plugin_folder) )
+ $plugin_root .= $plugin_folder;
// Files in wp-content/plugins directory
$plugins_dir = @ opendir( $plugin_root);
@@ -86,6 +88,117 @@ function get_plugins() {
return $wp_plugins;
}
+function is_plugin_active($plugin){
+ return in_array($plugin, get_option('active_plugins'));
+}
+
+function activate_plugin($plugin, $redirect = '') {
+ $current = get_option('active_plugins');
+ $plugin = trim($plugin);
+
+ $valid = validate_plugin($plugin);
+ if ( is_wp_error($valid) )
+ return $valid;
+
+ if ( !in_array($plugin, $current) ) {
+ if ( !empty($redirect) )
+ wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
+ ob_start();
+ @include(ABSPATH . PLUGINDIR . '/' . $plugin);
+ $current[] = $plugin;
+ sort($current);
+ update_option('active_plugins', $current);
+ do_action('activate_' . $plugin);
+ ob_end_clean();
+ }
+
+ return null;
+}
+
+function deactivate_plugins($plugins, $silent= false) {
+ $current = get_option('active_plugins');
+
+ if ( !is_array($plugins) )
+ $plugins = array($plugins);
+
+ foreach ( $plugins as $plugin ) {
+ if( ! is_plugin_active($plugin) )
+ continue;
+ array_splice($current, array_search( $plugin, $current), 1 ); // Fixed Array-fu!
+ if ( ! $silent ) //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output.
+ do_action('deactivate_' . trim( $plugin ));
+ }
+
+ update_option('active_plugins', $current);
+}
+
+function deactivate_all_plugins() {
+ $current = get_option('active_plugins');
+ if ( empty($current) )
+ return;
+
+ deactivate_plugins($current);
+
+ update_option('deactivated_plugins', $current);
+}
+
+function reactivate_all_plugins($redirect = '') {
+ $plugins = get_option('deactivated_plugins');
+
+ if ( empty($plugins) )
+ return;
+
+ if ( !empty($redirect) )
+ wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
+
+ $errors = array();
+ foreach ( (array) $plugins as $plugin ) {
+ $result = activate_plugin($plugin);
+ if ( is_wp_error($result) )
+ $errors[$plugin] = $result;
+ }
+
+ delete_option('deactivated_plugins');
+
+ if ( !empty($errors) )
+ return new WP_Error('plugins_invalid', __('One of the plugins is invalid.'), $errors);
+
+ return true;
+}
+
+function validate_active_plugins() {
+ $check_plugins = get_option('active_plugins');
+
+ // Sanity check. If the active plugin list is not an array, make it an
+ // empty array.
+ if ( !is_array($check_plugins) ) {
+ update_option('active_plugins', array());
+ return;
+ }
+
+ // If a plugin file does not exist, remove it from the list of active
+ // plugins.
+ foreach ( $check_plugins as $check_plugin ) {
+ if ( !file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin) ) {
+ $current = get_option('active_plugins');
+ $key = array_search($check_plugin, $current);
+ if ( false !== $key && NULL !== $key ) {
+ unset($current[$key]);
+ update_option('active_plugins', $current);
+ }
+ }
+ }
+}
+
+function validate_plugin($plugin) {
+ if ( validate_file($plugin) )
+ return new WP_Error('plugin_invalid', __('Invalid plugin.'));
+ if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
+ return new WP_Error('plugin_not_found', __('Plugin file does not exist.'));
+
+ return 0;
+}
+
//
// Menu
//
@@ -111,7 +224,6 @@ function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $fi
global $menu;
global $_wp_real_parent_file;
global $_wp_submenu_nopriv;
- global $_wp_menu_nopriv;
$file = plugin_basename( $file );
@@ -287,10 +399,8 @@ function get_admin_page_title() {
}
function get_plugin_page_hook( $plugin_page, $parent_page ) {
- global $wp_filter;
-
$hook = get_plugin_page_hookname( $plugin_page, $parent_page );
- if ( isset( $wp_filter[$hook] ))
+ if ( has_action($hook) )
return $hook;
else
return null;
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index acd6e64..2ee6210 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -2,7 +2,6 @@
// Update an existing post with values provided in $_POST.
function edit_post() {
- global $user_ID;
$post_ID = (int) $_POST['post_ID'];
@@ -19,8 +18,7 @@ function edit_post() {
$post =& get_post( $post_ID );
$now = time();
$then = strtotime($post->post_date_gmt . ' +0000');
- // Keep autosave_interval in sync with autosave-js.php.
- $delta = apply_filters( 'autosave_interval', 120 ) / 2;
+ $delta = AUTOSAVE_INTERVAL / 2;
if ( ($now - $then) < $delta )
return $post_ID;
}
@@ -29,7 +27,7 @@ function edit_post() {
$_POST['ID'] = (int) $_POST['post_ID'];
$_POST['post_content'] = $_POST['content'];
$_POST['post_excerpt'] = $_POST['excerpt'];
- $_POST['post_parent'] = $_POST['parent_id'];
+ $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
$_POST['to_ping'] = $_POST['trackback_url'];
if (!empty ( $_POST['post_author_override'] ) ) {
@@ -53,20 +51,20 @@ function edit_post() {
}
// What to do based on which button they pressed
- if ('' != $_POST['saveasdraft'] )
+ if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
$_POST['post_status'] = 'draft';
- if ('' != $_POST['saveasprivate'] )
+ if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
$_POST['post_status'] = 'private';
- if ('' != $_POST['publish'] )
+ if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
$_POST['post_status'] = 'publish';
- if ('' != $_POST['advanced'] )
+ if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
$_POST['post_status'] = 'draft';
if ( 'page' == $_POST['post_type'] ) {
- if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' ))
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ))
$_POST['post_status'] = 'pending';
} else {
- if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' ))
+ if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ))
$_POST['post_status'] = 'pending';
}
@@ -76,6 +74,13 @@ function edit_post() {
if (!isset( $_POST['ping_status'] ))
$_POST['ping_status'] = 'closed';
+ foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
+ if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
+ $_POST['edit_date'] = '1';
+ break;
+ }
+ }
+
if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
@@ -92,12 +97,12 @@ function edit_post() {
}
// Meta Stuff
- if ( $_POST['meta'] ) {
+ if ( isset($_POST['meta']) && $_POST['meta'] ) {
foreach ( $_POST['meta'] as $key => $value )
update_meta( $key, $value['key'], $value['value'] );
}
- if ( $_POST['deletemeta'] ) {
+ if ( isset($_POST['deletemeta']) && $_POST['deletemeta'] ) {
foreach ( $_POST['deletemeta'] as $key => $value )
delete_meta( $key );
}
@@ -115,6 +120,8 @@ function edit_post() {
// Now that we have an ID we can fix any attachment anchor hrefs
_fix_attachment_links( $post_ID );
+ wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
+
return $post_ID;
}
@@ -129,6 +136,7 @@ function get_default_post_to_edit() {
$post_title = '';
}
+ $post_content = '';
if ( !empty( $_REQUEST['content'] ) )
$post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
else if ( !empty( $post_title ) ) {
@@ -143,7 +151,14 @@ function get_default_post_to_edit() {
else
$post_excerpt = '';
+ $post->ID = 0;
+ $post->post_name = '';
+ $post->post_author = '';
+ $post->post_date = '';
$post->post_status = 'draft';
+ $post->post_type = 'post';
+ $post->to_ping = '';
+ $post->pinged = '';
$post->comment_status = get_option( 'default_comment_status' );
$post->ping_status = get_option( 'default_ping_status' );
$post->post_pingback = get_option( 'default_pingback_flag' );
@@ -158,6 +173,12 @@ function get_default_post_to_edit() {
return $post;
}
+function get_default_page_to_edit() {
+ $page = get_default_post_to_edit();
+ $page->post_type = 'page';
+ return $page;
+}
+
// Get an existing post and format it for editing.
function get_post_to_edit( $id ) {
@@ -218,7 +239,7 @@ function wp_write_post() {
// Rename.
$_POST['post_content'] = $_POST['content'];
$_POST['post_excerpt'] = $_POST['excerpt'];
- $_POST['post_parent'] = $_POST['parent_id'];
+ $_POST['post_parent'] = isset($_POST['parent_id'])? $_POST['parent_id'] : '';
$_POST['to_ping'] = $_POST['trackback_url'];
if (!empty ( $_POST['post_author_override'] ) ) {
@@ -244,13 +265,13 @@ function wp_write_post() {
}
// What to do based on which button they pressed
- if ('' != $_POST['saveasdraft'] )
+ if ( isset($_POST['saveasdraft']) && '' != $_POST['saveasdraft'] )
$_POST['post_status'] = 'draft';
- if ('' != $_POST['saveasprivate'] )
+ if ( isset($_POST['saveasprivate']) && '' != $_POST['saveasprivate'] )
$_POST['post_status'] = 'private';
- if ('' != $_POST['publish'] )
+ if ( isset($_POST['publish']) && ( '' != $_POST['publish'] ) && ( $_POST['post_status'] != 'private' ) )
$_POST['post_status'] = 'publish';
- if ('' != $_POST['advanced'] )
+ if ( isset($_POST['advanced']) && '' != $_POST['advanced'] )
$_POST['post_status'] = 'draft';
if ( 'page' == $_POST['post_type'] ) {
@@ -267,6 +288,13 @@ function wp_write_post() {
if (!isset( $_POST['ping_status'] ))
$_POST['ping_status'] = 'closed';
+ foreach ( array ('aa', 'mm', 'jj', 'hh', 'mm') as $timeunit ) {
+ if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
+ $_POST['edit_date'] = '1';
+ break;
+ }
+ }
+
if (!empty ( $_POST['edit_date'] ) ) {
$aa = $_POST['aa'];
$mm = $_POST['mm'];
@@ -309,6 +337,8 @@ function wp_write_post() {
// Now that we have an ID we can fix any attachment anchor hrefs
_fix_attachment_links( $post_ID );
+ wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
+
return $post_ID;
}
@@ -348,11 +378,13 @@ function add_meta( $post_ID ) {
if ( in_array($metakey, $protected) )
return false;
- $result = $wpdb->query( "
- INSERT INTO $wpdb->postmeta
- (post_id,meta_key,meta_value )
- VALUES ('$post_ID','$metakey','$metavalue' )
- " );
+ wp_cache_delete($post_ID, 'post_meta');
+
+ $wpdb->query( "
+ INSERT INTO $wpdb->postmeta
+ (post_id,meta_key,meta_value )
+ VALUES ('$post_ID','$metakey','$metavalue' )
+ " );
return $wpdb->insert_id;
}
return false;
@@ -362,6 +394,9 @@ function delete_meta( $mid ) {
global $wpdb;
$mid = (int) $mid;
+ $post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = '$mid'");
+ wp_cache_delete($post_id, 'post_meta');
+
return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" );
}
@@ -408,6 +443,9 @@ function update_meta( $mid, $mkey, $mvalue ) {
if ( in_array($mkey, $protected) )
return false;
+ $post_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = '$mid'");
+ wp_cache_delete($post_id, 'post_meta');
+
$mvalue = maybe_serialize( stripslashes( $mvalue ));
$mvalue = $wpdb->escape( $mvalue );
$mid = (int) $mid;
@@ -420,7 +458,6 @@ function update_meta( $mid, $mkey, $mvalue ) {
// Replace hrefs of attachment anchors with up-to-date permalinks.
function _fix_attachment_links( $post_ID ) {
- global $wp_rewrite;
$post = & get_post( $post_ID, ARRAY_A );
@@ -468,4 +505,191 @@ function _relocate_children( $old_ID, $new_ID ) {
return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" );
}
+function get_available_post_statuses($type = 'post') {
+ global $wpdb;
+
+ $stati = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_status FROM $wpdb->posts WHERE post_type = %s", $type));
+ return $stati;
+}
+
+function wp_edit_posts_query( $q = false ) {
+ global $wpdb;
+ if ( false === $q )
+ $q = $_GET;
+ $q['m'] = (int) $q['m'];
+ $q['cat'] = (int) $q['cat'];
+ $post_stati = array( // array( adj, noun )
+ 'publish' => array(__('Published'), __('Published posts'), __ngettext_noop('Published (%s)', 'Published (%s)')),
+ 'future' => array(__('Scheduled'), __('Scheduled posts'), __ngettext_noop('Scheduled (%s)', 'Scheduled (%s)')),
+ 'pending' => array(__('Pending Review'), __('Pending posts'), __ngettext_noop('Pending Review (%s)', 'Pending Review (%s)')),
+ 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft (%s)', 'Drafts (%s)')),
+ 'private' => array(__('Private'), __('Private posts'), __ngettext_noop('Private (%s)', 'Private (%s)')),
+ );
+
+ $post_stati = apply_filters('post_stati', $post_stati);
+
+ $avail_post_stati = get_available_post_statuses('post');
+
+ $post_status_q = '';
+ if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) {
+ $post_status_q = '&post_status=' . $q['post_status'];
+ $post_status_q .= '&perm=readable';
+ }
+
+ if ( 'pending' === $q['post_status'] ) {
+ $order = 'ASC';
+ $orderby = 'modified';
+ } elseif ( 'draft' === $q['post_status'] ) {
+ $order = 'DESC';
+ $orderby = 'modified';
+ } else {
+ $order = 'DESC';
+ $orderby = 'date';
+ }
+
+ wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby");
+
+ return array($post_stati, $avail_post_stati);
+}
+
+function get_available_post_mime_types($type = 'attachment') {
+ global $wpdb;
+
+ $types = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type));
+ return $types;
+}
+
+function wp_edit_attachments_query( $q = false ) {
+ global $wpdb;
+ if ( false === $q )
+ $q = $_GET;
+ $q['m'] = (int) $q['m'];
+ $q['cat'] = (int) $q['cat'];
+ $q['post_type'] = 'attachment';
+ $q['post_status'] = 'any';
+ $q['posts_per_page'] = 15;
+ $post_mime_types = array( // array( adj, noun )
+ 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image (%s)', 'Images (%s)')),
+ 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio (%s)', 'Audio (%s)')),
+ 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video (%s)', 'Video (%s)')),
+ );
+ $post_mime_types = apply_filters('post_mime_types', $post_mime_types);
+
+ $avail_post_mime_types = get_available_post_mime_types('attachment');
+
+ if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
+ unset($q['post_mime_type']);
+
+ wp($q);
+
+ return array($post_mime_types, $avail_post_mime_types);
+}
+
+function postbox_classes( $id, $page ) {
+ $current_user = wp_get_current_user();
+ if ( $closed = get_usermeta( $current_user->ID, 'closedpostboxes_'.$page ) ) {
+ if ( !is_array( $closed ) ) return '';
+ return in_array( $id, $closed )? 'if-js-closed' : '';
+ } else {
+ if ( 'tagsdiv' == $id || 'categorydiv' == $id ) return '';
+ else return 'if-js-closed';
+ }
+}
+
+function get_sample_permalink($id, $title=null, $name = null) {
+ $post = &get_post($id);
+ if (!$post->ID) {
+ return array('', '');
+ }
+ $original_status = $post->post_status;
+ $original_date = $post->post_date;
+ $original_name = $post->post_name;
+
+ // Hack: get_permalink would return ugly permalink for
+ // drafts, so we will fake, that our post is published
+ if (in_array($post->post_status, array('draft', 'pending'))) {
+ $post->post_status = 'publish';
+ $post->post_date = date('Y-m-d H:i:s');
+ $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
+ }
+
+ // If the user wants to set a new name -- override the current one
+ // Note: if empty name is supplied -- use the title instead, see #6072
+ if (!is_null($name)) {
+ $post->post_name = sanitize_title($name? $name : $title, $post->ID);
+ }
+
+ $permalink = get_permalink($post, true);
+
+ // Handle page hierarchy
+ if ( 'page' == $post->post_type ) {
+ $uri = get_page_uri($post->ID);
+ $uri = untrailingslashit($uri);
+ $uri = strrev( stristr( strrev( $uri ), '/' ) );
+ $uri = untrailingslashit($uri);
+ if ( !empty($uri) )
+ $uri .='/';
+ $permalink = str_replace('%pagename%', "${uri}%pagename%", $permalink);
+ }
+
+ $permalink = array($permalink, $post->post_name);
+ $post->post_status = $original_status;
+ $post->post_date = $original_date;
+ $post->post_name = $original_name;
+ $post->post_title = $original_title;
+ return $permalink;
+}
+
+function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
+ $post = &get_post($id);
+ list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
+ if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
+ return '';
+ }
+ $title = __('Click to edit this part of the permalink');
+ if (strlen($post_name) > 30) {
+ $post_name_abridged = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
+ } else {
+ $post_name_abridged = $post_name;
+ }
+ $post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name_abridged.'</span><span id="editable-post-name-full">'.$post_name.'</span>';
+ $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
+ $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
+ $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
+ return $return;
+}
+
+// false: not locked or locked by current user
+// int: user ID of user with lock
+function wp_check_post_lock( $post_id ) {
+ global $current_user;
+
+ if ( !$post = get_post( $post_id ) )
+ return false;
+
+ $lock = get_post_meta( $post->ID, '_edit_lock', true );
+ $last = get_post_meta( $post->ID, '_edit_last', true );
+
+ $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
+
+ if ( $lock && $lock > time() - $time_window && $last != $current_user->ID )
+ return $last;
+ return false;
+}
+
+function wp_set_post_lock( $post_id ) {
+ global $current_user;
+ if ( !$post = get_post( $post_id ) )
+ return false;
+ if ( !$current_user || !$current_user->ID )
+ return false;
+
+ $now = time();
+
+ if ( !add_post_meta( $post->ID, '_edit_lock', $now, true ) )
+ update_post_meta( $post->ID, '_edit_lock', $now );
+ if ( !add_post_meta( $post->ID, '_edit_last', $current_user->ID, true ) )
+ update_post_meta( $post->ID, '_edit_last', $current_user->ID );
+}
+
?>
diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php
index 310c2c1..7b78d93 100644
--- a/wp-admin/includes/schema.php
+++ b/wp-admin/includes/schema.php
@@ -1,10 +1,12 @@
<?php
// Here we keep the DB structure and option values
-global $wp_queries;
$charset_collate = '';
-if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
+// Declare these as global in case schema.php is included from a function.
+global $wpdb, $wp_queries;
+
+if ( $wpdb->supports_collation() ) {
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
@@ -32,6 +34,7 @@ CREATE TABLE $wpdb->term_taxonomy (
CREATE TABLE $wpdb->term_relationships (
object_id bigint(20) NOT NULL default 0,
term_taxonomy_id bigint(20) NOT NULL default 0,
+ term_order int(11) NOT NULL default 0,
PRIMARY KEY (object_id,term_taxonomy_id),
KEY term_taxonomy_id (term_taxonomy_id)
) $charset_collate;
@@ -46,14 +49,16 @@ CREATE TABLE $wpdb->comments (
comment_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
comment_content text NOT NULL,
comment_karma int(11) NOT NULL default '0',
- comment_approved enum('0','1','spam') NOT NULL default '1',
+ comment_approved varchar(20) NOT NULL default '1',
comment_agent varchar(255) NOT NULL default '',
comment_type varchar(20) NOT NULL default '',
comment_parent bigint(20) NOT NULL default '0',
user_id bigint(20) NOT NULL default '0',
PRIMARY KEY (comment_ID),
KEY comment_approved (comment_approved),
- KEY comment_post_ID (comment_post_ID)
+ KEY comment_post_ID (comment_post_ID),
+ KEY comment_approved_date_gmt (comment_approved,comment_date_gmt),
+ KEY comment_date_gmt (comment_date_gmt)
) $charset_collate;
CREATE TABLE $wpdb->links (
link_id bigint(20) NOT NULL auto_increment,
@@ -63,7 +68,7 @@ CREATE TABLE $wpdb->links (
link_target varchar(25) NOT NULL default '',
link_category bigint(20) NOT NULL default '0',
link_description varchar(255) NOT NULL default '',
- link_visible enum('Y','N') NOT NULL default 'Y',
+ link_visible varchar(20) NOT NULL default 'Y',
link_owner int(11) NOT NULL default '1',
link_rating int(11) NOT NULL default '0',
link_updated datetime NOT NULL default '0000-00-00 00:00:00',
@@ -79,7 +84,7 @@ CREATE TABLE $wpdb->options (
blog_id int(11) NOT NULL default '0',
option_name varchar(64) NOT NULL default '',
option_value longtext NOT NULL,
- autoload enum('yes','no') NOT NULL default 'yes',
+ autoload varchar(20) NOT NULL default 'yes',
PRIMARY KEY (option_id,blog_id,option_name),
KEY option_name (option_name)
) $charset_collate;
@@ -101,9 +106,9 @@ CREATE TABLE $wpdb->posts (
post_title text NOT NULL,
post_category int(4) NOT NULL default '0',
post_excerpt text NOT NULL,
- post_status enum('publish','draft','private','static','object','attachment','inherit','future', 'pending') NOT NULL default 'publish',
- comment_status enum('open','closed','registered_only') NOT NULL default 'open',
- ping_status enum('open','closed') NOT NULL default 'open',
+ post_status varchar(20) NOT NULL default 'publish',
+ comment_status varchar(20) NOT NULL default 'open',
+ ping_status varchar(20) NOT NULL default 'open',
post_password varchar(20) NOT NULL default '',
post_name varchar(200) NOT NULL default '',
to_ping text NOT NULL,
@@ -301,7 +306,7 @@ function populate_options() {
}
// 2.0.3
- add_option('secret', md5(uniqid(microtime())));
+ add_option('secret', wp_generate_password());
// 2.1
add_option('blog_public', '1');
@@ -311,8 +316,18 @@ function populate_options() {
// 2.2
add_option('tag_base');
+ // 2.5
+ add_option('show_avatars', '1');
+ add_option('avatar_rating', 'G');
+ add_option('upload_url_path', '');
+ add_option('thumbnail_size_w', 150);
+ add_option('thumbnail_size_h', 150);
+ add_option('thumbnail_crop', 1);
+ add_option('medium_size_w', 300);
+ add_option('medium_size_h', 300);
+
// Delete unused options
- $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing');
+ $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval');
foreach ($unusedoptions as $option) :
delete_option($option);
endforeach;
@@ -328,17 +343,24 @@ function populate_roles() {
populate_roles_160();
populate_roles_210();
populate_roles_230();
+ populate_roles_250();
}
function populate_roles_160() {
- global $wp_roles;
-
// Add roles
- add_role('administrator', __('Administrator'));
- add_role('editor', __('Editor'));
- add_role('author', __('Author'));
- add_role('contributor', __('Contributor'));
- add_role('subscriber', __('Subscriber'));
+
+ // Dummy gettext calls to get strings in the catalog.
+ _c('Administrator|User role');
+ _c('Editor|User role');
+ _c('Author|User role');
+ _c('Contributor|User role');
+ _c('Subscriber|User role');
+
+ add_role('administrator', 'Administrator|User role');
+ add_role('editor', 'Editor|User role');
+ add_role('author', 'Author|User role');
+ add_role('contributor', 'Contributor|User role');
+ add_role('subscriber', 'Subscriber|User role');
// Add caps for Administrator role
$role = get_role('administrator');
@@ -469,4 +491,12 @@ function populate_roles_230() {
*/
}
+function populate_roles_250() {
+ $role = get_role( 'administrator' );
+
+ if ( !empty( $role ) ) {
+ $role->add_cap( 'edit_dashboard' );
+ }
+}
+
?>
diff --git a/wp-admin/includes/taxonomy.php b/wp-admin/includes/taxonomy.php
index 3f70f45..b490ed6 100644
--- a/wp-admin/includes/taxonomy.php
+++ b/wp-admin/includes/taxonomy.php
@@ -16,11 +16,11 @@ function get_category_to_edit( $id ) {
return $category;
}
-function wp_create_category($cat_name) {
+function wp_create_category( $cat_name, $parent = 0 ) {
if ( $id = category_exists($cat_name) )
return $id;
- return wp_insert_category( array('cat_name' => $cat_name) );
+ return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
}
function wp_create_categories($categories, $post_id = '') {
@@ -40,8 +40,6 @@ function wp_create_categories($categories, $post_id = '') {
}
function wp_delete_category($cat_ID) {
- global $wpdb;
-
$cat_ID = (int) $cat_ID;
$default = get_option('default_category');
@@ -52,13 +50,17 @@ function wp_delete_category($cat_ID) {
return wp_delete_term($cat_ID, 'category', "default=$default");
}
-function wp_insert_category($catarr) {
- global $wpdb;
-
+function wp_insert_category($catarr, $wp_error = false) {
+ $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
+ $cat_arr = wp_parse_args($cat_arr, $cat_defaults);
extract($catarr, EXTR_SKIP);
- if ( trim( $cat_name ) == '' )
- return 0;
+ if ( trim( $cat_name ) == '' ) {
+ if ( ! $wp_error )
+ return 0;
+ else
+ return new WP_Error( 'cat_name', __('You did not enter a category name.') );
+ }
$cat_ID = (int) $cat_ID;
@@ -74,6 +76,9 @@ function wp_insert_category($catarr) {
$parent = $category_parent;
$parent = (int) $parent;
+ if ( $parent < 0 )
+ $parent = 0;
+
if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
$parent = 0;
@@ -84,15 +89,17 @@ function wp_insert_category($catarr) {
else
$cat_ID = wp_insert_term($cat_name, 'category', $args);
- if ( is_wp_error($cat_ID) )
- return 0;
+ if ( is_wp_error($cat_ID) ) {
+ if ( $wp_error )
+ return $cat_ID;
+ else
+ return 0;
+ }
return $cat_ID['term_id'];
}
function wp_update_category($catarr) {
- global $wpdb;
-
$cat_ID = (int) $catarr['cat_ID'];
if ( $cat_ID == $catarr['category_parent'] )
@@ -115,8 +122,6 @@ function wp_update_category($catarr) {
//
function get_tags_to_edit( $post_id ) {
- global $wpdb;
-
$post_id = (int) $post_id;
if ( !$post_id )
return false;
@@ -145,4 +150,4 @@ function wp_create_tag($tag_name) {
return wp_insert_term($tag_name, 'post_tag');
}
-?> \ No newline at end of file
+?>
diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php
index ff809ec..3e67338 100644
--- a/wp-admin/includes/template.php
+++ b/wp-admin/includes/template.php
@@ -6,8 +6,12 @@
// Dandy new recursive multiple category stuff.
function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
- if ( !$categories )
- $categories = get_categories( 'hide_empty=0' );
+ if ( !$categories ) {
+ $args = array('hide_empty' => 0);
+ if ( !empty($_GET['s']) )
+ $args['search'] = $_GET['s'];
+ $categories = get_categories( $args );
+ }
$children = _get_term_hierarchy('category');
@@ -34,43 +38,68 @@ function cat_rows( $parent = 0, $level = 0, $categories = 0 ) {
function _cat_row( $category, $level, $name_override = false ) {
global $class;
+ $category = get_category( $category );
+
$pad = str_repeat( '&#8212; ', $level );
+ $name = ( $name_override ? $name_override : $pad . ' ' . $category->name );
if ( current_user_can( 'manage_categories' ) ) {
- $edit = "<a href='categories.php?action=edit&amp;cat_ID=$category->term_id' class='edit'>".__( 'Edit' )."</a></td>";
- $default_cat_id = (int) get_option( 'default_category' );
- $default_link_cat_id = (int) get_option( 'default_link_category' );
-
- if ( $category->term_id != $default_cat_id )
- $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&amp;cat_ID=$category->term_id", 'delete-category_' . $category->term_id ) . "' onclick=\"return deleteSomething( 'cat', $category->term_id, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>";
- else
- $edit .= "<td style='text-align:center'>".__( "Default" );
- } else
- $edit = '';
+ $edit = "<a class='row-title' href='categories.php?action=edit&amp;cat_ID=$category->term_id' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "'>$name</a>";
+ } else {
+ $edit = $name;
+ }
- $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";
+ $class = " class='alternate'" == $class ? '' : " class='alternate'";
$category->count = number_format_i18n( $category->count );
$posts_count = ( $category->count > 0 ) ? "<a href='edit.php?cat=$category->term_id'>$category->count</a>" : $category->count;
$output = "<tr id='cat-$category->term_id'$class>
- <th scope='row' style='text-align: center'>$category->term_id</th>
- <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->name ) . "</td>
- <td>$category->description</td>
- <td align='center'>$posts_count</td>
- <td>$edit</td>\n\t</tr>\n";
+ <th scope='row' class='check-column'>";
+ if ( absint(get_option( 'default_category' ) ) != $category->term_id ) {
+ $output .= "<input type='checkbox' name='delete[]' value='$category->term_id' /></th>";
+ } else {
+ $output .= "&nbsp;";
+ }
+ $output .= "<td>$edit</td>
+ <td>$category->description</td>
+ <td class='num'>$posts_count</td>\n\t</tr>\n";
return apply_filters('cat_row', $output);
}
+function link_cat_row( $category ) {
+ global $class;
+
+ if ( !$category = get_term( $category, 'link_category' ) )
+ return false;
+ if ( is_wp_error( $category ) )
+ return $category;
+
+ $name = ( $name_override ? $name_override : $category->name );
+ if ( current_user_can( 'manage_categories' ) ) {
+ $edit = "<a class='row-title' href='link-category.php?action=edit&amp;cat_ID=$category->term_id' title='" . attribute_escape(sprintf(__('Edit "%s"'), $category->name)) . "' class='edit'>$name</a>";
+ $default_cat_id = (int) get_option( 'default_link_category' );
+ } else {
+ $edit = $name;
+ }
+
+ $class = " class='alternate'" == $class ? '' : " class='alternate'";
+
+ $category->count = number_format_i18n( $category->count );
+ $count = ( $category->count > 0 ) ? "<a href='link-manager.php?cat_id=$category->term_id'>$category->count</a>" : $category->count;
+ $output = "<tr id='link-cat-$category->term_id'$class>" .
+ '<th scope="row" class="check-column"> <input type="checkbox" name="delete[]" value="' . $category->term_id . '" /></th>' .
+ "<td>$edit</td>
+ <td>$category->description</td>
+ <td class='num'>$count</td></tr>";
+
+ return apply_filters( 'link_cat_row', $output );
+}
+
function checked( $checked, $current) {
if ( $checked == $current)
echo ' checked="checked"';
}
-// TODO: Remove?
-function documentation_link( $for ) {
- return;
-}
-
function selected( $selected, $current) {
if ( $selected == $current)
echo ' selected="selected"';
@@ -87,8 +116,8 @@ function sort_cats( $cat1, $cat2 ) {
return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] );
}
-function get_nested_categories( $default = 0, $parent = 0 ) {
- global $post_ID, $mode, $wpdb, $checked_categories;
+function wp_set_checked_post_categories( $default = 0 ) {
+ global $post_ID, $checked_categories;
if ( empty($checked_categories) ) {
if ( $post_ID ) {
@@ -103,15 +132,33 @@ function get_nested_categories( $default = 0, $parent = 0 ) {
}
}
- $cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
+}
+function get_nested_categories( $default = 0, $parent = 0 ) {
+ global $checked_categories;
+
+ wp_set_checked_post_categories( $default = 0 );
+
+ if ( is_object($parent) ) { // Hack: if passed a category object, will return nested cats with parent as root
+ $root = array(
+ 'children' => get_nested_categories( $default, $parent->term_id ),
+ 'cat_ID' => $parent->term_id,
+ 'checked' => in_array( $parent->term_id, $checked_categories ),
+ 'cat_name' => get_the_category_by_ID( $parent->term_id )
+ );
+ $result = array( $parent->term_id => $root );
+ } else {
+ $parent = (int) $parent;
+
+ $cats = get_categories("parent=$parent&hide_empty=0&fields=ids");
- $result = array ();
- if ( is_array( $cats ) ) {
- foreach ( $cats as $cat) {
- $result[$cat]['children'] = get_nested_categories( $default, $cat);
- $result[$cat]['cat_ID'] = $cat;
- $result[$cat]['checked'] = in_array( $cat, $checked_categories );
- $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);
+ $result = array();
+ if ( is_array( $cats ) ) {
+ foreach ( $cats as $cat ) {
+ $result[$cat]['children'] = get_nested_categories( $default, $cat );
+ $result[$cat]['cat_ID'] = $cat;
+ $result[$cat]['checked'] = in_array( $cat, $checked_categories );
+ $result[$cat]['cat_name'] = get_the_category_by_ID( $cat );
+ }
}
}
@@ -123,18 +170,37 @@ function get_nested_categories( $default = 0, $parent = 0 ) {
function write_nested_categories( $categories ) {
foreach ( $categories as $category ) {
- echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>";
+ echo "\n", '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), '</label>';
if ( $category['children'] ) {
- echo "<ul>\n";
+ echo "\n<ul>";
write_nested_categories( $category['children'] );
- echo "</ul>\n";
+ echo "\n</ul>";
}
+ echo '</li>';
}
}
-function dropdown_categories( $default = 0 ) {
- write_nested_categories( get_nested_categories( $default) );
+function dropdown_categories( $default = 0, $parent = 0 ) {
+ write_nested_categories( get_nested_categories( $default, $parent ) );
+}
+
+function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10 ) {
+ $categories = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number ) );
+
+ foreach ( (array) $categories as $category ) {
+ $id = "popular-category-$category->term_id";
+ ?>
+
+ <li id="<?php echo $id; ?>" >
+ <label class="selectit" for="in-<?php echo $id; ?>">
+ <input id="in-<?php echo $id; ?>" type="checkbox" value="<?php echo (int) $category->term_id; ?>" />
+ <?php echo wp_specialchars( apply_filters( 'the_category', $category->name ) ); ?>
+ </label>
+ </li>
+
+ <?php
+ }
}
function dropdown_link_categories( $default = 0 ) {
@@ -164,46 +230,309 @@ function dropdown_link_categories( $default = 0 ) {
}
}
-function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) {
- global $wpdb, $class, $post;
+// Tag stuff
- if (!$pages )
- $pages = get_pages( 'sort_column=menu_order' );
+// Returns a single tag row (see tag_rows below)
+// Note: this is also used in admin-ajax.php!
+function _tag_row( $tag, $class = '' ) {
+ $count = number_format_i18n( $tag->count );
+ $count = ( $count > 0 ) ? "<a href='edit.php?tag=$tag->slug'>$count</a>" : $count;
- if (! $pages )
- return false;
+ $name = apply_filters( 'term_name', $tag->name );
+ $out = '';
+ $out .= '<tr id="tag-' . $tag->term_id . '"' . $class . '>';
+ $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>';
+ $out .= '<td><strong><a class="row-title" href="edit-tags.php?action=edit&amp;tag_ID=' . $tag->term_id . '" title="' . attribute_escape(sprintf(__('Edit "%s"'), $name)) . '">' .
+ $name . '</a></td>';
+
+ $out .= "<td class='num'>$count</td>";
+ $out .= '</tr>';
+
+ return $out;
+}
- foreach ( $pages as $post) {
- setup_postdata( $post);
- if ( $hierarchy && ($post->post_parent != $parent) )
- continue;
+// Outputs appropriate rows for the Nth page of the Tag Management screen,
+// assuming M tags displayed at a time on the page
+// Returns the number of tags displayed
+function tag_rows( $page = 1, $pagesize = 20, $searchterms = '' ) {
- $post->post_title = wp_specialchars( $post->post_title );
- $pad = str_repeat( '&#8212; ', $level );
- $id = (int) $post->ID;
- $class = ('alternate' == $class ) ? '' : 'alternate';
+ // Get a page worth of tags
+ $start = ($page - 1) * $pagesize;
+
+ $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0);
+
+ if ( !empty( $searchterms ) ) {
+ $args['search'] = $searchterms;
+ }
+
+ $tags = get_terms( 'post_tag', $args );
+
+ // convert it to table rows
+ $out = '';
+ $class = '';
+ $count = 0;
+ foreach( $tags as $tag )
+ $out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '' );
+
+ // filter and send to screen
+ $out = apply_filters('tag_rows', $out);
+ echo $out;
+ return $count;
+}
+
+// define the columns to display, the syntax is 'internal name' => 'display name'
+function wp_manage_posts_columns() {
+ $posts_columns = array();
+ $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
+ if ( 'draft' === $_GET['post_status'] )
+ $posts_columns['modified'] = __('Modified');
+ elseif ( 'pending' === $_GET['post_status'] )
+ $posts_columns['modified'] = __('Submitted');
+ else
+ $posts_columns['date'] = __('Date');
+ $posts_columns['title'] = __('Title');
+ $posts_columns['author'] = __('Author');
+ $posts_columns['categories'] = __('Categories');
+ $posts_columns['tags'] = __('Tags');
+ if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
+ $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
+ $posts_columns['status'] = __('Status');
+ $posts_columns = apply_filters('manage_posts_columns', $posts_columns);
+
+ return $posts_columns;
+}
+
+// define the columns to display, the syntax is 'internal name' => 'display name'
+function wp_manage_media_columns() {
+ $posts_columns = array();
+ $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
+ $posts_columns['icon'] = '';
+ $posts_columns['media'] = _c('Media|media column header');
+ $posts_columns['desc'] = _c('Description|media column header');
+ $posts_columns['date'] = _c('Date Added|media column header');
+ $posts_columns['parent'] = _c('Appears with|media column header');
+ $posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
+ $posts_columns['location'] = _c('Location|media column header');
+ $posts_columns = apply_filters('manage_media_columns', $posts_columns);
+
+ return $posts_columns;
+}
+
+function wp_manage_pages_columns() {
+ $posts_columns = array();
+ $posts_columns['cb'] = '<input type="checkbox" onclick="checkAll(document.getElementById(\'posts-filter\'));" />';
+ if ( 'draft' === $_GET['post_status'] )
+ $posts_columns['modified'] = __('Modified');
+ elseif ( 'pending' === $_GET['post_status'] )
+ $posts_columns['modified'] = __('Submitted');
+ else
+ $posts_columns['date'] = __('Date');
+ $posts_columns['title'] = __('Title');
+ $posts_columns['author'] = __('Author');
+ if ( !in_array($_GET['post_status'], array('pending', 'draft', 'future')) )
+ $posts_columns['comments'] = '<div class="vers"><img alt="" src="images/comment-grey-bubble.png" /></div>';
+ $posts_columns['status'] = __('Status');
+ $posts_columns = apply_filters('manage_pages_columns', $posts_columns);
+
+ return $posts_columns;
+}
+
+/*
+ * display one row if the page doesn't have any children
+ * otherwise, display the row and its children in subsequent rows
+ */
+function display_page_row( $page, &$children_pages, $level = 0 ) {
+ global $post;
+ static $class;
+
+ $post = $page;
+ setup_postdata($page);
+
+ $page->post_title = wp_specialchars( $page->post_title );
+ $pad = str_repeat( '&#8212; ', $level );
+ $id = (int) $page->ID;
+ $class = ('alternate' == $class ) ? '' : 'alternate';
+ $posts_columns = wp_manage_pages_columns();
+ $title = get_the_title();
+ if ( empty($title) )
+ $title = __('(no title)');
?>
<tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
- <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th>
- <td>
- <?php echo $pad; ?><?php the_title() ?>
- </td>
- <td><?php the_author() ?></td>
- <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td>
- <td><a href="<?php the_permalink(); ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td>
- <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
- <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
- </tr>
+
+
+ <?php
+
+foreach ($posts_columns as $column_name=>$column_display_name) {
+
+ switch ($column_name) {
+
+ case 'cb':
+ ?>
+ <th scope="row" class="check-column"><input type="checkbox" name="delete[]" value="<?php the_ID(); ?>" /></th>
+ <?php
+ break;
+ case 'modified':
+ case 'date':
+ if ( '0000-00-00 00:00:00' == $page->post_date && 'date' == $column_name ) {
+ $t_time = $h_time = __('Unpublished');
+ } else {
+ if ( 'modified' == $column_name ) {
+ $t_time = get_the_modified_time(__('Y/m/d g:i:s A'));
+ $m_time = $page->post_modified;
+ $time = get_post_modified_time('G', true);
+ } else {
+ $t_time = get_the_time(__('Y/m/d g:i:s A'));
+ $m_time = $page->post_date;
+ $time = get_post_time('G', true);
+ }
+ if ( ( abs(time() - $time) ) < 86400 ) {
+ if ( ( 'future' == $page->post_status) )
+ $h_time = sprintf( __('%s from now'), human_time_diff( $time ) );
+ else
+ $h_time = sprintf( __('%s ago'), human_time_diff( $time ) );
+ } else {
+ $h_time = mysql2date(__('Y/m/d'), $m_time);
+ }
+ }
+ ?>
+ <td><abbr title="<?php echo $t_time ?>"><?php echo $h_time ?></abbr></td>
+ <?php
+ break;
+ case 'title':
+ ?>
+ <td><strong><a class="row-title" href="page.php?action=edit&amp;post=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $pad; echo $title ?></a></strong>
+ <?php if ('private' == $page->post_status) _e(' &#8212; <strong>Private</strong>'); ?></td>
+ <?php
+ break;
+
+ case 'comments':
+ ?>
+ <td class="num"><div class="post-com-count-wrapper">
+ <?php
+ $left = get_pending_comments_num( $page->ID );
+ $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
+ if ( $left )
+ echo '<strong>';
+ comments_number("<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('0') . '</span></a>', "<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('1') . '</span></a>', "<a href='edit-pages.php?page_id=$id' title='$pending_phrase' class='post-com-count'><span class='comment-count'>" . __('%') . '</span></a>');
+ if ( $left )
+ echo '</strong>';
+ ?>
+ </div></td>
+ <?php
+ break;
+
+ case 'author':
+ ?>
+ <td><a href="edit-pages.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
+ <?php
+ break;
+
+ case 'status':
+ ?>
+ <td>
+ <a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
+ <?php
+ switch ( $page->post_status ) {
+ case 'publish' :
+ case 'private' :
+ _e('Published');
+ break;
+ case 'future' :
+ _e('Scheduled');
+ break;
+ case 'pending' :
+ _e('Pending Review');
+ break;
+ case 'draft' :
+ _e('Unpublished');
+ break;
+ }
+ ?>
+ </a>
+ </td>
+ <?php
+ break;
+
+ default:
+ ?>
+ <td><?php do_action('manage_pages_custom_column', $column_name, $id); ?></td>
+ <?php
+ break;
+ }
+}
+ ?>
+
+ </tr>
<?php
- if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
+
+ if ( ! $children_pages )
+ return true;
+
+ for ( $i = 0; $i < count($children_pages); $i++ ) {
+
+ $child = $children_pages[$i];
+
+ if ( $child->post_parent == $id ) {
+ array_splice($children_pages, $i, 1);
+ display_page_row($child, $children_pages, $level+1);
+ $i = -1; //as numeric keys in $children_pages are not preserved after splice
+ }
+ }
+}
+
+/*
+ * displays pages in hierarchical order
+ */
+function page_rows( $pages ) {
+ if ( ! $pages )
+ $pages = get_pages( 'sort_column=menu_order' );
+
+ if ( ! $pages )
+ return false;
+
+ // splice pages into two parts: those without parent and those with parent
+
+ $top_level_pages = array();
+ $children_pages = array();
+
+ foreach ( $pages as $page ) {
+
+ // catch and repair bad pages
+ if ( $page->post_parent == $page->ID ) {
+ $page->post_parent = 0;
+ $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $page->ID) );
+ clean_page_cache( $page->ID );
+ }
+
+ if ( 0 == $page->post_parent )
+ $top_level_pages[] = $page;
+ else
+ $children_pages[] = $page;
}
+
+ foreach ( $top_level_pages as $page )
+ display_page_row($page, $children_pages, 0);
+
+ /*
+ * display the remaining children_pages which are orphans
+ * having orphan requires parental attention
+ */
+ if ( count($children_pages) > 0 ) {
+ $empty_array = array();
+ foreach ( $children_pages as $orphan_page ) {
+ clean_page_cache( $orphan_page->ID);
+ display_page_row( $orphan_page, $empty_array, 0 );
+ }
+ }
}
-function user_row( $user_object, $style = '' ) {
- global $current_user;
+function user_row( $user_object, $style = '', $role = '' ) {
+ global $wp_roles;
- if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
+ $current_user = wp_get_current_user();
+
+ if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
$user_object = new WP_User( (int) $user_object );
$email = $user_object->user_email;
$url = $user_object->user_url;
@@ -214,33 +543,50 @@ function user_row( $user_object, $style = '' ) {
if ( strlen( $short_url ) > 35 )
$short_url = substr( $short_url, 0, 32 ).'...';
$numposts = get_usernumposts( $user_object->ID );
+ if ( current_user_can( 'edit_user', $user_object->ID ) ) {
+ if ($current_user->ID == $user_object->ID) {
+ $edit = 'profile.php';
+ } else {
+ $edit = clean_url( add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
+ }
+ $edit = "<a href=\"$edit\">$user_object->user_login</a>";
+ } else {
+ $edit = $user_object->user_login;
+ }
+ $role_name = translate_with_context($wp_roles->role_names[$role]);
$r = "<tr id='user-$user_object->ID'$style>
- <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
- <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
- <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
+ <th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>
+ <td><strong>$edit</strong></td>
+ <td>$user_object->first_name $user_object->last_name</td>
<td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
- <td><a href='$url' title='website: $url'>$short_url</a></td>";
- $r .= "\n\t\t<td align='center'>";
+ <td>$role_name</td>";
+ $r .= "\n\t\t<td class='num'>";
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
- $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts);
+ $r .= $numposts;
$r .= '</a>';
- }
- $r .= "</td>\n\t\t<td>";
- if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can( 'edit_user', $user_object->ID ) ) {
- $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" );
- $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>";
+ } else {
+ $r .= 0;
}
$r .= "</td>\n\t</tr>";
return $r;
}
-function _wp_get_comment_list( $s = false, $start, $num ) {
+function _wp_get_comment_list( $status = '', $s = false, $start, $num ) {
global $wpdb;
$start = abs( (int) $start );
$num = (int) $num;
+ if ( 'moderated' == $status )
+ $approved = "comment_approved = '0'";
+ elseif ( 'approved' == $status )
+ $approved = "comment_approved = '1'";
+ elseif ( 'spam' == $status )
+ $approved = "comment_approved = 'spam'";
+ else
+ $approved = "comment_approved != 'spam'";
+
if ( $s ) {
$s = $wpdb->escape($s);
$comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
@@ -249,10 +595,10 @@ function _wp_get_comment_list( $s = false, $start, $num ) {
comment_author_url LIKE ('%$s%') OR
comment_author_IP LIKE ('%$s%') OR
comment_content LIKE ('%$s%') ) AND
- comment_approved != 'spam'
- ORDER BY comment_date DESC LIMIT $start, $num");
+ $approved
+ ORDER BY comment_date_gmt DESC LIMIT $start, $num");
} else {
- $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" );
+ $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved ORDER BY comment_date_gmt DESC LIMIT $start, $num" );
}
update_comment_cache($comments);
@@ -262,46 +608,95 @@ function _wp_get_comment_list( $s = false, $start, $num ) {
return array($comments, $total);
}
-function _wp_comment_list_item( $id, $alt = 0 ) {
- global $authordata, $comment, $wpdb;
- $id = (int) $id;
- $comment =& get_comment( $id );
- $class = '';
+function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true ) {
+ global $comment, $post;
+ $comment = get_comment( $comment_id );
$post = get_post($comment->comment_post_ID);
$authordata = get_userdata($post->post_author);
- $comment_status = wp_get_comment_status($comment->comment_ID);
- if ( 'unapproved' == $comment_status )
- $class .= ' unapproved';
- if ( $alt % 2 )
- $class .= ' alternate';
- echo "<li id='comment-$comment->comment_ID' class='$class'>";
-?>
-<p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
+ $the_comment_status = wp_get_comment_status($comment->comment_ID);
+ $class = ('unapproved' == $the_comment_status) ? 'unapproved' : '';
-<?php comment_text() ?>
+ if ( current_user_can( 'edit_post', $post->ID ) ) {
+ $post_link = "<a href='" . get_comment_link() . "'>";
-<p><?php comment_date(__('M j, g:i A')); ?> &#8212; [
-<?php
-if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
- echo " <a href='comment.php?action=editcomment&amp;c=".$comment->comment_ID."'>" . __('Edit') . '</a>';
- echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> ';
- if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) {
- echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>';
- echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&amp;p=' . $comment->comment_post_ID . '&amp;c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>';
+ $post_link .= get_the_title($comment->comment_post_ID) . '</a>';
+
+ $edit_link_start = "<a class='row-title' href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . __('Edit comment') . "'>";
+ $edit_link_end = '</a>';
+ } else {
+ $post_link = get_the_title($comment->comment_post_ID);
+ $edit_link_start = $edit_link_end ='';
}
- echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&amp;dt=spam&amp;p=" . $comment->comment_post_ID . "&amp;c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> ";
-}
-$post = get_post($comment->comment_post_ID, OBJECT, 'display');
-$post_title = wp_specialchars( $post->post_title, 'double' );
-$post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title;
+
+ $author_url = get_comment_author_url();
+ if ( 'http://' == $author_url )
+ $author_url = '';
+ $author_url_display = $author_url;
+ if ( strlen($author_url_display) > 50 )
+ $author_url_display = substr($author_url_display, 0, 49) . '...';
+
+ $ptime = date('G', strtotime( $comment->comment_date ) );
+ if ( ( abs(time() - $ptime) ) < 86400 )
+ $ptime = sprintf( __('%s ago'), human_time_diff( $ptime ) );
+ else
+ $ptime = mysql2date(__('Y/m/d \a\t g:i A'), $comment->comment_date );
+
+ $delete_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
+ $approve_url = clean_url( wp_nonce_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "approve-comment_$comment->comment_ID" ) );
+ $unapprove_url = clean_url( wp_nonce_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID", "unapprove-comment_$comment->comment_ID" ) );
+ $spam_url = clean_url( wp_nonce_url( "comment.php?action=deletecomment&dt=spam&p=$comment->comment_post_ID&c=$comment->comment_ID", "delete-comment_$comment->comment_ID" ) );
+
?>
- ] &#8212; <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p>
- </li>
+ <tr id="comment-<?php echo $comment->comment_ID; ?>" class='<?php echo $class; ?>'>
+<?php if ( $checkbox ) : ?>
+ <td class="check-column"><?php if ( current_user_can('edit_post', $comment->comment_post_ID) ) { ?><input type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /><?php } ?></td>
+<?php endif; ?>
+ <td class="comment">
+ <p class="comment-author"><strong><?php echo $edit_link_start; comment_author(); echo $edit_link_end; ?></strong><br />
+ <?php if ( !empty($author_url) ) : ?>
+ <a href="<?php echo $author_url ?>"><?php echo $author_url_display; ?></a> |
+ <?php endif; ?>
+ <?php if ( current_user_can( 'edit_post', $post->ID ) ) : ?>
+ <?php if ( !empty($comment->comment_author_email) ): ?>
+ <?php comment_author_email_link() ?> |
+ <?php endif; ?>
+ <a href="edit-comments.php?s=<?php comment_author_IP() ?>&amp;mode=detail"><?php comment_author_IP() ?></a>
+ <?php endif; //current_user_can?>
+ </p>
+ <?php if ( 'detail' == $mode ) comment_text(); ?>
+ <p><?php printf(__('From %1$s, %2$s'), $post_link, $ptime) ?></p>
+ </td>
+ <td><?php comment_date(__('Y/m/d')); ?></td>
+ <td class="action-links">
<?php
+
+ $actions = array();
+
+ $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
+ $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
+
+ // we're looking at list of only approved or only unapproved comments
+ if ( 'moderated' == $comment_status ) {
+ $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a> | ';
+ unset($actions['unapprove']);
+ } elseif ( 'approved' == $comment_status ) {
+ $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a> | ';
+ unset($actions['approve']);
+ }
+
+ if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
+ $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1' title='" . __( 'Mark this comment as spam' ) . "'>" . __( 'Spam' ) . '</a> | ';
+ $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID delete'>" . __('Delete') . '</a>';
+ foreach ( $actions as $action => $link )
+ echo "<span class='$action'>$link</span>";
+ }
+ ?>
+ </td>
+ </tr>
+ <?php
}
function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {
- global $wpdb;
if (!$categories )
$categories = get_categories( 'hide_empty=0' );
@@ -323,10 +718,9 @@ function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $le
}
function list_meta( $meta ) {
- global $post_ID;
// Exit if no meta
if (!$meta ) {
- echo '<tbody id="the-list"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
+ echo '<tbody id="the-list" class="list:meta"><tr style="display: none;"><td>&nbsp;</td></tr></tbody>'; //TBODY needed for list-manipulation JS
return;
}
$count = 0;
@@ -338,43 +732,53 @@ function list_meta( $meta ) {
<th colspan='2'><?php _e( 'Action' ) ?></th>
</tr>
</thead>
+ <tbody id='the-list' class='list:meta'>
<?php
- $r ="\n\t<tbody id='the-list'>";
- foreach ( $meta as $entry ) {
- ++ $count;
- if ( $count % 2 )
- $style = 'alternate';
- else
- $style = '';
- if ('_' == $entry['meta_key'] { 0 } )
- $style .= ' hidden';
-
- if ( is_serialized( $entry['meta_value'] ) ) {
- if ( is_serialized_string( $entry['meta_value'] ) ) {
- // this is a serialized string, so we should display it
- $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
- } else {
- // this is a serialized array/object so we should NOT display it
- --$count;
- continue;
- }
- }
+ foreach ( $meta as $entry )
+ echo _list_meta_row( $entry, $count );
+ echo "\n\t</tbody>";
+}
+
+function _list_meta_row( $entry, &$count ) {
+ static $update_nonce = false;
+ if ( !$update_nonce )
+ $update_nonce = wp_create_nonce( 'add-meta' );
- $key_js = js_escape( $entry['meta_key'] );
- $entry['meta_key'] = attribute_escape($entry['meta_key']);
- $entry['meta_value'] = attribute_escape($entry['meta_value']);
- $entry['meta_id'] = (int) $entry['meta_id'];
- $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
- $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
- $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
- $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".attribute_escape(__( 'Update' ))."' /><br />";
- $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '";
- $r .= js_escape(sprintf( __("You are about to delete the '%s' custom field on this post.\n'OK' to delete, 'Cancel' to stop." ), $key_js ) );
- $r .= "' );\" class='deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' /></td>";
- $r .= "\n\t</tr>";
+ $r = '';
+ ++ $count;
+ if ( $count % 2 )
+ $style = 'alternate';
+ else
+ $style = '';
+ if ('_' == $entry['meta_key'] { 0 } )
+ $style .= ' hidden';
+
+ if ( is_serialized( $entry['meta_value'] ) ) {
+ if ( is_serialized_string( $entry['meta_value'] ) ) {
+ // this is a serialized string, so we should display it
+ $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] );
+ } else {
+ // this is a serialized array/object so we should NOT display it
+ --$count;
+ return;
+ }
}
- echo $r;
- echo "\n\t</tbody>";
+
+ $entry['meta_key'] = attribute_escape($entry['meta_key']);
+ $entry['meta_value'] = htmlspecialchars($entry['meta_value']); // using a <textarea />
+ $entry['meta_id'] = (int) $entry['meta_id'];
+
+ $delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
+
+ $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>";
+ $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>";
+ $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>";
+ $r .= "\n\t\t<td style='text-align: center;'><input name='updatemeta' type='submit' tabindex='6' value='".attribute_escape(__( 'Update' ))."' class='add:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$update_nonce updatemeta' /><br />";
+ $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' ";
+ $r .= "class='delete:the-list:meta-{$entry['meta_id']}::_ajax_nonce=$delete_nonce deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' />";
+ $r .= wp_nonce_field( 'change-meta', '_ajax_nonce', false, false );
+ $r .= "</td>\n\t</tr>";
+ return $r;
}
function meta_form() {
@@ -390,14 +794,14 @@ function meta_form() {
if ( $keys )
natcasesort($keys);
?>
-<h3><?php _e( 'Add a new custom field:' ) ?></h3>
+<p><strong><?php _e( 'Add a new custom field:' ) ?></strong></p>
<table id="newmeta" cellspacing="3" cellpadding="3">
<tr>
<th colspan="2"><?php _e( 'Key' ) ?></th>
<th><?php _e( 'Value' ) ?></th>
</tr>
<tr valign="top">
- <td align="right" width="18%">
+ <td style="width: 18%;" class="textright">
<?php if ( $keys ) : ?>
<select id="metakeyselect" name="metakeyselect" tabindex="7">
<option value="#NONE#"><?php _e( '- Select -' ); ?></option>
@@ -414,9 +818,11 @@ function meta_form() {
<td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td>
<td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td>
</tr>
-
+<tr class="submit"><td colspan="3">
+ <?php wp_nonce_field( 'add-meta', '_ajax_nonce', false ); ?>
+ <input type="submit" id="addmetasub" name="addmeta" class="add:the-list:newmeta::post_id=<?php echo $GLOBALS['post_ID'] ? $GLOBALS['post_ID'] : $GLOBALS['temp_ID']; ?>" tabindex="9" value="<?php _e( 'Add Custom Field' ) ?>" />
+</td></tr>
</table>
-<p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field &raquo;' ) ?>" /></p>
<?php
}
@@ -426,12 +832,12 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
if ( $for_post )
$edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
-
+
$tab_index_attribute = '';
if ( (int) $tab_index > 0 )
$tab_index_attribute = " tabindex=\"$tab_index\"";
- echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
+ // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
$time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
$post_date = ($for_post) ? $post->post_date : $comment->comment_date;
@@ -442,28 +848,27 @@ function touch_time( $edit = 1, $for_post = 1, $tab_index = 0 ) {
$mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
$ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
- echo "<select name=\"mm\" onchange=\"edit_date.checked=true\"$tab_index_attribute>\n";
+ $month = "<select id=\"mm\" name=\"mm\"$tab_index_attribute>\n";
for ( $i = 1; $i < 13; $i = $i +1 ) {
- echo "\t\t\t<option value=\"$i\"";
+ $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
if ( $i == $mm )
- echo ' selected="selected"';
- echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
- }
-?>
-</select>
-<input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
-<input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> @
-<input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> /> :
-<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true"<?php echo $tab_index_attribute ?> />
-<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
-<?php
- if ( $edit ) {
- printf( _c( 'Existing timestamp: %1$s %2$s, %3$s @ %4$s:%5$s|1: month, 2: month string, 3: full year, 4: hours, 5: minutes' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn );
+ $month .= ' selected="selected"';
+ $month .= '>' . $wp_locale->get_month( $i ) . "</option>\n";
}
+ $month .= '</select>';
+
+ $day = '<input type="text" id="jj" name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
+ $year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off" />';
+ $hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
+ $minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
+ printf(_c('%1$s%2$s, %3$s <br />@ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute);
+ echo "\n\n";
+ foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
+ echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
?>
-</fieldset>
- <?php
+<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
+<?php
}
function page_template_dropdown( $default = '' ) {
@@ -507,12 +912,12 @@ function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {
function browse_happy() {
$getit = __( 'WordPress recommends a better browser' );
echo '
- <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p>
+ <span id="bh" class="alignright"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></span>
';
}
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
- add_action( 'admin_footer', 'browse_happy' );
+ add_action( 'in_admin_footer', 'browse_happy' );
function the_attachment_links( $id = false ) {
$id = (int) $id;
@@ -560,11 +965,13 @@ function the_attachment_links( $id = false ) {
function wp_dropdown_roles( $default = false ) {
global $wp_roles;
$r = '';
- foreach( array_reverse($wp_roles->role_names) as $role => $name )
+ foreach( $wp_roles->role_names as $role => $name ) {
+ $name = translate_with_context($name);
if ( $default == $role ) // Make default first in list
$p = "\n\t<option selected='selected' value='$role'>$name</option>";
else
$r .= "\n\t<option value='$role'>$name</option>";
+ }
echo $p . $r;
}
@@ -588,10 +995,15 @@ function wp_convert_bytes_to_hr( $bytes ) {
return $size . $units[$power];
}
-function wp_import_upload_form( $action ) {
+function wp_max_upload_size() {
$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
- $bytes = apply_filters( 'import_upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
+ $bytes = apply_filters( 'upload_size_limit', min($u_bytes, $p_bytes), $u_bytes, $p_bytes );
+ return $bytes;
+}
+
+function wp_import_upload_form( $action ) {
+ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
$size = wp_convert_bytes_to_hr( $bytes );
?>
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>">
@@ -603,7 +1015,7 @@ function wp_import_upload_form( $action ) {
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
</p>
<p class="submit">
-<input type="submit" value="<?php _e( 'Upload file and import &raquo;' ); ?>" />
+<input type="submit" class="button" value="<?php _e( 'Upload file and import' ); ?>" />
</p>
</form>
<?php
@@ -616,4 +1028,44 @@ function wp_remember_old_slug() {
echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
}
+/**
+ * add_meta_box() - Add a meta box to an edit form
+ *
+ * @since 2.5
+ *
+ * @param string $id String for use in the 'id' attribute of tags.
+ * @param string $title Title of the meta box
+ * @param string $callback Function that fills the box with the desired content. The function should echo its output.
+ * @param string $page The type of edit page on which to show the box (post, page, link)
+ * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
+ */
+function add_meta_box($id, $title, $callback, $page, $context = 'advanced') {
+ global $wp_meta_boxes;
+
+ if ( !isset($wp_meta_boxes) )
+ $wp_meta_boxes = array();
+ if ( !isset($wp_meta_boxes[$page]) )
+ $wp_meta_boxes[$page] = array();
+ if ( !isset($wp_meta_boxes[$page][$context]) )
+ $wp_meta_boxes[$page][$context] = array();
+
+ $wp_meta_boxes[$page][$context][] = array('id' => $id, 'title' => $title, 'callback' => $callback);
+}
+
+function do_meta_boxes($page, $context, $object) {
+ global $wp_meta_boxes;
+
+ if ( !isset($wp_meta_boxes) || !isset($wp_meta_boxes[$page]) || !isset($wp_meta_boxes[$page][$context]) )
+ return;
+
+ foreach ( (array) $wp_meta_boxes[$page][$context] as $box ) {
+ echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . '">' . "\n";
+ echo "<h3>{$box['title']}</h3>\n";
+ echo '<div class="inside">' . "\n";
+ call_user_func($box['callback'], $object, $box);
+ echo "</div>\n";
+ echo "</div>\n";
+ }
+}
+
?>
diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php
index bd39dea..7dae5be 100644
--- a/wp-admin/includes/theme.php
+++ b/wp-admin/includes/theme.php
@@ -14,6 +14,7 @@ function current_theme_info() {
$ct->screenshot = $themes[$current_theme]['Screenshot'];
$ct->description = $themes[$current_theme]['Description'];
$ct->author = $themes[$current_theme]['Author'];
+ $ct->tags = $themes[$current_theme]['Tags'];
return $ct;
}
diff --git a/wp-admin/includes/update.php b/wp-admin/includes/update.php
index cbd0d4a..70d1441 100644
--- a/wp-admin/includes/update.php
+++ b/wp-admin/includes/update.php
@@ -1,8 +1,9 @@
<?php
/*
-// The admin side of our 1.0 update system
-function core_update_footer( $msg ) {
+// The admin side of our 1.1 update system
+
+function core_update_footer( $msg = '' ) {
if ( !current_user_can('manage_options') )
return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
@@ -10,16 +11,18 @@ function core_update_footer( $msg ) {
switch ( $cur->response ) {
case 'development' :
- return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], 'http://wordpress.org/download/svn/' );
+ return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
break;
case 'upgrade' :
- return sprintf( '| <strong>'.__( 'Your WordPress %s is out of date. <a href="%s">Please update</a>.' ).'</strong>', $GLOBALS['wp_version'], $cur->url );
- break;
+ if ( current_user_can('manage_options') ) {
+ return sprintf( '| <strong>'.__( '<a href="%2$s">Get Version %3$s</a>' ).'</strong>', $GLOBALS['wp_version'], $cur->url, $cur->current );
+ break;
+ }
case 'latest' :
default :
- return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
+ return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'], $cur->url, $cur->current );
break;
}
}
@@ -32,14 +35,25 @@ function update_nag() {
return false;
if ( current_user_can('manage_options') )
- $msg = sprintf( __('A new version of WordPress is available! <a href="%s">Please update now</a>.'), $cur->url );
+ $msg = sprintf( __('WordPress %2$s is available! <a href="%1$s">Please update now</a>.'), $cur->url, $cur->current );
else
- $msg = __('A new version of WordPress is available! Please notify the site administrator.');
+ $msg = sprintf( __('WordPress %2$s is available! Please notify the site administrator.'), $cur->url, $cur->current );
echo "<div id='update-nag'>$msg</div>";
}
add_action( 'admin_notices', 'update_nag', 3 );
+// Called directly from dashboard
+function update_right_now_message() {
+ $cur = get_option( 'update_core' );
+
+ $msg = sprintf( __('This is WordPress version %s.'), $GLOBALS['wp_version'] );
+ if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') )
+ $msg .= " <a href='$cur->url' class='rbutton'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
+
+ echo "<span id='wp-version-message'>$msg</span>";
+}
+
function wp_update_plugins() {
global $wp_version;
@@ -62,7 +76,7 @@ function wp_update_plugins() {
continue;
}
- if ( $current->checked[ $file ] != $p['Version'] )
+ if ( strval($current->checked[ $file ]) !== strval($p['Version']) )
$plugin_changed = true;
}
@@ -114,9 +128,123 @@ function wp_plugin_update_row( $file ) {
$r = $current->response[ $file ];
echo "<tr><td colspan='5' class='plugin-update'>";
- printf( __('There is a new version of %s available. <a href="%s">Download version %s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version );
+ if ( !current_user_can('edit_plugins') )
+ printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version);
+ else if ( empty($r->package) )
+ printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a> <em>automatic upgrade unavailable for this plugin</em>.'), $plugin_data['Name'], $r->url, $r->new_version);
+ else
+ printf( __('There is a new version of %1$s available. <a href="%2$s">Download version %3$s here</a> or <a href="%4$s">upgrade automatically</a>.'), $plugin_data['Name'], $r->url, $r->new_version, wp_nonce_url("update.php?action=upgrade-plugin&amp;plugin=$file", 'upgrade-plugin_' . $file) );
+
echo "</td></tr>";
}
add_action( 'after_plugin_row', 'wp_plugin_update_row' );
+
+function wp_update_plugin($plugin, $feedback = '') {
+ global $wp_filesystem;
+
+ if ( !empty($feedback) )
+ add_filter('update_feedback', $feedback);
+
+ // Is an update available?
+ $current = get_option( 'update_plugins' );
+ if ( !isset( $current->response[ $plugin ] ) )
+ return new WP_Error('up_to_date', __('The plugin is at the latest version.'));
+
+ // Is a filesystem accessor setup?
+ if ( ! $wp_filesystem || !is_object($wp_filesystem) )
+ WP_Filesystem();
+
+ if ( ! is_object($wp_filesystem) )
+ return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
+
+ if ( $wp_filesystem->errors->get_error_code() )
+ return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
+
+ //Get the Base folder
+ $base = $wp_filesystem->get_base_dir();
+
+ if ( empty($base) )
+ return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));
+
+ // Get the URL to the zip file
+ $r = $current->response[ $plugin ];
+
+ if ( empty($r->package) )
+ return new WP_Error('no_package', __('Upgrade package not available.'));
+
+ // Download the package
+ $package = $r->package;
+ apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
+ $file = download_url($package);
+
+ if ( is_wp_error($file) )
+ return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
+
+ $working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php');
+
+ // Clean up working directory
+ if ( $wp_filesystem->is_dir($working_dir) )
+ $wp_filesystem->delete($working_dir, true);
+
+ apply_filters('update_feedback', __('Unpacking the update'));
+ // Unzip package to working directory
+ $result = unzip_file($file, $working_dir);
+ if ( is_wp_error($result) ) {
+ unlink($file);
+ $wp_filesystem->delete($working_dir, true);
+ return $result;
+ }
+
+ // Once extracted, delete the package
+ unlink($file);
+
+ if ( is_plugin_active($plugin) ) {
+ //Deactivate the plugin silently, Prevent deactivation hooks from running.
+ apply_filters('update_feedback', __('Deactivating the plugin'));
+ deactivate_plugins($plugin, true);
+ }
+
+ // Remove the existing plugin.
+ apply_filters('update_feedback', __('Removing the old version of the plugin'));
+ $plugin_dir = dirname($base . PLUGINDIR . "/$plugin");
+ $plugin_dir = trailingslashit($plugin_dir);
+
+ // If plugin is in its own directory, recursively delete the directory.
+ if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
+ $deleted = $wp_filesystem->delete($plugin_dir, true);
+ else
+ $deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin");
+
+ if ( !$deleted ) {
+ $wp_filesystem->delete($working_dir, true);
+ return new WP_Error('delete_failed', __('Could not remove the old plugin'));
+ }
+
+ apply_filters('update_feedback', __('Installing the latest version'));
+ // Copy new version of plugin into place.
+ if ( !copy_dir($working_dir, $base . PLUGINDIR) ) {
+ //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
+ return new WP_Error('install_failed', __('Installation failed'));
+ }
+
+ //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
+ $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
+
+ // Remove working directory
+ $wp_filesystem->delete($working_dir, true);
+
+ // Force refresh of plugin update information
+ delete_option('update_plugins');
+
+ if( empty($filelist) )
+ return false; //We couldnt find any files in the working dir
+
+ $folder = $filelist[0];
+ $plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder,
+ $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
+
+ return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
+}
+
*/
?>
diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php
index 797e6e7..1cc9df9 100644
--- a/wp-admin/includes/upgrade.php
+++ b/wp-admin/includes/upgrade.php
@@ -6,7 +6,7 @@ require_once(ABSPATH . 'wp-admin/includes/admin.php');
require_once(ABSPATH . 'wp-admin/includes/schema.php');
if ( !function_exists('wp_install') ) :
-function wp_install($blog_title, $user_name, $user_email, $public, $meta='') {
+function wp_install($blog_title, $user_name, $user_email, $public, $deprecated='') {
global $wp_rewrite;
wp_check_mysql_version();
@@ -35,7 +35,7 @@ function wp_install($blog_title, $user_name, $user_email, $public, $meta='') {
// being shared among blogs. Just set the role in that case.
$user_id = username_exists($user_name);
if ( !$user_id ) {
- $random_password = substr(md5(uniqid(microtime())), 0, 6);
+ $random_password = wp_generate_password();
$user_id = wp_create_user($user_name, $random_password, $user_email);
} else {
$random_password = __('User already exists. Password inherited.');
@@ -105,7 +105,8 @@ function wp_install_defaults($user_id) {
$wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.'))."')");
// First Page
- $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'publish', 'page', '', '', '')");
+ $first_post_guid = get_option('home') . '/?page_id=2';
+ $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt','$first_post_guid', 'publish', 'page', '', '', '')");
}
endif;
@@ -198,6 +199,9 @@ function upgrade_all() {
if ( $wp_current_db_version < 6124 )
upgrade_230_old_tables();
+ if ( $wp_current_db_version < 7499 )
+ upgrade_250();
+
maybe_disable_automattic_widgets();
$wp_rewrite->flush_rules();
@@ -724,6 +728,15 @@ function upgrade_old_slugs() {
}
+function upgrade_250() {
+ global $wp_current_db_version;
+
+ if ( $wp_current_db_version < 6689 ) {
+ populate_roles_250();
+ }
+
+}
+
// The functions we use to actually do stuff
// General
@@ -1253,12 +1266,10 @@ function translate_level_to_role($level) {
}
function wp_check_mysql_version() {
- global $wp_version;
-
- // Make sure the server has MySQL 4.0
- $mysql_version = preg_replace('|[^0-9\.]|', '', @mysql_get_server_info());
- if ( version_compare($mysql_version, '4.0.0', '<') )
- die(sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
+ global $wpdb;
+ $result = $wpdb->check_database_version();
+ if ( is_wp_error( $result ) )
+ die( $result->get_error_message() );
}
function maybe_disable_automattic_widgets() {
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php
index ca15057..e423465 100644
--- a/wp-admin/includes/user.php
+++ b/wp-admin/includes/user.php
@@ -73,6 +73,13 @@ function edit_user( $user_id = 0 ) {
else
$user->rich_editing = 'false';
+ if ( !$update )
+ $user->admin_color = 'fresh'; // Default to fresh for new users.
+ else if ( isset( $_POST['admin_color'] ) )
+ $user->admin_color = $_POST['admin_color'];
+ else
+ $user->admin_color = 'fresh';
+
$errors = new WP_Error();
/* checking that username has been typed */
@@ -82,37 +89,41 @@ function edit_user( $user_id = 0 ) {
/* checking the password has been typed twice */
do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 ));
- if (!$update ) {
- if ( $pass1 == '' || $pass2 == '' )
- $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ));
+ if ( $update ) {
+ if ( empty($pass1) && !empty($pass2) )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass1' ) );
+ elseif ( !empty($pass1) && empty($pass2) )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass2' ) );
} else {
- if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) )
- $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." ));
+ if ( empty($pass1) )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password.' ), array( 'form-field' => 'pass1' ) );
+ elseif ( empty($pass2) )
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ), array( 'form-field' => 'pass2' ) );
}
/* Check for "\" in password */
if( strpos( " ".$pass1, "\\" ) )
- $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ));
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) );
/* checking the password has been typed twice the same */
if ( $pass1 != $pass2 )
- $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' ));
+ $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) );
if (!empty ( $pass1 ))
$user->user_pass = $pass1;
if ( !$update && !validate_username( $user->user_login ) )
- $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
+ $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' ));
if (!$update && username_exists( $user->user_login ))
- $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ));
+ $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ));
/* checking e-mail address */
if ( empty ( $user->user_email ) ) {
- $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" ));
+ $errors->add( 'user_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) );
} else
if (!is_email( $user->user_email ) ) {
- $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" ));
+ $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) );
}
if ( $errors->get_error_codes() )
@@ -186,8 +197,6 @@ function get_nonauthor_user_ids() {
function get_others_unpublished_posts($user_id, $type='any') {
global $wpdb;
- $user = get_userdata( $user_id );
- $level_key = $wpdb->prefix . 'user_level';
$editable = get_editable_user_ids( $user_id );
@@ -245,7 +254,6 @@ function wp_delete_user($id, $reassign = 'novalue') {
global $wpdb;
$id = (int) $id;
- $user = get_userdata($id);
if ($reassign == 'novalue') {
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id");
@@ -270,6 +278,7 @@ function wp_delete_user($id, $reassign = 'novalue') {
wp_cache_delete($id, 'users');
wp_cache_delete($user->user_login, 'userlogins');
+ wp_cache_delete($user->user_email, 'useremail');
return true;
}
@@ -281,4 +290,108 @@ function wp_revoke_user($id) {
$user->remove_all_caps();
}
+// WP_User_Search class
+// by Mark Jaquith
+
+if ( !class_exists('WP_User_Search') ) :
+class WP_User_Search {
+ var $results;
+ var $search_term;
+ var $page;
+ var $role;
+ var $raw_page;
+ var $users_per_page = 50;
+ var $first_user;
+ var $last_user;
+ var $query_limit;
+ var $query_sort;
+ var $query_from_where;
+ var $total_users_for_query = 0;
+ var $too_many_total_users = false;
+ var $search_errors;
+
+ function WP_User_Search ($search_term = '', $page = '', $role = '') { // constructor
+ $this->search_term = $search_term;
+ $this->raw_page = ( '' == $page ) ? false : (int) $page;
+ $this->page = (int) ( '' == $page ) ? 1 : $page;
+ $this->role = $role;
+
+ $this->prepare_query();
+ $this->query();
+ $this->prepare_vars_for_template_usage();
+ $this->do_paging();
+ }
+
+ function prepare_query() {
+ global $wpdb;
+ $this->first_user = ($this->page - 1) * $this->users_per_page;
+ $this->query_limit = ' LIMIT ' . $this->first_user . ',' . $this->users_per_page;
+ $this->query_sort = ' ORDER BY user_login';
+ $search_sql = '';
+ if ( $this->search_term ) {
+ $searches = array();
+ $search_sql = 'AND (';
+ foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col )
+ $searches[] = $col . " LIKE '%$this->search_term%'";
+ $search_sql .= implode(' OR ', $searches);
+ $search_sql .= ')';
+ }
+
+ $this->query_from_where = "FROM $wpdb->users";
+ if ( $this->role )
+ $this->query_from_where .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE '%$this->role%'";
+ else
+ $this->query_from_where .= " WHERE 1=1";
+ $this->query_from_where .= " $search_sql";
+
+ }
+
+ function query() {
+ global $wpdb;
+ $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_sort . $this->query_limit);
+
+ if ( $this->results )
+ $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit
+ else
+ $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!'));
+ }
+
+ function prepare_vars_for_template_usage() {
+ $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone
+ }
+
+ function do_paging() {
+ if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results
+ $this->paging_text = paginate_links( array(
+ 'total' => ceil($this->total_users_for_query / $this->users_per_page),
+ 'current' => $this->page,
+ 'base' => 'users.php?%_%',
+ 'format' => 'userspage=%#%',
+ 'add_args' => array( 'usersearch' => urlencode($this->search_term) )
+ ) );
+ }
+ }
+
+ function get_results() {
+ return (array) $this->results;
+ }
+
+ function page_links() {
+ echo $this->paging_text;
+ }
+
+ function results_are_paged() {
+ if ( $this->paging_text )
+ return true;
+ return false;
+ }
+
+ function is_search() {
+ if ( $this->search_term )
+ return true;
+ return false;
+ }
+}
+endif;
+
?>
diff --git a/wp-admin/includes/widgets.php b/wp-admin/includes/widgets.php
index 4523b24..bd425f9 100644
--- a/wp-admin/includes/widgets.php
+++ b/wp-admin/includes/widgets.php
@@ -2,7 +2,7 @@
// $_search is unsanitized
function wp_list_widgets( $show = 'all', $_search = false ) {
- global $wp_registered_widgets, $sidebars_widgets;
+ global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
if ( $_search ) {
// sanitize
$search = preg_replace( '/[^\w\s]/', '', $_search );
@@ -52,17 +52,31 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
$widget_control_template = ob_get_contents();
ob_end_clean();
+ $widget_id = $widget['id']; // save this for later in case we mess with $widget['id']
+
$is_multi = false !== strpos( $widget_control_template, '%i%' );
if ( !$sidebar || $is_multi ) {
- if ( $is_multi )
- $already_shown[] = $widget['callback']; // it's a multi-widget. We only need to show it in the list once.
- $action = 'add';
- $add_url = wp_nonce_url( add_query_arg( array(
+ $add_query = array(
'sidebar' => $sidebar,
- 'add' => $widget['id'],
'key' => false,
'edit' => false
- ) ), "add-widget_$widget[id]" );
+ );
+ if ( $is_multi ) {
+ // it's a multi-widget. We only need to show it in the list once.
+ $already_shown[] = $widget['callback'];
+ $num = (int) array_pop( explode( '-', $widget['id'] ) );
+ $id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
+ // so that we always add a new one when clicking "add"
+ while ( isset($wp_registered_widgets["$id_base-$num"]) )
+ $num++;
+ $widget['id'] = "$id_base-$num";
+ $add_query['base'] = $id_base;
+ $add_query['key'] = $num;
+ $add_query['sidebar'] = $GLOBALS['sidebar'];
+ }
+ $add_query['add'] = $widget['id'];
+ $action = 'add';
+ $add_url = wp_nonce_url( add_query_arg( $add_query ), "add-widget_$widget[id]" );
} else {
$action = 'edit';
$edit_url = clean_url( add_query_arg( array(
@@ -110,7 +124,7 @@ function wp_list_widgets( $show = 'all', $_search = false ) {
<?php endif; ?>
<div class="widget-description">
- <?php echo ( $widget_description = wp_widget_description( $widget['id'] ) ) ? $widget_description : '&nbsp;'; ?>
+ <?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? $widget_description : '&nbsp;'; ?>
</div>
<br class="clear" />
@@ -174,7 +188,7 @@ function wp_widget_control( $sidebar_args ) {
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
- $edit = $edit_widget > 0 && $key && $edit_widget == $key; // (bool) are we currently editing this widget
+ $edit = -1 < $edit_widget && is_numeric($key) && $edit_widget === $key; // (bool) are we currently editing this widget
$id_format = $widget['id'];
// We aren't showing a widget control, we're outputing a template for a mult-widget control
@@ -198,12 +212,11 @@ function wp_widget_control( $sidebar_args ) {
$wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
unset($wp_registered_widgets[$widget_id]['_callback']);
- if ( $widget_title )
- $widget_title = sprintf( _c('%1$s: %2$s|widget_admin_title' ), $sidebar_args['widget_name'], $widget_title );
+ if ( $widget_title && $widget_title != $control['name'] )
+ $widget_title = sprintf( _c('%1$s: %2$s|1: widget name, 2: widget title' ), $sidebar_args['widget_name'], $widget_title );
else
$widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) );
-
if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] )
echo $sidebar_args['before_widget'];
?>
@@ -241,7 +254,7 @@ function wp_widget_control( $sidebar_args ) {
<?php endif; ?>
- <a class="widget-action widget-control-remove delete alignright" href="<?php echo clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ), wp_nonce_url( null, "remove-widget_$widget[id]" ) ) ); ?>"><?php _e('Remove'); ?></a>
+ <a class="widget-action widget-control-remove delete alignright" href="<?php echo clean_url( wp_nonce_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ) ), "remove-widget_$widget[id]" ) ); ?>"><?php _e('Remove'); ?></a>
<br class="clear" />
</div>
</div>