Changes in trunk/wp-admin/admin-functions.php [3501:4418]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r3501 r4418 1 1 <?php 2 2 3 function write_post() { 4 $result = wp_write_post(); 5 if( is_wp_error($result) ) 6 wp_die( $result->get_error_message() ); 7 else 8 return $result; 9 } 10 3 11 // Creates a new post from the "Write Post" form using $_POST information. 4 function w rite_post() {12 function wp_write_post() { 5 13 global $user_ID; 6 14 7 if (!current_user_can('edit_posts')) 8 die(__('You are not allowed to create posts or drafts on this blog.')); 15 if ( 'page' == $_POST['post_type'] ) { 16 if ( !current_user_can('edit_pages') ) 17 return new WP_Error('edit_pages', __('You are not allowed to create pages on this blog.')); 18 } else { 19 if ( !current_user_can('edit_posts') ) 20 return new WP_Error('edit_posts', __('You are not allowed to create posts or drafts on this blog.')); 21 } 9 22 10 23 // Rename. … … 16 29 if (!empty ($_POST['post_author_override'])) { 17 30 $_POST['post_author'] = (int) $_POST['post_author_override']; 18 } else 31 } else { 19 32 if (!empty ($_POST['post_author'])) { 20 33 $_POST['post_author'] = (int) $_POST['post_author']; … … 23 36 } 24 37 25 if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts')) 26 die(__('You cannot post as this user.')); 38 } 39 40 if ($_POST['post_author'] != $_POST['user_ID']) { 41 if ( 'page' == $_POST['post_type'] ) { 42 if ( !current_user_can('edit_others_pages') ) 43 return new WP_Error('edit_others_pages', __('You cannot create pages as this user.')); 44 } else { 45 if ( !current_user_can('edit_others_posts') ) 46 return new WP_Error('edit_others_posts', __('You cannot post as this user.')); 47 48 } 49 } 27 50 28 51 // What to do based on which button they pressed … … 35 58 if ('' != $_POST['advanced']) 36 59 $_POST['post_status'] = 'draft'; 37 if ('' != $_POST['savepage']) 38 $_POST['post_status'] = 'static'; 39 40 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) 60 61 if ( 'page' == $_POST['post_type'] ) { 62 if ('publish' == $_POST['post_status'] && !current_user_can('publish_pages')) 63 $_POST['post_status'] = 'draft'; 64 } else { 65 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) 66 $_POST['post_status'] = 'draft'; 67 } 68 69 if (!isset ($_POST['comment_status'])) 70 $_POST['comment_status'] = 'closed'; 71 72 if (!isset ($_POST['ping_status'])) 73 $_POST['ping_status'] = 'closed'; 74 75 if (!empty ($_POST['edit_date'])) { 76 $aa = $_POST['aa']; 77 $mm = $_POST['mm']; 78 $jj = $_POST['jj']; 79 $hh = $_POST['hh']; 80 $mn = $_POST['mn']; 81 $ss = $_POST['ss']; 82 $jj = ($jj > 31) ? 31 : $jj; 83 $hh = ($hh > 23) ? $hh -24 : $hh; 84 $mn = ($mn > 59) ? $mn -60 : $mn; 85 $ss = ($ss > 59) ? $ss -60 : $ss; 86 $_POST['post_date'] = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss); 87 $_POST['post_date_gmt'] = get_gmt_from_date($_POST['post_date']); 88 } 89 90 // Create the post. 91 $post_ID = wp_insert_post($_POST); 92 add_meta($post_ID); 93 94 // Reunite any orphaned attachments with their parent 95 if ( $_POST['temp_ID'] ) 96 relocate_children($_POST['temp_ID'], $post_ID); 97 98 // Now that we have an ID we can fix any attachment anchor hrefs 99 fix_attachment_links($post_ID); 100 101 return $post_ID; 102 } 103 104 // Move child posts to a new parent 105 function relocate_children($old_ID, $new_ID) { 106 global $wpdb; 107 $old_ID = (int) $old_ID; 108 $new_ID = (int) $new_ID; 109 return $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID"); 110 } 111 112 // Replace hrefs of attachment anchors with up-to-date permalinks. 113 function fix_attachment_links($post_ID) { 114 global $wp_rewrite; 115 116 $post = & get_post($post_ID, ARRAY_A); 117 118 $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; 119 120 // See if we have any rel="attachment" links 121 if ( 0 == preg_match_all($search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER) ) 122 return; 123 124 $i = 0; 125 $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; 126 foreach ( $anchor_matches[0] as $anchor ) { 127 if ( 0 == preg_match($search, $anchor, $id_matches) ) 128 continue; 129 130 $id = $id_matches[3]; 131 132 // While we have the attachment ID, let's adopt any orphans. 133 $attachment = & get_post($id, ARRAY_A); 134 if ( ! empty($attachment) && ! is_object(get_post($attachment['post_parent'])) ) { 135 $attachment['post_parent'] = $post_ID; 136 // Escape data pulled from DB. 137 $attachment = add_magic_quotes($attachment); 138 wp_update_post($attachment); 139 } 140 141 $post_search[$i] = $anchor; 142 $post_replace[$i] = preg_replace("#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor); 143 ++$i; 144 } 145 146 $post['post_content'] = str_replace($post_search, $post_replace, $post['post_content']); 147 148 // Escape data pulled from DB. 149 $post = add_magic_quotes($post); 150 151 return wp_update_post($post); 152 } 153 154 // Update an existing post with values provided in $_POST. 155 function edit_post() { 156 global $user_ID; 157 158 $post_ID = (int) $_POST['post_ID']; 159 160 if ( 'page' == $_POST['post_type'] ) { 161 if ( !current_user_can('edit_page', $post_ID) ) 162 wp_die(__('You are not allowed to edit this page.')); 163 } else { 164 if ( !current_user_can('edit_post', $post_ID) ) 165 wp_die(__('You are not allowed to edit this post.')); 166 } 167 168 // Rename. 169 $_POST['ID'] = (int) $_POST['post_ID']; 170 $_POST['post_content'] = $_POST['content']; 171 $_POST['post_excerpt'] = $_POST['excerpt']; 172 $_POST['post_parent'] = $_POST['parent_id']; 173 $_POST['to_ping'] = $_POST['trackback_url']; 174 175 if (!empty ($_POST['post_author_override'])) { 176 $_POST['post_author'] = (int) $_POST['post_author_override']; 177 } else 178 if (!empty ($_POST['post_author'])) { 179 $_POST['post_author'] = (int) $_POST['post_author']; 180 } else { 181 $_POST['post_author'] = (int) $_POST['user_ID']; 182 } 183 184 if ($_POST['post_author'] != $_POST['user_ID']) { 185 if ( 'page' == $_POST['post_type'] ) { 186 if ( !current_user_can('edit_others_pages') ) 187 wp_die(__('You cannot edit pages as this user.')); 188 } else { 189 if ( !current_user_can('edit_others_posts') ) 190 wp_die(__('You cannot edit posts as this user.')); 191 192 } 193 } 194 195 // What to do based on which button they pressed 196 if ('' != $_POST['saveasdraft']) 41 197 $_POST['post_status'] = 'draft'; 42 43 if ('static' == $_POST['post_status'] && !current_user_can('edit_pages')) 44 die(__('This user cannot edit pages.')); 198 if ('' != $_POST['saveasprivate']) 199 $_POST['post_status'] = 'private'; 200 if ('' != $_POST['publish']) 201 $_POST['post_status'] = 'publish'; 202 if ('' != $_POST['advanced']) 203 $_POST['post_status'] = 'draft'; 204 205 if ( 'page' == $_POST['post_type'] ) { 206 if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_pages')) 207 $_POST['post_status'] = 'draft'; 208 } else { 209 if ('publish' == $_POST['post_status'] && !current_user_can('edit_published_posts')) 210 $_POST['post_status'] = 'draft'; 211 } 212 213 if (!isset ($_POST['comment_status'])) 214 $_POST['comment_status'] = 'closed'; 215 216 if (!isset ($_POST['ping_status'])) 217 $_POST['ping_status'] = 'closed'; 45 218 46 219 if (!empty ($_POST['edit_date'])) { … … 59 232 } 60 233 61 // Create the post.62 $post_ID = wp_insert_post($_POST);63 add_meta($post_ID);64 65 // Reunite any orphaned attachments with their parent66 if ( $_POST['temp_ID'] )67 relocate_children($_POST['temp_ID'], $post_ID);68 69 // Now that we have an ID we can fix any attachment anchor hrefs70 fix_attachment_links($post_ID);71 72 return $post_ID;73 }74 75 // Move child posts to a new parent76 function relocate_children($old_ID, $new_ID) {77 global $wpdb;78 $old_ID = (int) $old_ID;79 $new_ID = (int) $new_ID;80 return $wpdb->query("UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID");81 }82 83 // Replace hrefs of attachment anchors with up-to-date permalinks.84 function fix_attachment_links($post_ID) {85 global $wp_rewrite;86 87 $post = & get_post($post_ID);88 89 $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";90 91 // See if we have any rel="attachment" links92 if ( 0 == preg_match_all($search, $post->post_content, $anchor_matches, PREG_PATTERN_ORDER) )93 return;94 95 $i = 0;96 $search = "# id=(\"|')p(\d+)\\1#i";97 foreach ( $anchor_matches[0] as $anchor ) {98 if ( 0 == preg_match($search, $anchor, $id_matches) )99 continue;100 101 $id = $id_matches[2];102 103 // While we have the attachment ID, let's adopt any orphans.104 $attachment = & get_post($id);105 if ( ! is_object(get_post($attachment->post_parent)) ) {106 $attachment->post_parent = $post_ID;107 wp_update_post($attachment);108 }109 110 $post_search[$i] = $anchor;111 $post_replace[$i] = preg_replace("#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor);112 ++$i;113 }114 115 $post->post_content = str_replace($post_search, $post_replace, $post->post_content);116 117 return wp_update_post($post);118 }119 120 // Update an existing post with values provided in $_POST.121 function edit_post() {122 global $user_ID;123 124 $post_ID = (int) $_POST['post_ID'];125 126 if (!current_user_can('edit_post', $post_ID))127 die(__('You are not allowed to edit this post.'));128 129 // Rename.130 $_POST['ID'] = (int) $_POST['post_ID'];131 $_POST['post_content'] = $_POST['content'];132 $_POST['post_excerpt'] = $_POST['excerpt'];133 $_POST['post_parent'] = $_POST['parent_id'];134 $_POST['to_ping'] = $_POST['trackback_url'];135 136 if (!empty ($_POST['post_author_override'])) {137 $_POST['post_author'] = (int) $_POST['post_author_override'];138 } else139 if (!empty ($_POST['post_author'])) {140 $_POST['post_author'] = (int) $_POST['post_author'];141 } else {142 $_POST['post_author'] = (int) $_POST['user_ID'];143 }144 145 if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts'))146 die(__('You cannot post as this user.'));147 148 // What to do based on which button they pressed149 if ('' != $_POST['saveasdraft'])150 $_POST['post_status'] = 'draft';151 if ('' != $_POST['saveasprivate'])152 $_POST['post_status'] = 'private';153 if ('' != $_POST['publish'])154 $_POST['post_status'] = 'publish';155 if ('' != $_POST['advanced'])156 $_POST['post_status'] = 'draft';157 if ('' != $_POST['savepage'])158 $_POST['post_status'] = 'static';159 160 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts'))161 $_POST['post_status'] = 'draft';162 163 if ('static' == $_POST['post_status'] && !current_user_can('edit_pages'))164 die(__('This user cannot edit pages.'));165 166 if (!isset ($_POST['comment_status']))167 $_POST['comment_status'] = 'closed';168 169 if (!isset ($_POST['ping_status']))170 $_POST['ping_status'] = 'closed';171 172 if (!empty ($_POST['edit_date'])) {173 $aa = $_POST['aa'];174 $mm = $_POST['mm'];175 $jj = $_POST['jj'];176 $hh = $_POST['hh'];177 $mn = $_POST['mn'];178 $ss = $_POST['ss'];179 $jj = ($jj > 31) ? 31 : $jj;180 $hh = ($hh > 23) ? $hh -24 : $hh;181 $mn = ($mn > 59) ? $mn -60 : $mn;182 $ss = ($ss > 59) ? $ss -60 : $ss;183 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";184 $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss");185 }186 187 234 // Meta Stuff 188 235 if ($_POST['meta']) { … … 190 237 update_meta($key, $value['key'], $value['value']); 191 238 } 192 239 193 240 if ($_POST['deletemeta']) { 194 241 foreach ($_POST['deletemeta'] as $key => $value) … … 213 260 214 261 if (!current_user_can('edit_post', $comment_post_ID)) 215 die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.'));262 wp_die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.')); 216 263 217 264 $_POST['comment_author'] = $_POST['newcomment_author']; … … 241 288 // Get an existing post and format it for editing. 242 289 function get_post_to_edit($id) { 243 global $richedit;244 $richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false;245 290 246 291 $post = get_post($id); 247 292 248 $post->post_content = format_to_edit($post->post_content, $richedit);293 $post->post_content = format_to_edit($post->post_content, user_can_richedit()); 249 294 $post->post_content = apply_filters('content_edit_pre', $post->post_content); 250 295 … … 255 300 $post->post_title = apply_filters('title_edit_pre', $post->post_title); 256 301 257 if ($post->post_status == 'static') 302 $post->post_password = format_to_edit($post->post_password); 303 304 if ($post->post_type == 'page') 258 305 $post->page_template = get_post_meta($id, '_wp_page_template', true); 259 306 … … 287 334 288 335 $post->post_status = 'draft'; 289 $post->comment_status = get_ settings('default_comment_status');290 $post->ping_status = get_ settings('default_ping_status');291 $post->post_pingback = get_ settings('default_pingback_flag');292 $post->post_category = get_ settings('default_category');336 $post->comment_status = get_option('default_comment_status'); 337 $post->ping_status = get_option('default_ping_status'); 338 $post->post_pingback = get_option('default_pingback_flag'); 339 $post->post_category = get_option('default_category'); 293 340 $post->post_content = apply_filters('default_content', $post_content); 294 341 $post->post_title = apply_filters('default_title', $post_title); … … 302 349 303 350 function get_comment_to_edit($id) { 304 global $richedit;305 $richedit = ( 'true' == get_user_option('rich_editing') ) ? true : false;306 307 351 $comment = get_comment($id); 308 352 309 $comment->comment_content = format_to_edit($comment->comment_content, $richedit);353 $comment->comment_content = format_to_edit($comment->comment_content, user_can_richedit()); 310 354 $comment->comment_content = apply_filters('comment_edit_pre', $comment->comment_content); 311 355 … … 323 367 } 324 368 369 function wp_dropdown_roles( $default = false ) { 370 global $wp_roles; 371 $r = ''; 372 foreach($wp_roles->role_names as $role => $name) 373 if ( $default == $role ) // Make default first in list 374 $p = "\n\t<option selected='selected' value='$role'>$name</option>"; 375 else 376 $r .= "\n\t<option value='$role'>$name</option>"; 377 echo $p . $r; 378 } 379 380 381 function get_user_to_edit($user_id) { 382 $user = new WP_User($user_id); 383 $user->user_login = wp_specialchars($user->user_login, 1); 384 $user->user_email = wp_specialchars($user->user_email, 1); 385 $user->user_url = wp_specialchars($user->user_url, 1); 386 $user->first_name = wp_specialchars($user->first_name, 1); 387 $user->last_name = wp_specialchars($user->last_name, 1); 388 $user->display_name = wp_specialchars($user->display_name, 1); 389 $user->nickname = wp_specialchars($user->nickname, 1); 390 $user->aim = wp_specialchars($user->aim, 1); 391 $user->yim = wp_specialchars($user->yim, 1); 392 $user->jabber = wp_specialchars($user->jabber, 1); 393 $user->description = wp_specialchars($user->description); 394 395 return $user; 396 } 397 325 398 // Creates a new user from the "Users" form using $_POST information. 326 399 327 400 function add_user() { 328 return edit_user(); 401 if ( func_num_args() ) { // The hackiest hack that ever did hack 402 global $current_user, $wp_roles; 403 $user_id = func_get_arg(0); 404 405 if (isset ($_POST['role'])) { 406 if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) { 407 $user = new WP_User($user_id); 408 $user->set_role($_POST['role']); 409 } 410 } 411 } else { 412 add_action('user_register', 'add_user'); // See above 413 return edit_user(); 414 } 329 415 } 330 416 331 417 function edit_user($user_id = 0) { 332 418 global $current_user, $wp_roles, $wpdb; 333 334 419 if ($user_id != 0) { 335 420 $update = true; … … 351 436 $pass2 = $_POST['pass2']; 352 437 353 if (isset ($_POST['role']) ) {438 if (isset ($_POST['role']) && current_user_can('edit_users')) { 354 439 if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) 355 440 $user->role = $_POST['role']; … … 371 456 $user->display_name = wp_specialchars(trim($_POST['display_name'])); 372 457 if (isset ($_POST['description'])) 373 $user->description = wp_specialchars(trim($_POST['description']));458 $user->description = trim($_POST['description']); 374 459 if (isset ($_POST['jabber'])) 375 460 $user->jabber = wp_specialchars(trim($_POST['jabber'])); … … 379 464 $user->yim = wp_specialchars(trim($_POST['yim'])); 380 465 381 $errors = array();466 $errors = new WP_Error(); 382 467 383 468 /* checking that username has been typed */ 384 469 if ($user->user_login == '') 385 $errors ['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');470 $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); 386 471 387 472 /* checking the password has been typed twice */ 388 do_action ('check_passwords', array ($user->user_login, & $pass1, & $pass2));473 do_action_ref_array('check_passwords', array ($user->user_login, & $pass1, & $pass2)); 389 474 390 475 if (!$update) { 391 476 if ($pass1 == '' || $pass2 == '') 392 $errors ['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');477 $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.')); 393 478 } else { 394 479 if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))) 395 $errors ['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");480 $errors->add('pass', __("<strong>ERROR</strong>: you typed your new password only once.")); 396 481 } 397 482 398 483 /* Check for "\" in password */ 399 484 if( strpos( " ".$pass1, "\\" ) ) 400 $errors ['pass'] = __('<strong>ERROR</strong>: Passwords may not contain the character "\\".');485 $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".')); 401 486 402 487 /* checking the password has been typed twice the same */ 403 488 if ($pass1 != $pass2) 404 $errors ['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');489 $errors->add('pass', __('<strong>ERROR</strong>: Please type the same password in the two password fields.')); 405 490 406 491 if (!empty ($pass1)) … … 408 493 409 494 if ( !validate_username($user->user_login) ) 410 $errors ['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');495 $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); 411 496 412 497 if (!$update && username_exists($user->user_login)) 413 $errors ['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');498 $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 414 499 415 500 /* checking e-mail address */ 416 501 if (empty ($user->user_email)) { 417 $errors ['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");502 $errors->add('user_email', __("<strong>ERROR</strong>: please type an e-mail address")); 418 503 } else 419 504 if (!is_email($user->user_email)) { 420 $errors ['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");421 } 422 423 if ( count($errors) != 0)505 $errors->add('user_email', __("<strong>ERROR</strong>: the email address isn't correct")); 506 } 507 508 if ( $errors->get_error_codes() ) 424 509 return $errors; 425 510 … … 430 515 wp_new_user_notification($user_id); 431 516 } 432 433 return $errors; 517 return $user_id; 434 518 } 435 519 … … 437 521 function get_link_to_edit($link_id) { 438 522 $link = get_link($link_id); 439 523 440 524 $link->link_url = wp_specialchars($link->link_url, 1); 441 525 $link->link_name = wp_specialchars($link->link_name, 1); 442 $link->link_description = wp_specialchars($link->link_description); 526 $link->link_image = wp_specialchars($link->link_image, 1); 527 $link->link_description = wp_specialchars($link->link_description, 1); 443 528 $link->link_notes = wp_specialchars($link->link_notes); 444 $link->link_rss = wp_specialchars($link->link_rss); 445 529 $link->link_rss = wp_specialchars($link->link_rss, 1); 530 $link->link_rel = wp_specialchars($link->link_rel, 1); 531 $link->post_category = $link->link_category; 532 446 533 return $link; 447 534 } … … 452 539 else 453 540 $link->link_url = ''; 454 541 455 542 if ( isset($_GET['name']) ) 456 543 $link->link_name = wp_specialchars($_GET['name'], 1); 457 544 else 458 545 $link->link_name = ''; 459 546 547 $link->link_visible = 'Y'; 548 460 549 return $link; 461 550 } 462 551 463 552 function add_link() { 464 return edit_link(); 553 return edit_link(); 465 554 } 466 555 467 556 function edit_link($link_id = '') { 468 557 if (!current_user_can('manage_links')) 469 die(__("Cheatin' uh ?"));558 wp_die(__("Cheatin' uh ?")); 470 559 471 560 $_POST['link_url'] = wp_specialchars($_POST['link_url']); … … 474 563 $_POST['link_image'] = wp_specialchars($_POST['link_image']); 475 564 $_POST['link_rss'] = wp_specialchars($_POST['link_rss']); 476 $auto_toggle = get_autotoggle($_POST['link_category']); 477 478 // if we are in an auto toggle category and this one is visible then we 479 // need to make the others invisible before we add this new one. 480 // FIXME Add category toggle func. 481 //if (($auto_toggle == 'Y') && ($link_visible == 'Y')) { 482 // $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category"); 483 //} 565 $_POST['link_category'] = $_POST['post_category']; 484 566 485 567 if ( !empty($link_id) ) { … … 513 595 function return_categories_list($parent = 0) { 514 596 global $wpdb; 515 return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC LIMIT 100");597 return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC"); 516 598 } 517 599 … … 521 603 522 604 function get_nested_categories($default = 0, $parent = 0) { 523 global $post_ID, $ mode, $wpdb;605 global $post_ID, $link_id, $mode, $wpdb; 524 606 525 607 if ($post_ID) { … … 534 616 $checked_categories[] = $default; 535 617 } 536 618 } else if ($link_id) { 619 $checked_categories = $wpdb->get_col(" 620 SELECT category_id 621 FROM $wpdb->categories, $wpdb->link2cat 622 WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 623 "); 624 625 if (count($checked_categories) == 0) { 626 // No selected categories, strange 627 $checked_categories[] = $default; 628 } 537 629 } else { 538 630 $checked_categories[] = $default; … … 550 642 } 551 643 } 552 644 553 645 usort($result, 'sort_cats'); 554 646 … … 558 650 function write_nested_categories($categories) { 559 651 foreach ($categories as $category) { 560 echo '<l abel for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n";561 562 if ( isset ($category['children'])) {563 echo " \n<span class='cat-nest'>\n";652 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($category['cat_name']), "</label></li>\n"; 653 654 if ( $category['children'] ) { 655 echo "<ul>\n"; 564 656 write_nested_categories($category['children']); 565 echo "</ span>\n";657 echo "</ul>\n"; 566 658 } 567 659 } … … 572 664 } 573 665 666 function return_link_categories_list($parent = 0) { 667 global $wpdb; 668 return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC"); 669 } 670 671 function get_nested_link_categories( $default = 0, $parent = 0 ) { 672 global $post_ID, $link_id, $mode, $wpdb; 673 674 if ($link_id) { 675 $checked_categories = $wpdb->get_col(" 676 SELECT category_id 677 FROM $wpdb->categories, $wpdb->link2cat 678 WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 679 "); 680 681 if (count($checked_categories) == 0) { 682 // No selected categories, strange 683 $checked_categories[] = $default; 684 } 685 } else { 686 $checked_categories[] = $default; 687 } 688 689 $cats = return_link_categories_list($parent); 690 $result = array (); 691 692 if (is_array($cats)) { 693 foreach ($cats as $cat) { 694 $result[$cat]['children'] = get_nested_link_categories($default, $cat); 695 $result[$cat]['cat_ID'] = $cat; 696 $result[$cat]['checked'] = in_array($cat, $checked_categories); 697 $result[$cat]['cat_name'] = get_the_category_by_ID($cat); 698 } 699 } 700 701 usort($result, 'sort_cats'); 702 703 return $result; 704 } 705 706 function dropdown_link_categories($default = 0) { 707 write_nested_categories(get_nested_link_categories($default)); 708 } 709 574 710 // Dandy new recursive multiple category stuff. 575 711 function cat_rows($parent = 0, $level = 0, $categories = 0) { 576 global $wpdb, $class;577 578 712 if (!$categories) 579 $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");713 $categories = get_categories('hide_empty=0'); 580 714 581 715 if ($categories) { 582 716 foreach ($categories as $category) { 583 717 if ($category->category_parent == $parent) { 584 $category->cat_name = wp_specialchars($category->cat_name); 585 $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); 586 $pad = str_repeat('— ', $level); 587 if ( current_user_can('manage_categories') ) { 588 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; 589 $default_cat_id = get_option('default_category'); 590 591 if ($category->cat_ID != $default_cat_id) 592 $edit .= "<td><a href='categories.php?action=delete&cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->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')."</a>"; 593 else 594 $edit .= "<td style='text-align:center'>".__("Default"); 595 } 596 else 597 $edit = ''; 598 599 $class = ('alternate' == $class) ? '' : 'alternate'; 600 echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td> 601 <td>$category->category_description</td> 602 <td>$count</td> 603 <td>$edit</td> 604 </tr>"; 718 echo "\t" . _cat_row( $category, $level ); 605 719 cat_rows($category->cat_ID, $level +1, $categories); 606 720 } … … 611 725 } 612 726 613 function page_rows($parent = 0, $level = 0, $pages = 0) { 727 function _cat_row( $category, $level, $name_override = false ) { 728 global $class; 729 730 $pad = str_repeat('— ', $level); 731 if ( current_user_can('manage_categories') ) { 732 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td>"; 733 $default_cat_id = get_option('default_category'); 734 $default_link_cat_id = get_option('default_link_category'); 735 736 if ( ($category->cat_ID != $default_cat_id) && ($category->cat_ID != $default_link_cat_id) ) 737 $edit .= "<td><a href='" . wp_nonce_url("categories.php?action=delete&cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->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."), js_escape($category->cat_name), js_escape(get_catname($default_cat_id)), js_escape(get_catname($default_link_cat_id))) . "' );\" class='delete'>".__('Delete')."</a>"; 738 else 739 $edit .= "<td style='text-align:center'>".__("Default"); 740 } else 741 $edit = ''; 742 743 $class = ( ( defined('DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; 744 745 $category->category_count = number_format( $category->category_count ); 746 $category->link_count = number_format( $category->link_count ); 747 return "<tr id='cat-$category->cat_ID'$class> 748 <th scope='row' style='text-align: center'>$category->cat_ID</th> 749 <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td> 750 <td>$category->category_description</td> 751 <td align='center'>$category->category_count</td> 752 <td align='center'>$category->link_count</td> 753 <td>$edit</td>\n\t</tr>\n"; 754 } 755 756 function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) { 614 757 global $wpdb, $class, $post; 758 615 759 if (!$pages) 616 $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'static' ORDER BY menu_order"); 617 618 if ($pages) { 619 foreach ($pages as $post) { 620 start_wp(); 621 if ($post->post_parent == $parent) { 622 $post->post_title = wp_specialchars($post->post_title); 623 $pad = str_repeat('— ', $level); 624 $id = $post->ID; 625 $class = ('alternate' == $class) ? '' : 'alternate'; 760 $pages = get_pages('sort_column=menu_order'); 761 762 if (! $pages) 763 return false; 764 765 foreach ($pages as $post) { 766 setup_postdata($post); 767 if ( $hierarchy && ($post->post_parent != $parent) ) 768 continue; 769 770 $post->post_title = wp_specialchars($post->post_title); 771 $pad = str_repeat('— ', $level); 772 $id = $post->ID; 773 $class = ('alternate' == $class) ? '' : 'alternate'; 626 774 ?> 627 775 <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'> 628 <th scope="row" ><?php echo $post->ID; ?></th>776 <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th> 629 777 <td> 630 <?php echo $pad; ?><?php the_title() ?> 778 <?php echo $pad; ?><?php the_title() ?> 779 <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?> 631 780 </td> 632 781 <td><?php the_author() ?></td> 633 782 <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td> 634 783 <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e('View'); ?></a></td> 635 <td><?php if ( current_user_can('edit_page s') ) { echo "<a href='post.php?action=edit&post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>636 <td><?php if ( current_user_can(' edit_pages') ) { echo "<a href='post.php?action=delete&post=$id' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the "%s" page.\\n"OK" to delete, "Cancel" to stop."), wp_specialchars(get_the_title('','',0), 1)) . "' );\">" . __('Delete') . "</a>"; } ?></td>784 <td><?php if ( current_user_can('edit_page', $id) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td> 785 <td><?php if ( current_user_can('delete_page', $id) ) { echo "<a href='" . wp_nonce_url("page.php?action=delete&post=$id", 'delete-page_' . $id) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . sprintf(__("You are about to delete the "%s" page.\\n"OK" to delete, "Cancel" to stop."), js_escape(get_the_title()) ) . "' );\">" . __('Delete') . "</a>"; } ?></td> 637 786 </tr> 638 787 639 788 <?php 640 641 page_rows($id, $level +1, $pages); 642 } 643 } 644 } else { 645 return false; 646 } 789 if ( $hierarchy) page_rows($id, $level + 1, $pages); 790 } 791 } 792 793 function user_row( $user_object, $style = '' ) { 794 if ( !(is_object($user_object) && is_a($user_object, 'WP_User')) ) 795 $user_object = new WP_User( (int) $user_object ); 796 $email = $user_object->user_email; 797 $url = $user_object->user_url; 798 $short_url = str_replace('http://', '', $url); 799 $short_url = str_replace('www.', '', $short_url); 800 if ('/' == substr($short_url, -1)) 801 $short_url = substr($short_url, 0, -1); 802 if (strlen($short_url) > 35) 803 $short_url = substr($short_url, 0, 32).'...'; 804 $numposts = get_usernumposts($user_object->ID); 805 $r = "<tr id='user-$user_object->ID'$style> 806 <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> 807 <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 808 <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 809 <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td> 810 <td><a href='$url' title='website: $url'>$short_url</a></td>"; 811 $r .= "\n\t\t<td align='center'>"; 812 if ($numposts > 0) { 813 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __('View posts by this author') . "' class='edit'>"; 814 $r .= sprintf(__('View %1$s %2$s'), $numposts, __ngettext('post', 'posts', $numposts)); 815 } 816 $r .= "</td>\n\t\t<td>"; 817 $edit_link = add_query_arg('wp_http_referer', wp_specialchars(urlencode(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id=$user_object->ID"); 818 if ( current_user_can('edit_user', $user_object->ID) ) 819 $r .= "<a href='$edit_link' class='edit'>".__('Edit')."</a>"; 820 $r .= "</td>\n\t</tr>"; 821 return $r; 647 822 } 648 823 649 824 function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) { 650 global $wpdb , $bgcolor;651 if (!$categories) {652 $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");653 } 825 global $wpdb; 826 if (!$categories) 827 $categories = get_categories('hide_empty=0'); 828 654 829 if ($categories) { 655 830 foreach ($categories as $category) { 656 831 if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { 657 $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");658 832 $pad = str_repeat('– ', $level); 659 833 $category->cat_name = wp_specialchars($category->cat_name); … … 668 842 return false; 669 843 } 670 }671 672 function link_category_dropdown($fieldname, $selected = 0) {673 global $wpdb;674 675 $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $wpdb->linkcategories ORDER BY cat_id");676 echo "\n<select name='$fieldname' size='1'>\n";677 foreach ($results as $row) {678 echo "\n\t<option value='$row->cat_id'";679 if ($row->cat_id == $selected)680 echo " selected='selected'";681 echo ">$row->cat_id : " . wp_specialchars($row->cat_name);682 if ($row->auto_toggle == 'Y')683 echo ' (auto toggle)';684 echo "</option>";685 }686 echo "\n</select>\n";687 844 } 688 845 … … 777 934 return $error; 778 935 } else { 936 apply_filters( 'wp_create_thumbnail', $thumbpath ); 779 937 return $thumbpath; 780 938 } … … 796 954 global $post_ID; 797 955 // Exit if no meta 798 if (!$meta) 956 if (!$meta) { 957 echo '<tbody id="the-list"><tr style="display: none;"><td> </td></tr></tbody>'; //TBODY needed for list-manipulation JS 799 958 return; 959 } 800 960 $count = 0; 801 961 ?> 802 <table id='meta-list' cellpadding="3">962 <thead> 803 963 <tr> 804 964 <th><?php _e('Key') ?></th> … … 806 966 <th colspan='2'><?php _e('Action') ?></th> 807 967 </tr> 968 </thead> 808 969 <?php 809 810 970 $r ="\n\t<tbody id='the-list'>"; 811 971 foreach ($meta as $entry) { 812 972 ++ $count; … … 817 977 if ('_' == $entry['meta_key'] { 0 }) 818 978 $style .= ' hidden'; 819 echo " 820 <tr class='$style'> 821 <td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td> 822 <td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td> 823 <td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br /> 824 <input name='deletemeta[{$entry['meta_id']}]' type='submit' class='deletemeta' tabindex='6' value='".__('Delete')."' /></td> 825 </tr> 826 "; 827 } 828 echo " 829 </table> 830 "; 979 980 if ( is_serialized($entry['meta_value']) ) { 981 if ( is_serialized_string($entry['meta_value']) ) { 982 // this is a serialized string, so we should display it 983 $entry['meta_value'] = maybe_unserialize($entry['meta_value']); 984 } else { 985 // this is a serialized array/object so we should NOT display it 986 --$count; 987 continue; 988 } 989 } 990 991 $key_js = js_escape($entry['meta_key']); 992 $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true ); 993 $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true ); 994 $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>"; 995 $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>"; 996 $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>"; 997 $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__('Update')."' /><br />"; 998 $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '"; 999 $r .= sprintf(__("You are about to delete the "%s" custom field on this post.\\n"OK" to delete, "Cancel" to stop."), $key_js); 1000 $r .= "' );\" class='deletemeta' tabindex='6' value='".__('Delete')."' /></td>"; 1001 $r .= "\n\t</tr>"; 1002 } 1003 echo $r; 1004 echo "\n\t</tbody>"; 831 1005 } 832 1006 … … 846 1020 function meta_form() { 847 1021 global $wpdb; 1022 $limit = (int) apply_filters('postmeta_form_limit', 30); 848 1023 $keys = $wpdb->get_col(" 849 SELECT meta_key 850 FROM $wpdb->postmeta 851 GROUP BY meta_key 852 ORDER BY meta_id DESC 853 LIMIT 10"); 1024 SELECT meta_key 1025 FROM $wpdb->postmeta 1026 GROUP BY meta_key 1027 ORDER BY meta_id DESC 1028 LIMIT $limit"); 1029 natcasesort($keys); 854 1030 ?> 855 1031 <h3><?php _e('Add a new custom field:') ?></h3> 856 <table cellspacing="3" cellpadding="3">1032 <table id="newmeta" cellspacing="3" cellpadding="3"> 857 1033 <tr> 858 1034 <th colspan="2"><?php _e('Key') ?></th> … … 861 1037 <tr valign="top"> 862 1038 <td align="right" width="18%"> 863 <?php if ( $keys) : ?>1039 <?php if ( $keys ) : ?> 864 1040 <select id="metakeyselect" name="metakeyselect" tabindex="7"> 865 1041 <option value="#NONE#"><?php _e('- Select -'); ?></option> 866 1042 <?php 867 1043 868 foreach ($keys as $key) { 1044 foreach ( $keys as $key ) { 1045 $key = wp_specialchars($key, 1); 869 1046 echo "\n\t<option value='$key'>$key</option>"; 870 1047 } … … 878 1055 879 1056 </table> 880 <p class="submit"><input type="submit" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field »') ?>" /></p>1057 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e('Add Custom Field »') ?>" /></p> 881 1058 <?php 882 1059 … … 885 1062 function add_meta($post_ID) { 886 1063 global $wpdb; 1064 $post_ID = (int) $post_ID; 887 1065 888 1066 $metakeyselect = $wpdb->escape(stripslashes(trim($_POST['metakeyselect']))); 889 1067 $metakeyinput = $wpdb->escape(stripslashes(trim($_POST['metakeyinput']))); 890 $metavalue = $wpdb->escape(stripslashes(trim($_POST['metavalue']))); 1068 $metavalue = maybe_serialize(stripslashes((trim($_POST['metavalue'])))); 1069 $metavalue = $wpdb->escape($metavalue); 891 1070 892 1071 if ( ('0' === $metavalue || !empty ($metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) { … … 894 1073 // input for the key have data, the input takes precedence: 895 1074 896 if ('#NONE#' != $metakeyselect)1075 if ('#NONE#' != $metakeyselect) 897 1076 $metakey = $metakeyselect; 898 1077 … … 905 1084 VALUES ('$post_ID','$metakey','$metavalue') 906 1085 "); 907 } 1086 return $wpdb->insert_id; 1087 } 1088 return false; 908 1089 } // add_meta 909 1090 910 1091 function delete_meta($mid) { 911 1092 global $wpdb; 912 913 $result = $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'"); 1093 $mid = (int) $mid; 1094 1095 return $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'"); 914 1096 } 915 1097 916 1098 function update_meta($mid, $mkey, $mvalue) { 917 1099 global $wpdb; 918 1100 $mvalue = maybe_serialize(stripslashes($mvalue)); 1101 $mvalue = $wpdb->escape($mvalue); 1102 $mid = (int) $mid; 919 1103 return $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'"); 920 1104 } 921 1105 1106 function get_post_meta_by_id($mid) { 1107 global $wpdb; 1108 $mid = (int) $mid; 1109 1110 $meta = $wpdb->get_row("SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'"); 1111 if ( is_serialized_string($meta->meta_value) ) 1112 $meta->meta_value = maybe_unserialize($meta->meta_value); 1113 return $meta; 1114 } 1115 922 1116 function touch_time($edit = 1, $for_post = 1) { 923 global $ month, $post, $comment;1117 global $wp_locale, $post, $comment; 924 1118 925 1119 if ( $for_post ) … … 928 1122 echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__('Edit timestamp').'</label></legend>'; 929 1123 930 $time_adj = time() + (get_ settings('gmt_offset') * 3600);1124 $time_adj = time() + (get_option('gmt_offset') * 3600); 931 1125 $post_date = ($for_post) ? $post->post_date : $comment->comment_date; 932 1126 $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj); … … 937 1131 $ss = ($edit) ? mysql2date('s', $post_date) : gmdate('s', $time_adj); 938 1132 939 echo "<select name=\"mm\" >\n";1133 echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n"; 940 1134 for ($i = 1; $i < 13; $i = $i +1) { 941 1135 echo "\t\t\t<option value=\"$i\""; 942 1136 if ($i == $mm) 943 echo " selected='selected'"; 944 if ($i < 10) { 945 $ii = "0".$i; 946 } else { 947 $ii = "$i"; 948 } 949 echo ">".$month["$ii"]."</option>\n"; 1137 echo ' selected="selected"'; 1138 echo '>' . $wp_locale->get_month($i) . "</option>\n"; 950 1139 } 951 1140 ?> 952 1141 </select> 953 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" />954 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" /> @955 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" /> :956 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" />957 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />1142 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/> 1143 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @ 1144 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> : 1145 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 1146 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 958 1147 <?php 959 1148 if ( $edit ) { 960 1149 _e('Existing timestamp'); 961 echo ": {$month[$mm]} $jj, $aa @ $hh:$mn"; 1150 //echo ': ' . $wp_locale->get_month($mm) . "$jj, $aa @ $hh:$mn"; 1151 echo sprintf(__(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn); 962 1152 } 963 1153 ?> … … 984 1174 if ($markerdata) { 985 1175 $state = true; 986 foreach ($markerdata as $ markerline) {1176 foreach ($markerdata as $n => $markerline) { 987 1177 if (strstr($markerline, "# BEGIN {$marker}")) 988 1178 $state = false; 989 if ($state) 990 fwrite($f, "{$markerline}\n"); 1179 if ($state) { 1180 if ( $n + 1 < count($markerdata) ) 1181 fwrite($f, "{$markerline}\n"); 1182 else 1183 fwrite($f, "{$markerline}"); 1184 } 991 1185 if (strstr($markerline, "# END {$marker}")) { 992 1186 fwrite($f, "# BEGIN {$marker}\n"); … … 1071 1265 } 1072 1266 1073 function the_quicktags() {1074 // Browser detection sucks, but until Safari supports the JS needed for this to work people just assume it's a bug in WP1075 if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Safari'))1076 echo '1077 <div id="quicktags">1078 <script src="../wp-includes/js/quicktags.js" type="text/javascript"></script>1079 <script type="text/javascript">if ( typeof tinyMCE == "undefined" || tinyMCE.configs.length < 1 ) edToolbar();</script>1080 </div>1081 ';1082 else echo '1083 <script type="text/javascript">1084 function edInsertContent(myField, myValue) {1085 //IE support1086 if (document.selection) {1087 myField.focus();1088 sel = document.selection.createRange();1089 sel.text = myValue;1090 myField.focus();1091 }1092 //MOZILLA/NETSCAPE support1093 else if (myField.selectionStart || myField.selectionStart == "0") {1094 var startPos = myField.selectionStart;1095 var endPos = myField.selectionEnd;1096 myField.value = myField.value.substring(0, startPos)1097 + myValue1098 + myField.value.substring(endPos, myField.value.length);1099 myField.focus();1100 myField.selectionStart = startPos + myValue.length;1101 myField.selectionEnd = startPos + myValue.length;1102 } else {1103 myField.value += myValue;1104 myField.focus();1105 }1106 }1107 </script>1108 ';1109 }1110 1111 function validate_current_theme() {1112 $theme_loc = 'wp-content/themes';1113 $theme_root = ABSPATH.$theme_loc;1114 1115 $template = get_settings('template');1116 $stylesheet = get_settings('stylesheet');1117 1118 if (($template != 'default') && (!file_exists("$theme_root/$template/index.php"))) {1119 update_option('template', 'default');1120 update_option('stylesheet', 'default');1121 do_action('switch_theme', 'Default');1122 return false;1123 }1124 1125 if (($stylesheet != 'default') && (!file_exists("$theme_root/$stylesheet/style.css"))) {1126 update_option('template', 'default');1127 update_option('stylesheet', 'default');1128 do_action('switch_theme', 'Default');1129 return false;1130 }1131 1132 return true;1133 }1134 1135 1267 function get_broken_themes() { 1136 1268 global $wp_broken_themes; … … 1177 1309 function parent_dropdown($default = 0, $parent = 0, $level = 0) { 1178 1310 global $wpdb, $post_ID; 1179 $items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_ status = 'static' ORDER BY menu_order");1311 $items = $wpdb->get_results("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order"); 1180 1312 1181 1313 if ($items) { … … 1205 1337 global $menu; 1206 1338 global $submenu; 1339 global $_wp_menu_nopriv; 1340 global $_wp_submenu_nopriv; 1341 global $plugin_page; 1207 1342 1208 1343 $parent = get_admin_page_parent(); 1209 1210 foreach ($menu as $menu_array) { 1211 //echo "parent array: " . $menu_array[2]; 1212 if ($menu_array[2] == $parent) { 1213 if (!current_user_can($menu_array[1])) { 1344 /*echo "pa: $parent pn: $pagenow pp: $plugin_page<br/>"; 1345 echo "<pre>"; 1346 print_r($_wp_menu_nopriv); 1347 print_r($_wp_submenu_nopriv); 1348 echo "</pre>";*/ 1349 if ( isset($_wp_submenu_nopriv[$parent][$pagenow]) ) 1350 return false; 1351 1352 if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$parent][$plugin_page]) ) 1353 return false; 1354 1355 if ( empty($parent) ) { 1356 if ( isset($_wp_menu_nopriv[$pagenow]) ) 1357 return false; 1358 if ( isset($_wp_submenu_nopriv[$pagenow][$pagenow]) ) 1359 return false; 1360 if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) 1361 return false; 1362 foreach (array_keys($_wp_submenu_nopriv) as $key) { 1363 if ( isset($_wp_submenu_nopriv[$key][$pagenow]) ) 1214 1364 return false; 1215 } else {1216 break;1217 1218 }1365 if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page]) ) 1366 return false; 1367 } 1368 return true; 1219 1369 } 1220 1370 … … 1222 1372 foreach ($submenu[$parent] as $submenu_array) { 1223 1373 if ($submenu_array[2] == $pagenow) { 1224 if (!current_user_can($submenu_array[1])) { 1374 if (current_user_can($submenu_array[1])) 1375 return true; 1376 else 1225 1377 return false; 1226 } else {1227 return true;1228 }1229 1378 } 1230 1379 } 1231 1380 } 1232 1381 1382 foreach ($menu as $menu_array) { 1383 if ($menu_array[2] == $parent) { 1384 if (current_user_can($menu_array[1])) 1385 return true; 1386 else 1387 return false; 1388 } 1389 } 1390 1233 1391 return true; 1234 1392 } … … 1287 1445 global $pagenow; 1288 1446 global $plugin_page; 1289 1290 if (isset ($parent_file) && !empty ($parent_file)) { 1447 global $_wp_real_parent_file; 1448 global $_wp_menu_nopriv; 1449 global $_wp_submenu_nopriv; 1450 1451 if ( !empty ($parent_file) ) { 1452 if ( isset($_wp_real_parent_file[$parent_file]) ) 1453 $parent_file = $_wp_real_parent_file[$parent_file]; 1454 1291 1455 return $parent_file; 1292 1456 } … … 1296 1460 if ($parent_menu[2] == $plugin_page) { 1297 1461 $parent_file = $plugin_page; 1298 return $plugin_page; 1462 if ( isset($_wp_real_parent_file[$parent_file]) ) 1463 $parent_file = $_wp_real_parent_file[$parent_file]; 1464 return $parent_file; 1299 1465 } 1300 1466 } 1467 if ( isset($_wp_menu_nopriv[$plugin_page]) ) { 1468 $parent_file = $plugin_page; 1469 if ( isset($_wp_real_parent_file[$parent_file]) ) 1470 $parent_file = $_wp_real_parent_file[$parent_file]; 1471 return $parent_file; 1472 } 1473 } 1474 1475 if ( isset($plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) { 1476 $parent_file = $pagenow; 1477 if ( isset($_wp_real_parent_file[$parent_file]) ) 1478 $parent_file = $_wp_real_parent_file[$parent_file]; 1479 return $parent_file; 1301 1480 } 1302 1481 1303 1482 foreach (array_keys($submenu) as $parent) { 1304 1483 foreach ($submenu[$parent] as $submenu_array) { 1484 if ( isset($_wp_real_parent_file[$parent]) ) 1485 $parent = $_wp_real_parent_file[$parent]; 1305 1486 if ($submenu_array[2] == $pagenow) { 1306 1487 $parent_file = $parent; … … 1337 1518 global $submenu; 1338 1519 global $menu; 1520 global $_wp_real_parent_file; 1521 global $_wp_submenu_nopriv; 1522 global $_wp_menu_nopriv; 1523 1524 $file = plugin_basename($file); 1339 1525 1340 1526 $parent = plugin_basename($parent); 1341 $file = plugin_basename($file); 1527 if ( isset($_wp_real_parent_file[$parent]) ) 1528 $parent = $_wp_real_parent_file[$parent]; 1529 1530 if ( !current_user_can($access_level) ) { 1531 $_wp_submenu_nopriv[$parent][$file] = true; 1532 return false; 1533 } 1342 1534 1343 1535 // If the parent doesn't already have a submenu, add a link to the parent … … 1345 1537 // parent file someone is trying to link back to the parent manually. In 1346 1538 // this case, don't automatically add a link back to avoid duplication. 1347 if (!isset ($submenu[$parent]) && $file != $parent ) {1539 if (!isset ($submenu[$parent]) && $file != $parent ) { 1348 1540 foreach ($menu as $parent_menu) { 1349 if ( $parent_menu[2] == $parent) {1541 if ( $parent_menu[2] == $parent && current_user_can($parent_menu[1]) ) { 1350 1542 $submenu[$parent][] = $parent_menu; 1351 1543 } … … 1397 1589 switch ($code) { 1398 1590 case 1 : 1399 die(__('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.'));1591 wp_die(__('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.')); 1400 1592 1401 1593 case 2 : 1402 die(__('Sorry, can’t call files with their real path.'));1594 wp_die(__('Sorry, can’t call files with their real path.')); 1403 1595 1404 1596 case 3 : 1405 die(__('Sorry, that file cannot be edited.'));1597 wp_die(__('Sorry, that file cannot be edited.')); 1406 1598 } 1407 1599 } 1408 1600 1409 1601 function get_home_path() { 1410 $home = get_ settings('home');1411 if ($home != '' && $home != get_ settings('siteurl')) {1602 $home = get_option('home'); 1603 if ($home != '' && $home != get_option('siteurl')) { 1412 1604 $home_path = parse_url($home); 1413 1605 $home_path = $home_path['path']; … … 1441 1633 return $wp_file_descriptions[basename($file)]; 1442 1634 } 1443 elseif ( file_exists(ABSPATH.$file)) {1444 $template_data = implode('', file( ABSPATH.$file));1635 elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) { 1636 $template_data = implode('', file( ABSPATH . $file )); 1445 1637 if (preg_match("|Template Name:(.*)|i", $template_data, $name)) 1446 1638 return $name[1]; … … 1473 1665 preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri); 1474 1666 if (preg_match("|Version:(.*)|i", $plugin_data, $version)) 1475 $version = $version[1];1667 $version = trim($version[1]); 1476 1668 else 1477 1669 $version = ''; 1478 1670 1479 $description = wptexturize( $description[1]);1671 $description = wptexturize(trim($description[1])); 1480 1672 1481 1673 $name = $plugin_name[1]; … … 1483 1675 $plugin = $name; 1484 1676 if ('' != $plugin_uri[1] && '' != $name) { 1485 $plugin = '<a href="' .$plugin_uri[1].'" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';1677 $plugin = '<a href="' . trim($plugin_uri[1]) . '" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>'; 1486 1678 } 1487 1679 1488 1680 if ('' == $author_uri[1]) { 1489 $author = $author_name[1];1490 } else { 1491 $author = '<a href="' .$author_uri[1].'" title="'.__('Visit author homepage').'">'.$author_name[1].'</a>';1681 $author = trim($author_name[1]); 1682 } else { 1683 $author = '<a href="' . trim($author_uri[1]) . '" title="'.__('Visit author homepage').'">' . trim($author_name[1]) . '</a>'; 1492 1684 } 1493 1685 … … 1503 1695 1504 1696 $wp_plugins = array (); 1505 $plugin_loc = 'wp-content/plugins'; 1506 $plugin_root = ABSPATH.$plugin_loc; 1697 $plugin_root = ABSPATH . PLUGINDIR; 1507 1698 1508 1699 // Files in wp-content/plugins directory … … 1529 1720 } 1530 1721 1531 if ( !$plugins_dir || !$plugin_files) {1722 if ( !$plugins_dir || !$plugin_files ) 1532 1723 return $wp_plugins; 1533 } 1534 1535 sort($plugin_files); 1536 1537 foreach ($plugin_files as $plugin_file) { 1538 if ( !is_readable("$plugin_root/$plugin_file")) 1724 1725 foreach ( $plugin_files as $plugin_file ) { 1726 if ( !is_readable("$plugin_root/$plugin_file") ) 1539 1727 continue; 1540 1728 1541 1729 $plugin_data = get_plugin_data("$plugin_root/$plugin_file"); 1542 1730 1543 if ( empty ($plugin_data['Name'])) {1731 if ( empty ($plugin_data['Name']) ) 1544 1732 continue; 1545 }1546 1733 1547 1734 $wp_plugins[plugin_basename($plugin_file)] = $plugin_data; 1548 1735 } 1736 1737 uasort($wp_plugins, create_function('$a, $b', 'return strnatcasecmp($a["Name"], $b["Name"]);')); 1549 1738 1550 1739 return $wp_plugins; … … 1655 1844 __("Failed to write file to disk.")); 1656 1845 1657 // Accepted MIME types are set here as PCRE. Override with $override['mimes'].1658 $mimes = apply_filters('upload_mimes', array (1659 'jpg|jpeg|jpe' => 'image/jpeg',1660 'gif' => 'image/gif',1661 'png' => 'image/png',1662 'bmp' => 'image/bmp',1663 'tif|tiff' => 'image/tiff',1664 'ico' => 'image/x-icon',1665 'asf|asx|wax|wmv|wmx' => 'video/asf',1666 'avi' => 'video/avi',1667 'mov|qt' => 'video/quicktime',1668 'mpeg|mpg|mpe' => 'video/mpeg',1669 'txt|c|cc|h' => 'text/plain',1670 'rtx' => 'text/richtext',1671 'css' => 'text/css',1672 'htm|html' => 'text/html',1673 'mp3|mp4' => 'audio/mpeg',1674 'ra|ram' => 'audio/x-realaudio',1675 'wav' => 'audio/wav',1676 'ogg' => 'audio/ogg',1677 'mid|midi' => 'audio/midi',1678 'wma' => 'audio/wma',1679 'rtf' => 'application/rtf',1680 'js' => 'application/javascript',1681 'pdf' => 'application/pdf',1682 'doc' => 'application/msword',1683 'pot|pps|ppt' => 'application/vnd.ms-powerpoint',1684 'wri' => 'application/vnd.ms-write',1685 'xla|xls|xlt|xlw' => 'application/vnd.ms-excel',1686 'mdb' => 'application/vnd.ms-access',1687 'mpp' => 'application/vnd.ms-project',1688 'swf' => 'application/x-shockwave-flash',1689 'class' => 'application/java',1690 'tar' => 'application/x-tar',1691 'zip' => 'application/zip',1692 'gz|gzip' => 'application/x-gzip',1693 'exe' => 'application/x-msdownload'1694 ));1695 1696 1846 // All tests are on by default. Most can be turned off by $override[{test_name}] = false; 1697 1847 $test_form = true; … … 1721 1871 return $upload_error_handler($file, __('Specified file failed upload test.')); 1722 1872 1723 // A correct MIME type will pass this test. 1873 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 1724 1874 if ( $test_type ) { 1725 $type = false; 1726 $ext = false; 1727 foreach ($mimes as $ext_preg => $mime_match) { 1728 $ext_preg = '![^.]\.(' . $ext_preg . ')$!i'; 1729 if ( preg_match($ext_preg, $file['name'], $ext_matches) ) { 1730 $type = $mime_match; 1731 $ext = $ext_matches[1]; 1732 } 1733 } 1875 $wp_filetype = wp_check_filetype($file['name'], $mimes); 1876 1877 extract($wp_filetype); 1734 1878 1735 1879 if ( !$type || !$ext ) … … 1758 1902 $filename = str_replace("$number$ext", ++$number . $ext, $filename); 1759 1903 } 1904 $filename = str_replace($ext, '', $filename); 1905 $filename = sanitize_title_with_dashes($filename) . $ext; 1760 1906 } 1761 1907 … … 1763 1909 $new_file = $uploads['path'] . "/$filename"; 1764 1910 if ( false === @ move_uploaded_file($file['tmp_name'], $new_file) ) 1765 die(printf(__('The uploaded file could not be moved to %s.'), $file['path']));1911 wp_die(printf(__('The uploaded file could not be moved to %s.'), $uploads['path'])); 1766 1912 1767 1913 // Set correct file permissions … … 1772 1918 // Compute the URL 1773 1919 $url = $uploads['url'] . "/$filename"; 1774 1775 return array('file' => $new_file, 'url' => $url, 'type' => $type); 1920 1921 $return = apply_filters( 'wp_handle_upload', array('file' => $new_file, 'url' => $url, 'type' => $type) ); 1922 1923 return $return; 1776 1924 } 1777 1925 … … 1790 1938 1791 1939 function wp_import_upload_form($action) { 1940 $size = strtolower( ini_get('upload_max_filesize') ); 1941 $bytes = 0; 1942 if ( strstr( $size, 'k' ) ) 1943 $bytes = $size * 1024; 1944 if ( strstr( $size, 'm' ) ) 1945 $bytes = $size * 1024 * 1024; 1946 if ( strstr( $size, 'g' ) ) 1947 $bytes = $size * 1024 * 1024 * 1024; 1792 1948 ?> 1793 <script type="text/javascript"> 1794 function cancelUpload() { 1795 o = document.getElementById('uploadForm'); 1796 o.method = 'GET'; 1797 o.action.value = 'view'; 1798 o.submit(); 1799 } 1800 </script> 1801 <form enctype="multipart/form-data" id="uploadForm" method="POST" action="<?php echo $action ?>"> 1802 <label for="upload"><?php _e('File:'); ?></label><input type="file" id="upload" name="import" /> 1949 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo $action ?>"> 1950 <p> 1951 <label for="upload"><?php _e('Choose a file from your computer:'); ?></label> (<?php printf( __('Maximum size: %s'), $size ); ?>) 1952 <input type="file" id="upload" name="import" size="25" /> 1803 1953 <input type="hidden" name="action" value="save" /> 1804 <div id="buttons"> 1805 <input type="submit" value="<?php _e('Import'); ?>" /> 1806 <input type="button" value="<?php _e('Cancel'); ?>" onclick="cancelUpload()" /> 1807 </div> 1954 <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> 1955 </p> 1956 <p class="submit"> 1957 <input type="submit" value="<?php _e('Upload file and import'); ?> »" /> 1958 </p> 1808 1959 </form> 1809 <?php 1960 <?php 1810 1961 } 1811 1962 … … 1818 1969 1819 1970 $url = $file['url']; 1820 $file = $file['file'];1971 $file = addslashes( $file['file'] ); 1821 1972 $filename = basename($file); 1822 1973 … … 1835 1986 } 1836 1987 1837 function user_can_richedit() {1838 if ( 'true' != get_user_option('rich_editing') )1839 return false;1840 1841 if ( preg_match('!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT']) )1842 return false;1843 1844 return true; // Best guess1845 }1846 1847 1988 function the_attachment_links($id = false) { 1848 1989 $id = (int) $id; 1849 1990 $post = & get_post($id); 1850 1991 1851 if ( $post->post_ status!= 'attachment' )1992 if ( $post->post_type != 'attachment' ) 1852 1993 return false; 1853 1994 1854 1995 $icon = get_attachment_icon($post->ID); 1855 1996 $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true ); 1997 $thumb = isset($attachment_data['thumb']); 1856 1998 ?> 1857 <p><?php _e('Text linked to file') ?><br /> 1858 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid) ?></a></textarea></p> 1859 <p><?php _e('Text linked to subpost') ?><br /> 1860 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $post->post_title ?></a></textarea></p> 1999 <form id="the-attachment-links"> 2000 <table> 2001 <col /> 2002 <col class="widefat" /> 2003 <tr> 2004 <th scope="row"><?php _e('URL') ?></th> 2005 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo $post->guid ?></textarea></td> 2006 </tr> 1861 2007 <?php if ( $icon ) : ?> 1862 <p><?php _e('Thumbnail linked to file') ?><br /> 1863 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo $icon ?></a></textarea></p> 1864 <p><?php _e('Thumbnail linked to subpost') ?><br /> 1865 <textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment" id="<?php echo $post->ID ?>"><?php echo $icon ?></a></textarea></p> 2008 <tr> 2009 <th scope="row"><?php $thumb ? _e('Thumbnail linked to file') : _e('Image linked to file'); ?></th> 2010 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid; ?>"><?php echo $icon ?></a></textarea></td> 2011 </tr> 2012 <tr> 2013 <th scope="row"><?php $thumb ? _e('Thumbnail linked to page') : _e('Image linked to file'); ?></th> 2014 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td> 2015 </tr> 2016 <?php else : ?> 2017 <tr> 2018 <th scope="row"><?php _e('Link to file') ?></th> 2019 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid ?>" class="attachmentlink"><?php echo basename($post->guid); ?></a></textarea></td> 2020 </tr> 2021 <tr> 2022 <th scope="row"><?php _e('Link to page') ?></th> 2023 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td> 2024 </tr> 1866 2025 <?php endif; ?> 2026 </table> 2027 </form> 1867 2028 <?php 1868 2029 } … … 1877 2038 } 1878 2039 2040 function wp_reset_vars($vars) { 2041 for ($i=0; $i<count($vars); $i += 1) { 2042 $var = $vars[$i]; 2043 global $$var; 2044 2045 if (!isset($$var)) { 2046 if (empty($_POST["$var"])) { 2047 if (empty($_GET["$var"])) 2048 $$var = ''; 2049 else 2050 $$var = $_GET["$var"]; 2051 } else { 2052 $$var = $_POST["$var"]; 2053 } 2054 } 2055 } 2056 } 2057 2058 // If siteurl or home changed, reset cookies and flush rewrite rules. 2059 function update_home_siteurl($old_value, $value) { 2060 global $wp_rewrite, $user_login, $user_pass_md5; 2061 2062 if ( defined("WP_INSTALLING") ) 2063 return; 2064 2065 // If home changed, write rewrite rules to new location. 2066 $wp_rewrite->flush_rules(); 2067 // Clear cookies for old paths. 2068 wp_clearcookie(); 2069 // Set cookies for new paths. 2070 wp_setcookie($user_login, $user_pass_md5, true, get_option('home'), get_option('siteurl')); 2071 } 2072 2073 add_action('update_option_home', 'update_home_siteurl', 10, 2); 2074 add_action('update_option_siteurl', 'update_home_siteurl', 10, 2); 2075 2076 function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false) { 2077 if ( ctype_digit($src_file) ) // Handle int as attachment ID 2078 $src_file = get_attached_file($src_file); 2079 2080 $src = wp_load_image($src_file); 2081 2082 if ( !is_resource($src) ) 2083 return $src; 2084 2085 $dst = imagecreatetruecolor($dst_w, $dst_h); 2086 2087 if ( $src_abs ) { 2088 $src_w -= $src_x; 2089 $src_h -= $src_y; 2090 } 2091 2092 imageantialias($dst, true); 2093 imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); 2094 2095 if ( !$dst_file ) 2096 $dst_file = str_replace(basename($src_file), 'cropped-'.basename($src_file), $src_file); 2097 2098 $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file); 2099 2100 if ( imagejpeg($dst, $dst_file) ) 2101 return $dst_file; 2102 else 2103 return false; 2104 } 2105 2106 function wp_load_image($file) { 2107 if ( ctype_digit($file) ) 2108 $file = get_attached_file($file); 2109 2110 if ( !file_exists($file) ) 2111 return "File '$file' doesn't exist?"; 2112 2113 $contents = file_get_contents($file); 2114 2115 $image = imagecreatefromstring($contents); 2116 2117 if ( !is_resource($image) ) 2118 return "File '$file' is not image?"; 2119 2120 return $image; 2121 } 2122 1879 2123 ?>
Note: See TracChangeset
for help on using the changeset viewer.