From 034694eb53dd71a980745f5594509890fd761998 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 15 May 2006 03:19:56 +0000 Subject: Lots and lots of changes. git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@543 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-inst/wp-admin/admin-functions.php | 252 ++++++++++++++++++++++------------- 1 file changed, 162 insertions(+), 90 deletions(-) (limited to 'wp-inst/wp-admin/admin-functions.php') diff --git a/wp-inst/wp-admin/admin-functions.php b/wp-inst/wp-admin/admin-functions.php index b33f94e..527df20 100644 --- a/wp-inst/wp-admin/admin-functions.php +++ b/wp-inst/wp-admin/admin-functions.php @@ -75,8 +75,8 @@ function write_post() { $hh = ($hh > 23) ? $hh -24 : $hh; $mn = ($mn > 59) ? $mn -60 : $mn; $ss = ($ss > 59) ? $ss -60 : $ss; - $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; - $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss"); + $_POST['post_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); + $_POST['post_date_gmt'] = get_gmt_from_date($_POST['post_date']); } // Create the post. @@ -361,15 +361,38 @@ function get_category_to_edit($id) { return $category; } +function wp_dropdown_roles( $default = false ) { + global $wp_roles; + $r = ''; + foreach($wp_roles->role_names as $role => $name) + if ( $default == $role ) // Make default first in list + $p = "\n\t"; + else + $r .= "\n\t"; + echo $p . $r; +} + + // Creates a new user from the "Users" form using $_POST information. function add_user() { - return edit_user(); + if ( func_num_args() ) { // The hackiest hack that ever did hack + global $current_user, $wp_roles; + $user_id = func_get_arg(0); + if (isset ($_POST['role'])) { + if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) { + $user = new WP_User($user_id); + $user->set_role($_POST['role']); + } + } + } else { + add_action('user_register', 'add_user'); // See above + return edit_user(); + } } function edit_user($user_id = 0) { global $current_user, $wp_roles, $wpdb; - if ($user_id != 0) { $update = true; $user->ID = $user_id; @@ -417,49 +440,49 @@ function edit_user($user_id = 0) { if (isset ($_POST['yim'])) $user->yim = wp_specialchars(trim($_POST['yim'])); - $errors = array (); + $errors = new WP_Error(); /* checking that username has been typed */ if ($user->user_login == '') - $errors['user_login'] = __('ERROR: Please enter a username.'); + $errors->add('user_login', __('ERROR: Please enter a username.')); /* checking the password has been typed twice */ do_action('check_passwords', array ($user->user_login, & $pass1, & $pass2)); if (!$update) { if ($pass1 == '' || $pass2 == '') - $errors['pass'] = __('ERROR: Please enter your password twice.'); + $errors->add('pass', __('ERROR: Please enter your password twice.')); } else { if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))) - $errors['pass'] = __("ERROR: you typed your new password only once."); + $errors->add('pass', __("ERROR: you typed your new password only once.")); } /* Check for "\" in password */ if( strpos( " ".$pass1, "\\" ) ) - $errors['pass'] = __('ERROR: Passwords may not contain the character "\\".'); + $errors->add('pass', __('ERROR: Passwords may not contain the character "\\".')); /* checking the password has been typed twice the same */ if ($pass1 != $pass2) - $errors['pass'] = __('ERROR: Please type the same password in the two password fields.'); + $errors->add('pass', __('ERROR: Please type the same password in the two password fields.')); if (!empty ($pass1)) $user->user_pass = $pass1; if ( !validate_username($user->user_login) ) - $errors['user_login'] = __('ERROR: This username is invalid. Please enter a valid username.'); + $errors->add('user_login', __('ERROR: This username is invalid. Please enter a valid username.')); if (!$update && username_exists($user->user_login)) - $errors['user_login'] = __('ERROR: This username is already registered, please choose another one.'); + $errors->add('user_login', __('ERROR: This username is already registered, please choose another one.')); /* checking e-mail address */ if (empty ($user->user_email)) { - $errors['user_email'] = __("ERROR: please type an e-mail address"); + $errors->add('user_email', __("ERROR: please type an e-mail address")); } else if (!is_email($user->user_email)) { - $errors['user_email'] = __("ERROR: the email address isn't correct"); + $errors->add('user_email', __("ERROR: the email address isn't correct")); } - if (count($errors) != 0) + if ( $errors->get_error_codes() ) return $errors; if ($update) { @@ -468,8 +491,7 @@ function edit_user($user_id = 0) { $user_id = wp_insert_user(get_object_vars($user)); wp_new_user_notification($user_id); } - - return $errors; + return $user_id; } @@ -481,6 +503,7 @@ function get_link_to_edit($link_id) { $link->link_description = wp_specialchars($link->link_description); $link->link_notes = wp_specialchars($link->link_notes); $link->link_rss = wp_specialchars($link->link_rss); + $link->post_category = $link->link_category; return $link; } @@ -514,14 +537,7 @@ function edit_link($link_id = '') { $_POST['link_name'] = wp_specialchars($_POST['link_name']); $_POST['link_image'] = wp_specialchars($_POST['link_image']); $_POST['link_rss'] = wp_specialchars($_POST['link_rss']); - $auto_toggle = get_autotoggle($_POST['link_category']); - - // if we are in an auto toggle category and this one is visible then we - // need to make the others invisible before we add this new one. - // FIXME Add category toggle func. - //if (($auto_toggle == 'Y') && ($link_visible == 'Y')) { - // $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category"); - //} + $_POST['link_category'] = $_POST['post_category']; if ( !empty($link_id) ) { $_POST['link_id'] = $link_id; @@ -553,7 +569,7 @@ function checked($checked, $current) { function return_categories_list($parent = 0) { global $wpdb; - return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC LIMIT 100"); + return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC"); } function sort_cats($cat1, $cat2) { @@ -561,7 +577,7 @@ function sort_cats($cat1, $cat2) { } function get_nested_categories($default = 0, $parent = 0) { - global $post_ID, $mode, $wpdb; + global $post_ID, $link_id, $mode, $wpdb; if ($post_ID) { $checked_categories = $wpdb->get_col(" @@ -574,7 +590,17 @@ function get_nested_categories($default = 0, $parent = 0) { // No selected categories, strange $checked_categories[] = $default; } + } else if ($link_id) { + $checked_categories = $wpdb->get_col(" + SELECT category_id + FROM $wpdb->categories, $wpdb->link2cat + WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' + "); + if (count($checked_categories) == 0) { + // No selected categories, strange + $checked_categories[] = $default; + } } else { $checked_categories[] = $default; } @@ -584,6 +610,10 @@ function get_nested_categories($default = 0, $parent = 0) { if (is_array($cats)) { foreach ($cats as $cat) { + if ( $cat == 0 ) { // HACK, added 2006-05-13 + $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); + continue; + } $result[$cat]['children'] = get_nested_categories($default, $cat); $result[$cat]['cat_ID'] = $cat; $result[$cat]['checked'] = in_array($cat, $checked_categories); @@ -598,12 +628,12 @@ function get_nested_categories($default = 0, $parent = 0) { function write_nested_categories($categories) { foreach ($categories as $category) { - echo '\n"; + echo '
  • \n"; - if (isset ($category['children'])) { - echo "\n\n"; + if ( $category['children'] ) { + echo "\n"; } } } @@ -621,15 +651,20 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) { if ($categories) { foreach ($categories as $category) { + if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 + $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); + continue; + } if ($category->category_parent == $parent) { - $category->cat_name = wp_specialchars($category->cat_name); + $category->cat_name = wp_specialchars($category->cat_name,'double'); $pad = str_repeat('— ', $level); if ( current_user_can('manage_categories') ) { $edit = "".__('Edit').""; $default_cat_id = get_option('default_category'); + $default_link_cat_id = get_option('default_link_category'); - if ($category->cat_ID != $default_cat_id) - $edit .= "cat_ID, '".sprintf(__("You are about to delete the category "%s". All of its posts will go to the default category.\\n"OK" to delete, "Cancel" to stop."), wp_specialchars($category->cat_name, 1))."' );\" class='delete'>".__('Delete').""; + if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) + $edit .= "cat_ID, '".sprintf(__("You are about to delete the category "%s".\\nAll of its posts will go into the default category of "%s"\\nAll of its bookmarks will go into the default category of "%s".\\n"OK" to delete, "Cancel" to stop."), addslashes($category->cat_name), addslashes(wp_specialchars(get_catname($default_cat_id),'double')), addslashes(wp_specialchars(get_catname($default_link_cat_id),'double')))."' );\" class='delete'>".__('Delete').""; else $edit .= "".__("Default"); } @@ -637,9 +672,13 @@ function cat_rows($parent = 0, $level = 0, $categories = 0) { $edit = ''; $class = ('alternate' == $class) ? '' : 'alternate'; + + $category->category_count = number_format( $category->category_count ); + $category->link_count = number_format( $category->link_count ); echo "$category->cat_ID$pad $category->cat_name $category->category_description - $category->category_count + $category->category_count + $category->link_count $edit "; cat_rows($category->cat_ID, $level +1, $categories); @@ -678,7 +717,7 @@ function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) { post_modified); ?> " . __('Edit') . ""; } ?> - " . __('Delete') . ""; } ?> + " . __('Delete') . ""; } ?> user_email; + $url = $user_object->user_url; + $short_url = str_replace('http://', '', $url); + $short_url = str_replace('www.', '', $short_url); + if ('/' == substr($short_url, -1)) + $short_url = substr($short_url, 0, -1); + if (strlen($short_url) > 35) + $short_url = substr($short_url, 0, 32).'...'; + $numposts = get_usernumposts($user_object->ID); + if (0 < $numposts) $numposts = "$numposts"; + $r = " + + + + $email + $short_url"; + $r .= "\n\t\t$numposts"; + $r .= "\n\t\t"; + if (current_user_can('edit_users')) + $r .= "".__('Edit').""; + $r .= "\n\t"; + return $r; +} + function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) { global $wpdb, $bgcolor; if (!$categories) { @@ -694,7 +760,6 @@ function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $lev if ($categories) { foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { - $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); $pad = str_repeat('– ', $level); $category->cat_name = wp_specialchars($category->cat_name); echo "\n\t\n"; + echo ' selected="selected"'; + echo '>' . $wp_locale->get_month($i) . "\n"; } ?> - - @ - : - - + + @ + : + + get_month($mm) . "$jj, $aa @ $hh:$mn"; + echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn); } ?> @@ -1023,11 +1089,15 @@ function insert_with_markers($filename, $marker, $insertion) { $foundit = false; if ($markerdata) { $state = true; - foreach ($markerdata as $markerline) { + foreach ($markerdata as $n => $markerline) { if (strstr($markerline, "# BEGIN {$marker}")) $state = false; - if ($state) - fwrite($f, "{$markerline}\n"); + if ($state) { + if ( $n + 1 < count($markerdata) ) + fwrite($f, "{$markerline}\n"); + else + fwrite($f, "{$markerline}"); + } if (strstr($markerline, "# END {$marker}")) { fwrite($f, "# BEGIN {$marker}\n"); if (is_array($insertion)) @@ -1829,8 +1899,10 @@ function wp_handle_upload(&$file, $overrides = false) { // Compute the URL $url = $uploads['url'] . "/$filename"; + + $return = apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type) ); - return array('file' => $new_file, 'url' => $url, 'type' => $type); + return $return; } function wp_shrink_dimensions($width, $height, $wmax = 128, $hmax = 96) { -- cgit