Changeset 4478
- Timestamp:
- 11/18/06 06:09:48 (2 years ago)
- Files:
-
- trunk/wp-admin/admin-functions.php (modified) (89 diffs)
- trunk/wp-admin/admin-header.php (modified) (1 diff)
- trunk/wp-admin/admin.php (modified) (1 diff)
- trunk/wp-admin/categories.php (modified) (1 diff)
- trunk/wp-admin/comment.php (modified) (1 diff)
- trunk/wp-admin/edit-comments.php (modified) (1 diff)
- trunk/wp-admin/edit-pages.php (modified) (1 diff)
- trunk/wp-admin/edit.php (modified) (1 diff)
- trunk/wp-admin/export.php (modified) (1 diff)
- trunk/wp-admin/import.php (modified) (1 diff)
- trunk/wp-admin/index.php (modified) (1 diff)
- trunk/wp-admin/link-add.php (modified) (1 diff)
- trunk/wp-admin/link-import.php (modified) (1 diff)
- trunk/wp-admin/link-manager.php (modified) (1 diff)
- trunk/wp-admin/menu-header.php (modified) (1 diff)
- trunk/wp-admin/menu.php (modified) (3 diffs)
- trunk/wp-admin/moderation.php (modified) (1 diff)
- trunk/wp-admin/options-discussion.php (modified) (1 diff)
- trunk/wp-admin/options-general.php (modified) (1 diff)
- trunk/wp-admin/options-misc.php (modified) (1 diff)
- trunk/wp-admin/options-permalink.php (modified) (1 diff)
- trunk/wp-admin/options-privacy.php (modified) (1 diff)
- trunk/wp-admin/options-reading.php (modified) (1 diff)
- trunk/wp-admin/options-writing.php (modified) (1 diff)
- trunk/wp-admin/options.php (modified) (1 diff)
- trunk/wp-admin/page-new.php (modified) (1 diff)
- trunk/wp-admin/plugin-editor.php (modified) (1 diff)
- trunk/wp-admin/plugins.php (modified) (1 diff)
- trunk/wp-admin/post-new.php (modified) (1 diff)
- trunk/wp-admin/profile.php (modified) (1 diff)
- trunk/wp-admin/templates.php (modified) (1 diff)
- trunk/wp-admin/theme-editor.php (modified) (1 diff)
- trunk/wp-admin/themes.php (modified) (1 diff)
- trunk/wp-admin/user-edit.php (modified) (1 diff)
- trunk/wp-admin/users.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/admin-functions.php
r4418 r4478 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
