Changeset 810
- Timestamp:
- 11/24/06 16:16:44 (3 years ago)
- Files:
-
- trunk/index.php (modified) (1 diff)
- trunk/wp-admin/admin-ajax.php (modified) (1 diff)
- trunk/wp-admin/admin-db.php (modified) (12 diffs)
- trunk/wp-admin/admin-functions.php (modified) (88 diffs)
- trunk/wp-admin/admin-header.php (modified) (1 diff)
- trunk/wp-admin/bookmarklet.php (modified) (2 diffs)
- trunk/wp-admin/categories.php (modified) (7 diffs)
- trunk/wp-admin/comment.php (modified) (1 diff)
- trunk/wp-admin/custom-fields.js (modified) (1 diff)
- trunk/wp-admin/dbx-admin-key-js.php (modified) (1 diff)
- trunk/wp-admin/edit-category-form.php (modified) (1 diff)
- trunk/wp-admin/edit-comments.php (modified) (6 diffs)
- trunk/wp-admin/edit-form-advanced.php (modified) (5 diffs)
- trunk/wp-admin/edit-form-comment.php (modified) (1 diff)
- trunk/wp-admin/edit-form.php (modified) (1 diff)
- trunk/wp-admin/edit-link-form.php (modified) (3 diffs)
- trunk/wp-admin/edit-page-form.php (modified) (6 diffs)
- trunk/wp-admin/edit-pages.php (modified) (3 diffs)
- trunk/wp-admin/edit.php (modified) (13 diffs)
- trunk/wp-admin/export.php (modified) (5 diffs)
- trunk/wp-admin/import/blogger.php (modified) (1 diff)
- trunk/wp-admin/import/blogware.php (modified) (7 diffs)
- trunk/wp-admin/import/dotclear.php (modified) (18 diffs)
- trunk/wp-admin/import/greymatter.php (modified) (4 diffs)
- trunk/wp-admin/import/mt.php (modified) (1 diff)
- trunk/wp-admin/import/textpattern.php (modified) (18 diffs)
- trunk/wp-admin/import/wordpress.php (modified) (1 diff)
- trunk/wp-admin/index-extra.php (added)
- trunk/wp-admin/install-helper.php (modified) (5 diffs)
- trunk/wp-admin/link-add.php (modified) (2 diffs)
- trunk/wp-admin/link-import.php (modified) (5 diffs)
- trunk/wp-admin/link-manager.php (modified) (7 diffs)
- trunk/wp-admin/link-parse-opml.php (modified) (3 diffs)
- trunk/wp-admin/link.php (modified) (6 diffs)
- trunk/wp-admin/menu-header.php (modified) (3 diffs)
- trunk/wp-admin/menu.php (modified) (2 diffs)
- trunk/wp-admin/moderation.php (modified) (7 diffs)
- trunk/wp-admin/options-misc.php (modified) (2 diffs)
- trunk/wp-admin/options-permalink.php (modified) (1 diff)
- trunk/wp-admin/options-reading.php (modified) (2 diffs)
- trunk/wp-admin/options-writing.php (modified) (1 diff)
- trunk/wp-admin/plugin-editor.php (modified) (2 diffs)
- trunk/wp-admin/plugins.php (modified) (2 diffs)
- trunk/wp-admin/post.php (modified) (2 diffs)
- trunk/wp-admin/profile.php (modified) (3 diffs)
- trunk/wp-admin/setup-config.php (modified) (4 diffs)
- trunk/wp-admin/sidebar.php (modified) (2 diffs)
- trunk/wp-admin/templates.php (modified) (6 diffs)
- trunk/wp-admin/theme-editor.php (modified) (4 diffs)
- trunk/wp-admin/themes.php (modified) (1 diff)
- trunk/wp-admin/update-links.php (modified) (1 diff)
- trunk/wp-admin/upgrade-functions.php (modified) (15 diffs)
- trunk/wp-admin/upgrade-schema.php (modified) (1 diff)
- trunk/wp-admin/upgrade.php (modified) (1 diff)
- trunk/wp-admin/upload-functions.php (modified) (2 diffs)
- trunk/wp-admin/upload-js.php (modified) (8 diffs)
- trunk/wp-admin/upload-rtl.css (modified) (2 diffs)
- trunk/wp-admin/upload.css (modified) (2 diffs)
- trunk/wp-admin/upload.php (modified) (5 diffs)
- trunk/wp-admin/user-edit.php (modified) (2 diffs)
- trunk/wp-admin/users.php (modified) (10 diffs)
- trunk/wp-admin/wp-admin.css (modified) (4 diffs)
- trunk/wp-admin/xfn.js (modified) (1 diff)
- trunk/wp-atom.php (modified) (4 diffs)
- trunk/wp-commentsrss2.php (modified) (3 diffs)
- trunk/wp-content/themes/classic/comments-popup.php (modified) (2 diffs)
- trunk/wp-content/themes/classic/comments.php (modified) (2 diffs)
- trunk/wp-content/themes/classic/header.php (modified) (1 diff)
- trunk/wp-content/themes/classic/sidebar.php (modified) (1 diff)
- trunk/wp-content/themes/default/archives.php (modified) (1 diff)
- trunk/wp-content/themes/default/comments-popup.php (modified) (2 diffs)
- trunk/wp-content/themes/default/comments.php (modified) (3 diffs)
- trunk/wp-content/themes/default/header.php (modified) (1 diff)
- trunk/wp-content/themes/default/page.php (modified) (2 diffs)
- trunk/wp-content/themes/default/sidebar.php (modified) (1 diff)
- trunk/wp-content/themes/default/single.php (modified) (2 diffs)
- trunk/wp-cron.php (modified) (3 diffs)
- trunk/wp-feed.php (modified) (1 diff)
- trunk/wp-includes/author-template.php (modified) (1 diff)
- trunk/wp-includes/bookmark-template.php (modified) (3 diffs)
- trunk/wp-includes/bookmark.php (modified) (2 diffs)
- trunk/wp-includes/cache.php (modified) (3 diffs)
- trunk/wp-includes/capabilities.php (modified) (11 diffs)
- trunk/wp-includes/category-template.php (modified) (3 diffs)
- trunk/wp-includes/category.php (modified) (3 diffs)
- trunk/wp-includes/classes.php (modified) (24 diffs)
- trunk/wp-includes/comment-template.php (modified) (8 diffs)
- trunk/wp-includes/comment.php (modified) (11 diffs)
- trunk/wp-includes/compat.php (modified) (4 diffs)
- trunk/wp-includes/deprecated.php (modified) (8 diffs)
- trunk/wp-includes/feed.php (modified) (1 diff)
- trunk/wp-includes/formatting.php (modified) (15 diffs)
- trunk/wp-includes/functions.php (modified) (10 diffs)
- trunk/wp-includes/general-template.php (modified) (7 diffs)
- trunk/wp-includes/js/autosave.js.php (modified) (1 diff)
- trunk/wp-includes/js/list-manipulation-js.php (modified) (5 diffs)
- trunk/wp-includes/js/tinymce/license.txt (modified) (12 diffs)
- trunk/wp-includes/js/tinymce/plugins/autosave/editor_plugin.js (modified) (3 diffs)
- trunk/wp-includes/js/tinymce/plugins/directionality/editor_plugin.js (modified) (3 diffs)
- trunk/wp-includes/js/tinymce/plugins/inlinepopups/editor_plugin.js (modified) (4 diffs)
- trunk/wp-includes/js/tinymce/plugins/inlinepopups/jscripts/mcwindows.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/plugins/paste/editor_plugin.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/plugins/paste/jscripts/pastetext.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/plugins/paste/jscripts/pasteword.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/charmap.htm (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/color_picker.htm (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/css/editor_content.css (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/css/editor_popup.css (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/css/editor_ui.css (modified) (1 diff)
- trunk/wp-includes/js/tinymce/themes/advanced/editor_template.js (modified) (19 diffs)
- trunk/wp-includes/js/tinymce/themes/advanced/editor_template_src.js (deleted)
- trunk/wp-includes/js/tinymce/themes/advanced/images/backcolor.gif (modified) (previous)
- trunk/wp-includes/js/tinymce/themes/advanced/images/buttons.gif (modified) (previous)
- trunk/wp-includes/js/tinymce/themes/advanced/images/forecolor.gif (modified) (previous)
- trunk/wp-includes/js/tinymce/themes/advanced/jscripts/source_editor.js (modified) (3 diffs)
- trunk/wp-includes/js/tinymce/themes/advanced/langs/en.js (modified) (2 diffs)
- trunk/wp-includes/js/tinymce/tiny_mce.js (modified) (223 diffs)
- trunk/wp-includes/js/tinymce/tiny_mce_popup.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/utils/form_utils.js (modified) (4 diffs)
- trunk/wp-includes/js/tinymce/utils/mclayer.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/utils/mctabs.js (modified) (1 diff)
- trunk/wp-includes/js/tinymce/utils/validate.js (modified) (2 diffs)
- trunk/wp-includes/js/wp-ajax-js.php (modified) (2 diffs)
- trunk/wp-includes/l10n.php (modified) (1 diff)
- trunk/wp-includes/link-template.php (modified) (11 diffs)
- trunk/wp-includes/pluggable.php (modified) (8 diffs)
- trunk/wp-includes/post.php (modified) (21 diffs)
- trunk/wp-includes/query.php (modified) (24 diffs)
- trunk/wp-includes/registration.php (modified) (1 diff)
- trunk/wp-includes/rewrite.php (modified) (25 diffs)
- trunk/wp-includes/script-loader.php (modified) (4 diffs)
- trunk/wp-includes/theme.php (modified) (17 diffs)
- trunk/wp-includes/user.php (modified) (1 diff)
- trunk/wp-includes/wp-db.php (modified) (1 diff)
- trunk/wp-includes/wpmu-functions.php (modified) (1 diff)
- trunk/wp-links-opml.php (modified) (2 diffs)
- trunk/wp-login.php (modified) (1 diff)
- trunk/wp-rss.php (modified) (2 diffs)
- trunk/wp-rss2.php (modified) (3 diffs)
- trunk/wp-settings.php (modified) (4 diffs)
- trunk/wp-trackback.php (modified) (1 diff)
- trunk/xmlrpc.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/index.php
r591 r810 1 <?php 1 <?php 2 2 /* Short and sweet */ 3 3 define('WP_USE_THEMES', true); trunk/wp-admin/admin-ajax.php
r753 r810 129 129 case 'add-cat' : // From Manage->Categories 130 130 if ( !current_user_can( 'manage_categories' ) ) 131 die('-1');131 die('-1'); 132 132 if ( !$cat = wp_insert_category( $_POST ) ) 133 133 die('0'); trunk/wp-admin/admin-db.php
r798 r810 49 49 if ( $user->has_cap('edit_posts') || $exclude_zeros == false ) 50 50 return array($user->id); 51 else 51 else 52 52 return false; 53 53 } … … 157 157 158 158 $cat_ID = (int) $catarr['cat_ID']; 159 160 if( $cat_ID == $catarr['category_parent'] ) 161 return false; 159 162 160 163 // First, get all of the original fields … … 202 205 else 203 206 $cats = array_diff($cats, array($cat_ID)); 204 wp_set_post_categories($post_id, $cats); 207 wp_set_post_categories($post_id, $cats); 205 208 } 206 209 … … 213 216 else 214 217 $cats = array_diff($cats, array($cat_ID)); 215 wp_set_link_cats($link_id, $cats); 216 } 217 218 wp_set_link_cats($link_id, $cats); 219 } 220 218 221 wp_cache_delete($cat_ID, 'category'); 219 222 wp_cache_delete('all_category_ids', 'category'); … … 288 291 function wp_revoke_user($id) { 289 292 $id = (int) $id; 290 293 291 294 $user = new WP_User($id); 292 $user->remove_all_caps(); 295 $user->remove_all_caps(); 293 296 } 294 297 … … 388 391 389 392 // Passed link category list overwrites existing category list if not empty. 390 if ( isset($linkdata['link_category']) && is_array($linkdata['link_category'])393 if ( isset($linkdata['link_category']) && is_array($linkdata['link_category']) 391 394 && 0 != count($linkdata['link_category']) ) 392 $link_cats = $linkdata['link_category'];393 else 394 $link_cats = $link['link_category'];395 $link_cats = $linkdata['link_category']; 396 else 397 $link_cats = $link['link_category']; 395 398 396 399 // Merge old and new fields with new fields overwriting old ones. 397 400 $linkdata = array_merge($link, $linkdata); 398 $linkdata['link_category'] = $link_cats;401 $linkdata['link_category'] = $link_cats; 399 402 400 403 return wp_insert_link($linkdata); … … 405 408 406 409 do_action('delete_link', $link_id); 407 410 408 411 $categories = wp_get_link_cats($link_id); 409 412 if( is_array( $categories ) ) { … … 421 424 global $wpdb; 422 425 423 $sql = "SELECT category_id 424 FROM $wpdb->link2cat 425 WHERE link_id = $link_ID 426 $sql = "SELECT category_id 427 FROM $wpdb->link2cat 428 WHERE link_id = $link_ID 426 429 ORDER BY category_id"; 427 430 … … 444 447 // First the old categories 445 448 $old_categories = $wpdb->get_col(" 446 SELECT category_id 447 FROM $wpdb->link2cat 449 SELECT category_id 450 FROM $wpdb->link2cat 448 451 WHERE link_id = $link_ID"); 449 452 … … 460 463 foreach ($delete_cats as $del) { 461 464 $wpdb->query(" 462 DELETE FROM $wpdb->link2cat 463 WHERE category_id = $del 464 AND link_id = $link_ID 465 DELETE FROM $wpdb->link2cat 466 WHERE category_id = $del 467 AND link_id = $link_ID 465 468 "); 466 469 } … … 473 476 foreach ($add_cats as $new_cat) { 474 477 $wpdb->query(" 475 INSERT INTO $wpdb->link2cat (link_id, category_id) 478 INSERT INTO $wpdb->link2cat (link_id, category_id) 476 479 VALUES ($link_ID, $new_cat)"); 477 480 } 478 481 } 479 482 480 483 // Update category counts. 481 484 $all_affected_cats = array_unique(array_merge($link_categories, $old_categories)); … … 484 487 $wpdb->query("UPDATE $wpdb->categories SET link_count = '$count' WHERE cat_ID = '$cat_id'"); 485 488 wp_cache_delete($cat_id, 'category'); 486 } 489 do_action('edit_category', $cat_id); 490 } 491 492 do_action('edit_link', $link_ID); 487 493 } // wp_set_link_cats() 488 494 trunk/wp-admin/admin-functions.php
r804 r810 3 3 function write_post() { 4 4 $result = wp_write_post(); 5 if( is_wp_error( $result) )5 if( is_wp_error( $result ) ) 6 6 wp_die( $result->get_error_message() ); 7 7 else … … 14 14 15 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.'));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 21 } 22 22 … … 27 27 $_POST['to_ping'] = $_POST['trackback_url']; 28 28 29 if (!empty ( $_POST['post_author_override'])) {29 if (!empty ( $_POST['post_author_override'] ) ) { 30 30 $_POST['post_author'] = (int) $_POST['post_author_override']; 31 31 } else { 32 if (!empty ( $_POST['post_author'])) {32 if (!empty ( $_POST['post_author'] ) ) { 33 33 $_POST['post_author'] = (int) $_POST['post_author']; 34 34 } else { … … 38 38 } 39 39 40 if ( $_POST['post_author'] != $_POST['user_ID']) {40 if ( $_POST['post_author'] != $_POST['user_ID'] ) { 41 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.'));42 if ( !current_user_can( 'edit_others_pages' ) ) 43 return new WP_Error( 'edit_others_pages', __( 'You cannot create pages as this user.' ) ); 44 44 } else { 45 if ( !current_user_can( 'edit_others_posts') )46 return new WP_Error( 'edit_others_posts', __('You cannot post as this user.'));45 if ( !current_user_can( 'edit_others_posts' ) ) 46 return new WP_Error( 'edit_others_posts', __( 'You cannot post as this user.' ) ); 47 47 48 48 } … … 50 50 51 51 // What to do based on which button they pressed 52 if ('' != $_POST['saveasdraft'] )52 if ('' != $_POST['saveasdraft'] ) 53 53 $_POST['post_status'] = 'draft'; 54 if ('' != $_POST['saveasprivate'] )54 if ('' != $_POST['saveasprivate'] ) 55 55 $_POST['post_status'] = 'private'; 56 if ('' != $_POST['publish'] )56 if ('' != $_POST['publish'] ) 57 57 $_POST['post_status'] = 'publish'; 58 if ('' != $_POST['advanced'] )58 if ('' != $_POST['advanced'] ) 59 59 $_POST['post_status'] = 'draft'; 60 60 61 61 if ( 'page' == $_POST['post_type'] ) { 62 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages'))62 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) 63 63 $_POST['post_status'] = 'draft'; 64 64 } else { 65 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts'))65 if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) ) 66 66 $_POST['post_status'] = 'draft'; 67 67 } 68 68 69 if (!isset ($_POST['comment_status']))69 if (!isset( $_POST['comment_status'] )) 70 70 $_POST['comment_status'] = 'closed'; 71 71 72 if (!isset ($_POST['ping_status']))72 if (!isset( $_POST['ping_status'] )) 73 73 $_POST['ping_status'] = 'closed'; 74 74 75 if (!empty ( $_POST['edit_date'])) {75 if (!empty ( $_POST['edit_date'] ) ) { 76 76 $aa = $_POST['aa']; 77 77 $mm = $_POST['mm']; … … 80 80 $mn = $_POST['mn']; 81 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']);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 88 } 89 89 90 90 // Create the post. 91 $post_ID = wp_insert_post( $_POST);92 add_meta( $post_ID);91 $post_ID = wp_insert_post( $_POST); 92 add_meta( $post_ID ); 93 93 94 94 // Reunite any orphaned attachments with their parent 95 95 if ( $_POST['temp_ID'] ) 96 relocate_children( $_POST['temp_ID'], $post_ID);96 relocate_children( $_POST['temp_ID'], $post_ID ); 97 97 98 98 // Now that we have an ID we can fix any attachment anchor hrefs 99 fix_attachment_links( $post_ID);99 fix_attachment_links( $post_ID ); 100 100 101 101 return $post_ID; … … 103 103 104 104 // Move child posts to a new parent 105 function relocate_children( $old_ID, $new_ID) {105 function relocate_children( $old_ID, $new_ID ) { 106 106 global $wpdb; 107 107 $old_ID = (int) $old_ID; 108 108 $new_ID = (int) $new_ID; 109 return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID");109 return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); 110 110 } 111 111 112 112 // Replace hrefs of attachment anchors with up-to-date permalinks. 113 function fix_attachment_links( $post_ID) {113 function fix_attachment_links( $post_ID ) { 114 114 global $wp_rewrite; 115 115 116 $post = & get_post( $post_ID, ARRAY_A);117 118 $search = "#<a[^>]+rel=('|\" )[^'\"]*attachment[^>]*>#ie";116 $post = & get_post( $post_ID, ARRAY_A ); 117 118 $search = "#<a[^>]+rel=('|\" )[^'\"]*attachment[^>]*>#ie"; 119 119 120 120 // See if we have any rel="attachment" links 121 if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER) )121 if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) 122 122 return; 123 123 124 124 $i = 0; 125 $search = "#[\s]+rel=(\"|' )(.*?)wp-att-(\d+)\\1#i";125 $search = "#[\s]+rel=(\"|' )(.*? )wp-att-(\d+ )\\1#i"; 126 126 foreach ( $anchor_matches[0] as $anchor ) { 127 if ( 0 == preg_match( $search, $anchor, $id_matches) )127 if ( 0 == preg_match( $search, $anchor, $id_matches ) ) 128 128 continue; 129 129 … … 131 131 132 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'])) ) {133 $attachment = & get_post( $id, ARRAY_A ); 134 if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { 135 135 $attachment['post_parent'] = $post_ID; 136 136 // Escape data pulled from DB. 137 $attachment = add_magic_quotes( $attachment);138 wp_update_post( $attachment);137 $attachment = add_magic_quotes( $attachment); 138 wp_update_post( $attachment); 139 139 } 140 140 141 141 $post_search[$i] = $anchor; 142 $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes('href=\\1').get_attachment_link($id).stripslashes('\\1')", $anchor);142 $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); 143 143 ++$i; 144 144 } 145 145 146 $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content']);146 $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); 147 147 148 148 // Escape data pulled from DB. 149 $post = add_magic_quotes( $post);150 151 return wp_update_post( $post);149 $post = add_magic_quotes( $post); 150 151 return wp_update_post( $post); 152 152 } 153 153 … … 159 159 160 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.'));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 166 } 167 167 … … 173 173 $_POST['to_ping'] = $_POST['trackback_url']; 174 174 175 if (!empty ( $_POST['post_author_override'])) {175 if (!empty ( $_POST['post_author_override'] ) ) { 176 176 $_POST['post_author'] = (int) $_POST['post_author_override']; 177 177 } else 178 if (!empty ( $_POST['post_author'])) {178 if (!empty ( $_POST['post_author'] ) ) { 179 179 $_POST['post_author'] = (int) $_POST['post_author']; 180 180 } else { … … 182 182 } 183 183 184 if ( $_POST['post_author'] != $_POST['user_ID']) {184 if ( $_POST['post_author'] != $_POST['user_ID'] ) { 185 185 if ( 'page' == $_POST['post_type'] ) { 186 if ( !current_user_can( 'edit_others_pages') )187 wp_die( __('You cannot edit pages as this user.'));186 if ( !current_user_can( 'edit_others_pages' ) ) 187 wp_die( __('You cannot edit pages as this user.' )); 188 188 } else { 189 if ( !current_user_can( 'edit_others_posts') )190 wp_die( __('You cannot edit posts as this user.'));189 if ( !current_user_can( 'edit_others_posts' ) ) 190 wp_die( __('You cannot edit posts as this user.' )); 191 191 192 192 } … … 194 194 195 195 // What to do based on which button they pressed 196 if ('' != $_POST['saveasdraft'] )196 if ('' != $_POST['saveasdraft'] ) 197 197 $_POST['post_status'] = 'draft'; 198 if ('' != $_POST['saveasprivate'] )198 if ('' != $_POST['saveasprivate'] ) 199 199 $_POST['post_status'] = 'private'; 200 if ('' != $_POST['publish'] )200 if ('' != $_POST['publish'] ) 201 201 $_POST['post_status'] = 'publish'; 202 if ('' != $_POST['advanced'] )202 if ('' != $_POST['advanced'] ) 203 203 $_POST['post_status'] = 'draft'; 204 204 205 205 if ( 'page' == $_POST['post_type'] ) { 206 if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages'))206 if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' )) 207 207 $_POST['post_status'] = 'draft'; 208 208 } else { 209 if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts'))209 if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' )) 210 210 $_POST['post_status'] = 'draft'; 211 211 } 212 212 213 if (!isset ($_POST['comment_status']))213 if (!isset( $_POST['comment_status'] )) 214 214 $_POST['comment_status'] = 'closed'; 215 215 216 if (!isset ($_POST['ping_status']))216 if (!isset( $_POST['ping_status'] )) 217 217 $_POST['ping_status'] = 'closed'; 218 218 219 if (!empty ( $_POST['edit_date'])) {219 if (!empty ( $_POST['edit_date'] ) ) { 220 220 $aa = $_POST['aa']; 221 221 $mm = $_POST['mm']; … … 224 224 $mn = $_POST['mn']; 225 225 $ss = $_POST['ss']; 226 $jj = ($jj > 31 ) ? 31 : $jj;227 $hh = ($hh > 23 ) ? $hh -24 : $hh;228 $mn = ($mn > 59 ) ? $mn -60 : $mn;229 $ss = ($ss > 59 ) ? $ss -60 : $ss;226 $jj = ($jj > 31 ) ? 31 : $jj; 227 $hh = ($hh > 23 ) ? $hh -24 : $hh; 228 $mn = ($mn > 59 ) ? $mn -60 : $mn; 229 $ss = ($ss > 59 ) ? $ss -60 : $ss; 230 230 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 231 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss");231 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" ); 232 232 } 233 233 234 234 // Meta Stuff 235 if ( $_POST['meta']) {236 foreach ( $_POST['meta'] as $key => $value)237 update_meta( $key, $value['key'], $value['value']);238 } 239 240 if ( $_POST['deletemeta']) {241 foreach ( $_POST['deletemeta'] as $key => $value)242 delete_meta( $key);243 } 244 245 add_meta( $post_ID);246 247 wp_update_post( $_POST);235 if ( $_POST['meta'] ) { 236 foreach ( $_POST['meta'] as $key => $value ) 237 update_meta( $key, $value['key'], $value['value'] ); 238 } 239 240 if ( $_POST['deletemeta'] ) { 241 foreach ( $_POST['deletemeta'] as $key => $value ) 242 delete_meta( $key ); 243 } 244 245 add_meta( $post_ID ); 246 247 wp_update_post( $_POST); 248 248 249 249 // Now that we have an ID we can fix any attachment anchor hrefs 250 fix_attachment_links( $post_ID);250 fix_attachment_links( $post_ID ); 251 251 252 252 return $post_ID; … … 259 259 $comment_post_ID = (int) $_POST['comment_post_ID']; 260 260 261 if (!current_user_can( 'edit_post', $comment_post_ID))262 wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.'));261 if (!current_user_can( 'edit_post', $comment_post_ID )) 262 wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' )); 263 263 264 264 $_POST['comment_author'] = $_POST['newcomment_author']; … … 269 269 $_POST['comment_ID'] = (int) $_POST['comment_ID']; 270 270 271 if (!empty ( $_POST['edit_date'])) {271 if (!empty ( $_POST['edit_date'] ) ) { 272 272 $aa = $_POST['aa']; 273 273 $mm = $_POST['mm']; … … 276 276 $mn = $_POST['mn']; 277 277 $ss = $_POST['ss']; 278 $jj = ($jj > 31 ) ? 31 : $jj;279 $hh = ($hh > 23 ) ? $hh -24 : $hh;280 $mn = ($mn > 59 ) ? $mn -60 : $mn;281 $ss = ($ss > 59 ) ? $ss -60 : $ss;278 $jj = ($jj > 31 ) ? 31 : $jj; 279 $hh = ($hh > 23 ) ? $hh -24 : $hh; 280 $mn = ($mn > 59 ) ? $mn -60 : $mn; 281 $ss = ($ss > 59 ) ? $ss -60 : $ss; 282 282 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 283 283 } 284 284 285 wp_update_comment( $_POST);285 wp_update_comment( $_POST); 286 286 } 287 287 288 288 // Get an existing post and format it for editing. 289 function get_post_to_edit( $id) {290 291 $post = get_post( $id);292 293 $post->post_content = format_to_edit( $post->post_content, user_can_richedit());294 $post->post_content = apply_filters( 'content_edit_pre', $post->post_content);295 296 $post->post_excerpt = format_to_edit( $post->post_excerpt);297 $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt);298 299 $post->post_title = format_to_edit( $post->post_title);300 $post->post_title = apply_filters( 'title_edit_pre', $post->post_title);301 302 $post->post_password = format_to_edit( $post->post_password);303 304 if ( $post->post_type == 'page')305 $post->page_template = get_post_meta( $id, '_wp_page_template', true);289 function get_post_to_edit( $id ) { 290 291 $post = get_post( $id ); 292 293 $post->post_content = format_to_edit( $post->post_content, user_can_richedit() ); 294 $post->post_content = apply_filters( 'content_edit_pre', $post->post_content); 295 296 $post->post_excerpt = format_to_edit( $post->post_excerpt); 297 $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt); 298 299 $post->post_title = format_to_edit( $post->post_title ); 300 $post->post_title = apply_filters( 'title_edit_pre', $post->post_title ); 301 302 $post->post_password = format_to_edit( $post->post_password ); 303 304 if ( $post->post_type == 'page' ) 305 $post->page_template = get_post_meta( $id, '_wp_page_template', true ); 306 306 307 307 return $post; … … 310 310 // Default post information to use when populating the "Write Post" form. 311 311 function get_default_post_to_edit() { 312 if ( !empty( $_REQUEST['post_title']) )313 $post_title = wp_specialchars( stripslashes($_REQUEST['post_title']));314 else if ( !empty( $_REQUEST['popuptitle']) ) {315 $post_title = wp_specialchars( stripslashes($_REQUEST['popuptitle']));316 $post_title = funky_javascript_fix( $post_title);312 if ( !empty( $_REQUEST['post_title'] ) ) 313 $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); 314 else if ( !empty( $_REQUEST['popuptitle'] ) ) { 315 $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); 316 $post_title = funky_javascript_fix( $post_title ); 317 317 } else { 318 318 $post_title = ''; 319 319 } 320 320 321 if ( !empty( $_REQUEST['content']) )322 $post_content = wp_specialchars( stripslashes($_REQUEST['content']));323 else if ( !empty( $post_title) ) {324 $text = wp_specialchars( stripslashes(urldecode($_REQUEST['text'])));325 $text = funky_javascript_fix( $text);326 $popupurl = wp_specialchars( $_REQUEST['popupurl']);321 if ( !empty( $_REQUEST['content'] ) ) 322 $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); 323 else if ( !empty( $post_title ) ) { 324 $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); 325 $text = funky_javascript_fix( $text); 326 $popupurl = wp_specialchars( $_REQUEST['popupurl'] ); 327 327 $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text"; 328 328 } 329 329 330 if ( !empty( $_REQUEST['excerpt']) )331 $post_excerpt = wp_specialchars( stripslashes($_REQUEST['excerpt']));330 if ( !empty( $_REQUEST['excerpt'] ) ) 331 $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] )); 332 332 else 333 333 $post_excerpt = ''; 334 334 335 335 $post->post_status = 'draft'; 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');340 $post->post_content = apply_filters( 'default_content', $post_content);341 $post->post_title = apply_filters( 'default_title', $post_title);342 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);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' ); 340 $post->post_content = apply_filters( 'default_content', $post_content); 341 $post->post_title = apply_filters( 'default_title', $post_title ); 342 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt); 343 343 $post->page_template = 'default'; 344 344 $post->post_parent = 0; … … 348 348 } 349 349 350 function get_comment_to_edit( $id) {351 $comment = get_comment( $id);352 353 $comment->comment_content = format_to_edit( $comment->comment_content, user_can_richedit());354 $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content);355 356 $comment->comment_author = format_to_edit( $comment->comment_author);357 $comment->comment_author_email = format_to_edit( $comment->comment_author_email);358 $comment->comment_author_url = format_to_edit( $comment->comment_author_url);350 function get_comment_to_edit( $id ) { 351 $comment = get_comment( $id ); 352 353 $comment->comment_content = format_to_edit( $comment->comment_content, user_can_richedit() ); 354 $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content); 355 356 $comment->comment_author = format_to_edit( $comment->comment_author ); 357 $comment->comment_author_email = format_to_edit( $comment->comment_author_email ); 358 $comment->comment_author_url = format_to_edit( $comment->comment_author_url ); 359 359 360 360 return $comment; 361 361 } 362 362 363 function get_category_to_edit( $id) {364 $category = get_category( $id);363 function get_category_to_edit( $id ) { 364 $category = get_category( $id ); 365 365 366 366 return $category; … … 370 370 global $wp_roles; 371 371 $r = ''; 372 foreach( $wp_roles->role_names as $role => $name)372 foreach( $wp_roles->role_names as $role => $name ) 373 373 if ( $default == $role ) // Make default first in list 374 374 $p = "\n\t<option selected='selected' value='$role'>$name</option>"; … … 379 379 380 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);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 394 395 395 return $user; … … 401 401 if ( func_num_args() ) { // The hackiest hack that ever did hack 402 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']);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 409 } 410 410 } 411 411 } else { 412 add_action( 'user_register', 'add_user'); // See above412 add_action( 'user_register', 'add_user' ); // See above 413 413 return edit_user(); 414 414 } 415 415 } 416 416 417 function edit_user( $user_id = 0) {417 function edit_user( $user_id = 0 ) { 418 418 global $current_user, $wp_roles, $wpdb; 419 if ( $user_id != 0) {419 if ( $user_id != 0 ) { 420 420 $update = true; 421 421 $user->ID = $user_id; 422 $userdata = get_userdata( $user_id);423 $user->user_login = $wpdb->escape( $userdata->user_login);422 $userdata = get_userdata( $user_id ); 423 $user->user_login = $wpdb->escape( $userdata->user_login ); 424 424 } else { 425 425 $update = false; … … 427 427 } 428 428 429 if ( isset ($_POST['user_login']))430 $user->user_login = wp_specialchars( trim($_POST['user_login']));429 if ( isset( $_POST['user_login'] )) 430 $user->user_login = wp_specialchars( trim( $_POST['user_login'] )); 431 431 432 432 $pass1 = $pass2 = ''; 433 if ( isset ($_POST['pass1']))433 if ( isset( $_POST['pass1'] )) 434 434 $pass1 = $_POST['pass1']; 435 if ( isset ($_POST['pass2']))435 if ( isset( $_POST['pass2'] )) 436 436 $pass2 = $_POST['pass2']; 437 437 438 if ( isset ($_POST['role']) && current_user_can('edit_users')) {439 if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users'))438 if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { 439 if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' )) 440 440 $user->role = $_POST['role']; 441 441 } 442 442 443 if ( isset ($_POST['email']))444 $user->user_email = wp_specialchars( trim($_POST['email']));445 if ( isset ($_POST['url'])) {446 $user->user_url = wp_specialchars( trim($_POST['url']));447 $user->user_url = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url;448 } 449 if ( isset ($_POST['first_name']))450 $user->first_name = wp_specialchars( trim($_POST['first_name']));451 if ( isset ($_POST['last_name']))452 $user->last_name = wp_specialchars( trim($_POST['last_name']));453 if ( isset ($_POST['nickname']))454 $user->nickname = wp_specialchars( trim($_POST['nickname']));455 if ( isset ($_POST['display_name']))456 $user->display_name = wp_specialchars( trim($_POST['display_name']));457 if ( isset ($_POST['description']))458 $user->description = trim( $_POST['description']);459 if ( isset ($_POST['jabber']))460 $user->jabber = wp_specialchars( trim($_POST['jabber']));461 if ( isset ($_POST['aim']))462 $user->aim = wp_specialchars( trim($_POST['aim']));463 if ( isset ($_POST['yim']))464 $user->yim = wp_specialchars( trim($_POST['yim']));443 if ( isset( $_POST['email'] )) 444 $user->user_email = wp_specialchars( trim( $_POST['email'] )); 445 if ( isset( $_POST['url'] ) ) { 446 $user->user_url = wp_specialchars( trim( $_POST['url'] )); 447 $user->user_url = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url ) ? $user->user_url : 'http://'.$user->user_url; 448 } 449 if ( isset( $_POST['first_name'] )) 450 $user->first_name = wp_specialchars( trim( $_POST['first_name'] )); 451 if ( isset( $_POST['last_name'] )) 452 $user->last_name = wp_specialchars( trim( $_POST['last_name'] )); 453 if ( isset( $_POST['nickname'] )) 454 $user->nickname = wp_specialchars( trim( $_POST['nickname'] )); 455 if ( isset( $_POST['display_name'] )) 456 $user->display_name = wp_specialchars( trim( $_POST['display_name'] )); 457 if ( isset( $_POST['description'] )) 458 $user->description = trim( $_POST['description'] ); 459 if ( isset( $_POST['jabber'] )) 460 $user->jabber = wp_specialchars( trim( $_POST['jabber'] )); 461 if ( isset( $_POST['aim'] )) 462 $user->aim = wp_specialchars( trim( $_POST['aim'] )); 463 if ( isset( $_POST['yim'] )) 464 $user->yim = wp_specialchars( trim( $_POST['yim'] )); 465 465 466 466 $errors = new WP_Error(); 467 467 468 468 /* checking that username has been typed */ 469 if ( $user->user_login == '')470 $errors->add( 'user_login', __('<strong>ERROR</strong>: Please enter a username.'));469 if ( $user->user_login == '' ) 470 $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' )); 471 471 472 472 /* checking the password has been typed twice */ 473 do_action_ref_array( 'check_passwords', array ($user->user_login, & $pass1, & $pass2));474 475 if (!$update ) {476 if ( $pass1 == '' || $pass2 == '')477 $errors->add( 'pass', __('<strong>ERROR</strong>: Please enter your password twice.'));478 } else { 479 if ((empty ( $pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1)))480 $errors->add( 'pass', __("<strong>ERROR</strong>: you typed your new password only once."));473 do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); 474 475 if (!$update ) { 476 if ( $pass1 == '' || $pass2 == '' ) 477 $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); 478 } else { 479 if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) ) 480 $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." )); 481 481 } 482 482 483 483 /* Check for "\" in password */ 484 484 if( strpos( " ".$pass1, "\\" ) ) 485 $errors->add( 'pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".'));485 $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); 486 486 487 487 /* checking the password has been typed twice the same */ 488 if ( $pass1 != $pass2)489 $errors->add( 'pass', __('<strong>ERROR</strong>: Please type the same password in the two password fields.'));490 491 if (!empty ( $pass1))488 if ( $pass1 != $pass2 ) 489 $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' )); 490 491 if (!empty ( $pass1 )) 492 492 $user->user_pass = $pass1; 493 493 494 if ( !validate_username( $user->user_login) )495 $errors->add( 'user_login', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.'));496 497 if (!$update && username_exists( $user->user_login))498 $errors->add( 'user_login', __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));494 if ( !validate_username( $user->user_login ) ) 495 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); 496 497 if (!$update && username_exists( $user->user_login )) 498 $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' )); 499 499 500 500 /* checking e-mail address */ 501 if ( empty ($user->user_email)) {502 $errors->add( 'user_email', __("<strong>ERROR</strong>: please type an e-mail address"));501 if ( empty ( $user->user_email ) ) { 502 $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" )); 503 503 } else 504 if (!is_email( $user->user_email)) {505 $errors->add( 'user_email', __("<strong>ERROR</strong>: the email address isn't correct"));504 if (!is_email( $user->user_email ) ) { 505 $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" )); 506 506 } 507 507 … … 509 509 return $errors; 510 510 511 if ( $update) {512 $user_id = wp_update_user( get_object_vars($user));513 } else { 514 $user_id = wp_insert_user( get_object_vars($user));515 wp_new_user_notification( $user_id);511 if ( $update ) { 512 $user_id = wp_update_user( get_object_vars( $user )); 513 } else { 514 $user_id = wp_insert_user( get_object_vars( $user )); 515 wp_new_user_notification( $user_id ); 516 516 } 517 517 return $user_id; … … 519 519 520 520 521 function get_link_to_edit( $link_id) {522 $link = get_link( $link_id);523 524 $link->link_url = wp_specialchars( $link->link_url, 1);525 $link->link_name = wp_specialchars( $link->link_name, 1);526 $link->link_image = wp_specialchars( $link->link_image, 1);527 $link->link_description = wp_specialchars( $link->link_description, 1);528 $link->link_notes = wp_specialchars( $link->link_notes);529 $link->link_rss = wp_specialchars( $link->link_rss, 1);530 $link->link_rel = wp_specialchars( $link->link_rel, 1);521 function get_link_to_edit( $link_id ) { 522 $link = get_link( $link_id ); 523 524 $link->link_url = wp_specialchars( $link->link_url, 1 ); 525 $link->link_name = wp_specialchars( $link->link_name, 1 ); 526 $link->link_image = wp_specialchars( $link->link_image, 1 ); 527 $link->link_description = wp_specialchars( $link->link_description, 1 ); 528 $link->link_notes = wp_specialchars( $link->link_notes ); 529 $link->link_rss = wp_specialchars( $link->link_rss, 1 ); 530 $link->link_rel = wp_specialchars( $link->link_rel, 1 ); 531 531 $link->post_category = $link->link_category; 532 532 … … 535 535 536 536 function get_default_link_to_edit() { 537 if ( isset( $_GET['linkurl']) )538 $link->link_url = wp_specialchars( $_GET['linkurl'], 1);537 if ( isset( $_GET['linkurl'] ) ) 538 $link->link_url = wp_specialchars( $_GET['linkurl'], 1 ); 539 539 else 540 540 $link->link_url = ''; 541 541 542 if ( isset( $_GET['name']) )543 $link->link_name = wp_specialchars( $_GET['name'], 1);542 if ( isset( $_GET['name'] ) ) 543 $link->link_name = wp_specialchars( $_GET['name'], 1 ); 544 544 else 545 545 $link->link_name = ''; … … 554 554 } 555 555 556 function edit_link( $link_id = '') {557 if (!current_user_can( 'manage_links'))558 wp_die( __("Cheatin' uh ?"));559 560 $_POST['link_url'] = wp_specialchars( $_POST['link_url']);561 $_POST['link_url'] = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url']) ? $_POST['link_url'] : 'http://' . $_POST['link_url'];562 $_POST['link_name'] = wp_specialchars( $_POST['link_name']);563 $_POST['link_image'] = wp_specialchars( $_POST['link_image']);564 $_POST['link_rss'] = wp_specialchars( $_POST['link_rss']);556 function edit_link( $link_id = '' ) { 557 if (!current_user_can( 'manage_links' )) 558 wp_die( __("Cheatin' uh ?" )); 559 560 $_POST['link_url'] = wp_specialchars( $_POST['link_url'] ); 561 $_POST['link_url'] = preg_match( '/^(https?|ftps?|mailto|news|gopher):/is', $_POST['link_url'] ) ? $_POST['link_url'] : 'http://' . $_POST['link_url']; 562 $_POST['link_name'] = wp_specialchars( $_POST['link_name'] ); 563 $_POST['link_image'] = wp_specialchars( $_POST['link_image'] ); 564 $_POST['link_rss'] = wp_specialchars( $_POST['link_rss'] ); 565 565 $_POST['link_category'] = $_POST['post_category']; 566 566 567 if ( !empty( $link_id) ) {567 if ( !empty( $link_id ) ) { 568 568 $_POST['link_id'] = $link_id; 569 return wp_update_link( $_POST);570 } else { 571 return wp_insert_link( $_POST);572 } 573 } 574 575 function url_shorten( $url) {576 $short_url = str_replace( 'http://', '', stripslashes($url));577 $short_url = str_replace( 'www.', '', $short_url);578 if ('/' == substr( $short_url, -1))579 $short_url = substr( $short_url, 0, -1);580 if ( strlen($short_url) > 35)581 $short_url = substr( $short_url, 0, 32).'...';569 return wp_update_link( $_POST); 570 } else { 571 return wp_insert_link( $_POST); 572 } 573 } 574 575 function url_shorten( $url ) { 576 $short_url = str_replace( 'http://', '', stripslashes( $url )); 577 $short_url = str_replace( 'www.', '', $short_url ); 578 if ('/' == substr( $short_url, -1 )) 579 $short_url = substr( $short_url, 0, -1 ); 580 if ( strlen( $short_url ) > 35 ) 581 $short_url = substr( $short_url, 0, 32 ).'...'; 582 582 return $short_url; 583 583 } 584 584 585 function selected( $selected, $current) {586 if ( $selected == $current)585 function selected( $selected, $current) { 586 if ( $selected == $current) 587 587 echo ' selected="selected"'; 588 588 } 589 589 590 function checked( $checked, $current) {591 if ( $checked == $current)590 function checked( $checked, $current) { 591 if ( $checked == $current) 592 592 echo ' checked="checked"'; 593 593 } 594 594 595 function return_categories_list( $parent = 0) {595 function return_categories_list( $parent = 0 ) { 596 596 global $wpdb; 597 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC");598 } 599 600 function sort_cats( $cat1, $cat2) {601 return strcasecmp( $cat1['cat_name'], $cat2['cat_name']);602 } 603 604 function get_nested_categories( $default = 0, $parent = 0) {597 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC" ); 598 } 599 600 function sort_cats( $cat1, $cat2 ) { 601 return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); 602 } 603 604 function get_nested_categories( $default = 0, $parent = 0 ) { 605 605 global $post_ID, $link_id, $mode, $wpdb; 606 606 607 if ( $post_ID) {608 $checked_categories = $wpdb->get_col( "607 if ( $post_ID ) { 608 $checked_categories = $wpdb->get_col( " 609 609 SELECT category_id 610 610 FROM $wpdb->categories, $wpdb->post2cat 611 611 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 612 " );613 614 if ( count($checked_categories) == 0) {612 " ); 613 614 if ( count( $checked_categories ) == 0 ) { 615 615 // No selected categories, strange 616 616 $checked_categories[] = $default; 617 617 } 618 } else if ( $link_id) {619 $checked_categories = $wpdb->get_col( "618 } else if ( $link_id ) { 619 $checked_categories = $wpdb->get_col( " 620 620 SELECT category_id 621 621 FROM $wpdb->categories, $wpdb->link2cat 622 622 WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 623 " );624 625 if ( count($checked_categories) == 0) {623 " ); 624 625 if ( count( $checked_categories ) == 0 ) { 626 626 // No selected categories, strange 627 627 $checked_categories[] = $default; … … 631 631 } 632 632 633 $cats = return_categories_list( $parent);633 $cats = return_categories_list( $parent); 634 634 $result = array (); 635 635 636 if ( is_array($cats)) {637 foreach ( $cats as $cat) {636 if ( is_array( $cats ) ) { 637 foreach ( $cats as $cat) { 638 638 if ( $cat == 0 ) { // HACK, added 2006-05-13 639 639 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); 640 640 continue; 641 641 } 642 $result[$cat]['children'] = get_nested_categories( $default, $cat);642 $result[$cat]['children'] = get_nested_categories( $default, $cat); 643 643 $result[$cat]['cat_ID'] = $cat; 644 $result[$cat]['checked'] = in_array( $cat, $checked_categories);645 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);646 } 647 } 648 649 usort( $result, 'sort_cats');644 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 645 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 646 } 647 } 648 649 usort( $result, 'sort_cats' ); 650 650 651 651 return $result; 652 652 } 653 653 654 function write_nested_categories( $categories) {655 foreach ( $categories as $category) {656 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";654 function write_nested_categories( $categories ) { 655 foreach ( $categories as $category ) { 656 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>"; 657 657 658 658 if ( $category['children'] ) { 659 659 echo "<ul>\n"; 660 write_nested_categories( $category['children']);660 write_nested_categories( $category['children'] ); 661 661 echo "</ul>\n"; 662 662 } … … 664 664 } 665 665 666 function dropdown_categories( $default = 0) {667 write_nested_categories( get_nested_categories($default));668 } 669 670 function return_link_categories_list( $parent = 0) {666 function dropdown_categories( $default = 0 ) { 667 write_nested_categories( get_nested_categories( $default) ); 668 } 669 670 function return_link_categories_list( $parent = 0 ) { 671 671 global $wpdb; 672 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC");672 return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC" ); 673 673 } 674 674 … … 676 676 global $post_ID, $link_id, $mode, $wpdb; 677 677 678 if ( $link_id) {679 $checked_categories = $wpdb->get_col( "678 if ( $link_id ) { 679 $checked_categories = $wpdb->get_col( " 680 680 SELECT category_id 681 681 FROM $wpdb->categories, $wpdb->link2cat 682 682 WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' 683 " );684 685 if ( count($checked_categories) == 0) {683 " ); 684 685 if ( count( $checked_categories ) == 0 ) { 686 686 // No selected categories, strange 687 687 $checked_categories[] = $default; … … 691 691 } 692 692 693 $cats = return_link_categories_list( $parent);693 $cats = return_link_categories_list( $parent); 694 694 $result = array (); 695 695 696 if ( is_array($cats)) {697 foreach ( $cats as $cat) {698 $result[$cat]['children'] = get_nested_link_categories( $default, $cat);696 if ( is_array( $cats ) ) { 697 foreach ( $cats as $cat) { 698 $result[$cat]['children'] = get_nested_link_categories( $default, $cat); 699 699 $result[$cat]['cat_ID'] = $cat; 700 $result[$cat]['checked'] = in_array( $cat, $checked_categories);701 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat);702 } 703 } 704 705 usort( $result, 'sort_cats');700 $result[$cat]['checked'] = in_array( $cat, $checked_categories ); 701 $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); 702 } 703 } 704 705 usort( $result, 'sort_cats' ); 706 706 707 707 return $result; 708 708 } 709 709 710 function dropdown_link_categories( $default = 0) {711 write_nested_categories( get_nested_link_categories($default));710 function dropdown_link_categories( $default = 0 ) { 711 write_nested_categories( get_nested_link_categories( $default) ); 712 712 } 713 713 714 714 // Dandy new recursive multiple category stuff. 715 function cat_rows( $parent = 0, $level = 0, $categories = 0) {715 function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { 716 716 global $wpdb, $class; 717 717 718 if (!$categories )719 $categories = get_categories( 'hide_empty=0');720 721 if ( $categories) {722 foreach ( $categories as $category) {718 if (!$categories ) 719 $categories = get_categories( 'hide_empty=0' ); 720 721 if ( $categories ) { 722 foreach ( $categories as $category ) { 723 723 if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 724 724 $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); 725 725 continue; 726 726 } 727 if ( $category->category_parent == $parent) {727 if ( $category->category_parent == $parent) { 728 728 echo "\t" . _cat_row( $category, $level ); 729 cat_rows( $category->cat_ID, $level +1, $categories);729 cat_rows( $category->cat_ID, $level +1, $categories ); 730 730 } 731 731 } … … 738 738 global $class; 739 739 740 $pad = str_repeat( '— ', $level);741 if ( current_user_can( 'manage_categories') ) {742 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__( 'Edit')."</a></td>";743 $default_cat_id = get_option( 'default_category');744 $default_link_cat_id = get_option( 'default_link_category');745 746 if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id) )747 $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>";740 $pad = str_repeat( '— ', $level ); 741 if ( current_user_can( 'manage_categories' ) ) { 742 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>"; 743 $default_cat_id = get_option( 'default_category' ); 744 $default_link_cat_id = get_option( 'default_link_category' ); 745 746 if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) ) 747 $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>"; 748 748 else 749 $edit .= "<td style='text-align:center'>".__( "Default");749 $edit .= "<td style='text-align:center'>".__( "Default" ); 750 750 } else 751 751 $edit = ''; 752 752 753 $class = ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'";753 $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; 754 754 755 755 $category->category_count = number_format( $category->category_count ); … … 764 764 } 765 765 766 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true) {766 function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { 767 767 global $wpdb, $class, $post; 768 768 769 if (!$pages )770 $pages = get_pages( 'sort_column=menu_order');771 772 if (! $pages )769 if (!$pages ) 770 $pages = get_pages( 'sort_column=menu_order' ); 771 772 if (! $pages ) 773 773 return false; 774 774 775 foreach ( $pages as $post) {776 setup_postdata( $post);775 foreach ( $pages as $post) { 776 setup_postdata( $post); 777 777 if ( $hierarchy && ($post->post_parent != $parent) ) 778 778 continue; 779 779 780 $post->post_title = wp_specialchars( $post->post_title);781 $pad = str_repeat( '— ', $level);780 $post->post_title = wp_specialchars( $post->post_title ); 781 $pad = str_repeat( '— ', $level ); 782 782 $id = $post->ID; 783 $class = ('alternate' == $class ) ? '' : 'alternate';783 $class = ('alternate' == $class ) ? '' : 'alternate'; 784 784 ?> 785 785 <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'> … … 787 787 <td> 788 788 <?php echo $pad; ?><?php the_title() ?> 789 <?php if ('private' == $post->post_status) _e(' - <strong>Private</strong>'); ?>790 789 </td> 791 790 <td><?php the_author() ?></td> 792 <td><?php echo mysql2date('Y-m-d g:i a', $post->post_modified); ?></td>793 <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View'); ?></a></td>794 <td><?php if ( current_user_can( 'edit_page', $id) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __('Edit') . "</a>"; } ?></td>795 <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>791 <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( 'Y-m-d g:i a', $post->post_modified ); ?></td> 792 <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td> 793 <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td> 794 <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> 796 795 </tr> 797 796 798 797 <?php 799 if ( $hierarchy ) page_rows($id, $level + 1, $pages);798 if ( $hierarchy ) page_rows( $id, $level + 1, $pages ); 800 799 } 801 800 } … … 804 803 global $current_user; 805 804 806 if ( !(is_object( $user_object) && is_a($user_object, 'WP_User')) )805 if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) 807 806 $user_object = new WP_User( (int) $user_object ); 808 807 $email = $user_object->user_email; 809 808 $url = $user_object->user_url; 810 $short_url = str_replace( 'http://', '', $url);811 $short_url = str_replace( 'www.', '', $short_url);812 if ('/' == substr( $short_url, -1))813 $short_url = substr( $short_url, 0, -1);814 if ( strlen($short_url) > 35)815 $short_url = substr( $short_url, 0, 32).'...';816 $numposts = get_usernumposts( $user_object->ID);809 $short_url = str_replace( 'http://', '', $url ); 810 $short_url = str_replace( 'www.', '', $short_url ); 811 if ('/' == substr( $short_url, -1 )) 812 $short_url = substr( $short_url, 0, -1 ); 813 if ( strlen( $short_url ) > 35 ) 814 $short_url = substr( $short_url, 0, 32 ).'...'; 815 $numposts = get_usernumposts( $user_object->ID ); 817 816 $r = "<tr id='user-$user_object->ID'$style> 818 817 <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> 819 818 <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 820 819 <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 821 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s'), $email) . "'>$email</a></td>820 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td> 822 821 <td><a href='$url' title='website: $url'>$short_url</a></td>"; 823 822 $r .= "\n\t\t<td align='center'>"; 824 if ( $numposts > 0) {825 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author') . "' class='edit'>";826 $r .= sprintf( __('View %1$s %2$s'), $numposts, __ngettext('post', 'posts', $numposts));823 if ( $numposts > 0 ) { 824 $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>"; 825 $r .= sprintf( __('View %1$s %2$s' ), $numposts, __ngettext( 'post', 'posts', $numposts )); 827 826 } 828 827 $r .= "</td>\n\t\t<td>"; 829 $edit_link = add_query_arg( 'wp_http_referer', wp_specialchars(urlencode(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id=$user_object->ID");828 $edit_link = add_query_arg( 'wp_http_referer', wp_specialchars( urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ); 830 829 if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can('edit_user', $user_object->ID) ) 831 $r .= "<a href='$edit_link' class='edit'>".__( 'Edit')."</a>";830 $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>"; 832 831 $r .= "</td>\n\t</tr>"; 833 832 return $r; 834 833 } 835 834 836 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {835 function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { 837 836 global $wpdb; 838 if (!$categories )839 $categories = get_categories( 'hide_empty=0');840 841 if ( $categories) {842 foreach ( $categories as $category) {843 if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) {844 $pad = str_repeat( '– ', $level);845 $category->cat_name = wp_specialchars( $category->cat_name);837 if (!$categories ) 838 $categories = get_categories( 'hide_empty=0' ); 839 840 if ( $categories ) { 841 foreach ( $categories as $category ) { 842 if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) { 843 $pad = str_repeat( '– ', $level ); 844 $category->cat_name = wp_specialchars( $category->cat_name ); 846 845 echo "\n\t<option value='$category->cat_ID'"; 847 if ( $currentparent == $category->cat_ID)846 if ( $currentparent == $category->cat_ID ) 848 847 echo " selected='selected'"; 849 848 echo ">$pad$category->cat_name</option>"; 850 wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories);849 wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories ); 851 850 } 852 851 } … … 856 855 } 857 856 858 function wp_create_thumbnail( $file, $max_side, $effect = '') {857 function wp_create_thumbnail( $file, $max_side, $effect = '' ) { 859 858 860 859 // 1 = GIF, 2 = JPEG, 3 = PNG 861 860 862 if ( file_exists($file)) {863 $type = getimagesize( $file);861 if ( file_exists( $file ) ) { 862 $type = getimagesize( $file ); 864 863 865 864 // if the associated function doesn't exist - then it's not 866 865 // handle. duh. i hope. 867 866 868 if (!function_exists( 'imagegif') && $type[2] == 1) {869 $error = __( 'Filetype not supported. Thumbnail not created.');870 } 871 elseif (!function_exists( 'imagejpeg') && $type[2] == 2) {872 $error = __( 'Filetype not supported. Thumbnail not created.');873 } 874 elseif (!function_exists( 'imagepng') && $type[2] == 3) {875 $error = __( 'Filetype not supported. Thumbnail not created.');867 if (!function_exists( 'imagegif' ) && $type[2] == 1 ) { 868 $error = __( 'Filetype not supported. Thumbnail not created.' ); 869 } 870 elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) { 871 $error = __( 'Filetype not supported. Thumbnail not created.' ); 872 } 873 elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) { 874 $error = __( 'Filetype not supported. Thumbnail not created.' ); 876 875 } else { 877 876 878 877 // create the initial copy from the original file 879 if ( $type[2] == 1) {880 $image = imagecreatefromgif( $file);878 if ( $type[2] == 1 ) { 879 $image = imagecreatefromgif( $file ); 881 880 } 882 elseif ( $type[2] == 2) {883 $image = imagecreatefromjpeg( $file);881 elseif ( $type[2] == 2 ) { 882 $image = imagecreatefromjpeg( $file ); 884 883 } 885 elseif ( $type[2] == 3) {886 $image = imagecreatefrompng( $file);884 elseif ( $type[2] == 3 ) { 885 $image = imagecreatefrompng( $file ); 887 886 } 888 887 889 if ( function_exists('imageantialias'))890 imageantialias( $image, TRUE);891 892 $image_attr = getimagesize( $file);888 if ( function_exists( 'imageantialias' )) 889 imageantialias( $image, TRUE ); 890 891 $image_attr = getimagesize( $file ); 893 892 894 893 // figure out the longest side 895 894 896 if ( $image_attr[0] > $image_attr[1]) {895 if ( $image_attr[0] > $image_attr[1] ) { 897 896 $image_width = $image_attr[0]; 898 897 $image_height = $image_attr[1]; … … 912 911 } 913 912 914 $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height);915 @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);913 $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); 914 @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] ); 916 915 917 916 // If no filters change the filename, we'll do a default transformation. 918 if ( basename( $file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )919 $thumb = preg_replace( '!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);920 921 $thumbpath = str_replace( basename($file), $thumb, $file);917 if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) ) 918 $thumb = preg_replace( '!(\.[^.]+)?$!', __( '.thumbnail' ).'$1', basename( $file ), 1 ); 919 920 $thumbpath = str_replace( basename( $file ), $thumb, $file ); 922 921 923 922 // move the thumbnail to it's final destination 924 if ( $type[2] == 1) {925 if (!imagegif( $thumbnail, $thumbpath)) {926 $error = __( "Thumbnail path invalid");923 if ( $type[2] == 1 ) { 924 if (!imagegif( $thumbnail, $thumbpath ) ) { 925 $error = __( "Thumbnail path invalid" ); 927 926 } 928 927 } 929 elseif ( $type[2] == 2) {930 if (!imagejpeg( $thumbnail, $thumbpath)) {931 $error = __( "Thumbnail path invalid");928 elseif ( $type[2] == 2 ) { 929 if (!imagejpeg( $thumbnail, $thumbpath ) ) { 930 $error = __( "Thumbnail path invalid" ); 932 931 } 933 932 } 934 elseif ( $type[2] == 3) {935 if (!imagepng( $thumbnail, $thumbpath)) {936 $error = __( "Thumbnail path invalid");933 elseif ( $type[2] == 3 ) { 934 if (!imagepng( $thumbnail, $thumbpath ) ) { 935 $error = __( "Thumbnail path invalid" ); 937 936 } 938 937 } … … 940 939 } 941 940 } else { 942 $error = __( 'File not found');943 } 944 945 if (!empty ( $error)) {941 $error = __( 'File not found' ); 942 } 943 944 if (!empty ( $error ) ) { 946 945 return $error; 947 946 } else { … … 952 951 953 952 // Some postmeta stuff 954 function has_meta( $postid) {953 function has_meta( $postid ) { 955 954 global $wpdb; 956 955 957 return $wpdb->get_results( "956 return $wpdb->get_results( " 958 957 SELECT meta_key, meta_value, meta_id, post_id 959 958 FROM $wpdb->postmeta 960 959 WHERE post_id = '$postid' 961 ORDER BY meta_key,meta_id", ARRAY_A );962 963 } 964 965 function list_meta( $meta) {960 ORDER BY meta_key,meta_id", ARRAY_A ); 961 962 } 963 964 function list_meta( $meta ) { 966 965 global $post_ID; 967 966 // Exit if no meta 968 if (!$meta ) {967 if (!$meta ) { 969 968 echo '<tbody id="the-list"><tr style="display: none;"><td> </td></tr></tbody>'; //TBODY needed for list-manipulation JS 970 969 return; … … 974 973 <thead> 975 974 <tr> 976 <th><?php _e( 'Key') ?></th>977 <th><?php _e( 'Value') ?></th>978 <th colspan='2'><?php _e( 'Action') ?></th>975 <th><?php _e( 'Key' ) ?></th> 976 <th><?php _e( 'Value' ) ?></th> 977 <th colspan='2'><?php _e( 'Action' ) ?></th> 979 978 </tr> 980 979 </thead> 981 980 <?php 982 981 $r ="\n\t<tbody id='the-list'>"; 983 foreach ( $meta as $entry) {982 foreach ( $meta as $entry ) { 984 983 ++ $count; 985 if ( $count % 2)984 if ( $count % 2 ) 986 985 $style = 'alternate'; 987 986 else 988 987 $style = ''; 989 if ('_' == $entry['meta_key'] { 0 } )988 if ('_' == $entry['meta_key'] { 0 } ) 990 989 $style .= ' hidden'; 991 990 992 if ( is_serialized( $entry['meta_value']) ) {993 if ( is_serialized_string( $entry['meta_value']) ) {991 if ( is_serialized( $entry['meta_value'] ) ) { 992 if ( is_serialized_string( $entry['meta_value'] ) ) { 994 993 // this is a serialized string, so we should display it 995 $entry['meta_value'] = maybe_unserialize( $entry['meta_value']);994 $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); 996 995 } else { 997 996 // this is a serialized array/object so we should NOT display it … … 1001 1000 } 1002 1001 1003 $key_js = js_escape( $entry['meta_key']);1002 $key_js = js_escape( $entry['meta_key'] ); 1004 1003 $entry['meta_key'] = wp_specialchars( $entry['meta_key'], true ); 1005 1004 $entry['meta_value'] = wp_specialchars( $entry['meta_value'], true ); … … 1007 1006 $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>"; 1008 1007 $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>"; 1009 $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__( 'Update')."' /><br />";1008 $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".__( 'Update' )."' /><br />"; 1010 1009 $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '"; 1011 $r .= sprintf( __("You are about to delete the "%s" custom field on this post.\\n"OK" to delete, "Cancel" to stop."), $key_js);1012 $r .= "' );\" class='deletemeta' tabindex='6' value='".__( 'Delete')."' /></td>";1010 $r .= sprintf( __("You are about to delete the "%s" custom field on this post.\\n"OK" to delete, "Cancel" to stop." ), $key_js ); 1011 $r .= "' );\" class='deletemeta' tabindex='6' value='".__( 'Delete' )."' /></td>"; 1013 1012 $r .= "\n\t</tr>"; 1014 1013 } … … 1021 1020 global $wpdb; 1022 1021 1023 $keys = $wpdb->get_col( "1022 $keys = $wpdb->get_col( " 1024 1023 SELECT meta_key 1025 1024 FROM $wpdb->postmeta 1026 1025 GROUP BY meta_key 1027 ORDER BY meta_key" );1026 ORDER BY meta_key" ); 1028 1027 1029 1028 return $keys; … … 1032 1031 function meta_form() { 1033 1032 global $wpdb; 1034 $limit = (int) apply_filters( 'postmeta_form_limit', 30);1035 $keys = $wpdb->get_col( "1033 $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); 1034 $keys = $wpdb->get_col( " 1036 1035 SELECT meta_key 1037 1036 FROM $wpdb->postmeta 1038 1037 GROUP BY meta_key 1039 1038 ORDER BY meta_id DESC 1040 LIMIT $limit" );1041 natcasesort( $keys);1039 LIMIT $limit" ); 1040 natcasesort( $keys ); 1042 1041 ?> 1043 <h3><?php _e( 'Add a new custom field:') ?></h3>1042 <h3><?php _e( 'Add a new custom field:' ) ?></h3> 1044 1043 <table id="newmeta" cellspacing="3" cellpadding="3"> 1045 1044 <tr> 1046 <th colspan="2"><?php _e( 'Key') ?></th>1047 <th><?php _e( 'Value') ?></th>1045 <th colspan="2"><?php _e( 'Key' ) ?></th> 1046 <th><?php _e( 'Value' ) ?></th> 1048 1047 </tr> 1049 1048 <tr valign="top"> … … 1051 1050 <?php if ( $keys ) : ?> 1052 1051 <select id="metakeyselect" name="metakeyselect" tabindex="7"> 1053 <option value="#NONE#"><?php _e( '- Select -'); ?></option>1052 <option value="#NONE#"><?php _e( '- Select -' ); ?></option> 1054 1053 <?php 1055 1054 1056 1055 foreach ( $keys as $key ) { 1057 $key = wp_specialchars( $key, 1);1056 $key = wp_specialchars( $key, 1 ); 1058 1057 echo "\n\t<option value='$key'>$key</option>"; 1059 1058 } 1060 1059 ?> 1061 </select> <?php _e( 'or'); ?>1060 </select> <?php _e( 'or' ); ?> 1062 1061 <?php endif; ?> 1063 1062 </td> … … 1067 1066 1068 1067 </table> 1069 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field »') ?>" /></p>1068 <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field »' ) ?>" /></p> 1070 1069 <?php 1071 1070 1072 1071 } 1073 1072 1074 function add_meta( $post_ID) {1073 function add_meta( $post_ID ) { 1075 1074 global $wpdb; 1076 1075 $post_ID = (int) $post_ID; 1077 1076 1078 $metakeyselect = $wpdb->escape( stripslashes(trim($_POST['metakeyselect'])));1079 $metakeyinput = $wpdb->escape( stripslashes(trim($_POST['metakeyinput'])));1080 $metavalue = maybe_serialize( stripslashes((trim($_POST['metavalue']))));1081 $metavalue = $wpdb->escape( $metavalue);1082 1083 if ( ('0' === $metavalue || !empty ( $metavalue)) && ((('#NONE#' != $metakeyselect) && !empty ($metakeyselect)) || !empty ($metakeyinput)) ) {1077 $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) ); 1078 $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) ); 1079 $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) )); 1080 $metavalue = $wpdb->escape( $metavalue ); 1081 1082 if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) { 1084 1083 // We have a key/value pair. If both the select and the 1085 1084 // input for the key have data, the input takes precedence: … … 1088 1087 $metakey = $metakeyselect; 1089 1088 1090 if ( $metakeyinput)1089 if ( $metakeyinput) 1091 1090 $metakey = $metakeyinput; // default 1092 1091 1093 $result = $wpdb->query( "1092 $result = $wpdb->query( " 1094 1093 INSERT INTO $wpdb->postmeta 1095 (post_id,meta_key,meta_value )1096 VALUES ('$post_ID','$metakey','$metavalue' )1097 " );1094 (post_id,meta_key,meta_value ) 1095 VALUES ('$post_ID','$metakey','$metavalue' ) 1096 " ); 1098 1097 return $wpdb->insert_id; 1099 1098 } … … 1101 1100 } // add_meta 1102 1101 1103 function delete_meta( $mid) {1102 function delete_meta( $mid ) { 1104 1103 global $wpdb; 1105 1104 $mid = (int) $mid; 1106 1105 1107 return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'");1108 } 1109 1110 function update_meta( $mid, $mkey, $mvalue) {1106 return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); 1107 } 1108 1109 function update_meta( $mid, $mkey, $mvalue ) { 1111 1110 global $wpdb; 1112 $mvalue = maybe_serialize( stripslashes($mvalue));1113 $mvalue = $wpdb->escape( $mvalue);1111 $mvalue = maybe_serialize( stripslashes( $mvalue )); 1112 $mvalue = $wpdb->escape( $mvalue ); 1114 1113 $mid = (int) $mid; 1115 return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'");1116 } 1117 1118 function get_post_meta_by_id( $mid) {1114 return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" ); 1115 } 1116 1117 function get_post_meta_by_id( $mid ) { 1119 1118 global $wpdb; 1120 1119 $mid = (int) $mid; 1121 1120 1122 $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'");1123 if ( is_serialized_string( $meta->meta_value) )1124 $meta->meta_value = maybe_unserialize( $meta->meta_value);1121 $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); 1122 if ( is_serialized_string( $meta->meta_value ) ) 1123 $meta->meta_value = maybe_unserialize( $meta->meta_value ); 1125 1124 return $meta; 1126 1125 } 1127 1126 1128 function touch_time( $edit = 1, $for_post = 1) {1127 function touch_time( $edit = 1, $for_post = 1 ) { 1129 1128 global $wp_locale, $post, $comment; 1130 1129 1131 1130 if ( $for_post ) 1132 $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date) ) ? false : true;1131 $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true; 1133 1132 1134 echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp').'</label></legend>';1135 1136 $time_adj = time() + (get_option( 'gmt_offset') * 3600);1133 echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>'; 1134 1135 $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 ); 1137 1136 $post_date = ($for_post) ? $post->post_date : $comment->comment_date; 1138 $jj = ($edit) ? mysql2date( 'd', $post_date) : gmdate('d', $time_adj);1139 $mm = ($edit) ? mysql2date( 'm', $post_date) : gmdate('m', $time_adj);1140 $aa = ($edit) ? mysql2date( 'Y', $post_date) : gmdate('Y', $time_adj);1141 $hh = ($edit) ? mysql2date( 'H', $post_date) : gmdate('H', $time_adj);1142 $mn = ($edit) ? mysql2date( 'i', $post_date) : gmdate('i', $time_adj);1143 $ss = ($edit) ? mysql2date( 's', $post_date) : gmdate('s', $time_adj);1137 $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj ); 1138 $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj ); 1139 $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj ); 1140 $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj ); 1141 $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); 1142 $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); 1144 1143 1145 1144 echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n"; 1146 for ( $i = 1; $i < 13; $i = $i +1) {1145 for ( $i = 1; $i < 13; $i = $i +1 ) { 1147 1146 echo "\t\t\t<option value=\"$i\""; 1148 if ( $i == $mm)1147 if ( $i == $mm ) 1149 1148 echo ' selected="selected"'; 1150 echo '>' . $wp_locale->get_month( $i) . "</option>\n";1149 echo '>' . $wp_locale->get_month( $i ) . "</option>\n"; 1151 1150 } 1152 1151 ?> 1153 1152 </select> 1154 1153 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/> 1155 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @ 1156 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> : 1157 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 1158 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 1154 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @ 1155 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> : 1156 <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 1157 <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> 1159 1158 <?php 1160 1159 if ( $edit ) { 1161 _e( 'Existing timestamp');1162 //echo ': ' . $wp_locale->get_month( $mm) . "$jj, $aa @ $hh:$mn";1163 echo sprintf( __(': %1$s %2$s, %3$s @ %4$s:%5$s'), $wp_locale->get_month($mm), $jj, $aa, $hh, $mn);1160 _e( 'Existing timestamp' ); 1161 //echo ': ' . $wp_locale->get_month( $mm ) . "$jj, $aa @ $hh:$mn"; 1162 echo sprintf( __(': %1$s %2$s, %3$s @ %4$s:%5$s' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn ); 1164 1163 } 1165 1164 ?> … … 1170 1169 1171 1170 // insert_with_markers: Owen Winkler, fixed by Eric Anderson 1172 // Inserts an array of strings into a file (.htaccess ), placing it between1171 // Inserts an array of strings into a file (.htaccess ), placing it between 1173 1172 // BEGIN and END markers. Replaces existing marked info. Retains surrounding 1174 1173 // data. Creates file if none exists. 1175 1174 // Returns true on write success, false on failure. 1176 function insert_with_markers( $filename, $marker, $insertion) {1175 function insert_with_markers( $filename, $marker, $insertion ) { 1177 1176 return true; 1178 if (!file_exists( $filename) || is_writeable($filename)) {1179 if (!file_exists( $filename)) {1177 if (!file_exists( $filename ) || is_writeable( $filename ) ) { 1178 if (!file_exists( $filename ) ) { 1180 1179 $markerdata = ''; 1181 1180 } else { 1182 $markerdata = explode( "\n", implode('', file($filename)));1183 } 1184 1185 $f = fopen( $filename, 'w');1181 $markerdata = explode( "\n", implode( '', file( $filename ) ) ); 1182 } 1183 1184 $f = fopen( $filename, 'w' ); 1186 1185 $foundit = false; 1187 if ( $markerdata) {1186 if ( $markerdata ) { 1188 1187 $state = true; 1189 foreach ( $markerdata as $n => $markerline) {1190 if ( strstr($markerline, "# BEGIN {$marker}"))1188 foreach ( $markerdata as $n => $markerline ) { 1189 if ( strstr( $markerline, "# BEGIN {$marker}" )) 1191 1190 $state = false; 1192 if ( $state) {1193 if ( $n + 1 < count( $markerdata) )1194 fwrite( $f, "{$markerline}\n");1191 if ( $state ) { 1192 if ( $n + 1 < count( $markerdata ) ) 1193 fwrite( $f, "{$markerline}\n" ); 1195 1194 else 1196 fwrite( $f, "{$markerline}");1195 fwrite( $f, "{$markerline}" ); 1197 1196 } 1198 if ( strstr($markerline, "# END {$marker}")) {1199 fwrite( $f, "# BEGIN {$marker}\n");1200 if ( is_array($insertion))1201 foreach ( $insertion as $insertline)1202 fwrite( $f, "{$insertline}\n");1203 fwrite( $f, "# END {$marker}\n");1197 if ( strstr( $markerline, "# END {$marker}" ) ) { 1198 fwrite( $f, "# BEGIN {$marker}\n" ); 1199 if ( is_array( $insertion )) 1200 foreach ( $insertion as $insertline ) 1201 fwrite( $f, "{$insertline}\n" ); 1202 fwrite( $f, "# END {$marker}\n" ); 1204 1203 $state = true; 1205 1204 $foundit = true; … … 1208 1207 } 1209 1208 if (!$foundit) { 1210 fwrite( $f, "# BEGIN {$marker}\n");1211 foreach ( $insertion as $insertline)1212 fwrite( $f, "{$insertline}\n");1213 fwrite( $f, "# END {$marker}\n");1214 } 1215 fclose( $f);1209 fwrite( $f, "# BEGIN {$marker}\n" ); 1210 foreach ( $insertion as $insertline ) 1211 fwrite( $f, "{$insertline}\n" ); 1212 fwrite( $f, "# END {$marker}\n" ); 1213 } 1214 fclose( $f ); 1216 1215 return true; 1217 1216 } else { … … 1221 1220 1222 1221 // extract_from_markers: Owen Winkler 1223 // Returns an array of strings from a file (.htaccess ) from between BEGIN1222 // Returns an array of strings from a file (.htaccess ) from between BEGIN 1224 1223 // and END markers. 1225 function extract_from_markers( $filename, $marker) {1224 function extract_from_markers( $filename, $marker ) { 1226 1225 $result = array (); 1227 1226 1228 if (!file_exists( $filename)) {1227 if (!file_exists( $filename ) ) { 1229 1228 return $result; 1230 1229 } 1231 1230 1232 if ( $markerdata = explode("\n", implode('', file($filename))));1231 if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); 1233 1232 { 1234 1233 $state = false; 1235 foreach ( $markerdata as $markerline) {1236 if ( strstr($markerline, "# END {$marker}"))1234 foreach ( $markerdata as $markerline ) { 1235 if ( strstr( $markerline, "# END {$marker}" )) 1237 1236 $state = false; 1238 if ( $state)1237 if ( $state ) 1239 1238 $result[] = $markerline; 1240 if ( strstr($markerline, "# BEGIN {$marker}"))1239 if ( strstr( $markerline, "# BEGIN {$marker}" )) 1241 1240 $state = true; 1242 1241 } … … 1253 1252 return false; 1254 1253 1255 if ( function_exists( 'apache_get_modules') ) {1256 if ( !in_array( 'mod_rewrite', apache_get_modules()) )1254 if ( function_exists( 'apache_get_modules' ) ) { 1255 if ( !in_array( 'mod_rewrite', apache_get_modules() ) ) 1257 1256 return false; 1258 1257 } … … 1265 1264 $home_path = get_home_path(); 1266 1265 1267 if (!$wp_rewrite->using_mod_rewrite_permalinks() )1266 if (!$wp_rewrite->using_mod_rewrite_permalinks() ) 1268 1267 return; 1269 1268 1270 if (!((!file_exists( $home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess')))1269 if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) ) 1271 1270 return; 1272 1271 1273 if (! got_mod_rewrite() )1272 if (! got_mod_rewrite() ) 1274 1273 return; 1275 1274 1276 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules());1277 insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules);1275 $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); 1276 insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); 1278 1277 } 1279 1278 … … 1291 1290 $page_templates = array (); 1292 1291 1293 if ( is_array($templates)) {1294 foreach ( $templates as $template) {1295 $template_data = implode( '', file(ABSPATH.$template));1296 preg_match( "|Template Name:(.*)|i", $template_data, $name);1297 preg_match( "|Description:(.*)|i", $template_data, $description);1292 if ( is_array( $templates ) ) { 1293 foreach ( $templates as $template ) { 1294 $template_data = implode( '', file( ABSPATH.$template )); 1295 preg_match( "|Template Name:(.* )|i", $template_data, $name ); 1296 preg_match( "|Description:(.* )|i", $template_data, $description ); 1298 1297 1299 1298 $name = $name[1]; 1300 1299 $description = $description[1]; 1301 1300 1302 if (!empty ( $name)) {1303 $page_templates[trim( $name)] = basename($template);1301 if (!empty ( $name ) ) { 1302 $page_templates[trim( $name )] = basename( $template ); 1304 1303 } 1305 1304 } … … 1309 1308 } 1310 1309 1311 function page_template_dropdown( $default = '') {1310 function page_template_dropdown( $default = '' ) { 1312 1311 $templates = get_page_templates(); 1313 foreach (array_keys( $templates) as $template)1314 : if ( $default == $templates[$template])1312 foreach (array_keys( $templates ) as $template ) 1313 : if ( $default == $templates[$template] ) 1315 1314 $selected = " selected='selected'"; 1316 1315 else … … 1320 1319 } 1321 1320 1322 function parent_dropdown( $default = 0, $parent = 0, $level = 0) {1321 function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { 1323 1322 global $wpdb, $post_ID; 1324 $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");1325 1326 if ( $items) {1327 foreach ( $items as $item) {1323 $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" ); 1324 1325 if ( $items ) { 1326 foreach ( $items as $item ) { 1328 1327 // A page cannot be it's own parent. 1329 if (!empty ( $post_ID)) {1330 if ( $item->ID == $post_ID) {1328 if (!empty ( $post_ID ) ) { 1329 if ( $item->ID == $post_ID ) { 1331 1330 continue; 1332 1331 } 1333 1332 } 1334 $pad = str_repeat( ' ', $level * 3);1335 if ( $item->ID == $default)1333 $pad = str_repeat( ' ', $level * 3 ); 1334 if ( $item->ID == $default) 1336 1335 $current = ' selected="selected"'; 1337 1336 else … … 1339 1338 1340 1339 echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>"; 1341 parent_dropdown( $default, $item->ID, $level +1);1340 parent_dropdown( $default, $item->ID, $level +1 ); 1342 1341 } 1343 1342 } else { … … 1355 1354 1356 1355 $parent = get_admin_page_parent(); 1357 /*echo "pa: $parent pn: $pagenow pp: $plugin_page<br/>"; 1358 echo "<pre>"; 1359 print_r($_wp_menu_nopriv); 1360 print_r($_wp_submenu_nopriv); 1361 echo "</pre>";*/ 1362 if ( isset($_wp_submenu_nopriv[$parent][$pagenow]) ) 1356 1357 if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) 1363 1358 return false; 1364 1359 1365 if ( isset( $plugin_page) && isset($_wp_submenu_nopriv[$parent][$plugin_page]) )1360 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) 1366 1361 return false; 1367 1362 1368 if ( empty( $parent) ) {1369 if ( isset( $_wp_menu_nopriv[$pagenow]) )1363 if ( empty( $parent) ) { 1364 if ( isset( $_wp_menu_nopriv[$pagenow] ) ) 1370 1365 return false; 1371 if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow]) )1366 if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) 1372 1367 return false; 1373 if ( isset( $plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) )1368 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) 1374 1369 return false; 1375 foreach (array_keys( $_wp_submenu_nopriv) as $key) {1376 if ( isset( $_wp_submenu_nopriv[$key][$pagenow]) )1370 foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { 1371 if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) 1377 1372 return false; 1378 if ( isset( $plugin_page) && isset($_wp_submenu_nopriv[$key][$plugin_page]) )1373 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) 1379 1374 return false; 1380 1375 } … … 1382 1377 } 1383 1378 1384 if (isset ($submenu[$parent])) { 1385 foreach ($submenu[$parent] as $submenu_array) { 1386 if ($submenu_array[2] == $pagenow) { 1387 if (current_user_can($submenu_array[1])) 1379 if ( isset( $submenu[$parent] ) ) { 1380 foreach ( $submenu[$parent] as $submenu_array ) { 1381 if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { 1382 if ( current_user_can( $submenu_array[1] )) 1383 return true; 1384 else 1385 return false; 1386 } else if ( $submenu_array[2] == $pagenow ) { 1387 if ( current_user_can( $submenu_array[1] )) 1388 1388 return true; 1389 1389 else … … 1393 1393 } 1394 1394 1395 foreach ( $menu as $menu_array) {1396 if ( $menu_array[2] == $parent) {1397 if ( current_user_can($menu_array[1]))1395 foreach ( $menu as $menu_array ) { 1396 if ( $menu_array[2] == $parent) { 1397 if ( current_user_can( $menu_array[1] )) 1398 1398 return true; 1399 1399 else … … 1401 1401 } 1402 1402 } 1403 1403 1404 1404 return true; 1405 1405 } … … 1412 1412 global $plugin_page; 1413 1413 1414 if ( isset ($title) && !empty ($title)) {1414 if ( isset( $title ) && !empty ( $title ) ) { 1415 1415 return $title; 1416 1416 } 1417 1417 1418 $hook = get_plugin_page_hook( $plugin_page, $pagenow);1418 $hook = get_plugin_page_hook( $plugin_page, $pagenow ); 1419 1419 1420 1420 $parent = $parent1 = get_admin_page_parent(); 1421 if ( empty ($parent)) {1422 foreach ( $menu as $menu_array) {1423 if ( isset ($menu_array[3])) {1424 if ( $menu_array[2] == $pagenow) {1421 if ( empty ( $parent) ) { 1422 foreach ( $menu as $menu_array ) { 1423 if ( isset( $menu_array[3] ) ) { 1424 if ( $menu_array[2] == $pagenow ) { 1425 1425 $title = $menu_array[3]; 1426 1426 return $menu_array[3]; 1427 1427 } else 1428 if ( isset ($plugin_page) && ($plugin_page == $menu_array[2]) && ($hook == $menu_array[3])) {1428 if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { 1429 1429 $title = $menu_array[3]; 1430 1430 return $menu_array[3]; 1431 1431 } 1432 } else { 1433 $title = $menu_array[0]; 1434 return $title; 1432 1435 } 1433 1436 } 1434 1437 } else { 1435 foreach (array_keys($submenu) as $parent) { 1436 foreach ($submenu[$parent] as $submenu_array) { 1437 if (isset ($submenu_array[3])) { 1438 if ($submenu_array[2] == $pagenow) { 1438 foreach (array_keys( $submenu ) as $parent) { 1439 foreach ( $submenu[$parent] as $submenu_array ) { 1440 if ( isset( $plugin_page ) && 1441 ($plugin_page == $submenu_array[2] ) && 1442 (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) ) 1443 ) { 1439 1444 $title = $submenu_array[3]; 1440 1445 return $submenu_array[3]; 1441 } else 1442 if (isset ($plugin_page) && ($plugin_page == $submenu_array[2]) && (($parent == $pagenow) || ($parent == $plugin_page) || ($plugin_page == $hook) || (($pagenow == 'admin.php') && ($parent1 != $submenu_array[2])))) { 1443 $title = $submenu_array[3]; 1444 return $submenu_array[3]; 1445 } 1446 } 1447 1448 if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page 1449 continue; 1450 1451 if ( isset( $submenu_array[3] ) ) { 1452 $title = $submenu_array[3]; 1453 return $submenu_array[3]; 1454 } else { 1455 $title = $submenu_array[0]; 1456 return $title; 1446 1457 } 1447 1458 } … … 1449 1460 } 1450 1461 1451 return '';1462 return $title; 1452 1463 } 1453 1464 … … 1462 1473 global $_wp_submenu_nopriv; 1463 1474 1464 if ( !empty ( $parent_file) ) {1465 if ( isset( $_wp_real_parent_file[$parent_file]) )1475 if ( !empty ( $parent_file ) ) { 1476 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1466 1477 $parent_file = $_wp_real_parent_file[$parent_file]; 1467 1478 … … 1469 1480 } 1470 1481 1471 if ( $pagenow == 'admin.php' && isset ($plugin_page)) {1472 foreach ( $menu as $parent_menu) {1473 if ( $parent_menu[2] == $plugin_page) {1482 if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { 1483 foreach ( $menu as $parent_menu ) { 1484 if ( $parent_menu[2] == $plugin_page ) { 1474 1485 $parent_file = $plugin_page; 1475 if ( isset( $_wp_real_parent_file[$parent_file]) )1486 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1476 1487 $parent_file = $_wp_real_parent_file[$parent_file]; 1477 1488 return $parent_file; 1478 1489 } 1479 1490 } 1480 if ( isset( $_wp_menu_nopriv[$plugin_page]) ) {1491 if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { 1481 1492 $parent_file = $plugin_page; 1482 if ( isset( $_wp_real_parent_file[$parent_file]) )1493 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1483 1494 $parent_file = $_wp_real_parent_file[$parent_file]; 1484 1495 return $parent_file; … … 1486 1497 } 1487 1498 1488 if ( isset( $plugin_page) && isset($_wp_submenu_nopriv[$pagenow][$plugin_page]) ) {1499 if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { 1489 1500 $parent_file = $pagenow; 1490 if ( isset( $_wp_real_parent_file[$parent_file]) )1501 if ( isset( $_wp_real_parent_file[$parent_file] ) ) 1491 1502 $parent_file = $_wp_real_parent_file[$parent_file]; 1492 1503 return $parent_file; 1493 1504 } 1494 1505 1495 foreach (array_keys( $submenu) as $parent) {1496 foreach ( $submenu[$parent] as $submenu_array) {1497 if ( isset( $_wp_real_parent_file[$parent]) )1506 foreach (array_keys( $submenu ) as $parent) { 1507 foreach ( $submenu[$parent] as $submenu_array ) { 1508 if ( isset( $_wp_real_parent_file[$parent] ) ) 1498 1509 $parent = $_wp_real_parent_file[$parent]; 1499 if ( $submenu_array[2] == $pagenow) {1510 if ( $submenu_array[2] == $pagenow ) { 1500 1511 $parent_file = $parent; 1501 1512 return $parent; 1502 1513 } else 1503 if ( isset ($plugin_page) && ($plugin_page == $submenu_array[2])) {1514 if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { 1504 1515 $parent_file = $parent; 1505 1516 return $parent; … … 1512 1523 } 1513 1524 1514 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '') {1525 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 1515 1526 global $menu, $admin_page_hooks; 1516 1527 1517 $file = plugin_basename( $file);1518 1519 $menu[] = array ( $menu_title, $access_level, $file, $page_title);1520 1521 $admin_page_hooks[$file] = sanitize_title( $menu_title);1522 1523 $hookname = get_plugin_page_hookname( $file, '');1524 if (!empty ( $function) && !empty ($hookname))1525 add_action( $hookname, $function);1528 $file = plugin_basename( $file ); 1529 1530 $menu[] = array ( $menu_title, $access_level, $file, $page_title ); 1531 1532 $admin_page_hooks[$file] = sanitize_title( $menu_title ); 1533 1534 $hookname = get_plugin_page_hookname( $file, '' ); 1535 if (!empty ( $function ) && !empty ( $hookname )) 1536 add_action( $hookname, $function ); 1526 1537 1527 1538 return $hookname; 1528 1539 } 1529 1540 1530 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '') {1541 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { 1531 1542 global $submenu; 1532 1543 global $menu; … … 1535 1546 global $_wp_menu_nopriv; 1536 1547 1537 $file = plugin_basename( $file);1538 1539 $parent = plugin_basename( $parent);1540 if ( isset( $_wp_real_parent_file[$parent]) )1548 $file = plugin_basename( $file ); 1549 1550 $parent = plugin_basename( $parent); 1551 if ( isset( $_wp_real_parent_file[$parent] ) ) 1541 1552 $parent = $_wp_real_parent_file[$parent]; 1542 1553 1543 if ( !current_user_can( $access_level) ) {1554 if ( !current_user_can( $access_level ) ) { 1544 1555 $_wp_submenu_nopriv[$parent][$file] = true; 1545 1556 return false; … … 1550 1561 // parent file someone is trying to link back to the parent manually. In 1551 1562 // this case, don't automatically add a link back to avoid duplication. 1552 if (!isset ($submenu[$parent]) && $file != $parent ) {1553 foreach ( $menu as $parent_menu) {1554 if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1]) ) {1563 if (!isset( $submenu[$parent] ) && $file != $parent ) { 1564 foreach ( $menu as $parent_menu ) { 1565 if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) 1555 1566 $submenu[$parent][] = $parent_menu; 1556 } 1557 } 1558 } 1559 1560 $submenu[$parent][] = array ($menu_title, $access_level, $file, $page_title); 1561 1562 $hookname = get_plugin_page_hookname($file, $parent); 1563 if (!empty ($function) && !empty ($hookname)) 1564 add_action($hookname, $function); 1567 } 1568 } 1569 1570 $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title ); 1571 1572 $hookname = get_plugin_page_hookname( $file, $parent); 1573 if (!empty ( $function ) && !empty ( $hookname )) 1574 add_action( $hookname, $function ); 1565 1575 1566 1576 return $hookname; 1567 1577 } 1568 1578 1569 function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '') {1570 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function);1571 } 1572 1573 function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '') {1574 return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function);1575 } 1576 1577 function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '') {1578 return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function);1579 } 1580 1581 function validate_file( $file, $allowed_files = '') {1582 if ( false !== strpos($file, './'))1579 function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 1580 return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); 1581 } 1582 1583 function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 1584 return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); 1585 } 1586 1587 function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { 1588 return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); 1589 } 1590 1591 function validate_file( $file, $allowed_files = '' ) { 1592 if ( false !== strpos( $file, './' )) 1583 1593 return 1; 1584 1594 1585 if (':' == substr( $file, 1, 1))1595 if (':' == substr( $file, 1, 1 )) 1586 1596 return 2; 1587 1597 1588 if (!empty ( $allowed_files) && (!in_array($file, $allowed_files)))1598 if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) 1589 1599 return 3; 1590 1600 … … 1592 1602 } 1593 1603 1594 function validate_file_to_edit( $file, $allowed_files = '') {1595 $file = stripslashes( $file);1596 1597 $code = validate_file( $file, $allowed_files);1598 1599 if (!$code )1604 function validate_file_to_edit( $file, $allowed_files = '' ) { 1605 $file = stripslashes( $file ); 1606 1607 $code = validate_file( $file, $allowed_files ); 1608 1609 if (!$code ) 1600 1610 return $file; 1601 1611 1602 switch ( $code) {1612 switch ( $code ) { 1603 1613 case 1 : 1604 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.'));1614 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.' )); 1605 1615 1606 1616 case 2 : 1607 wp_die( __('Sorry, can’t call files with their real path.'));1617 wp_die( __('Sorry, can’t call files with their real path.' )); 1608 1618 1609 1619 case 3 : 1610 wp_die( __('Sorry, that file cannot be edited.'));1620 wp_die( __('Sorry, that file cannot be edited.' )); 1611 1621 } 1612 1622 } 1613 1623 1614 1624 function get_home_path() { 1615 $home = get_option( 'home');1616 if ( $home != '' && $home != get_option('siteurl')) {1617 $home_path = parse_url( $home);1625 $home = get_option( 'home' ); 1626 if ( $home != '' && $home != get_option( 'siteurl' ) ) { 1627 $home_path = parse_url( $home ); 1618 1628 $home_path = $home_path['path']; 1619 $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"]);1620 $home_path = trailingslashit( $root.$home_path);1629 $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); 1630 $home_path = trailingslashit( $root.$home_path ); 1621 1631 } else { 1622 1632 $home_path = ABSPATH; … … 1626 1636 } 1627 1637 1628 function get_real_file_to_edit( $file) {1629 if ('index.php' == $file || '.htaccess' == $file ) {1638 function get_real_file_to_edit( $file ) { 1639 if ('index.php' == $file || '.htaccess' == $file ) { 1630 1640 $real_file = get_home_path().$file; 1631 1641 } else { … … 1636 1646 } 1637 1647 1638 $wp_file_descriptions = array ('index.php' => __( 'Main Index Template'), 'style.css' => __('Stylesheet'), 'comments.php' => __('Comments'), 'comments-popup.php' => __('Popup Comments'), 'footer.php' => __('Footer'), 'header.php' => __('Header'), 'sidebar.php' => __('Sidebar'), 'archive.php' => __('Archives'), 'category.php' => __('Category Template'), 'page.php' => __('Page Template'), 'search.php' => __('Search Results'), 'single.php' => __('Single Post'), '404.php' => __('404 Template'), 'my-hacks.php' => __('my-hacks.php (legacy hacks support)'), '.htaccess' => __('.htaccess (for rewrite rules)'),1648 $wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ), 1639 1649 // Deprecated files 1640 'wp-layout.css' => __( 'Stylesheet'), 'wp-comments.php' => __('Comments Template'), 'wp-comments-popup.php' => __('Popup Comments Template'));1641 1642 function get_file_description( $file) {1650 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' )); 1651 1652 function get_file_description( $file ) { 1643 1653 global $wp_file_descriptions; 1644 1654 1645 if ( isset ($wp_file_descriptions[basename($file)])) {1646 return $wp_file_descriptions[basename( $file)];1655 if ( isset( $wp_file_descriptions[basename( $file )] ) ) { 1656 return $wp_file_descriptions[basename( $file )]; 1647 1657 } 1648 1658 elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) { 1649 $template_data = implode( '', file( ABSPATH . $file ));1650 if ( preg_match("|Template Name:(.*)|i", $template_data, $name))1659 $template_data = implode( '', file( ABSPATH . $file ) ); 1660 if ( preg_match( "|Template Name:(.* )|i", $template_data, $name )) 1651 1661 return $name[1]; 1652 1662 } 1653 1663 1654 return basename( $file);1655 } 1656 1657 function update_recently_edited( $file) {1658 $oldfiles = (array ) get_option('recently_edited');1659 if ( $oldfiles) {1660 $oldfiles = array_reverse( $oldfiles);1664 return basename( $file ); 1665 } 1666 1667 function update_recently_edited( $file ) { 1668 $oldfiles = (array ) get_option( 'recently_edited' ); 1669 if ( $oldfiles ) { 1670 $oldfiles = array_reverse( $oldfiles ); 1661 1671 $oldfiles[] = $file; 1662 $oldfiles = array_reverse( $oldfiles);1663 $oldfiles = array_unique( $oldfiles);1664 if ( 5 < count($oldfiles))1665 array_pop( $oldfiles);1672 $oldfiles = array_reverse( $oldfiles ); 1673 $oldfiles = array_unique( $oldfiles ); 1674 if ( 5 < count( $oldfiles )) 1675 array_pop( $oldfiles ); 1666 1676 } else { 1667 1677 $oldfiles[] = $file; 1668 1678 } 1669 update_option( 'recently_edited', $oldfiles);1670 } 1671 1672 function get_plugin_data( $plugin_file) {1673 $plugin_data = implode( '', file($plugin_file));1674 preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name);1675 preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);1676 preg_match( "|Description:(.*)|i", $plugin_data, $description);1677 preg_match( "|Author:(.*)|i", $plugin_data, $author_name);1678 preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri);1679 if ( preg_match("|Version:(.*)|i", $plugin_data, $version))1680 $version = trim( $version[1]);1679 update_option( 'recently_edited', $oldfiles ); 1680 } 1681 1682 function get_plugin_data( $plugin_file ) { 1683 $plugin_data = implode( '', file( $plugin_file )); 1684 preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name ); 1685 preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri ); 1686 preg_match( "|Description:(.*)|i", $plugin_data, $description ); 1687 preg_match( "|Author:(.*)|i", $plugin_data, $author_name ); 1688 preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri ); 1689 if ( preg_match( "|Version:(.*)|i", $plugin_data, $version )) 1690 $version = trim( $version[1] ); 1681 1691 else 1682 1692 $version = ''; 1683 1693 1684 $description = wptexturize( trim($description[1]));1694 $description = wptexturize( trim( $description[1] )); 1685 1695 1686 1696 $name = $plugin_name[1]; 1687 $name = trim( $name);1697 $name = trim( $name ); 1688 1698 $plugin = $name; 1689 if ('' != $plugin_uri[1] && '' != $name ) {1690 $plugin = '<a href="' . trim( $plugin_uri[1]) . '" title="'.__('Visit plugin homepage').'">'.$plugin.'</a>';1691 } 1692 1693 if ('' == $author_uri[1] ) {1694 $author = trim( $author_name[1]);1695 } else { 1696 $author = '<a href="' . trim( $author_uri[1]) . '" title="'.__('Visit author homepage').'">' . trim($author_name[1]) . '</a>';1697 } 1698 1699 return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1] );1699 if ('' != $plugin_uri[1] && '' != $name ) { 1700 $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>'; 1701 } 1702 1703 if ('' == $author_uri[1] ) { 1704 $author = trim( $author_name[1] ); 1705 } else { 1706 $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>'; 1707 } 1708 1709 return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1] ); 1700 1710 } 1701 1711 … … 1703 1713 global $wp_plugins; 1704 1714 1705 if ( isset ($wp_plugins)) {1715 if ( isset( $wp_plugins ) ) { 1706 1716 return $wp_plugins; 1707 1717 } … … 1711 1721 1712 1722 // Files in wp-content/plugins directory 1713 $plugins_dir = @ dir( $plugin_root);1714 if ( $plugins_dir) {1715 while (($file = $plugins_dir->read() ) !== false) {1716 if ( preg_match('|^\.+$|', $file))1723 $plugins_dir = @ dir( $plugin_root); 1724 if ( $plugins_dir ) { 1725 while (($file = $plugins_dir->read() ) !== false ) { 1726 if ( preg_match( '|^\.+$|', $file )) 1717 1727 continue; 1718 if ( is_dir($plugin_root.'/'.$file)) {1719 $plugins_subdir = @ dir( $plugin_root.'/'.$file);1720 if ( $plugins_subdir) {1721 while (($subfile = $plugins_subdir->read() ) !== false) {1722 if ( preg_match('|^\.+$|', $subfile))1728 if ( is_dir( $plugin_root.'/'.$file ) ) { 1729 $plugins_subdir = @ dir( $plugin_root.'/'.$file ); 1730 if ( $plugins_subdir ) { 1731 while (($subfile = $plugins_subdir->read() ) !== false ) { 1732 if ( preg_match( '|^\.+$|', $subfile )) 1723 1733 continue; 1724 if ( preg_match('|\.php$|', $subfile))1734 if ( preg_match( '|\.php$|', $subfile )) 1725 1735 $plugin_files[] = "$file/$subfile"; 1726 1736 } 1727 1737 } 1728 1738 } else { 1729 if ( preg_match('|\.php$|', $file))1739 if ( preg_match( '|\.php$|', $file )) 1730 1740 $plugin_files[] = $file; 1731 1741 } … … 1737 1747 1738 1748 foreach ( $plugin_files as $plugin_file ) { 1739 if ( !is_readable( "$plugin_root/$plugin_file") )1749 if ( !is_readable( "$plugin_root/$plugin_file" ) ) 1740 1750 continue; 1741 1751 1742 $plugin_data = get_plugin_data( "$plugin_root/$plugin_file");1743 1744 if ( empty ( $plugin_data['Name']) )1752 $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" ); 1753 1754 if ( empty ( $plugin_data['Name'] ) ) 1745 1755 continue; 1746 1756 1747 $wp_plugins[plugin_basename( $plugin_file)] = $plugin_data;1748 } 1749 1750 uasort( $wp_plugins, create_function('$a, $b', 'return strnatcasecmp($a["Name"], $b["Name"]);'));1757 $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; 1758 } 1759 1760 uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); 1751 1761 1752 1762 return $wp_plugins; 1753 1763 } 1754 1764 1755 function get_plugin_page_hookname( $plugin_page, $parent_page) {1765 function get_plugin_page_hookname( $plugin_page, $parent_page ) { 1756 1766 global $admin_page_hooks; 1757 1767 1758 1768 $parent = get_admin_page_parent(); 1759 1769 1760 if ( empty ($parent_page) || 'admin.php' == $parent_page) {1761 if ( isset ($admin_page_hooks[$plugin_page]))1770 if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) { 1771 if ( isset( $admin_page_hooks[$plugin_page] )) 1762 1772 $page_type = 'toplevel'; 1763 1773 else 1764 if ( isset ($admin_page_hooks[$parent]))1774 if ( isset( $admin_page_hooks[$parent] )) 1765 1775 $page_type = $admin_page_hooks[$parent]; 1766 1776 } else 1767 if ( isset ($admin_page_hooks[$parent_page])) {1777 if ( isset( $admin_page_hooks[$parent_page] ) ) { 1768 1778 $page_type = $admin_page_hooks[$parent_page]; 1769 1779 } else { … … 1771 1781 } 1772 1782 1773 $plugin_name = preg_replace( '!\.php!', '', $plugin_page);1783 $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); 1774 1784 1775 1785 return $page_type.'_page_'.$plugin_name; 1776 1786 } 1777 1787 1778 function get_plugin_page_hook( $plugin_page, $parent_page) {1788 function get_plugin_page_hook( $plugin_page, $parent_page ) { 1779 1789 global $wp_filter; 1780 1790 1781 $hook = get_plugin_page_hookname( $plugin_page, $parent_page);1782 if ( isset ($wp_filter[$hook]))1791 $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); 1792 if ( isset( $wp_filter[$hook] )) 1783 1793 return $hook; 1784 1794 else … … 1787 1797 1788 1798 function browse_happy() { 1789 $getit = __( 'WordPress recommends a better browser');1799 $getit = __( 'WordPress recommends a better browser' ); 1790 1800 echo ' 1791 1801 <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p> 1792 1802 '; 1793 1803 } 1794 if ( strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE'))1795 add_action( 'admin_footer', 'browse_happy');1796 1797 function documentation_link( $for) {1804 if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' )) 1805 add_action( 'admin_footer', 'browse_happy' ); 1806 1807 function documentation_link( $for ) { 1798 1808 return; 1799 1809 } 1800 1810 1801 function register_importer( $id, $name, $description, $callback) {1811 function register_importer( $id, $name, $description, $callback ) { 1802 1812 global $wp_importers; 1803 1813 1804 $wp_importers[$id] = array ( $name, $description, $callback);1814 $wp_importers[$id] = array ( $name, $description, $callback ); 1805 1815 } 1806 1816 … … 1831 1841 // array wp_handle_upload ( array &file [, array overrides] ) 1832 1842 // file: reference to a single element of $_FILES. Call the function once for each uploaded file. 1833 // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE).1843 // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). 1834 1844 // On success, returns an associative array of file attributes. 1835 // On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array('error'=>$message).1836 function wp_handle_upload( &$file, $overrides = false) {1845 // On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). 1846 function wp_handle_upload( &$file, $overrides = false ) { 1837 1847 // The default error handler. 1838 if (! function_exists( 'wp_handle_upload_error') ) {1839 function wp_handle_upload_error( &$file, $message) {1840 return array( 'error'=>$message);1848 if (! function_exists( 'wp_handle_upload_error' ) ) { 1849 function wp_handle_upload_error( &$file, $message ) { 1850 return array( 'error'=>$message ); 1841 1851 } 1842 1852 } … … 1849 1859 1850 1860 // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. 1851 $upload_error_strings = array( false,1852 __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>."),1853 __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form."),1854 __( "The uploaded file was only partially uploaded."),1855 __( "No file was uploaded."),1856 __( "Missing a temporary folder."),1857 __( "Failed to write file to disk."));1861 $upload_error_strings = array( false, 1862 __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ), 1863 __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ), 1864 __( "The uploaded file was only partially uploaded." ), 1865 __( "No file was uploaded." ), 1866 __( "Missing a temporary folder." ), 1867 __( "Failed to write file to disk." )); 1858 1868 1859 1869 // All tests are on by default. Most can be turned off by $override[{test_name}] = false; … … 1865 1875 1866 1876 // Install user overrides. Did we mention that this voids your warranty? 1867 if ( is_array( $overrides) )1868 extract( $overrides, EXTR_OVERWRITE);1877 if ( is_array( $overrides ) ) 1878 extract( $overrides, EXTR_OVERWRITE ); 1869 1879 1870 1880 // A correct form post will pass this test. 1871 if ( $test_form && (!isset( $_POST['action']) || ($_POST['action'] != $action)) )1872 return $upload_error_handler( $file, __('Invalid form submission.'));1881 if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) 1882 return $upload_error_handler( $file, __( 'Invalid form submission.' )); 1873 1883 1874 1884 // A successful upload will pass this test. It makes no sense to override this one. 1875 1885 if ( $file['error'] > 0 ) 1876 return $upload_error_handler( $file, $upload_error_strings[$file['error']]);1886 return $upload_error_handler( $file, $upload_error_strings[$file['error']] ); 1877 1887 1878 1888 // A non-empty file will pass this test. 1879 if ( $test_size && !($file['size'] > 0 ) )1880 return $upload_error_handler( $file, __('File is empty. Please upload something more substantial.'));1889 if ( $test_size && !($file['size'] > 0 ) ) 1890 return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' )); 1881 1891 1882 1892 // A properly uploaded file will pass this test. There should be no reason to override this one. 1883 if (! @ is_uploaded_file( $file['tmp_name']) )1884 return $upload_error_handler( $file, __('Specified file failed upload test.'));1893 if (! @ is_uploaded_file( $file['tmp_name'] ) ) 1894 return $upload_error_handler( $file, __( 'Specified file failed upload test.' )); 1885 1895 1886 1896 // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. 1887 1897 if ( $test_type ) { 1888 $wp_filetype = wp_check_filetype( $file['name'], $mimes);1889 1890 extract( $wp_filetype);1898 $wp_filetype = wp_check_filetype( $file['name'], $mimes ); 1899 1900 extract( $wp_filetype ); 1891 1901 1892 1902 if ( !$type || !$ext ) 1893 return $upload_error_handler( $file, __('File type does not meet security guidelines. Try another.'));1894 } 1895 1896 // A writable uploads dir will pass this test. Override with $uploads = array('path'=>$path, 'url'=>$url);1897 if ( ( empty( $uploads['path'] ) || empty( $uploads['url'] ) ) &&! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )1898 return $upload_error_handler( $file, $uploads['error']);1903 return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' )); 1904 } 1905 1906 // A writable uploads dir will pass this test. Again, there's no point overriding this one. 1907 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 1908 return $upload_error_handler( $file, $uploads['error'] ); 1899 1909 1900 1910 // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. 1901 if ( isset( $unique_filename_callback) && function_exists($unique_filename_callback) ) {1902 $filename = $unique_filename_callback( $uploads['path'], $file['name']);1911 if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) { 1912 $filename = $unique_filename_callback( $uploads['path'], $file['name'] ); 1903 1913 } else { 1904 1914 $number = ''; 1905 $filename = str_replace( '#', '_', $file['name']);1906 $filename = str_replace( array('\\', "'"), '', $filename);1907 if ( empty( $ext) )1915 $filename = str_replace( '#', '_', $file['name'] ); 1916 $filename = str_replace( array( '\\', "'" ), '', $filename ); 1917 if ( empty( $ext) ) 1908 1918 $ext = ''; 1909 1919 else 1910 1920 $ext = ".$ext"; 1911 while ( file_exists( $uploads['path'] . "/$filename") ) {1921 while ( file_exists( $uploads['path'] . "/$filename" ) ) { 1912 1922 if ( '' == "$number$ext" ) 1913 1923 $filename = $filename . ++$number . $ext; 1914 1924 else 1915 $filename = str_replace( "$number$ext", ++$number . $ext, $filename);1916 } 1917 $filename = str_replace( $ext, '', $filename);1918 $filename = sanitize_title_with_dashes( $filename) . $ext;1925 $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); 1926 } 1927 $filename = str_replace( $ext, '', $filename ); 1928 $filename = sanitize_title_with_dashes( $filename ) . $ext; 1919 1929 } 1920 1930 1921 1931 // Move the file to the uploads dir 1922 1932 $new_file = $uploads['path'] . "/$filename"; 1923 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file) )1924 wp_die( printf(__('The uploaded file could not be moved to %s.'), $uploads['path']));1933 if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) 1934 wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] )); 1925 1935 1926 1936 // Set correct file permissions 1927 $stat = stat( dirname($new_file));1937 $stat = stat( dirname( $new_file )); 1928 1938 $perms = $stat['mode'] & 0000666; 1929 @ chmod( $new_file, $perms);1939 @ chmod( $new_file, $perms ); 1930 1940 1931 1941 // Compute the URL 1932 1942 $url = $uploads['url'] . "/$filename"; 1933 1943 1934 $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type) );1944 $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ); 1935 1945 1936 1946 return $return; 1937 1947 } 1938 1948 1939 function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96) {1949 function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { 1940 1950 if ( $height <= $hmax && $width <= $wmax ) 1941 return array( $width, $height);1951 return array( $width, $height); 1942 1952 elseif ( $width / $height > $wmax / $hmax ) 1943 return array( $wmax, (int) ($height / $width * $wmax));1953 return array( $wmax, (int) ($height / $width * $wmax )); 1944 1954 else 1945 return array( (int) ($width / $height * $hmax), $hmax);1946 } 1947 1948 function wp_import_cleanup( $id) {1949 wp_delete_attachment( $id);1950 } 1951 1952 function wp_import_upload_form( $action) {1953 $size = strtolower( ini_get( 'upload_max_filesize') );1955 return array( (int) ($width / $height * $hmax ), $hmax ); 1956 } 1957 1958 function wp_import_cleanup( $id ) { 1959 wp_delete_attachment( $id ); 1960 } 1961 1962 function wp_import_upload_form( $action ) { 1963 $size = strtolower( ini_get( 'upload_max_filesize' ) ); 1954 1964 $bytes = 0; 1955 1965 if ( strstr( $size, 'k' ) ) … … 1962 1972 <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo $action ?>"> 1963 1973 <p> 1964 <label for="upload"><?php _e( 'Choose a file from your computer:'); ?></label> (<?php printf( __('Maximum size: %s'), $size ); ?>)1974 <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?> ) 1965 1975 <input type="file" id="upload" name="import" size="25" /> 1966 1976 <input type="hidden" name="action" value="save" /> … … 1968 1978 </p> 1969 1979 <p class="submit"> 1970 <input type="submit" value="<?php _e( 'Upload file and import'); ?> »" />1980 <input type="submit" value="<?php _e( 'Upload file and import' ); ?> »" /> 1971 1981 </p> 1972 1982 </form> … … 1975 1985 1976 1986 function wp_import_handle_upload() { 1977 $overrides = array( 'test_form' => false, 'test_type' => false);1978 $file = wp_handle_upload( $_FILES['import'], $overrides);1979 1980 if ( isset( $file['error']) )1987 $overrides = array( 'test_form' => false, 'test_type' => false ); 1988 $file = wp_handle_upload( $_FILES['import'], $overrides ); 1989 1990 if ( isset( $file['error'] ) ) 1981 1991 return $file; 1982 1992 1983 1993 $url = $file['url']; 1984 1994 $file = addslashes( $file['file'] ); 1985 $filename = basename( $file);1995 $filename = basename( $file ); 1986 1996 1987 1997 // Construct the object array 1988 $object = array( 1989 'post_title' => $filename, 1998 $object = array( 'post_title' => $filename, 1990 1999 'post_content' => $url, 1991 2000 'post_mime_type' => 'import', … … 1994 2003 1995 2004 // Save the data 1996 $id = wp_insert_attachment( $object, $file);1997 1998 return array( 'file' => $file, 'id' => $id);1999 } 2000 2001 function the_attachment_links( $id = false) {2005 $id = wp_insert_attachment( $object, $file ); 2006 2007 return array( 'file' => $file, 'id' => $id ); 2008 } 2009 2010 function the_attachment_links( $id = false ) { 2002 2011 $id = (int) $id; 2003 $post = & get_post( $id);2012 $post = & get_post( $id ); 2004 2013 2005 2014 if ( $post->post_type != 'attachment' ) 2006 2015 return false; 2007 2016 2008 $icon = get_attachment_icon( $post->ID);2017 $icon = get_attachment_icon( $post->ID ); 2009 2018 $attachment_data = get_post_meta( $id, '_wp_attachment_metadata', true ); 2010 $thumb = isset( $attachment_data['thumb']);2019 $thumb = isset( $attachment_data['thumb'] ); 2011 2020 ?> 2012 2021 <form id="the-attachment-links"> … … 2015 2024 <col class="widefat" /> 2016 2025 <tr> 2017 <th scope="row"><?php _e( 'URL') ?></th>2026 <th scope="row"><?php _e( 'URL' ) ?></th> 2018 2027 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo $post->guid ?></textarea></td> 2019 2028 </tr> 2020 2029 <?php if ( $icon ) : ?> 2021 2030 <tr> 2022 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file') : _e('Image linked to file'); ?></th>2031 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th> 2023 2032 <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo $post->guid; ?>"><?php echo $icon ?></a></textarea></td> 2024 2033 </tr> 2025 2034 <tr> 2026 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page') : _e('Image linked to file'); ?></th>2027 <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>2035 <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to file' ); ?></th> 2036 <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> 2028 2037 </tr> 2029 2038 <?php else : ?> 2030 2039 <tr> 2031 <th scope="row"><?php _e( 'Link to file') ?></th>2032 <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>2040 <th scope="row"><?php _e( 'Link to file' ) ?></th> 2041 <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> 2033 2042 </tr> 2034 2043 <tr> 2035 <th scope="row"><?php _e( 'Link to page') ?></th>2036 <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>2044 <th scope="row"><?php _e( 'Link to page' ) ?></th> 2045 <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> 2037 2046 </tr> 2038 2047 <?php endif; ?> … … 2042 2051 } 2043 2052 2044 function get_udims( $width, $height) {2053 function get_udims( $width, $height) { 2045 2054 if ( $height <= 96 && $width <= 128 ) 2046 return array( $width, $height);2055 return array( $width, $height); 2047 2056 elseif ( $width / $height > 4 / 3 ) 2048 return array( 128, (int) ($height / $width * 128));2057 return array( 128, (int) ($height / $width * 128 )); 2049 2058 else 2050 return array( (int) ($width / $height * 96), 96);2051 } 2052 2053 function wp_reset_vars( $vars) {2054 for ( $i=0; $i<count($vars); $i += 1) {2059 return array( (int) ($width / $height * 96 ), 96 ); 2060 } 2061 2062 function wp_reset_vars( $vars ) { 2063 for ( $i=0; $i<count( $vars ); $i += 1 ) { 2055 2064 $var = $vars[$i]; 2056 2065 global $$var; 2057 2066 2058 if (!isset( $$var)) {2059 if ( empty($_POST["$var"])) {2060 if ( empty($_GET["$var"]))2067 if (!isset( $$var ) ) { 2068 if ( empty( $_POST["$var"] ) ) { 2069 if ( empty( $_GET["$var"] ) ) 2061 2070 $$var = ''; 2062 2071 else … … 2070 2079 2071 2080 // If siteurl or home changed, reset cookies and flush rewrite rules. 2072 function update_home_siteurl( $old_value, $value) {2081 function update_home_siteurl( $old_value, $value ) { 2073 2082 global $wp_rewrite, $user_login, $user_pass_md5; 2074 2083 2075 if ( defined( "WP_INSTALLING") )2084 if ( defined( "WP_INSTALLING" ) ) 2076 2085 return; 2077 2086 … … 2081 2090 wp_clearcookie(); 2082 2091 // Set cookies for new paths. 2083 wp_setcookie($user_login, $user_pass_md5, true, get_option('home'), get_option('siteurl')); 2084 } 2085 2086 add_action('update_option_home', 'update_home_siteurl', 10, 2); 2087 add_action('update_option_siteurl', 'update_home_siteurl', 10, 2); 2092 wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' )); 2093 } 2094 2095 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); 2096 add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); 2097 2098 function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { 2099 if ( ctype_digit( $src_file ) ) // Handle int as attachment ID 2100 $src_file = get_attached_file( $src_file ); 2101 2102 $src = wp_load_image( $src_file ); 2103 2104 if ( !is_resource( $src )) 2105 return $src; 2106 2107 $dst = imagecreatetruecolor( $dst_w, $dst_h ); 2108 2109 if ( $src_abs ) { 2110 $src_w -= $src_x; 2111 $src_h -= $src_y; 2112 } 2113 2114 imageantialias( $dst, true ); 2115 imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 2116 2117 if ( !$dst_file ) 2118 $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file ); 2119 2120 $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); 2121 2122 if ( imagejpeg( $dst, $dst_file ) ) 2123 return $dst_file; 2124 else 2125 return false; 2126 } 2127 2128 function wp_load_image( $file ) { 2129 if ( ctype_digit( $file ) ) 2130 $file = get_attached_file( $file ); 2131 2132 if ( !file_exists( $file ) ) 2133 return "File '$file' doesn't exist?"; 2134 2135 $contents = file_get_contents( $file ); 2136 2137 $image = imagecreatefromstring( $contents ); 2138 2139 if ( !is_resource( $image ) ) 2140 return "File '$file' is not image?"; 2141 2142 return $image; 2143 } 2088 2144 2089 2145 function autocomplete_css() { … … 2164 2220 2165 2221 add_action('update_option_new_admin_email', 'update_option_new_admin_email', 10, 2); 2166 2167 function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false) {2168 if ( ctype_digit($src_file) ) // Handle int as attachment ID2169 $src_file = get_attached_file($src_file);2170 2171 $src = wp_load_image($src_file);2172 2173 if ( !is_resource($src) )2174 return $src;2175 2176 $dst = imagecreatetruecolor($dst_w, $dst_h);2177 2178 if ( $src_abs ) {2179 $src_w -= $src_x;2180 $src_h -= $src_y;2181 }2182 2183 imageantialias($dst, true);2184 imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);2185 2186 if ( !$dst_file )2187 $dst_file = str_replace(basename($src_file), 'cropped-'.basename($src_file), $src_file);2188 2189 $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);2190 2191 if ( imagejpeg($dst, $dst_file) )2192 return $dst_file;2193 else2194 return false;2195 }2196 2197 function wp_load_image($file) {2198 if ( ctype_digit($file) )2199 $file = get_attached_file($file);2200 2201 if ( !file_exists($file) )2202 return "File '$file' doesn't exist?";2203 2204 $contents = file_get_contents($file);2205 2206 $image = imagecreatefromstring($contents);2207 2208 if ( !is_resource($image) )2209 return "File '$file' is not image?";2210 2211 return $image;2212 }2213 2214 2222 ?> trunk/wp-admin/admin-header.php
r770 r810 17 17 <head> 18 18 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 19 <title><?php bloginfo('name') ?> › <?php echo $title; ?> — WordPress</title>19 <title><?php bloginfo('name') ?> › <?php echo wp_specialchars( strip_tags( $title ) ); ?> — WordPress</title> 20 20 <link rel="stylesheet" href="<?php echo get_option('siteurl') ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 21 21 <?php if ( ('rtl' == $wp_locale->text_direction) ) : ?> trunk/wp-admin/bookmarklet.php
r729 r810 36 36 $post->post_title = $popuptitle; 37 37 38 38 39 39 $content = wp_specialchars($_REQUEST['content']); 40 40 $popupurl = wp_specialchars($_REQUEST['popupurl']); 41 if ( !empty($content) ) {42 $post->post_content = wp_specialchars( stripslashes($_REQUEST['content']) );43 } else {44 $post->post_content = '<a href="'.$popupurl.'">'.$popuptitle.'</a>'."\n$text";45 }41 if ( !empty($content) ) { 42 $post->post_content = wp_specialchars( stripslashes($_REQUEST['content']) ); 43 } else { 44 $post->post_content = '<a href="'.$popupurl.'">'.$popuptitle.'</a>'."\n$text"; 45 } 46 46 47 /* /big funky fixes */47 /* /big funky fixes */ 48 48 49 49 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> … … 78 78 79 79 #wpbookmarklet .wrap { 80 border: 0px;80 border: 0px; 81 81 } 82 82 83 83 #wpbookmarklet #postdiv { 84 margin-bottom: 0.5em;84 margin-bottom: 0.5em; 85 85 } 86 86 87 87 #wpbookmarklet #titlediv { 88 margin-bottom: 1em;88 margin-bottom: 1em; 89 89 } 90 90 trunk/wp-admin/categories.php
r774 r810 21 21 wp_redirect('categories.php?message=4#addcat'); 22 22 } 23 exit; 23 24 break; 24 25 … … 37 38 38 39 if ( $cat_ID == get_option('default_link_category') ) 39
