Changeset 2889
- Timestamp:
- 09/18/05 19:44:14 (3 years ago)
- Files:
-
- trunk/wp-admin/admin-functions.php (modified) (83 diffs)
- trunk/wp-admin/link-add.php (modified) (5 diffs)
- trunk/wp-admin/link-manager.php (modified) (7 diffs)
- trunk/wp-admin/profile-update.php (modified) (1 diff)
- trunk/wp-admin/user-edit.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wp-admin/admin-functions.php
r2886 r2889 1 1 <?php 2 2 3 3 4 // Creates a new post from the "Write Post" form using $_POST information. … … 5 6 global $user_ID; 6 7 7 if ( ! current_user_can('edit_posts'))8 die( __('You are not allowed to create posts or drafts on this blog.'));8 if (!current_user_can('edit_posts')) 9 die(__('You are not allowed to create posts or drafts on this blog.')); 9 10 10 11 // Rename. 11 $_POST['post_content'] = $_POST['content'];12 $_POST['post_excerpt'] = $_POST['excerpt'];12 $_POST['post_content'] = $_POST['content']; 13 $_POST['post_excerpt'] = $_POST['excerpt']; 13 14 $_POST['post_parent'] = $_POST['parent_id']; 14 15 $_POST['to_ping'] = $_POST['trackback_url']; 15 16 16 if (! empty($_POST['post_author_override'])) {17 if (!empty ($_POST['post_author_override'])) { 17 18 $_POST['$post_author'] = (int) $_POST['post_author_override']; 18 } else if (! empty($_POST['post_author'])) { 19 $_POST['post_author'] = (int) $_POST['post_author']; 20 } else { 21 $_POST['post_author'] = (int) $_POST['user_ID']; 22 } 23 24 if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') ) 25 die( __('You cannot post as this user.') ); 26 19 } else 20 if (!empty ($_POST['post_author'])) { 21 $_POST['post_author'] = (int) $_POST['post_author']; 22 } else { 23 $_POST['post_author'] = (int) $_POST['user_ID']; 24 } 25 26 if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts')) 27 die(__('You cannot post as this user.')); 28 27 29 // What to do based on which button they pressed 28 if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft'; 29 if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private'; 30 if ('' != $_POST['publish']) $_POST['post_status'] = 'publish'; 31 if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft'; 32 if ('' != $_POST['savepage']) $_POST['post_status'] = 'static'; 33 34 if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') ) 30 if ('' != $_POST['saveasdraft']) 35 31 $_POST['post_status'] = 'draft'; 36 37 if ( !empty($_POST['edit_date']) ) { 32 if ('' != $_POST['saveasprivate']) 33 $_POST['post_status'] = 'private'; 34 if ('' != $_POST['publish']) 35 $_POST['post_status'] = 'publish'; 36 if ('' != $_POST['advanced']) 37 $_POST['post_status'] = 'draft'; 38 if ('' != $_POST['savepage']) 39 $_POST['post_status'] = 'static'; 40 41 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) 42 $_POST['post_status'] = 'draft'; 43 44 if (!empty ($_POST['edit_date'])) { 38 45 $aa = $_POST['aa']; 39 46 $mm = $_POST['mm']; … … 43 50 $ss = $_POST['ss']; 44 51 $jj = ($jj > 31) ? 31 : $jj; 45 $hh = ($hh > 23) ? $hh - 24 : $hh;46 $mn = ($mn > 59) ? $mn - 60 : $mn;47 $ss = ($ss > 59) ? $ss - 60 : $ss;52 $hh = ($hh > 23) ? $hh -24 : $hh; 53 $mn = ($mn > 59) ? $mn -60 : $mn; 54 $ss = ($ss > 59) ? $ss -60 : $ss; 48 55 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 49 56 $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss"); 50 } 57 } 51 58 52 59 // Create the post. … … 63 70 $post_ID = (int) $_POST['post_ID']; 64 71 65 if ( ! current_user_can('edit_post', $post_ID))66 die( __('You are not allowed to edit this post.'));72 if (!current_user_can('edit_post', $post_ID)) 73 die(__('You are not allowed to edit this post.')); 67 74 68 75 // Rename. 69 76 $_POST['ID'] = (int) $_POST['post_ID']; 70 $_POST['post_content'] = $_POST['content'];71 $_POST['post_excerpt'] = $_POST['excerpt'];77 $_POST['post_content'] = $_POST['content']; 78 $_POST['post_excerpt'] = $_POST['excerpt']; 72 79 $_POST['post_parent'] = $_POST['parent_id']; 73 80 $_POST['to_ping'] = $_POST['trackback_url']; 74 81 75 if (! empty($_POST['post_author_override'])) {82 if (!empty ($_POST['post_author_override'])) { 76 83 $_POST['$post_author'] = (int) $_POST['post_author_override']; 77 } else if (! empty($_POST['post_author'])) { 78 $_POST['post_author'] = (int) $_POST['post_author']; 79 } else { 80 $_POST['post_author'] = (int) $_POST['user_ID']; 81 } 82 83 if ( ($_POST['post_author'] != $_POST['user_ID']) && ! current_user_can('edit_others_posts') ) 84 die( __('You cannot post as this user.') ); 84 } else 85 if (!empty ($_POST['post_author'])) { 86 $_POST['post_author'] = (int) $_POST['post_author']; 87 } else { 88 $_POST['post_author'] = (int) $_POST['user_ID']; 89 } 90 91 if (($_POST['post_author'] != $_POST['user_ID']) && !current_user_can('edit_others_posts')) 92 die(__('You cannot post as this user.')); 85 93 86 94 // What to do based on which button they pressed 87 if ('' != $_POST['saveasdraft']) $_POST['post_status'] = 'draft'; 88 if ('' != $_POST['saveasprivate']) $_POST['post_status'] = 'private'; 89 if ('' != $_POST['publish']) $_POST['post_status'] = 'publish'; 90 if ('' != $_POST['advanced']) $_POST['post_status'] = 'draft'; 91 if ('' != $_POST['savepage']) $_POST['post_status'] = 'static'; 92 93 if ( 'publish' == $_POST['post_status'] && ! current_user_can('publish_posts') ) 95 if ('' != $_POST['saveasdraft']) 94 96 $_POST['post_status'] = 'draft'; 95 96 if ( !isset($_POST['comment_status']) ) 97 if ('' != $_POST['saveasprivate']) 98 $_POST['post_status'] = 'private'; 99 if ('' != $_POST['publish']) 100 $_POST['post_status'] = 'publish'; 101 if ('' != $_POST['advanced']) 102 $_POST['post_status'] = 'draft'; 103 if ('' != $_POST['savepage']) 104 $_POST['post_status'] = 'static'; 105 106 if ('publish' == $_POST['post_status'] && !current_user_can('publish_posts')) 107 $_POST['post_status'] = 'draft'; 108 109 if (!isset ($_POST['comment_status'])) 97 110 $_POST['comment_status'] = 'closed'; 98 111 99 if ( !isset($_POST['ping_status']))112 if (!isset ($_POST['ping_status'])) 100 113 $_POST['ping_status'] = 'closed'; 101 102 if ( !empty($_POST['edit_date'])) {114 115 if (!empty ($_POST['edit_date'])) { 103 116 $aa = $_POST['aa']; 104 117 $mm = $_POST['mm']; … … 108 121 $ss = $_POST['ss']; 109 122 $jj = ($jj > 31) ? 31 : $jj; 110 $hh = ($hh > 23) ? $hh - 24 : $hh;111 $mn = ($mn > 59) ? $mn - 60 : $mn;112 $ss = ($ss > 59) ? $ss - 60 : $ss;123 $hh = ($hh > 23) ? $hh -24 : $hh; 124 $mn = ($mn > 59) ? $mn -60 : $mn; 125 $ss = ($ss > 59) ? $ss -60 : $ss; 113 126 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 114 127 $_POST['post_date_gmt'] = get_gmt_from_date("$aa-$mm-$jj $hh:$mn:$ss"); 115 } 128 } 116 129 117 130 wp_update_post($_POST); 118 131 119 132 // Meta Stuff 120 if ($_POST['meta']) :121 foreach ($_POST['meta'] as $key => $value) :122 update_meta($key, $value['key'], $value['value']);123 endforeach;133 if ($_POST['meta']) 134 : foreach ($_POST['meta'] as $key => $value) 135 : update_meta($key, $value['key'], $value['value']); 136 endforeach; 124 137 endif; 125 138 126 if ($_POST['deletemeta']) :127 foreach ($_POST['deletemeta'] as $key => $value) :128 delete_meta($key);129 endforeach;139 if ($_POST['deletemeta']) 140 : foreach ($_POST['deletemeta'] as $key => $value) 141 : delete_meta($key); 142 endforeach; 130 143 endif; 131 144 132 145 add_meta($post_ID); 133 146 134 147 return $post_ID; 135 148 } … … 141 154 $comment_post_ID = (int) $_POST['comment_post_ID']; 142 155 143 if ( ! current_user_can('edit_post', $comment_post_ID))144 die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.'));156 if (!current_user_can('edit_post', $comment_post_ID)) 157 die(__('You are not allowed to edit comments on this post, so you cannot edit this comment.')); 145 158 146 159 $_POST['comment_author'] = $_POST['newcomment_author']; 147 $_POST['comment_author_email'] = $_POST['newcomment_author_email'];160 $_POST['comment_author_email'] = $_POST['newcomment_author_email']; 148 161 $_POST['comment_author_url'] = $_POST['newcomment_author_url']; 149 162 $_POST['comment_approved'] = $_POST['comment_status']; 150 163 $_POST['comment_content'] = $_POST['content']; 151 164 $_POST['comment_ID'] = (int) $_POST['comment_ID']; 152 153 if ( !empty($_POST['edit_date'])) {165 166 if (!empty ($_POST['edit_date'])) { 154 167 $aa = $_POST['aa']; 155 168 $mm = $_POST['mm']; … … 159 172 $ss = $_POST['ss']; 160 173 $jj = ($jj > 31) ? 31 : $jj; 161 $hh = ($hh > 23) ? $hh - 24 : $hh;162 $mn = ($mn > 59) ? $mn - 60 : $mn;163 $ss = ($ss > 59) ? $ss - 60 : $ss;174 $hh = ($hh > 23) ? $hh -24 : $hh; 175 $mn = ($mn > 59) ? $mn -60 : $mn; 176 $ss = ($ss > 59) ? $ss -60 : $ss; 164 177 $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; 165 178 } … … 182 195 183 196 if ($post->post_status == 'static') 184 $post->page_template = get_post_meta($id, '_wp_page_template', true); 197 $post->page_template = get_post_meta($id, '_wp_page_template', true); 185 198 186 199 return $post; … … 234 247 235 248 // Are we updating or creating? 236 if ( !empty($cat_ID)) {249 if (!empty ($cat_ID)) { 237 250 $update = true; 238 251 } else { … … 244 257 $cat_name = wp_specialchars($cat_name); 245 258 246 if ( empty($category_nicename))259 if (empty ($category_nicename)) 247 260 $category_nicename = sanitize_title($cat_name, $cat_ID); 248 261 else 249 262 $category_nicename = sanitize_title($category_nicename, $cat_ID); 250 263 251 if ( empty($category_description))264 if (empty ($category_description)) 252 265 $category_description = ''; 253 266 254 if ( empty($category_parent))267 if (empty ($category_parent)) 255 268 $category_parent = 0; 256 269 257 if ( !$update)270 if (!$update) 258 271 $query = "INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_description, category_parent) VALUES ('0', '$cat_name', '$category_nicename', '$category_description', '$cat')"; 259 272 else … … 262 275 $result = $wpdb->query($query); 263 276 264 if ( $update) {277 if ($update) { 265 278 do_action('edit_category', $cat_ID); 266 279 } else { … … 276 289 277 290 $cat_ID = (int) $catarr['cat_ID']; 278 291 279 292 // First, get all of the original fields 280 $category = get_category($cat_ID, ARRAY_A); 293 $category = get_category($cat_ID, ARRAY_A); 281 294 282 295 // Escape data pulled from DB. … … 295 308 296 309 // Don't delete the default cat. 297 if ( 1 == $cat_ID)310 if (1 == $cat_ID) 298 311 return 0; 299 312 … … 321 334 } 322 335 323 324 336 function wp_create_categories($categories, $post_id = '') { 325 $cat_ids = array ();337 $cat_ids = array (); 326 338 foreach ($categories as $category) { 327 if ( $id = category_exists($category))339 if ($id = category_exists($category)) 328 340 $cat_ids[] = $id; 329 else if ( $id = wp_create_category($category) ) 330 $cat_ids[] = $id; 331 } 332 333 if ( $post_id ) 341 else 342 if ($id = wp_create_category($category)) 343 $cat_ids[] = $id; 344 } 345 346 if ($post_id) 334 347 wp_set_post_cats('', $post_id, $cat_ids); 335 348 336 349 return $cat_ids; 337 350 } … … 339 352 function category_exists($cat_name) { 340 353 global $wpdb; 341 if ( !$category_nicename = sanitize_title($cat_name))354 if (!$category_nicename = sanitize_title($cat_name)) 342 355 return 0; 343 356 344 357 return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); 345 358 } … … 348 361 349 362 function add_user() { 350 return update_user();351 } 352 353 function update_user($user_id = 0) {354 355 if ( $user_id != 0) {363 return edit_user(); 364 } 365 366 function edit_user($user_id = 0) { 367 368 if ($user_id != 0) { 356 369 $update = true; 357 370 $user->ID = $user_id; … … 362 375 $user = ''; 363 376 } 364 365 if ( isset($_POST['user_login']))377 378 if (isset ($_POST['user_login'])) 366 379 $user->user_login = wp_specialchars(trim($_POST['user_login'])); 367 380 368 381 $pass1 = $pass2 = ''; 369 if ( isset($_POST['pass1']))382 if (isset ($_POST['pass1'])) 370 383 $pass1 = $_POST['pass1']; 371 if ( isset($_POST['pass2']))384 if (isset ($_POST['pass2'])) 372 385 $pass2 = $_POST['pass2']; 373 386 374 if ( isset($_POST['email']))387 if (isset ($_POST['email'])) 375 388 $user->user_email = wp_specialchars(trim($_POST['email'])); 376 if ( isset($_POST['url'])) {389 if (isset ($_POST['url'])) { 377 390 $user->user_url = wp_specialchars(trim($_POST['url'])); 378 $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url;379 } 380 if ( isset($_POST['first_name']))391 $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; 392 } 393 if (isset ($_POST['first_name'])) 381 394 $user->first_name = wp_specialchars(trim($_POST['first_name'])); 382 if ( isset($_POST['last_name']))395 if (isset ($_POST['last_name'])) 383 396 $user->last_name = wp_specialchars(trim($_POST['last_name'])); 384 if ( isset($_POST['nickname']))397 if (isset ($_POST['nickname'])) 385 398 $user->nickname = wp_specialchars(trim($_POST['nickname'])); 386 if ( isset($_POST['display_name']))399 if (isset ($_POST['display_name'])) 387 400 $user->display_name = wp_specialchars(trim($_POST['display_name'])); 388 if ( isset($_POST['description']))401 if (isset ($_POST['description'])) 389 402 $user->description = wp_specialchars(trim($_POST['description'])); 390 if ( isset($_POST['jabber']))403 if (isset ($_POST['jabber'])) 391 404 $user->jabber = wp_specialchars(trim($_POST['jabber'])); 392 if ( isset($_POST['aim']))405 if (isset ($_POST['aim'])) 393 406 $user->aim = wp_specialchars(trim($_POST['aim'])); 394 if ( isset($_POST['yim']))407 if (isset ($_POST['yim'])) 395 408 $user->yim = wp_specialchars(trim($_POST['yim'])); 396 409 397 $errors = array ();398 410 $errors = array (); 411 399 412 /* checking that username has been typed */ 400 413 if ($user->user_login == '') … … 402 415 403 416 /* checking the password has been typed twice */ 404 do_action('check_passwords', array ($user->user_login, &$pass1, &$pass2));405 406 if ( !$update) {407 if ( $pass1 == '' || $pass2 == '')417 do_action('check_passwords', array ($user->user_login, & $pass1, & $pass2)); 418 419 if (!$update) { 420 if ($pass1 == '' || $pass2 == '') 408 421 $errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.'); 409 422 } else { 410 if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ))423 if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))) 411 424 $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once."); 412 425 } 413 426 414 427 /* checking the password has been typed twice the same */ 415 428 if ($pass1 != $pass2) 416 429 $errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.'); 417 430 418 if ( !empty($pass1))431 if (!empty ($pass1)) 419 432 $user->user_pass = $pass1; 420 421 if ( !$update && username_exists( $user_login ))433 434 if (!$update && username_exists($user_login)) 422 435 $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.'); 423 436 424 437 /* checking e-mail address */ 425 if (empty ($user->user_email)) {438 if (empty ($user->user_email)) { 426 439 $errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address"); 427 } else if (!is_email($user->user_email)) { 428 $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct"); 429 } 430 431 if ( count($errors) != 0 ) 440 } else 441 if (!is_email($user->user_email)) { 442 $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct"); 443 } 444 445 if (count($errors) != 0) 432 446 return $errors; 433 434 if ( $update) {447 448 if ($update) { 435 449 $user_id = wp_update_user(get_object_vars($user)); 436 450 } else { … … 438 452 wp_new_user_notification($user_id); 439 453 } 440 454 441 455 return $errors; 442 456 } … … 446 460 447 461 $id = (int) $id; 448 449 if ($reassign == 'novalue') {462 463 if ($reassign == 'novalue') { 450 464 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_author = $id"); 451 465 452 466 if ($post_ids) { 453 467 $post_ids = implode(',', $post_ids); 454 468 455 469 // Delete comments, *backs 456 470 $wpdb->query("DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($post_ids)"); … … 462 476 $wpdb->query("DELETE FROM $wpdb->posts WHERE post_author = $id"); 463 477 } 464 478 465 479 // Clean links 466 480 $wpdb->query("DELETE FROM $wpdb->links WHERE link_owner = $id"); 467 481 } else { 468 $reassign = (int) $reassign;482 $reassign = (int) $reassign; 469 483 $wpdb->query("UPDATE $wpdb->posts SET post_author = {$reassign} WHERE post_author = {$id}"); 470 484 $wpdb->query("UPDATE $wpdb->links SET link_owner = {$reassign} WHERE link_owner = {$id}"); … … 479 493 } 480 494 495 function get_link($link_id, $output = OBJECT) { 496 global $wpdb; 497 498 $link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$link_id'"); 499 500 if ( $output == OBJECT ) { 501 return $link; 502 } elseif ( $output == ARRAY_A ) { 503 return get_object_vars($link); 504 } elseif ( $output == ARRAY_N ) { 505 return array_values(get_object_vars($link)); 506 } else { 507 return $link; 508 } 509 } 510 511 function get_link_to_edit($link_id) { 512 $link = get_link($link_id); 513 514 $link->link_url = wp_specialchars($link->link_url, 1); 515 $link->link_name = wp_specialchars($link->link_name, 1); 516 $link->link_description = wp_specialchars($link->link_description); 517 $link->link_notes = wp_specialchars($link->link_notes); 518 $link->link_rss = wp_specialchars($link->link_rss); 519 520 return $link; 521 } 522 523 function add_link() { 524 return edit_link(); 525 } 526 527 function edit_link($link_id = '') { 528 if (!current_user_can('manage_links')) 529 die(__("Cheatin' uh ?")); 530 531 $_POST['link_url'] = wp_specialchars($_POST['link_url']); 532 //$link_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $link_url) ? $link_url : 'http://'.$link_url; 533 $_POST['link_name'] = wp_specialchars($_POST['link_name']); 534 $_POST['link_image'] = wp_specialchars($_POST['link_image']); 535 $_POST['link_rss'] = wp_specialchars($_POST['link_rss']); 536 $auto_toggle = get_autotoggle($_POST['link_category']); 537 538 // if we are in an auto toggle category and this one is visible then we 539 // need to make the others invisible before we add this new one. 540 // FIXME Add category toggle func. 541 //if (($auto_toggle == 'Y') && ($link_visible == 'Y')) { 542 // $wpdb->query("UPDATE $wpdb->links set link_visible = 'N' WHERE link_category = $link_category"); 543 //} 544 545 if ( !empty($link_id) ) { 546 $_POST['link_id'] = $link_id; 547 return wp_update_link($_POST); 548 } else { 549 return wp_insert_link($_POST); 550 } 551 } 552 553 function wp_insert_link($linkdata) { 554 global $wpdb; 555 556 extract($linkdata); 557 558 $update = false; 559 if ( !empty($link_id) ) 560 $update = true; 561 562 if ( empty($link_rating) ) 563 $link_rating = 0; 564 565 if ( empty($link_target) ) 566 $link_target = ''; 567 568 if ( empty($link_visible) ) 569 $link_visible = 'Y'; 570 571 if ( $update ) { 572 $wpdb->query("UPDATE $wpdb->links SET link_url='$link_url', 573 link_name='$link_name', link_image='$link_image', 574 link_target='$link_target', link_category='$link_category', 575 link_visible='$link_visible', link_description='$link_description', 576 link_rating='$link_rating', link_rel='$link_rel', 577 link_notes='$link_notes', link_rss = '$link_rss' 578 WHERE link_id='$link_id'"); 579 } else { 580 $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('$link_url','$link_name', '$link_image', '$link_target', '$link_category', '$link_description', '$link_visible', '$link_owner', '$link_rating', '$link_rel', '$link_notes', '$link_rss')"); 581 $link_id = $wpdb->insert_id; 582 } 583 584 if ( $update ) 585 do_action('edit_link', $link_id); 586 else 587 do_action('add_link', $link_id); 588 589 return $link_id; 590 } 591 592 function wp_update_link($linkdata) { 593 global $wpdb; 594 595 $link_id = (int) $linkdata['link_id']; 596 597 $link = get_link($link_id, ARRAY_A); 598 599 // Escape data pulled from DB. 600 $link = add_magic_quotes($link); 601 602 // Merge old and new fields with new fields overwriting old ones. 603 $linkdata = array_merge($link, $linkdata); 604 605 return wp_insert_link($linkdata); 606 } 607 608 function wp_delete_link($link_id) { 609 global $wpdb; 610 611 return $wpdb->query("DELETE FROM $wpdb->links WHERE link_id = '$link_id'"); 612 } 613 481 614 function post_exists($title, $content = '', $post_date = '') { 482 615 global $wpdb; 483 484 if ( !empty($post_date))616 617 if (!empty ($post_date)) 485 618 $post_date = "AND post_date = '$post_date'"; 486 619 487 if ( ! empty($title))620 if (!empty ($title)) 488 621 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' $post_date"); 489 else if ( ! empty($content) ) 490 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date"); 622 else 623 if (!empty ($content)) 624 return $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' $post_date"); 491 625 492 626 return 0; … … 497 631 498 632 return $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments 499 WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'");500 } 501 502 function url_shorten ($url) {633 WHERE comment_author = '$comment_author' AND comment_date = '$comment_date'"); 634 } 635 636 function url_shorten($url) { 503 637 $short_url = str_replace('http://', '', stripslashes($url)); 504 638 $short_url = str_replace('www.', '', $short_url); … … 506 640 $short_url = substr($short_url, 0, -1); 507 641 if (strlen($short_url) > 35) 508 $short_url = substr($short_url, 0, 32).'...';642 $short_url = substr($short_url, 0, 32).'...'; 509 643 return $short_url; 510 644 } 511 645 512 646 function selected($selected, $current) { 513 if ($selected == $current) echo ' selected="selected"'; 647 if ($selected == $current) 648 echo ' selected="selected"'; 514 649 } 515 650 516 651 function checked($checked, $current) { 517 if ($checked == $current) echo ' checked="checked"'; 518 } 519 520 function return_categories_list( $parent = 0 ) { 652 if ($checked == $current) 653 echo ' checked="checked"'; 654 } 655 656 function return_categories_list($parent = 0) { 521 657 global $wpdb; 522 658 return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY category_count DESC"); … … 524 660 525 661 function get_nested_categories($default = 0, $parent = 0) { 526 global $post_ID, $mode, $wpdb; 527 528 if ($post_ID) { 529 $checked_categories = $wpdb->get_col(" 530 SELECT category_id 531 FROM $wpdb->categories, $wpdb->post2cat 532 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 533 "); 534 535 if(count($checked_categories) == 0) 536 { 537 // No selected categories, strange 538 $checked_categories[] = $default; 539 } 540 541 } else { 542 $checked_categories[] = $default; 543 } 544 545 $cats = return_categories_list($parent); 546 $result = array(); 547 548 if ( is_array( $cats ) ) { 549 foreach($cats as $cat) { 662 global $post_ID, $mode, $wpdb; 663 664 if ($post_ID) { 665 $checked_categories = $wpdb->get_col(" 666 SELECT category_id 667 FROM $wpdb->categories, $wpdb->post2cat 668 WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' 669 "); 670 671 if (count($checked_categories) == 0) { 672 // No selected categories, strange 673 $checked_categories[] = $default; 674 } 675 676 } else { 677 $checked_categories[] = $default; 678 } 679 680 $cats = return_categories_list($parent); 681 $result = array (); 682 683 if (is_array($cats)) { 684 foreach ($cats as $cat) { 550 685 $result[$cat]['children'] = get_nested_categories($default, $cat); 551 686 $result[$cat]['cat_ID'] = $cat; … … 559 694 560 695 function write_nested_categories($categories) { 561 foreach($categories as $category) { 562 echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], 563 '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', 564 ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n"; 565 566 if(isset($category['children'])) { 567 echo "\n<span class='cat-nest'>\n"; 568 write_nested_categories($category['children']); 569 echo "</span>\n"; 570 } 571 } 696 foreach ($categories as $category) { 697 echo '<label for="category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : ""), '/> ', wp_specialchars($category['cat_name']), "</label>\n"; 698 699 if (isset ($category['children'])) { 700 echo "\n<span class='cat-nest'>\n"; 701 write_nested_categories($category['children']); 702 echo "</span>\n"; 703 } 704 } 572 705 } 573 706 574 707 function dropdown_categories($default = 0) { 575 write_nested_categories(get_nested_categories($default));576 } 708 write_nested_categories(get_nested_categories($default)); 709 } 577 710 578 711 // Dandy new recursive multiple category stuff. … … 580 713 global $wpdb, $class; 581 714 582 if ( !$categories)715 if (!$categories) 583 716 $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name"); 584 717 … … 589 722 $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); 590 723 $pad = str_repeat('— ', $level); 591 if ( current_user_can('manage_categories'))592 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>" . __('Edit') . "</a></td><td><a href='categories.php?action=delete&cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . sprintf(__("You are about to delete the category "%s". All of its posts will go to the default category.\\n"OK" to delete, "Cancel" to stop."), wp_specialchars($category->cat_name, 1)) . "' );\" class='delete'>" . __('Delete') ."</a>";724 if (current_user_can('manage_categories')) 725 $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__('Edit')."</a></td><td><a href='categories.php?action=delete&cat_ID=$category->cat_ID' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '".sprintf(__("You are about to delete the category "%s". All of its posts will go to the default category.\\n"OK" to delete, "Cancel" to stop."), wp_specialchars($category->cat_name, 1))."' );\" class='delete'>".__('Delete')."</a>"; 593 726 else 594 727 $edit = ''; 595 728 596 729 $class = ('alternate' == $class) ? '' : 'alternate'; 597 730 echo "<tr id='cat-$category->cat_ID' class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td> 598 <td>$category->category_description</td>599 <td>$count</td>600 <td>$edit</td>601 </tr>";602 cat_rows($category->cat_ID, $level + 1, $categories);731 <td>$category->category_description</td> 732 <td>$count</td> 733 <td>$edit</td> 734 </tr>"; 735 cat_rows($category->cat_ID, $level +1, $categories); 603 736 } 604 737 } … … 608 741 } 609 742 610 function page_rows( $parent = 0, $level = 0, $pages = 0) {743 function page_rows($parent = 0, $level = 0, $pages = 0) { 611 744 global $wpdb, $class, $post; 612 745 if (!$pages) … … 614 747 615 748 if ($pages) { 616 foreach ($pages as $post) { start_wp(); 749 foreach ($pages as $post) { 750 start_wp(); 617 751 if ($post->post_parent == $parent) { 618 752 $post->post_title = wp_specialchars($post->post_title); … … 634 768 635 769 <?php 636 page_rows($id, $level + 1, $pages); 770 771 page_rows($id, $level +1, $pages); 637 772 } 638 773 } … … 648 783 } 649 784 if ($categories) { 650 foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { 651 $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); 652 $pad = str_repeat('– ', $level); 653 $category->cat_name = wp_specialchars($category->cat_name); 654 echo "\n\t<option value='$category->cat_ID'"; 655 if ($currentparent == $category->cat_ID) 656 echo " selected='selected'"; 657 echo ">$pad$category->cat_name</option>"; 658 wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level + 1, $categories); 659 } } 785 foreach ($categories as $category) { 786 if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { 787 $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID"); 788 $pad = str_repeat('– ', $level); 789 $category->cat_name = wp_specialchars($category->cat_name); 790 echo "\n\t<option value='$category->cat_ID'"; 791 if ($currentparent == $category->cat_ID) 792 echo " selected='selected'"; 793 echo ">$pad$category->cat_name</option>"; 794 wp_dropdown_cats($currentcat, $currentparent, $category->cat_ID, $level +1, $categories); 795 } 796 } 660 797 } else { 661 798 return false; … … 665 802 function wp_create_thumbnail($file, $max_side, $effect = '') { 666 803 667 // 1 = GIF, 2 = JPEG, 3 = PNG 668 669 if(file_exists($file)) { 670 $type = getimagesize($file); 671 672 // if the associated function doesn't exist - then it's not 673 // handle. duh. i hope. 674 675 if(!function_exists('imagegif') && $type[2] == 1) { 676 $error = __('Filetype not supported. Thumbnail not created.'); 677 }elseif(!function_exists('imagejpeg') && $type[2] == 2) { 678 $error = __('Filetype not supported. Thumbnail not created.'); 679 }elseif(!function_exists('imagepng') && $type[2] == 3) { 680 $error = __('Filetype not supported. Thumbnail not created.'); 681 } else { 682 683 // create the initial copy from the original file 684 if($type[2] == 1) { 685 $image = imagecreatefromgif($file); 686 } elseif($type[2] == 2) { 687 $image = imagecreatefromjpeg($file); 688 } elseif($type[2] == 3) { 689 $image = imagecreatefrompng($file); 690 } 691 804 // 1 = GIF, 2 = JPEG, 3 = PNG 805 806 if (file_exists($file)) { 807 $type = getimagesize($file); 808 809 // if the associated function doesn't exist - then it's not 810 // handle. duh. i hope. 811 812 if (!function_exists('imagegif') && $type[2] == 1) { 813 $error = __('Filetype not supported. Thumbnail not created.'); 814 } 815 elseif (!function_exists('imagejpeg') && $type[2] == 2) { 816 $error = __('Filetype not supported. Thumbnail not created.'); 817 } 818 elseif (!function_exists('imagepng') && $type[2] == 3) { 819 $error = __('Filetype not supported. Thumbnail not created.'); 820 } else { 821 822 // create the initial copy from the original file 823 if ($type[2] == 1) { 824 $image = imagecreatefromgif($file); 825 } 826 elseif ($type[2] == 2) { 827 $image = imagecreatefromjpeg($file); 828 } 829 elseif ($type[2] == 3) { 830 $image = imagecreatefrompng($file); 831 } 832 692 833 if (function_exists('imageantialias')) 693 imageantialias($image, TRUE); 694 695 $image_attr = getimagesize($file); 696 697 // figure out the longest side 698 699 if($image_attr[0] > $image_attr[1]) { 700 $image_width = $image_attr[0]; 701 $image_height = $image_attr[1]; 702 $image_new_width = $max_side; 703 704 $image_ratio = $image_width/$image_new_width; 705 $image_new_height = $image_height/$image_ratio; 706 //width is > height 707 } else { 708 $image_width = $image_attr[0]; 709 $image_height = $image_attr[1]; 710 $image_new_height = $max_side; 711 712 $image_ratio = $image_height/$image_new_height; 713 $image_new_width = $image_width/$image_ratio; 714 //height > width 715 } 716 717 $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 718 @imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 719 720 // move the thumbnail to it's final destination 721 722 $path = explode('/', $file); 723 $thumbpath = substr($file, 0, strrpos($file, '/')) . '/thumb-' . $path[count($path)-1]; 724 725 if($type[2] == 1) { 726 if(!imagegif($thumbnail, $thumbpath)) { 727 $error = __("Thumbnail path invalid"); 728 } 729 } elseif($type[2] == 2) { 730 if(!imagejpeg($thumbnail, $thumbpath)) { 731 $error = __("Thumbnail path invalid"); 732 } 733 } elseif($type[2] == 3) { 734 if(!imagepng($thumbnail, $thumbpath)) { 735 $error = __("Thumbnail path invalid"); 736 } 737 } 738 739 } 740 } 741 742 if(!empty($error)) 743 { 744 return $error; 745 } 746 else 747 { 748 return 1; 749 } 834 imageantialias($image, TRUE); 835 836 $image_attr = getimagesize($file); 837 838 // figure out the longest side 839 840 if ($image_attr[0] > $image_attr[1]) { 841 $image_width = $image_attr[0]; 842 $image_height = $image_attr[1]; 843 $image_new_width = $max_side; 844 845 $image_ratio = $image_width / $image_new_width; 846 $image_new_height = $image_height / $image_ratio; 847 //width is > height 848 } else { 849 $image_width = $image_attr[0]; 850 $image_height = $image_attr[1]; 851 $image_new_height = $max_side; 852 853 $image_ratio = $image_height / $image_new_height; 854 $image_new_width = $image_width / $image_ratio; 855 //height > width 856 } 857 858 $thumbnail = imagecreatetruecolor($image_new_width, $image_new_height); 859 @ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]); 860 861 // move the thumbnail to it's final destination 862 863 $path = explode('/', $file); 864 $thumbpath = substr($file, 0, strrpos($file, '/')).'/thumb-'.$p
