=== modified file 'wp-admin/admin-functions.php'
|
|
|
|
| 1 | 1 | <?php |
| | 2 | /** |
| | 3 | * admin-functions |
| | 4 | * |
| | 5 | * @author Wordpress team (FIXME) |
| | 6 | * @version "$Id$" |
| | 7 | * @copyright FIXME |
| | 8 | * @package wordpress |
| | 9 | * @subpackage admin-functions |
| | 10 | */ |
| 2 | 11 | |
| | 12 | /** |
| | 13 | * calls wp_write_post and handles the errors |
| | 14 | * |
| | 15 | * @return int post ID, dies in case of failure |
| | 16 | */ |
| 3 | 17 | function write_post() { |
| 4 | 18 | $result = wp_write_post(); |
| 5 | 19 | if( is_wp_error( $result ) ) |
| … |
… |
|
| 8 | 22 | return $result; |
| 9 | 23 | } |
| 10 | 24 | |
| 11 | | // Creates a new post from the "Write Post" form using $_POST information. |
| | 25 | /** |
| | 26 | * Creates a new post from the "Write Post" form using $_POST information. |
| | 27 | * |
| | 28 | * @return mixed post ID on success, Wp_Error on failure |
| | 29 | */ |
| 12 | 30 | function wp_write_post() { |
| 13 | 31 | global $user_ID; |
| 14 | 32 | |
| … |
… |
|
| 131 | 149 | return $post_ID; |
| 132 | 150 | } |
| 133 | 151 | |
| 134 | | // Move child posts to a new parent |
| | 152 | /** |
| | 153 | * Move child posts to a new parent |
| | 154 | * |
| | 155 | * @param int $old_ID current parent ID |
| | 156 | * @param int $new_ID ID of the new parent |
| | 157 | * @return mixed number of affected rows on success, false on failure |
| | 158 | */ |
| 135 | 159 | function relocate_children( $old_ID, $new_ID ) { |
| 136 | 160 | global $wpdb; |
| 137 | 161 | $old_ID = (int) $old_ID; |
| … |
… |
|
| 139 | 163 | return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); |
| 140 | 164 | } |
| 141 | 165 | |
| 142 | | // Replace hrefs of attachment anchors with up-to-date permalinks. |
| | 166 | /** |
| | 167 | * Replace hrefs of attachment anchors with up-to-date permalinks. |
| | 168 | * |
| | 169 | * @param int $post_ID |
| | 170 | * @return int post ID |
| | 171 | */ |
| 143 | 172 | function fix_attachment_links( $post_ID ) { |
| 144 | 173 | global $wp_rewrite; |
| 145 | 174 | |
| … |
… |
|
| 181 | 210 | return wp_update_post( $post); |
| 182 | 211 | } |
| 183 | 212 | |
| 184 | | // Update an existing post with values provided in $_POST. |
| | 213 | /** |
| | 214 | * Update an existing post with values provided in $_POST. |
| | 215 | * |
| | 216 | * @filter autosave_interval |
| | 217 | * @return int post ID or dies on wrong permissions |
| | 218 | */ |
| 185 | 219 | function edit_post() { |
| 186 | 220 | global $user_ID; |
| 187 | 221 | |
| … |
… |
|
| 299 | 333 | return $post_ID; |
| 300 | 334 | } |
| 301 | 335 | |
| | 336 | /** |
| | 337 | * update a comment using data from $_POST |
| | 338 | * |
| | 339 | * @return int number of affected rows |
| | 340 | */ |
| 302 | 341 | function edit_comment() { |
| 303 | 342 | global $user_ID; |
| 304 | 343 | |
| … |
… |
|
| 332 | 371 | wp_update_comment( $_POST); |
| 333 | 372 | } |
| 334 | 373 | |
| 335 | | // Get an existing post and format it for editing. |
| | 374 | /** |
| | 375 | * Get an existing post and format it for editing. |
| | 376 | * |
| | 377 | * @filter content_edit_pre |
| | 378 | * @filter excerpt_edit_pre |
| | 379 | * @filter title_edit_pre |
| | 380 | * @param int $id post ID |
| | 381 | * @return object post |
| | 382 | */ |
| 336 | 383 | function get_post_to_edit( $id ) { |
| 337 | 384 | |
| 338 | 385 | $post = get_post( $id ); |
| … |
… |
|
| 354 | 401 | return $post; |
| 355 | 402 | } |
| 356 | 403 | |
| 357 | | // Default post information to use when populating the "Write Post" form. |
| | 404 | /** |
| | 405 | * Default post information to use when populating the "Write Post" form. |
| | 406 | * |
| | 407 | * @filter default_content |
| | 408 | * @filter default_title |
| | 409 | * @filter default_excerpt |
| | 410 | * @return object |
| | 411 | */ |
| 358 | 412 | function get_default_post_to_edit() { |
| 359 | 413 | if ( !empty( $_REQUEST['post_title'] ) ) |
| 360 | 414 | $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); |
| … |
… |
|
| 394 | 448 | return $post; |
| 395 | 449 | } |
| 396 | 450 | |
| | 451 | /** |
| | 452 | * get a comment and format it for editing |
| | 453 | * |
| | 454 | * @filter comment_edit_pre |
| | 455 | * @return object comment |
| | 456 | */ |
| 397 | 457 | function get_comment_to_edit( $id ) { |
| 398 | 458 | $comment = get_comment( $id ); |
| 399 | 459 | |
| … |
… |
|
| 407 | 467 | return $comment; |
| 408 | 468 | } |
| 409 | 469 | |
| | 470 | /** |
| | 471 | * get a category for editing |
| | 472 | * |
| | 473 | * @param int $id category ID |
| | 474 | * @return object |
| | 475 | */ |
| 410 | 476 | function get_category_to_edit( $id ) { |
| 411 | 477 | $category = get_category( $id ); |
| 412 | 478 | |
| … |
… |
|
| 425 | 491 | } |
| 426 | 492 | |
| 427 | 493 | |
| | 494 | /** |
| | 495 | * get user information and format it for editing |
| | 496 | * |
| | 497 | * @param int $user_id user ID |
| | 498 | * @return object |
| | 499 | */ |
| 428 | 500 | function get_user_to_edit( $user_id ) { |
| 429 | 501 | $user = new WP_User( $user_id ); |
| 430 | 502 | $user->user_login = attribute_escape($user->user_login); |
| … |
… |
|
| 442 | 514 | return $user; |
| 443 | 515 | } |
| 444 | 516 | |
| 445 | | // Creates a new user from the "Users" form using $_POST information. |
| 446 | | |
| | 517 | /** |
| | 518 | * Creates a new user from the "Users" form using $_POST information. |
| | 519 | * |
| | 520 | * @return object |
| | 521 | */ |
| 447 | 522 | function add_user() { |
| 448 | 523 | if ( func_num_args() ) { // The hackiest hack that ever did hack |
| 449 | 524 | global $current_user, $wp_roles; |
| … |
… |
|
| 461 | 536 | } |
| 462 | 537 | } |
| 463 | 538 | |
| | 539 | /** |
| | 540 | * update user information or create a new user |
| | 541 | * |
| | 542 | * @param int $user_id user ID |
| | 543 | * @return mixed user ID or WP_Error |
| | 544 | */ |
| 464 | 545 | function edit_user( $user_id = 0 ) { |
| 465 | 546 | global $current_user, $wp_roles, $wpdb; |
| 466 | 547 | if ( $user_id != 0 ) { |
| … |
… |
|
| 571 | 652 | } |
| 572 | 653 | |
| 573 | 654 | |
| | 655 | /** |
| | 656 | * get a link and format it for editing |
| | 657 | * |
| | 658 | * @param int $link_id |
| | 659 | * @return object |
| | 660 | */ |
| 574 | 661 | function get_link_to_edit( $link_id ) { |
| 575 | 662 | $link = get_link( $link_id ); |
| 576 | 663 | |
| … |
… |
|
| 586 | 673 | return $link; |
| 587 | 674 | } |
| 588 | 675 | |
| | 676 | /** |
| | 677 | * default information for link editing |
| | 678 | * |
| | 679 | * @return object |
| | 680 | */ |
| 589 | 681 | function get_default_link_to_edit() { |
| 590 | 682 | if ( isset( $_GET['linkurl'] ) ) |
| 591 | 683 | $link->link_url = attribute_escape( $_GET['linkurl']); |
| … |
… |
|
| 606 | 698 | return edit_link(); |
| 607 | 699 | } |
| 608 | 700 | |
| 609 | | function edit_link( $link_id = '' ) { |
| | 701 | /** |
| | 702 | * update a link information or create new one |
| | 703 | * |
| | 704 | * @param int $link_id |
| | 705 | * @return mixed link ID or Wp_Error |
| | 706 | */ |
| | 707 | function edit_link( $link_id = '' ) { //FIXME this is not very consistent; default for $link_id should be int |
| 610 | 708 | if (!current_user_can( 'manage_links' )) |
| 611 | 709 | wp_die( __( 'Cheatin’ uh?' )); |
| 612 | 710 | |
| … |
… |
|
| 625 | 723 | } |
| 626 | 724 | } |
| 627 | 725 | |
| | 726 | /** |
| | 727 | * make a short version of the url |
| | 728 | * |
| | 729 | * @param string $url |
| | 730 | * @return string |
| | 731 | */ |
| 628 | 732 | function url_shorten( $url ) { |
| 629 | 733 | $short_url = str_replace( 'http://', '', stripslashes( $url )); |
| 630 | 734 | $short_url = str_replace( 'www.', '', $short_url ); |
| … |
… |
|
| 635 | 739 | return $short_url; |
| 636 | 740 | } |
| 637 | 741 | |
| | 742 | /** |
| | 743 | * select helper; output selected status |
| | 744 | * |
| | 745 | * @param string $selected value to be selected |
| | 746 | * @param string $current current value |
| | 747 | */ |
| 638 | 748 | function selected( $selected, $current) { |
| 639 | 749 | if ( $selected == $current) |
| 640 | 750 | echo ' selected="selected"'; |
| 641 | 751 | } |
| 642 | 752 | |
| | 753 | /** |
| | 754 | * input helper; output checked status |
| | 755 | * |
| | 756 | * @param string $checked value to be checked |
| | 757 | * @param string $current current value |
| | 758 | */ |
| 643 | 759 | function checked( $checked, $current) { |
| 644 | 760 | if ( $checked == $current) |
| 645 | 761 | echo ' checked="checked"'; |
| 646 | 762 | } |
| 647 | 763 | |
| | 764 | /** |
| | 765 | * get a list of categories |
| | 766 | * |
| | 767 | * @param int $parent category parent ID |
| | 768 | * @return array |
| | 769 | */ |
| 648 | 770 | function return_categories_list( $parent = 0 ) { |
| 649 | 771 | global $wpdb; |
| 650 | 772 | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" ); |
| 651 | 773 | } |
| 652 | 774 | |
| | 775 | /** |
| | 776 | * sorting helper |
| | 777 | * |
| | 778 | * @param string $cat1 |
| | 779 | * @param string $cat2 |
| | 780 | * @return bool |
| | 781 | */ |
| 653 | 782 | function sort_cats( $cat1, $cat2 ) { |
| 654 | 783 | if ( $cat1['checked'] || $cat2['checked'] ) |
| 655 | 784 | return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; |
| … |
… |
|
| 657 | 786 | return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); |
| 658 | 787 | } |
| 659 | 788 | |
| | 789 | /** |
| | 790 | * get the (sorted) list of categories as a tree |
| | 791 | * |
| | 792 | * @param int $default default category |
| | 793 | * @param int $parent parent category |
| | 794 | * @return array |
| | 795 | */ |
| 660 | 796 | function get_nested_categories( $default = 0, $parent = 0 ) { |
| 661 | 797 | global $post_ID, $link_id, $mode, $wpdb; |
| 662 | 798 | |
| … |
… |
|
| 703 | 839 | return $result; |
| 704 | 840 | } |
| 705 | 841 | |
| | 842 | /** |
| | 843 | * output category list together with checkboxes for selecting |
| | 844 | * |
| | 845 | * @filter the_category |
| | 846 | * @param array $categories category tree |
| | 847 | */ |
| 706 | 848 | function write_nested_categories( $categories ) { |
| 707 | 849 | foreach ( $categories as $category ) { |
| 708 | 850 | 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>"; |
| … |
… |
|
| 715 | 857 | } |
| 716 | 858 | } |
| 717 | 859 | |
| | 860 | /** |
| | 861 | * get the list of categories from the database and display it |
| | 862 | * |
| | 863 | * @param int $default |
| | 864 | */ |
| 718 | 865 | function dropdown_categories( $default = 0 ) { |
| 719 | 866 | write_nested_categories( get_nested_categories( $default) ); |
| 720 | 867 | } |
| 721 | 868 | |
| | 869 | /** |
| | 870 | * get the list of link categories |
| | 871 | * |
| | 872 | * @param array $parent |
| | 873 | * @return array |
| | 874 | */ |
| 722 | 875 | function return_link_categories_list( $parent = 0 ) { |
| 723 | 876 | global $wpdb; |
| 724 | 877 | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" ); |
| 725 | 878 | } |
| 726 | 879 | |
| | 880 | /** |
| | 881 | * get the link categories as a tree |
| | 882 | * |
| | 883 | * @param int $default |
| | 884 | * @param int $parent |
| | 885 | * @return array |
| | 886 | */ |
| 727 | 887 | function get_nested_link_categories( $default = 0, $parent = 0 ) { |
| 728 | 888 | global $post_ID, $link_id, $mode, $wpdb; |
| 729 | 889 | |
| … |
… |
|
| 759 | 919 | return $result; |
| 760 | 920 | } |
| 761 | 921 | |
| | 922 | /** |
| | 923 | * get the link categories from the database and output them |
| | 924 | * |
| | 925 | * @param int $parent |
| | 926 | */ |
| 762 | 927 | function dropdown_link_categories( $default = 0 ) { |
| 763 | 928 | write_nested_categories( get_nested_link_categories( $default) ); |
| 764 | 929 | } |
| 765 | 930 | |
| 766 | | // Dandy new recursive multiple category stuff. |
| 767 | | function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { |
| | 931 | /** |
| | 932 | * output table rows for the category management page |
| | 933 | * |
| | 934 | * @filter cat_rows |
| | 935 | * @param int $parent |
| | 936 | * @param int $level |
| | 937 | * @param array $categories |
| | 938 | */ |
| | 939 | function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { //FIXME categories int or array? |
| 768 | 940 | if (!$categories ) |
| 769 | 941 | $categories = get_categories( 'hide_empty=0' ); |
| 770 | 942 | |
| … |
… |
|
| 787 | 959 | } |
| 788 | 960 | } |
| 789 | 961 | |
| | 962 | /** |
| | 963 | * output a table row with category information and edit/delete links |
| | 964 | * |
| | 965 | * @param object $category |
| | 966 | * @param int $level indent level |
| | 967 | * @param bool $name_override |
| | 968 | */ |
| 790 | 969 | function _cat_row( $category, $level, $name_override = false ) { |
| 791 | 970 | global $class; |
| 792 | 971 | |
| … |
… |
|
| 797 | 976 | $default_link_cat_id = get_option( 'default_link_category' ); |
| 798 | 977 | |
| 799 | 978 | if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) ) |
| 800 | | $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, '" . 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->cat_name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>"; |
| | 979 | $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, '" . js_escape(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." ), $category->cat_name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>"; |
| 801 | 980 | else |
| 802 | 981 | $edit .= "<td style='text-align:center'>".__( "Default" ); |
| 803 | 982 | } else |
| … |
… |
|
| 817 | 996 | <td>$edit</td>\n\t</tr>\n"; |
| 818 | 997 | } |
| 819 | 998 | |
| | 999 | /** |
| | 1000 | * output table rows for the page management page |
| | 1001 | * |
| | 1002 | * @param int $parent |
| | 1003 | * @param int $level |
| | 1004 | * @param array $pages |
| | 1005 | * @param bool $hierarchy |
| | 1006 | */ |
| 820 | 1007 | function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { |
| 821 | 1008 | global $wpdb, $class, $post; |
| 822 | 1009 | |
| … |
… |
|
| 853 | 1040 | } |
| 854 | 1041 | } |
| 855 | 1042 | |
| | 1043 | /** |
| | 1044 | * format user information as a table row |
| | 1045 | * |
| | 1046 | * @param object $user_object |
| | 1047 | * @param string $style |
| | 1048 | * @return string |
| | 1049 | */ |
| 856 | 1050 | function user_row( $user_object, $style = '' ) { |
| 857 | 1051 | if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) |
| 858 | 1052 | $user_object = new WP_User( (int) $user_object ); |
| … |
… |
|
| 886 | 1080 | return $r; |
| 887 | 1081 | } |
| 888 | 1082 | |
| 889 | | function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { |
| | 1083 | /** |
| | 1084 | * output category list as select options |
| | 1085 | * |
| | 1086 | * @param int $currentcat |
| | 1087 | * @param int $currentparent |
| | 1088 | * @param int $parent |
| | 1089 | * @param int $level |
| | 1090 | * @param int $categories |
| | 1091 | */ |
| | 1092 | function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) {//FIXME $categories array or int? |
| 890 | 1093 | global $wpdb; |
| 891 | 1094 | if (!$categories ) |
| 892 | 1095 | $categories = get_categories( 'hide_empty=0' ); |
| … |
… |
|
| 908 | 1111 | } |
| 909 | 1112 | } |
| 910 | 1113 | |
| 911 | | // Some postmeta stuff |
| | 1114 | /** |
| | 1115 | * get meta information for post |
| | 1116 | * |
| | 1117 | * @param int $postid |
| | 1118 | * @return array |
| | 1119 | */ |
| 912 | 1120 | function has_meta( $postid ) { |
| 913 | 1121 | global $wpdb; |
| 914 | 1122 | |
| … |
… |
|
| 920 | 1128 | |
| 921 | 1129 | } |
| 922 | 1130 | |
| | 1131 | /** |
| | 1132 | * output post meta |
| | 1133 | * |
| | 1134 | * @param array $meta |
| | 1135 | */ |
| 923 | 1136 | function list_meta( $meta ) { |
| 924 | 1137 | global $post_ID; |
| 925 | 1138 | // Exit if no meta |
| … |
… |
|
| 974 | 1187 | echo "\n\t</tbody>"; |
| 975 | 1188 | } |
| 976 | 1189 | |
| 977 | | // Get a list of previously defined keys |
| | 1190 | /** |
| | 1191 | * Get a list of previously defined keys |
| | 1192 | * |
| | 1193 | * @return array |
| | 1194 | */ |
| 978 | 1195 | function get_meta_keys() { |
| 979 | 1196 | global $wpdb; |
| 980 | 1197 | |
| … |
… |
|
| 987 | 1204 | return $keys; |
| 988 | 1205 | } |
| 989 | 1206 | |
| | 1207 | /** |
| | 1208 | * output meta editing form |
| | 1209 | * |
| | 1210 | * @filter postmeta_form_limit |
| | 1211 | */ |
| 990 | 1212 | function meta_form() { |
| 991 | 1213 | global $wpdb; |
| 992 | 1214 | $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); |
| … |
… |
|
| 1030 | 1252 | |
| 1031 | 1253 | } |
| 1032 | 1254 | |
| | 1255 | /** |
| | 1256 | * add meta from $_POST |
| | 1257 | * |
| | 1258 | * @param int $post_ID |
| | 1259 | * @return mixed meta ID or false |
| | 1260 | */ |
| 1033 | 1261 | function add_meta( $post_ID ) { |
| 1034 | 1262 | global $wpdb; |
| 1035 | 1263 | $post_ID = (int) $post_ID; |
| … |
… |
|
| 1059 | 1287 | return false; |
| 1060 | 1288 | } // add_meta |
| 1061 | 1289 | |
| | 1290 | /** |
| | 1291 | * delete meta |
| | 1292 | * |
| | 1293 | * @param int $mid meta ID |
| | 1294 | * @return mixed number of accected rows or false |
| | 1295 | */ |
| 1062 | 1296 | function delete_meta( $mid ) { |
| 1063 | 1297 | global $wpdb; |
| 1064 | 1298 | $mid = (int) $mid; |
| … |
… |
|
| 1066 | 1300 | return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); |
| 1067 | 1301 | } |
| 1068 | 1302 | |
| | 1303 | /** |
| | 1304 | * update meta |
| | 1305 | * |
| | 1306 | * @param int $mid |
| | 1307 | * @param string $mkey |
| | 1308 | * @param mixed $mvalue |
| | 1309 | * @return mixed number of affected rows or false |
| | 1310 | */ |
| 1069 | 1311 | function update_meta( $mid, $mkey, $mvalue ) { |
| 1070 | 1312 | global $wpdb; |
| 1071 | 1313 | $mvalue = maybe_serialize( stripslashes( $mvalue )); |
| … |
… |
|
| 1074 | 1316 | return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" ); |
| 1075 | 1317 | } |
| 1076 | 1318 | |
| | 1319 | /** |
| | 1320 | * get post meta by ID |
| | 1321 | * |
| | 1322 | * @param int $mid |
| | 1323 | * @return object |
| | 1324 | */ |
| 1077 | 1325 | function get_post_meta_by_id( $mid ) { |
| 1078 | 1326 | global $wpdb; |
| 1079 | 1327 | $mid = (int) $mid; |
| … |
… |
|
| 1084 | 1332 | return $meta; |
| 1085 | 1333 | } |
| 1086 | 1334 | |
| | 1335 | /** |
| | 1336 | * output timestamp editing form |
| | 1337 | * |
| | 1338 | * @param int $edit |
| | 1339 | * @param int $for_post |
| | 1340 | */ |
| 1087 | 1341 | function touch_time( $edit = 1, $for_post = 1 ) { |
| 1088 | 1342 | global $wp_locale, $post, $comment; |
| 1089 | 1343 | |
| … |
… |
|
| 1125 | 1379 | |
| 1126 | 1380 | } |
| 1127 | 1381 | |
| 1128 | | // insert_with_markers: Owen Winkler, fixed by Eric Anderson |
| 1129 | | // Inserts an array of strings into a file (.htaccess ), placing it between |
| 1130 | | // BEGIN and END markers. Replaces existing marked info. Retains surrounding |
| 1131 | | // data. Creates file if none exists. |
| 1132 | | // Returns true on write success, false on failure. |
| | 1382 | /** |
| | 1383 | * Inserts an array of strings into a file (.htaccess ), placing it between |
| | 1384 | * BEGIN and END markers. Replaces existing marked info. Retains surrounding |
| | 1385 | * data. Creates file if none exists. |
| | 1386 | * |
| | 1387 | * @param string $filename |
| | 1388 | * @param string $marker |
| | 1389 | * @param string $insertion |
| | 1390 | * @return bool |
| | 1391 | */ |
| 1133 | 1392 | function insert_with_markers( $filename, $marker, $insertion ) { |
| 1134 | 1393 | if (!file_exists( $filename ) || is_writeable( $filename ) ) { |
| 1135 | 1394 | if (!file_exists( $filename ) ) { |
| … |
… |
|
| 1175 | 1434 | } |
| 1176 | 1435 | } |
| 1177 | 1436 | |
| 1178 | | // extract_from_markers: Owen Winkler |
| 1179 | | // Returns an array of strings from a file (.htaccess ) from between BEGIN |
| 1180 | | // and END markers. |
| | 1437 | /** |
| | 1438 | * extracts text between some markers in a file |
| | 1439 | * |
| | 1440 | * @param string $filename |
| | 1441 | * @param string marker |
| | 1442 | * @return array array of strings from a file (.htaccess ) from between BEGIN |
| | 1443 | * and END markers. |
| | 1444 | */ |
| 1181 | 1445 | function extract_from_markers( $filename, $marker ) { |
| 1182 | 1446 | $result = array (); |
| 1183 | 1447 | |
| … |
… |
|
| 1201 | 1465 | return $result; |
| 1202 | 1466 | } |
| 1203 | 1467 | |
| | 1468 | /** |
| | 1469 | * find out if we have mod_rewrite |
| | 1470 | * |
| | 1471 | * @return bool |
| | 1472 | */ |
| 1204 | 1473 | function got_mod_rewrite() { |
| 1205 | 1474 | global $is_apache; |
| 1206 | 1475 | |
| … |
… |
|
| 1216 | 1485 | return true; |
| 1217 | 1486 | } |
| 1218 | 1487 | |
| | 1488 | /** |
| | 1489 | * save mod_rewrite rules to .htaccess |
| | 1490 | * |
| | 1491 | * @return bool |
| | 1492 | */ |
| 1219 | 1493 | function save_mod_rewrite_rules() { |
| 1220 | 1494 | global $is_apache, $wp_rewrite; |
| 1221 | 1495 | $home_path = get_home_path(); |
| … |
… |
|
| 1233 | 1507 | return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); |
| 1234 | 1508 | } |
| 1235 | 1509 | |
| | 1510 | /** |
| | 1511 | * get the list of broken themes |
| | 1512 | * |
| | 1513 | * @return array |
| | 1514 | */ |
| 1236 | 1515 | function get_broken_themes() { |
| 1237 | 1516 | global $wp_broken_themes; |
| 1238 | 1517 | |
| … |
… |
|
| 1240 | 1519 | return $wp_broken_themes; |
| 1241 | 1520 | } |
| 1242 | 1521 | |
| | 1522 | /** |
| | 1523 | * build the page template list |
| | 1524 | * |
| | 1525 | * @return array |
| | 1526 | */ |
| 1243 | 1527 | function get_page_templates() { |
| 1244 | 1528 | $themes = get_themes(); |
| 1245 | 1529 | $theme = get_current_theme(); |
| … |
… |
|
| 1264 | 1548 | return $page_templates; |
| 1265 | 1549 | } |
| 1266 | 1550 | |
| | 1551 | /** |
| | 1552 | * output the template dropdown for the current page |
| | 1553 | * |
| | 1554 | * @param string default the currently selected template |
| | 1555 | */ |
| 1267 | 1556 | function page_template_dropdown( $default = '' ) { |
| 1268 | 1557 | $templates = get_page_templates(); |
| 1269 | 1558 | foreach (array_keys( $templates ) as $template ) |
| … |
… |
|
| 1275 | 1564 | endforeach; |
| 1276 | 1565 | } |
| 1277 | 1566 | |
| | 1567 | /** |
| | 1568 | * get the page parent dropdown |
| | 1569 | * |
| | 1570 | * @param int $default the ID of the selected item |
| | 1571 | * @param int $parent the ID of the parent |
| | 1572 | * @param int $level the current nesting level |
| | 1573 | */ |
| 1278 | 1574 | function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { |
| 1279 | 1575 | global $wpdb, $post_ID; |
| 1280 | 1576 | $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" ); |
| … |
… |
|
| 1301 | 1597 | } |
| 1302 | 1598 | } |
| 1303 | 1599 | |
| | 1600 | /** |
| | 1601 | * check if the user can access the current admin page |
| | 1602 | * |
| | 1603 | * @return bool |
| | 1604 | */ |
| 1304 | 1605 | function user_can_access_admin_page() { |
| 1305 | 1606 | global $pagenow; |
| 1306 | 1607 | global $menu; |
| … |
… |
|
| 1361 | 1662 | return true; |
| 1362 | 1663 | } |
| 1363 | 1664 | |
| | 1665 | /** |
| | 1666 | * get title of the current admin page |
| | 1667 | * |
| | 1668 | * @return string |
| | 1669 | */ |
| 1364 | 1670 | function get_admin_page_title() { |
| 1365 | 1671 | global $title; |
| 1366 | 1672 | global $menu; |
| … |
… |
|
| 1419 | 1725 | return $title; |
| 1420 | 1726 | } |
| 1421 | 1727 | |
| | 1728 | /** |
| | 1729 | * get the parent for the current admin page |
| | 1730 | * |
| | 1731 | * @return string |
| | 1732 | */ |
| 1422 | 1733 | function get_admin_page_parent() { |
| 1423 | 1734 | global $parent_file; |
| 1424 | 1735 | global $menu; |
| … |
… |
|
| 1479 | 1790 | return ''; |
| 1480 | 1791 | } |
| 1481 | 1792 | |
| | 1793 | /** |
| | 1794 | * add a toplevel menu item |
| | 1795 | * |
| | 1796 | * @param string $page_title page title |
| | 1797 | * @param string $menu_title menu item label |
| | 1798 | * @param int $access_level minimum user level |
| | 1799 | * @param string $file filename (relative to wp-content/plugins) |
| | 1800 | * @param callback $function function that generates the page |
| | 1801 | * @return string th page hook name |
| | 1802 | */ |
| 1482 | 1803 | function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1483 | 1804 | global $menu, $admin_page_hooks; |
| 1484 | 1805 | |
| … |
… |
|
| 1495 | 1816 | return $hookname; |
| 1496 | 1817 | } |
| 1497 | 1818 | |
| | 1819 | /** |
| | 1820 | * add a subpage to the menu |
| | 1821 | * |
| | 1822 | * @param string $parent parent page |
| | 1823 | * @param string $page_title subpage title |
| | 1824 | * @param string $menu_title menu item label |
| | 1825 | * @param int $access_level minimum user level |
| | 1826 | * @param string $file filename (relative to wp-content/plugins) |
| | 1827 | * @param callback $function function that generates the subpage |
| | 1828 | * @return string the page hook name |
| | 1829 | */ |
| 1498 | 1830 | function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1499 | 1831 | global $submenu; |
| 1500 | 1832 | global $menu; |
| … |
… |
|
| 1533 | 1865 | return $hookname; |
| 1534 | 1866 | } |
| 1535 | 1867 | |
| | 1868 | /** |
| | 1869 | * add an options subpage |
| | 1870 | * |
| | 1871 | * @param string $page_title @see add_submenu_page() |
| | 1872 | * @param string $menu_title @see add_submenu_page() |
| | 1873 | * @param int $access_level @see add_submenu_page() |
| | 1874 | * @param string $file @see add_submenu_page() |
| | 1875 | * @param callback $function @see add_submenu_page() |
| | 1876 | * @return string @see add_submenu_page() |
| | 1877 | */ |
| 1536 | 1878 | function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1537 | 1879 | return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); |
| 1538 | 1880 | } |
| 1539 | 1881 | |
| | 1882 | /** |
| | 1883 | * add a management subpage |
| | 1884 | * |
| | 1885 | * @param string $page_title @see add_submenu_page() |
| | 1886 | * @param string $menu_title @see add_submenu_page() |
| | 1887 | * @param int $access_level @see add_submenu_page() |
| | 1888 | * @param string $file @see add_submenu_page() |
| | 1889 | * @param callback $function @see add_submenu_page() |
| | 1890 | * @return string @see add_submenu_page() |
| | 1891 | */ |
| 1540 | 1892 | function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1541 | 1893 | return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); |
| 1542 | 1894 | } |
| 1543 | 1895 | |
| | 1896 | /** |
| | 1897 | * add a theme subpage |
| | 1898 | * |
| | 1899 | * @param string $page_title @see add_submenu_page() |
| | 1900 | * @param string $menu_title @see add_submenu_page() |
| | 1901 | * @param int $access_level @see add_submenu_page() |
| | 1902 | * @param string $file @see add_submenu_page() |
| | 1903 | * @param callback $function @see add_submenu_page() |
| | 1904 | * @return string @see add_submenu_page() |
| | 1905 | */ |
| 1544 | 1906 | function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1545 | 1907 | return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); |
| 1546 | 1908 | } |
| 1547 | 1909 | |
| | 1910 | /** |
| | 1911 | * add a users subpage |
| | 1912 | * |
| | 1913 | * @param string $page_title @see add_submenu_page() |
| | 1914 | * @param string $menu_title @see add_submenu_page() |
| | 1915 | * @param int $access_level @see add_submenu_page() |
| | 1916 | * @param string $file @see add_submenu_page() |
| | 1917 | * @param callback $function @see add_submenu_page() |
| | 1918 | * @return string @see add_submenu_page() |
| | 1919 | */ |
| 1548 | 1920 | function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
| 1549 | 1921 | if ( current_user_can('edit_users') ) |
| 1550 | 1922 | $parent = 'users.php'; |
| … |
… |
|
| 1553 | 1925 | return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function ); |
| 1554 | 1926 | } |
| 1555 | 1927 | |
| | 1928 | /** |
| | 1929 | * validate a file |
| | 1930 | * |
| | 1931 | * @param string $file |
| | 1932 | * @param array $allowed_files |
| | 1933 | * @return int |
| | 1934 | */ |
| 1556 | 1935 | function validate_file( $file, $allowed_files = '' ) { |
| 1557 | 1936 | if ( false !== strpos( $file, './' )) |
| 1558 | 1937 | return 1; |
| … |
… |
|
| 1566 | 1945 | return 0; |
| 1567 | 1946 | } |
| 1568 | 1947 | |
| | 1948 | /** |
| | 1949 | * validate a file before editing and abort with a friendly error message |
| | 1950 | * |
| | 1951 | * @param string $file |
| | 1952 | * @param array $allowed_files |
| | 1953 | */ |
| 1569 | 1954 | function validate_file_to_edit( $file, $allowed_files = '' ) { |
| 1570 | 1955 | $file = stripslashes( $file ); |
| 1571 | 1956 | |
| … |
… |
|
| 1586 | 1971 | } |
| 1587 | 1972 | } |
| 1588 | 1973 | |
| | 1974 | /** |
| | 1975 | * get the home path |
| | 1976 | * |
| | 1977 | * @return string |
| | 1978 | */ |
| 1589 | 1979 | function get_home_path() { |
| 1590 | 1980 | $home = get_option( 'home' ); |
| 1591 | 1981 | if ( $home != '' && $home != get_option( 'siteurl' ) ) { |
| … |
… |
|
| 1600 | 1990 | return $home_path; |
| 1601 | 1991 | } |
| 1602 | 1992 | |
| | 1993 | /** |
| | 1994 | * resolve the file path |
| | 1995 | * |
| | 1996 | * @return string |
| | 1997 | */ |
| 1603 | 1998 | function get_real_file_to_edit( $file ) { |
| 1604 | 1999 | if ('index.php' == $file || '.htaccess' == $file ) { |
| 1605 | 2000 | $real_file = get_home_path().$file; |
| … |
… |
|
| 1614 | 2009 | // Deprecated files |
| 1615 | 2010 | 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' )); |
| 1616 | 2011 | |
| | 2012 | /** |
| | 2013 | * get description for a template file |
| | 2014 | * |
| | 2015 | * @param string $file |
| | 2016 | * @return string |
| | 2017 | */ |
| 1617 | 2018 | function get_file_description( $file ) { |
| 1618 | 2019 | global $wp_file_descriptions; |
| 1619 | 2020 | |
| … |
… |
|
| 1629 | 2030 | return basename( $file ); |
| 1630 | 2031 | } |
| 1631 | 2032 | |
| | 2033 | /** |
| | 2034 | * update the list of recently edited files |
| | 2035 | * |
| | 2036 | * @param string $file |
| | 2037 | */ |
| 1632 | 2038 | function update_recently_edited( $file ) { |
| 1633 | 2039 | $oldfiles = (array ) get_option( 'recently_edited' ); |
| 1634 | 2040 | if ( $oldfiles ) { |
| … |
… |
|
| 1644 | 2050 | update_option( 'recently_edited', $oldfiles ); |
| 1645 | 2051 | } |
| 1646 | 2052 | |
| | 2053 | /** |
| | 2054 | * read the plugin data |
| | 2055 | * |
| | 2056 | * @param string $plugin_file |
| | 2057 | * @return array |
| | 2058 | */ |
| 1647 | 2059 | function get_plugin_data( $plugin_file ) { |
| 1648 | 2060 | $plugin_data = implode( '', file( $plugin_file )); |
| 1649 | 2061 | preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name ); |
| … |
… |
|
| 1674 | 2086 | return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1] ); |
| 1675 | 2087 | } |
| 1676 | 2088 | |
| | 2089 | /** |
| | 2090 | * build the list of plugins in the wp-content/plugins directory |
| | 2091 | * |
| | 2092 | * @return array |
| | 2093 | */ |
| 1677 | 2094 | function get_plugins() { |
| 1678 | 2095 | global $wp_plugins; |
| 1679 | 2096 | |
| … |
… |
|
| 1727 | 2144 | return $wp_plugins; |
| 1728 | 2145 | } |
| 1729 | 2146 | |
| | 2147 | /** |
| | 2148 | * compose a plugin page hook name from the nme of the plugin page and the name of its parent page |
| | 2149 | * |
| | 2150 | * @param string $plugin_page plugin page name |
| | 2151 | * @param string $parent_page parent page name |
| | 2152 | * @return string |
| | 2153 | */ |
| 1730 | 2154 | function get_plugin_page_hookname( $plugin_page, $parent_page ) { |
| 1731 | 2155 | global $admin_page_hooks; |
| 1732 | 2156 | |
| … |
… |
|
| 1750 | 2174 | return $page_type.'_page_'.$plugin_name; |
| 1751 | 2175 | } |
| 1752 | 2176 | |
| | 2177 | /** |
| | 2178 | * the hook name for a plugin page, if it is defined |
| | 2179 | * |
| | 2180 | * @param string $plugin_page @see get_plugin_page_hookname |
| | 2181 | * @param string $parent_page @see get_plugin_page_hookname |
| | 2182 | * @return string |
| | 2183 | */ |
| 1753 | 2184 | function get_plugin_page_hook( $plugin_page, $parent_page ) { |
| 1754 | 2185 | global $wp_filter; |
| 1755 | 2186 | |
| … |
… |
|
| 1786 | 2217 | return $wp_importers; |
| 1787 | 2218 | } |
| 1788 | 2219 | |
| | 2220 | /** |
| | 2221 | * get current theme info |
| | 2222 | * |
| | 2223 | * @return object |
| | 2224 | */ |
| 1789 | 2225 | function current_theme_info() { |
| 1790 | 2226 | $themes = get_themes(); |
| 1791 | 2227 | $current_theme = get_current_theme(); |
| … |
… |
|
| 1803 | 2239 | return $ct; |
| 1804 | 2240 | } |
| 1805 | 2241 | |
| 1806 | | |
| 1807 | | // array wp_handle_upload ( array &file [, array overrides] ) |
| 1808 | | // file: reference to a single element of $_FILES. Call the function once for each uploaded file. |
| 1809 | | // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
| 1810 | | // On success, returns an associative array of file attributes. |
| 1811 | | // On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
| | 2242 | /** |
| | 2243 | * handle an uploaded file |
| | 2244 | * |
| | 2245 | * @filter wp_handle_upload |
| | 2246 | * @param array &$file file info; reference to a single element if $_FILES |
| | 2247 | * @param array $overrides associative array of names=>values to override default variables with extract($overrides, EXTR_OVERWRITE) |
| | 2248 | * @return mixed associative array of file attributes on success, |
| | 2249 | * $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ) on failure |
| | 2250 | */ |
| 1812 | 2251 | function wp_handle_upload( &$file, $overrides = false ) { |
| 1813 | 2252 | // The default error handler. |
| 1814 | 2253 | if (! function_exists( 'wp_handle_upload_error' ) ) { |
| … |
… |
|
| 1912 | 2351 | return $return; |
| 1913 | 2352 | } |
| 1914 | 2353 | |
| | 2354 | /** |
| | 2355 | * compute dimensions for display in the upload list |
| | 2356 | * |
| | 2357 | * @param int $width image width |
| | 2358 | * @param int $height image height |
| | 2359 | * @param int $wmax maximum width of the resized image |
| | 2360 | * @param int $hmax maximum height of the resized image |
| | 2361 | * @return array |
| | 2362 | */ |
| 1915 | 2363 | function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { |
| 1916 | 2364 | if ( $height <= $hmax && $width <= $wmax ) |
| 1917 | 2365 | return array( $width, $height); |
| … |
… |
|
| 1921 | 2369 | return array( (int) ($width / $height * $hmax ), $hmax ); |
| 1922 | 2370 | } |
| 1923 | 2371 | |
| | 2372 | /** |
| | 2373 | * delete an attachment |
| | 2374 | * |
| | 2375 | * @param int $id attachment ID |
| | 2376 | */ |
| 1924 | 2377 | function wp_import_cleanup( $id ) { |
| 1925 | 2378 | wp_delete_attachment( $id ); |
| 1926 | 2379 | } |
| 1927 | 2380 | |
| | 2381 | /** |
| | 2382 | * outputs the file upload form for importing |
| | 2383 | * |
| | 2384 | * @param string $action form action |
| | 2385 | */ |
| 1928 | 2386 | function wp_import_upload_form( $action ) { |
| 1929 | 2387 | $size = strtolower( ini_get( 'upload_max_filesize' ) ); |
| 1930 | 2388 | $bytes = 0; |
| … |
… |
|
| 1949 | 2407 | <?php |
| 1950 | 2408 | } |
| 1951 | 2409 | |
| | 2410 | /** |
| | 2411 | * handles an import file upload |
| | 2412 | * |
| | 2413 | * @return array array containing attachment data |
| | 2414 | */ |
| 1952 | 2415 | function wp_import_handle_upload() { |
| 1953 | 2416 | $overrides = array( 'test_form' => false, 'test_type' => false ); |
| 1954 | 2417 | $file = wp_handle_upload( $_FILES['import'], $overrides ); |
| … |
… |
|
| 1974 | 2437 | return array( 'file' => $file, 'id' => $id ); |
| 1975 | 2438 | } |
| 1976 | 2439 | |
| | 2440 | /** |
| | 2441 | * output the attachment links form |
| | 2442 | * |
| | 2443 | * @param int $id attachment ID |
| | 2444 | */ |
| 1977 | 2445 | function the_attachment_links( $id = false ) { |
| 1978 | 2446 | $id = (int) $id; |
| 1979 | 2447 | $post = & get_post( $id ); |
| … |
… |
|
| 2017 | 2485 | <?php |
| 2018 | 2486 | } |
| 2019 | 2487 | |
| | 2488 | /** |
| | 2489 | * compute and return dimensions for displaying a "thumbnail"; apparently not used |
| | 2490 | * |
| | 2491 | * @return array |
| | 2492 | */ |
| 2020 | 2493 | function get_udims( $width, $height) { |
| 2021 | 2494 | if ( $height <= 96 && $width <= 128 ) |
| 2022 | 2495 | return array( $width, $height); |
| … |
… |
|
| 2026 | 2499 | return array( (int) ($width / $height * 96 ), 96 ); |
| 2027 | 2500 | } |
| 2028 | 2501 | |
| | 2502 | /** |
| | 2503 | * resets the variables passed |
| | 2504 | * |
| | 2505 | * @param array $vars array of variable names |
| | 2506 | */ |
| 2029 | 2507 | function wp_reset_vars( $vars ) { |
| 2030 | 2508 | for ( $i=0; $i<count( $vars ); $i += 1 ) { |
| 2031 | 2509 | $var = $vars[$i]; |
| … |
… |
|
| 2044 | 2522 | } |
| 2045 | 2523 | } |
| 2046 | 2524 | |
| 2047 | | |
| | 2525 | /** |
| | 2526 | * output a hidden input field with the current post slug |
| | 2527 | */ |
| 2048 | 2528 | function wp_remember_old_slug() { |
| 2049 | 2529 | global $post; |
| 2050 | 2530 | $name = attribute_escape($post->post_name); // just in case |
| … |
… |
|
| 2053 | 2533 | } |
| 2054 | 2534 | |
| 2055 | 2535 | |
| 2056 | | // If siteurl or home changed, reset cookies and flush rewrite rules. |
| | 2536 | /** |
| | 2537 | * If siteurl or home changed, reset cookies and flush rewrite rules. |
| | 2538 | * |
| | 2539 | * @param string $old_value |
| | 2540 | * @param string $value |
| | 2541 | */ |
| 2057 | 2542 | function update_home_siteurl( $old_value, $value ) { |
| 2058 | 2543 | global $wp_rewrite, $user_login, $user_pass_md5; |
| 2059 | 2544 | |
| … |
… |
|
| 2071 | 2556 | add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); |
| 2072 | 2557 | add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); |
| 2073 | 2558 | |
| | 2559 | /** |
| | 2560 | * crop an image |
| | 2561 | * |
| | 2562 | * @param mixed $src_file filename or attachment ID |
| | 2563 | * @param int $src_x starting x |
| | 2564 | * @param int $src_y starting y |
| | 2565 | * @param int $src_w crop width |
| | 2566 | * @param int $src_h crop height |
| | 2567 | * @param int $dst_w output width |
| | 2568 | * @param int $dst_h output width |
| | 2569 | * @param bool $src_abs whether $src_w and $src_h are absolute coordinates instead of width and height |
| | 2570 | * @param string $dst_file destination filename |
| | 2571 | * @return mixed the path to the cropped file or false on error |
| | 2572 | */ |
| 2074 | 2573 | function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { |
| 2075 | 2574 | if ( ctype_digit( $src_file ) ) // Handle int as attachment ID |
| 2076 | 2575 | $src_file = get_attached_file( $src_file ); |
| … |
… |
|
| 2103 | 2602 | return false; |
| 2104 | 2603 | } |
| 2105 | 2604 | |
| | 2605 | /** |
| | 2606 | * load an image |
| | 2607 | * |
| | 2608 | * @param mixed $file file name or attachment ID |
| | 2609 | * @return int resource |
| | 2610 | */ |
| 2106 | 2611 | function wp_load_image( $file ) { |
| 2107 | 2612 | if ( ctype_digit( $file ) ) |
| 2108 | 2613 | $file = get_attached_file( $file ); |
| … |
… |
|
| 2123 | 2628 | return $image; |
| 2124 | 2629 | } |
| 2125 | 2630 | |
| | 2631 | /** |
| | 2632 | * retrieve metadata for an image attachment |
| | 2633 | * |
| | 2634 | * @filter wp_generate_attachment_metadata |
| | 2635 | * @filter wp_thumbnail_creation_size_limit |
| | 2636 | * @filter wp_thumbnail_max_side_length |
| | 2637 | * @param int $attachment_id attachment ID |
| | 2638 | * @param string $file file path |
| | 2639 | * @return array |
| | 2640 | */ |
| 2126 | 2641 | function wp_generate_attachment_metadata( $attachment_id, $file ) { |
| 2127 | 2642 | $attachment = get_post( $attachment_id ); |
| 2128 | 2643 | |
| … |
… |
|
| 2148 | 2663 | return apply_filters( 'wp_generate_attachment_metadata', $metadata ); |
| 2149 | 2664 | } |
| 2150 | 2665 | |
| | 2666 | /** |
| | 2667 | * create a thumbnail |
| | 2668 | * |
| | 2669 | * @filter thumbnail_filename |
| | 2670 | * @filter wp_create_thumbnail |
| | 2671 | * @param string $file file name |
| | 2672 | * @param int $max_side length of the longest side |
| | 2673 | * @param string $effect apparently unused |
| | 2674 | * @return string thumbnail path |
| | 2675 | */ |
| 2151 | 2676 | function wp_create_thumbnail( $file, $max_side, $effect = '' ) { |
| 2152 | 2677 | |
| 2153 | 2678 | // 1 = GIF, 2 = JPEG, 3 = PNG |