Ticket #11876: ms-functions.cleanup.patch
| File ms-functions.cleanup.patch, 50.6 KB (added by , 16 years ago) |
|---|
-
ms-functions.php
31 31 function get_blogaddress_by_name( $blogname ) { 32 32 global $current_site; 33 33 34 if ( is_subdomain_install() ) {35 if ( $blogname == 'main' )34 if ( is_subdomain_install() ) { 35 if ( $blogname == 'main' ) 36 36 $blogname = 'www'; 37 37 return clean_url( "http://" . $blogname . "." . $current_site->domain . $current_site->path ); 38 38 } else { … … 41 41 } 42 42 43 43 function get_blogaddress_by_domain( $domain, $path ){ 44 if ( is_subdomain_install() ) {44 if ( is_subdomain_install() ) { 45 45 $url = "http://".$domain.$path; 46 46 } else { 47 if ( $domain != $_SERVER['HTTP_HOST'] ) {47 if ( $domain != $_SERVER['HTTP_HOST'] ) { 48 48 $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); 49 if ( $blogname != 'www.' ) {49 if ( $blogname != 'www.' ) { 50 50 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path . $blogname . '/'; 51 51 } else { // we're installing the main blog 52 52 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path; … … 64 64 $stats['blogs'] = get_blog_count(); 65 65 66 66 $count_ts = get_site_option( "get_user_count_ts" ); 67 if ( time() - $count_ts > 3600 ) {67 if ( time() - $count_ts > 3600 ) { 68 68 $count = $wpdb->get_var( "SELECT COUNT(ID) FROM {$wpdb->users}" ); 69 69 update_site_option( "user_count", $count ); 70 70 update_site_option( "user_count_ts", time() ); … … 78 78 function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { 79 79 global $wpdb; 80 80 81 if ( $sitedomain == '' ) {81 if ( $sitedomain == '' ) 82 82 $site_id = $wpdb->siteid; 83 } else {83 else 84 84 $site_id = $wpdb->get_var( $wpdb->prepare("SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); 85 }86 85 87 if ( $site_id != false ) {86 if ( $site_id != false ) 88 87 return $wpdb->get_results( $wpdb->prepare("SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id), ARRAY_A ); 89 } 88 90 89 return false; 91 90 } 92 91 … … 97 96 98 97 function is_main_blog() { 99 98 global $current_blog, $current_site; 100 if ( $current_blog->domain == $current_site->domain && $current_blog->path == $current_site->path )99 if ( $current_blog->domain == $current_site->domain && $current_blog->path == $current_site->path ) 101 100 return true; 102 101 return false; 103 102 } … … 123 122 function get_blog_details( $id, $getall = true ) { 124 123 global $wpdb; 125 124 126 if ( !is_numeric( $id ) ) {125 if ( !is_numeric( $id ) ) 127 126 $id = get_id_from_blogname( $id ); 128 } 127 129 128 $all = $getall == true ? '' : 'short'; 130 129 $details = wp_cache_get( $id . $all, 'blog-details' ); 131 130 … … 151 150 152 151 $wpdb->suppress_errors(); 153 152 switch_to_blog( $id ); 154 $details->blogname = get_option( 'blogname' );155 $details->siteurl = get_option( 'siteurl' );156 $details->post_count = get_option( 'post_count' );153 $details->blogname = get_option( 'blogname' ); 154 $details->siteurl = get_option( 'siteurl' ); 155 $details->post_count = get_option( 'post_count' ); 157 156 restore_current_blog(); 158 157 $wpdb->suppress_errors( false ); 159 158 … … 216 215 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) ); 217 216 if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values 218 217 $value = $row->option_value; 219 if ( $value == false ) {218 if ( $value == false ) 220 219 wp_cache_set( $key, 'falsevalue', 'site-options' ); 221 } else {220 else 222 221 wp_cache_set( $key, $value, 'site-options' ); 223 }224 222 } else { // option does not exist, so we must cache its non-existence 225 223 wp_cache_set( $key, 'noop', 'site-options' ); 226 224 $value = $default; 227 225 } 228 } elseif ( $value == 'noop' ) {226 } elseif ( $value == 'noop' ) { 229 227 $value = $default; 230 } elseif ( $value == 'falsevalue' ) {228 } elseif ( $value == 'falsevalue' ) { 231 229 $value = false; 232 230 } 233 231 // If home is not set use siteurl. … … 268 266 update_option( $key, $value ); 269 267 restore_current_blog(); 270 268 271 if ( $refresh == true )269 if ( $refresh == true ) 272 270 refresh_blog_details( $id ); 273 271 wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options'); 274 272 } … … 298 296 $prev_blog_id = $blog_id; 299 297 $blog_id = $new_blog; 300 298 301 if ( is_object( $wp_roles ) ) {299 if ( is_object( $wp_roles ) ) { 302 300 $wpdb->suppress_errors(); 303 if ( method_exists( $wp_roles ,'_init' ) ) {301 if ( method_exists( $wp_roles ,'_init' ) ) 304 302 $wp_roles->_init(); 305 } elseif( method_exists( $wp_roles, '__construct' ) ) {303 elseif ( method_exists( $wp_roles, '__construct' ) ) 306 304 $wp_roles->__construct(); 307 }308 305 $wpdb->suppress_errors( false ); 309 306 } 310 307 311 308 if ( is_object( $current_user ) ) 312 309 $current_user->_init_caps(); 313 310 314 if ( is_object( $wp_object_cache ) ) {311 if ( is_object( $wp_object_cache ) ) 315 312 $global_groups = $wp_object_cache->global_groups; 316 } else {313 else 317 314 $global_groups = false; 318 } 315 319 316 wp_cache_init(); 320 317 if ( function_exists('wp_cache_add_global_groups') ) { 321 if ( is_array( $global_groups ) ) {318 if ( is_array( $global_groups ) ) 322 319 wp_cache_add_global_groups( $global_groups ); 323 } else {320 else 324 321 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient', 'global-posts' ) ); 325 }326 322 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 327 323 } 328 324 … … 353 349 $blog_id = $blog; 354 350 $table_prefix = $wpdb->prefix; 355 351 356 if ( is_object( $wp_roles ) ) {352 if ( is_object( $wp_roles ) ) { 357 353 $wpdb->suppress_errors(); 358 if ( method_exists( $wp_roles ,'_init' ) ) {354 if ( method_exists( $wp_roles ,'_init' ) ) 359 355 $wp_roles->_init(); 360 } elseif( method_exists( $wp_roles, '__construct' ) ) {356 elseif ( method_exists( $wp_roles, '__construct' ) ) 361 357 $wp_roles->__construct(); 362 }363 358 $wpdb->suppress_errors( false ); 364 359 } 365 360 366 361 if ( is_object( $current_user ) ) 367 362 $current_user->_init_caps(); 368 363 369 if ( is_object( $wp_object_cache ) ) {364 if ( is_object( $wp_object_cache ) ) 370 365 $global_groups = $wp_object_cache->global_groups; 371 } else {366 else 372 367 $global_groups = false; 373 } 368 374 369 wp_cache_init(); 375 370 if ( function_exists('wp_cache_add_global_groups') ) { 376 if ( is_array( $global_groups ) ) {371 if ( is_array( $global_groups ) ) 377 372 wp_cache_add_global_groups( $global_groups ); 378 } else {373 else 379 374 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient' ) ); 380 }381 375 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 382 376 } 383 377 … … 393 387 394 388 $cache_suffix = $all ? '_all' : '_short'; 395 389 $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' ); 396 if ( $return ) {390 if ( $return ) 397 391 return apply_filters( 'get_blogs_of_user', $return, $id, $all ); 398 }399 392 400 393 $user = get_userdata( (int) $id ); 401 394 if ( !$user ) … … 406 399 if ( false !== strpos( $key, '_capabilities') && 0 === strpos( $key, $wpdb->base_prefix ) && preg_match( '/' . $wpdb->base_prefix . '(\d+)_capabilities/', $key, $match ) ) { 407 400 $blog = get_blog_details( $match[1] ); 408 401 if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) { 409 $blogs[$match[1]]->userblog_id = $match[1];410 $blogs[$match[1]]->blogname = $blog->blogname;411 $blogs[$match[1]]->domain = $blog->domain;412 $blogs[$match[1]]->path = $blog->path;413 $blogs[$match[1]]->site_id = $blog->site_id;414 $blogs[$match[1]]->siteurl = $blog->siteurl;402 $blogs[$match[1]]->userblog_id = $match[1]; 403 $blogs[$match[1]]->blogname = $blog->blogname; 404 $blogs[$match[1]]->domain = $blog->domain; 405 $blogs[$match[1]]->path = $blog->path; 406 $blogs[$match[1]]->site_id = $blog->site_id; 407 $blogs[$match[1]]->siteurl = $blog->siteurl; 415 408 } 416 409 } 417 410 } … … 488 481 $user_id = (int) $user_id; 489 482 $blog_id = (int) $blog_id; 490 483 491 if ( $blog_id == 0 ) {484 if ( $blog_id == 0 ) { 492 485 global $wpdb; 493 486 $blog_id = $wpdb->blogid; 494 487 } 495 488 496 489 $blogs = get_blogs_of_user( $user_id ); 497 if ( is_array( $blogs ) ) {490 if ( is_array( $blogs ) ) 498 491 return array_key_exists( $blog_id, $blogs ); 499 } else {492 else 500 493 return false; 501 }502 494 } 503 495 504 496 function is_archived( $id ) { … … 517 509 return $value; 518 510 519 511 $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $id) ); 520 if ( $refresh == 1 )512 if ( $refresh == 1 ) 521 513 refresh_blog_details($id); 522 514 523 if ( $pref == 'spam' ) {524 if ( $value == 1 ) {515 if ( $pref == 'spam' ) { 516 if ( $value == 1 ) 525 517 do_action( "make_spam_blog", $id ); 526 } else {518 else 527 519 do_action( "make_ham_blog", $id ); 528 }529 520 } 530 521 531 522 return $value; … … 535 526 global $wpdb; 536 527 537 528 $details = get_blog_details( $id, false ); 538 if ( $details ) {529 if ( $details ) 539 530 return $details->$pref; 540 } 531 541 532 return $wpdb->get_var( $wpdb->prepare("SELECT $pref FROM {$wpdb->blogs} WHERE blog_id = %d", $id) ); 542 533 } 543 534 … … 549 540 function get_most_active_blogs( $num = 10, $display = true ) { 550 541 $most_active = get_site_option( "most_active" ); 551 542 $update = false; 552 if ( is_array( $most_active ) ) {553 if ( ( $most_active['time'] + 60 ) < time() ) { // cache for 60 seconds.543 if ( is_array( $most_active ) ) { 544 if ( ( $most_active['time'] + 60 ) < time() ) { // cache for 60 seconds. 554 545 $update = true; 555 546 } 556 547 } else { 557 548 $update = true; 558 549 } 559 550 560 if ( $update == true ) {551 if ( $update == true ) { 561 552 unset( $most_active ); 562 553 $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details 563 if ( is_array( $blogs ) ) {554 if ( is_array( $blogs ) ) { 564 555 reset( $blogs ); 565 556 foreach ( (array) $blogs as $key => $details ) { 566 557 $most_active[ $details['blog_id'] ] = $details['postcount']; … … 568 559 } 569 560 arsort( $most_active ); 570 561 reset( $most_active ); 571 foreach ( (array) $most_active as $key => $details ) {562 foreach ( (array) $most_active as $key => $details ) 572 563 $t[ $key ] = $blog_list[ $key ]; 573 } 564 574 565 unset( $most_active ); 575 566 $most_active = $t; 576 567 } 577 568 update_site_option( "most_active", $most_active ); 578 569 } 579 570 580 if ( $display == true ) {581 if ( is_array( $most_active ) ) {571 if ( $display == true ) { 572 if ( is_array( $most_active ) ) { 582 573 reset( $most_active ); 583 574 foreach ( (array) $most_active as $key => $details ) { 584 575 $url = clean_url("http://" . $details['domain'] . $details['path']); … … 594 585 595 586 $blogs = get_site_option( "blog_list" ); 596 587 $update = false; 597 if ( is_array( $blogs ) ) {598 if ( ( $blogs['time'] + 60 ) < time() ) { // cache for 60 seconds.588 if ( is_array( $blogs ) ) { 589 if ( ( $blogs['time'] + 60 ) < time() ) { // cache for 60 seconds. 599 590 $update = true; 600 591 } 601 592 } else { 602 593 $update = true; 603 594 } 604 595 605 if ( $update == true ) {596 if ( $update == true ) { 606 597 unset( $blogs ); 607 598 $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); 608 599 … … 615 606 update_site_option( "blog_list", $blogs ); 616 607 } 617 608 618 if ( false == is_array( $blogs ) )609 if ( false == is_array( $blogs ) ) 619 610 return array(); 620 611 621 if ( $num == 'all' ) {612 if ( $num == 'all' ) 622 613 return array_slice( $blogs, $start, count( $blogs ) ); 623 } else {614 else 624 615 return array_slice( $blogs, $start, $num ); 625 }626 616 } 627 617 628 618 function get_user_count() { 629 619 global $wpdb; 630 620 631 621 $count_ts = get_site_option( "user_count_ts" ); 632 if ( time() - $count_ts > 3600 ) {622 if ( time() - $count_ts > 3600 ) { 633 623 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") ); 634 624 update_site_option( "user_count", $count ); 635 625 update_site_option( "user_count_ts", time() ); … … 643 633 function get_blog_count( $id = 0 ) { 644 634 global $wpdb; 645 635 646 if ( $id == 0 )636 if ( $id == 0 ) 647 637 $id = $wpdb->siteid; 648 638 649 639 $count_ts = get_site_option( "blog_count_ts" ); 650 if ( time() - $count_ts > 3600 ) {640 if ( time() - $count_ts > 3600 ) { 651 641 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $id) ); 652 642 update_site_option( "blog_count", $count ); 653 643 update_site_option( "blog_count_ts", time() ); … … 663 653 664 654 $key = $blog_id . "-" . $post_id; 665 655 $post = wp_cache_get( $key, "global-posts" ); 666 if ( $post == false ) {656 if ( $post == false ) { 667 657 $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->get_blog_prefix( $blog_id ) . "posts WHERE ID = %d", $post_id ) ); 668 658 wp_cache_add( $key, $post, "global-posts" ); 669 659 } … … 736 726 update_usermeta($user_id, 'source_domain', ''); 737 727 } 738 728 739 if ( $reassign != '' ) {729 if ( $reassign != '' ) { 740 730 $reassign = (int) $reassign; 741 731 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE post_author = %d", $reassign, $user_id) ); 742 732 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_owner = %d WHERE link_owner = %d", $reassign, $user_id) ); … … 746 736 } 747 737 748 738 function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { 749 $domain = addslashes( $domain );750 $weblog_title = addslashes( $weblog_title );739 $domain = addslashes( $domain ); 740 $weblog_title = addslashes( $weblog_title ); 751 741 752 if ( empty($path) )742 if ( empty($path) ) 753 743 $path = '/'; 754 744 755 745 // Check if the domain has been used already. We should return an error message. … … 773 763 function get_blog_permalink( $_blog_id, $post_id ) { 774 764 $key = "{$_blog_id}-{$post_id}-blog_permalink"; 775 765 $link = wp_cache_get( $key, 'site-options' ); 776 if ( $link == false ) {766 if ( $link == false ) { 777 767 switch_to_blog( $_blog_id ); 778 768 $link = get_permalink( $post_id ); 779 769 restore_current_blog(); … … 789 779 $path = strtolower( $wpdb->escape( $path ) ); 790 780 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); 791 781 792 if ( $id == -1 ) { // blog does not exist782 if ( $id == -1 ) { // blog does not exist 793 783 return 0; 794 } elseif ( $id ) {784 } elseif ( $id ) { 795 785 return (int)$id; 796 786 } 797 787 … … 815 805 if ( isset( $_POST['ref'] ) ) 816 806 $ref = $_POST['ref']; 817 807 818 if ( $ref ) {808 if ( $ref ) { 819 809 $ref = wpmu_admin_redirect_add_updated_param( $ref ); 820 810 wp_redirect( $ref ); 821 811 exit(); 822 812 } 823 if ( empty( $_SERVER['HTTP_REFERER'] ) == false ) {813 if ( empty( $_SERVER['HTTP_REFERER'] ) == false ) { 824 814 wp_redirect( $_SERVER['HTTP_REFERER'] ); 825 815 exit(); 826 816 } 827 817 828 818 $url = wpmu_admin_redirect_add_updated_param( $url ); 829 if ( isset( $_GET['redirect'] ) ) {830 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) {819 if ( isset( $_GET['redirect'] ) ) { 820 if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) 831 821 $url .= "&action=blogs&s=". wp_specialchars( substr( $_GET['redirect'], 2 ) ); 832 } 833 } elseif( isset( $_POST['redirect'] ) ) { 822 } elseif ( isset( $_POST['redirect'] ) ) { 834 823 $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] ); 835 824 } 836 825 wp_redirect( $url ); … … 838 827 } 839 828 840 829 function wpmu_admin_redirect_add_updated_param( $url = '' ) { 841 if ( strpos( $url, 'updated=true' ) === false ) {842 if ( strpos( $url, '?' ) === false ) {830 if ( strpos( $url, 'updated=true' ) === false ) { 831 if ( strpos( $url, '?' ) === false ) 843 832 return $url . '?updated=true'; 844 } else {833 else 845 834 return $url . '&updated=true'; 846 }847 835 } 848 836 return $url; 849 837 } … … 863 851 } 864 852 865 853 function validate_email( $email, $check_domain = true) { 866 if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.867 '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.868 '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email))869 {870 if ($check_domain && function_exists('checkdnsrr')) {871 list (, $domain) = explode('@', $email);854 if (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'. 855 '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'. 856 '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) 857 { 858 if ($check_domain && function_exists('checkdnsrr')) { 859 list (, $domain) = explode('@', $email); 872 860 873 if (checkdnsrr($domain.'.', 'MX') || checkdnsrr($domain.'.', 'A')) { 874 return true; 875 } 876 return false; 877 } 878 return true; 879 } 880 return false; 861 if (checkdnsrr($domain.'.', 'MX') || checkdnsrr($domain.'.', 'A')) 862 return true; 863 return false; 864 } 865 return true; 866 } 867 return false; 881 868 } 882 869 883 870 function is_email_address_unsafe( $user_email ) { 884 871 $banned_names = get_site_option( "banned_email_domains" ); 885 if ($banned_names && !is_array( $banned_names )) {872 if ($banned_names && !is_array( $banned_names )) 886 873 $banned_names = explode( "\n", $banned_names); 887 } 874 888 875 if ( is_array( $banned_names ) && empty( $banned_names ) == false ) { 889 876 $email_domain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) ); 890 877 foreach( (array) $banned_names as $banned_domain ) { 891 if ( $banned_domain == '' )878 if ( $banned_domain == '' ) 892 879 continue; 893 880 if ( 894 881 strstr( $email_domain, $banned_domain ) || … … 917 904 $maybe = array(); 918 905 preg_match( "/[a-z0-9]+/", $user_name, $maybe ); 919 906 920 if( $user_name != $maybe[0] ) { 921 $errors->add('user_name', __("Only lowercase letters and numbers allowed")); 922 } 907 if ( $user_name != $maybe[0] ) 908 $errors->add('user_name', __("Only lowercase letters and numbers allowed")); 923 909 924 910 $illegal_names = get_site_option( "illegal_names" ); 925 if ( is_array( $illegal_names ) == false ) {911 if ( is_array( $illegal_names ) == false ) { 926 912 $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" ); 927 913 add_site_option( "illegal_names", $illegal_names ); 928 914 } 929 if( in_array( $user_name, $illegal_names ) == true ) { 930 $errors->add('user_name', __("That username is not allowed")); 931 } 915 if ( in_array( $user_name, $illegal_names ) == true ) 916 $errors->add('user_name', __("That username is not allowed")); 932 917 933 if ( is_email_address_unsafe( $user_email ) )918 if ( is_email_address_unsafe( $user_email ) ) 934 919 $errors->add('user_email', __("You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.")); 935 920 936 if( strlen( $user_name ) < 4 ) { 937 $errors->add('user_name', __("Username must be at least 4 characters")); 938 } 921 if ( strlen( $user_name ) < 4 ) 922 $errors->add('user_name', __("Username must be at least 4 characters")); 939 923 940 924 if ( strpos( " " . $user_name, "_" ) != false ) 941 925 $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!")); … … 947 931 $errors->add('user_name', __("Sorry, usernames must have letters too!")); 948 932 949 933 if ( !is_email( $user_email ) ) 950 $errors->add('user_email', __("Please enter a correct email address"));934 $errors->add('user_email', __("Please enter a correct email address")); 951 935 952 936 if ( !validate_email( $user_email ) ) 953 937 $errors->add('user_email', __("Please check your email address.")); … … 955 939 $limited_email_domains = get_site_option( 'limited_email_domains' ); 956 940 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { 957 941 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); 958 if ( in_array( $emaildomain, $limited_email_domains ) == false ) {942 if ( in_array( $emaildomain, $limited_email_domains ) == false ) 959 943 $errors->add('user_email', __("Sorry, that email address is not allowed!")); 960 }961 944 } 962 945 963 946 // Check if the username has been used already. … … 975 958 $now = current_time( 'timestamp', true ); 976 959 $diff = $now - $registered_at; 977 960 // If registered more than two days ago, cancel registration and let this signup go through. 978 if ( $diff > 172800 ) {961 if ( $diff > 172800 ) 979 962 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_login = %s", $user_name) ); 980 } else {963 else 981 964 $errors->add('user_name', __("That username is currently reserved but may be available in a couple of days.")); 982 } 983 if ( $signup->active == 0 && $signup->user_email == $user_email )965 966 if ( $signup->active == 0 && $signup->user_email == $user_email ) 984 967 $errors->add('user_email_used', __("username and email used")); 985 968 } 986 969 … … 988 971 if ( $signup != null ) { 989 972 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); 990 973 // If registered more than two days ago, cancel registration and let this signup go through. 991 if ( $diff > 172800 ) {974 if ( $diff > 172800 ) 992 975 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_email = %s", $user_email) ); 993 } else {976 else 994 977 $errors->add('user_email', __("That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.")); 995 }996 978 } 997 979 998 980 $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); … … 1009 991 1010 992 $errors = new WP_Error(); 1011 993 $illegal_names = get_site_option( "illegal_names" ); 1012 if ( $illegal_names == false ) {1013 $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" );1014 add_site_option( "illegal_names", $illegal_names );994 if ( $illegal_names == false ) { 995 $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" ); 996 add_site_option( "illegal_names", $illegal_names ); 1015 997 } 1016 998 1017 999 if ( empty( $blogname ) ) 1018 $errors->add('blogname', __("Please enter a blog name"));1000 $errors->add('blogname', __("Please enter a blog name")); 1019 1001 1020 1002 $maybe = array(); 1021 1003 preg_match( "/[a-z0-9]+/", $blogname, $maybe ); 1022 if( $blogname != $maybe[0] ) { 1023 $errors->add('blogname', __("Only lowercase letters and numbers allowed")); 1024 } 1025 if( in_array( $blogname, $illegal_names ) == true ) { 1026 $errors->add('blogname', __("That name is not allowed")); 1027 } 1028 if( strlen( $blogname ) < 4 && !is_super_admin() ) { 1029 $errors->add('blogname', __("Blog name must be at least 4 characters")); 1030 } 1004 if ( $blogname != $maybe[0] ) 1005 $errors->add('blogname', __("Only lowercase letters and numbers allowed")); 1031 1006 1007 if ( in_array( $blogname, $illegal_names ) == true ) 1008 $errors->add('blogname', __("That name is not allowed")); 1009 1010 if ( strlen( $blogname ) < 4 && !is_super_admin() ) 1011 $errors->add('blogname', __("Blog name must be at least 4 characters")); 1012 1032 1013 if ( strpos( " " . $blogname, "_" ) != false ) 1033 1014 $errors->add('blogname', __("Sorry, blog names may not contain the character '_'!")); 1034 1015 1035 1016 // do not allow users to create a blog that conflicts with a page on the main blog. 1036 if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) {1017 if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) 1037 1018 $errors->add( 'blogname', __( "Sorry, you may not use that blog name" ) ); 1038 }1039 1019 1040 1020 // all numeric? 1041 1021 $match = array(); … … 1048 1028 $blog_title = stripslashes( $blog_title ); 1049 1029 1050 1030 if ( empty( $blog_title ) ) 1051 $errors->add('blog_title', __("Please enter a blog title"));1031 $errors->add('blog_title', __("Please enter a blog title")); 1052 1032 1053 1033 // Check if the domain/path has been used already. 1054 if ( is_subdomain_install() ) {1034 if ( is_subdomain_install() ) { 1055 1035 $mydomain = "$blogname.$domain"; 1056 1036 $path = $base; 1057 1037 } else { … … 1071 1051 if ( ! empty($signup) ) { 1072 1052 $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); 1073 1053 // If registered more than two days ago, cancel registration and let this signup go through. 1074 if ( $diff > 172800 ) {1054 if ( $diff > 172800 ) 1075 1055 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) ); 1076 } else {1056 else 1077 1057 $errors->add('blogname', __("That blog is currently reserved but may be available in a couple days.")); 1078 }1079 1058 } 1080 1059 1081 1060 $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors); … … 1134 1113 function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') { 1135 1114 global $current_site; 1136 1115 1137 if ( !apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta) )1116 if ( !apply_filters('wpmu_signup_blog_notification', $domain, $path, $title, $user, $user_email, $key, $meta) ) 1138 1117 return false; 1139 1118 1140 1119 // Send email with activation link. 1141 if ( !is_subdomain_install() || $current_site->id != 1 ) {1120 if ( !is_subdomain_install() || $current_site->id != 1 ) 1142 1121 $activate_url = "http://" . $current_site->domain . $current_site->path . "wp-activate.php?key=$key"; 1143 } else {1122 else 1144 1123 $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; 1145 } 1124 1146 1125 $activate_url = clean_url($activate_url); 1147 1126 $admin_email = get_site_option( "admin_email" ); 1148 if ( $admin_email == '' )1127 if ( $admin_email == '' ) 1149 1128 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1150 1129 $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 1151 1130 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; … … 1159 1138 function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') { 1160 1139 global $current_site; 1161 1140 1162 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) )1141 if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) ) 1163 1142 return false; 1164 1143 1165 1144 // Send email with activation link. 1166 1145 $admin_email = get_site_option( "admin_email" ); 1167 if ( $admin_email == '' )1146 if ( $admin_email == '' ) 1168 1147 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1169 1148 $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 1170 1149 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; … … 1206 1185 1207 1186 if ( empty($signup->domain) ) { 1208 1187 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) ); 1188 1209 1189 if ( isset( $user_already_exists ) ) 1210 1190 return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup); 1191 1211 1192 wpmu_welcome_user_notification($user_id, $password, $meta); 1212 1193 $user_site = get_site_option( 'dashboard_blog', $current_site->blog_id ); 1213 if ( $user_site == false ) { 1194 1195 if ( $user_site == false ) 1214 1196 add_user_to_blog( '1', $user_id, get_site_option( 'default_user_role', 'subscriber' ) ); 1215 } else {1197 else 1216 1198 add_user_to_blog( $user_site, $user_id, get_site_option( 'default_user_role', 'subscriber' ) ); 1217 } 1199 1218 1200 add_new_user_to_blog( $user_id, $user_email, $meta ); 1219 1201 do_action('wpmu_activate_user', $user_id, $password, $meta); 1220 1202 return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta); … … 1231 1213 $blog_id->add_data( $signup ); 1232 1214 $wpdb->update( $wpdb->signups, array( 'active' => 1, 'activated' => $now ), array( 'activation_key' => $key ) ); 1233 1215 } 1234 1235 1216 return $blog_id; 1236 1217 } 1237 1218 1238 1219 $wpdb->update( $wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key) ); 1239 1240 1220 wpmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta); 1241 1242 1221 do_action('wpmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta); 1243 1222 1244 1223 return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); … … 1267 1246 1268 1247 function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { 1269 1248 $domain = preg_replace( "/\s+/", '', sanitize_user( $domain, true ) ); 1270 if( is_subdomain_install() ) 1249 1250 if ( is_subdomain_install() ) 1271 1251 $domain = str_replace( '@', '', $domain ); 1252 1272 1253 $title = strip_tags( $title ); 1273 1254 $user_id = (int) $user_id; 1274 1255 1275 if ( empty($path) )1256 if ( empty($path) ) 1276 1257 $path = '/'; 1277 1258 1278 1259 // Check if the domain has been used already. We should return an error message. … … 1286 1267 return new WP_Error('insert_blog', __('Could not create blog.')); 1287 1268 1288 1269 switch_to_blog($blog_id); 1289 1290 1270 install_blog($blog_id, $title); 1291 1292 1271 install_blog_defaults($blog_id, $user_id); 1293 1272 1294 1273 add_user_to_blog($blog_id, $user_id, 'administrator'); 1295 1274 1296 1275 if ( is_array($meta) ) foreach ($meta as $key => $value) { 1297 if ( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' ) {1276 if ( $key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id' ) 1298 1277 update_blog_status( $blog_id, $key, $value ); 1299 } else {1278 else 1300 1279 update_option( $key, $value ); 1301 }1302 1280 } 1303 1281 1304 1282 add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); 1305 1306 1283 update_option( 'blog_public', $meta['public'] ); 1307 1284 1308 1285 if ( !is_super_admin() && get_usermeta( $user_id, 'primary_blog' ) == get_site_option( 'dashboard_blog', 1 ) ) 1309 1286 update_usermeta( $user_id, 'primary_blog', $blog_id ); 1310 1287 1311 1288 restore_current_blog(); 1312 1313 1289 do_action( 'wpmu_new_blog', $blog_id, $user_id ); 1314 1290 1315 1291 return $blog_id; … … 1317 1293 1318 1294 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 1319 1295 global $current_site; 1320 if ( get_site_option( 'registrationnotification' ) != 'yes' )1296 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 1321 1297 return false; 1322 1298 1323 1299 $email = get_site_option( 'admin_email' ); 1324 if ( is_email($email) == false )1300 if ( is_email($email) == false ) 1325 1301 return false; 1326 1302 1327 1303 $options_site_url = clean_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php"); … … 1344 1320 1345 1321 function newuser_notify_siteadmin( $user_id ) { 1346 1322 global $current_site; 1347 if( get_site_option( 'registrationnotification' ) != 'yes' ) 1323 1324 if ( get_site_option( 'registrationnotification' ) != 'yes' ) 1348 1325 return false; 1349 1326 1350 1327 $email = get_site_option( 'admin_email' ); 1351 if( is_email($email) == false ) 1328 1329 if ( is_email($email) == false ) 1352 1330 return false; 1331 1353 1332 $user = new WP_User($user_id); 1354 1333 1355 1334 $options_site_url = clean_url("http://{$current_site->domain}{$current_site->path}wp-admin/ms-options.php"); … … 1390 1369 // Cast for security 1391 1370 $blog_id = (int) $blog_id; 1392 1371 1393 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );1372 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1394 1373 1395 1374 if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") ) 1396 1375 die(__('<h1>Already Installed</h1><p>You appear to have already installed WordPress. To reinstall please clear your old database tables first.</p>') . '</body></html>'); 1397 $wpdb->suppress_errors( false); 1376 1377 $wpdb->suppress_errors(false); 1398 1378 1399 1379 $url = get_blogaddress_by_id($blog_id); 1400 1380 … … 1422 1402 $cat_slug = sanitize_title($cat_name); 1423 1403 1424 1404 $blogroll_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); 1425 if( $blogroll_id == null ) { 1405 1406 if ( $blogroll_id == null ) { 1426 1407 $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); 1427 1408 $blogroll_id = $wpdb->insert_id; 1428 1409 } … … 1457 1438 $now = date('Y-m-d H:i:s'); 1458 1439 $now_gmt = gmdate('Y-m-d H:i:s'); 1459 1440 $first_post = get_site_option( 'first_post' ); 1460 if( $first_post == false ) { 1441 1442 if ( $first_post == false ) 1461 1443 $first_post = stripslashes( __( 'Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!' ) ); 1462 } 1444 1463 1445 $first_post = str_replace( "SITE_URL", clean_url("http://" . $current_site->domain . $current_site->path), $first_post ); 1464 1446 $first_post = str_replace( "SITE_NAME", $current_site->site_name, $first_post ); 1465 1447 $wpdb->insert( $wpdb->posts, array( … … 1531 1513 function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') { 1532 1514 global $current_site; 1533 1515 1534 if ( !apply_filters('wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta) )1516 if ( !apply_filters('wpmu_welcome_notification', $blog_id, $user_id, $password, $title, $meta) ) 1535 1517 return false; 1536 1518 1537 1519 $welcome_email = stripslashes( get_site_option( 'welcome_email' ) ); 1538 if ( $welcome_email == false )1520 if ( $welcome_email == false ) 1539 1521 $welcome_email = stripslashes( __( "Dear User, 1540 1522 1541 1523 Your new SITE_NAME blog has been successfully set up at: … … 1563 1545 1564 1546 $welcome_email = apply_filters( "update_welcome_email", $welcome_email, $blog_id, $user_id, $password, $title, $meta); 1565 1547 $admin_email = get_site_option( "admin_email" ); 1566 if( $admin_email == '' ) 1548 1549 if ( $admin_email == '' ) 1567 1550 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1551 1568 1552 $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 1569 1553 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 1570 1554 $message = $welcome_email; 1571 if( empty( $current_site->site_name ) ) 1555 1556 if ( empty( $current_site->site_name ) ) 1572 1557 $current_site->site_name = "WordPress MU"; 1558 1573 1559 $subject = apply_filters( 'update_welcome_subject', sprintf(__('New %1$s Blog: %2$s'), $current_site->site_name, stripslashes( $title ) ) ); 1574 1560 wp_mail($user->user_email, $subject, $message, $message_headers); 1575 1561 return true; … … 1578 1564 function wpmu_welcome_user_notification($user_id, $password, $meta = '') { 1579 1565 global $current_site; 1580 1566 1581 if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) )1567 if ( !apply_filters('wpmu_welcome_user_notification', $user_id, $password, $meta) ) 1582 1568 return false; 1583 1569 1584 1570 $welcome_email = get_site_option( 'welcome_user_email' ); … … 1592 1578 $welcome_email = str_replace( "LOGINLINK", wp_login_url(), $welcome_email ); 1593 1579 1594 1580 $admin_email = get_site_option( "admin_email" ); 1595 if( $admin_email == '' ) 1581 1582 if ( $admin_email == '' ) 1596 1583 $admin_email = 'support@' . $_SERVER['SERVER_NAME']; 1584 1597 1585 $from_name = get_site_option( "site_name" ) == '' ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 1598 1586 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 1599 1587 $message = $welcome_email; 1600 if( empty( $current_site->site_name ) ) 1588 1589 if ( empty( $current_site->site_name ) ) 1601 1590 $current_site->site_name = "WordPress MU"; 1591 1602 1592 $subject = apply_filters( 'update_welcome_user_subject', sprintf(__('New %1$s User: %2$s'), $current_site->site_name, $user->user_login) ); 1603 1593 wp_mail($user->user_email, $subject, $message, $message_headers); 1604 1594 return true; … … 1646 1636 // If this is the first post checked or if this post is 1647 1637 // newer than the current recent post, make it the new 1648 1638 // most recent post. 1649 if ( 1650 !isset($most_recent_post['post_gmt_ts']) 1651 || ($post_gmt_ts > $most_recent_post['post_gmt_ts']) 1652 ) { 1639 if ( !isset($most_recent_post['post_gmt_ts']) || ( $post_gmt_ts > $most_recent_post['post_gmt_ts'] ) ) { 1653 1640 $most_recent_post = array( 1654 1641 'blog_id' => $blog->userblog_id, 1655 1642 'post_id' => $recent_post['ID'], … … 1672 1659 1673 1660 function get_dirsize( $directory ) { 1674 1661 $dirsize = get_transient( 'dirsize_cache' ); 1675 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) {1662 if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) 1676 1663 return $dirsize[ $directory ][ 'size' ]; 1677 } 1678 if ( false == is_array( $dirsize ) ) {1664 1665 if ( false == is_array( $dirsize ) ) 1679 1666 $dirsize = array(); 1680 } 1667 1681 1668 $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory ); 1682 1669 1683 1670 set_transient( 'dirsize_cache', $dirsize, 3600 ); … … 1693 1680 1694 1681 function recurse_dirsize( $directory ) { 1695 1682 $size = 0; 1696 if(substr($directory,-1) == '/') $directory = substr($directory,0,-1); 1697 if(!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) return false; 1698 if($handle = opendir($directory)) { 1683 1684 if ( substr( $directory, -1 ) == '/' ) 1685 $directory = substr($directory,0,-1); 1686 1687 if ( !file_exists($directory) || !is_dir( $directory ) || !is_readable( $directory ) ) 1688 return false; 1689 1690 if ($handle = opendir($directory)) { 1699 1691 while(($file = readdir($handle)) !== false) { 1700 1692 $path = $directory.'/'.$file; 1701 if ($file != '.' && $file != '..') {1702 if (is_file($path)) {1693 if ($file != '.' && $file != '..') { 1694 if (is_file($path)) { 1703 1695 $size += filesize($path); 1704 } elseif (is_dir($path)) {1696 } elseif (is_dir($path)) { 1705 1697 $handlesize = recurse_dirsize($path); 1706 if ($handlesize >= 0) {1698 if ($handlesize >= 0) 1707 1699 $size += $handlesize; 1708 } else {1700 else 1709 1701 return false; 1710 }1711 1702 } 1712 1703 } 1713 1704 } … … 1717 1708 } 1718 1709 1719 1710 function upload_is_user_over_quota( $echo = true ) { 1720 if ( get_site_option( 'upload_space_check_disabled' ) ) {1711 if ( get_site_option( 'upload_space_check_disabled' ) ) 1721 1712 return true; 1722 } 1713 1723 1714 $spaceAllowed = get_space_allowed(); 1724 if (empty($spaceAllowed) || !is_numeric($spaceAllowed))1715 if ( empty( $spaceAllowed ) || !is_numeric( $spaceAllowed ) ) 1725 1716 $spaceAllowed = 10; // Default space allowed is 10 MB 1726 1717 1727 1718 $dirName = BLOGUPLOADDIR; 1728 1719 $size = get_dirsize($dirName) / 1024 / 1024; 1729 1720 1730 if ( ($spaceAllowed-$size) < 0 ) {1731 if ( $echo )1721 if ( ($spaceAllowed-$size) < 0 ) { 1722 if ( $echo ) 1732 1723 _e( "Sorry, you have used your space allocation. Please delete some files to upload more files." ); //No space left 1733 1724 return true; 1734 1725 } else { … … 1736 1727 } 1737 1728 } 1738 1729 1739 function check_upload_mimes( $mimes) {1730 function check_upload_mimes( $mimes ) { 1740 1731 $site_exts = explode( " ", get_site_option( "upload_filetypes" ) ); 1741 1732 foreach ( $site_exts as $ext ) { 1742 foreach ( $mimes as $ext_pattern => $mime ) {1743 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) {1733 foreach ( $mimes as $ext_pattern => $mime ) 1734 if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false ) { 1744 1735 $site_mimes[$ext_pattern] = $mime; 1745 }1746 1736 } 1747 1737 } 1748 1738 return $site_mimes; … … 1760 1750 } 1761 1751 1762 1752 function fix_import_form_size( $size ) { 1763 if ( upload_is_user_over_quota( false ) == true ) {1753 if ( upload_is_user_over_quota( false ) == true ) 1764 1754 return 0; 1765 }1766 1755 1767 1756 $spaceAllowed = 1024 * 1024 * get_space_allowed(); 1768 1757 $dirName = BLOGUPLOADDIR; 1769 1758 $dirsize = get_dirsize($dirName) ; 1770 if ( $size > $spaceAllowed - $dirsize ) {1759 if ( $size > $spaceAllowed - $dirsize ) 1771 1760 return $spaceAllowed - $dirsize; // remaining space 1772 } else {1761 else 1773 1762 return $size; // default 1774 }1775 1763 } 1776 1764 1777 1765 if ( !function_exists('graceful_fail') ) : … … 1815 1803 1816 1804 function admin_footer() { 1817 1805 global $wpdb, $current_blog, $current_site; 1818 if ( $current_blog->domain . $current_blog->path == $current_site->domain . $current_site->path )1806 if ( $current_blog->domain . $current_blog->path == $current_site->domain . $current_site->path ) 1819 1807 return false; 1820 1808 1821 if ( $this->reallydeleteblog == true ) {1809 if ( $this->reallydeleteblog == true ) 1822 1810 wpmu_delete_blog( $wpdb->blogid ); 1823 }1824 1811 } 1825 1812 1826 1813 function admin_menu() { 1827 1814 global $current_blog, $current_site; 1828 if ( $current_blog->domain . $current_blog->path != $current_site->domain . $current_site->path )1815 if ( $current_blog->domain . $current_blog->path != $current_site->domain . $current_site->path ) 1829 1816 add_submenu_page('options-general.php', __('Delete Blog'), __('Delete Blog'), 'manage_options', 'delete-blog', array(&$this, 'plugin_content')); 1830 1817 } 1831 1818 … … 1833 1820 global $current_blog, $current_site; 1834 1821 $this->delete_blog_hash = get_settings('delete_blog_hash'); 1835 1822 echo '<div class="wrap"><h2>' . __('Delete Blog') . '</h2>'; 1836 if ( $_POST['action'] == "deleteblog" && $_POST['confirmdelete'] == '1' ) {1823 if ( $_POST['action'] == "deleteblog" && $_POST['confirmdelete'] == '1' ) { 1837 1824 $hash = substr( md5( $_SERVER['REQUEST_URI'] . time() ), 0, 6 ); 1838 1825 update_option( "delete_blog_hash", $hash ); 1839 1826 $url_delete = get_option( "siteurl" ) . "/wp-admin/options-general.php?page=delete-blog&h=" . $hash; … … 1858 1845 ?> 1859 1846 <p><?php _e('Thank you. Please check your email for a link to confirm your action. Your blog will not be deleted until this link is clicked.') ?></p> 1860 1847 <?php 1861 } elseif ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option('delete_blog_hash') != false ) {1862 if ( get_option('delete_blog_hash') == $_GET['h'] ) {1848 } elseif ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option('delete_blog_hash') != false ) { 1849 if ( get_option('delete_blog_hash') == $_GET['h'] ) { 1863 1850 $this->reallydeleteblog = true; 1864 1851 echo "<p>" . sprintf(__('Thank you for using %s, your blog has been deleted. Happy trails to you until we meet again.'), $current_site->site_name) . "</p>"; 1865 1852 } else { … … 1899 1886 if ( $global_id == $term_id ) 1900 1887 return $global_id; 1901 1888 1902 if ( get_option( 'default_category' ) == $term_id )1889 if ( get_option( 'default_category' ) == $term_id ) 1903 1890 update_option( 'default_category', $global_id ); 1904 1891 1905 1892 $wpdb->update( $wpdb->terms, array('term_id' => $global_id), array('term_id' => $term_id) ); … … 1917 1904 } 1918 1905 1919 1906 function upload_is_file_too_big( $upload ) { 1920 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) )1907 if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) 1921 1908 return $upload; 1922 if( strlen( $upload[ 'bits' ] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) { 1909 1910 if ( strlen( $upload[ 'bits' ] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) 1923 1911 return sprintf(__( "This file is too big. Files must be less than %dKb in size.<br />" ), get_site_option( 'fileupload_maxk', 1500 )); 1924 }1925 1912 1926 1913 return $upload; 1927 1914 } 1928 1915 1929 1916 function wordpressmu_authenticate_siteadmin( $user, $password = '' ) { 1930 if ( is_super_admin( $user->user_login ) == false && ( $primary_blog = get_usermeta( $user->user_id, "primary_blog" ) ) ) {1917 if ( is_super_admin( $user->user_login ) == false && ( $primary_blog = get_usermeta( $user->user_id, "primary_blog" ) ) ) { 1931 1918 $details = get_blog_details( $primary_blog ); 1932 if ( is_object( $details ) && $details->spam == 1 ) {1919 if ( is_object( $details ) && $details->spam == 1 ) 1933 1920 return new WP_Error('blog_suspended', __('Blog Suspended.')); 1934 }1935 1921 } 1936 1922 return $user; 1937 1923 } 1938 1924 1939 1925 function wordpressmu_wp_mail_from( $email ) { 1940 if ( strpos( $email, 'wordpress@' ) !== false )1926 if ( strpos( $email, 'wordpress@' ) !== false ) 1941 1927 $email = get_option( 'admin_email' ); 1942 1928 return $email; 1943 1929 } … … 1946 1932 XMLRPC getUsersBlogs() for a multiblog environment 1947 1933 http://trac.mu.wordpress.org/attachment/ticket/551/xmlrpc-mu.php 1948 1934 */ 1949 function wpmu_blogger_getUsersBlogs( $args) {1935 function wpmu_blogger_getUsersBlogs( $args ) { 1950 1936 global $current_blog; 1951 1937 $domain = $current_blog->domain; 1952 1938 $path = $current_blog->path . 'xmlrpc.php'; … … 1955 1941 $rpc->query('wp.getUsersBlogs', $args[1], $args[2]); 1956 1942 $blogs = $rpc->getResponse(); 1957 1943 1958 if ( isset($blogs['faultCode']) ) {1944 if ( isset($blogs['faultCode']) ) 1959 1945 return new IXR_Error($blogs['faultCode'], $blogs['faultString']); 1960 }1961 1946 1962 1947 if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { 1963 1948 return $blogs; … … 1970 1955 } 1971 1956 } 1972 1957 1973 function attach_wpmu_xmlrpc( $methods) {1958 function attach_wpmu_xmlrpc( $methods ) { 1974 1959 $methods['blogger.getUsersBlogs'] = 'wpmu_blogger_getUsersBlogs'; 1975 1960 return $methods; 1976 1961 } 1977 1962 1978 1963 function mu_locale( $locale ) { 1979 if ( defined('WP_INSTALLING') == false ) {1964 if ( defined('WP_INSTALLING') == false ) { 1980 1965 $mu_locale = get_option('WPLANG'); 1981 if ( $mu_locale === false )1966 if ( $mu_locale === false ) 1982 1967 $mu_locale = get_site_option('WPLANG'); 1983 1968 1984 if ( $mu_locale !== false )1969 if ( $mu_locale !== false ) 1985 1970 return $mu_locale; 1986 1971 } 1987 1972 return $locale; … … 1994 1979 } 1995 1980 1996 1981 function signup_nonce_check( $result ) { 1997 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) )1982 if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) ) 1998 1983 return $result; 1999 1984 2000 1985 if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] ) … … 2005 1990 2006 1991 function maybe_redirect_404() { 2007 1992 global $current_site; 2008 if ( is_main_blog() && is_404() && defined( 'NOBLOGREDIRECT' ) && constant( 'NOBLOGREDIRECT' ) != '' ) {1993 if ( is_main_blog() && is_404() && defined( 'NOBLOGREDIRECT' ) && constant( 'NOBLOGREDIRECT' ) != '' ) { 2009 1994 $destination = constant( 'NOBLOGREDIRECT' ); 2010 1995 if ( $destination == '%siteurl%' ) 2011 1996 $destination = $current_site->domain . $current_site->path; … … 2020 2005 } 2021 2006 2022 2007 function maybe_add_existing_user_to_blog() { 2023 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) {2008 if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) ) 2024 2009 return false; 2025 }2026 2010 2027 2011 $parts = explode( '/', $_SERVER[ 'REQUEST_URI' ] ); 2028 2012 $key = array_pop( $parts ); 2013 2029 2014 if ( $key == '' ) 2030 2015 $key = array_pop( $parts ); 2016 2031 2017 $details = get_option( "new_user_" . $key ); 2032 2018 add_existing_user_to_blog( $details ); 2033 2019 delete_option( 'new_user_' . $key ); … … 2043 2029 2044 2030 function add_new_user_to_blog( $user_id, $email, $meta ) { 2045 2031 global $current_site; 2046 if ( $meta[ 'add_to_blog' ] ) {2032 if ( $meta[ 'add_to_blog' ] ) { 2047 2033 $blog_id = $meta[ 'add_to_blog' ]; 2048 2034 $role = $meta[ 'new_role' ]; 2049 2035 remove_user_from_blog($user_id, $current_site->blogid); // remove user from main blog. … … 2058 2044 } 2059 2045 2060 2046 function is_user_spammy( $username = 0 ) { 2061 if ( $username == 0 ) {2047 if ( $username == 0 ) { 2062 2048 global $current_user; 2063 2049 $user_id = $current_user->ID; 2064 2050 } else { 2065 2051 $user_id = get_user_id_from_string( $username ); 2066 2052 } 2067 2053 $u = new WP_User( $user_id ); 2068 if( $u->spam == 1 ) 2054 2055 if ( $u->spam == 1 ) 2069 2056 return true; 2057 2070 2058 return false; 2071 2059 } 2072 2060 2073 2061 function login_spam_check( $user, $password ) { 2074 if ( is_user_spammy( $user->ID ) )2062 if ( is_user_spammy( $user->ID ) ) 2075 2063 return new WP_Error('invalid_username', __('<strong>ERROR</strong>: your account has been marked as a spammer.')); 2076 2064 return $user; 2077 2065 } … … 2104 2092 function get_dashboard_blog() { 2105 2093 global $current_site; 2106 2094 2107 if ( get_site_option( 'dashboard_blog' ) == false ) {2095 if ( get_site_option( 'dashboard_blog' ) == false ) 2108 2096 return get_blog_details( $current_site->blog_id ); 2109 } else {2097 else 2110 2098 return get_blog_details( get_site_option( 'dashboard_blog' ) ); 2111 }2112 2099 } 2113 2100 2114 2101 function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 2115 2102 global $current_user, $wpdb; 2116 2103 2117 if ( $user_id == 0 )2104 if ( $user_id == 0 ) 2118 2105 $user_id = $current_user->ID; 2119 if ( $blog_id == 0 )2106 if ( $blog_id == 0 ) 2120 2107 $blog_id = $wpdb->blogid; 2121 2108 2122 2109 $local_key = $wpdb->base_prefix . $blog_id . "_" . $key; 2123 if( isset( $current_user->$local_key ) ) 2110 2111 if ( isset( $current_user->$local_key ) ) 2124 2112 return true; 2113 2125 2114 return false; 2126 2115 } 2127 2116 2128 2117 function fix_active_plugins( $value ) { 2129 if ( false == is_array( $value ) )2118 if ( false == is_array( $value ) ) 2130 2119 $value = array(); 2131 2120 return $value; 2132 2121 } … … 2137 2126 global $wpdb; 2138 2127 // Garbage Collection 2139 2128 $rows = $wpdb->get_results( "SELECT meta_key FROM {$wpdb->sitemeta} WHERE meta_key LIKE 'rss\_%\_ts' AND meta_value < unix_timestamp( date_sub( NOW(), interval 7200 second ) )" ); 2140 if ( is_array( $rows ) ) {2129 if ( is_array( $rows ) ) { 2141 2130 foreach( $rows as $row ) { 2142 2131 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s", $row->meta_key ) ); 2143 2132 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s", str_replace( '_ts', '', $row->meta_key ) ) ); … … 2166 2155 2167 2156 function mu_upload_dir( $uploads ) { 2168 2157 $dir = $uploads[ 'basedir' ]; 2169 if ( defined( 'BLOGUPLOADDIR' ) )2158 if ( defined( 'BLOGUPLOADDIR' ) ) 2170 2159 $dir = constant( 'BLOGUPLOADDIR' ); 2171 2160 $dir = untrailingslashit( $dir ) . $uploads[ 'subdir' ]; 2172 2161 $uploads[ 'path' ] = $dir; … … 2177 2166 2178 2167 function users_can_register_signup_filter() { 2179 2168 $registration = get_site_option('registration'); 2180 if ( $registration == 'all' || $registration == 'user' ) {2169 if ( $registration == 'all' || $registration == 'user' ) 2181 2170 return true; 2182 } else {2171 else 2183 2172 return false; 2184 }2185 2173 } 2186 2174 add_filter('option_users_can_register', 'users_can_register_signup_filter'); 2187 2175 … … 2205 2193 add_filter( 'site_option_welcome_user_email', 'welcome_user_msg_filter' ); 2206 2194 2207 2195 function first_page_filter( $text ) { 2208 if ( !$text ) {2196 if ( !$text ) 2209 2197 return __( "This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress." ); 2210 } 2198 2211 2199 return $text; 2212 2200 } 2213 2201 add_filter( 'site_option_first_page', 'first_page_filter' ); 2214 2202 2215 2203 function first_comment_filter( $text ) { 2216 if ( !$text ) {2204 if ( !$text ) 2217 2205 return __( "This is an example of a WordPress comment, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many comments like this one or sub-comments as you like and manage all of your content inside of WordPress." ); 2218 } 2206 2219 2207 return $text; 2220 2208 } 2221 2209 add_filter( 'site_option_first_comment', 'first_comment_filter' ); 2222 2210 2223 2211 function first_comment_author_filter( $text ) { 2224 if ( !$text ) {2212 if ( !$text ) 2225 2213 return __( "Mr WordPress" ); 2226 } 2214 2227 2215 return $text; 2228 2216 } 2229 2217 add_filter( 'site_option_first_comment_author', 'first_comment_author_filter' ); 2230 2218 2231 2219 function first_comment_url_filter( $text ) { 2232 2220 global $current_site; 2233 if ( !$text ) {2221 if ( !$text ) 2234 2222 return 'http://' . $current_site->domain . $current_site->path; 2235 } 2223 2236 2224 return $text; 2237 2225 } 2238 2226 add_filter( 'site_option_first_comment_url', 'first_comment_url_filter' ); … … 2258 2246 * @return bool True if forced, false if not forced. 2259 2247 */ 2260 2248 function force_ssl_content( $force = '' ) { 2261 static $forced_content;2249 static $forced_content; 2262 2250 2263 if ( '' != $force ) {2264 $old_forced = $forced_content;2265 $forced_content = $force;2266 return $old_forced;2267 }2268 return $forced_content;2251 if ( '' != $force ) { 2252 $old_forced = $forced_content; 2253 $forced_content = $force; 2254 return $old_forced; 2255 } 2256 return $forced_content; 2269 2257 } 2270 2258 2271 2259 /** … … 2275 2263 * @since 2.8.5 2276 2264 **/ 2277 2265 function filter_SSL( $url) { 2278 if ( !is_string( $url ) ) {2266 if ( !is_string( $url ) ) 2279 2267 return get_bloginfo( 'url' ); //return home blog url with proper scheme 2280 }2281 2268 2282 2269 $arrURL = parse_url( $url ); 2283 2270 2284 2271 if ( force_ssl_content() && is_ssl() ) { 2285 if ( 'http' === $arrURL['scheme'] && 'https' !== $arrURL['scheme'] ) {2272 if ( 'http' === $arrURL['scheme'] && 'https' !== $arrURL['scheme'] ) 2286 2273 $url = str_replace( $arrURL['scheme'], 'https', $url ); 2287 }2288 2274 } 2289 2275 2290 2276 return $url; 2291 2277 } 2292 2278 2293 2279 function maybe_cancel_post_by_email() { 2294 if ( !defined( 'POST_BY_EMAIL' ) || !POST_BY_EMAIL ) {2280 if ( !defined( 'POST_BY_EMAIL' ) || !POST_BY_EMAIL ) 2295 2281 die( __( 'This action has been disabled by the administrator' ) ); 2296 }2297 2282 } 2298 2283 add_action( 'wp-mail.php', 'maybe_cancel_post_by_email' ); 2299 2284