@@ -1795,7 +1795,7 @@ discard block |
||
| 1795 | 1795 | * |
| 1796 | 1796 | * @param string $table Database table name. |
| 1797 | 1797 | * @param string $index Index name to drop. |
| 1798 | - * @return true True, when finished. |
|
| 1798 | + * @return boolean True, when finished. |
|
| 1799 | 1799 | */ |
| 1800 | 1800 | function drop_index($table, $index) { |
| 1801 | 1801 | global $wpdb; |
@@ -1818,7 +1818,7 @@ discard block |
||
| 1818 | 1818 | * |
| 1819 | 1819 | * @param string $table Database table name. |
| 1820 | 1820 | * @param string $index Database table index column. |
| 1821 | - * @return true True, when done with execution. |
|
| 1821 | + * @return boolean True, when done with execution. |
|
| 1822 | 1822 | */ |
| 1823 | 1823 | function add_clean_index($table, $index) { |
| 1824 | 1824 | global $wpdb; |
@@ -2114,7 +2114,7 @@ |
||
| 2114 | 2114 | global $wpdb; |
| 2115 | 2115 | |
| 2116 | 2116 | if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) |
| 2117 | - $queries = wp_get_db_schema( $queries ); |
|
| 2117 | + $queries = wp_get_db_schema( $queries ); |
|
| 2118 | 2118 | |
| 2119 | 2119 | // Separate individual queries into an array |
| 2120 | 2120 | if ( !is_array($queries) ) { |
@@ -2710,22 +2710,22 @@ |
||
| 2710 | 2710 | */ |
| 2711 | 2711 | function translate_level_to_role($level) { |
| 2712 | 2712 | switch ($level) { |
| 2713 | - case 10: |
|
| 2714 | - case 9: |
|
| 2715 | - case 8: |
|
| 2716 | - return 'administrator'; |
|
| 2717 | - case 7: |
|
| 2718 | - case 6: |
|
| 2719 | - case 5: |
|
| 2720 | - return 'editor'; |
|
| 2721 | - case 4: |
|
| 2722 | - case 3: |
|
| 2723 | - case 2: |
|
| 2724 | - return 'author'; |
|
| 2725 | - case 1: |
|
| 2726 | - return 'contributor'; |
|
| 2727 | - case 0: |
|
| 2728 | - return 'subscriber'; |
|
| 2713 | + case 10: |
|
| 2714 | + case 9: |
|
| 2715 | + case 8: |
|
| 2716 | + return 'administrator'; |
|
| 2717 | + case 7: |
|
| 2718 | + case 6: |
|
| 2719 | + case 5: |
|
| 2720 | + return 'editor'; |
|
| 2721 | + case 4: |
|
| 2722 | + case 3: |
|
| 2723 | + case 2: |
|
| 2724 | + return 'author'; |
|
| 2725 | + case 1: |
|
| 2726 | + return 'contributor'; |
|
| 2727 | + case 0: |
|
| 2728 | + return 'subscriber'; |
|
| 2729 | 2729 | } |
| 2730 | 2730 | } |
| 2731 | 2731 | |
@@ -9,16 +9,16 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | /** Include user install customize script. */ |
| 12 | -if ( file_exists(WP_CONTENT_DIR . '/install.php') ) |
|
| 13 | - require (WP_CONTENT_DIR . '/install.php'); |
|
| 12 | +if (file_exists(WP_CONTENT_DIR.'/install.php')) |
|
| 13 | + require (WP_CONTENT_DIR.'/install.php'); |
|
| 14 | 14 | |
| 15 | 15 | /** WordPress Administration API */ |
| 16 | -require_once(ABSPATH . 'wp-admin/includes/admin.php'); |
|
| 16 | +require_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
| 17 | 17 | |
| 18 | 18 | /** WordPress Schema API */ |
| 19 | -require_once(ABSPATH . 'wp-admin/includes/schema.php'); |
|
| 19 | +require_once(ABSPATH.'wp-admin/includes/schema.php'); |
|
| 20 | 20 | |
| 21 | -if ( !function_exists('wp_install') ) : |
|
| 21 | +if ( ! function_exists('wp_install')) : |
|
| 22 | 22 | /** |
| 23 | 23 | * Installs the site. |
| 24 | 24 | * |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * @param string $language Optional. Language chosen. Default empty. |
| 37 | 37 | * @return array Array keys 'url', 'user_id', 'password', and 'password_message'. |
| 38 | 38 | */ |
| 39 | -function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { |
|
| 40 | - if ( !empty( $deprecated ) ) |
|
| 41 | - _deprecated_argument( __FUNCTION__, '2.6.0' ); |
|
| 39 | +function wp_install($blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '') { |
|
| 40 | + if ( ! empty($deprecated)) |
|
| 41 | + _deprecated_argument(__FUNCTION__, '2.6.0'); |
|
| 42 | 42 | |
| 43 | 43 | wp_check_mysql_version(); |
| 44 | 44 | wp_cache_flush(); |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | update_option('blog_public', $public); |
| 52 | 52 | |
| 53 | 53 | // Freshness of site - in the future, this could get more specific about actions taken, perhaps. |
| 54 | - update_option( 'fresh_site', 1 ); |
|
| 54 | + update_option('fresh_site', 1); |
|
| 55 | 55 | |
| 56 | - if ( $language ) { |
|
| 57 | - update_option( 'WPLANG', $language ); |
|
| 56 | + if ($language) { |
|
| 57 | + update_option('WPLANG', $language); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $guessurl = wp_guess_url(); |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | update_option('siteurl', $guessurl); |
| 63 | 63 | |
| 64 | 64 | // If not a public blog, don't ping. |
| 65 | - if ( ! $public ) |
|
| 65 | + if ( ! $public) |
|
| 66 | 66 | update_option('default_pingback_flag', 0); |
| 67 | 67 | |
| 68 | 68 | /* |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | $user_id = username_exists($user_name); |
| 73 | 73 | $user_password = trim($user_password); |
| 74 | 74 | $email_password = false; |
| 75 | - if ( !$user_id && empty($user_password) ) { |
|
| 76 | - $user_password = wp_generate_password( 12, false ); |
|
| 75 | + if ( ! $user_id && empty($user_password)) { |
|
| 76 | + $user_password = wp_generate_password(12, false); |
|
| 77 | 77 | $message = __('<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.'); |
| 78 | 78 | $user_id = wp_create_user($user_name, $user_password, $user_email); |
| 79 | 79 | update_user_option($user_id, 'default_password_nag', true, true); |
| 80 | 80 | $email_password = true; |
| 81 | - } elseif ( ! $user_id ) { |
|
| 81 | + } elseif ( ! $user_id) { |
|
| 82 | 82 | // Password has been provided |
| 83 | 83 | $message = '<em>'.__('Your chosen password.').'</em>'; |
| 84 | 84 | $user_id = wp_create_user($user_name, $user_password, $user_email); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | flush_rewrite_rules(); |
| 97 | 97 | |
| 98 | - wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.') ) ); |
|
| 98 | + wp_new_blog_notification($blog_title, $guessurl, $user_id, ($email_password ? $user_password : __('The password you chose during the install.'))); |
|
| 99 | 99 | |
| 100 | 100 | wp_cache_flush(); |
| 101 | 101 | |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @param WP_User $user The site owner. |
| 108 | 108 | */ |
| 109 | - do_action( 'wp_install', $user ); |
|
| 109 | + do_action('wp_install', $user); |
|
| 110 | 110 | |
| 111 | 111 | return array('url' => $guessurl, 'user_id' => $user_id, 'password' => $user_password, 'password_message' => $message); |
| 112 | 112 | } |
| 113 | 113 | endif; |
| 114 | 114 | |
| 115 | -if ( !function_exists('wp_install_defaults') ) : |
|
| 115 | +if ( ! function_exists('wp_install_defaults')) : |
|
| 116 | 116 | /** |
| 117 | 117 | * Creates the initial content for a newly-installed site. |
| 118 | 118 | * |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @param int $user_id User ID. |
| 129 | 129 | */ |
| 130 | -function wp_install_defaults( $user_id ) { |
|
| 130 | +function wp_install_defaults($user_id) { |
|
| 131 | 131 | global $wpdb, $wp_rewrite, $table_prefix; |
| 132 | 132 | |
| 133 | 133 | // Default category |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | /* translators: Default category slug */ |
| 136 | 136 | $cat_slug = sanitize_title(_x('Uncategorized', 'Default category slug')); |
| 137 | 137 | |
| 138 | - if ( global_terms_enabled() ) { |
|
| 139 | - $cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug ) ); |
|
| 140 | - if ( $cat_id == null ) { |
|
| 141 | - $wpdb->insert( $wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true)) ); |
|
| 138 | + if (global_terms_enabled()) { |
|
| 139 | + $cat_id = $wpdb->get_var($wpdb->prepare("SELECT cat_ID FROM {$wpdb->sitecategories} WHERE category_nicename = %s", $cat_slug)); |
|
| 140 | + if ($cat_id == null) { |
|
| 141 | + $wpdb->insert($wpdb->sitecategories, array('cat_ID' => 0, 'cat_name' => $cat_name, 'category_nicename' => $cat_slug, 'last_updated' => current_time('mysql', true))); |
|
| 142 | 142 | $cat_id = $wpdb->insert_id; |
| 143 | 143 | } |
| 144 | 144 | update_option('default_category', $cat_id); |
@@ -146,35 +146,35 @@ discard block |
||
| 146 | 146 | $cat_id = 1; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $wpdb->insert( $wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) ); |
|
| 150 | - $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1)); |
|
| 149 | + $wpdb->insert($wpdb->terms, array('term_id' => $cat_id, 'name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0)); |
|
| 150 | + $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1)); |
|
| 151 | 151 | $cat_tt_id = $wpdb->insert_id; |
| 152 | 152 | |
| 153 | 153 | // First post |
| 154 | - $now = current_time( 'mysql' ); |
|
| 155 | - $now_gmt = current_time( 'mysql', 1 ); |
|
| 156 | - $first_post_guid = get_option( 'home' ) . '/?p=1'; |
|
| 154 | + $now = current_time('mysql'); |
|
| 155 | + $now_gmt = current_time('mysql', 1); |
|
| 156 | + $first_post_guid = get_option('home').'/?p=1'; |
|
| 157 | 157 | |
| 158 | - if ( is_multisite() ) { |
|
| 159 | - $first_post = get_site_option( 'first_post' ); |
|
| 158 | + if (is_multisite()) { |
|
| 159 | + $first_post = get_site_option('first_post'); |
|
| 160 | 160 | |
| 161 | - if ( ! $first_post ) { |
|
| 161 | + if ( ! $first_post) { |
|
| 162 | 162 | /* translators: %s: site link */ |
| 163 | - $first_post = __( 'Welcome to %s. This is your first post. Edit or delete it, then start blogging!' ); |
|
| 163 | + $first_post = __('Welcome to %s. This is your first post. Edit or delete it, then start blogging!'); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $first_post = sprintf( $first_post, |
|
| 167 | - sprintf( '<a href="%s">%s</a>', esc_url( network_home_url() ), get_network()->site_name ) |
|
| 166 | + $first_post = sprintf($first_post, |
|
| 167 | + sprintf('<a href="%s">%s</a>', esc_url(network_home_url()), get_network()->site_name) |
|
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | 170 | // Back-compat for pre-4.4 |
| 171 | - $first_post = str_replace( 'SITE_URL', esc_url( network_home_url() ), $first_post ); |
|
| 172 | - $first_post = str_replace( 'SITE_NAME', get_network()->site_name, $first_post ); |
|
| 171 | + $first_post = str_replace('SITE_URL', esc_url(network_home_url()), $first_post); |
|
| 172 | + $first_post = str_replace('SITE_NAME', get_network()->site_name, $first_post); |
|
| 173 | 173 | } else { |
| 174 | - $first_post = __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!' ); |
|
| 174 | + $first_post = __('Welcome to WordPress. This is your first post. Edit or delete it, then start writing!'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $wpdb->insert( $wpdb->posts, array( |
|
| 177 | + $wpdb->insert($wpdb->posts, array( |
|
| 178 | 178 | 'post_author' => $user_id, |
| 179 | 179 | 'post_date' => $now, |
| 180 | 180 | 'post_date_gmt' => $now_gmt, |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | 'post_excerpt' => '', |
| 183 | 183 | 'post_title' => __('Hello world!'), |
| 184 | 184 | /* translators: Default post slug */ |
| 185 | - 'post_name' => sanitize_title( _x('hello-world', 'Default post slug') ), |
|
| 185 | + 'post_name' => sanitize_title(_x('hello-world', 'Default post slug')), |
|
| 186 | 186 | 'post_modified' => $now, |
| 187 | 187 | 'post_modified_gmt' => $now_gmt, |
| 188 | 188 | 'guid' => $first_post_guid, |
@@ -191,23 +191,23 @@ discard block |
||
| 191 | 191 | 'pinged' => '', |
| 192 | 192 | 'post_content_filtered' => '' |
| 193 | 193 | )); |
| 194 | - $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) ); |
|
| 194 | + $wpdb->insert($wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1)); |
|
| 195 | 195 | |
| 196 | 196 | // Default comment |
| 197 | - if ( is_multisite() ) { |
|
| 198 | - $first_comment_author = get_site_option( 'first_comment_author' ); |
|
| 199 | - $first_comment_email = get_site_option( 'first_comment_email' ); |
|
| 200 | - $first_comment_url = get_site_option( 'first_comment_url', network_home_url() ); |
|
| 201 | - $first_comment = get_site_option( 'first_comment' ); |
|
| 197 | + if (is_multisite()) { |
|
| 198 | + $first_comment_author = get_site_option('first_comment_author'); |
|
| 199 | + $first_comment_email = get_site_option('first_comment_email'); |
|
| 200 | + $first_comment_url = get_site_option('first_comment_url', network_home_url()); |
|
| 201 | + $first_comment = get_site_option('first_comment'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - $first_comment_author = ! empty( $first_comment_author ) ? $first_comment_author : __( 'A WordPress Commenter' ); |
|
| 205 | - $first_comment_email = ! empty( $first_comment_email ) ? $first_comment_email : '[email protected]'; |
|
| 206 | - $first_comment_url = ! empty( $first_comment_url ) ? $first_comment_url : 'https://wordpress.org/'; |
|
| 207 | - $first_comment = ! empty( $first_comment ) ? $first_comment : __( 'Hi, this is a comment. |
|
| 204 | + $first_comment_author = ! empty($first_comment_author) ? $first_comment_author : __('A WordPress Commenter'); |
|
| 205 | + $first_comment_email = ! empty($first_comment_email) ? $first_comment_email : '[email protected]'; |
|
| 206 | + $first_comment_url = ! empty($first_comment_url) ? $first_comment_url : 'https://wordpress.org/'; |
|
| 207 | + $first_comment = ! empty($first_comment) ? $first_comment : __('Hi, this is a comment. |
|
| 208 | 208 | To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard. |
| 209 | 209 | Commenter avatars come from <a href="https://gravatar.com">Gravatar</a>.' ); |
| 210 | - $wpdb->insert( $wpdb->comments, array( |
|
| 210 | + $wpdb->insert($wpdb->comments, array( |
|
| 211 | 211 | 'comment_post_ID' => 1, |
| 212 | 212 | 'comment_author' => $first_comment_author, |
| 213 | 213 | 'comment_author_email' => $first_comment_email, |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | )); |
| 219 | 219 | |
| 220 | 220 | // First Page |
| 221 | - if ( is_multisite() ) |
|
| 222 | - $first_page = get_site_option( 'first_page' ); |
|
| 221 | + if (is_multisite()) |
|
| 222 | + $first_page = get_site_option('first_page'); |
|
| 223 | 223 | |
| 224 | - $first_page = ! empty( $first_page ) ? $first_page : sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this: |
|
| 224 | + $first_page = ! empty($first_page) ? $first_page : sprintf(__("This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this: |
|
| 225 | 225 | |
| 226 | 226 | <blockquote>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)</blockquote> |
| 227 | 227 | |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | <blockquote>The XYZ Doohickey Company was founded in 1971, and has been providing quality doohickeys to the public ever since. Located in Gotham City, XYZ employs over 2,000 people and does all kinds of awesome things for the Gotham community.</blockquote> |
| 231 | 231 | |
| 232 | -As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() ); |
|
| 232 | +As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url()); |
|
| 233 | 233 | |
| 234 | - $first_post_guid = get_option('home') . '/?page_id=2'; |
|
| 235 | - $wpdb->insert( $wpdb->posts, array( |
|
| 234 | + $first_post_guid = get_option('home').'/?page_id=2'; |
|
| 235 | + $wpdb->insert($wpdb->posts, array( |
|
| 236 | 236 | 'post_author' => $user_id, |
| 237 | 237 | 'post_date' => $now, |
| 238 | 238 | 'post_date_gmt' => $now_gmt, |
| 239 | 239 | 'post_content' => $first_page, |
| 240 | 240 | 'post_excerpt' => '', |
| 241 | 241 | 'comment_status' => 'closed', |
| 242 | - 'post_title' => __( 'Sample Page' ), |
|
| 242 | + 'post_title' => __('Sample Page'), |
|
| 243 | 243 | /* translators: Default page slug */ |
| 244 | - 'post_name' => __( 'sample-page' ), |
|
| 244 | + 'post_name' => __('sample-page'), |
|
| 245 | 245 | 'post_modified' => $now, |
| 246 | 246 | 'post_modified_gmt' => $now_gmt, |
| 247 | 247 | 'guid' => $first_post_guid, |
@@ -250,36 +250,36 @@ discard block |
||
| 250 | 250 | 'pinged' => '', |
| 251 | 251 | 'post_content_filtered' => '' |
| 252 | 252 | )); |
| 253 | - $wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) ); |
|
| 253 | + $wpdb->insert($wpdb->postmeta, array('post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default')); |
|
| 254 | 254 | |
| 255 | 255 | // Set up default widgets for default theme. |
| 256 | - update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); |
|
| 257 | - update_option( 'widget_recent-posts', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) ); |
|
| 258 | - update_option( 'widget_recent-comments', array ( 2 => array ( 'title' => '', 'number' => 5 ), '_multiwidget' => 1 ) ); |
|
| 259 | - update_option( 'widget_archives', array ( 2 => array ( 'title' => '', 'count' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); |
|
| 260 | - update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); |
|
| 261 | - update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); |
|
| 262 | - update_option( 'sidebars_widgets', array( 'wp_inactive_widgets' => array(), 'sidebar-1' => array( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2' ), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3 ) ); |
|
| 263 | - if ( ! is_multisite() ) |
|
| 264 | - update_user_meta( $user_id, 'show_welcome_panel', 1 ); |
|
| 265 | - elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) |
|
| 266 | - update_user_meta( $user_id, 'show_welcome_panel', 2 ); |
|
| 267 | - |
|
| 268 | - if ( is_multisite() ) { |
|
| 256 | + update_option('widget_search', array(2 => array('title' => ''), '_multiwidget' => 1)); |
|
| 257 | + update_option('widget_recent-posts', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1)); |
|
| 258 | + update_option('widget_recent-comments', array(2 => array('title' => '', 'number' => 5), '_multiwidget' => 1)); |
|
| 259 | + update_option('widget_archives', array(2 => array('title' => '', 'count' => 0, 'dropdown' => 0), '_multiwidget' => 1)); |
|
| 260 | + update_option('widget_categories', array(2 => array('title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0), '_multiwidget' => 1)); |
|
| 261 | + update_option('widget_meta', array(2 => array('title' => ''), '_multiwidget' => 1)); |
|
| 262 | + update_option('sidebars_widgets', array('wp_inactive_widgets' => array(), 'sidebar-1' => array(0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2'), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3)); |
|
| 263 | + if ( ! is_multisite()) |
|
| 264 | + update_user_meta($user_id, 'show_welcome_panel', 1); |
|
| 265 | + elseif ( ! is_super_admin($user_id) && ! metadata_exists('user', $user_id, 'show_welcome_panel')) |
|
| 266 | + update_user_meta($user_id, 'show_welcome_panel', 2); |
|
| 267 | + |
|
| 268 | + if (is_multisite()) { |
|
| 269 | 269 | // Flush rules to pick up the new page. |
| 270 | 270 | $wp_rewrite->init(); |
| 271 | 271 | $wp_rewrite->flush_rules(); |
| 272 | 272 | |
| 273 | 273 | $user = new WP_User($user_id); |
| 274 | - $wpdb->update( $wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email') ); |
|
| 274 | + $wpdb->update($wpdb->options, array('option_value' => $user->user_email), array('option_name' => 'admin_email')); |
|
| 275 | 275 | |
| 276 | 276 | // Remove all perms except for the login user. |
| 277 | - $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level') ); |
|
| 278 | - $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') ); |
|
| 277 | + $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'user_level')); |
|
| 278 | + $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities')); |
|
| 279 | 279 | |
| 280 | 280 | // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id. |
| 281 | - if ( !is_super_admin( $user_id ) && $user_id != 1 ) |
|
| 282 | - $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) ); |
|
| 281 | + if ( ! is_super_admin($user_id) && $user_id != 1) |
|
| 282 | + $wpdb->delete($wpdb->usermeta, array('user_id' => $user_id, 'meta_key' => $wpdb->base_prefix.'1_capabilities')); |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | endif; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | global $wp_rewrite; |
| 300 | 300 | |
| 301 | 301 | // Bail if a permalink structure is already enabled. |
| 302 | - if ( get_option( 'permalink_structure' ) ) { |
|
| 302 | + if (get_option('permalink_structure')) { |
|
| 303 | 303 | return true; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -316,21 +316,21 @@ discard block |
||
| 316 | 316 | '/index.php/%year%/%monthnum%/%day%/%postname%/' |
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | - foreach ( (array) $permalink_structures as $permalink_structure ) { |
|
| 320 | - $wp_rewrite->set_permalink_structure( $permalink_structure ); |
|
| 319 | + foreach ((array) $permalink_structures as $permalink_structure) { |
|
| 320 | + $wp_rewrite->set_permalink_structure($permalink_structure); |
|
| 321 | 321 | |
| 322 | 322 | /* |
| 323 | 323 | * Flush rules with the hard option to force refresh of the web-server's |
| 324 | 324 | * rewrite config file (e.g. .htaccess or web.config). |
| 325 | 325 | */ |
| 326 | - $wp_rewrite->flush_rules( true ); |
|
| 326 | + $wp_rewrite->flush_rules(true); |
|
| 327 | 327 | |
| 328 | 328 | $test_url = ''; |
| 329 | 329 | |
| 330 | 330 | // Test against a real WordPress Post |
| 331 | - $first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' ); |
|
| 332 | - if ( $first_post ) { |
|
| 333 | - $test_url = get_permalink( $first_post->ID ); |
|
| 331 | + $first_post = get_page_by_path(sanitize_title(_x('hello-world', 'Default post slug')), OBJECT, 'post'); |
|
| 332 | + if ($first_post) { |
|
| 333 | + $test_url = get_permalink($first_post->ID); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /* |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | * Uses wp_remote_get() instead of wp_remote_head() because web servers |
| 341 | 341 | * can block head requests. |
| 342 | 342 | */ |
| 343 | - $response = wp_remote_get( $test_url, array( 'timeout' => 5 ) ); |
|
| 344 | - $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' ); |
|
| 345 | - $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' ); |
|
| 343 | + $response = wp_remote_get($test_url, array('timeout' => 5)); |
|
| 344 | + $x_pingback_header = wp_remote_retrieve_header($response, 'x-pingback'); |
|
| 345 | + $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo('pingback_url'); |
|
| 346 | 346 | |
| 347 | - if ( $pretty_permalinks ) { |
|
| 347 | + if ($pretty_permalinks) { |
|
| 348 | 348 | return true; |
| 349 | 349 | } |
| 350 | 350 | } |
@@ -353,13 +353,13 @@ discard block |
||
| 353 | 353 | * If it makes it this far, pretty permalinks failed. |
| 354 | 354 | * Fallback to query-string permalinks. |
| 355 | 355 | */ |
| 356 | - $wp_rewrite->set_permalink_structure( '' ); |
|
| 357 | - $wp_rewrite->flush_rules( true ); |
|
| 356 | + $wp_rewrite->set_permalink_structure(''); |
|
| 357 | + $wp_rewrite->flush_rules(true); |
|
| 358 | 358 | |
| 359 | 359 | return false; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | -if ( !function_exists('wp_new_blog_notification') ) : |
|
| 362 | +if ( ! function_exists('wp_new_blog_notification')) : |
|
| 363 | 363 | /** |
| 364 | 364 | * Notifies the site admin that the setup is complete. |
| 365 | 365 | * |
@@ -374,12 +374,12 @@ discard block |
||
| 374 | 374 | * @param string $password User's Password. |
| 375 | 375 | */ |
| 376 | 376 | function wp_new_blog_notification($blog_title, $blog_url, $user_id, $password) { |
| 377 | - $user = new WP_User( $user_id ); |
|
| 377 | + $user = new WP_User($user_id); |
|
| 378 | 378 | $email = $user->user_email; |
| 379 | 379 | $name = $user->user_login; |
| 380 | 380 | $login_url = wp_login_url(); |
| 381 | 381 | /* translators: New site notification email. 1: New site URL, 2: User login, 3: User password or password reset link, 4: Login URL */ |
| 382 | - $message = sprintf( __( "Your new WordPress site has been successfully set up at: |
|
| 382 | + $message = sprintf(__("Your new WordPress site has been successfully set up at: |
|
| 383 | 383 | |
| 384 | 384 | %1\$s |
| 385 | 385 | |
@@ -393,13 +393,13 @@ discard block |
||
| 393 | 393 | |
| 394 | 394 | --The WordPress Team |
| 395 | 395 | https://wordpress.org/ |
| 396 | -"), $blog_url, $name, $password, $login_url ); |
|
| 396 | +"), $blog_url, $name, $password, $login_url); |
|
| 397 | 397 | |
| 398 | 398 | @wp_mail($email, __('New WordPress Site'), $message); |
| 399 | 399 | } |
| 400 | 400 | endif; |
| 401 | 401 | |
| 402 | -if ( !function_exists('wp_upgrade') ) : |
|
| 402 | +if ( ! function_exists('wp_upgrade')) : |
|
| 403 | 403 | /** |
| 404 | 404 | * Runs WordPress Upgrade functions. |
| 405 | 405 | * |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | $wp_current_db_version = __get_option('db_version'); |
| 418 | 418 | |
| 419 | 419 | // We are up-to-date. Nothing to do. |
| 420 | - if ( $wp_db_version == $wp_current_db_version ) |
|
| 420 | + if ($wp_db_version == $wp_current_db_version) |
|
| 421 | 421 | return; |
| 422 | 422 | |
| 423 | - if ( ! is_blog_installed() ) |
|
| 423 | + if ( ! is_blog_installed()) |
|
| 424 | 424 | return; |
| 425 | 425 | |
| 426 | 426 | wp_check_mysql_version(); |
@@ -428,15 +428,15 @@ discard block |
||
| 428 | 428 | pre_schema_upgrade(); |
| 429 | 429 | make_db_current_silent(); |
| 430 | 430 | upgrade_all(); |
| 431 | - if ( is_multisite() && is_main_site() ) |
|
| 431 | + if (is_multisite() && is_main_site()) |
|
| 432 | 432 | upgrade_network(); |
| 433 | 433 | wp_cache_flush(); |
| 434 | 434 | |
| 435 | - if ( is_multisite() ) { |
|
| 436 | - if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) |
|
| 437 | - $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); |
|
| 435 | + if (is_multisite()) { |
|
| 436 | + if ($wpdb->get_row("SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'")) |
|
| 437 | + $wpdb->query("UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'"); |
|
| 438 | 438 | else |
| 439 | - $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); |
|
| 439 | + $wpdb->query("INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());"); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @param int $wp_db_version The new $wp_db_version. |
| 448 | 448 | * @param int $wp_current_db_version The old (current) $wp_db_version. |
| 449 | 449 | */ |
| 450 | - do_action( 'wp_upgrade', $wp_db_version, $wp_current_db_version ); |
|
| 450 | + do_action('wp_upgrade', $wp_db_version, $wp_current_db_version); |
|
| 451 | 451 | } |
| 452 | 452 | endif; |
| 453 | 453 | |
@@ -468,109 +468,109 @@ discard block |
||
| 468 | 468 | $wp_current_db_version = __get_option('db_version'); |
| 469 | 469 | |
| 470 | 470 | // We are up-to-date. Nothing to do. |
| 471 | - if ( $wp_db_version == $wp_current_db_version ) |
|
| 471 | + if ($wp_db_version == $wp_current_db_version) |
|
| 472 | 472 | return; |
| 473 | 473 | |
| 474 | 474 | // If the version is not set in the DB, try to guess the version. |
| 475 | - if ( empty($wp_current_db_version) ) { |
|
| 475 | + if (empty($wp_current_db_version)) { |
|
| 476 | 476 | $wp_current_db_version = 0; |
| 477 | 477 | |
| 478 | 478 | // If the template option exists, we have 1.5. |
| 479 | 479 | $template = __get_option('template'); |
| 480 | - if ( !empty($template) ) |
|
| 480 | + if ( ! empty($template)) |
|
| 481 | 481 | $wp_current_db_version = 2541; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - if ( $wp_current_db_version < 6039 ) |
|
| 484 | + if ($wp_current_db_version < 6039) |
|
| 485 | 485 | upgrade_230_options_table(); |
| 486 | 486 | |
| 487 | 487 | populate_options(); |
| 488 | 488 | |
| 489 | - if ( $wp_current_db_version < 2541 ) { |
|
| 489 | + if ($wp_current_db_version < 2541) { |
|
| 490 | 490 | upgrade_100(); |
| 491 | 491 | upgrade_101(); |
| 492 | 492 | upgrade_110(); |
| 493 | 493 | upgrade_130(); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - if ( $wp_current_db_version < 3308 ) |
|
| 496 | + if ($wp_current_db_version < 3308) |
|
| 497 | 497 | upgrade_160(); |
| 498 | 498 | |
| 499 | - if ( $wp_current_db_version < 4772 ) |
|
| 499 | + if ($wp_current_db_version < 4772) |
|
| 500 | 500 | upgrade_210(); |
| 501 | 501 | |
| 502 | - if ( $wp_current_db_version < 4351 ) |
|
| 502 | + if ($wp_current_db_version < 4351) |
|
| 503 | 503 | upgrade_old_slugs(); |
| 504 | 504 | |
| 505 | - if ( $wp_current_db_version < 5539 ) |
|
| 505 | + if ($wp_current_db_version < 5539) |
|
| 506 | 506 | upgrade_230(); |
| 507 | 507 | |
| 508 | - if ( $wp_current_db_version < 6124 ) |
|
| 508 | + if ($wp_current_db_version < 6124) |
|
| 509 | 509 | upgrade_230_old_tables(); |
| 510 | 510 | |
| 511 | - if ( $wp_current_db_version < 7499 ) |
|
| 511 | + if ($wp_current_db_version < 7499) |
|
| 512 | 512 | upgrade_250(); |
| 513 | 513 | |
| 514 | - if ( $wp_current_db_version < 7935 ) |
|
| 514 | + if ($wp_current_db_version < 7935) |
|
| 515 | 515 | upgrade_252(); |
| 516 | 516 | |
| 517 | - if ( $wp_current_db_version < 8201 ) |
|
| 517 | + if ($wp_current_db_version < 8201) |
|
| 518 | 518 | upgrade_260(); |
| 519 | 519 | |
| 520 | - if ( $wp_current_db_version < 8989 ) |
|
| 520 | + if ($wp_current_db_version < 8989) |
|
| 521 | 521 | upgrade_270(); |
| 522 | 522 | |
| 523 | - if ( $wp_current_db_version < 10360 ) |
|
| 523 | + if ($wp_current_db_version < 10360) |
|
| 524 | 524 | upgrade_280(); |
| 525 | 525 | |
| 526 | - if ( $wp_current_db_version < 11958 ) |
|
| 526 | + if ($wp_current_db_version < 11958) |
|
| 527 | 527 | upgrade_290(); |
| 528 | 528 | |
| 529 | - if ( $wp_current_db_version < 15260 ) |
|
| 529 | + if ($wp_current_db_version < 15260) |
|
| 530 | 530 | upgrade_300(); |
| 531 | 531 | |
| 532 | - if ( $wp_current_db_version < 19389 ) |
|
| 532 | + if ($wp_current_db_version < 19389) |
|
| 533 | 533 | upgrade_330(); |
| 534 | 534 | |
| 535 | - if ( $wp_current_db_version < 20080 ) |
|
| 535 | + if ($wp_current_db_version < 20080) |
|
| 536 | 536 | upgrade_340(); |
| 537 | 537 | |
| 538 | - if ( $wp_current_db_version < 22422 ) |
|
| 538 | + if ($wp_current_db_version < 22422) |
|
| 539 | 539 | upgrade_350(); |
| 540 | 540 | |
| 541 | - if ( $wp_current_db_version < 25824 ) |
|
| 541 | + if ($wp_current_db_version < 25824) |
|
| 542 | 542 | upgrade_370(); |
| 543 | 543 | |
| 544 | - if ( $wp_current_db_version < 26148 ) |
|
| 544 | + if ($wp_current_db_version < 26148) |
|
| 545 | 545 | upgrade_372(); |
| 546 | 546 | |
| 547 | - if ( $wp_current_db_version < 26691 ) |
|
| 547 | + if ($wp_current_db_version < 26691) |
|
| 548 | 548 | upgrade_380(); |
| 549 | 549 | |
| 550 | - if ( $wp_current_db_version < 29630 ) |
|
| 550 | + if ($wp_current_db_version < 29630) |
|
| 551 | 551 | upgrade_400(); |
| 552 | 552 | |
| 553 | - if ( $wp_current_db_version < 33055 ) |
|
| 553 | + if ($wp_current_db_version < 33055) |
|
| 554 | 554 | upgrade_430(); |
| 555 | 555 | |
| 556 | - if ( $wp_current_db_version < 33056 ) |
|
| 556 | + if ($wp_current_db_version < 33056) |
|
| 557 | 557 | upgrade_431(); |
| 558 | 558 | |
| 559 | - if ( $wp_current_db_version < 35700 ) |
|
| 559 | + if ($wp_current_db_version < 35700) |
|
| 560 | 560 | upgrade_440(); |
| 561 | 561 | |
| 562 | - if ( $wp_current_db_version < 36686 ) |
|
| 562 | + if ($wp_current_db_version < 36686) |
|
| 563 | 563 | upgrade_450(); |
| 564 | 564 | |
| 565 | - if ( $wp_current_db_version < 37965 ) |
|
| 565 | + if ($wp_current_db_version < 37965) |
|
| 566 | 566 | upgrade_460(); |
| 567 | 567 | |
| 568 | 568 | maybe_disable_link_manager(); |
| 569 | 569 | |
| 570 | 570 | maybe_disable_automattic_widgets(); |
| 571 | 571 | |
| 572 | - update_option( 'db_version', $wp_db_version ); |
|
| 573 | - update_option( 'db_upgraded', true ); |
|
| 572 | + update_option('db_version', $wp_db_version); |
|
| 573 | + update_option('db_upgraded', true); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | foreach ($posts as $post) { |
| 591 | 591 | if ('' == $post->post_name) { |
| 592 | 592 | $newtitle = sanitize_title($post->post_title); |
| 593 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) ); |
|
| 593 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID)); |
|
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | } |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | foreach ($categories as $category) { |
| 600 | 600 | if ('' == $category->category_nicename) { |
| 601 | 601 | $newtitle = sanitize_title($category->cat_name); |
| 602 | - $wpdb->update( $wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID) ); |
|
| 602 | + $wpdb->update($wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID)); |
|
| 603 | 603 | } |
| 604 | 604 | } |
| 605 | 605 | |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | SET option_value = REPLACE(option_value, 'wp-links/links-images/', 'wp-images/links/') |
| 608 | 608 | WHERE option_name LIKE %s |
| 609 | 609 | AND option_value LIKE %s"; |
| 610 | - $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( 'links_rating_image' ) . '%', $wpdb->esc_like( 'wp-links/links-images/' ) . '%' ) ); |
|
| 610 | + $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('links_rating_image').'%', $wpdb->esc_like('wp-links/links-images/').'%')); |
|
| 611 | 611 | |
| 612 | 612 | $done_ids = $wpdb->get_results("SELECT DISTINCT post_id FROM $wpdb->post2cat"); |
| 613 | 613 | if ($done_ids) : |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | foreach ($done_ids as $done_id) : |
| 616 | 616 | $done_posts[] = $done_id->post_id; |
| 617 | 617 | endforeach; |
| 618 | - $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')'; |
|
| 618 | + $catwhere = ' AND ID NOT IN ('.implode(',', $done_posts).')'; |
|
| 619 | 619 | else: |
| 620 | 620 | $catwhere = ''; |
| 621 | 621 | endif; |
@@ -624,9 +624,9 @@ discard block |
||
| 624 | 624 | if ($allposts) : |
| 625 | 625 | foreach ($allposts as $post) { |
| 626 | 626 | // Check to see if it's already been imported |
| 627 | - $cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) ); |
|
| 628 | - if (!$cat && 0 != $post->post_category) { // If there's no result |
|
| 629 | - $wpdb->insert( $wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category) ); |
|
| 627 | + $cat = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category)); |
|
| 628 | + if ( ! $cat && 0 != $post->post_category) { // If there's no result |
|
| 629 | + $wpdb->insert($wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category)); |
|
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | endif; |
@@ -649,8 +649,8 @@ discard block |
||
| 649 | 649 | add_clean_index($wpdb->categories, 'category_nicename'); |
| 650 | 650 | add_clean_index($wpdb->comments, 'comment_approved'); |
| 651 | 651 | add_clean_index($wpdb->comments, 'comment_post_ID'); |
| 652 | - add_clean_index($wpdb->links , 'link_category'); |
|
| 653 | - add_clean_index($wpdb->links , 'link_visible'); |
|
| 652 | + add_clean_index($wpdb->links, 'link_category'); |
|
| 653 | + add_clean_index($wpdb->links, 'link_visible'); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -669,14 +669,14 @@ discard block |
||
| 669 | 669 | foreach ($users as $user) { |
| 670 | 670 | if ('' == $user->user_nicename) { |
| 671 | 671 | $newname = sanitize_title($user->user_nickname); |
| 672 | - $wpdb->update( $wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID) ); |
|
| 672 | + $wpdb->update($wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID)); |
|
| 673 | 673 | } |
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | $users = $wpdb->get_results("SELECT ID, user_pass from $wpdb->users"); |
| 677 | 677 | foreach ($users as $row) { |
| 678 | - if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) { |
|
| 679 | - $wpdb->update( $wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID) ); |
|
| 678 | + if ( ! preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) { |
|
| 679 | + $wpdb->update($wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID)); |
|
| 680 | 680 | } |
| 681 | 681 | } |
| 682 | 682 | |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | $time_difference = $all_options->time_difference; |
| 687 | 687 | |
| 688 | - $server_time = time()+date('Z'); |
|
| 688 | + $server_time = time() + date('Z'); |
|
| 689 | 689 | $weblogger_time = $server_time + $time_difference * HOUR_IN_SECONDS; |
| 690 | 690 | $gmt_time = time(); |
| 691 | 691 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | // <michel_v> I just slapped myself silly for not thinking about it earlier |
| 703 | 703 | $got_gmt_fields = ! ($wpdb->get_var("SELECT MAX(post_date_gmt) FROM $wpdb->posts") == '0000-00-00 00:00:00'); |
| 704 | 704 | |
| 705 | - if (!$got_gmt_fields) { |
|
| 705 | + if ( ! $got_gmt_fields) { |
|
| 706 | 706 | |
| 707 | 707 | // Add or subtract time to all dates, to get GMT dates |
| 708 | 708 | $add_hours = intval($diff_gmt_weblogger); |
@@ -734,12 +734,12 @@ discard block |
||
| 734 | 734 | $post_content = addslashes(deslash($post->post_content)); |
| 735 | 735 | $post_title = addslashes(deslash($post->post_title)); |
| 736 | 736 | $post_excerpt = addslashes(deslash($post->post_excerpt)); |
| 737 | - if ( empty($post->guid) ) |
|
| 737 | + if (empty($post->guid)) |
|
| 738 | 738 | $guid = get_permalink($post->ID); |
| 739 | 739 | else |
| 740 | 740 | $guid = $post->guid; |
| 741 | 741 | |
| 742 | - $wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) ); |
|
| 742 | + $wpdb->update($wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID)); |
|
| 743 | 743 | |
| 744 | 744 | } |
| 745 | 745 | } |
@@ -751,7 +751,7 @@ discard block |
||
| 751 | 751 | $comment_content = deslash($comment->comment_content); |
| 752 | 752 | $comment_author = deslash($comment->comment_author); |
| 753 | 753 | |
| 754 | - $wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID) ); |
|
| 754 | + $wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID)); |
|
| 755 | 755 | } |
| 756 | 756 | } |
| 757 | 757 | |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | $link_name = deslash($link->link_name); |
| 763 | 763 | $link_description = deslash($link->link_description); |
| 764 | 764 | |
| 765 | - $wpdb->update( $wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id) ); |
|
| 765 | + $wpdb->update($wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id)); |
|
| 766 | 766 | } |
| 767 | 767 | } |
| 768 | 768 | |
@@ -772,16 +772,16 @@ discard block |
||
| 772 | 772 | * If plugins are not stored in an array, they're stored in the old |
| 773 | 773 | * newline separated format. Convert to new format. |
| 774 | 774 | */ |
| 775 | - if ( !is_array( $active_plugins ) ) { |
|
| 775 | + if ( ! is_array($active_plugins)) { |
|
| 776 | 776 | $active_plugins = explode("\n", trim($active_plugins)); |
| 777 | 777 | update_option('active_plugins', $active_plugins); |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // Obsolete tables |
| 781 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues'); |
|
| 782 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes'); |
|
| 783 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups'); |
|
| 784 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options'); |
|
| 781 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'optionvalues'); |
|
| 782 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'optiontypes'); |
|
| 783 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'optiongroups'); |
|
| 784 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'optiongroup_options'); |
|
| 785 | 785 | |
| 786 | 786 | // Update comments table to use comment_type |
| 787 | 787 | $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'"); |
@@ -789,11 +789,11 @@ discard block |
||
| 789 | 789 | |
| 790 | 790 | // Some versions have multiple duplicate option_name rows with the same values |
| 791 | 791 | $options = $wpdb->get_results("SELECT option_name, COUNT(option_name) AS dupes FROM `$wpdb->options` GROUP BY option_name"); |
| 792 | - foreach ( $options as $option ) { |
|
| 793 | - if ( 1 != $option->dupes ) { // Could this be done in the query? |
|
| 792 | + foreach ($options as $option) { |
|
| 793 | + if (1 != $option->dupes) { // Could this be done in the query? |
|
| 794 | 794 | $limit = $option->dupes - 1; |
| 795 | - $dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) ); |
|
| 796 | - if ( $dupe_ids ) { |
|
| 795 | + $dupe_ids = $wpdb->get_col($wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit)); |
|
| 796 | + if ($dupe_ids) { |
|
| 797 | 797 | $dupe_ids = join($dupe_ids, ','); |
| 798 | 798 | $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); |
| 799 | 799 | } |
@@ -818,27 +818,27 @@ discard block |
||
| 818 | 818 | populate_roles_160(); |
| 819 | 819 | |
| 820 | 820 | $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); |
| 821 | - foreach ( $users as $user ) : |
|
| 822 | - if ( !empty( $user->user_firstname ) ) |
|
| 823 | - update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) ); |
|
| 824 | - if ( !empty( $user->user_lastname ) ) |
|
| 825 | - update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) ); |
|
| 826 | - if ( !empty( $user->user_nickname ) ) |
|
| 827 | - update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) ); |
|
| 828 | - if ( !empty( $user->user_level ) ) |
|
| 829 | - update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level ); |
|
| 830 | - if ( !empty( $user->user_icq ) ) |
|
| 831 | - update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) ); |
|
| 832 | - if ( !empty( $user->user_aim ) ) |
|
| 833 | - update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) ); |
|
| 834 | - if ( !empty( $user->user_msn ) ) |
|
| 835 | - update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) ); |
|
| 836 | - if ( !empty( $user->user_yim ) ) |
|
| 837 | - update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) ); |
|
| 838 | - if ( !empty( $user->user_description ) ) |
|
| 839 | - update_user_meta( $user->ID, 'description', wp_slash($user->user_description) ); |
|
| 840 | - |
|
| 841 | - if ( isset( $user->user_idmode ) ): |
|
| 821 | + foreach ($users as $user) : |
|
| 822 | + if ( ! empty($user->user_firstname)) |
|
| 823 | + update_user_meta($user->ID, 'first_name', wp_slash($user->user_firstname)); |
|
| 824 | + if ( ! empty($user->user_lastname)) |
|
| 825 | + update_user_meta($user->ID, 'last_name', wp_slash($user->user_lastname)); |
|
| 826 | + if ( ! empty($user->user_nickname)) |
|
| 827 | + update_user_meta($user->ID, 'nickname', wp_slash($user->user_nickname)); |
|
| 828 | + if ( ! empty($user->user_level)) |
|
| 829 | + update_user_meta($user->ID, $wpdb->prefix.'user_level', $user->user_level); |
|
| 830 | + if ( ! empty($user->user_icq)) |
|
| 831 | + update_user_meta($user->ID, 'icq', wp_slash($user->user_icq)); |
|
| 832 | + if ( ! empty($user->user_aim)) |
|
| 833 | + update_user_meta($user->ID, 'aim', wp_slash($user->user_aim)); |
|
| 834 | + if ( ! empty($user->user_msn)) |
|
| 835 | + update_user_meta($user->ID, 'msn', wp_slash($user->user_msn)); |
|
| 836 | + if ( ! empty($user->user_yim)) |
|
| 837 | + update_user_meta($user->ID, 'yim', wp_slash($user->user_icq)); |
|
| 838 | + if ( ! empty($user->user_description)) |
|
| 839 | + update_user_meta($user->ID, 'description', wp_slash($user->user_description)); |
|
| 840 | + |
|
| 841 | + if (isset($user->user_idmode)): |
|
| 842 | 842 | $idmode = $user->user_idmode; |
| 843 | 843 | if ($idmode == 'nickname') $id = $user->user_nickname; |
| 844 | 844 | if ($idmode == 'login') $id = $user->user_login; |
@@ -846,46 +846,46 @@ discard block |
||
| 846 | 846 | if ($idmode == 'lastname') $id = $user->user_lastname; |
| 847 | 847 | if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname; |
| 848 | 848 | if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname; |
| 849 | - if (!$idmode) $id = $user->user_nickname; |
|
| 850 | - $wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) ); |
|
| 849 | + if ( ! $idmode) $id = $user->user_nickname; |
|
| 850 | + $wpdb->update($wpdb->users, array('display_name' => $id), array('ID' => $user->ID)); |
|
| 851 | 851 | endif; |
| 852 | 852 | |
| 853 | 853 | // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set. |
| 854 | - $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities'); |
|
| 855 | - if ( empty($caps) || defined('RESET_CAPS') ) { |
|
| 856 | - $level = get_user_meta($user->ID, $wpdb->prefix . 'user_level', true); |
|
| 854 | + $caps = get_user_meta($user->ID, $wpdb->prefix.'capabilities'); |
|
| 855 | + if (empty($caps) || defined('RESET_CAPS')) { |
|
| 856 | + $level = get_user_meta($user->ID, $wpdb->prefix.'user_level', true); |
|
| 857 | 857 | $role = translate_level_to_role($level); |
| 858 | - update_user_meta( $user->ID, $wpdb->prefix . 'capabilities', array($role => true) ); |
|
| 858 | + update_user_meta($user->ID, $wpdb->prefix.'capabilities', array($role => true)); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | endforeach; |
| 862 | - $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' ); |
|
| 862 | + $old_user_fields = array('user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level'); |
|
| 863 | 863 | $wpdb->hide_errors(); |
| 864 | - foreach ( $old_user_fields as $old ) |
|
| 864 | + foreach ($old_user_fields as $old) |
|
| 865 | 865 | $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); |
| 866 | 866 | $wpdb->show_errors(); |
| 867 | 867 | |
| 868 | 868 | // Populate comment_count field of posts table. |
| 869 | - $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); |
|
| 870 | - if ( is_array( $comments ) ) |
|
| 869 | + $comments = $wpdb->get_results("SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID"); |
|
| 870 | + if (is_array($comments)) |
|
| 871 | 871 | foreach ($comments as $comment) |
| 872 | - $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) ); |
|
| 872 | + $wpdb->update($wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID)); |
|
| 873 | 873 | |
| 874 | 874 | /* |
| 875 | 875 | * Some alpha versions used a post status of object instead of attachment |
| 876 | 876 | * and put the mime type in post_type instead of post_mime_type. |
| 877 | 877 | */ |
| 878 | - if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) { |
|
| 878 | + if ($wp_current_db_version > 2541 && $wp_current_db_version <= 3091) { |
|
| 879 | 879 | $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); |
| 880 | 880 | foreach ($objects as $object) { |
| 881 | - $wpdb->update( $wpdb->posts, array( 'post_status' => 'attachment', |
|
| 881 | + $wpdb->update($wpdb->posts, array('post_status' => 'attachment', |
|
| 882 | 882 | 'post_mime_type' => $object->post_type, |
| 883 | 883 | 'post_type' => ''), |
| 884 | - array( 'ID' => $object->ID ) ); |
|
| 884 | + array('ID' => $object->ID)); |
|
| 885 | 885 | |
| 886 | 886 | $meta = get_post_meta($object->ID, 'imagedata', true); |
| 887 | - if ( ! empty($meta['file']) ) |
|
| 888 | - update_attached_file( $object->ID, $meta['file'] ); |
|
| 887 | + if ( ! empty($meta['file'])) |
|
| 888 | + update_attached_file($object->ID, $meta['file']); |
|
| 889 | 889 | } |
| 890 | 890 | } |
| 891 | 891 | } |
@@ -902,38 +902,38 @@ discard block |
||
| 902 | 902 | function upgrade_210() { |
| 903 | 903 | global $wpdb, $wp_current_db_version; |
| 904 | 904 | |
| 905 | - if ( $wp_current_db_version < 3506 ) { |
|
| 905 | + if ($wp_current_db_version < 3506) { |
|
| 906 | 906 | // Update status and type. |
| 907 | 907 | $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts"); |
| 908 | 908 | |
| 909 | - if ( ! empty($posts) ) foreach ($posts as $post) { |
|
| 909 | + if ( ! empty($posts)) foreach ($posts as $post) { |
|
| 910 | 910 | $status = $post->post_status; |
| 911 | 911 | $type = 'post'; |
| 912 | 912 | |
| 913 | - if ( 'static' == $status ) { |
|
| 913 | + if ('static' == $status) { |
|
| 914 | 914 | $status = 'publish'; |
| 915 | 915 | $type = 'page'; |
| 916 | - } elseif ( 'attachment' == $status ) { |
|
| 916 | + } elseif ('attachment' == $status) { |
|
| 917 | 917 | $status = 'inherit'; |
| 918 | 918 | $type = 'attachment'; |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) ); |
|
| 921 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID)); |
|
| 922 | 922 | } |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | - if ( $wp_current_db_version < 3845 ) { |
|
| 925 | + if ($wp_current_db_version < 3845) { |
|
| 926 | 926 | populate_roles_210(); |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - if ( $wp_current_db_version < 3531 ) { |
|
| 929 | + if ($wp_current_db_version < 3531) { |
|
| 930 | 930 | // Give future posts a post_status of future. |
| 931 | 931 | $now = gmdate('Y-m-d H:i:59'); |
| 932 | - $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); |
|
| 932 | + $wpdb->query("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); |
|
| 933 | 933 | |
| 934 | 934 | $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'"); |
| 935 | - if ( !empty($posts) ) |
|
| 936 | - foreach ( $posts as $post ) |
|
| 935 | + if ( ! empty($posts)) |
|
| 936 | + foreach ($posts as $post) |
|
| 937 | 937 | wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID)); |
| 938 | 938 | } |
| 939 | 939 | } |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | function upgrade_230() { |
| 951 | 951 | global $wp_current_db_version, $wpdb; |
| 952 | 952 | |
| 953 | - if ( $wp_current_db_version < 5200 ) { |
|
| 953 | + if ($wp_current_db_version < 5200) { |
|
| 954 | 954 | populate_roles_230(); |
| 955 | 955 | } |
| 956 | 956 | |
@@ -967,78 +967,78 @@ discard block |
||
| 967 | 967 | $term_group = 0; |
| 968 | 968 | |
| 969 | 969 | // Associate terms with the same slug in a term group and make slugs unique. |
| 970 | - if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { |
|
| 970 | + if ($exists = $wpdb->get_results($wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug))) { |
|
| 971 | 971 | $term_group = $exists[0]->term_group; |
| 972 | 972 | $id = $exists[0]->term_id; |
| 973 | 973 | $num = 2; |
| 974 | 974 | do { |
| 975 | - $alt_slug = $slug . "-$num"; |
|
| 975 | + $alt_slug = $slug."-$num"; |
|
| 976 | 976 | $num++; |
| 977 | - $slug_check = $wpdb->get_var( $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug) ); |
|
| 978 | - } while ( $slug_check ); |
|
| 977 | + $slug_check = $wpdb->get_var($wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug)); |
|
| 978 | + } while ($slug_check); |
|
| 979 | 979 | |
| 980 | 980 | $slug = $alt_slug; |
| 981 | 981 | |
| 982 | - if ( empty( $term_group ) ) { |
|
| 982 | + if (empty($term_group)) { |
|
| 983 | 983 | $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1; |
| 984 | - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id) ); |
|
| 984 | + $wpdb->query($wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id)); |
|
| 985 | 985 | } |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES |
|
| 989 | - (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) ); |
|
| 988 | + $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES |
|
| 989 | + (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group)); |
|
| 990 | 990 | |
| 991 | 991 | $count = 0; |
| 992 | - if ( !empty($category->category_count) ) { |
|
| 992 | + if ( ! empty($category->category_count)) { |
|
| 993 | 993 | $count = (int) $category->category_count; |
| 994 | 994 | $taxonomy = 'category'; |
| 995 | - $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) ); |
|
| 995 | + $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count)); |
|
| 996 | 996 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
| 997 | 997 | } |
| 998 | 998 | |
| 999 | - if ( !empty($category->link_count) ) { |
|
| 999 | + if ( ! empty($category->link_count)) { |
|
| 1000 | 1000 | $count = (int) $category->link_count; |
| 1001 | 1001 | $taxonomy = 'link_category'; |
| 1002 | - $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) ); |
|
| 1002 | + $wpdb->query($wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count)); |
|
| 1003 | 1003 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | - if ( !empty($category->tag_count) ) { |
|
| 1006 | + if ( ! empty($category->tag_count)) { |
|
| 1007 | 1007 | $have_tags = true; |
| 1008 | 1008 | $count = (int) $category->tag_count; |
| 1009 | 1009 | $taxonomy = 'post_tag'; |
| 1010 | - $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') ); |
|
| 1010 | + $wpdb->insert($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count')); |
|
| 1011 | 1011 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | - if ( empty($count) ) { |
|
| 1014 | + if (empty($count)) { |
|
| 1015 | 1015 | $count = 0; |
| 1016 | 1016 | $taxonomy = 'category'; |
| 1017 | - $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') ); |
|
| 1017 | + $wpdb->insert($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count')); |
|
| 1018 | 1018 | $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | $select = 'post_id, category_id'; |
| 1023 | - if ( $have_tags ) |
|
| 1023 | + if ($have_tags) |
|
| 1024 | 1024 | $select .= ', rel_type'; |
| 1025 | 1025 | |
| 1026 | 1026 | $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id"); |
| 1027 | - foreach ( $posts as $post ) { |
|
| 1027 | + foreach ($posts as $post) { |
|
| 1028 | 1028 | $post_id = (int) $post->post_id; |
| 1029 | 1029 | $term_id = (int) $post->category_id; |
| 1030 | 1030 | $taxonomy = 'category'; |
| 1031 | - if ( !empty($post->rel_type) && 'tag' == $post->rel_type) |
|
| 1031 | + if ( ! empty($post->rel_type) && 'tag' == $post->rel_type) |
|
| 1032 | 1032 | $taxonomy = 'tag'; |
| 1033 | 1033 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
| 1034 | - if ( empty($tt_id) ) |
|
| 1034 | + if (empty($tt_id)) |
|
| 1035 | 1035 | continue; |
| 1036 | 1036 | |
| 1037 | - $wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) ); |
|
| 1037 | + $wpdb->insert($wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id)); |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | // < 3570 we used linkcategories. >= 3570 we used categories and link2cat. |
| 1041 | - if ( $wp_current_db_version < 3570 ) { |
|
| 1041 | + if ($wp_current_db_version < 3570) { |
|
| 1042 | 1042 | /* |
| 1043 | 1043 | * Create link_category terms for link categories. Create a map of link |
| 1044 | 1044 | * cat IDs to link_category terms. |
@@ -1046,8 +1046,8 @@ discard block |
||
| 1046 | 1046 | $link_cat_id_map = array(); |
| 1047 | 1047 | $default_link_cat = 0; |
| 1048 | 1048 | $tt_ids = array(); |
| 1049 | - $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->prefix . 'linkcategories'); |
|
| 1050 | - foreach ( $link_cats as $category) { |
|
| 1049 | + $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM ".$wpdb->prefix.'linkcategories'); |
|
| 1050 | + foreach ($link_cats as $category) { |
|
| 1051 | 1051 | $cat_id = (int) $category->cat_id; |
| 1052 | 1052 | $term_id = 0; |
| 1053 | 1053 | $name = wp_slash($category->cat_name); |
@@ -1055,66 +1055,66 @@ discard block |
||
| 1055 | 1055 | $term_group = 0; |
| 1056 | 1056 | |
| 1057 | 1057 | // Associate terms with the same slug in a term group and make slugs unique. |
| 1058 | - if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { |
|
| 1058 | + if ($exists = $wpdb->get_results($wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug))) { |
|
| 1059 | 1059 | $term_group = $exists[0]->term_group; |
| 1060 | 1060 | $term_id = $exists[0]->term_id; |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - if ( empty($term_id) ) { |
|
| 1064 | - $wpdb->insert( $wpdb->terms, compact('name', 'slug', 'term_group') ); |
|
| 1063 | + if (empty($term_id)) { |
|
| 1064 | + $wpdb->insert($wpdb->terms, compact('name', 'slug', 'term_group')); |
|
| 1065 | 1065 | $term_id = (int) $wpdb->insert_id; |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | $link_cat_id_map[$cat_id] = $term_id; |
| 1069 | 1069 | $default_link_cat = $term_id; |
| 1070 | 1070 | |
| 1071 | - $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $term_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 0) ); |
|
| 1071 | + $wpdb->insert($wpdb->term_taxonomy, array('term_id' => $term_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 0)); |
|
| 1072 | 1072 | $tt_ids[$term_id] = (int) $wpdb->insert_id; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | // Associate links to cats. |
| 1076 | 1076 | $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); |
| 1077 | - if ( !empty($links) ) foreach ( $links as $link ) { |
|
| 1078 | - if ( 0 == $link->link_category ) |
|
| 1077 | + if ( ! empty($links)) foreach ($links as $link) { |
|
| 1078 | + if (0 == $link->link_category) |
|
| 1079 | 1079 | continue; |
| 1080 | - if ( ! isset($link_cat_id_map[$link->link_category]) ) |
|
| 1080 | + if ( ! isset($link_cat_id_map[$link->link_category])) |
|
| 1081 | 1081 | continue; |
| 1082 | 1082 | $term_id = $link_cat_id_map[$link->link_category]; |
| 1083 | 1083 | $tt_id = $tt_ids[$term_id]; |
| 1084 | - if ( empty($tt_id) ) |
|
| 1084 | + if (empty($tt_id)) |
|
| 1085 | 1085 | continue; |
| 1086 | 1086 | |
| 1087 | - $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id) ); |
|
| 1087 | + $wpdb->insert($wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id)); |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | // Set default to the last category we grabbed during the upgrade loop. |
| 1091 | 1091 | update_option('default_link_category', $default_link_cat); |
| 1092 | 1092 | } else { |
| 1093 | 1093 | $links = $wpdb->get_results("SELECT link_id, category_id FROM $wpdb->link2cat GROUP BY link_id, category_id"); |
| 1094 | - foreach ( $links as $link ) { |
|
| 1094 | + foreach ($links as $link) { |
|
| 1095 | 1095 | $link_id = (int) $link->link_id; |
| 1096 | 1096 | $term_id = (int) $link->category_id; |
| 1097 | 1097 | $taxonomy = 'link_category'; |
| 1098 | 1098 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
| 1099 | - if ( empty($tt_id) ) |
|
| 1099 | + if (empty($tt_id)) |
|
| 1100 | 1100 | continue; |
| 1101 | - $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id) ); |
|
| 1101 | + $wpdb->insert($wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id)); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | - if ( $wp_current_db_version < 4772 ) { |
|
| 1105 | + if ($wp_current_db_version < 4772) { |
|
| 1106 | 1106 | // Obsolete linkcategories table |
| 1107 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'linkcategories'); |
|
| 1107 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'linkcategories'); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | 1110 | // Recalculate all counts |
| 1111 | 1111 | $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy"); |
| 1112 | - foreach ( (array) $terms as $term ) { |
|
| 1113 | - if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) |
|
| 1114 | - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1112 | + foreach ((array) $terms as $term) { |
|
| 1113 | + if (('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy)) |
|
| 1114 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id)); |
|
| 1115 | 1115 | else |
| 1116 | - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1117 | - $wpdb->update( $wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id) ); |
|
| 1116 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id)); |
|
| 1117 | + $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id)); |
|
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | |
@@ -1128,9 +1128,9 @@ discard block |
||
| 1128 | 1128 | */ |
| 1129 | 1129 | function upgrade_230_options_table() { |
| 1130 | 1130 | global $wpdb; |
| 1131 | - $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' ); |
|
| 1131 | + $old_options_fields = array('option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level'); |
|
| 1132 | 1132 | $wpdb->hide_errors(); |
| 1133 | - foreach ( $old_options_fields as $old ) |
|
| 1133 | + foreach ($old_options_fields as $old) |
|
| 1134 | 1134 | $wpdb->query("ALTER TABLE $wpdb->options DROP $old"); |
| 1135 | 1135 | $wpdb->show_errors(); |
| 1136 | 1136 | } |
@@ -1145,9 +1145,9 @@ discard block |
||
| 1145 | 1145 | */ |
| 1146 | 1146 | function upgrade_230_old_tables() { |
| 1147 | 1147 | global $wpdb; |
| 1148 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories'); |
|
| 1149 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat'); |
|
| 1150 | - $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat'); |
|
| 1148 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'categories'); |
|
| 1149 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'link2cat'); |
|
| 1150 | + $wpdb->query('DROP TABLE IF EXISTS '.$wpdb->prefix.'post2cat'); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1175,7 +1175,7 @@ discard block |
||
| 1175 | 1175 | function upgrade_250() { |
| 1176 | 1176 | global $wp_current_db_version; |
| 1177 | 1177 | |
| 1178 | - if ( $wp_current_db_version < 6689 ) { |
|
| 1178 | + if ($wp_current_db_version < 6689) { |
|
| 1179 | 1179 | populate_roles_250(); |
| 1180 | 1180 | } |
| 1181 | 1181 | |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | function upgrade_260() { |
| 1207 | 1207 | global $wp_current_db_version; |
| 1208 | 1208 | |
| 1209 | - if ( $wp_current_db_version < 8000 ) |
|
| 1209 | + if ($wp_current_db_version < 8000) |
|
| 1210 | 1210 | populate_roles_260(); |
| 1211 | 1211 | } |
| 1212 | 1212 | |
@@ -1222,12 +1222,12 @@ discard block |
||
| 1222 | 1222 | function upgrade_270() { |
| 1223 | 1223 | global $wpdb, $wp_current_db_version; |
| 1224 | 1224 | |
| 1225 | - if ( $wp_current_db_version < 8980 ) |
|
| 1225 | + if ($wp_current_db_version < 8980) |
|
| 1226 | 1226 | populate_roles_270(); |
| 1227 | 1227 | |
| 1228 | 1228 | // Update post_date for unpublished posts with empty timestamp |
| 1229 | - if ( $wp_current_db_version < 8921 ) |
|
| 1230 | - $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); |
|
| 1229 | + if ($wp_current_db_version < 8921) |
|
| 1230 | + $wpdb->query("UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'"); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | /** |
@@ -1242,22 +1242,22 @@ discard block |
||
| 1242 | 1242 | function upgrade_280() { |
| 1243 | 1243 | global $wp_current_db_version, $wpdb; |
| 1244 | 1244 | |
| 1245 | - if ( $wp_current_db_version < 10360 ) |
|
| 1245 | + if ($wp_current_db_version < 10360) |
|
| 1246 | 1246 | populate_roles_280(); |
| 1247 | - if ( is_multisite() ) { |
|
| 1247 | + if (is_multisite()) { |
|
| 1248 | 1248 | $start = 0; |
| 1249 | - while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) { |
|
| 1250 | - foreach ( $rows as $row ) { |
|
| 1249 | + while ($rows = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20")) { |
|
| 1250 | + foreach ($rows as $row) { |
|
| 1251 | 1251 | $value = $row->option_value; |
| 1252 | - if ( !@unserialize( $value ) ) |
|
| 1253 | - $value = stripslashes( $value ); |
|
| 1254 | - if ( $value !== $row->option_value ) { |
|
| 1255 | - update_option( $row->option_name, $value ); |
|
| 1252 | + if ( ! @unserialize($value)) |
|
| 1253 | + $value = stripslashes($value); |
|
| 1254 | + if ($value !== $row->option_value) { |
|
| 1255 | + update_option($row->option_name, $value); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | } |
| 1258 | 1258 | $start += 20; |
| 1259 | 1259 | } |
| 1260 | - refresh_blog_details( $wpdb->blogid ); |
|
| 1260 | + refresh_blog_details($wpdb->blogid); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
@@ -1272,11 +1272,11 @@ discard block |
||
| 1272 | 1272 | function upgrade_290() { |
| 1273 | 1273 | global $wp_current_db_version; |
| 1274 | 1274 | |
| 1275 | - if ( $wp_current_db_version < 11958 ) { |
|
| 1275 | + if ($wp_current_db_version < 11958) { |
|
| 1276 | 1276 | // Previously, setting depth to 1 would redundantly disable threading, but now 2 is the minimum depth to avoid confusion |
| 1277 | - if ( get_option( 'thread_comments_depth' ) == '1' ) { |
|
| 1278 | - update_option( 'thread_comments_depth', 2 ); |
|
| 1279 | - update_option( 'thread_comments', 0 ); |
|
| 1277 | + if (get_option('thread_comments_depth') == '1') { |
|
| 1278 | + update_option('thread_comments_depth', 2); |
|
| 1279 | + update_option('thread_comments', 0); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | } |
| 1282 | 1282 | } |
@@ -1293,14 +1293,14 @@ discard block |
||
| 1293 | 1293 | function upgrade_300() { |
| 1294 | 1294 | global $wp_current_db_version, $wpdb; |
| 1295 | 1295 | |
| 1296 | - if ( $wp_current_db_version < 15093 ) |
|
| 1296 | + if ($wp_current_db_version < 15093) |
|
| 1297 | 1297 | populate_roles_300(); |
| 1298 | 1298 | |
| 1299 | - if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) |
|
| 1300 | - add_site_option( 'siteurl', '' ); |
|
| 1299 | + if ($wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined('MULTISITE') && get_site_option('siteurl') === false) |
|
| 1300 | + add_site_option('siteurl', ''); |
|
| 1301 | 1301 | |
| 1302 | 1302 | // 3.0 screen options key name changes. |
| 1303 | - if ( wp_should_upgrade_global_tables() ) { |
|
| 1303 | + if (wp_should_upgrade_global_tables()) { |
|
| 1304 | 1304 | $sql = "DELETE FROM $wpdb->usermeta |
| 1305 | 1305 | WHERE meta_key LIKE %s |
| 1306 | 1306 | OR meta_key LIKE %s |
@@ -1314,15 +1314,15 @@ discard block |
||
| 1314 | 1314 | OR meta_key = 'manageeditcolumnshidden' |
| 1315 | 1315 | OR meta_key = 'categories_per_page' |
| 1316 | 1316 | OR meta_key = 'edit_tags_per_page'"; |
| 1317 | - $prefix = $wpdb->esc_like( $wpdb->base_prefix ); |
|
| 1318 | - $wpdb->query( $wpdb->prepare( $sql, |
|
| 1319 | - $prefix . '%' . $wpdb->esc_like( 'meta-box-hidden' ) . '%', |
|
| 1320 | - $prefix . '%' . $wpdb->esc_like( 'closedpostboxes' ) . '%', |
|
| 1321 | - $prefix . '%' . $wpdb->esc_like( 'manage-' ) . '%' . $wpdb->esc_like( '-columns-hidden' ) . '%', |
|
| 1322 | - $prefix . '%' . $wpdb->esc_like( 'meta-box-order' ) . '%', |
|
| 1323 | - $prefix . '%' . $wpdb->esc_like( 'metaboxorder' ) . '%', |
|
| 1324 | - $prefix . '%' . $wpdb->esc_like( 'screen_layout' ) . '%' |
|
| 1325 | - ) ); |
|
| 1317 | + $prefix = $wpdb->esc_like($wpdb->base_prefix); |
|
| 1318 | + $wpdb->query($wpdb->prepare($sql, |
|
| 1319 | + $prefix.'%'.$wpdb->esc_like('meta-box-hidden').'%', |
|
| 1320 | + $prefix.'%'.$wpdb->esc_like('closedpostboxes').'%', |
|
| 1321 | + $prefix.'%'.$wpdb->esc_like('manage-').'%'.$wpdb->esc_like('-columns-hidden').'%', |
|
| 1322 | + $prefix.'%'.$wpdb->esc_like('meta-box-order').'%', |
|
| 1323 | + $prefix.'%'.$wpdb->esc_like('metaboxorder').'%', |
|
| 1324 | + $prefix.'%'.$wpdb->esc_like('screen_layout').'%' |
|
| 1325 | + )); |
|
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | 1328 | } |
@@ -1341,52 +1341,52 @@ discard block |
||
| 1341 | 1341 | function upgrade_330() { |
| 1342 | 1342 | global $wp_current_db_version, $wpdb, $wp_registered_widgets, $sidebars_widgets; |
| 1343 | 1343 | |
| 1344 | - if ( $wp_current_db_version < 19061 && wp_should_upgrade_global_tables() ) { |
|
| 1345 | - $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); |
|
| 1344 | + if ($wp_current_db_version < 19061 && wp_should_upgrade_global_tables()) { |
|
| 1345 | + $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')"); |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | - if ( $wp_current_db_version >= 11548 ) |
|
| 1348 | + if ($wp_current_db_version >= 11548) |
|
| 1349 | 1349 | return; |
| 1350 | 1350 | |
| 1351 | - $sidebars_widgets = get_option( 'sidebars_widgets', array() ); |
|
| 1351 | + $sidebars_widgets = get_option('sidebars_widgets', array()); |
|
| 1352 | 1352 | $_sidebars_widgets = array(); |
| 1353 | 1353 | |
| 1354 | - if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) ) |
|
| 1354 | + if (isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets)) |
|
| 1355 | 1355 | $sidebars_widgets['array_version'] = 3; |
| 1356 | - elseif ( !isset($sidebars_widgets['array_version']) ) |
|
| 1356 | + elseif ( ! isset($sidebars_widgets['array_version'])) |
|
| 1357 | 1357 | $sidebars_widgets['array_version'] = 1; |
| 1358 | 1358 | |
| 1359 | - switch ( $sidebars_widgets['array_version'] ) { |
|
| 1359 | + switch ($sidebars_widgets['array_version']) { |
|
| 1360 | 1360 | case 1 : |
| 1361 | - foreach ( (array) $sidebars_widgets as $index => $sidebar ) |
|
| 1362 | - if ( is_array($sidebar) ) |
|
| 1363 | - foreach ( (array) $sidebar as $i => $name ) { |
|
| 1361 | + foreach ((array) $sidebars_widgets as $index => $sidebar) |
|
| 1362 | + if (is_array($sidebar)) |
|
| 1363 | + foreach ((array) $sidebar as $i => $name) { |
|
| 1364 | 1364 | $id = strtolower($name); |
| 1365 | - if ( isset($wp_registered_widgets[$id]) ) { |
|
| 1365 | + if (isset($wp_registered_widgets[$id])) { |
|
| 1366 | 1366 | $_sidebars_widgets[$index][$i] = $id; |
| 1367 | 1367 | continue; |
| 1368 | 1368 | } |
| 1369 | 1369 | $id = sanitize_title($name); |
| 1370 | - if ( isset($wp_registered_widgets[$id]) ) { |
|
| 1370 | + if (isset($wp_registered_widgets[$id])) { |
|
| 1371 | 1371 | $_sidebars_widgets[$index][$i] = $id; |
| 1372 | 1372 | continue; |
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | $found = false; |
| 1376 | 1376 | |
| 1377 | - foreach ( $wp_registered_widgets as $widget_id => $widget ) { |
|
| 1378 | - if ( strtolower($widget['name']) == strtolower($name) ) { |
|
| 1377 | + foreach ($wp_registered_widgets as $widget_id => $widget) { |
|
| 1378 | + if (strtolower($widget['name']) == strtolower($name)) { |
|
| 1379 | 1379 | $_sidebars_widgets[$index][$i] = $widget['id']; |
| 1380 | 1380 | $found = true; |
| 1381 | 1381 | break; |
| 1382 | - } elseif ( sanitize_title($widget['name']) == sanitize_title($name) ) { |
|
| 1382 | + } elseif (sanitize_title($widget['name']) == sanitize_title($name)) { |
|
| 1383 | 1383 | $_sidebars_widgets[$index][$i] = $widget['id']; |
| 1384 | 1384 | $found = true; |
| 1385 | 1385 | break; |
| 1386 | 1386 | } |
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | - if ( $found ) |
|
| 1389 | + if ($found) |
|
| 1390 | 1390 | continue; |
| 1391 | 1391 | |
| 1392 | 1392 | unset($_sidebars_widgets[$index][$i]); |
@@ -1398,7 +1398,7 @@ discard block |
||
| 1398 | 1398 | case 2 : |
| 1399 | 1399 | $sidebars_widgets = retrieve_widgets(); |
| 1400 | 1400 | $sidebars_widgets['array_version'] = 3; |
| 1401 | - update_option( 'sidebars_widgets', $sidebars_widgets ); |
|
| 1401 | + update_option('sidebars_widgets', $sidebars_widgets); |
|
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | 1404 | |
@@ -1414,27 +1414,27 @@ discard block |
||
| 1414 | 1414 | function upgrade_340() { |
| 1415 | 1415 | global $wp_current_db_version, $wpdb; |
| 1416 | 1416 | |
| 1417 | - if ( $wp_current_db_version < 19798 ) { |
|
| 1417 | + if ($wp_current_db_version < 19798) { |
|
| 1418 | 1418 | $wpdb->hide_errors(); |
| 1419 | - $wpdb->query( "ALTER TABLE $wpdb->options DROP COLUMN blog_id" ); |
|
| 1419 | + $wpdb->query("ALTER TABLE $wpdb->options DROP COLUMN blog_id"); |
|
| 1420 | 1420 | $wpdb->show_errors(); |
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | - if ( $wp_current_db_version < 19799 ) { |
|
| 1423 | + if ($wp_current_db_version < 19799) { |
|
| 1424 | 1424 | $wpdb->hide_errors(); |
| 1425 | 1425 | $wpdb->query("ALTER TABLE $wpdb->comments DROP INDEX comment_approved"); |
| 1426 | 1426 | $wpdb->show_errors(); |
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | - if ( $wp_current_db_version < 20022 && wp_should_upgrade_global_tables() ) { |
|
| 1430 | - $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'" ); |
|
| 1429 | + if ($wp_current_db_version < 20022 && wp_should_upgrade_global_tables()) { |
|
| 1430 | + $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key = 'themes_last_view'"); |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | - if ( $wp_current_db_version < 20080 ) { |
|
| 1434 | - if ( 'yes' == $wpdb->get_var( "SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'" ) ) { |
|
| 1435 | - $uninstall_plugins = get_option( 'uninstall_plugins' ); |
|
| 1436 | - delete_option( 'uninstall_plugins' ); |
|
| 1437 | - add_option( 'uninstall_plugins', $uninstall_plugins, null, 'no' ); |
|
| 1433 | + if ($wp_current_db_version < 20080) { |
|
| 1434 | + if ('yes' == $wpdb->get_var("SELECT autoload FROM $wpdb->options WHERE option_name = 'uninstall_plugins'")) { |
|
| 1435 | + $uninstall_plugins = get_option('uninstall_plugins'); |
|
| 1436 | + delete_option('uninstall_plugins'); |
|
| 1437 | + add_option('uninstall_plugins', $uninstall_plugins, null, 'no'); |
|
| 1438 | 1438 | } |
| 1439 | 1439 | } |
| 1440 | 1440 | } |
@@ -1451,23 +1451,23 @@ discard block |
||
| 1451 | 1451 | function upgrade_350() { |
| 1452 | 1452 | global $wp_current_db_version, $wpdb; |
| 1453 | 1453 | |
| 1454 | - if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) |
|
| 1455 | - update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() |
|
| 1454 | + if ($wp_current_db_version < 22006 && $wpdb->get_var("SELECT link_id FROM $wpdb->links LIMIT 1")) |
|
| 1455 | + update_option('link_manager_enabled', 1); // Previously set to 0 by populate_options() |
|
| 1456 | 1456 | |
| 1457 | - if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) { |
|
| 1457 | + if ($wp_current_db_version < 21811 && wp_should_upgrade_global_tables()) { |
|
| 1458 | 1458 | $meta_keys = array(); |
| 1459 | - foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { |
|
| 1460 | - if ( false !== strpos( $name, '-' ) ) |
|
| 1461 | - $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page'; |
|
| 1459 | + foreach (array_merge(get_post_types(), get_taxonomies()) as $name) { |
|
| 1460 | + if (false !== strpos($name, '-')) |
|
| 1461 | + $meta_keys[] = 'edit_'.str_replace('-', '_', $name).'_per_page'; |
|
| 1462 | 1462 | } |
| 1463 | - if ( $meta_keys ) { |
|
| 1464 | - $meta_keys = implode( "', '", $meta_keys ); |
|
| 1465 | - $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')" ); |
|
| 1463 | + if ($meta_keys) { |
|
| 1464 | + $meta_keys = implode("', '", $meta_keys); |
|
| 1465 | + $wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key IN ('$meta_keys')"); |
|
| 1466 | 1466 | } |
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | - if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) ) |
|
| 1470 | - wp_delete_term( $term->term_id, 'post_format' ); |
|
| 1469 | + if ($wp_current_db_version < 22422 && $term = get_term_by('slug', 'post-format-standard', 'post_format')) |
|
| 1470 | + wp_delete_term($term->term_id, 'post_format'); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | 1473 | /** |
@@ -1480,8 +1480,8 @@ discard block |
||
| 1480 | 1480 | */ |
| 1481 | 1481 | function upgrade_370() { |
| 1482 | 1482 | global $wp_current_db_version; |
| 1483 | - if ( $wp_current_db_version < 25824 ) |
|
| 1484 | - wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' ); |
|
| 1483 | + if ($wp_current_db_version < 25824) |
|
| 1484 | + wp_clear_scheduled_hook('wp_auto_updates_maybe_update'); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
@@ -1495,8 +1495,8 @@ discard block |
||
| 1495 | 1495 | */ |
| 1496 | 1496 | function upgrade_372() { |
| 1497 | 1497 | global $wp_current_db_version; |
| 1498 | - if ( $wp_current_db_version < 26148 ) |
|
| 1499 | - wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); |
|
| 1498 | + if ($wp_current_db_version < 26148) |
|
| 1499 | + wp_clear_scheduled_hook('wp_maybe_auto_update'); |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | /** |
@@ -1509,8 +1509,8 @@ discard block |
||
| 1509 | 1509 | */ |
| 1510 | 1510 | function upgrade_380() { |
| 1511 | 1511 | global $wp_current_db_version; |
| 1512 | - if ( $wp_current_db_version < 26691 ) { |
|
| 1513 | - deactivate_plugins( array( 'mp6/mp6.php' ), true ); |
|
| 1512 | + if ($wp_current_db_version < 26691) { |
|
| 1513 | + deactivate_plugins(array('mp6/mp6.php'), true); |
|
| 1514 | 1514 | } |
| 1515 | 1515 | } |
| 1516 | 1516 | |
@@ -1524,12 +1524,12 @@ discard block |
||
| 1524 | 1524 | */ |
| 1525 | 1525 | function upgrade_400() { |
| 1526 | 1526 | global $wp_current_db_version; |
| 1527 | - if ( $wp_current_db_version < 29630 ) { |
|
| 1528 | - if ( ! is_multisite() && false === get_option( 'WPLANG' ) ) { |
|
| 1529 | - if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && in_array( WPLANG, get_available_languages() ) ) { |
|
| 1530 | - update_option( 'WPLANG', WPLANG ); |
|
| 1527 | + if ($wp_current_db_version < 29630) { |
|
| 1528 | + if ( ! is_multisite() && false === get_option('WPLANG')) { |
|
| 1529 | + if (defined('WPLANG') && ('' !== WPLANG) && in_array(WPLANG, get_available_languages())) { |
|
| 1530 | + update_option('WPLANG', WPLANG); |
|
| 1531 | 1531 | } else { |
| 1532 | - update_option( 'WPLANG', '' ); |
|
| 1532 | + update_option('WPLANG', ''); |
|
| 1533 | 1533 | } |
| 1534 | 1534 | } |
| 1535 | 1535 | } |
@@ -1558,29 +1558,29 @@ discard block |
||
| 1558 | 1558 | function upgrade_430() { |
| 1559 | 1559 | global $wp_current_db_version, $wpdb; |
| 1560 | 1560 | |
| 1561 | - if ( $wp_current_db_version < 32364 ) { |
|
| 1561 | + if ($wp_current_db_version < 32364) { |
|
| 1562 | 1562 | upgrade_430_fix_comments(); |
| 1563 | 1563 | } |
| 1564 | 1564 | |
| 1565 | 1565 | // Shared terms are split in a separate process. |
| 1566 | - if ( $wp_current_db_version < 32814 ) { |
|
| 1567 | - update_option( 'finished_splitting_shared_terms', 0 ); |
|
| 1568 | - wp_schedule_single_event( time() + ( 1 * MINUTE_IN_SECONDS ), 'wp_split_shared_term_batch' ); |
|
| 1566 | + if ($wp_current_db_version < 32814) { |
|
| 1567 | + update_option('finished_splitting_shared_terms', 0); |
|
| 1568 | + wp_schedule_single_event(time() + (1 * MINUTE_IN_SECONDS), 'wp_split_shared_term_batch'); |
|
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | - if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { |
|
| 1572 | - if ( is_multisite() ) { |
|
| 1573 | - $tables = $wpdb->tables( 'blog' ); |
|
| 1571 | + if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) { |
|
| 1572 | + if (is_multisite()) { |
|
| 1573 | + $tables = $wpdb->tables('blog'); |
|
| 1574 | 1574 | } else { |
| 1575 | - $tables = $wpdb->tables( 'all' ); |
|
| 1576 | - if ( ! wp_should_upgrade_global_tables() ) { |
|
| 1577 | - $global_tables = $wpdb->tables( 'global' ); |
|
| 1578 | - $tables = array_diff_assoc( $tables, $global_tables ); |
|
| 1575 | + $tables = $wpdb->tables('all'); |
|
| 1576 | + if ( ! wp_should_upgrade_global_tables()) { |
|
| 1577 | + $global_tables = $wpdb->tables('global'); |
|
| 1578 | + $tables = array_diff_assoc($tables, $global_tables); |
|
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - foreach ( $tables as $table ) { |
|
| 1583 | - maybe_convert_table_to_utf8mb4( $table ); |
|
| 1582 | + foreach ($tables as $table) { |
|
| 1583 | + maybe_convert_table_to_utf8mb4($table); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | } |
| 1586 | 1586 | } |
@@ -1597,18 +1597,18 @@ discard block |
||
| 1597 | 1597 | function upgrade_430_fix_comments() { |
| 1598 | 1598 | global $wp_current_db_version, $wpdb; |
| 1599 | 1599 | |
| 1600 | - $content_length = $wpdb->get_col_length( $wpdb->comments, 'comment_content' ); |
|
| 1600 | + $content_length = $wpdb->get_col_length($wpdb->comments, 'comment_content'); |
|
| 1601 | 1601 | |
| 1602 | - if ( is_wp_error( $content_length ) ) { |
|
| 1602 | + if (is_wp_error($content_length)) { |
|
| 1603 | 1603 | return; |
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | - if ( false === $content_length ) { |
|
| 1606 | + if (false === $content_length) { |
|
| 1607 | 1607 | $content_length = array( |
| 1608 | 1608 | 'type' => 'byte', |
| 1609 | 1609 | 'length' => 65535, |
| 1610 | 1610 | ); |
| 1611 | - } elseif ( ! is_array( $content_length ) ) { |
|
| 1611 | + } elseif ( ! is_array($content_length)) { |
|
| 1612 | 1612 | $length = (int) $content_length > 0 ? (int) $content_length : 65535; |
| 1613 | 1613 | $content_length = array( |
| 1614 | 1614 | 'type' => 'byte', |
@@ -1616,12 +1616,12 @@ discard block |
||
| 1616 | 1616 | ); |
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | - if ( 'byte' !== $content_length['type'] || 0 === $content_length['length'] ) { |
|
| 1619 | + if ('byte' !== $content_length['type'] || 0 === $content_length['length']) { |
|
| 1620 | 1620 | // Sites with malformed DB schemas are on their own. |
| 1621 | 1621 | return; |
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | - $allowed_length = intval( $content_length['length'] ) - 10; |
|
| 1624 | + $allowed_length = intval($content_length['length']) - 10; |
|
| 1625 | 1625 | |
| 1626 | 1626 | $comments = $wpdb->get_results( |
| 1627 | 1627 | "SELECT `comment_ID` FROM `{$wpdb->comments}` |
@@ -1630,8 +1630,8 @@ discard block |
||
| 1630 | 1630 | AND ( `comment_content` LIKE '%<%' OR `comment_content` LIKE '%>%' )" |
| 1631 | 1631 | ); |
| 1632 | 1632 | |
| 1633 | - foreach ( $comments as $comment ) { |
|
| 1634 | - wp_delete_comment( $comment->comment_ID, true ); |
|
| 1633 | + foreach ($comments as $comment) { |
|
| 1634 | + wp_delete_comment($comment->comment_ID, true); |
|
| 1635 | 1635 | } |
| 1636 | 1636 | } |
| 1637 | 1637 | |
@@ -1644,9 +1644,9 @@ discard block |
||
| 1644 | 1644 | function upgrade_431() { |
| 1645 | 1645 | // Fix incorrect cron entries for term splitting |
| 1646 | 1646 | $cron_array = _get_cron_array(); |
| 1647 | - if ( isset( $cron_array['wp_batch_split_terms'] ) ) { |
|
| 1648 | - unset( $cron_array['wp_batch_split_terms'] ); |
|
| 1649 | - _set_cron_array( $cron_array ); |
|
| 1647 | + if (isset($cron_array['wp_batch_split_terms'])) { |
|
| 1648 | + unset($cron_array['wp_batch_split_terms']); |
|
| 1649 | + _set_cron_array($cron_array); |
|
| 1650 | 1650 | } |
| 1651 | 1651 | } |
| 1652 | 1652 | |
@@ -1662,15 +1662,15 @@ discard block |
||
| 1662 | 1662 | function upgrade_440() { |
| 1663 | 1663 | global $wp_current_db_version, $wpdb; |
| 1664 | 1664 | |
| 1665 | - if ( $wp_current_db_version < 34030 ) { |
|
| 1666 | - $wpdb->query( "ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)" ); |
|
| 1665 | + if ($wp_current_db_version < 34030) { |
|
| 1666 | + $wpdb->query("ALTER TABLE {$wpdb->options} MODIFY option_name VARCHAR(191)"); |
|
| 1667 | 1667 | } |
| 1668 | 1668 | |
| 1669 | 1669 | // Remove the unused 'add_users' role. |
| 1670 | 1670 | $roles = wp_roles(); |
| 1671 | - foreach ( $roles->role_objects as $role ) { |
|
| 1672 | - if ( $role->has_cap( 'add_users' ) ) { |
|
| 1673 | - $role->remove_cap( 'add_users' ); |
|
| 1671 | + foreach ($roles->role_objects as $role) { |
|
| 1672 | + if ($role->has_cap('add_users')) { |
|
| 1673 | + $role->remove_cap('add_users'); |
|
| 1674 | 1674 | } |
| 1675 | 1675 | } |
| 1676 | 1676 | } |
@@ -1687,17 +1687,17 @@ discard block |
||
| 1687 | 1687 | function upgrade_450() { |
| 1688 | 1688 | global $wp_current_db_version, $wpdb; |
| 1689 | 1689 | |
| 1690 | - if ( $wp_current_db_version < 36180 ) { |
|
| 1691 | - wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); |
|
| 1690 | + if ($wp_current_db_version < 36180) { |
|
| 1691 | + wp_clear_scheduled_hook('wp_maybe_auto_update'); |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | // Remove unused email confirmation options, moved to usermeta. |
| 1695 | - if ( $wp_current_db_version < 36679 && is_multisite() ) { |
|
| 1696 | - $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'" ); |
|
| 1695 | + if ($wp_current_db_version < 36679 && is_multisite()) { |
|
| 1696 | + $wpdb->query("DELETE FROM $wpdb->options WHERE option_name REGEXP '^[0-9]+_new_email$'"); |
|
| 1697 | 1697 | } |
| 1698 | 1698 | |
| 1699 | 1699 | // Remove unused user setting for wpLink. |
| 1700 | - delete_user_setting( 'wplink' ); |
|
| 1700 | + delete_user_setting('wplink'); |
|
| 1701 | 1701 | } |
| 1702 | 1702 | |
| 1703 | 1703 | /** |
@@ -1712,22 +1712,22 @@ discard block |
||
| 1712 | 1712 | global $wp_current_db_version; |
| 1713 | 1713 | |
| 1714 | 1714 | // Remove unused post meta. |
| 1715 | - if ( $wp_current_db_version < 37854 ) { |
|
| 1716 | - delete_post_meta_by_key( '_post_restored_from' ); |
|
| 1715 | + if ($wp_current_db_version < 37854) { |
|
| 1716 | + delete_post_meta_by_key('_post_restored_from'); |
|
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | // Remove plugins with callback as an array object/method as the uninstall hook, see #13786. |
| 1720 | - if ( $wp_current_db_version < 37965 ) { |
|
| 1721 | - $uninstall_plugins = get_option( 'uninstall_plugins', array() ); |
|
| 1720 | + if ($wp_current_db_version < 37965) { |
|
| 1721 | + $uninstall_plugins = get_option('uninstall_plugins', array()); |
|
| 1722 | 1722 | |
| 1723 | - if ( ! empty( $uninstall_plugins ) ) { |
|
| 1724 | - foreach ( $uninstall_plugins as $basename => $callback ) { |
|
| 1725 | - if ( is_array( $callback ) && is_object( $callback[0] ) ) { |
|
| 1726 | - unset( $uninstall_plugins[ $basename ] ); |
|
| 1723 | + if ( ! empty($uninstall_plugins)) { |
|
| 1724 | + foreach ($uninstall_plugins as $basename => $callback) { |
|
| 1725 | + if (is_array($callback) && is_object($callback[0])) { |
|
| 1726 | + unset($uninstall_plugins[$basename]); |
|
| 1727 | 1727 | } |
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | - update_option( 'uninstall_plugins', $uninstall_plugins ); |
|
| 1730 | + update_option('uninstall_plugins', $uninstall_plugins); |
|
| 1731 | 1731 | } |
| 1732 | 1732 | } |
| 1733 | 1733 | } |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | global $wp_current_db_version, $wpdb; |
| 1745 | 1745 | |
| 1746 | 1746 | // Always. |
| 1747 | - if ( is_main_network() ) { |
|
| 1747 | + if (is_main_network()) { |
|
| 1748 | 1748 | /* |
| 1749 | 1749 | * Deletes all expired transients. The multi-table delete syntax is used |
| 1750 | 1750 | * to delete the transient record from table a, and the corresponding |
@@ -1756,32 +1756,32 @@ discard block |
||
| 1756 | 1756 | AND a.meta_key NOT LIKE %s |
| 1757 | 1757 | AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) |
| 1758 | 1758 | AND b.meta_value < %d"; |
| 1759 | - $wpdb->query( $wpdb->prepare( $sql, $wpdb->esc_like( '_site_transient_' ) . '%', $wpdb->esc_like ( '_site_transient_timeout_' ) . '%', $time ) ); |
|
| 1759 | + $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_site_transient_').'%', $wpdb->esc_like('_site_transient_timeout_').'%', $time)); |
|
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | 1762 | // 2.8. |
| 1763 | - if ( $wp_current_db_version < 11549 ) { |
|
| 1764 | - $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); |
|
| 1765 | - $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
|
| 1766 | - if ( $wpmu_sitewide_plugins ) { |
|
| 1767 | - if ( !$active_sitewide_plugins ) |
|
| 1763 | + if ($wp_current_db_version < 11549) { |
|
| 1764 | + $wpmu_sitewide_plugins = get_site_option('wpmu_sitewide_plugins'); |
|
| 1765 | + $active_sitewide_plugins = get_site_option('active_sitewide_plugins'); |
|
| 1766 | + if ($wpmu_sitewide_plugins) { |
|
| 1767 | + if ( ! $active_sitewide_plugins) |
|
| 1768 | 1768 | $sitewide_plugins = (array) $wpmu_sitewide_plugins; |
| 1769 | 1769 | else |
| 1770 | - $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins ); |
|
| 1770 | + $sitewide_plugins = array_merge((array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins); |
|
| 1771 | 1771 | |
| 1772 | - update_site_option( 'active_sitewide_plugins', $sitewide_plugins ); |
|
| 1772 | + update_site_option('active_sitewide_plugins', $sitewide_plugins); |
|
| 1773 | 1773 | } |
| 1774 | - delete_site_option( 'wpmu_sitewide_plugins' ); |
|
| 1775 | - delete_site_option( 'deactivated_sitewide_plugins' ); |
|
| 1774 | + delete_site_option('wpmu_sitewide_plugins'); |
|
| 1775 | + delete_site_option('deactivated_sitewide_plugins'); |
|
| 1776 | 1776 | |
| 1777 | 1777 | $start = 0; |
| 1778 | - while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) { |
|
| 1779 | - foreach ( $rows as $row ) { |
|
| 1778 | + while ($rows = $wpdb->get_results("SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20")) { |
|
| 1779 | + foreach ($rows as $row) { |
|
| 1780 | 1780 | $value = $row->meta_value; |
| 1781 | - if ( !@unserialize( $value ) ) |
|
| 1782 | - $value = stripslashes( $value ); |
|
| 1783 | - if ( $value !== $row->meta_value ) { |
|
| 1784 | - update_site_option( $row->meta_key, $value ); |
|
| 1781 | + if ( ! @unserialize($value)) |
|
| 1782 | + $value = stripslashes($value); |
|
| 1783 | + if ($value !== $row->meta_value) { |
|
| 1784 | + update_site_option($row->meta_key, $value); |
|
| 1785 | 1785 | } |
| 1786 | 1786 | } |
| 1787 | 1787 | $start += 20; |
@@ -1789,95 +1789,95 @@ discard block |
||
| 1789 | 1789 | } |
| 1790 | 1790 | |
| 1791 | 1791 | // 3.0 |
| 1792 | - if ( $wp_current_db_version < 13576 ) |
|
| 1793 | - update_site_option( 'global_terms_enabled', '1' ); |
|
| 1792 | + if ($wp_current_db_version < 13576) |
|
| 1793 | + update_site_option('global_terms_enabled', '1'); |
|
| 1794 | 1794 | |
| 1795 | 1795 | // 3.3 |
| 1796 | - if ( $wp_current_db_version < 19390 ) |
|
| 1797 | - update_site_option( 'initial_db_version', $wp_current_db_version ); |
|
| 1796 | + if ($wp_current_db_version < 19390) |
|
| 1797 | + update_site_option('initial_db_version', $wp_current_db_version); |
|
| 1798 | 1798 | |
| 1799 | - if ( $wp_current_db_version < 19470 ) { |
|
| 1800 | - if ( false === get_site_option( 'active_sitewide_plugins' ) ) |
|
| 1801 | - update_site_option( 'active_sitewide_plugins', array() ); |
|
| 1799 | + if ($wp_current_db_version < 19470) { |
|
| 1800 | + if (false === get_site_option('active_sitewide_plugins')) |
|
| 1801 | + update_site_option('active_sitewide_plugins', array()); |
|
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | 1804 | // 3.4 |
| 1805 | - if ( $wp_current_db_version < 20148 ) { |
|
| 1805 | + if ($wp_current_db_version < 20148) { |
|
| 1806 | 1806 | // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
| 1807 | - $allowedthemes = get_site_option( 'allowedthemes' ); |
|
| 1808 | - $allowed_themes = get_site_option( 'allowed_themes' ); |
|
| 1809 | - if ( false === $allowedthemes && is_array( $allowed_themes ) && $allowed_themes ) { |
|
| 1807 | + $allowedthemes = get_site_option('allowedthemes'); |
|
| 1808 | + $allowed_themes = get_site_option('allowed_themes'); |
|
| 1809 | + if (false === $allowedthemes && is_array($allowed_themes) && $allowed_themes) { |
|
| 1810 | 1810 | $converted = array(); |
| 1811 | 1811 | $themes = wp_get_themes(); |
| 1812 | - foreach ( $themes as $stylesheet => $theme_data ) { |
|
| 1813 | - if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) ) |
|
| 1814 | - $converted[ $stylesheet ] = true; |
|
| 1812 | + foreach ($themes as $stylesheet => $theme_data) { |
|
| 1813 | + if (isset($allowed_themes[$theme_data->get('Name')])) |
|
| 1814 | + $converted[$stylesheet] = true; |
|
| 1815 | 1815 | } |
| 1816 | - update_site_option( 'allowedthemes', $converted ); |
|
| 1817 | - delete_site_option( 'allowed_themes' ); |
|
| 1816 | + update_site_option('allowedthemes', $converted); |
|
| 1817 | + delete_site_option('allowed_themes'); |
|
| 1818 | 1818 | } |
| 1819 | 1819 | } |
| 1820 | 1820 | |
| 1821 | 1821 | // 3.5 |
| 1822 | - if ( $wp_current_db_version < 21823 ) |
|
| 1823 | - update_site_option( 'ms_files_rewriting', '1' ); |
|
| 1822 | + if ($wp_current_db_version < 21823) |
|
| 1823 | + update_site_option('ms_files_rewriting', '1'); |
|
| 1824 | 1824 | |
| 1825 | 1825 | // 3.5.2 |
| 1826 | - if ( $wp_current_db_version < 24448 ) { |
|
| 1827 | - $illegal_names = get_site_option( 'illegal_names' ); |
|
| 1828 | - if ( is_array( $illegal_names ) && count( $illegal_names ) === 1 ) { |
|
| 1829 | - $illegal_name = reset( $illegal_names ); |
|
| 1830 | - $illegal_names = explode( ' ', $illegal_name ); |
|
| 1831 | - update_site_option( 'illegal_names', $illegal_names ); |
|
| 1826 | + if ($wp_current_db_version < 24448) { |
|
| 1827 | + $illegal_names = get_site_option('illegal_names'); |
|
| 1828 | + if (is_array($illegal_names) && count($illegal_names) === 1) { |
|
| 1829 | + $illegal_name = reset($illegal_names); |
|
| 1830 | + $illegal_names = explode(' ', $illegal_name); |
|
| 1831 | + update_site_option('illegal_names', $illegal_names); |
|
| 1832 | 1832 | } |
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | // 4.2 |
| 1836 | - if ( $wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4' ) { |
|
| 1837 | - if ( wp_should_upgrade_global_tables() ) { |
|
| 1838 | - $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 1839 | - $wpdb->query( "ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))" ); |
|
| 1840 | - $wpdb->query( "ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 1841 | - $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" ); |
|
| 1836 | + if ($wp_current_db_version < 31351 && $wpdb->charset === 'utf8mb4') { |
|
| 1837 | + if (wp_should_upgrade_global_tables()) { |
|
| 1838 | + $wpdb->query("ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 1839 | + $wpdb->query("ALTER TABLE $wpdb->site DROP INDEX domain, ADD INDEX domain(domain(140),path(51))"); |
|
| 1840 | + $wpdb->query("ALTER TABLE $wpdb->sitemeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 1841 | + $wpdb->query("ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))"); |
|
| 1842 | 1842 | |
| 1843 | - $tables = $wpdb->tables( 'global' ); |
|
| 1843 | + $tables = $wpdb->tables('global'); |
|
| 1844 | 1844 | |
| 1845 | 1845 | // sitecategories may not exist. |
| 1846 | - if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { |
|
| 1847 | - unset( $tables['sitecategories'] ); |
|
| 1846 | + if ( ! $wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) { |
|
| 1847 | + unset($tables['sitecategories']); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | - foreach ( $tables as $table ) { |
|
| 1851 | - maybe_convert_table_to_utf8mb4( $table ); |
|
| 1850 | + foreach ($tables as $table) { |
|
| 1851 | + maybe_convert_table_to_utf8mb4($table); |
|
| 1852 | 1852 | } |
| 1853 | 1853 | } |
| 1854 | 1854 | } |
| 1855 | 1855 | |
| 1856 | 1856 | // 4.3 |
| 1857 | - if ( $wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset ) { |
|
| 1858 | - if ( wp_should_upgrade_global_tables() ) { |
|
| 1857 | + if ($wp_current_db_version < 33055 && 'utf8mb4' === $wpdb->charset) { |
|
| 1858 | + if (wp_should_upgrade_global_tables()) { |
|
| 1859 | 1859 | $upgrade = false; |
| 1860 | - $indexes = $wpdb->get_results( "SHOW INDEXES FROM $wpdb->signups" ); |
|
| 1861 | - foreach ( $indexes as $index ) { |
|
| 1862 | - if ( 'domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part ) { |
|
| 1860 | + $indexes = $wpdb->get_results("SHOW INDEXES FROM $wpdb->signups"); |
|
| 1861 | + foreach ($indexes as $index) { |
|
| 1862 | + if ('domain_path' == $index->Key_name && 'domain' == $index->Column_name && 140 != $index->Sub_part) { |
|
| 1863 | 1863 | $upgrade = true; |
| 1864 | 1864 | break; |
| 1865 | 1865 | } |
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | - if ( $upgrade ) { |
|
| 1869 | - $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))" ); |
|
| 1868 | + if ($upgrade) { |
|
| 1869 | + $wpdb->query("ALTER TABLE $wpdb->signups DROP INDEX domain_path, ADD INDEX domain_path(domain(140),path(51))"); |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | - $tables = $wpdb->tables( 'global' ); |
|
| 1872 | + $tables = $wpdb->tables('global'); |
|
| 1873 | 1873 | |
| 1874 | 1874 | // sitecategories may not exist. |
| 1875 | - if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$tables['sitecategories']}'" ) ) { |
|
| 1876 | - unset( $tables['sitecategories'] ); |
|
| 1875 | + if ( ! $wpdb->get_var("SHOW TABLES LIKE '{$tables['sitecategories']}'")) { |
|
| 1876 | + unset($tables['sitecategories']); |
|
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | - foreach ( $tables as $table ) { |
|
| 1880 | - maybe_convert_table_to_utf8mb4( $table ); |
|
| 1879 | + foreach ($tables as $table) { |
|
| 1880 | + maybe_convert_table_to_utf8mb4($table); |
|
| 1881 | 1881 | } |
| 1882 | 1882 | } |
| 1883 | 1883 | } |
@@ -1905,9 +1905,9 @@ discard block |
||
| 1905 | 1905 | function maybe_create_table($table_name, $create_ddl) { |
| 1906 | 1906 | global $wpdb; |
| 1907 | 1907 | |
| 1908 | - $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_name ) ); |
|
| 1908 | + $query = $wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($table_name)); |
|
| 1909 | 1909 | |
| 1910 | - if ( $wpdb->get_var( $query ) == $table_name ) { |
|
| 1910 | + if ($wpdb->get_var($query) == $table_name) { |
|
| 1911 | 1911 | return true; |
| 1912 | 1912 | } |
| 1913 | 1913 | |
@@ -1915,7 +1915,7 @@ discard block |
||
| 1915 | 1915 | $wpdb->query($create_ddl); |
| 1916 | 1916 | |
| 1917 | 1917 | // We cannot directly tell that whether this succeeded! |
| 1918 | - if ( $wpdb->get_var( $query ) == $table_name ) { |
|
| 1918 | + if ($wpdb->get_var($query) == $table_name) { |
|
| 1919 | 1919 | return true; |
| 1920 | 1920 | } |
| 1921 | 1921 | return false; |
@@ -1976,7 +1976,7 @@ discard block |
||
| 1976 | 1976 | */ |
| 1977 | 1977 | function maybe_add_column($table_name, $column_name, $create_ddl) { |
| 1978 | 1978 | global $wpdb; |
| 1979 | - foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { |
|
| 1979 | + foreach ($wpdb->get_col("DESC $table_name", 0) as $column) { |
|
| 1980 | 1980 | if ($column == $column_name) { |
| 1981 | 1981 | return true; |
| 1982 | 1982 | } |
@@ -1986,7 +1986,7 @@ discard block |
||
| 1986 | 1986 | $wpdb->query($create_ddl); |
| 1987 | 1987 | |
| 1988 | 1988 | // We cannot directly tell that whether this succeeded! |
| 1989 | - foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) { |
|
| 1989 | + foreach ($wpdb->get_col("DESC $table_name", 0) as $column) { |
|
| 1990 | 1990 | if ($column == $column_name) { |
| 1991 | 1991 | return true; |
| 1992 | 1992 | } |
@@ -2004,37 +2004,37 @@ discard block |
||
| 2004 | 2004 | * @param string $table The table to convert. |
| 2005 | 2005 | * @return bool true if the table was converted, false if it wasn't. |
| 2006 | 2006 | */ |
| 2007 | -function maybe_convert_table_to_utf8mb4( $table ) { |
|
| 2007 | +function maybe_convert_table_to_utf8mb4($table) { |
|
| 2008 | 2008 | global $wpdb; |
| 2009 | 2009 | |
| 2010 | - $results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" ); |
|
| 2011 | - if ( ! $results ) { |
|
| 2010 | + $results = $wpdb->get_results("SHOW FULL COLUMNS FROM `$table`"); |
|
| 2011 | + if ( ! $results) { |
|
| 2012 | 2012 | return false; |
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | - foreach ( $results as $column ) { |
|
| 2016 | - if ( $column->Collation ) { |
|
| 2017 | - list( $charset ) = explode( '_', $column->Collation ); |
|
| 2018 | - $charset = strtolower( $charset ); |
|
| 2019 | - if ( 'utf8' !== $charset && 'utf8mb4' !== $charset ) { |
|
| 2015 | + foreach ($results as $column) { |
|
| 2016 | + if ($column->Collation) { |
|
| 2017 | + list($charset) = explode('_', $column->Collation); |
|
| 2018 | + $charset = strtolower($charset); |
|
| 2019 | + if ('utf8' !== $charset && 'utf8mb4' !== $charset) { |
|
| 2020 | 2020 | // Don't upgrade tables that have non-utf8 columns. |
| 2021 | 2021 | return false; |
| 2022 | 2022 | } |
| 2023 | 2023 | } |
| 2024 | 2024 | } |
| 2025 | 2025 | |
| 2026 | - $table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" ); |
|
| 2027 | - if ( ! $table_details ) { |
|
| 2026 | + $table_details = $wpdb->get_row("SHOW TABLE STATUS LIKE '$table'"); |
|
| 2027 | + if ( ! $table_details) { |
|
| 2028 | 2028 | return false; |
| 2029 | 2029 | } |
| 2030 | 2030 | |
| 2031 | - list( $table_charset ) = explode( '_', $table_details->Collation ); |
|
| 2032 | - $table_charset = strtolower( $table_charset ); |
|
| 2033 | - if ( 'utf8mb4' === $table_charset ) { |
|
| 2031 | + list($table_charset) = explode('_', $table_details->Collation); |
|
| 2032 | + $table_charset = strtolower($table_charset); |
|
| 2033 | + if ('utf8mb4' === $table_charset) { |
|
| 2034 | 2034 | return true; |
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | - return $wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci" ); |
|
| 2037 | + return $wpdb->query("ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); |
|
| 2038 | 2038 | } |
| 2039 | 2039 | |
| 2040 | 2040 | /** |
@@ -2049,11 +2049,11 @@ discard block |
||
| 2049 | 2049 | function get_alloptions_110() { |
| 2050 | 2050 | global $wpdb; |
| 2051 | 2051 | $all_options = new stdClass; |
| 2052 | - if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) { |
|
| 2053 | - foreach ( $options as $option ) { |
|
| 2054 | - if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name ) |
|
| 2055 | - $option->option_value = untrailingslashit( $option->option_value ); |
|
| 2056 | - $all_options->{$option->option_name} = stripslashes( $option->option_value ); |
|
| 2052 | + if ($options = $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options")) { |
|
| 2053 | + foreach ($options as $option) { |
|
| 2054 | + if ('siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name) |
|
| 2055 | + $option->option_value = untrailingslashit($option->option_value); |
|
| 2056 | + $all_options->{$option->option_name} = stripslashes($option->option_value); |
|
| 2057 | 2057 | } |
| 2058 | 2058 | } |
| 2059 | 2059 | return $all_options; |
@@ -2074,21 +2074,21 @@ discard block |
||
| 2074 | 2074 | function __get_option($setting) { |
| 2075 | 2075 | global $wpdb; |
| 2076 | 2076 | |
| 2077 | - if ( $setting == 'home' && defined( 'WP_HOME' ) ) |
|
| 2078 | - return untrailingslashit( WP_HOME ); |
|
| 2077 | + if ($setting == 'home' && defined('WP_HOME')) |
|
| 2078 | + return untrailingslashit(WP_HOME); |
|
| 2079 | 2079 | |
| 2080 | - if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) |
|
| 2081 | - return untrailingslashit( WP_SITEURL ); |
|
| 2080 | + if ($setting == 'siteurl' && defined('WP_SITEURL')) |
|
| 2081 | + return untrailingslashit(WP_SITEURL); |
|
| 2082 | 2082 | |
| 2083 | - $option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) ); |
|
| 2083 | + $option = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting)); |
|
| 2084 | 2084 | |
| 2085 | - if ( 'home' == $setting && '' == $option ) |
|
| 2086 | - return __get_option( 'siteurl' ); |
|
| 2085 | + if ('home' == $setting && '' == $option) |
|
| 2086 | + return __get_option('siteurl'); |
|
| 2087 | 2087 | |
| 2088 | - if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) |
|
| 2089 | - $option = untrailingslashit( $option ); |
|
| 2088 | + if ('siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting) |
|
| 2089 | + $option = untrailingslashit($option); |
|
| 2090 | 2090 | |
| 2091 | - return maybe_unserialize( $option ); |
|
| 2091 | + return maybe_unserialize($option); |
|
| 2092 | 2092 | } |
| 2093 | 2093 | |
| 2094 | 2094 | /** |
@@ -2136,16 +2136,16 @@ discard block |
||
| 2136 | 2136 | * Default true. |
| 2137 | 2137 | * @return array Strings containing the results of the various update queries. |
| 2138 | 2138 | */ |
| 2139 | -function dbDelta( $queries = '', $execute = true ) { |
|
| 2139 | +function dbDelta($queries = '', $execute = true) { |
|
| 2140 | 2140 | global $wpdb; |
| 2141 | 2141 | |
| 2142 | - if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) |
|
| 2143 | - $queries = wp_get_db_schema( $queries ); |
|
| 2142 | + if (in_array($queries, array('', 'all', 'blog', 'global', 'ms_global'), true)) |
|
| 2143 | + $queries = wp_get_db_schema($queries); |
|
| 2144 | 2144 | |
| 2145 | 2145 | // Separate individual queries into an array |
| 2146 | - if ( !is_array($queries) ) { |
|
| 2147 | - $queries = explode( ';', $queries ); |
|
| 2148 | - $queries = array_filter( $queries ); |
|
| 2146 | + if ( ! is_array($queries)) { |
|
| 2147 | + $queries = explode(';', $queries); |
|
| 2148 | + $queries = array_filter($queries); |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | 2151 | /** |
@@ -2155,7 +2155,7 @@ discard block |
||
| 2155 | 2155 | * |
| 2156 | 2156 | * @param array $queries An array of dbDelta SQL queries. |
| 2157 | 2157 | */ |
| 2158 | - $queries = apply_filters( 'dbdelta_queries', $queries ); |
|
| 2158 | + $queries = apply_filters('dbdelta_queries', $queries); |
|
| 2159 | 2159 | |
| 2160 | 2160 | $cqueries = array(); // Creation Queries |
| 2161 | 2161 | $iqueries = array(); // Insertion Queries |
@@ -2163,14 +2163,14 @@ discard block |
||
| 2163 | 2163 | |
| 2164 | 2164 | // Create a tablename index for an array ($cqueries) of queries |
| 2165 | 2165 | foreach ($queries as $qry) { |
| 2166 | - if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) { |
|
| 2167 | - $cqueries[ trim( $matches[1], '`' ) ] = $qry; |
|
| 2166 | + if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) { |
|
| 2167 | + $cqueries[trim($matches[1], '`')] = $qry; |
|
| 2168 | 2168 | $for_update[$matches[1]] = 'Created table '.$matches[1]; |
| 2169 | - } elseif ( preg_match( "|CREATE DATABASE ([^ ]*)|", $qry, $matches ) ) { |
|
| 2170 | - array_unshift( $cqueries, $qry ); |
|
| 2171 | - } elseif ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) { |
|
| 2169 | + } elseif (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) { |
|
| 2170 | + array_unshift($cqueries, $qry); |
|
| 2171 | + } elseif (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) { |
|
| 2172 | 2172 | $iqueries[] = $qry; |
| 2173 | - } elseif ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) { |
|
| 2173 | + } elseif (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) { |
|
| 2174 | 2174 | $iqueries[] = $qry; |
| 2175 | 2175 | } else { |
| 2176 | 2176 | // Unrecognized query type |
@@ -2186,7 +2186,7 @@ discard block |
||
| 2186 | 2186 | * |
| 2187 | 2187 | * @param array $cqueries An array of dbDelta create SQL queries. |
| 2188 | 2188 | */ |
| 2189 | - $cqueries = apply_filters( 'dbdelta_create_queries', $cqueries ); |
|
| 2189 | + $cqueries = apply_filters('dbdelta_create_queries', $cqueries); |
|
| 2190 | 2190 | |
| 2191 | 2191 | /** |
| 2192 | 2192 | * Filters the dbDelta SQL queries for inserting or updating. |
@@ -2197,25 +2197,25 @@ discard block |
||
| 2197 | 2197 | * |
| 2198 | 2198 | * @param array $iqueries An array of dbDelta insert or update SQL queries. |
| 2199 | 2199 | */ |
| 2200 | - $iqueries = apply_filters( 'dbdelta_insert_queries', $iqueries ); |
|
| 2200 | + $iqueries = apply_filters('dbdelta_insert_queries', $iqueries); |
|
| 2201 | 2201 | |
| 2202 | - $text_fields = array( 'tinytext', 'text', 'mediumtext', 'longtext' ); |
|
| 2203 | - $blob_fields = array( 'tinyblob', 'blob', 'mediumblob', 'longblob' ); |
|
| 2202 | + $text_fields = array('tinytext', 'text', 'mediumtext', 'longtext'); |
|
| 2203 | + $blob_fields = array('tinyblob', 'blob', 'mediumblob', 'longblob'); |
|
| 2204 | 2204 | |
| 2205 | - $global_tables = $wpdb->tables( 'global' ); |
|
| 2206 | - foreach ( $cqueries as $table => $qry ) { |
|
| 2205 | + $global_tables = $wpdb->tables('global'); |
|
| 2206 | + foreach ($cqueries as $table => $qry) { |
|
| 2207 | 2207 | // Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal. |
| 2208 | - if ( in_array( $table, $global_tables ) && ! wp_should_upgrade_global_tables() ) { |
|
| 2209 | - unset( $cqueries[ $table ], $for_update[ $table ] ); |
|
| 2208 | + if (in_array($table, $global_tables) && ! wp_should_upgrade_global_tables()) { |
|
| 2209 | + unset($cqueries[$table], $for_update[$table]); |
|
| 2210 | 2210 | continue; |
| 2211 | 2211 | } |
| 2212 | 2212 | |
| 2213 | 2213 | // Fetch the table column structure from the database |
| 2214 | 2214 | $suppress = $wpdb->suppress_errors(); |
| 2215 | 2215 | $tablefields = $wpdb->get_results("DESCRIBE {$table};"); |
| 2216 | - $wpdb->suppress_errors( $suppress ); |
|
| 2216 | + $wpdb->suppress_errors($suppress); |
|
| 2217 | 2217 | |
| 2218 | - if ( ! $tablefields ) |
|
| 2218 | + if ( ! $tablefields) |
|
| 2219 | 2219 | continue; |
| 2220 | 2220 | |
| 2221 | 2221 | // Clear the field and index arrays. |
@@ -2229,17 +2229,17 @@ discard block |
||
| 2229 | 2229 | $flds = explode("\n", $qryline); |
| 2230 | 2230 | |
| 2231 | 2231 | // For every field line specified in the query. |
| 2232 | - foreach ( $flds as $fld ) { |
|
| 2233 | - $fld = trim( $fld, " \t\n\r\0\x0B," ); // Default trim characters, plus ','. |
|
| 2232 | + foreach ($flds as $fld) { |
|
| 2233 | + $fld = trim($fld, " \t\n\r\0\x0B,"); // Default trim characters, plus ','. |
|
| 2234 | 2234 | |
| 2235 | 2235 | // Extract the field name. |
| 2236 | - preg_match( '|^([^ ]*)|', $fld, $fvals ); |
|
| 2237 | - $fieldname = trim( $fvals[1], '`' ); |
|
| 2238 | - $fieldname_lowercased = strtolower( $fieldname ); |
|
| 2236 | + preg_match('|^([^ ]*)|', $fld, $fvals); |
|
| 2237 | + $fieldname = trim($fvals[1], '`'); |
|
| 2238 | + $fieldname_lowercased = strtolower($fieldname); |
|
| 2239 | 2239 | |
| 2240 | 2240 | // Verify the found field name. |
| 2241 | 2241 | $validfield = true; |
| 2242 | - switch ( $fieldname_lowercased ) { |
|
| 2242 | + switch ($fieldname_lowercased) { |
|
| 2243 | 2243 | case '': |
| 2244 | 2244 | case 'primary': |
| 2245 | 2245 | case 'index': |
@@ -2283,19 +2283,19 @@ discard block |
||
| 2283 | 2283 | ); |
| 2284 | 2284 | |
| 2285 | 2285 | // Uppercase the index type and normalize space characters. |
| 2286 | - $index_type = strtoupper( preg_replace( '/\s+/', ' ', trim( $index_matches['index_type'] ) ) ); |
|
| 2286 | + $index_type = strtoupper(preg_replace('/\s+/', ' ', trim($index_matches['index_type']))); |
|
| 2287 | 2287 | |
| 2288 | 2288 | // 'INDEX' is a synonym for 'KEY', standardize on 'KEY'. |
| 2289 | - $index_type = str_replace( 'INDEX', 'KEY', $index_type ); |
|
| 2289 | + $index_type = str_replace('INDEX', 'KEY', $index_type); |
|
| 2290 | 2290 | |
| 2291 | 2291 | // Escape the index name with backticks. An index for a primary key has no name. |
| 2292 | - $index_name = ( 'PRIMARY KEY' === $index_type ) ? '' : '`' . strtolower( $index_matches['index_name'] ) . '`'; |
|
| 2292 | + $index_name = ('PRIMARY KEY' === $index_type) ? '' : '`'.strtolower($index_matches['index_name']).'`'; |
|
| 2293 | 2293 | |
| 2294 | 2294 | // Parse the columns. Multiple columns are separated by a comma. |
| 2295 | - $index_columns = $index_columns_without_subparts = array_map( 'trim', explode( ',', $index_matches['index_columns'] ) ); |
|
| 2295 | + $index_columns = $index_columns_without_subparts = array_map('trim', explode(',', $index_matches['index_columns'])); |
|
| 2296 | 2296 | |
| 2297 | 2297 | // Normalize columns. |
| 2298 | - foreach ( $index_columns as $id => &$index_column ) { |
|
| 2298 | + foreach ($index_columns as $id => &$index_column) { |
|
| 2299 | 2299 | // Extract column name and number of indexed characters (sub_part). |
| 2300 | 2300 | preg_match( |
| 2301 | 2301 | '/' |
@@ -2320,70 +2320,70 @@ discard block |
||
| 2320 | 2320 | ); |
| 2321 | 2321 | |
| 2322 | 2322 | // Escape the column name with backticks. |
| 2323 | - $index_column = '`' . $index_column_matches['column_name'] . '`'; |
|
| 2323 | + $index_column = '`'.$index_column_matches['column_name'].'`'; |
|
| 2324 | 2324 | |
| 2325 | 2325 | // We don't need to add the subpart to $index_columns_without_subparts |
| 2326 | - $index_columns_without_subparts[ $id ] = $index_column; |
|
| 2326 | + $index_columns_without_subparts[$id] = $index_column; |
|
| 2327 | 2327 | |
| 2328 | 2328 | // Append the optional sup part with the number of indexed characters. |
| 2329 | - if ( isset( $index_column_matches['sub_part'] ) ) { |
|
| 2330 | - $index_column .= '(' . $index_column_matches['sub_part'] . ')'; |
|
| 2329 | + if (isset($index_column_matches['sub_part'])) { |
|
| 2330 | + $index_column .= '('.$index_column_matches['sub_part'].')'; |
|
| 2331 | 2331 | } |
| 2332 | 2332 | } |
| 2333 | 2333 | |
| 2334 | 2334 | // Build the normalized index definition and add it to the list of indices. |
| 2335 | - $indices[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns ) . ")"; |
|
| 2336 | - $indices_without_subparts[] = "{$index_type} {$index_name} (" . implode( ',', $index_columns_without_subparts ) . ")"; |
|
| 2335 | + $indices[] = "{$index_type} {$index_name} (".implode(',', $index_columns).")"; |
|
| 2336 | + $indices_without_subparts[] = "{$index_type} {$index_name} (".implode(',', $index_columns_without_subparts).")"; |
|
| 2337 | 2337 | |
| 2338 | 2338 | // Destroy no longer needed variables. |
| 2339 | - unset( $index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts ); |
|
| 2339 | + unset($index_column, $index_column_matches, $index_matches, $index_type, $index_name, $index_columns, $index_columns_without_subparts); |
|
| 2340 | 2340 | |
| 2341 | 2341 | break; |
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | // If it's a valid field, add it to the field array. |
| 2345 | - if ( $validfield ) { |
|
| 2346 | - $cfields[ $fieldname_lowercased ] = $fld; |
|
| 2345 | + if ($validfield) { |
|
| 2346 | + $cfields[$fieldname_lowercased] = $fld; |
|
| 2347 | 2347 | } |
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | 2350 | // For every field in the table. |
| 2351 | - foreach ( $tablefields as $tablefield ) { |
|
| 2352 | - $tablefield_field_lowercased = strtolower( $tablefield->Field ); |
|
| 2353 | - $tablefield_type_lowercased = strtolower( $tablefield->Type ); |
|
| 2351 | + foreach ($tablefields as $tablefield) { |
|
| 2352 | + $tablefield_field_lowercased = strtolower($tablefield->Field); |
|
| 2353 | + $tablefield_type_lowercased = strtolower($tablefield->Type); |
|
| 2354 | 2354 | |
| 2355 | 2355 | // If the table field exists in the field array ... |
| 2356 | - if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { |
|
| 2356 | + if (array_key_exists($tablefield_field_lowercased, $cfields)) { |
|
| 2357 | 2357 | |
| 2358 | 2358 | // Get the field type from the query. |
| 2359 | - preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches ); |
|
| 2359 | + preg_match('|`?'.$tablefield->Field.'`? ([^ ]*( unsigned)?)|i', $cfields[$tablefield_field_lowercased], $matches); |
|
| 2360 | 2360 | $fieldtype = $matches[1]; |
| 2361 | - $fieldtype_lowercased = strtolower( $fieldtype ); |
|
| 2361 | + $fieldtype_lowercased = strtolower($fieldtype); |
|
| 2362 | 2362 | |
| 2363 | 2363 | // Is actual field type different from the field type in query? |
| 2364 | 2364 | if ($tablefield->Type != $fieldtype) { |
| 2365 | 2365 | $do_change = true; |
| 2366 | - if ( in_array( $fieldtype_lowercased, $text_fields ) && in_array( $tablefield_type_lowercased, $text_fields ) ) { |
|
| 2367 | - if ( array_search( $fieldtype_lowercased, $text_fields ) < array_search( $tablefield_type_lowercased, $text_fields ) ) { |
|
| 2366 | + if (in_array($fieldtype_lowercased, $text_fields) && in_array($tablefield_type_lowercased, $text_fields)) { |
|
| 2367 | + if (array_search($fieldtype_lowercased, $text_fields) < array_search($tablefield_type_lowercased, $text_fields)) { |
|
| 2368 | 2368 | $do_change = false; |
| 2369 | 2369 | } |
| 2370 | 2370 | } |
| 2371 | 2371 | |
| 2372 | - if ( in_array( $fieldtype_lowercased, $blob_fields ) && in_array( $tablefield_type_lowercased, $blob_fields ) ) { |
|
| 2373 | - if ( array_search( $fieldtype_lowercased, $blob_fields ) < array_search( $tablefield_type_lowercased, $blob_fields ) ) { |
|
| 2372 | + if (in_array($fieldtype_lowercased, $blob_fields) && in_array($tablefield_type_lowercased, $blob_fields)) { |
|
| 2373 | + if (array_search($fieldtype_lowercased, $blob_fields) < array_search($tablefield_type_lowercased, $blob_fields)) { |
|
| 2374 | 2374 | $do_change = false; |
| 2375 | 2375 | } |
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | - if ( $do_change ) { |
|
| 2378 | + if ($do_change) { |
|
| 2379 | 2379 | // Add a query to change the column type. |
| 2380 | - $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` " . $cfields[ $tablefield_field_lowercased ]; |
|
| 2380 | + $cqueries[] = "ALTER TABLE {$table} CHANGE COLUMN `{$tablefield->Field}` ".$cfields[$tablefield_field_lowercased]; |
|
| 2381 | 2381 | $for_update[$table.'.'.$tablefield->Field] = "Changed type of {$table}.{$tablefield->Field} from {$tablefield->Type} to {$fieldtype}"; |
| 2382 | 2382 | } |
| 2383 | 2383 | } |
| 2384 | 2384 | |
| 2385 | 2385 | // Get the default value from the array. |
| 2386 | - if ( preg_match( "| DEFAULT '(.*?)'|i", $cfields[ $tablefield_field_lowercased ], $matches ) ) { |
|
| 2386 | + if (preg_match("| DEFAULT '(.*?)'|i", $cfields[$tablefield_field_lowercased], $matches)) { |
|
| 2387 | 2387 | $default_value = $matches[1]; |
| 2388 | 2388 | if ($tablefield->Default != $default_value) { |
| 2389 | 2389 | // Add a query to change the column's default value |
@@ -2393,7 +2393,7 @@ discard block |
||
| 2393 | 2393 | } |
| 2394 | 2394 | |
| 2395 | 2395 | // Remove the field from the array (so it's not added). |
| 2396 | - unset( $cfields[ $tablefield_field_lowercased ] ); |
|
| 2396 | + unset($cfields[$tablefield_field_lowercased]); |
|
| 2397 | 2397 | } else { |
| 2398 | 2398 | // This field exists in the table, but not in the creation queries? |
| 2399 | 2399 | } |
@@ -2417,9 +2417,9 @@ discard block |
||
| 2417 | 2417 | foreach ($tableindices as $tableindex) { |
| 2418 | 2418 | |
| 2419 | 2419 | // Add the index to the index data array. |
| 2420 | - $keyname = strtolower( $tableindex->Key_name ); |
|
| 2420 | + $keyname = strtolower($tableindex->Key_name); |
|
| 2421 | 2421 | $index_ary[$keyname]['columns'][] = array('fieldname' => $tableindex->Column_name, 'subpart' => $tableindex->Sub_part); |
| 2422 | - $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0)?true:false; |
|
| 2422 | + $index_ary[$keyname]['unique'] = ($tableindex->Non_unique == 0) ? true : false; |
|
| 2423 | 2423 | $index_ary[$keyname]['index_type'] = $tableindex->Index_type; |
| 2424 | 2424 | } |
| 2425 | 2425 | |
@@ -2430,52 +2430,52 @@ discard block |
||
| 2430 | 2430 | $index_string = ''; |
| 2431 | 2431 | if ($index_name == 'primary') { |
| 2432 | 2432 | $index_string .= 'PRIMARY '; |
| 2433 | - } elseif ( $index_data['unique'] ) { |
|
| 2433 | + } elseif ($index_data['unique']) { |
|
| 2434 | 2434 | $index_string .= 'UNIQUE '; |
| 2435 | 2435 | } |
| 2436 | - if ( 'FULLTEXT' === strtoupper( $index_data['index_type'] ) ) { |
|
| 2436 | + if ('FULLTEXT' === strtoupper($index_data['index_type'])) { |
|
| 2437 | 2437 | $index_string .= 'FULLTEXT '; |
| 2438 | 2438 | } |
| 2439 | - if ( 'SPATIAL' === strtoupper( $index_data['index_type'] ) ) { |
|
| 2439 | + if ('SPATIAL' === strtoupper($index_data['index_type'])) { |
|
| 2440 | 2440 | $index_string .= 'SPATIAL '; |
| 2441 | 2441 | } |
| 2442 | 2442 | $index_string .= 'KEY '; |
| 2443 | - if ( 'primary' !== $index_name ) { |
|
| 2444 | - $index_string .= '`' . $index_name . '`'; |
|
| 2443 | + if ('primary' !== $index_name) { |
|
| 2444 | + $index_string .= '`'.$index_name.'`'; |
|
| 2445 | 2445 | } |
| 2446 | 2446 | $index_columns = ''; |
| 2447 | 2447 | |
| 2448 | 2448 | // For each column in the index. |
| 2449 | 2449 | foreach ($index_data['columns'] as $column_data) { |
| 2450 | - if ( $index_columns != '' ) { |
|
| 2450 | + if ($index_columns != '') { |
|
| 2451 | 2451 | $index_columns .= ','; |
| 2452 | 2452 | } |
| 2453 | 2453 | |
| 2454 | 2454 | // Add the field to the column list string. |
| 2455 | - $index_columns .= '`' . $column_data['fieldname'] . '`'; |
|
| 2455 | + $index_columns .= '`'.$column_data['fieldname'].'`'; |
|
| 2456 | 2456 | } |
| 2457 | 2457 | |
| 2458 | 2458 | // Add the column list to the index create string. |
| 2459 | 2459 | $index_string .= " ($index_columns)"; |
| 2460 | 2460 | |
| 2461 | 2461 | // Check if the index definition exists, ignoring subparts. |
| 2462 | - if ( ! ( ( $aindex = array_search( $index_string, $indices_without_subparts ) ) === false ) ) { |
|
| 2462 | + if ( ! (($aindex = array_search($index_string, $indices_without_subparts)) === false)) { |
|
| 2463 | 2463 | // If the index already exists (even with different subparts), we don't need to create it. |
| 2464 | - unset( $indices_without_subparts[ $aindex ] ); |
|
| 2465 | - unset( $indices[ $aindex ] ); |
|
| 2464 | + unset($indices_without_subparts[$aindex]); |
|
| 2465 | + unset($indices[$aindex]); |
|
| 2466 | 2466 | } |
| 2467 | 2467 | } |
| 2468 | 2468 | } |
| 2469 | 2469 | |
| 2470 | 2470 | // For every remaining index specified for the table. |
| 2471 | - foreach ( (array) $indices as $index ) { |
|
| 2471 | + foreach ((array) $indices as $index) { |
|
| 2472 | 2472 | // Push a query line into $cqueries that adds the index to that table. |
| 2473 | 2473 | $cqueries[] = "ALTER TABLE {$table} ADD $index"; |
| 2474 | - $for_update[] = 'Added index ' . $table . ' ' . $index; |
|
| 2474 | + $for_update[] = 'Added index '.$table.' '.$index; |
|
| 2475 | 2475 | } |
| 2476 | 2476 | |
| 2477 | 2477 | // Remove the original table creation query from processing. |
| 2478 | - unset( $cqueries[ $table ], $for_update[ $table ] ); |
|
| 2478 | + unset($cqueries[$table], $for_update[$table]); |
|
| 2479 | 2479 | } |
| 2480 | 2480 | |
| 2481 | 2481 | $allqueries = array_merge($cqueries, $iqueries); |
@@ -2500,8 +2500,8 @@ discard block |
||
| 2500 | 2500 | * |
| 2501 | 2501 | * @param string $tables Optional. Which set of tables to update. Default is 'all'. |
| 2502 | 2502 | */ |
| 2503 | -function make_db_current( $tables = 'all' ) { |
|
| 2504 | - $alterations = dbDelta( $tables ); |
|
| 2503 | +function make_db_current($tables = 'all') { |
|
| 2504 | + $alterations = dbDelta($tables); |
|
| 2505 | 2505 | echo "<ol>\n"; |
| 2506 | 2506 | foreach ($alterations as $alteration) echo "<li>$alteration</li>\n"; |
| 2507 | 2507 | echo "</ol>\n"; |
@@ -2519,8 +2519,8 @@ discard block |
||
| 2519 | 2519 | * |
| 2520 | 2520 | * @param string $tables Optional. Which set of tables to update. Default is 'all'. |
| 2521 | 2521 | */ |
| 2522 | -function make_db_current_silent( $tables = 'all' ) { |
|
| 2523 | - dbDelta( $tables ); |
|
| 2522 | +function make_db_current_silent($tables = 'all') { |
|
| 2523 | + dbDelta($tables); |
|
| 2524 | 2524 | } |
| 2525 | 2525 | |
| 2526 | 2526 | /** |
@@ -2536,9 +2536,9 @@ discard block |
||
| 2536 | 2536 | */ |
| 2537 | 2537 | function make_site_theme_from_oldschool($theme_name, $template) { |
| 2538 | 2538 | $home_path = get_home_path(); |
| 2539 | - $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
|
| 2539 | + $site_dir = WP_CONTENT_DIR."/themes/$template"; |
|
| 2540 | 2540 | |
| 2541 | - if (! file_exists("$home_path/index.php")) |
|
| 2541 | + if ( ! file_exists("$home_path/index.php")) |
|
| 2542 | 2542 | return false; |
| 2543 | 2543 | |
| 2544 | 2544 | /* |
@@ -2557,7 +2557,7 @@ discard block |
||
| 2557 | 2557 | if ($oldfile == 'index.php') { |
| 2558 | 2558 | $index = implode('', file("$oldpath/$oldfile")); |
| 2559 | 2559 | if (strpos($index, 'WP_USE_THEMES') !== false) { |
| 2560 | - if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) |
|
| 2560 | + if ( ! @copy(WP_CONTENT_DIR.'/themes/'.WP_DEFAULT_THEME.'/index.php', "$site_dir/$newfile")) |
|
| 2561 | 2561 | return false; |
| 2562 | 2562 | |
| 2563 | 2563 | // Don't copy anything. |
@@ -2565,7 +2565,7 @@ discard block |
||
| 2565 | 2565 | } |
| 2566 | 2566 | } |
| 2567 | 2567 | |
| 2568 | - if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) |
|
| 2568 | + if ( ! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) |
|
| 2569 | 2569 | return false; |
| 2570 | 2570 | |
| 2571 | 2571 | chmod("$site_dir/$newfile", 0777); |
@@ -2577,7 +2577,7 @@ discard block |
||
| 2577 | 2577 | |
| 2578 | 2578 | foreach ($lines as $line) { |
| 2579 | 2579 | if (preg_match('/require.*wp-blog-header/', $line)) |
| 2580 | - $line = '//' . $line; |
|
| 2580 | + $line = '//'.$line; |
|
| 2581 | 2581 | |
| 2582 | 2582 | // Update stylesheet references. |
| 2583 | 2583 | $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line); |
@@ -2592,7 +2592,7 @@ discard block |
||
| 2592 | 2592 | } |
| 2593 | 2593 | |
| 2594 | 2594 | // Add a theme header. |
| 2595 | - $header = "/*\nTheme Name: $theme_name\nTheme URI: " . __get_option('siteurl') . "\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n"; |
|
| 2595 | + $header = "/*\nTheme Name: $theme_name\nTheme URI: ".__get_option('siteurl')."\nDescription: A theme automatically created by the update.\nVersion: 1.0\nAuthor: Moi\n*/\n"; |
|
| 2596 | 2596 | |
| 2597 | 2597 | $stylelines = file_get_contents("$site_dir/style.css"); |
| 2598 | 2598 | if ($stylelines) { |
@@ -2618,18 +2618,18 @@ discard block |
||
| 2618 | 2618 | * @return false|void |
| 2619 | 2619 | */ |
| 2620 | 2620 | function make_site_theme_from_default($theme_name, $template) { |
| 2621 | - $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
|
| 2622 | - $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; |
|
| 2621 | + $site_dir = WP_CONTENT_DIR."/themes/$template"; |
|
| 2622 | + $default_dir = WP_CONTENT_DIR.'/themes/'.WP_DEFAULT_THEME; |
|
| 2623 | 2623 | |
| 2624 | 2624 | // Copy files from the default theme to the site theme. |
| 2625 | 2625 | //$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css'); |
| 2626 | 2626 | |
| 2627 | 2627 | $theme_dir = @ opendir($default_dir); |
| 2628 | 2628 | if ($theme_dir) { |
| 2629 | - while(($theme_file = readdir( $theme_dir )) !== false) { |
|
| 2629 | + while (($theme_file = readdir($theme_dir)) !== false) { |
|
| 2630 | 2630 | if (is_dir("$default_dir/$theme_file")) |
| 2631 | 2631 | continue; |
| 2632 | - if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) |
|
| 2632 | + if ( ! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) |
|
| 2633 | 2633 | return; |
| 2634 | 2634 | chmod("$site_dir/$theme_file", 0777); |
| 2635 | 2635 | } |
@@ -2642,28 +2642,28 @@ discard block |
||
| 2642 | 2642 | $f = fopen("$site_dir/style.css", 'w'); |
| 2643 | 2643 | |
| 2644 | 2644 | foreach ($stylelines as $line) { |
| 2645 | - if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; |
|
| 2646 | - elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); |
|
| 2645 | + if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: '.$theme_name; |
|
| 2646 | + elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: '.__get_option('url'); |
|
| 2647 | 2647 | elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; |
| 2648 | 2648 | elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; |
| 2649 | 2649 | elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; |
| 2650 | - fwrite($f, $line . "\n"); |
|
| 2650 | + fwrite($f, $line."\n"); |
|
| 2651 | 2651 | } |
| 2652 | 2652 | fclose($f); |
| 2653 | 2653 | } |
| 2654 | 2654 | |
| 2655 | 2655 | // Copy the images. |
| 2656 | 2656 | umask(0); |
| 2657 | - if (! mkdir("$site_dir/images", 0777)) { |
|
| 2657 | + if ( ! mkdir("$site_dir/images", 0777)) { |
|
| 2658 | 2658 | return false; |
| 2659 | 2659 | } |
| 2660 | 2660 | |
| 2661 | 2661 | $images_dir = @ opendir("$default_dir/images"); |
| 2662 | 2662 | if ($images_dir) { |
| 2663 | - while(($image = readdir($images_dir)) !== false) { |
|
| 2663 | + while (($image = readdir($images_dir)) !== false) { |
|
| 2664 | 2664 | if (is_dir("$default_dir/images/$image")) |
| 2665 | 2665 | continue; |
| 2666 | - if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) |
|
| 2666 | + if ( ! @copy("$default_dir/images/$image", "$site_dir/images/$image")) |
|
| 2667 | 2667 | return; |
| 2668 | 2668 | chmod("$site_dir/images/$image", 0777); |
| 2669 | 2669 | } |
@@ -2684,30 +2684,30 @@ discard block |
||
| 2684 | 2684 | // Name the theme after the blog. |
| 2685 | 2685 | $theme_name = __get_option('blogname'); |
| 2686 | 2686 | $template = sanitize_title($theme_name); |
| 2687 | - $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
|
| 2687 | + $site_dir = WP_CONTENT_DIR."/themes/$template"; |
|
| 2688 | 2688 | |
| 2689 | 2689 | // If the theme already exists, nothing to do. |
| 2690 | - if ( is_dir($site_dir)) { |
|
| 2690 | + if (is_dir($site_dir)) { |
|
| 2691 | 2691 | return false; |
| 2692 | 2692 | } |
| 2693 | 2693 | |
| 2694 | 2694 | // We must be able to write to the themes dir. |
| 2695 | - if (! is_writable(WP_CONTENT_DIR . "/themes")) { |
|
| 2695 | + if ( ! is_writable(WP_CONTENT_DIR."/themes")) { |
|
| 2696 | 2696 | return false; |
| 2697 | 2697 | } |
| 2698 | 2698 | |
| 2699 | 2699 | umask(0); |
| 2700 | - if (! mkdir($site_dir, 0777)) { |
|
| 2700 | + if ( ! mkdir($site_dir, 0777)) { |
|
| 2701 | 2701 | return false; |
| 2702 | 2702 | } |
| 2703 | 2703 | |
| 2704 | - if (file_exists(ABSPATH . 'wp-layout.css')) { |
|
| 2705 | - if (! make_site_theme_from_oldschool($theme_name, $template)) { |
|
| 2704 | + if (file_exists(ABSPATH.'wp-layout.css')) { |
|
| 2705 | + if ( ! make_site_theme_from_oldschool($theme_name, $template)) { |
|
| 2706 | 2706 | // TODO: rm -rf the site theme directory. |
| 2707 | 2707 | return false; |
| 2708 | 2708 | } |
| 2709 | 2709 | } else { |
| 2710 | - if (! make_site_theme_from_default($theme_name, $template)) |
|
| 2710 | + if ( ! make_site_theme_from_default($theme_name, $template)) |
|
| 2711 | 2711 | // TODO: rm -rf the site theme directory. |
| 2712 | 2712 | return false; |
| 2713 | 2713 | } |
@@ -2760,8 +2760,8 @@ discard block |
||
| 2760 | 2760 | function wp_check_mysql_version() { |
| 2761 | 2761 | global $wpdb; |
| 2762 | 2762 | $result = $wpdb->check_database_version(); |
| 2763 | - if ( is_wp_error( $result ) ) |
|
| 2764 | - die( $result->get_error_message() ); |
|
| 2763 | + if (is_wp_error($result)) |
|
| 2764 | + die($result->get_error_message()); |
|
| 2765 | 2765 | } |
| 2766 | 2766 | |
| 2767 | 2767 | /** |
@@ -2770,12 +2770,12 @@ discard block |
||
| 2770 | 2770 | * @since 2.2.0 |
| 2771 | 2771 | */ |
| 2772 | 2772 | function maybe_disable_automattic_widgets() { |
| 2773 | - $plugins = __get_option( 'active_plugins' ); |
|
| 2773 | + $plugins = __get_option('active_plugins'); |
|
| 2774 | 2774 | |
| 2775 | - foreach ( (array) $plugins as $plugin ) { |
|
| 2776 | - if ( basename( $plugin ) == 'widgets.php' ) { |
|
| 2777 | - array_splice( $plugins, array_search( $plugin, $plugins ), 1 ); |
|
| 2778 | - update_option( 'active_plugins', $plugins ); |
|
| 2775 | + foreach ((array) $plugins as $plugin) { |
|
| 2776 | + if (basename($plugin) == 'widgets.php') { |
|
| 2777 | + array_splice($plugins, array_search($plugin, $plugins), 1); |
|
| 2778 | + update_option('active_plugins', $plugins); |
|
| 2779 | 2779 | break; |
| 2780 | 2780 | } |
| 2781 | 2781 | } |
@@ -2792,8 +2792,8 @@ discard block |
||
| 2792 | 2792 | function maybe_disable_link_manager() { |
| 2793 | 2793 | global $wp_current_db_version, $wpdb; |
| 2794 | 2794 | |
| 2795 | - if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) |
|
| 2796 | - update_option( 'link_manager_enabled', 0 ); |
|
| 2795 | + if ($wp_current_db_version >= 22006 && get_option('link_manager_enabled') && ! $wpdb->get_var("SELECT link_id FROM $wpdb->links LIMIT 1")) |
|
| 2796 | + update_option('link_manager_enabled', 0); |
|
| 2797 | 2797 | } |
| 2798 | 2798 | |
| 2799 | 2799 | /** |
@@ -2808,7 +2808,7 @@ discard block |
||
| 2808 | 2808 | global $wp_current_db_version, $wpdb; |
| 2809 | 2809 | |
| 2810 | 2810 | // Upgrade versions prior to 2.9 |
| 2811 | - if ( $wp_current_db_version < 11557 ) { |
|
| 2811 | + if ($wp_current_db_version < 11557) { |
|
| 2812 | 2812 | // Delete duplicate options. Keep the option with the highest option_id. |
| 2813 | 2813 | $wpdb->query("DELETE o1 FROM $wpdb->options AS o1 JOIN $wpdb->options AS o2 USING (`option_name`) WHERE o2.option_id > o1.option_id"); |
| 2814 | 2814 | |
@@ -2820,45 +2820,45 @@ discard block |
||
| 2820 | 2820 | } |
| 2821 | 2821 | |
| 2822 | 2822 | // Multisite schema upgrades. |
| 2823 | - if ( $wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables() ) { |
|
| 2823 | + if ($wp_current_db_version < 25448 && is_multisite() && wp_should_upgrade_global_tables()) { |
|
| 2824 | 2824 | |
| 2825 | 2825 | // Upgrade versions prior to 3.7 |
| 2826 | - if ( $wp_current_db_version < 25179 ) { |
|
| 2826 | + if ($wp_current_db_version < 25179) { |
|
| 2827 | 2827 | // New primary key for signups. |
| 2828 | - $wpdb->query( "ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST" ); |
|
| 2829 | - $wpdb->query( "ALTER TABLE $wpdb->signups DROP INDEX domain" ); |
|
| 2828 | + $wpdb->query("ALTER TABLE $wpdb->signups ADD signup_id BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); |
|
| 2829 | + $wpdb->query("ALTER TABLE $wpdb->signups DROP INDEX domain"); |
|
| 2830 | 2830 | } |
| 2831 | 2831 | |
| 2832 | - if ( $wp_current_db_version < 25448 ) { |
|
| 2832 | + if ($wp_current_db_version < 25448) { |
|
| 2833 | 2833 | // Convert archived from enum to tinyint. |
| 2834 | - $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'" ); |
|
| 2835 | - $wpdb->query( "ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0" ); |
|
| 2834 | + $wpdb->query("ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived varchar(1) NOT NULL default '0'"); |
|
| 2835 | + $wpdb->query("ALTER TABLE $wpdb->blogs CHANGE COLUMN archived archived tinyint(2) NOT NULL default 0"); |
|
| 2836 | 2836 | } |
| 2837 | 2837 | } |
| 2838 | 2838 | |
| 2839 | 2839 | // Upgrade versions prior to 4.2. |
| 2840 | - if ( $wp_current_db_version < 31351 ) { |
|
| 2841 | - if ( ! is_multisite() && wp_should_upgrade_global_tables() ) { |
|
| 2842 | - $wpdb->query( "ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 2840 | + if ($wp_current_db_version < 31351) { |
|
| 2841 | + if ( ! is_multisite() && wp_should_upgrade_global_tables()) { |
|
| 2842 | + $wpdb->query("ALTER TABLE $wpdb->usermeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 2843 | 2843 | } |
| 2844 | - $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))" ); |
|
| 2845 | - $wpdb->query( "ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))" ); |
|
| 2846 | - $wpdb->query( "ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 2847 | - $wpdb->query( "ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 2848 | - $wpdb->query( "ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))" ); |
|
| 2844 | + $wpdb->query("ALTER TABLE $wpdb->terms DROP INDEX slug, ADD INDEX slug(slug(191))"); |
|
| 2845 | + $wpdb->query("ALTER TABLE $wpdb->terms DROP INDEX name, ADD INDEX name(name(191))"); |
|
| 2846 | + $wpdb->query("ALTER TABLE $wpdb->commentmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 2847 | + $wpdb->query("ALTER TABLE $wpdb->postmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 2848 | + $wpdb->query("ALTER TABLE $wpdb->posts DROP INDEX post_name, ADD INDEX post_name(post_name(191))"); |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | // Upgrade versions prior to 4.4. |
| 2852 | - if ( $wp_current_db_version < 34978 ) { |
|
| 2852 | + if ($wp_current_db_version < 34978) { |
|
| 2853 | 2853 | // If compatible termmeta table is found, use it, but enforce a proper index and update collation. |
| 2854 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->termmeta}'" ) && $wpdb->get_results( "SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'" ) ) { |
|
| 2855 | - $wpdb->query( "ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))" ); |
|
| 2856 | - maybe_convert_table_to_utf8mb4( $wpdb->termmeta ); |
|
| 2854 | + if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->termmeta}'") && $wpdb->get_results("SHOW INDEX FROM {$wpdb->termmeta} WHERE Column_name = 'meta_key'")) { |
|
| 2855 | + $wpdb->query("ALTER TABLE $wpdb->termmeta DROP INDEX meta_key, ADD INDEX meta_key(meta_key(191))"); |
|
| 2856 | + maybe_convert_table_to_utf8mb4($wpdb->termmeta); |
|
| 2857 | 2857 | } |
| 2858 | 2858 | } |
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | -if ( !function_exists( 'install_global_terms' ) ) : |
|
| 2861 | +if ( ! function_exists('install_global_terms')) : |
|
| 2862 | 2862 | /** |
| 2863 | 2863 | * Install global terms. |
| 2864 | 2864 | * |
@@ -2881,7 +2881,7 @@ discard block |
||
| 2881 | 2881 | ) $charset_collate; |
| 2882 | 2882 | "; |
| 2883 | 2883 | // now create tables |
| 2884 | - dbDelta( $ms_queries ); |
|
| 2884 | + dbDelta($ms_queries); |
|
| 2885 | 2885 | } |
| 2886 | 2886 | endif; |
| 2887 | 2887 | |
@@ -2906,7 +2906,7 @@ discard block |
||
| 2906 | 2906 | function wp_should_upgrade_global_tables() { |
| 2907 | 2907 | |
| 2908 | 2908 | // Return false early if explicitly not upgrading |
| 2909 | - if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { |
|
| 2909 | + if (defined('DO_NOT_UPGRADE_GLOBAL_TABLES')) { |
|
| 2910 | 2910 | return false; |
| 2911 | 2911 | } |
| 2912 | 2912 | |
@@ -2914,12 +2914,12 @@ discard block |
||
| 2914 | 2914 | $should_upgrade = true; |
| 2915 | 2915 | |
| 2916 | 2916 | // Set to false if not on main network (does not matter if not multi-network) |
| 2917 | - if ( ! is_main_network() ) { |
|
| 2917 | + if ( ! is_main_network()) { |
|
| 2918 | 2918 | $should_upgrade = false; |
| 2919 | 2919 | } |
| 2920 | 2920 | |
| 2921 | 2921 | // Set to false if not on main site of current network (does not matter if not multi-site) |
| 2922 | - if ( ! is_main_site() ) { |
|
| 2922 | + if ( ! is_main_site()) { |
|
| 2923 | 2923 | $should_upgrade = false; |
| 2924 | 2924 | } |
| 2925 | 2925 | |
@@ -2928,5 +2928,5 @@ discard block |
||
| 2928 | 2928 | * |
| 2929 | 2929 | * @param bool $should_upgrade Whether to run the upgrade routines on global tables. |
| 2930 | 2930 | */ |
| 2931 | - return apply_filters( 'wp_should_upgrade_global_tables', $should_upgrade ); |
|
| 2931 | + return apply_filters('wp_should_upgrade_global_tables', $should_upgrade); |
|
| 2932 | 2932 | } |
@@ -9,8 +9,9 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | /** Include user install customize script. */ |
| 12 | -if ( file_exists(WP_CONTENT_DIR . '/install.php') ) |
|
| 12 | +if ( file_exists(WP_CONTENT_DIR . '/install.php') ) { |
|
| 13 | 13 | require (WP_CONTENT_DIR . '/install.php'); |
| 14 | +} |
|
| 14 | 15 | |
| 15 | 16 | /** WordPress Administration API */ |
| 16 | 17 | require_once(ABSPATH . 'wp-admin/includes/admin.php'); |
@@ -37,8 +38,9 @@ discard block |
||
| 37 | 38 | * @return array Array keys 'url', 'user_id', 'password', and 'password_message'. |
| 38 | 39 | */ |
| 39 | 40 | function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { |
| 40 | - if ( !empty( $deprecated ) ) |
|
| 41 | - _deprecated_argument( __FUNCTION__, '2.6.0' ); |
|
| 41 | + if ( !empty( $deprecated ) ) { |
|
| 42 | + _deprecated_argument( __FUNCTION__, '2.6.0' ); |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | wp_check_mysql_version(); |
| 44 | 46 | wp_cache_flush(); |
@@ -62,8 +64,9 @@ discard block |
||
| 62 | 64 | update_option('siteurl', $guessurl); |
| 63 | 65 | |
| 64 | 66 | // If not a public blog, don't ping. |
| 65 | - if ( ! $public ) |
|
| 66 | - update_option('default_pingback_flag', 0); |
|
| 67 | + if ( ! $public ) { |
|
| 68 | + update_option('default_pingback_flag', 0); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | /* |
| 69 | 72 | * Create default user. If the user already exists, the user tables are |
@@ -218,8 +221,9 @@ discard block |
||
| 218 | 221 | )); |
| 219 | 222 | |
| 220 | 223 | // First Page |
| 221 | - if ( is_multisite() ) |
|
| 222 | - $first_page = get_site_option( 'first_page' ); |
|
| 224 | + if ( is_multisite() ) { |
|
| 225 | + $first_page = get_site_option( 'first_page' ); |
|
| 226 | + } |
|
| 223 | 227 | |
| 224 | 228 | $first_page = ! empty( $first_page ) ? $first_page : sprintf( __( "This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this: |
| 225 | 229 | |
@@ -260,10 +264,11 @@ discard block |
||
| 260 | 264 | update_option( 'widget_categories', array ( 2 => array ( 'title' => '', 'count' => 0, 'hierarchical' => 0, 'dropdown' => 0 ), '_multiwidget' => 1 ) ); |
| 261 | 265 | update_option( 'widget_meta', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) ); |
| 262 | 266 | update_option( 'sidebars_widgets', array( 'wp_inactive_widgets' => array(), 'sidebar-1' => array( 0 => 'search-2', 1 => 'recent-posts-2', 2 => 'recent-comments-2', 3 => 'archives-2', 4 => 'categories-2', 5 => 'meta-2' ), 'sidebar-2' => array(), 'sidebar-3' => array(), 'array_version' => 3 ) ); |
| 263 | - if ( ! is_multisite() ) |
|
| 264 | - update_user_meta( $user_id, 'show_welcome_panel', 1 ); |
|
| 265 | - elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) |
|
| 266 | - update_user_meta( $user_id, 'show_welcome_panel', 2 ); |
|
| 267 | + if ( ! is_multisite() ) { |
|
| 268 | + update_user_meta( $user_id, 'show_welcome_panel', 1 ); |
|
| 269 | + } elseif ( ! is_super_admin( $user_id ) && ! metadata_exists( 'user', $user_id, 'show_welcome_panel' ) ) { |
|
| 270 | + update_user_meta( $user_id, 'show_welcome_panel', 2 ); |
|
| 271 | + } |
|
| 267 | 272 | |
| 268 | 273 | if ( is_multisite() ) { |
| 269 | 274 | // Flush rules to pick up the new page. |
@@ -278,8 +283,9 @@ discard block |
||
| 278 | 283 | $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id != %d AND meta_key = %s", $user_id, $table_prefix.'capabilities') ); |
| 279 | 284 | |
| 280 | 285 | // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id. |
| 281 | - if ( !is_super_admin( $user_id ) && $user_id != 1 ) |
|
| 282 | - $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) ); |
|
| 286 | + if ( !is_super_admin( $user_id ) && $user_id != 1 ) { |
|
| 287 | + $wpdb->delete( $wpdb->usermeta, array( 'user_id' => $user_id , 'meta_key' => $wpdb->base_prefix.'1_capabilities' ) ); |
|
| 288 | + } |
|
| 283 | 289 | } |
| 284 | 290 | } |
| 285 | 291 | endif; |
@@ -417,26 +423,30 @@ discard block |
||
| 417 | 423 | $wp_current_db_version = __get_option('db_version'); |
| 418 | 424 | |
| 419 | 425 | // We are up-to-date. Nothing to do. |
| 420 | - if ( $wp_db_version == $wp_current_db_version ) |
|
| 421 | - return; |
|
| 426 | + if ( $wp_db_version == $wp_current_db_version ) { |
|
| 427 | + return; |
|
| 428 | + } |
|
| 422 | 429 | |
| 423 | - if ( ! is_blog_installed() ) |
|
| 424 | - return; |
|
| 430 | + if ( ! is_blog_installed() ) { |
|
| 431 | + return; |
|
| 432 | + } |
|
| 425 | 433 | |
| 426 | 434 | wp_check_mysql_version(); |
| 427 | 435 | wp_cache_flush(); |
| 428 | 436 | pre_schema_upgrade(); |
| 429 | 437 | make_db_current_silent(); |
| 430 | 438 | upgrade_all(); |
| 431 | - if ( is_multisite() && is_main_site() ) |
|
| 432 | - upgrade_network(); |
|
| 439 | + if ( is_multisite() && is_main_site() ) { |
|
| 440 | + upgrade_network(); |
|
| 441 | + } |
|
| 433 | 442 | wp_cache_flush(); |
| 434 | 443 | |
| 435 | 444 | if ( is_multisite() ) { |
| 436 | - if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) |
|
| 437 | - $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); |
|
| 438 | - else |
|
| 439 | - $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); |
|
| 445 | + if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'" ) ) { |
|
| 446 | + $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'" ); |
|
| 447 | + } else { |
|
| 448 | + $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());" ); |
|
| 449 | + } |
|
| 440 | 450 | } |
| 441 | 451 | |
| 442 | 452 | /** |
@@ -468,8 +478,9 @@ discard block |
||
| 468 | 478 | $wp_current_db_version = __get_option('db_version'); |
| 469 | 479 | |
| 470 | 480 | // We are up-to-date. Nothing to do. |
| 471 | - if ( $wp_db_version == $wp_current_db_version ) |
|
| 472 | - return; |
|
| 481 | + if ( $wp_db_version == $wp_current_db_version ) { |
|
| 482 | + return; |
|
| 483 | + } |
|
| 473 | 484 | |
| 474 | 485 | // If the version is not set in the DB, try to guess the version. |
| 475 | 486 | if ( empty($wp_current_db_version) ) { |
@@ -477,12 +488,14 @@ discard block |
||
| 477 | 488 | |
| 478 | 489 | // If the template option exists, we have 1.5. |
| 479 | 490 | $template = __get_option('template'); |
| 480 | - if ( !empty($template) ) |
|
| 481 | - $wp_current_db_version = 2541; |
|
| 491 | + if ( !empty($template) ) { |
|
| 492 | + $wp_current_db_version = 2541; |
|
| 493 | + } |
|
| 482 | 494 | } |
| 483 | 495 | |
| 484 | - if ( $wp_current_db_version < 6039 ) |
|
| 485 | - upgrade_230_options_table(); |
|
| 496 | + if ( $wp_current_db_version < 6039 ) { |
|
| 497 | + upgrade_230_options_table(); |
|
| 498 | + } |
|
| 486 | 499 | |
| 487 | 500 | populate_options(); |
| 488 | 501 | |
@@ -493,77 +506,101 @@ discard block |
||
| 493 | 506 | upgrade_130(); |
| 494 | 507 | } |
| 495 | 508 | |
| 496 | - if ( $wp_current_db_version < 3308 ) |
|
| 497 | - upgrade_160(); |
|
| 509 | + if ( $wp_current_db_version < 3308 ) { |
|
| 510 | + upgrade_160(); |
|
| 511 | + } |
|
| 498 | 512 | |
| 499 | - if ( $wp_current_db_version < 4772 ) |
|
| 500 | - upgrade_210(); |
|
| 513 | + if ( $wp_current_db_version < 4772 ) { |
|
| 514 | + upgrade_210(); |
|
| 515 | + } |
|
| 501 | 516 | |
| 502 | - if ( $wp_current_db_version < 4351 ) |
|
| 503 | - upgrade_old_slugs(); |
|
| 517 | + if ( $wp_current_db_version < 4351 ) { |
|
| 518 | + upgrade_old_slugs(); |
|
| 519 | + } |
|
| 504 | 520 | |
| 505 | - if ( $wp_current_db_version < 5539 ) |
|
| 506 | - upgrade_230(); |
|
| 521 | + if ( $wp_current_db_version < 5539 ) { |
|
| 522 | + upgrade_230(); |
|
| 523 | + } |
|
| 507 | 524 | |
| 508 | - if ( $wp_current_db_version < 6124 ) |
|
| 509 | - upgrade_230_old_tables(); |
|
| 525 | + if ( $wp_current_db_version < 6124 ) { |
|
| 526 | + upgrade_230_old_tables(); |
|
| 527 | + } |
|
| 510 | 528 | |
| 511 | - if ( $wp_current_db_version < 7499 ) |
|
| 512 | - upgrade_250(); |
|
| 529 | + if ( $wp_current_db_version < 7499 ) { |
|
| 530 | + upgrade_250(); |
|
| 531 | + } |
|
| 513 | 532 | |
| 514 | - if ( $wp_current_db_version < 7935 ) |
|
| 515 | - upgrade_252(); |
|
| 533 | + if ( $wp_current_db_version < 7935 ) { |
|
| 534 | + upgrade_252(); |
|
| 535 | + } |
|
| 516 | 536 | |
| 517 | - if ( $wp_current_db_version < 8201 ) |
|
| 518 | - upgrade_260(); |
|
| 537 | + if ( $wp_current_db_version < 8201 ) { |
|
| 538 | + upgrade_260(); |
|
| 539 | + } |
|
| 519 | 540 | |
| 520 | - if ( $wp_current_db_version < 8989 ) |
|
| 521 | - upgrade_270(); |
|
| 541 | + if ( $wp_current_db_version < 8989 ) { |
|
| 542 | + upgrade_270(); |
|
| 543 | + } |
|
| 522 | 544 | |
| 523 | - if ( $wp_current_db_version < 10360 ) |
|
| 524 | - upgrade_280(); |
|
| 545 | + if ( $wp_current_db_version < 10360 ) { |
|
| 546 | + upgrade_280(); |
|
| 547 | + } |
|
| 525 | 548 | |
| 526 | - if ( $wp_current_db_version < 11958 ) |
|
| 527 | - upgrade_290(); |
|
| 549 | + if ( $wp_current_db_version < 11958 ) { |
|
| 550 | + upgrade_290(); |
|
| 551 | + } |
|
| 528 | 552 | |
| 529 | - if ( $wp_current_db_version < 15260 ) |
|
| 530 | - upgrade_300(); |
|
| 553 | + if ( $wp_current_db_version < 15260 ) { |
|
| 554 | + upgrade_300(); |
|
| 555 | + } |
|
| 531 | 556 | |
| 532 | - if ( $wp_current_db_version < 19389 ) |
|
| 533 | - upgrade_330(); |
|
| 557 | + if ( $wp_current_db_version < 19389 ) { |
|
| 558 | + upgrade_330(); |
|
| 559 | + } |
|
| 534 | 560 | |
| 535 | - if ( $wp_current_db_version < 20080 ) |
|
| 536 | - upgrade_340(); |
|
| 561 | + if ( $wp_current_db_version < 20080 ) { |
|
| 562 | + upgrade_340(); |
|
| 563 | + } |
|
| 537 | 564 | |
| 538 | - if ( $wp_current_db_version < 22422 ) |
|
| 539 | - upgrade_350(); |
|
| 565 | + if ( $wp_current_db_version < 22422 ) { |
|
| 566 | + upgrade_350(); |
|
| 567 | + } |
|
| 540 | 568 | |
| 541 | - if ( $wp_current_db_version < 25824 ) |
|
| 542 | - upgrade_370(); |
|
| 569 | + if ( $wp_current_db_version < 25824 ) { |
|
| 570 | + upgrade_370(); |
|
| 571 | + } |
|
| 543 | 572 | |
| 544 | - if ( $wp_current_db_version < 26148 ) |
|
| 545 | - upgrade_372(); |
|
| 573 | + if ( $wp_current_db_version < 26148 ) { |
|
| 574 | + upgrade_372(); |
|
| 575 | + } |
|
| 546 | 576 | |
| 547 | - if ( $wp_current_db_version < 26691 ) |
|
| 548 | - upgrade_380(); |
|
| 577 | + if ( $wp_current_db_version < 26691 ) { |
|
| 578 | + upgrade_380(); |
|
| 579 | + } |
|
| 549 | 580 | |
| 550 | - if ( $wp_current_db_version < 29630 ) |
|
| 551 | - upgrade_400(); |
|
| 581 | + if ( $wp_current_db_version < 29630 ) { |
|
| 582 | + upgrade_400(); |
|
| 583 | + } |
|
| 552 | 584 | |
| 553 | - if ( $wp_current_db_version < 33055 ) |
|
| 554 | - upgrade_430(); |
|
| 585 | + if ( $wp_current_db_version < 33055 ) { |
|
| 586 | + upgrade_430(); |
|
| 587 | + } |
|
| 555 | 588 | |
| 556 | - if ( $wp_current_db_version < 33056 ) |
|
| 557 | - upgrade_431(); |
|
| 589 | + if ( $wp_current_db_version < 33056 ) { |
|
| 590 | + upgrade_431(); |
|
| 591 | + } |
|
| 558 | 592 | |
| 559 | - if ( $wp_current_db_version < 35700 ) |
|
| 560 | - upgrade_440(); |
|
| 593 | + if ( $wp_current_db_version < 35700 ) { |
|
| 594 | + upgrade_440(); |
|
| 595 | + } |
|
| 561 | 596 | |
| 562 | - if ( $wp_current_db_version < 36686 ) |
|
| 563 | - upgrade_450(); |
|
| 597 | + if ( $wp_current_db_version < 36686 ) { |
|
| 598 | + upgrade_450(); |
|
| 599 | + } |
|
| 564 | 600 | |
| 565 | - if ( $wp_current_db_version < 37965 ) |
|
| 566 | - upgrade_460(); |
|
| 601 | + if ( $wp_current_db_version < 37965 ) { |
|
| 602 | + upgrade_460(); |
|
| 603 | + } |
|
| 567 | 604 | |
| 568 | 605 | maybe_disable_link_manager(); |
| 569 | 606 | |
@@ -616,8 +653,10 @@ discard block |
||
| 616 | 653 | $done_posts[] = $done_id->post_id; |
| 617 | 654 | endforeach; |
| 618 | 655 | $catwhere = ' AND ID NOT IN (' . implode(',', $done_posts) . ')'; |
| 619 | - else: |
|
| 656 | + else { |
|
| 657 | + : |
|
| 620 | 658 | $catwhere = ''; |
| 659 | + } |
|
| 621 | 660 | endif; |
| 622 | 661 | |
| 623 | 662 | $allposts = $wpdb->get_results("SELECT ID, post_category FROM $wpdb->posts WHERE post_category != '0' $catwhere"); |
@@ -734,10 +773,11 @@ discard block |
||
| 734 | 773 | $post_content = addslashes(deslash($post->post_content)); |
| 735 | 774 | $post_title = addslashes(deslash($post->post_title)); |
| 736 | 775 | $post_excerpt = addslashes(deslash($post->post_excerpt)); |
| 737 | - if ( empty($post->guid) ) |
|
| 738 | - $guid = get_permalink($post->ID); |
|
| 739 | - else |
|
| 740 | - $guid = $post->guid; |
|
| 776 | + if ( empty($post->guid) ) { |
|
| 777 | + $guid = get_permalink($post->ID); |
|
| 778 | + } else { |
|
| 779 | + $guid = $post->guid; |
|
| 780 | + } |
|
| 741 | 781 | |
| 742 | 782 | $wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) ); |
| 743 | 783 | |
@@ -819,34 +859,57 @@ discard block |
||
| 819 | 859 | |
| 820 | 860 | $users = $wpdb->get_results("SELECT * FROM $wpdb->users"); |
| 821 | 861 | foreach ( $users as $user ) : |
| 822 | - if ( !empty( $user->user_firstname ) ) |
|
| 823 | - update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) ); |
|
| 824 | - if ( !empty( $user->user_lastname ) ) |
|
| 825 | - update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) ); |
|
| 826 | - if ( !empty( $user->user_nickname ) ) |
|
| 827 | - update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) ); |
|
| 828 | - if ( !empty( $user->user_level ) ) |
|
| 829 | - update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level ); |
|
| 830 | - if ( !empty( $user->user_icq ) ) |
|
| 831 | - update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) ); |
|
| 832 | - if ( !empty( $user->user_aim ) ) |
|
| 833 | - update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) ); |
|
| 834 | - if ( !empty( $user->user_msn ) ) |
|
| 835 | - update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) ); |
|
| 836 | - if ( !empty( $user->user_yim ) ) |
|
| 837 | - update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) ); |
|
| 838 | - if ( !empty( $user->user_description ) ) |
|
| 839 | - update_user_meta( $user->ID, 'description', wp_slash($user->user_description) ); |
|
| 862 | + if ( !empty( $user->user_firstname ) ) { |
|
| 863 | + update_user_meta( $user->ID, 'first_name', wp_slash($user->user_firstname) ); |
|
| 864 | + } |
|
| 865 | + if ( !empty( $user->user_lastname ) ) { |
|
| 866 | + update_user_meta( $user->ID, 'last_name', wp_slash($user->user_lastname) ); |
|
| 867 | + } |
|
| 868 | + if ( !empty( $user->user_nickname ) ) { |
|
| 869 | + update_user_meta( $user->ID, 'nickname', wp_slash($user->user_nickname) ); |
|
| 870 | + } |
|
| 871 | + if ( !empty( $user->user_level ) ) { |
|
| 872 | + update_user_meta( $user->ID, $wpdb->prefix . 'user_level', $user->user_level ); |
|
| 873 | + } |
|
| 874 | + if ( !empty( $user->user_icq ) ) { |
|
| 875 | + update_user_meta( $user->ID, 'icq', wp_slash($user->user_icq) ); |
|
| 876 | + } |
|
| 877 | + if ( !empty( $user->user_aim ) ) { |
|
| 878 | + update_user_meta( $user->ID, 'aim', wp_slash($user->user_aim) ); |
|
| 879 | + } |
|
| 880 | + if ( !empty( $user->user_msn ) ) { |
|
| 881 | + update_user_meta( $user->ID, 'msn', wp_slash($user->user_msn) ); |
|
| 882 | + } |
|
| 883 | + if ( !empty( $user->user_yim ) ) { |
|
| 884 | + update_user_meta( $user->ID, 'yim', wp_slash($user->user_icq) ); |
|
| 885 | + } |
|
| 886 | + if ( !empty( $user->user_description ) ) { |
|
| 887 | + update_user_meta( $user->ID, 'description', wp_slash($user->user_description) ); |
|
| 888 | + } |
|
| 840 | 889 | |
| 841 | 890 | if ( isset( $user->user_idmode ) ): |
| 842 | 891 | $idmode = $user->user_idmode; |
| 843 | - if ($idmode == 'nickname') $id = $user->user_nickname; |
|
| 844 | - if ($idmode == 'login') $id = $user->user_login; |
|
| 845 | - if ($idmode == 'firstname') $id = $user->user_firstname; |
|
| 846 | - if ($idmode == 'lastname') $id = $user->user_lastname; |
|
| 847 | - if ($idmode == 'namefl') $id = $user->user_firstname.' '.$user->user_lastname; |
|
| 848 | - if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname; |
|
| 849 | - if (!$idmode) $id = $user->user_nickname; |
|
| 892 | + if ($idmode == 'nickname') { |
|
| 893 | + $id = $user->user_nickname; |
|
| 894 | + } |
|
| 895 | + if ($idmode == 'login') { |
|
| 896 | + $id = $user->user_login; |
|
| 897 | + } |
|
| 898 | + if ($idmode == 'firstname') { |
|
| 899 | + $id = $user->user_firstname; |
|
| 900 | + } |
|
| 901 | + if ($idmode == 'lastname') { |
|
| 902 | + $id = $user->user_lastname; |
|
| 903 | + } |
|
| 904 | + if ($idmode == 'namefl') { |
|
| 905 | + $id = $user->user_firstname.' '.$user->user_lastname; |
|
| 906 | + } |
|
| 907 | + if ($idmode == 'namelf') { |
|
| 908 | + $id = $user->user_lastname.' '.$user->user_firstname; |
|
| 909 | + } |
|
| 910 | + if (!$idmode) { |
|
| 911 | + $id = $user->user_nickname; |
|
| 912 | + } |
|
| 850 | 913 | $wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) ); |
| 851 | 914 | endif; |
| 852 | 915 | |
@@ -861,15 +924,17 @@ discard block |
||
| 861 | 924 | endforeach; |
| 862 | 925 | $old_user_fields = array( 'user_firstname', 'user_lastname', 'user_icq', 'user_aim', 'user_msn', 'user_yim', 'user_idmode', 'user_ip', 'user_domain', 'user_browser', 'user_description', 'user_nickname', 'user_level' ); |
| 863 | 926 | $wpdb->hide_errors(); |
| 864 | - foreach ( $old_user_fields as $old ) |
|
| 865 | - $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); |
|
| 927 | + foreach ( $old_user_fields as $old ) { |
|
| 928 | + $wpdb->query("ALTER TABLE $wpdb->users DROP $old"); |
|
| 929 | + } |
|
| 866 | 930 | $wpdb->show_errors(); |
| 867 | 931 | |
| 868 | 932 | // Populate comment_count field of posts table. |
| 869 | 933 | $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" ); |
| 870 | - if ( is_array( $comments ) ) |
|
| 871 | - foreach ($comments as $comment) |
|
| 934 | + if ( is_array( $comments ) ) { |
|
| 935 | + foreach ($comments as $comment) |
|
| 872 | 936 | $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) ); |
| 937 | + } |
|
| 873 | 938 | |
| 874 | 939 | /* |
| 875 | 940 | * Some alpha versions used a post status of object instead of attachment |
@@ -884,8 +949,9 @@ discard block |
||
| 884 | 949 | array( 'ID' => $object->ID ) ); |
| 885 | 950 | |
| 886 | 951 | $meta = get_post_meta($object->ID, 'imagedata', true); |
| 887 | - if ( ! empty($meta['file']) ) |
|
| 888 | - update_attached_file( $object->ID, $meta['file'] ); |
|
| 952 | + if ( ! empty($meta['file']) ) { |
|
| 953 | + update_attached_file( $object->ID, $meta['file'] ); |
|
| 954 | + } |
|
| 889 | 955 | } |
| 890 | 956 | } |
| 891 | 957 | } |
@@ -906,8 +972,10 @@ discard block |
||
| 906 | 972 | // Update status and type. |
| 907 | 973 | $posts = $wpdb->get_results("SELECT ID, post_status FROM $wpdb->posts"); |
| 908 | 974 | |
| 909 | - if ( ! empty($posts) ) foreach ($posts as $post) { |
|
| 975 | + if ( ! empty($posts) ) { |
|
| 976 | + foreach ($posts as $post) { |
|
| 910 | 977 | $status = $post->post_status; |
| 978 | + } |
|
| 911 | 979 | $type = 'post'; |
| 912 | 980 | |
| 913 | 981 | if ( 'static' == $status ) { |
@@ -932,9 +1000,10 @@ discard block |
||
| 932 | 1000 | $wpdb->query ("UPDATE $wpdb->posts SET post_status = 'future' WHERE post_status = 'publish' AND post_date_gmt > '$now'"); |
| 933 | 1001 | |
| 934 | 1002 | $posts = $wpdb->get_results("SELECT ID, post_date FROM $wpdb->posts WHERE post_status ='future'"); |
| 935 | - if ( !empty($posts) ) |
|
| 936 | - foreach ( $posts as $post ) |
|
| 1003 | + if ( !empty($posts) ) { |
|
| 1004 | + foreach ( $posts as $post ) |
|
| 937 | 1005 | wp_schedule_single_event(mysql2date('U', $post->post_date, false), 'publish_future_post', array($post->ID)); |
| 1006 | + } |
|
| 938 | 1007 | } |
| 939 | 1008 | } |
| 940 | 1009 | |
@@ -1020,19 +1089,22 @@ discard block |
||
| 1020 | 1089 | } |
| 1021 | 1090 | |
| 1022 | 1091 | $select = 'post_id, category_id'; |
| 1023 | - if ( $have_tags ) |
|
| 1024 | - $select .= ', rel_type'; |
|
| 1092 | + if ( $have_tags ) { |
|
| 1093 | + $select .= ', rel_type'; |
|
| 1094 | + } |
|
| 1025 | 1095 | |
| 1026 | 1096 | $posts = $wpdb->get_results("SELECT $select FROM $wpdb->post2cat GROUP BY post_id, category_id"); |
| 1027 | 1097 | foreach ( $posts as $post ) { |
| 1028 | 1098 | $post_id = (int) $post->post_id; |
| 1029 | 1099 | $term_id = (int) $post->category_id; |
| 1030 | 1100 | $taxonomy = 'category'; |
| 1031 | - if ( !empty($post->rel_type) && 'tag' == $post->rel_type) |
|
| 1032 | - $taxonomy = 'tag'; |
|
| 1101 | + if ( !empty($post->rel_type) && 'tag' == $post->rel_type) { |
|
| 1102 | + $taxonomy = 'tag'; |
|
| 1103 | + } |
|
| 1033 | 1104 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
| 1034 | - if ( empty($tt_id) ) |
|
| 1035 | - continue; |
|
| 1105 | + if ( empty($tt_id) ) { |
|
| 1106 | + continue; |
|
| 1107 | + } |
|
| 1036 | 1108 | |
| 1037 | 1109 | $wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) ); |
| 1038 | 1110 | } |
@@ -1074,15 +1146,19 @@ discard block |
||
| 1074 | 1146 | |
| 1075 | 1147 | // Associate links to cats. |
| 1076 | 1148 | $links = $wpdb->get_results("SELECT link_id, link_category FROM $wpdb->links"); |
| 1077 | - if ( !empty($links) ) foreach ( $links as $link ) { |
|
| 1149 | + if ( !empty($links) ) { |
|
| 1150 | + foreach ( $links as $link ) { |
|
| 1078 | 1151 | if ( 0 == $link->link_category ) |
| 1079 | 1152 | continue; |
| 1080 | - if ( ! isset($link_cat_id_map[$link->link_category]) ) |
|
| 1081 | - continue; |
|
| 1153 | + } |
|
| 1154 | + if ( ! isset($link_cat_id_map[$link->link_category]) ) { |
|
| 1155 | + continue; |
|
| 1156 | + } |
|
| 1082 | 1157 | $term_id = $link_cat_id_map[$link->link_category]; |
| 1083 | 1158 | $tt_id = $tt_ids[$term_id]; |
| 1084 | - if ( empty($tt_id) ) |
|
| 1085 | - continue; |
|
| 1159 | + if ( empty($tt_id) ) { |
|
| 1160 | + continue; |
|
| 1161 | + } |
|
| 1086 | 1162 | |
| 1087 | 1163 | $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id) ); |
| 1088 | 1164 | } |
@@ -1096,8 +1172,9 @@ discard block |
||
| 1096 | 1172 | $term_id = (int) $link->category_id; |
| 1097 | 1173 | $taxonomy = 'link_category'; |
| 1098 | 1174 | $tt_id = $tt_ids[$term_id][$taxonomy]; |
| 1099 | - if ( empty($tt_id) ) |
|
| 1100 | - continue; |
|
| 1175 | + if ( empty($tt_id) ) { |
|
| 1176 | + continue; |
|
| 1177 | + } |
|
| 1101 | 1178 | $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id) ); |
| 1102 | 1179 | } |
| 1103 | 1180 | } |
@@ -1110,10 +1187,11 @@ discard block |
||
| 1110 | 1187 | // Recalculate all counts |
| 1111 | 1188 | $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy"); |
| 1112 | 1189 | foreach ( (array) $terms as $term ) { |
| 1113 | - if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) |
|
| 1114 | - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1115 | - else |
|
| 1116 | - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1190 | + if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) { |
|
| 1191 | + $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1192 | + } else { |
|
| 1193 | + $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) ); |
|
| 1194 | + } |
|
| 1117 | 1195 | $wpdb->update( $wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id) ); |
| 1118 | 1196 | } |
| 1119 | 1197 | } |
@@ -1130,8 +1208,9 @@ discard block |
||
| 1130 | 1208 | global $wpdb; |
| 1131 | 1209 | $old_options_fields = array( 'option_can_override', 'option_type', 'option_width', 'option_height', 'option_description', 'option_admin_level' ); |
| 1132 | 1210 | $wpdb->hide_errors(); |
| 1133 | - foreach ( $old_options_fields as $old ) |
|
| 1134 | - $wpdb->query("ALTER TABLE $wpdb->options DROP $old"); |
|
| 1211 | + foreach ( $old_options_fields as $old ) { |
|
| 1212 | + $wpdb->query("ALTER TABLE $wpdb->options DROP $old"); |
|
| 1213 | + } |
|
| 1135 | 1214 | $wpdb->show_errors(); |
| 1136 | 1215 | } |
| 1137 | 1216 | |
@@ -1206,9 +1285,10 @@ discard block |
||
| 1206 | 1285 | function upgrade_260() { |
| 1207 | 1286 | global $wp_current_db_version; |
| 1208 | 1287 | |
| 1209 | - if ( $wp_current_db_version < 8000 ) |
|
| 1210 | - populate_roles_260(); |
|
| 1211 | -} |
|
| 1288 | + if ( $wp_current_db_version < 8000 ) { |
|
| 1289 | + populate_roles_260(); |
|
| 1290 | + } |
|
| 1291 | + } |
|
| 1212 | 1292 | |
| 1213 | 1293 | /** |
| 1214 | 1294 | * Execute changes made in WordPress 2.7. |
@@ -1222,13 +1302,15 @@ discard block |
||
| 1222 | 1302 | function upgrade_270() { |
| 1223 | 1303 | global $wpdb, $wp_current_db_version; |
| 1224 | 1304 | |
| 1225 | - if ( $wp_current_db_version < 8980 ) |
|
| 1226 | - populate_roles_270(); |
|
| 1305 | + if ( $wp_current_db_version < 8980 ) { |
|
| 1306 | + populate_roles_270(); |
|
| 1307 | + } |
|
| 1227 | 1308 | |
| 1228 | 1309 | // Update post_date for unpublished posts with empty timestamp |
| 1229 | - if ( $wp_current_db_version < 8921 ) |
|
| 1230 | - $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); |
|
| 1231 | -} |
|
| 1310 | + if ( $wp_current_db_version < 8921 ) { |
|
| 1311 | + $wpdb->query( "UPDATE $wpdb->posts SET post_date = post_modified WHERE post_date = '0000-00-00 00:00:00'" ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1232 | 1314 | |
| 1233 | 1315 | /** |
| 1234 | 1316 | * Execute changes made in WordPress 2.8. |
@@ -1242,15 +1324,17 @@ discard block |
||
| 1242 | 1324 | function upgrade_280() { |
| 1243 | 1325 | global $wp_current_db_version, $wpdb; |
| 1244 | 1326 | |
| 1245 | - if ( $wp_current_db_version < 10360 ) |
|
| 1246 | - populate_roles_280(); |
|
| 1327 | + if ( $wp_current_db_version < 10360 ) { |
|
| 1328 | + populate_roles_280(); |
|
| 1329 | + } |
|
| 1247 | 1330 | if ( is_multisite() ) { |
| 1248 | 1331 | $start = 0; |
| 1249 | 1332 | while( $rows = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options ORDER BY option_id LIMIT $start, 20" ) ) { |
| 1250 | 1333 | foreach ( $rows as $row ) { |
| 1251 | 1334 | $value = $row->option_value; |
| 1252 | - if ( !@unserialize( $value ) ) |
|
| 1253 | - $value = stripslashes( $value ); |
|
| 1335 | + if ( !@unserialize( $value ) ) { |
|
| 1336 | + $value = stripslashes( $value ); |
|
| 1337 | + } |
|
| 1254 | 1338 | if ( $value !== $row->option_value ) { |
| 1255 | 1339 | update_option( $row->option_name, $value ); |
| 1256 | 1340 | } |
@@ -1293,11 +1377,13 @@ discard block |
||
| 1293 | 1377 | function upgrade_300() { |
| 1294 | 1378 | global $wp_current_db_version, $wpdb; |
| 1295 | 1379 | |
| 1296 | - if ( $wp_current_db_version < 15093 ) |
|
| 1297 | - populate_roles_300(); |
|
| 1380 | + if ( $wp_current_db_version < 15093 ) { |
|
| 1381 | + populate_roles_300(); |
|
| 1382 | + } |
|
| 1298 | 1383 | |
| 1299 | - if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) |
|
| 1300 | - add_site_option( 'siteurl', '' ); |
|
| 1384 | + if ( $wp_current_db_version < 14139 && is_multisite() && is_main_site() && ! defined( 'MULTISITE' ) && get_site_option( 'siteurl' ) === false ) { |
|
| 1385 | + add_site_option( 'siteurl', '' ); |
|
| 1386 | + } |
|
| 1301 | 1387 | |
| 1302 | 1388 | // 3.0 screen options key name changes. |
| 1303 | 1389 | if ( wp_should_upgrade_global_tables() ) { |
@@ -1345,23 +1431,26 @@ discard block |
||
| 1345 | 1431 | $wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key IN ('show_admin_bar_admin', 'plugins_last_view')" ); |
| 1346 | 1432 | } |
| 1347 | 1433 | |
| 1348 | - if ( $wp_current_db_version >= 11548 ) |
|
| 1349 | - return; |
|
| 1434 | + if ( $wp_current_db_version >= 11548 ) { |
|
| 1435 | + return; |
|
| 1436 | + } |
|
| 1350 | 1437 | |
| 1351 | 1438 | $sidebars_widgets = get_option( 'sidebars_widgets', array() ); |
| 1352 | 1439 | $_sidebars_widgets = array(); |
| 1353 | 1440 | |
| 1354 | - if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) ) |
|
| 1355 | - $sidebars_widgets['array_version'] = 3; |
|
| 1356 | - elseif ( !isset($sidebars_widgets['array_version']) ) |
|
| 1357 | - $sidebars_widgets['array_version'] = 1; |
|
| 1441 | + if ( isset($sidebars_widgets['wp_inactive_widgets']) || empty($sidebars_widgets) ) { |
|
| 1442 | + $sidebars_widgets['array_version'] = 3; |
|
| 1443 | + } elseif ( !isset($sidebars_widgets['array_version']) ) { |
|
| 1444 | + $sidebars_widgets['array_version'] = 1; |
|
| 1445 | + } |
|
| 1358 | 1446 | |
| 1359 | 1447 | switch ( $sidebars_widgets['array_version'] ) { |
| 1360 | 1448 | case 1 : |
| 1361 | - foreach ( (array) $sidebars_widgets as $index => $sidebar ) |
|
| 1362 | - if ( is_array($sidebar) ) |
|
| 1449 | + foreach ( (array) $sidebars_widgets as $index => $sidebar ) { |
|
| 1450 | + if ( is_array($sidebar) ) |
|
| 1363 | 1451 | foreach ( (array) $sidebar as $i => $name ) { |
| 1364 | 1452 | $id = strtolower($name); |
| 1453 | + } |
|
| 1365 | 1454 | if ( isset($wp_registered_widgets[$id]) ) { |
| 1366 | 1455 | $_sidebars_widgets[$index][$i] = $id; |
| 1367 | 1456 | continue; |
@@ -1386,8 +1475,9 @@ discard block |
||
| 1386 | 1475 | } |
| 1387 | 1476 | } |
| 1388 | 1477 | |
| 1389 | - if ( $found ) |
|
| 1390 | - continue; |
|
| 1478 | + if ( $found ) { |
|
| 1479 | + continue; |
|
| 1480 | + } |
|
| 1391 | 1481 | |
| 1392 | 1482 | unset($_sidebars_widgets[$index][$i]); |
| 1393 | 1483 | } |
@@ -1451,14 +1541,17 @@ discard block |
||
| 1451 | 1541 | function upgrade_350() { |
| 1452 | 1542 | global $wp_current_db_version, $wpdb; |
| 1453 | 1543 | |
| 1454 | - if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) |
|
| 1455 | - update_option( 'link_manager_enabled', 1 ); // Previously set to 0 by populate_options() |
|
| 1544 | + if ( $wp_current_db_version < 22006 && $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) { |
|
| 1545 | + update_option( 'link_manager_enabled', 1 ); |
|
| 1546 | + } |
|
| 1547 | + // Previously set to 0 by populate_options() |
|
| 1456 | 1548 | |
| 1457 | 1549 | if ( $wp_current_db_version < 21811 && wp_should_upgrade_global_tables() ) { |
| 1458 | 1550 | $meta_keys = array(); |
| 1459 | 1551 | foreach ( array_merge( get_post_types(), get_taxonomies() ) as $name ) { |
| 1460 | - if ( false !== strpos( $name, '-' ) ) |
|
| 1461 | - $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page'; |
|
| 1552 | + if ( false !== strpos( $name, '-' ) ) { |
|
| 1553 | + $meta_keys[] = 'edit_' . str_replace( '-', '_', $name ) . '_per_page'; |
|
| 1554 | + } |
|
| 1462 | 1555 | } |
| 1463 | 1556 | if ( $meta_keys ) { |
| 1464 | 1557 | $meta_keys = implode( "', '", $meta_keys ); |
@@ -1466,9 +1559,10 @@ discard block |
||
| 1466 | 1559 | } |
| 1467 | 1560 | } |
| 1468 | 1561 | |
| 1469 | - if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) ) |
|
| 1470 | - wp_delete_term( $term->term_id, 'post_format' ); |
|
| 1471 | -} |
|
| 1562 | + if ( $wp_current_db_version < 22422 && $term = get_term_by( 'slug', 'post-format-standard', 'post_format' ) ) { |
|
| 1563 | + wp_delete_term( $term->term_id, 'post_format' ); |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1472 | 1566 | |
| 1473 | 1567 | /** |
| 1474 | 1568 | * Execute changes made in WordPress 3.7. |
@@ -1480,9 +1574,10 @@ discard block |
||
| 1480 | 1574 | */ |
| 1481 | 1575 | function upgrade_370() { |
| 1482 | 1576 | global $wp_current_db_version; |
| 1483 | - if ( $wp_current_db_version < 25824 ) |
|
| 1484 | - wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' ); |
|
| 1485 | -} |
|
| 1577 | + if ( $wp_current_db_version < 25824 ) { |
|
| 1578 | + wp_clear_scheduled_hook( 'wp_auto_updates_maybe_update' ); |
|
| 1579 | + } |
|
| 1580 | + } |
|
| 1486 | 1581 | |
| 1487 | 1582 | /** |
| 1488 | 1583 | * Execute changes made in WordPress 3.7.2. |
@@ -1495,9 +1590,10 @@ discard block |
||
| 1495 | 1590 | */ |
| 1496 | 1591 | function upgrade_372() { |
| 1497 | 1592 | global $wp_current_db_version; |
| 1498 | - if ( $wp_current_db_version < 26148 ) |
|
| 1499 | - wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); |
|
| 1500 | -} |
|
| 1593 | + if ( $wp_current_db_version < 26148 ) { |
|
| 1594 | + wp_clear_scheduled_hook( 'wp_maybe_auto_update' ); |
|
| 1595 | + } |
|
| 1596 | + } |
|
| 1501 | 1597 | |
| 1502 | 1598 | /** |
| 1503 | 1599 | * Execute changes made in WordPress 3.8.0. |
@@ -1764,10 +1860,11 @@ discard block |
||
| 1764 | 1860 | $wpmu_sitewide_plugins = get_site_option( 'wpmu_sitewide_plugins' ); |
| 1765 | 1861 | $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
| 1766 | 1862 | if ( $wpmu_sitewide_plugins ) { |
| 1767 | - if ( !$active_sitewide_plugins ) |
|
| 1768 | - $sitewide_plugins = (array) $wpmu_sitewide_plugins; |
|
| 1769 | - else |
|
| 1770 | - $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins ); |
|
| 1863 | + if ( !$active_sitewide_plugins ) { |
|
| 1864 | + $sitewide_plugins = (array) $wpmu_sitewide_plugins; |
|
| 1865 | + } else { |
|
| 1866 | + $sitewide_plugins = array_merge( (array) $active_sitewide_plugins, (array) $wpmu_sitewide_plugins ); |
|
| 1867 | + } |
|
| 1771 | 1868 | |
| 1772 | 1869 | update_site_option( 'active_sitewide_plugins', $sitewide_plugins ); |
| 1773 | 1870 | } |
@@ -1778,8 +1875,9 @@ discard block |
||
| 1778 | 1875 | while( $rows = $wpdb->get_results( "SELECT meta_key, meta_value FROM {$wpdb->sitemeta} ORDER BY meta_id LIMIT $start, 20" ) ) { |
| 1779 | 1876 | foreach ( $rows as $row ) { |
| 1780 | 1877 | $value = $row->meta_value; |
| 1781 | - if ( !@unserialize( $value ) ) |
|
| 1782 | - $value = stripslashes( $value ); |
|
| 1878 | + if ( !@unserialize( $value ) ) { |
|
| 1879 | + $value = stripslashes( $value ); |
|
| 1880 | + } |
|
| 1783 | 1881 | if ( $value !== $row->meta_value ) { |
| 1784 | 1882 | update_site_option( $row->meta_key, $value ); |
| 1785 | 1883 | } |
@@ -1789,16 +1887,19 @@ discard block |
||
| 1789 | 1887 | } |
| 1790 | 1888 | |
| 1791 | 1889 | // 3.0 |
| 1792 | - if ( $wp_current_db_version < 13576 ) |
|
| 1793 | - update_site_option( 'global_terms_enabled', '1' ); |
|
| 1890 | + if ( $wp_current_db_version < 13576 ) { |
|
| 1891 | + update_site_option( 'global_terms_enabled', '1' ); |
|
| 1892 | + } |
|
| 1794 | 1893 | |
| 1795 | 1894 | // 3.3 |
| 1796 | - if ( $wp_current_db_version < 19390 ) |
|
| 1797 | - update_site_option( 'initial_db_version', $wp_current_db_version ); |
|
| 1895 | + if ( $wp_current_db_version < 19390 ) { |
|
| 1896 | + update_site_option( 'initial_db_version', $wp_current_db_version ); |
|
| 1897 | + } |
|
| 1798 | 1898 | |
| 1799 | 1899 | if ( $wp_current_db_version < 19470 ) { |
| 1800 | - if ( false === get_site_option( 'active_sitewide_plugins' ) ) |
|
| 1801 | - update_site_option( 'active_sitewide_plugins', array() ); |
|
| 1900 | + if ( false === get_site_option( 'active_sitewide_plugins' ) ) { |
|
| 1901 | + update_site_option( 'active_sitewide_plugins', array() ); |
|
| 1902 | + } |
|
| 1802 | 1903 | } |
| 1803 | 1904 | |
| 1804 | 1905 | // 3.4 |
@@ -1810,8 +1911,9 @@ discard block |
||
| 1810 | 1911 | $converted = array(); |
| 1811 | 1912 | $themes = wp_get_themes(); |
| 1812 | 1913 | foreach ( $themes as $stylesheet => $theme_data ) { |
| 1813 | - if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) ) |
|
| 1814 | - $converted[ $stylesheet ] = true; |
|
| 1914 | + if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) ) { |
|
| 1915 | + $converted[ $stylesheet ] = true; |
|
| 1916 | + } |
|
| 1815 | 1917 | } |
| 1816 | 1918 | update_site_option( 'allowedthemes', $converted ); |
| 1817 | 1919 | delete_site_option( 'allowed_themes' ); |
@@ -1819,8 +1921,9 @@ discard block |
||
| 1819 | 1921 | } |
| 1820 | 1922 | |
| 1821 | 1923 | // 3.5 |
| 1822 | - if ( $wp_current_db_version < 21823 ) |
|
| 1823 | - update_site_option( 'ms_files_rewriting', '1' ); |
|
| 1924 | + if ( $wp_current_db_version < 21823 ) { |
|
| 1925 | + update_site_option( 'ms_files_rewriting', '1' ); |
|
| 1926 | + } |
|
| 1824 | 1927 | |
| 1825 | 1928 | // 3.5.2 |
| 1826 | 1929 | if ( $wp_current_db_version < 24448 ) { |
@@ -2051,8 +2154,9 @@ discard block |
||
| 2051 | 2154 | $all_options = new stdClass; |
| 2052 | 2155 | if ( $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ) ) { |
| 2053 | 2156 | foreach ( $options as $option ) { |
| 2054 | - if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name ) |
|
| 2055 | - $option->option_value = untrailingslashit( $option->option_value ); |
|
| 2157 | + if ( 'siteurl' == $option->option_name || 'home' == $option->option_name || 'category_base' == $option->option_name ) { |
|
| 2158 | + $option->option_value = untrailingslashit( $option->option_value ); |
|
| 2159 | + } |
|
| 2056 | 2160 | $all_options->{$option->option_name} = stripslashes( $option->option_value ); |
| 2057 | 2161 | } |
| 2058 | 2162 | } |
@@ -2074,19 +2178,23 @@ discard block |
||
| 2074 | 2178 | function __get_option($setting) { |
| 2075 | 2179 | global $wpdb; |
| 2076 | 2180 | |
| 2077 | - if ( $setting == 'home' && defined( 'WP_HOME' ) ) |
|
| 2078 | - return untrailingslashit( WP_HOME ); |
|
| 2181 | + if ( $setting == 'home' && defined( 'WP_HOME' ) ) { |
|
| 2182 | + return untrailingslashit( WP_HOME ); |
|
| 2183 | + } |
|
| 2079 | 2184 | |
| 2080 | - if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) |
|
| 2081 | - return untrailingslashit( WP_SITEURL ); |
|
| 2185 | + if ( $setting == 'siteurl' && defined( 'WP_SITEURL' ) ) { |
|
| 2186 | + return untrailingslashit( WP_SITEURL ); |
|
| 2187 | + } |
|
| 2082 | 2188 | |
| 2083 | 2189 | $option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting ) ); |
| 2084 | 2190 | |
| 2085 | - if ( 'home' == $setting && '' == $option ) |
|
| 2086 | - return __get_option( 'siteurl' ); |
|
| 2191 | + if ( 'home' == $setting && '' == $option ) { |
|
| 2192 | + return __get_option( 'siteurl' ); |
|
| 2193 | + } |
|
| 2087 | 2194 | |
| 2088 | - if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) |
|
| 2089 | - $option = untrailingslashit( $option ); |
|
| 2195 | + if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting || 'tag_base' == $setting ) { |
|
| 2196 | + $option = untrailingslashit( $option ); |
|
| 2197 | + } |
|
| 2090 | 2198 | |
| 2091 | 2199 | return maybe_unserialize( $option ); |
| 2092 | 2200 | } |
@@ -2139,8 +2247,9 @@ discard block |
||
| 2139 | 2247 | function dbDelta( $queries = '', $execute = true ) { |
| 2140 | 2248 | global $wpdb; |
| 2141 | 2249 | |
| 2142 | - if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) |
|
| 2143 | - $queries = wp_get_db_schema( $queries ); |
|
| 2250 | + if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms_global' ), true ) ) { |
|
| 2251 | + $queries = wp_get_db_schema( $queries ); |
|
| 2252 | + } |
|
| 2144 | 2253 | |
| 2145 | 2254 | // Separate individual queries into an array |
| 2146 | 2255 | if ( !is_array($queries) ) { |
@@ -2215,8 +2324,9 @@ discard block |
||
| 2215 | 2324 | $tablefields = $wpdb->get_results("DESCRIBE {$table};"); |
| 2216 | 2325 | $wpdb->suppress_errors( $suppress ); |
| 2217 | 2326 | |
| 2218 | - if ( ! $tablefields ) |
|
| 2219 | - continue; |
|
| 2327 | + if ( ! $tablefields ) { |
|
| 2328 | + continue; |
|
| 2329 | + } |
|
| 2220 | 2330 | |
| 2221 | 2331 | // Clear the field and index arrays. |
| 2222 | 2332 | $cfields = $indices = $indices_without_subparts = array(); |
@@ -2503,7 +2613,9 @@ discard block |
||
| 2503 | 2613 | function make_db_current( $tables = 'all' ) { |
| 2504 | 2614 | $alterations = dbDelta( $tables ); |
| 2505 | 2615 | echo "<ol>\n"; |
| 2506 | - foreach ($alterations as $alteration) echo "<li>$alteration</li>\n"; |
|
| 2616 | + foreach ($alterations as $alteration) { |
|
| 2617 | + echo "<li>$alteration</li>\n"; |
|
| 2618 | + } |
|
| 2507 | 2619 | echo "</ol>\n"; |
| 2508 | 2620 | } |
| 2509 | 2621 | |
@@ -2538,8 +2650,9 @@ discard block |
||
| 2538 | 2650 | $home_path = get_home_path(); |
| 2539 | 2651 | $site_dir = WP_CONTENT_DIR . "/themes/$template"; |
| 2540 | 2652 | |
| 2541 | - if (! file_exists("$home_path/index.php")) |
|
| 2542 | - return false; |
|
| 2653 | + if (! file_exists("$home_path/index.php")) { |
|
| 2654 | + return false; |
|
| 2655 | + } |
|
| 2543 | 2656 | |
| 2544 | 2657 | /* |
| 2545 | 2658 | * Copy files from the old locations to the site theme. |
@@ -2548,25 +2661,28 @@ discard block |
||
| 2548 | 2661 | $files = array('index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php'); |
| 2549 | 2662 | |
| 2550 | 2663 | foreach ($files as $oldfile => $newfile) { |
| 2551 | - if ($oldfile == 'index.php') |
|
| 2552 | - $oldpath = $home_path; |
|
| 2553 | - else |
|
| 2554 | - $oldpath = ABSPATH; |
|
| 2664 | + if ($oldfile == 'index.php') { |
|
| 2665 | + $oldpath = $home_path; |
|
| 2666 | + } else { |
|
| 2667 | + $oldpath = ABSPATH; |
|
| 2668 | + } |
|
| 2555 | 2669 | |
| 2556 | 2670 | // Check to make sure it's not a new index. |
| 2557 | 2671 | if ($oldfile == 'index.php') { |
| 2558 | 2672 | $index = implode('', file("$oldpath/$oldfile")); |
| 2559 | 2673 | if (strpos($index, 'WP_USE_THEMES') !== false) { |
| 2560 | - if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) |
|
| 2561 | - return false; |
|
| 2674 | + if (! @copy(WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME . '/index.php', "$site_dir/$newfile")) { |
|
| 2675 | + return false; |
|
| 2676 | + } |
|
| 2562 | 2677 | |
| 2563 | 2678 | // Don't copy anything. |
| 2564 | 2679 | continue; |
| 2565 | 2680 | } |
| 2566 | 2681 | } |
| 2567 | 2682 | |
| 2568 | - if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) |
|
| 2569 | - return false; |
|
| 2683 | + if (! @copy("$oldpath/$oldfile", "$site_dir/$newfile")) { |
|
| 2684 | + return false; |
|
| 2685 | + } |
|
| 2570 | 2686 | |
| 2571 | 2687 | chmod("$site_dir/$newfile", 0777); |
| 2572 | 2688 | |
@@ -2576,8 +2692,9 @@ discard block |
||
| 2576 | 2692 | $f = fopen("$site_dir/$newfile", 'w'); |
| 2577 | 2693 | |
| 2578 | 2694 | foreach ($lines as $line) { |
| 2579 | - if (preg_match('/require.*wp-blog-header/', $line)) |
|
| 2580 | - $line = '//' . $line; |
|
| 2695 | + if (preg_match('/require.*wp-blog-header/', $line)) { |
|
| 2696 | + $line = '//' . $line; |
|
| 2697 | + } |
|
| 2581 | 2698 | |
| 2582 | 2699 | // Update stylesheet references. |
| 2583 | 2700 | $line = str_replace("<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line); |
@@ -2627,10 +2744,12 @@ discard block |
||
| 2627 | 2744 | $theme_dir = @ opendir($default_dir); |
| 2628 | 2745 | if ($theme_dir) { |
| 2629 | 2746 | while(($theme_file = readdir( $theme_dir )) !== false) { |
| 2630 | - if (is_dir("$default_dir/$theme_file")) |
|
| 2631 | - continue; |
|
| 2632 | - if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) |
|
| 2633 | - return; |
|
| 2747 | + if (is_dir("$default_dir/$theme_file")) { |
|
| 2748 | + continue; |
|
| 2749 | + } |
|
| 2750 | + if (! @copy("$default_dir/$theme_file", "$site_dir/$theme_file")) { |
|
| 2751 | + return; |
|
| 2752 | + } |
|
| 2634 | 2753 | chmod("$site_dir/$theme_file", 0777); |
| 2635 | 2754 | } |
| 2636 | 2755 | } |
@@ -2642,11 +2761,17 @@ discard block |
||
| 2642 | 2761 | $f = fopen("$site_dir/style.css", 'w'); |
| 2643 | 2762 | |
| 2644 | 2763 | foreach ($stylelines as $line) { |
| 2645 | - if (strpos($line, 'Theme Name:') !== false) $line = 'Theme Name: ' . $theme_name; |
|
| 2646 | - elseif (strpos($line, 'Theme URI:') !== false) $line = 'Theme URI: ' . __get_option('url'); |
|
| 2647 | - elseif (strpos($line, 'Description:') !== false) $line = 'Description: Your theme.'; |
|
| 2648 | - elseif (strpos($line, 'Version:') !== false) $line = 'Version: 1'; |
|
| 2649 | - elseif (strpos($line, 'Author:') !== false) $line = 'Author: You'; |
|
| 2764 | + if (strpos($line, 'Theme Name:') !== false) { |
|
| 2765 | + $line = 'Theme Name: ' . $theme_name; |
|
| 2766 | + } elseif (strpos($line, 'Theme URI:') !== false) { |
|
| 2767 | + $line = 'Theme URI: ' . __get_option('url'); |
|
| 2768 | + } elseif (strpos($line, 'Description:') !== false) { |
|
| 2769 | + $line = 'Description: Your theme.'; |
|
| 2770 | + } elseif (strpos($line, 'Version:') !== false) { |
|
| 2771 | + $line = 'Version: 1'; |
|
| 2772 | + } elseif (strpos($line, 'Author:') !== false) { |
|
| 2773 | + $line = 'Author: You'; |
|
| 2774 | + } |
|
| 2650 | 2775 | fwrite($f, $line . "\n"); |
| 2651 | 2776 | } |
| 2652 | 2777 | fclose($f); |
@@ -2661,10 +2786,12 @@ discard block |
||
| 2661 | 2786 | $images_dir = @ opendir("$default_dir/images"); |
| 2662 | 2787 | if ($images_dir) { |
| 2663 | 2788 | while(($image = readdir($images_dir)) !== false) { |
| 2664 | - if (is_dir("$default_dir/images/$image")) |
|
| 2665 | - continue; |
|
| 2666 | - if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) |
|
| 2667 | - return; |
|
| 2789 | + if (is_dir("$default_dir/images/$image")) { |
|
| 2790 | + continue; |
|
| 2791 | + } |
|
| 2792 | + if (! @copy("$default_dir/images/$image", "$site_dir/images/$image")) { |
|
| 2793 | + return; |
|
| 2794 | + } |
|
| 2668 | 2795 | chmod("$site_dir/images/$image", 0777); |
| 2669 | 2796 | } |
| 2670 | 2797 | } |
@@ -2707,9 +2834,10 @@ discard block |
||
| 2707 | 2834 | return false; |
| 2708 | 2835 | } |
| 2709 | 2836 | } else { |
| 2710 | - if (! make_site_theme_from_default($theme_name, $template)) |
|
| 2711 | - // TODO: rm -rf the site theme directory. |
|
| 2837 | + if (! make_site_theme_from_default($theme_name, $template)) { |
|
| 2838 | + // TODO: rm -rf the site theme directory. |
|
| 2712 | 2839 | return false; |
| 2840 | + } |
|
| 2713 | 2841 | } |
| 2714 | 2842 | |
| 2715 | 2843 | // Make the new site theme active. |
@@ -2760,9 +2888,10 @@ discard block |
||
| 2760 | 2888 | function wp_check_mysql_version() { |
| 2761 | 2889 | global $wpdb; |
| 2762 | 2890 | $result = $wpdb->check_database_version(); |
| 2763 | - if ( is_wp_error( $result ) ) |
|
| 2764 | - die( $result->get_error_message() ); |
|
| 2765 | -} |
|
| 2891 | + if ( is_wp_error( $result ) ) { |
|
| 2892 | + die( $result->get_error_message() ); |
|
| 2893 | + } |
|
| 2894 | + } |
|
| 2766 | 2895 | |
| 2767 | 2896 | /** |
| 2768 | 2897 | * Disables the Automattic widgets plugin, which was merged into core. |
@@ -2792,9 +2921,10 @@ discard block |
||
| 2792 | 2921 | function maybe_disable_link_manager() { |
| 2793 | 2922 | global $wp_current_db_version, $wpdb; |
| 2794 | 2923 | |
| 2795 | - if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) |
|
| 2796 | - update_option( 'link_manager_enabled', 0 ); |
|
| 2797 | -} |
|
| 2924 | + if ( $wp_current_db_version >= 22006 && get_option( 'link_manager_enabled' ) && ! $wpdb->get_var( "SELECT link_id FROM $wpdb->links LIMIT 1" ) ) { |
|
| 2925 | + update_option( 'link_manager_enabled', 0 ); |
|
| 2926 | + } |
|
| 2927 | + } |
|
| 2798 | 2928 | |
| 2799 | 2929 | /** |
| 2800 | 2930 | * Runs before the schema is upgraded. |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | * @since Twenty Eleven 1.0 |
| 388 | 388 | * |
| 389 | 389 | * @param string $more The Read More text. |
| 390 | - * @return The filtered Read More text. |
|
| 390 | + * @return string filtered Read More text. |
|
| 391 | 391 | */ |
| 392 | 392 | function twentyeleven_auto_excerpt_more( $more ) { |
| 393 | 393 | if ( ! is_admin() ) { |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | * |
| 541 | 541 | * @since Twenty Eleven 1.0 |
| 542 | 542 | * |
| 543 | - * @return string|bool URL or false when no link is present. |
|
| 543 | + * @return false|string URL or false when no link is present. |
|
| 544 | 544 | */ |
| 545 | 545 | function twentyeleven_url_grabber() { |
| 546 | 546 | if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) |
@@ -39,8 +39,9 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | // Set the content width based on the theme's design and stylesheet. |
| 42 | -if ( ! isset( $content_width ) ) |
|
| 42 | +if ( ! isset( $content_width ) ) { |
|
| 43 | 43 | $content_width = 584; |
| 44 | +} |
|
| 44 | 45 | |
| 45 | 46 | /* |
| 46 | 47 | * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. |
@@ -98,10 +99,11 @@ discard block |
||
| 98 | 99 | add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); |
| 99 | 100 | |
| 100 | 101 | $theme_options = twentyeleven_get_theme_options(); |
| 101 | - if ( 'dark' == $theme_options['color_scheme'] ) |
|
| 102 | - $default_background_color = '1d1d1d'; |
|
| 103 | - else |
|
| 104 | - $default_background_color = 'e2e2e2'; |
|
| 102 | + if ( 'dark' == $theme_options['color_scheme'] ) { |
|
| 103 | + $default_background_color = '1d1d1d'; |
|
| 104 | + } else { |
|
| 105 | + $default_background_color = 'e2e2e2'; |
|
| 106 | + } |
|
| 105 | 107 | |
| 106 | 108 | // Add support for custom backgrounds. |
| 107 | 109 | add_theme_support( 'custom-background', array( |
@@ -239,8 +241,9 @@ discard block |
||
| 239 | 241 | $text_color = get_header_textcolor(); |
| 240 | 242 | |
| 241 | 243 | // If no custom options for text are set, let's bail. |
| 242 | - if ( $text_color == HEADER_TEXTCOLOR ) |
|
| 243 | - return; |
|
| 244 | + if ( $text_color == HEADER_TEXTCOLOR ) { |
|
| 245 | + return; |
|
| 246 | + } |
|
| 244 | 247 | |
| 245 | 248 | // If we get this far, we have custom styles. Let's do this. |
| 246 | 249 | ?> |
@@ -257,11 +260,14 @@ discard block |
||
| 257 | 260 | } |
| 258 | 261 | <?php |
| 259 | 262 | // If the user has set a custom color for the text use that |
| 260 | - else : |
|
| 263 | + else { |
|
| 264 | + : |
|
| 261 | 265 | ?> |
| 262 | 266 | #site-title a, |
| 263 | 267 | #site-description { |
| 264 | - color: #<?php echo $text_color; ?>; |
|
| 268 | + color: #<?php echo $text_color; |
|
| 269 | + } |
|
| 270 | + ?>; |
|
| 265 | 271 | } |
| 266 | 272 | <?php endif; ?> |
| 267 | 273 | </style> |
@@ -425,8 +431,9 @@ discard block |
||
| 425 | 431 | * @return array The filtered page menu arguments. |
| 426 | 432 | */ |
| 427 | 433 | function twentyeleven_page_menu_args( $args ) { |
| 428 | - if ( ! isset( $args['show_home'] ) ) |
|
| 429 | - $args['show_home'] = true; |
|
| 434 | + if ( ! isset( $args['show_home'] ) ) { |
|
| 435 | + $args['show_home'] = true; |
|
| 436 | + } |
|
| 430 | 437 | return $args; |
| 431 | 438 | } |
| 432 | 439 | add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); |
@@ -528,8 +535,9 @@ discard block |
||
| 528 | 535 | $content = get_the_content(); |
| 529 | 536 | $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; |
| 530 | 537 | |
| 531 | - if ( ! $has_url ) |
|
| 532 | - $has_url = twentyeleven_url_grabber(); |
|
| 538 | + if ( ! $has_url ) { |
|
| 539 | + $has_url = twentyeleven_url_grabber(); |
|
| 540 | + } |
|
| 533 | 541 | |
| 534 | 542 | /** This filter is documented in wp-includes/link-template.php */ |
| 535 | 543 | return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); |
@@ -543,8 +551,9 @@ discard block |
||
| 543 | 551 | * @return string|bool URL or false when no link is present. |
| 544 | 552 | */ |
| 545 | 553 | function twentyeleven_url_grabber() { |
| 546 | - if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) |
|
| 547 | - return false; |
|
| 554 | + if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 548 | 557 | |
| 549 | 558 | return esc_url_raw( $matches[1] ); |
| 550 | 559 | } |
@@ -557,14 +566,17 @@ discard block |
||
| 557 | 566 | function twentyeleven_footer_sidebar_class() { |
| 558 | 567 | $count = 0; |
| 559 | 568 | |
| 560 | - if ( is_active_sidebar( 'sidebar-3' ) ) |
|
| 561 | - $count++; |
|
| 569 | + if ( is_active_sidebar( 'sidebar-3' ) ) { |
|
| 570 | + $count++; |
|
| 571 | + } |
|
| 562 | 572 | |
| 563 | - if ( is_active_sidebar( 'sidebar-4' ) ) |
|
| 564 | - $count++; |
|
| 573 | + if ( is_active_sidebar( 'sidebar-4' ) ) { |
|
| 574 | + $count++; |
|
| 575 | + } |
|
| 565 | 576 | |
| 566 | - if ( is_active_sidebar( 'sidebar-5' ) ) |
|
| 567 | - $count++; |
|
| 577 | + if ( is_active_sidebar( 'sidebar-5' ) ) { |
|
| 578 | + $count++; |
|
| 579 | + } |
|
| 568 | 580 | |
| 569 | 581 | $class = ''; |
| 570 | 582 | |
@@ -580,9 +592,10 @@ discard block |
||
| 580 | 592 | break; |
| 581 | 593 | } |
| 582 | 594 | |
| 583 | - if ( $class ) |
|
| 584 | - echo 'class="' . esc_attr( $class ) . '"'; |
|
| 585 | -} |
|
| 595 | + if ( $class ) { |
|
| 596 | + echo 'class="' . esc_attr( $class ) . '"'; |
|
| 597 | + } |
|
| 598 | + } |
|
| 586 | 599 | |
| 587 | 600 | if ( ! function_exists( 'twentyeleven_comment' ) ) : |
| 588 | 601 | /** |
@@ -617,8 +630,9 @@ discard block |
||
| 617 | 630 | <div class="comment-author vcard"> |
| 618 | 631 | <?php |
| 619 | 632 | $avatar_size = 68; |
| 620 | - if ( '0' != $comment->comment_parent ) |
|
| 621 | - $avatar_size = 39; |
|
| 633 | + if ( '0' != $comment->comment_parent ) { |
|
| 634 | + $avatar_size = 39; |
|
| 635 | + } |
|
| 622 | 636 | |
| 623 | 637 | echo get_avatar( $comment, $avatar_size ); |
| 624 | 638 | |
@@ -691,11 +705,13 @@ discard block |
||
| 691 | 705 | */ |
| 692 | 706 | function twentyeleven_body_classes( $classes ) { |
| 693 | 707 | |
| 694 | - if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) |
|
| 695 | - $classes[] = 'single-author'; |
|
| 708 | + if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) { |
|
| 709 | + $classes[] = 'single-author'; |
|
| 710 | + } |
|
| 696 | 711 | |
| 697 | - if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) |
|
| 698 | - $classes[] = 'singular'; |
|
| 712 | + if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) { |
|
| 713 | + $classes[] = 'singular'; |
|
| 714 | + } |
|
| 699 | 715 | |
| 700 | 716 | return $classes; |
| 701 | 717 | } |
@@ -716,14 +732,16 @@ discard block |
||
| 716 | 732 | |
| 717 | 733 | if ( function_exists( 'get_post_galleries' ) ) { |
| 718 | 734 | $galleries = get_post_galleries( get_the_ID(), false ); |
| 719 | - if ( isset( $galleries[0]['ids'] ) ) |
|
| 720 | - $images = explode( ',', $galleries[0]['ids'] ); |
|
| 735 | + if ( isset( $galleries[0]['ids'] ) ) { |
|
| 736 | + $images = explode( ',', $galleries[0]['ids'] ); |
|
| 737 | + } |
|
| 721 | 738 | } else { |
| 722 | 739 | $pattern = get_shortcode_regex(); |
| 723 | 740 | preg_match( "/$pattern/s", get_the_content(), $match ); |
| 724 | 741 | $atts = shortcode_parse_atts( $match[3] ); |
| 725 | - if ( isset( $atts['ids'] ) ) |
|
| 726 | - $images = explode( ',', $atts['ids'] ); |
|
| 742 | + if ( isset( $atts['ids'] ) ) { |
|
| 743 | + $images = explode( ',', $atts['ids'] ); |
|
| 744 | + } |
|
| 727 | 745 | } |
| 728 | 746 | |
| 729 | 747 | if ( ! $images ) { |
@@ -39,15 +39,15 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | |
| 41 | 41 | // Set the content width based on the theme's design and stylesheet. |
| 42 | -if ( ! isset( $content_width ) ) |
|
| 42 | +if ( ! isset($content_width)) |
|
| 43 | 43 | $content_width = 584; |
| 44 | 44 | |
| 45 | 45 | /* |
| 46 | 46 | * Tell WordPress to run twentyeleven_setup() when the 'after_setup_theme' hook is run. |
| 47 | 47 | */ |
| 48 | -add_action( 'after_setup_theme', 'twentyeleven_setup' ); |
|
| 48 | +add_action('after_setup_theme', 'twentyeleven_setup'); |
|
| 49 | 49 | |
| 50 | -if ( ! function_exists( 'twentyeleven_setup' ) ): |
|
| 50 | +if ( ! function_exists('twentyeleven_setup')): |
|
| 51 | 51 | /** |
| 52 | 52 | * Set up theme defaults and registers support for various WordPress features. |
| 53 | 53 | * |
@@ -77,43 +77,43 @@ discard block |
||
| 77 | 77 | * a find and replace to change 'twentyeleven' to the name |
| 78 | 78 | * of your theme in all the template files. |
| 79 | 79 | */ |
| 80 | - load_theme_textdomain( 'twentyeleven', get_template_directory() . '/languages' ); |
|
| 80 | + load_theme_textdomain('twentyeleven', get_template_directory().'/languages'); |
|
| 81 | 81 | |
| 82 | 82 | // This theme styles the visual editor with editor-style.css to match the theme style. |
| 83 | 83 | add_editor_style(); |
| 84 | 84 | |
| 85 | 85 | // Load up our theme options page and related code. |
| 86 | - require( get_template_directory() . '/inc/theme-options.php' ); |
|
| 86 | + require(get_template_directory().'/inc/theme-options.php'); |
|
| 87 | 87 | |
| 88 | 88 | // Grab Twenty Eleven's Ephemera widget. |
| 89 | - require( get_template_directory() . '/inc/widgets.php' ); |
|
| 89 | + require(get_template_directory().'/inc/widgets.php'); |
|
| 90 | 90 | |
| 91 | 91 | // Add default posts and comments RSS feed links to <head>. |
| 92 | - add_theme_support( 'automatic-feed-links' ); |
|
| 92 | + add_theme_support('automatic-feed-links'); |
|
| 93 | 93 | |
| 94 | 94 | // This theme uses wp_nav_menu() in one location. |
| 95 | - register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) ); |
|
| 95 | + register_nav_menu('primary', __('Primary Menu', 'twentyeleven')); |
|
| 96 | 96 | |
| 97 | 97 | // Add support for a variety of post formats |
| 98 | - add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); |
|
| 98 | + add_theme_support('post-formats', array('aside', 'link', 'gallery', 'status', 'quote', 'image')); |
|
| 99 | 99 | |
| 100 | 100 | $theme_options = twentyeleven_get_theme_options(); |
| 101 | - if ( 'dark' == $theme_options['color_scheme'] ) |
|
| 101 | + if ('dark' == $theme_options['color_scheme']) |
|
| 102 | 102 | $default_background_color = '1d1d1d'; |
| 103 | 103 | else |
| 104 | 104 | $default_background_color = 'e2e2e2'; |
| 105 | 105 | |
| 106 | 106 | // Add support for custom backgrounds. |
| 107 | - add_theme_support( 'custom-background', array( |
|
| 107 | + add_theme_support('custom-background', array( |
|
| 108 | 108 | /* |
| 109 | 109 | * Let WordPress know what our default background color is. |
| 110 | 110 | * This is dependent on our current color scheme. |
| 111 | 111 | */ |
| 112 | 112 | 'default-color' => $default_background_color, |
| 113 | - ) ); |
|
| 113 | + )); |
|
| 114 | 114 | |
| 115 | 115 | // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images |
| 116 | - add_theme_support( 'post-thumbnails' ); |
|
| 116 | + add_theme_support('post-thumbnails'); |
|
| 117 | 117 | |
| 118 | 118 | // Add support for custom headers. |
| 119 | 119 | $custom_header_support = array( |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @param int The default header image width in pixels. Default 1000. |
| 129 | 129 | */ |
| 130 | - 'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ), |
|
| 130 | + 'width' => apply_filters('twentyeleven_header_image_width', 1000), |
|
| 131 | 131 | /** |
| 132 | 132 | * Filter the Twenty Eleven default header image height. |
| 133 | 133 | * |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @param int The default header image height in pixels. Default 288. |
| 137 | 137 | */ |
| 138 | - 'height' => apply_filters( 'twentyeleven_header_image_height', 288 ), |
|
| 138 | + 'height' => apply_filters('twentyeleven_header_image_height', 288), |
|
| 139 | 139 | // Support flexible heights. |
| 140 | 140 | 'flex-height' => true, |
| 141 | 141 | // Random image rotation by default. |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | 'admin-preview-callback' => 'twentyeleven_admin_header_image', |
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - add_theme_support( 'custom-header', $custom_header_support ); |
|
| 151 | + add_theme_support('custom-header', $custom_header_support); |
|
| 152 | 152 | |
| 153 | - if ( ! function_exists( 'get_custom_header' ) ) { |
|
| 153 | + if ( ! function_exists('get_custom_header')) { |
|
| 154 | 154 | // This is all for compatibility with versions of WordPress prior to 3.4. |
| 155 | - define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] ); |
|
| 156 | - define( 'HEADER_IMAGE', '' ); |
|
| 157 | - define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] ); |
|
| 158 | - define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] ); |
|
| 159 | - add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] ); |
|
| 155 | + define('HEADER_TEXTCOLOR', $custom_header_support['default-text-color']); |
|
| 156 | + define('HEADER_IMAGE', ''); |
|
| 157 | + define('HEADER_IMAGE_WIDTH', $custom_header_support['width']); |
|
| 158 | + define('HEADER_IMAGE_HEIGHT', $custom_header_support['height']); |
|
| 159 | + add_custom_image_header($custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback']); |
|
| 160 | 160 | add_custom_background(); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -165,74 +165,74 @@ discard block |
||
| 165 | 165 | * We want them to be the size of the header image that we just defined. |
| 166 | 166 | * Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. |
| 167 | 167 | */ |
| 168 | - set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true ); |
|
| 168 | + set_post_thumbnail_size($custom_header_support['width'], $custom_header_support['height'], true); |
|
| 169 | 169 | |
| 170 | 170 | /* |
| 171 | 171 | * Add Twenty Eleven's custom image sizes. |
| 172 | 172 | * Used for large feature (header) images. |
| 173 | 173 | */ |
| 174 | - add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true ); |
|
| 174 | + add_image_size('large-feature', $custom_header_support['width'], $custom_header_support['height'], true); |
|
| 175 | 175 | // Used for featured posts if a large-feature doesn't exist. |
| 176 | - add_image_size( 'small-feature', 500, 300 ); |
|
| 176 | + add_image_size('small-feature', 500, 300); |
|
| 177 | 177 | |
| 178 | 178 | // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. |
| 179 | - register_default_headers( array( |
|
| 179 | + register_default_headers(array( |
|
| 180 | 180 | 'wheel' => array( |
| 181 | 181 | 'url' => '%s/images/headers/wheel.jpg', |
| 182 | 182 | 'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg', |
| 183 | 183 | /* translators: header image description */ |
| 184 | - 'description' => __( 'Wheel', 'twentyeleven' ) |
|
| 184 | + 'description' => __('Wheel', 'twentyeleven') |
|
| 185 | 185 | ), |
| 186 | 186 | 'shore' => array( |
| 187 | 187 | 'url' => '%s/images/headers/shore.jpg', |
| 188 | 188 | 'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg', |
| 189 | 189 | /* translators: header image description */ |
| 190 | - 'description' => __( 'Shore', 'twentyeleven' ) |
|
| 190 | + 'description' => __('Shore', 'twentyeleven') |
|
| 191 | 191 | ), |
| 192 | 192 | 'trolley' => array( |
| 193 | 193 | 'url' => '%s/images/headers/trolley.jpg', |
| 194 | 194 | 'thumbnail_url' => '%s/images/headers/trolley-thumbnail.jpg', |
| 195 | 195 | /* translators: header image description */ |
| 196 | - 'description' => __( 'Trolley', 'twentyeleven' ) |
|
| 196 | + 'description' => __('Trolley', 'twentyeleven') |
|
| 197 | 197 | ), |
| 198 | 198 | 'pine-cone' => array( |
| 199 | 199 | 'url' => '%s/images/headers/pine-cone.jpg', |
| 200 | 200 | 'thumbnail_url' => '%s/images/headers/pine-cone-thumbnail.jpg', |
| 201 | 201 | /* translators: header image description */ |
| 202 | - 'description' => __( 'Pine Cone', 'twentyeleven' ) |
|
| 202 | + 'description' => __('Pine Cone', 'twentyeleven') |
|
| 203 | 203 | ), |
| 204 | 204 | 'chessboard' => array( |
| 205 | 205 | 'url' => '%s/images/headers/chessboard.jpg', |
| 206 | 206 | 'thumbnail_url' => '%s/images/headers/chessboard-thumbnail.jpg', |
| 207 | 207 | /* translators: header image description */ |
| 208 | - 'description' => __( 'Chessboard', 'twentyeleven' ) |
|
| 208 | + 'description' => __('Chessboard', 'twentyeleven') |
|
| 209 | 209 | ), |
| 210 | 210 | 'lanterns' => array( |
| 211 | 211 | 'url' => '%s/images/headers/lanterns.jpg', |
| 212 | 212 | 'thumbnail_url' => '%s/images/headers/lanterns-thumbnail.jpg', |
| 213 | 213 | /* translators: header image description */ |
| 214 | - 'description' => __( 'Lanterns', 'twentyeleven' ) |
|
| 214 | + 'description' => __('Lanterns', 'twentyeleven') |
|
| 215 | 215 | ), |
| 216 | 216 | 'willow' => array( |
| 217 | 217 | 'url' => '%s/images/headers/willow.jpg', |
| 218 | 218 | 'thumbnail_url' => '%s/images/headers/willow-thumbnail.jpg', |
| 219 | 219 | /* translators: header image description */ |
| 220 | - 'description' => __( 'Willow', 'twentyeleven' ) |
|
| 220 | + 'description' => __('Willow', 'twentyeleven') |
|
| 221 | 221 | ), |
| 222 | 222 | 'hanoi' => array( |
| 223 | 223 | 'url' => '%s/images/headers/hanoi.jpg', |
| 224 | 224 | 'thumbnail_url' => '%s/images/headers/hanoi-thumbnail.jpg', |
| 225 | 225 | /* translators: header image description */ |
| 226 | - 'description' => __( 'Hanoi Plant', 'twentyeleven' ) |
|
| 226 | + 'description' => __('Hanoi Plant', 'twentyeleven') |
|
| 227 | 227 | ) |
| 228 | - ) ); |
|
| 228 | + )); |
|
| 229 | 229 | |
| 230 | 230 | // Indicate widget sidebars can use selective refresh in the Customizer. |
| 231 | - add_theme_support( 'customize-selective-refresh-widgets' ); |
|
| 231 | + add_theme_support('customize-selective-refresh-widgets'); |
|
| 232 | 232 | } |
| 233 | 233 | endif; // twentyeleven_setup |
| 234 | 234 | |
| 235 | -if ( ! function_exists( 'twentyeleven_header_style' ) ) : |
|
| 235 | +if ( ! function_exists('twentyeleven_header_style')) : |
|
| 236 | 236 | /** |
| 237 | 237 | * Styles the header image and text displayed on the blog. |
| 238 | 238 | * |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | $text_color = get_header_textcolor(); |
| 243 | 243 | |
| 244 | 244 | // If no custom options for text are set, let's bail. |
| 245 | - if ( $text_color == HEADER_TEXTCOLOR ) |
|
| 245 | + if ($text_color == HEADER_TEXTCOLOR) |
|
| 246 | 246 | return; |
| 247 | 247 | |
| 248 | 248 | // If we get this far, we have custom styles. Let's do this. |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | <style type="text/css" id="twentyeleven-header-css"> |
| 251 | 251 | <?php |
| 252 | 252 | // Has the text been hidden? |
| 253 | - if ( 'blank' == $text_color ) : |
|
| 253 | + if ('blank' == $text_color) : |
|
| 254 | 254 | ?> |
| 255 | 255 | #site-title, |
| 256 | 256 | #site-description { |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | endif; // twentyeleven_header_style |
| 274 | 274 | |
| 275 | -if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : |
|
| 275 | +if ( ! function_exists('twentyeleven_admin_header_style')) : |
|
| 276 | 276 | /** |
| 277 | 277 | * Styles the header image displayed on the Appearance > Header admin panel. |
| 278 | 278 | * |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | <?php |
| 307 | 307 | // If the user has set a custom color for the text use that |
| 308 | - if ( get_header_textcolor() != HEADER_TEXTCOLOR ) : |
|
| 308 | + if (get_header_textcolor() != HEADER_TEXTCOLOR) : |
|
| 309 | 309 | ?> |
| 310 | 310 | #site-title a, |
| 311 | 311 | #site-description { |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | endif; // twentyeleven_admin_header_style |
| 324 | 324 | |
| 325 | -if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : |
|
| 325 | +if ( ! function_exists('twentyeleven_admin_header_image')) : |
|
| 326 | 326 | /** |
| 327 | 327 | * Custom header image markup displayed on the Appearance > Header admin panel. |
| 328 | 328 | * |
@@ -336,14 +336,14 @@ discard block |
||
| 336 | 336 | $color = get_header_textcolor(); |
| 337 | 337 | $image = get_header_image(); |
| 338 | 338 | $style = 'display: none;'; |
| 339 | - if ( $color && $color != 'blank' ) { |
|
| 340 | - $style = 'color: #' . $color . ';'; |
|
| 339 | + if ($color && $color != 'blank') { |
|
| 340 | + $style = 'color: #'.$color.';'; |
|
| 341 | 341 | } |
| 342 | 342 | ?> |
| 343 | - <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr( $style ); ?>" onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1> |
|
| 344 | - <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div> |
|
| 345 | - <?php if ( $image ) : ?> |
|
| 346 | - <img src="<?php echo esc_url( $image ); ?>" alt="" /> |
|
| 343 | + <h1 class="displaying-header-text"><a id="name" style="<?php echo esc_attr($style); ?>" onclick="return false;" href="<?php echo esc_url(home_url('/')); ?>" tabindex="-1"><?php bloginfo('name'); ?></a></h1> |
|
| 344 | + <div id="desc" class="displaying-header-text" style="<?php echo esc_attr($style); ?>"><?php bloginfo('description'); ?></div> |
|
| 345 | + <?php if ($image) : ?> |
|
| 346 | + <img src="<?php echo esc_url($image); ?>" alt="" /> |
|
| 347 | 347 | <?php endif; ?> |
| 348 | 348 | </div> |
| 349 | 349 | <?php } |
@@ -361,12 +361,12 @@ discard block |
||
| 361 | 361 | * @param int $length The number of excerpt characters. |
| 362 | 362 | * @return int The filtered number of characters. |
| 363 | 363 | */ |
| 364 | -function twentyeleven_excerpt_length( $length ) { |
|
| 364 | +function twentyeleven_excerpt_length($length) { |
|
| 365 | 365 | return 40; |
| 366 | 366 | } |
| 367 | -add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); |
|
| 367 | +add_filter('excerpt_length', 'twentyeleven_excerpt_length'); |
|
| 368 | 368 | |
| 369 | -if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) : |
|
| 369 | +if ( ! function_exists('twentyeleven_continue_reading_link')) : |
|
| 370 | 370 | /** |
| 371 | 371 | * Return a "Continue Reading" link for excerpts |
| 372 | 372 | * |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | * @return string The "Continue Reading" HTML link. |
| 376 | 376 | */ |
| 377 | 377 | function twentyeleven_continue_reading_link() { |
| 378 | - return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; |
|
| 378 | + return ' <a href="'.esc_url(get_permalink()).'">'.__('Continue reading <span class="meta-nav">→</span>', 'twentyeleven').'</a>'; |
|
| 379 | 379 | } |
| 380 | 380 | endif; // twentyeleven_continue_reading_link |
| 381 | 381 | |
@@ -392,13 +392,13 @@ discard block |
||
| 392 | 392 | * @param string $more The Read More text. |
| 393 | 393 | * @return The filtered Read More text. |
| 394 | 394 | */ |
| 395 | -function twentyeleven_auto_excerpt_more( $more ) { |
|
| 396 | - if ( ! is_admin() ) { |
|
| 397 | - return ' …' . twentyeleven_continue_reading_link(); |
|
| 395 | +function twentyeleven_auto_excerpt_more($more) { |
|
| 396 | + if ( ! is_admin()) { |
|
| 397 | + return ' …'.twentyeleven_continue_reading_link(); |
|
| 398 | 398 | } |
| 399 | 399 | return $more; |
| 400 | 400 | } |
| 401 | -add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); |
|
| 401 | +add_filter('excerpt_more', 'twentyeleven_auto_excerpt_more'); |
|
| 402 | 402 | |
| 403 | 403 | /** |
| 404 | 404 | * Add a pretty "Continue Reading" link to custom post excerpts. |
@@ -411,13 +411,13 @@ discard block |
||
| 411 | 411 | * @param string $output The "Continue Reading" link. |
| 412 | 412 | * @return string The filtered "Continue Reading" link. |
| 413 | 413 | */ |
| 414 | -function twentyeleven_custom_excerpt_more( $output ) { |
|
| 415 | - if ( has_excerpt() && ! is_attachment() && ! is_admin() ) { |
|
| 414 | +function twentyeleven_custom_excerpt_more($output) { |
|
| 415 | + if (has_excerpt() && ! is_attachment() && ! is_admin()) { |
|
| 416 | 416 | $output .= twentyeleven_continue_reading_link(); |
| 417 | 417 | } |
| 418 | 418 | return $output; |
| 419 | 419 | } |
| 420 | -add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); |
|
| 420 | +add_filter('get_the_excerpt', 'twentyeleven_custom_excerpt_more'); |
|
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | 423 | * Show a home link for the wp_nav_menu() fallback, wp_page_menu(). |
@@ -427,12 +427,12 @@ discard block |
||
| 427 | 427 | * @param array $args The page menu arguments. @see wp_page_menu() |
| 428 | 428 | * @return array The filtered page menu arguments. |
| 429 | 429 | */ |
| 430 | -function twentyeleven_page_menu_args( $args ) { |
|
| 431 | - if ( ! isset( $args['show_home'] ) ) |
|
| 430 | +function twentyeleven_page_menu_args($args) { |
|
| 431 | + if ( ! isset($args['show_home'])) |
|
| 432 | 432 | $args['show_home'] = true; |
| 433 | 433 | return $args; |
| 434 | 434 | } |
| 435 | -add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); |
|
| 435 | +add_filter('wp_page_menu_args', 'twentyeleven_page_menu_args'); |
|
| 436 | 436 | |
| 437 | 437 | /** |
| 438 | 438 | * Register sidebars and widgetized areas. |
@@ -443,60 +443,60 @@ discard block |
||
| 443 | 443 | */ |
| 444 | 444 | function twentyeleven_widgets_init() { |
| 445 | 445 | |
| 446 | - register_widget( 'Twenty_Eleven_Ephemera_Widget' ); |
|
| 446 | + register_widget('Twenty_Eleven_Ephemera_Widget'); |
|
| 447 | 447 | |
| 448 | - register_sidebar( array( |
|
| 449 | - 'name' => __( 'Main Sidebar', 'twentyeleven' ), |
|
| 448 | + register_sidebar(array( |
|
| 449 | + 'name' => __('Main Sidebar', 'twentyeleven'), |
|
| 450 | 450 | 'id' => 'sidebar-1', |
| 451 | 451 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 452 | 452 | 'after_widget' => '</aside>', |
| 453 | 453 | 'before_title' => '<h3 class="widget-title">', |
| 454 | 454 | 'after_title' => '</h3>', |
| 455 | - ) ); |
|
| 455 | + )); |
|
| 456 | 456 | |
| 457 | - register_sidebar( array( |
|
| 458 | - 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), |
|
| 457 | + register_sidebar(array( |
|
| 458 | + 'name' => __('Showcase Sidebar', 'twentyeleven'), |
|
| 459 | 459 | 'id' => 'sidebar-2', |
| 460 | - 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), |
|
| 460 | + 'description' => __('The sidebar for the optional Showcase Template', 'twentyeleven'), |
|
| 461 | 461 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 462 | 462 | 'after_widget' => '</aside>', |
| 463 | 463 | 'before_title' => '<h3 class="widget-title">', |
| 464 | 464 | 'after_title' => '</h3>', |
| 465 | - ) ); |
|
| 465 | + )); |
|
| 466 | 466 | |
| 467 | - register_sidebar( array( |
|
| 468 | - 'name' => __( 'Footer Area One', 'twentyeleven' ), |
|
| 467 | + register_sidebar(array( |
|
| 468 | + 'name' => __('Footer Area One', 'twentyeleven'), |
|
| 469 | 469 | 'id' => 'sidebar-3', |
| 470 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 470 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 471 | 471 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 472 | 472 | 'after_widget' => '</aside>', |
| 473 | 473 | 'before_title' => '<h3 class="widget-title">', |
| 474 | 474 | 'after_title' => '</h3>', |
| 475 | - ) ); |
|
| 475 | + )); |
|
| 476 | 476 | |
| 477 | - register_sidebar( array( |
|
| 478 | - 'name' => __( 'Footer Area Two', 'twentyeleven' ), |
|
| 477 | + register_sidebar(array( |
|
| 478 | + 'name' => __('Footer Area Two', 'twentyeleven'), |
|
| 479 | 479 | 'id' => 'sidebar-4', |
| 480 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 480 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 481 | 481 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 482 | 482 | 'after_widget' => '</aside>', |
| 483 | 483 | 'before_title' => '<h3 class="widget-title">', |
| 484 | 484 | 'after_title' => '</h3>', |
| 485 | - ) ); |
|
| 485 | + )); |
|
| 486 | 486 | |
| 487 | - register_sidebar( array( |
|
| 488 | - 'name' => __( 'Footer Area Three', 'twentyeleven' ), |
|
| 487 | + register_sidebar(array( |
|
| 488 | + 'name' => __('Footer Area Three', 'twentyeleven'), |
|
| 489 | 489 | 'id' => 'sidebar-5', |
| 490 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 490 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 491 | 491 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 492 | 492 | 'after_widget' => '</aside>', |
| 493 | 493 | 'before_title' => '<h3 class="widget-title">', |
| 494 | 494 | 'after_title' => '</h3>', |
| 495 | - ) ); |
|
| 495 | + )); |
|
| 496 | 496 | } |
| 497 | -add_action( 'widgets_init', 'twentyeleven_widgets_init' ); |
|
| 497 | +add_action('widgets_init', 'twentyeleven_widgets_init'); |
|
| 498 | 498 | |
| 499 | -if ( ! function_exists( 'twentyeleven_content_nav' ) ) : |
|
| 499 | +if ( ! function_exists('twentyeleven_content_nav')) : |
|
| 500 | 500 | /** |
| 501 | 501 | * Display navigation to next/previous pages when applicable. |
| 502 | 502 | * |
@@ -504,14 +504,14 @@ discard block |
||
| 504 | 504 | * |
| 505 | 505 | * @param string $html_id The HTML id attribute. |
| 506 | 506 | */ |
| 507 | -function twentyeleven_content_nav( $html_id ) { |
|
| 507 | +function twentyeleven_content_nav($html_id) { |
|
| 508 | 508 | global $wp_query; |
| 509 | 509 | |
| 510 | - if ( $wp_query->max_num_pages > 1 ) : ?> |
|
| 511 | - <nav id="<?php echo esc_attr( $html_id ); ?>"> |
|
| 512 | - <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> |
|
| 513 | - <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> |
|
| 514 | - <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div> |
|
| 510 | + if ($wp_query->max_num_pages > 1) : ?> |
|
| 511 | + <nav id="<?php echo esc_attr($html_id); ?>"> |
|
| 512 | + <h3 class="assistive-text"><?php _e('Post navigation', 'twentyeleven'); ?></h3> |
|
| 513 | + <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">←</span> Older posts', 'twentyeleven')); ?></div> |
|
| 514 | + <div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">→</span>', 'twentyeleven')); ?></div> |
|
| 515 | 515 | </nav><!-- #nav-above --> |
| 516 | 516 | <?php endif; |
| 517 | 517 | } |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | function twentyeleven_get_first_url() { |
| 531 | 531 | $content = get_the_content(); |
| 532 | - $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; |
|
| 532 | + $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false; |
|
| 533 | 533 | |
| 534 | - if ( ! $has_url ) |
|
| 534 | + if ( ! $has_url) |
|
| 535 | 535 | $has_url = twentyeleven_url_grabber(); |
| 536 | 536 | |
| 537 | 537 | /** This filter is documented in wp-includes/link-template.php */ |
| 538 | - return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); |
|
| 538 | + return ($has_url) ? $has_url : apply_filters('the_permalink', get_permalink()); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -546,10 +546,10 @@ discard block |
||
| 546 | 546 | * @return string|bool URL or false when no link is present. |
| 547 | 547 | */ |
| 548 | 548 | function twentyeleven_url_grabber() { |
| 549 | - if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) |
|
| 549 | + if ( ! preg_match('/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches)) |
|
| 550 | 550 | return false; |
| 551 | 551 | |
| 552 | - return esc_url_raw( $matches[1] ); |
|
| 552 | + return esc_url_raw($matches[1]); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -560,18 +560,18 @@ discard block |
||
| 560 | 560 | function twentyeleven_footer_sidebar_class() { |
| 561 | 561 | $count = 0; |
| 562 | 562 | |
| 563 | - if ( is_active_sidebar( 'sidebar-3' ) ) |
|
| 563 | + if (is_active_sidebar('sidebar-3')) |
|
| 564 | 564 | $count++; |
| 565 | 565 | |
| 566 | - if ( is_active_sidebar( 'sidebar-4' ) ) |
|
| 566 | + if (is_active_sidebar('sidebar-4')) |
|
| 567 | 567 | $count++; |
| 568 | 568 | |
| 569 | - if ( is_active_sidebar( 'sidebar-5' ) ) |
|
| 569 | + if (is_active_sidebar('sidebar-5')) |
|
| 570 | 570 | $count++; |
| 571 | 571 | |
| 572 | 572 | $class = ''; |
| 573 | 573 | |
| 574 | - switch ( $count ) { |
|
| 574 | + switch ($count) { |
|
| 575 | 575 | case '1': |
| 576 | 576 | $class = 'one'; |
| 577 | 577 | break; |
@@ -583,11 +583,11 @@ discard block |
||
| 583 | 583 | break; |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | - if ( $class ) |
|
| 587 | - echo 'class="' . esc_attr( $class ) . '"'; |
|
| 586 | + if ($class) |
|
| 587 | + echo 'class="'.esc_attr($class).'"'; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | -if ( ! function_exists( 'twentyeleven_comment' ) ) : |
|
| 590 | +if ( ! function_exists('twentyeleven_comment')) : |
|
| 591 | 591 | /** |
| 592 | 592 | * Template for comments and pingbacks. |
| 593 | 593 | * |
@@ -602,14 +602,14 @@ discard block |
||
| 602 | 602 | * @param array $args An array of comment arguments. @see get_comment_reply_link() |
| 603 | 603 | * @param int $depth The depth of the comment. |
| 604 | 604 | */ |
| 605 | -function twentyeleven_comment( $comment, $args, $depth ) { |
|
| 605 | +function twentyeleven_comment($comment, $args, $depth) { |
|
| 606 | 606 | $GLOBALS['comment'] = $comment; |
| 607 | - switch ( $comment->comment_type ) : |
|
| 607 | + switch ($comment->comment_type) : |
|
| 608 | 608 | case 'pingback' : |
| 609 | 609 | case 'trackback' : |
| 610 | 610 | ?> |
| 611 | 611 | <li class="post pingback"> |
| 612 | - <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p> |
|
| 612 | + <p><?php _e('Pingback:', 'twentyeleven'); ?> <?php comment_author_link(); ?><?php edit_comment_link(__('Edit', 'twentyeleven'), '<span class="edit-link">', '</span>'); ?></p> |
|
| 613 | 613 | <?php |
| 614 | 614 | break; |
| 615 | 615 | default : |
@@ -620,28 +620,28 @@ discard block |
||
| 620 | 620 | <div class="comment-author vcard"> |
| 621 | 621 | <?php |
| 622 | 622 | $avatar_size = 68; |
| 623 | - if ( '0' != $comment->comment_parent ) |
|
| 623 | + if ('0' != $comment->comment_parent) |
|
| 624 | 624 | $avatar_size = 39; |
| 625 | 625 | |
| 626 | - echo get_avatar( $comment, $avatar_size ); |
|
| 626 | + echo get_avatar($comment, $avatar_size); |
|
| 627 | 627 | |
| 628 | 628 | /* translators: 1: comment author, 2: date and time */ |
| 629 | - printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ), |
|
| 630 | - sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), |
|
| 631 | - sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', |
|
| 632 | - esc_url( get_comment_link( $comment->comment_ID ) ), |
|
| 633 | - get_comment_time( 'c' ), |
|
| 629 | + printf(__('%1$s on %2$s <span class="says">said:</span>', 'twentyeleven'), |
|
| 630 | + sprintf('<span class="fn">%s</span>', get_comment_author_link()), |
|
| 631 | + sprintf('<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', |
|
| 632 | + esc_url(get_comment_link($comment->comment_ID)), |
|
| 633 | + get_comment_time('c'), |
|
| 634 | 634 | /* translators: 1: date, 2: time */ |
| 635 | - sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) |
|
| 635 | + sprintf(__('%1$s at %2$s', 'twentyeleven'), get_comment_date(), get_comment_time()) |
|
| 636 | 636 | ) |
| 637 | 637 | ); |
| 638 | 638 | ?> |
| 639 | 639 | |
| 640 | - <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> |
|
| 640 | + <?php edit_comment_link(__('Edit', 'twentyeleven'), '<span class="edit-link">', '</span>'); ?> |
|
| 641 | 641 | </div><!-- .comment-author .vcard --> |
| 642 | 642 | |
| 643 | - <?php if ( $comment->comment_approved == '0' ) : ?> |
|
| 644 | - <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em> |
|
| 643 | + <?php if ($comment->comment_approved == '0') : ?> |
|
| 644 | + <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'twentyeleven'); ?></em> |
|
| 645 | 645 | <br /> |
| 646 | 646 | <?php endif; ?> |
| 647 | 647 | |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | <div class="comment-content"><?php comment_text(); ?></div> |
| 651 | 651 | |
| 652 | 652 | <div class="reply"> |
| 653 | - <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>↓</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
|
| 653 | + <?php comment_reply_link(array_merge($args, array('reply_text' => __('Reply <span>↓</span>', 'twentyeleven'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> |
|
| 654 | 654 | </div><!-- .reply --> |
| 655 | 655 | </article><!-- #comment-## --> |
| 656 | 656 | |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | } |
| 661 | 661 | endif; // ends check for twentyeleven_comment() |
| 662 | 662 | |
| 663 | -if ( ! function_exists( 'twentyeleven_posted_on' ) ) : |
|
| 663 | +if ( ! function_exists('twentyeleven_posted_on')) : |
|
| 664 | 664 | /** |
| 665 | 665 | * Print HTML with meta information for the current post-date/time and author. |
| 666 | 666 | * |
@@ -669,13 +669,13 @@ discard block |
||
| 669 | 669 | * @since Twenty Eleven 1.0 |
| 670 | 670 | */ |
| 671 | 671 | function twentyeleven_posted_on() { |
| 672 | - printf( __( '<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven' ), |
|
| 673 | - esc_url( get_permalink() ), |
|
| 674 | - esc_attr( get_the_time() ), |
|
| 675 | - esc_attr( get_the_date( 'c' ) ), |
|
| 676 | - esc_html( get_the_date() ), |
|
| 677 | - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
|
| 678 | - esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), |
|
| 672 | + printf(__('<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a><span class="by-author"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'twentyeleven'), |
|
| 673 | + esc_url(get_permalink()), |
|
| 674 | + esc_attr(get_the_time()), |
|
| 675 | + esc_attr(get_the_date('c')), |
|
| 676 | + esc_html(get_the_date()), |
|
| 677 | + esc_url(get_author_posts_url(get_the_author_meta('ID'))), |
|
| 678 | + esc_attr(sprintf(__('View all posts by %s', 'twentyeleven'), get_the_author())), |
|
| 679 | 679 | get_the_author() |
| 680 | 680 | ); |
| 681 | 681 | } |
@@ -692,17 +692,17 @@ discard block |
||
| 692 | 692 | * @param array $classes Existing body classes. |
| 693 | 693 | * @return array The filtered array of body classes. |
| 694 | 694 | */ |
| 695 | -function twentyeleven_body_classes( $classes ) { |
|
| 695 | +function twentyeleven_body_classes($classes) { |
|
| 696 | 696 | |
| 697 | - if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) |
|
| 697 | + if (function_exists('is_multi_author') && ! is_multi_author()) |
|
| 698 | 698 | $classes[] = 'single-author'; |
| 699 | 699 | |
| 700 | - if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) |
|
| 700 | + if (is_singular() && ! is_home() && ! is_page_template('showcase.php') && ! is_page_template('sidebar-page.php')) |
|
| 701 | 701 | $classes[] = 'singular'; |
| 702 | 702 | |
| 703 | 703 | return $classes; |
| 704 | 704 | } |
| 705 | -add_filter( 'body_class', 'twentyeleven_body_classes' ); |
|
| 705 | +add_filter('body_class', 'twentyeleven_body_classes'); |
|
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | 708 | * Retrieve the IDs for images in a gallery. |
@@ -717,20 +717,20 @@ discard block |
||
| 717 | 717 | function twentyeleven_get_gallery_images() { |
| 718 | 718 | $images = array(); |
| 719 | 719 | |
| 720 | - if ( function_exists( 'get_post_galleries' ) ) { |
|
| 721 | - $galleries = get_post_galleries( get_the_ID(), false ); |
|
| 722 | - if ( isset( $galleries[0]['ids'] ) ) |
|
| 723 | - $images = explode( ',', $galleries[0]['ids'] ); |
|
| 720 | + if (function_exists('get_post_galleries')) { |
|
| 721 | + $galleries = get_post_galleries(get_the_ID(), false); |
|
| 722 | + if (isset($galleries[0]['ids'])) |
|
| 723 | + $images = explode(',', $galleries[0]['ids']); |
|
| 724 | 724 | } else { |
| 725 | 725 | $pattern = get_shortcode_regex(); |
| 726 | - preg_match( "/$pattern/s", get_the_content(), $match ); |
|
| 727 | - $atts = shortcode_parse_atts( $match[3] ); |
|
| 728 | - if ( isset( $atts['ids'] ) ) |
|
| 729 | - $images = explode( ',', $atts['ids'] ); |
|
| 726 | + preg_match("/$pattern/s", get_the_content(), $match); |
|
| 727 | + $atts = shortcode_parse_atts($match[3]); |
|
| 728 | + if (isset($atts['ids'])) |
|
| 729 | + $images = explode(',', $atts['ids']); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - if ( ! $images ) { |
|
| 733 | - $images = get_posts( array( |
|
| 732 | + if ( ! $images) { |
|
| 733 | + $images = get_posts(array( |
|
| 734 | 734 | 'fields' => 'ids', |
| 735 | 735 | 'numberposts' => 999, |
| 736 | 736 | 'order' => 'ASC', |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | 'post_mime_type' => 'image', |
| 739 | 739 | 'post_parent' => get_the_ID(), |
| 740 | 740 | 'post_type' => 'attachment', |
| 741 | - ) ); |
|
| 741 | + )); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | return $images; |
@@ -503,7 +503,7 @@ |
||
| 503 | 503 | * @access private |
| 504 | 504 | * |
| 505 | 505 | * @param string $query_string |
| 506 | - * @param array $args_to_check |
|
| 506 | + * @param string[] $args_to_check |
|
| 507 | 507 | * @param string $url |
| 508 | 508 | * @return string The altered query string |
| 509 | 509 | */ |
@@ -75,10 +75,12 @@ discard block |
||
| 75 | 75 | $redirect_url = false; |
| 76 | 76 | |
| 77 | 77 | // Notice fixing |
| 78 | - if ( !isset($redirect['path']) ) |
|
| 79 | - $redirect['path'] = ''; |
|
| 80 | - if ( !isset($redirect['query']) ) |
|
| 81 | - $redirect['query'] = ''; |
|
| 78 | + if ( !isset($redirect['path']) ) { |
|
| 79 | + $redirect['path'] = ''; |
|
| 80 | + } |
|
| 81 | + if ( !isset($redirect['query']) ) { |
|
| 82 | + $redirect['query'] = ''; |
|
| 83 | + } |
|
| 82 | 84 | |
| 83 | 85 | // If the original URL ended with non-breaking spaces, they were almost |
| 84 | 86 | // certainly inserted by accident. Let's remove them, so the reader doesn't |
@@ -102,11 +104,13 @@ discard block |
||
| 102 | 104 | $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); |
| 103 | 105 | |
| 104 | 106 | if ( isset($vars[0]) && $vars = $vars[0] ) { |
| 105 | - if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) |
|
| 106 | - $id = $vars->post_parent; |
|
| 107 | + if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) { |
|
| 108 | + $id = $vars->post_parent; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | - if ( $redirect_url = get_permalink($id) ) |
|
| 109 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
|
| 111 | + if ( $redirect_url = get_permalink($id) ) { |
|
| 112 | + $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
|
| 113 | + } |
|
| 110 | 114 | } |
| 111 | 115 | } |
| 112 | 116 | |
@@ -164,19 +168,23 @@ discard block |
||
| 164 | 168 | $redirect_url = get_attachment_link(); |
| 165 | 169 | } |
| 166 | 170 | } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { |
| 167 | - if ( $redirect_url = get_permalink(get_query_var('p')) ) |
|
| 168 | - $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); |
|
| 171 | + if ( $redirect_url = get_permalink(get_query_var('p')) ) { |
|
| 172 | + $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); |
|
| 173 | + } |
|
| 169 | 174 | } elseif ( is_single() && !empty($_GET['name']) && ! $redirect_url ) { |
| 170 | - if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) |
|
| 171 | - $redirect['query'] = remove_query_arg('name', $redirect['query']); |
|
| 175 | + if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) { |
|
| 176 | + $redirect['query'] = remove_query_arg('name', $redirect['query']); |
|
| 177 | + } |
|
| 172 | 178 | } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) { |
| 173 | - if ( $redirect_url = get_permalink(get_query_var('page_id')) ) |
|
| 174 | - $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
|
| 179 | + if ( $redirect_url = get_permalink(get_query_var('page_id')) ) { |
|
| 180 | + $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
|
| 181 | + } |
|
| 175 | 182 | } elseif ( is_page() && !is_feed() && 'page' == get_option('show_on_front') && get_queried_object_id() == get_option('page_on_front') && ! $redirect_url ) { |
| 176 | 183 | $redirect_url = home_url('/'); |
| 177 | 184 | } elseif ( is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && ! $redirect_url ) { |
| 178 | - if ( $redirect_url = get_permalink(get_option('page_for_posts')) ) |
|
| 179 | - $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
|
| 185 | + if ( $redirect_url = get_permalink(get_option('page_for_posts')) ) { |
|
| 186 | + $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
|
| 187 | + } |
|
| 180 | 188 | } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { |
| 181 | 189 | $m = get_query_var('m'); |
| 182 | 190 | switch ( strlen($m) ) { |
@@ -190,29 +198,35 @@ discard block |
||
| 190 | 198 | $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); |
| 191 | 199 | break; |
| 192 | 200 | } |
| 193 | - if ( $redirect_url ) |
|
| 194 | - $redirect['query'] = remove_query_arg('m', $redirect['query']); |
|
| 201 | + if ( $redirect_url ) { |
|
| 202 | + $redirect['query'] = remove_query_arg('m', $redirect['query']); |
|
| 203 | + } |
|
| 195 | 204 | // now moving on to non ?m=X year/month/day links |
| 196 | 205 | } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) { |
| 197 | - if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) |
|
| 198 | - $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); |
|
| 206 | + if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) { |
|
| 207 | + $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); |
|
| 208 | + } |
|
| 199 | 209 | } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { |
| 200 | - if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) |
|
| 201 | - $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); |
|
| 210 | + if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) { |
|
| 211 | + $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); |
|
| 212 | + } |
|
| 202 | 213 | } elseif ( is_year() && !empty($_GET['year']) ) { |
| 203 | - if ( $redirect_url = get_year_link(get_query_var('year')) ) |
|
| 204 | - $redirect['query'] = remove_query_arg('year', $redirect['query']); |
|
| 214 | + if ( $redirect_url = get_year_link(get_query_var('year')) ) { |
|
| 215 | + $redirect['query'] = remove_query_arg('year', $redirect['query']); |
|
| 216 | + } |
|
| 205 | 217 | } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { |
| 206 | 218 | $author = get_userdata(get_query_var('author')); |
| 207 | 219 | if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { |
| 208 | - if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) |
|
| 209 | - $redirect['query'] = remove_query_arg('author', $redirect['query']); |
|
| 220 | + if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) { |
|
| 221 | + $redirect['query'] = remove_query_arg('author', $redirect['query']); |
|
| 222 | + } |
|
| 210 | 223 | } |
| 211 | 224 | } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) |
| 212 | 225 | |
| 213 | 226 | $term_count = 0; |
| 214 | - foreach ( $wp_query->tax_query->queried_terms as $tax_query ) |
|
| 215 | - $term_count += count( $tax_query['terms'] ); |
|
| 227 | + foreach ( $wp_query->tax_query->queried_terms as $tax_query ) { |
|
| 228 | + $term_count += count( $tax_query['terms'] ); |
|
| 229 | + } |
|
| 216 | 230 | |
| 217 | 231 | $obj = $wp_query->get_queried_object(); |
| 218 | 232 | if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { |
@@ -227,8 +241,9 @@ discard block |
||
| 227 | 241 | $qv_remove[] = 'tag_id'; |
| 228 | 242 | } else { // Custom taxonomies will have a custom query var, remove those too: |
| 229 | 243 | $tax_obj = get_taxonomy( $obj->taxonomy ); |
| 230 | - if ( false !== $tax_obj->query_var ) |
|
| 231 | - $qv_remove[] = $tax_obj->query_var; |
|
| 244 | + if ( false !== $tax_obj->query_var ) { |
|
| 245 | + $qv_remove[] = $tax_obj->query_var; |
|
| 246 | + } |
|
| 232 | 247 | } |
| 233 | 248 | |
| 234 | 249 | $rewrite_vars = array_diff( array_keys($wp_query->query), array_keys($_GET) ); |
@@ -247,8 +262,9 @@ discard block |
||
| 247 | 262 | |
| 248 | 263 | } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite |
| 249 | 264 | foreach ( $qv_remove as $_qv ) { |
| 250 | - if ( isset($rewrite_vars[$_qv]) ) |
|
| 251 | - $redirect['query'] = remove_query_arg($_qv, $redirect['query']); |
|
| 265 | + if ( isset($rewrite_vars[$_qv]) ) { |
|
| 266 | + $redirect['query'] = remove_query_arg($_qv, $redirect['query']); |
|
| 267 | + } |
|
| 252 | 268 | } |
| 253 | 269 | } |
| 254 | 270 | } |
@@ -264,8 +280,9 @@ discard block |
||
| 264 | 280 | |
| 265 | 281 | // Post Paging |
| 266 | 282 | if ( is_singular() && get_query_var('page') ) { |
| 267 | - if ( !$redirect_url ) |
|
| 268 | - $redirect_url = get_permalink( get_queried_object_id() ); |
|
| 283 | + if ( !$redirect_url ) { |
|
| 284 | + $redirect_url = get_permalink( get_queried_object_id() ); |
|
| 285 | + } |
|
| 269 | 286 | |
| 270 | 287 | $page = get_query_var( 'page' ); |
| 271 | 288 | if ( $page > 1 ) { |
@@ -290,12 +307,14 @@ discard block |
||
| 290 | 307 | $addl_path = ''; |
| 291 | 308 | if ( is_feed() && in_array( get_query_var('feed'), $wp_rewrite->feeds ) ) { |
| 292 | 309 | $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; |
| 293 | - if ( !is_singular() && get_query_var( 'withcomments' ) ) |
|
| 294 | - $addl_path .= 'comments/'; |
|
| 295 | - if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var('feed') ) || 'rss' == get_query_var('feed') ) |
|
| 296 | - $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' ); |
|
| 297 | - else |
|
| 298 | - $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); |
|
| 310 | + if ( !is_singular() && get_query_var( 'withcomments' ) ) { |
|
| 311 | + $addl_path .= 'comments/'; |
|
| 312 | + } |
|
| 313 | + if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var('feed') ) || 'rss' == get_query_var('feed') ) { |
|
| 314 | + $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' ); |
|
| 315 | + } else { |
|
| 316 | + $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); |
|
| 317 | + } |
|
| 299 | 318 | $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); |
| 300 | 319 | } elseif ( is_feed() && 'old' == get_query_var('feed') ) { |
| 301 | 320 | $old_feed_files = array( |
@@ -336,10 +355,12 @@ discard block |
||
| 336 | 355 | } |
| 337 | 356 | |
| 338 | 357 | $redirect['path'] = user_trailingslashit( preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path']) ); // strip off trailing /index.php/ |
| 339 | - if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/' . $wp_rewrite->index . '/') === false ) |
|
| 340 | - $redirect['path'] = trailingslashit($redirect['path']) . $wp_rewrite->index . '/'; |
|
| 341 | - if ( !empty( $addl_path ) ) |
|
| 342 | - $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; |
|
| 358 | + if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/' . $wp_rewrite->index . '/') === false ) { |
|
| 359 | + $redirect['path'] = trailingslashit($redirect['path']) . $wp_rewrite->index . '/'; |
|
| 360 | + } |
|
| 361 | + if ( !empty( $addl_path ) ) { |
|
| 362 | + $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; |
|
| 363 | + } |
|
| 343 | 364 | $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; |
| 344 | 365 | } |
| 345 | 366 | |
@@ -365,29 +386,34 @@ discard block |
||
| 365 | 386 | if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { |
| 366 | 387 | parse_str( $redirect['query'], $_parsed_redirect_query ); |
| 367 | 388 | |
| 368 | - if ( empty( $_parsed_redirect_query['name'] ) ) |
|
| 369 | - unset( $_parsed_query['name'] ); |
|
| 389 | + if ( empty( $_parsed_redirect_query['name'] ) ) { |
|
| 390 | + unset( $_parsed_query['name'] ); |
|
| 391 | + } |
|
| 370 | 392 | } |
| 371 | 393 | |
| 372 | 394 | $_parsed_query = rawurlencode_deep( $_parsed_query ); |
| 373 | 395 | $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); |
| 374 | 396 | } |
| 375 | 397 | |
| 376 | - if ( $redirect_url ) |
|
| 377 | - $redirect = @parse_url($redirect_url); |
|
| 398 | + if ( $redirect_url ) { |
|
| 399 | + $redirect = @parse_url($redirect_url); |
|
| 400 | + } |
|
| 378 | 401 | |
| 379 | 402 | // www.example.com vs example.com |
| 380 | 403 | $user_home = @parse_url(home_url()); |
| 381 | - if ( !empty($user_home['host']) ) |
|
| 382 | - $redirect['host'] = $user_home['host']; |
|
| 383 | - if ( empty($user_home['path']) ) |
|
| 384 | - $user_home['path'] = '/'; |
|
| 404 | + if ( !empty($user_home['host']) ) { |
|
| 405 | + $redirect['host'] = $user_home['host']; |
|
| 406 | + } |
|
| 407 | + if ( empty($user_home['path']) ) { |
|
| 408 | + $user_home['path'] = '/'; |
|
| 409 | + } |
|
| 385 | 410 | |
| 386 | 411 | // Handle ports |
| 387 | - if ( !empty($user_home['port']) ) |
|
| 388 | - $redirect['port'] = $user_home['port']; |
|
| 389 | - else |
|
| 390 | - unset($redirect['port']); |
|
| 412 | + if ( !empty($user_home['port']) ) { |
|
| 413 | + $redirect['port'] = $user_home['port']; |
|
| 414 | + } else { |
|
| 415 | + unset($redirect['port']); |
|
| 416 | + } |
|
| 391 | 417 | |
| 392 | 418 | // trailing /index.php |
| 393 | 419 | $redirect['path'] = preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path']); |
@@ -410,8 +436,9 @@ discard block |
||
| 410 | 436 | } |
| 411 | 437 | |
| 412 | 438 | // strip /index.php/ when we're not using PATHINFO permalinks |
| 413 | - if ( !$wp_rewrite->using_index_permalinks() ) |
|
| 414 | - $redirect['path'] = str_replace( '/' . $wp_rewrite->index . '/', '/', $redirect['path'] ); |
|
| 439 | + if ( !$wp_rewrite->using_index_permalinks() ) { |
|
| 440 | + $redirect['path'] = str_replace( '/' . $wp_rewrite->index . '/', '/', $redirect['path'] ); |
|
| 441 | + } |
|
| 415 | 442 | |
| 416 | 443 | // trailing slashes |
| 417 | 444 | if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { |
@@ -433,42 +460,51 @@ discard block |
||
| 433 | 460 | } |
| 434 | 461 | |
| 435 | 462 | // Strip multiple slashes out of the URL |
| 436 | - if ( strpos($redirect['path'], '//') > -1 ) |
|
| 437 | - $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); |
|
| 463 | + if ( strpos($redirect['path'], '//') > -1 ) { |
|
| 464 | + $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); |
|
| 465 | + } |
|
| 438 | 466 | |
| 439 | 467 | // Always trailing slash the Front Page URL |
| 440 | - if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) |
|
| 441 | - $redirect['path'] = trailingslashit($redirect['path']); |
|
| 468 | + if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) { |
|
| 469 | + $redirect['path'] = trailingslashit($redirect['path']); |
|
| 470 | + } |
|
| 442 | 471 | |
| 443 | 472 | // Ignore differences in host capitalization, as this can lead to infinite redirects |
| 444 | 473 | // Only redirect no-www <=> yes-www |
| 445 | 474 | if ( strtolower($original['host']) == strtolower($redirect['host']) || |
| 446 | - ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) |
|
| 447 | - $redirect['host'] = $original['host']; |
|
| 475 | + ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) { |
|
| 476 | + $redirect['host'] = $original['host']; |
|
| 477 | + } |
|
| 448 | 478 | |
| 449 | 479 | $compare_original = array( $original['host'], $original['path'] ); |
| 450 | 480 | |
| 451 | - if ( !empty( $original['port'] ) ) |
|
| 452 | - $compare_original[] = $original['port']; |
|
| 481 | + if ( !empty( $original['port'] ) ) { |
|
| 482 | + $compare_original[] = $original['port']; |
|
| 483 | + } |
|
| 453 | 484 | |
| 454 | - if ( !empty( $original['query'] ) ) |
|
| 455 | - $compare_original[] = $original['query']; |
|
| 485 | + if ( !empty( $original['query'] ) ) { |
|
| 486 | + $compare_original[] = $original['query']; |
|
| 487 | + } |
|
| 456 | 488 | |
| 457 | 489 | $compare_redirect = array( $redirect['host'], $redirect['path'] ); |
| 458 | 490 | |
| 459 | - if ( !empty( $redirect['port'] ) ) |
|
| 460 | - $compare_redirect[] = $redirect['port']; |
|
| 491 | + if ( !empty( $redirect['port'] ) ) { |
|
| 492 | + $compare_redirect[] = $redirect['port']; |
|
| 493 | + } |
|
| 461 | 494 | |
| 462 | - if ( !empty( $redirect['query'] ) ) |
|
| 463 | - $compare_redirect[] = $redirect['query']; |
|
| 495 | + if ( !empty( $redirect['query'] ) ) { |
|
| 496 | + $compare_redirect[] = $redirect['query']; |
|
| 497 | + } |
|
| 464 | 498 | |
| 465 | 499 | if ( $compare_original !== $compare_redirect ) { |
| 466 | 500 | $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; |
| 467 | - if ( !empty($redirect['port']) ) |
|
| 468 | - $redirect_url .= ':' . $redirect['port']; |
|
| 501 | + if ( !empty($redirect['port']) ) { |
|
| 502 | + $redirect_url .= ':' . $redirect['port']; |
|
| 503 | + } |
|
| 469 | 504 | $redirect_url .= $redirect['path']; |
| 470 | - if ( !empty($redirect['query']) ) |
|
| 471 | - $redirect_url .= '?' . $redirect['query']; |
|
| 505 | + if ( !empty($redirect['query']) ) { |
|
| 506 | + $redirect_url .= '?' . $redirect['query']; |
|
| 507 | + } |
|
| 472 | 508 | } |
| 473 | 509 | |
| 474 | 510 | if ( ! $redirect_url || $redirect_url == $requested_url ) { |
@@ -534,8 +570,9 @@ discard block |
||
| 534 | 570 | if ( ! empty( $parsed_url['query'] ) ) { |
| 535 | 571 | parse_str( $parsed_url['query'], $parsed_query ); |
| 536 | 572 | foreach ( $args_to_check as $qv ) { |
| 537 | - if ( !isset( $parsed_query[$qv] ) ) |
|
| 538 | - $query_string = remove_query_arg( $qv, $query_string ); |
|
| 573 | + if ( !isset( $parsed_query[$qv] ) ) { |
|
| 574 | + $query_string = remove_query_arg( $qv, $query_string ); |
|
| 575 | + } |
|
| 539 | 576 | } |
| 540 | 577 | } else { |
| 541 | 578 | $query_string = remove_query_arg( $args_to_check, $query_string ); |
@@ -584,27 +621,33 @@ discard block |
||
| 584 | 621 | $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like( get_query_var('name') ) . '%'); |
| 585 | 622 | |
| 586 | 623 | // if any of post_type, year, monthnum, or day are set, use them to refine the query |
| 587 | - if ( get_query_var('post_type') ) |
|
| 588 | - $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type')); |
|
| 589 | - else |
|
| 590 | - $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
|
| 591 | - |
|
| 592 | - if ( get_query_var('year') ) |
|
| 593 | - $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); |
|
| 594 | - if ( get_query_var('monthnum') ) |
|
| 595 | - $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum')); |
|
| 596 | - if ( get_query_var('day') ) |
|
| 597 | - $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day')); |
|
| 624 | + if ( get_query_var('post_type') ) { |
|
| 625 | + $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type')); |
|
| 626 | + } else { |
|
| 627 | + $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + if ( get_query_var('year') ) { |
|
| 631 | + $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); |
|
| 632 | + } |
|
| 633 | + if ( get_query_var('monthnum') ) { |
|
| 634 | + $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum')); |
|
| 635 | + } |
|
| 636 | + if ( get_query_var('day') ) { |
|
| 637 | + $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day')); |
|
| 638 | + } |
|
| 598 | 639 | |
| 599 | 640 | $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'"); |
| 600 | - if ( ! $post_id ) |
|
| 601 | - return false; |
|
| 602 | - if ( get_query_var( 'feed' ) ) |
|
| 603 | - return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); |
|
| 604 | - elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) |
|
| 605 | - return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); |
|
| 606 | - else |
|
| 607 | - return get_permalink( $post_id ); |
|
| 641 | + if ( ! $post_id ) { |
|
| 642 | + return false; |
|
| 643 | + } |
|
| 644 | + if ( get_query_var( 'feed' ) ) { |
|
| 645 | + return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); |
|
| 646 | + } elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) { |
|
| 647 | + return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); |
|
| 648 | + } else { |
|
| 649 | + return get_permalink( $post_id ); |
|
| 650 | + } |
|
| 608 | 651 | } |
| 609 | 652 | |
| 610 | 653 | return false; |
@@ -622,8 +665,9 @@ discard block |
||
| 622 | 665 | */ |
| 623 | 666 | function wp_redirect_admin_locations() { |
| 624 | 667 | global $wp_rewrite; |
| 625 | - if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) |
|
| 626 | - return; |
|
| 668 | + if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) { |
|
| 669 | + return; |
|
| 670 | + } |
|
| 627 | 671 | |
| 628 | 672 | $admins = array( |
| 629 | 673 | home_url( 'wp-admin', 'relative' ), |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | * @param bool $do_redirect Optional. Redirect to the new URL. |
| 39 | 39 | * @return string|void The string of the URL, if redirect needed. |
| 40 | 40 | */ |
| 41 | -function redirect_canonical( $requested_url = null, $do_redirect = true ) { |
|
| 41 | +function redirect_canonical($requested_url = null, $do_redirect = true) { |
|
| 42 | 42 | global $wp_rewrite, $is_IIS, $wp_query, $wpdb, $wp; |
| 43 | 43 | |
| 44 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && ! in_array( strtoupper( $_SERVER['REQUEST_METHOD'] ), array( 'GET', 'HEAD' ) ) ) { |
|
| 44 | + if (isset($_SERVER['REQUEST_METHOD']) && ! in_array(strtoupper($_SERVER['REQUEST_METHOD']), array('GET', 'HEAD'))) { |
|
| 45 | 45 | return; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // If we're not in wp-admin and the post has been published and preview nonce |
| 49 | 49 | // is non-existent or invalid then no need for preview in query |
| 50 | - if ( is_preview() && get_query_var( 'p' ) && 'publish' == get_post_status( get_query_var( 'p' ) ) ) { |
|
| 51 | - if ( ! isset( $_GET['preview_id'] ) |
|
| 52 | - || ! isset( $_GET['preview_nonce'] ) |
|
| 53 | - || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] ) ) { |
|
| 50 | + if (is_preview() && get_query_var('p') && 'publish' == get_post_status(get_query_var('p'))) { |
|
| 51 | + if ( ! isset($_GET['preview_id']) |
|
| 52 | + || ! isset($_GET['preview_nonce']) |
|
| 53 | + || ! wp_verify_nonce($_GET['preview_nonce'], 'post_preview_'.(int) $_GET['preview_id'])) { |
|
| 54 | 54 | $wp_query->is_preview = false; |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) ) { |
|
| 58 | + if (is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || ($is_IIS && ! iis7_supports_permalinks())) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( ! $requested_url && isset( $_SERVER['HTTP_HOST'] ) ) { |
|
| 62 | + if ( ! $requested_url && isset($_SERVER['HTTP_HOST'])) { |
|
| 63 | 63 | // build the URL in the address bar |
| 64 | 64 | $requested_url = is_ssl() ? 'https://' : 'http://'; |
| 65 | 65 | $requested_url .= $_SERVER['HTTP_HOST']; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $original = @parse_url($requested_url); |
| 70 | - if ( false === $original ) { |
|
| 70 | + if (false === $original) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,170 +75,170 @@ discard block |
||
| 75 | 75 | $redirect_url = false; |
| 76 | 76 | |
| 77 | 77 | // Notice fixing |
| 78 | - if ( !isset($redirect['path']) ) |
|
| 78 | + if ( ! isset($redirect['path'])) |
|
| 79 | 79 | $redirect['path'] = ''; |
| 80 | - if ( !isset($redirect['query']) ) |
|
| 80 | + if ( ! isset($redirect['query'])) |
|
| 81 | 81 | $redirect['query'] = ''; |
| 82 | 82 | |
| 83 | 83 | // If the original URL ended with non-breaking spaces, they were almost |
| 84 | 84 | // certainly inserted by accident. Let's remove them, so the reader doesn't |
| 85 | 85 | // see a 404 error with no obvious cause. |
| 86 | - $redirect['path'] = preg_replace( '|(%C2%A0)+$|i', '', $redirect['path'] ); |
|
| 86 | + $redirect['path'] = preg_replace('|(%C2%A0)+$|i', '', $redirect['path']); |
|
| 87 | 87 | |
| 88 | 88 | // It's not a preview, so remove it from URL |
| 89 | - if ( get_query_var( 'preview' ) ) { |
|
| 90 | - $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] ); |
|
| 89 | + if (get_query_var('preview')) { |
|
| 90 | + $redirect['query'] = remove_query_arg('preview', $redirect['query']); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) { |
|
| 94 | - if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) { |
|
| 95 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url ); |
|
| 96 | - $redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH ); |
|
| 93 | + if (is_feed() && ($id = get_query_var('p'))) { |
|
| 94 | + if ($redirect_url = get_post_comments_feed_link($id, get_query_var('feed'))) { |
|
| 95 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url); |
|
| 96 | + $redirect['path'] = parse_url($redirect_url, PHP_URL_PATH); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) { |
|
| 100 | + if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) { |
|
| 101 | 101 | |
| 102 | - $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) ); |
|
| 102 | + $vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id)); |
|
| 103 | 103 | |
| 104 | - if ( isset($vars[0]) && $vars = $vars[0] ) { |
|
| 105 | - if ( 'revision' == $vars->post_type && $vars->post_parent > 0 ) |
|
| 104 | + if (isset($vars[0]) && $vars = $vars[0]) { |
|
| 105 | + if ('revision' == $vars->post_type && $vars->post_parent > 0) |
|
| 106 | 106 | $id = $vars->post_parent; |
| 107 | 107 | |
| 108 | - if ( $redirect_url = get_permalink($id) ) |
|
| 109 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
|
| 108 | + if ($redirect_url = get_permalink($id)) |
|
| 109 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // These tests give us a WP-generated permalink |
| 114 | - if ( is_404() ) { |
|
| 114 | + if (is_404()) { |
|
| 115 | 115 | |
| 116 | 116 | // Redirect ?page_id, ?p=, ?attachment_id= to their respective url's |
| 117 | - $id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id') ); |
|
| 118 | - if ( $id && $redirect_post = get_post($id) ) { |
|
| 117 | + $id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id')); |
|
| 118 | + if ($id && $redirect_post = get_post($id)) { |
|
| 119 | 119 | $post_type_obj = get_post_type_object($redirect_post->post_type); |
| 120 | - if ( $post_type_obj->public && 'auto-draft' != $redirect_post->post_status ) { |
|
| 120 | + if ($post_type_obj->public && 'auto-draft' != $redirect_post->post_status) { |
|
| 121 | 121 | $redirect_url = get_permalink($redirect_post); |
| 122 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
|
| 122 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( get_query_var( 'day' ) && get_query_var( 'monthnum' ) && get_query_var( 'year' ) ) { |
|
| 127 | - $year = get_query_var( 'year' ); |
|
| 128 | - $month = get_query_var( 'monthnum' ); |
|
| 129 | - $day = get_query_var( 'day' ); |
|
| 130 | - $date = sprintf( '%04d-%02d-%02d', $year, $month, $day ); |
|
| 131 | - if ( ! wp_checkdate( $month, $day, $year, $date ) ) { |
|
| 132 | - $redirect_url = get_month_link( $year, $month ); |
|
| 133 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum', 'day' ), $redirect_url ); |
|
| 126 | + if (get_query_var('day') && get_query_var('monthnum') && get_query_var('year')) { |
|
| 127 | + $year = get_query_var('year'); |
|
| 128 | + $month = get_query_var('monthnum'); |
|
| 129 | + $day = get_query_var('day'); |
|
| 130 | + $date = sprintf('%04d-%02d-%02d', $year, $month, $day); |
|
| 131 | + if ( ! wp_checkdate($month, $day, $year, $date)) { |
|
| 132 | + $redirect_url = get_month_link($year, $month); |
|
| 133 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum', 'day'), $redirect_url); |
|
| 134 | 134 | } |
| 135 | - } elseif ( get_query_var( 'monthnum' ) && get_query_var( 'year' ) && 12 < get_query_var( 'monthnum' ) ) { |
|
| 136 | - $redirect_url = get_year_link( get_query_var( 'year' ) ); |
|
| 137 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url ); |
|
| 135 | + } elseif (get_query_var('monthnum') && get_query_var('year') && 12 < get_query_var('monthnum')) { |
|
| 136 | + $redirect_url = get_year_link(get_query_var('year')); |
|
| 137 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum'), $redirect_url); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( ! $redirect_url ) { |
|
| 141 | - if ( $redirect_url = redirect_guess_404_permalink() ) { |
|
| 142 | - $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); |
|
| 140 | + if ( ! $redirect_url) { |
|
| 141 | + if ($redirect_url = redirect_guess_404_permalink()) { |
|
| 142 | + $redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( get_query_var( 'page' ) && $wp_query->post && |
|
| 147 | - false !== strpos( $wp_query->post->post_content, '<!--nextpage-->' ) ) { |
|
| 148 | - $redirect['path'] = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' ); |
|
| 149 | - $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); |
|
| 150 | - $redirect_url = get_permalink( $wp_query->post->ID ); |
|
| 146 | + if (get_query_var('page') && $wp_query->post && |
|
| 147 | + false !== strpos($wp_query->post->post_content, '<!--nextpage-->')) { |
|
| 148 | + $redirect['path'] = rtrim($redirect['path'], (int) get_query_var('page').'/'); |
|
| 149 | + $redirect['query'] = remove_query_arg('page', $redirect['query']); |
|
| 150 | + $redirect_url = get_permalink($wp_query->post->ID); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { |
|
| 153 | + } elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) { |
|
| 154 | 154 | // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 |
| 155 | - if ( is_attachment() && |
|
| 156 | - ! array_diff( array_keys( $wp->query_vars ), array( 'attachment', 'attachment_id' ) ) && |
|
| 157 | - ! $redirect_url ) { |
|
| 158 | - if ( ! empty( $_GET['attachment_id'] ) ) { |
|
| 159 | - $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) ); |
|
| 160 | - if ( $redirect_url ) { |
|
| 161 | - $redirect['query'] = remove_query_arg( 'attachment_id', $redirect['query'] ); |
|
| 155 | + if (is_attachment() && |
|
| 156 | + ! array_diff(array_keys($wp->query_vars), array('attachment', 'attachment_id')) && |
|
| 157 | + ! $redirect_url) { |
|
| 158 | + if ( ! empty($_GET['attachment_id'])) { |
|
| 159 | + $redirect_url = get_attachment_link(get_query_var('attachment_id')); |
|
| 160 | + if ($redirect_url) { |
|
| 161 | + $redirect['query'] = remove_query_arg('attachment_id', $redirect['query']); |
|
| 162 | 162 | } |
| 163 | 163 | } else { |
| 164 | 164 | $redirect_url = get_attachment_link(); |
| 165 | 165 | } |
| 166 | - } elseif ( is_single() && !empty($_GET['p']) && ! $redirect_url ) { |
|
| 167 | - if ( $redirect_url = get_permalink(get_query_var('p')) ) |
|
| 166 | + } elseif (is_single() && ! empty($_GET['p']) && ! $redirect_url) { |
|
| 167 | + if ($redirect_url = get_permalink(get_query_var('p'))) |
|
| 168 | 168 | $redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']); |
| 169 | - } elseif ( is_single() && !empty($_GET['name']) && ! $redirect_url ) { |
|
| 170 | - if ( $redirect_url = get_permalink( $wp_query->get_queried_object_id() ) ) |
|
| 169 | + } elseif (is_single() && ! empty($_GET['name']) && ! $redirect_url) { |
|
| 170 | + if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) |
|
| 171 | 171 | $redirect['query'] = remove_query_arg('name', $redirect['query']); |
| 172 | - } elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) { |
|
| 173 | - if ( $redirect_url = get_permalink(get_query_var('page_id')) ) |
|
| 172 | + } elseif (is_page() && ! empty($_GET['page_id']) && ! $redirect_url) { |
|
| 173 | + if ($redirect_url = get_permalink(get_query_var('page_id'))) |
|
| 174 | 174 | $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
| 175 | - } elseif ( is_page() && !is_feed() && 'page' == get_option('show_on_front') && get_queried_object_id() == get_option('page_on_front') && ! $redirect_url ) { |
|
| 175 | + } elseif (is_page() && ! is_feed() && 'page' == get_option('show_on_front') && get_queried_object_id() == get_option('page_on_front') && ! $redirect_url) { |
|
| 176 | 176 | $redirect_url = home_url('/'); |
| 177 | - } elseif ( is_home() && !empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && ! $redirect_url ) { |
|
| 178 | - if ( $redirect_url = get_permalink(get_option('page_for_posts')) ) |
|
| 177 | + } elseif (is_home() && ! empty($_GET['page_id']) && 'page' == get_option('show_on_front') && get_query_var('page_id') == get_option('page_for_posts') && ! $redirect_url) { |
|
| 178 | + if ($redirect_url = get_permalink(get_option('page_for_posts'))) |
|
| 179 | 179 | $redirect['query'] = remove_query_arg('page_id', $redirect['query']); |
| 180 | - } elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { |
|
| 180 | + } elseif ( ! empty($_GET['m']) && (is_year() || is_month() || is_day())) { |
|
| 181 | 181 | $m = get_query_var('m'); |
| 182 | - switch ( strlen($m) ) { |
|
| 182 | + switch (strlen($m)) { |
|
| 183 | 183 | case 4: // Yearly |
| 184 | 184 | $redirect_url = get_year_link($m); |
| 185 | 185 | break; |
| 186 | 186 | case 6: // Monthly |
| 187 | - $redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) ); |
|
| 187 | + $redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2)); |
|
| 188 | 188 | break; |
| 189 | 189 | case 8: // Daily |
| 190 | 190 | $redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2)); |
| 191 | 191 | break; |
| 192 | 192 | } |
| 193 | - if ( $redirect_url ) |
|
| 193 | + if ($redirect_url) |
|
| 194 | 194 | $redirect['query'] = remove_query_arg('m', $redirect['query']); |
| 195 | 195 | // now moving on to non ?m=X year/month/day links |
| 196 | - } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) { |
|
| 197 | - if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) |
|
| 196 | + } elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && ! empty($_GET['day'])) { |
|
| 197 | + if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) |
|
| 198 | 198 | $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); |
| 199 | - } elseif ( is_month() && get_query_var('year') && !empty($_GET['monthnum']) ) { |
|
| 200 | - if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) |
|
| 199 | + } elseif (is_month() && get_query_var('year') && ! empty($_GET['monthnum'])) { |
|
| 200 | + if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) |
|
| 201 | 201 | $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); |
| 202 | - } elseif ( is_year() && !empty($_GET['year']) ) { |
|
| 203 | - if ( $redirect_url = get_year_link(get_query_var('year')) ) |
|
| 202 | + } elseif (is_year() && ! empty($_GET['year'])) { |
|
| 203 | + if ($redirect_url = get_year_link(get_query_var('year'))) |
|
| 204 | 204 | $redirect['query'] = remove_query_arg('year', $redirect['query']); |
| 205 | - } elseif ( is_author() && !empty($_GET['author']) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) { |
|
| 205 | + } elseif (is_author() && ! empty($_GET['author']) && preg_match('|^[0-9]+$|', $_GET['author'])) { |
|
| 206 | 206 | $author = get_userdata(get_query_var('author')); |
| 207 | - if ( ( false !== $author ) && $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID ) ) ) { |
|
| 208 | - if ( $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) |
|
| 207 | + if ((false !== $author) && $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_author = %d AND $wpdb->posts.post_status = 'publish' LIMIT 1", $author->ID))) { |
|
| 208 | + if ($redirect_url = get_author_posts_url($author->ID, $author->user_nicename)) |
|
| 209 | 209 | $redirect['query'] = remove_query_arg('author', $redirect['query']); |
| 210 | 210 | } |
| 211 | - } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) |
|
| 211 | + } elseif (is_category() || is_tag() || is_tax()) { // Terms (Tags/categories) |
|
| 212 | 212 | |
| 213 | 213 | $term_count = 0; |
| 214 | - foreach ( $wp_query->tax_query->queried_terms as $tax_query ) |
|
| 215 | - $term_count += count( $tax_query['terms'] ); |
|
| 214 | + foreach ($wp_query->tax_query->queried_terms as $tax_query) |
|
| 215 | + $term_count += count($tax_query['terms']); |
|
| 216 | 216 | |
| 217 | 217 | $obj = $wp_query->get_queried_object(); |
| 218 | - if ( $term_count <= 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { |
|
| 219 | - if ( !empty($redirect['query']) ) { |
|
| 218 | + if ($term_count <= 1 && ! empty($obj->term_id) && ($tax_url = get_term_link((int) $obj->term_id, $obj->taxonomy)) && ! is_wp_error($tax_url)) { |
|
| 219 | + if ( ! empty($redirect['query'])) { |
|
| 220 | 220 | // Strip taxonomy query vars off the url. |
| 221 | - $qv_remove = array( 'term', 'taxonomy'); |
|
| 222 | - if ( is_category() ) { |
|
| 221 | + $qv_remove = array('term', 'taxonomy'); |
|
| 222 | + if (is_category()) { |
|
| 223 | 223 | $qv_remove[] = 'category_name'; |
| 224 | 224 | $qv_remove[] = 'cat'; |
| 225 | - } elseif ( is_tag() ) { |
|
| 225 | + } elseif (is_tag()) { |
|
| 226 | 226 | $qv_remove[] = 'tag'; |
| 227 | 227 | $qv_remove[] = 'tag_id'; |
| 228 | 228 | } else { // Custom taxonomies will have a custom query var, remove those too: |
| 229 | - $tax_obj = get_taxonomy( $obj->taxonomy ); |
|
| 230 | - if ( false !== $tax_obj->query_var ) |
|
| 229 | + $tax_obj = get_taxonomy($obj->taxonomy); |
|
| 230 | + if (false !== $tax_obj->query_var) |
|
| 231 | 231 | $qv_remove[] = $tax_obj->query_var; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $rewrite_vars = array_diff( array_keys($wp_query->query), array_keys($_GET) ); |
|
| 234 | + $rewrite_vars = array_diff(array_keys($wp_query->query), array_keys($_GET)); |
|
| 235 | 235 | |
| 236 | - if ( !array_diff($rewrite_vars, array_keys($_GET)) ) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET |
|
| 236 | + if ( ! array_diff($rewrite_vars, array_keys($_GET))) { // Check to see if all the Query vars are coming from the rewrite, none are set via $_GET |
|
| 237 | 237 | $redirect['query'] = remove_query_arg($qv_remove, $redirect['query']); //Remove all of the per-tax qv's |
| 238 | 238 | |
| 239 | 239 | // Create the destination url for this taxonomy |
| 240 | 240 | $tax_url = parse_url($tax_url); |
| 241 | - if ( ! empty($tax_url['query']) ) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. |
|
| 241 | + if ( ! empty($tax_url['query'])) { // Taxonomy accessible via ?taxonomy=..&term=.. or any custom qv.. |
|
| 242 | 242 | parse_str($tax_url['query'], $query_vars); |
| 243 | 243 | $redirect['query'] = add_query_arg($query_vars, $redirect['query']); |
| 244 | 244 | } else { // Taxonomy is accessible via a "pretty-URL" |
@@ -246,40 +246,40 @@ discard block |
||
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | } else { // Some query vars are set via $_GET. Unset those from $_GET that exist via the rewrite |
| 249 | - foreach ( $qv_remove as $_qv ) { |
|
| 250 | - if ( isset($rewrite_vars[$_qv]) ) |
|
| 249 | + foreach ($qv_remove as $_qv) { |
|
| 250 | + if (isset($rewrite_vars[$_qv])) |
|
| 251 | 251 | $redirect['query'] = remove_query_arg($_qv, $redirect['query']); |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | } |
| 257 | - } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) { |
|
| 258 | - $category = get_category_by_path( $cat ); |
|
| 259 | - if ( ( ! $category || is_wp_error( $category ) ) || ! has_term( $category->term_id, 'category', $wp_query->get_queried_object_id() ) ) { |
|
| 257 | + } elseif (is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var('category_name')) { |
|
| 258 | + $category = get_category_by_path($cat); |
|
| 259 | + if (( ! $category || is_wp_error($category)) || ! has_term($category->term_id, 'category', $wp_query->get_queried_object_id())) { |
|
| 260 | 260 | $redirect_url = get_permalink($wp_query->get_queried_object_id()); |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // Post Paging |
| 265 | - if ( is_singular() && get_query_var('page') ) { |
|
| 266 | - if ( !$redirect_url ) |
|
| 267 | - $redirect_url = get_permalink( get_queried_object_id() ); |
|
| 268 | - |
|
| 269 | - $page = get_query_var( 'page' ); |
|
| 270 | - if ( $page > 1 ) { |
|
| 271 | - if ( is_front_page() ) { |
|
| 272 | - $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( "$wp_rewrite->pagination_base/$page", 'paged' ); |
|
| 265 | + if (is_singular() && get_query_var('page')) { |
|
| 266 | + if ( ! $redirect_url) |
|
| 267 | + $redirect_url = get_permalink(get_queried_object_id()); |
|
| 268 | + |
|
| 269 | + $page = get_query_var('page'); |
|
| 270 | + if ($page > 1) { |
|
| 271 | + if (is_front_page()) { |
|
| 272 | + $redirect_url = trailingslashit($redirect_url).user_trailingslashit("$wp_rewrite->pagination_base/$page", 'paged'); |
|
| 273 | 273 | } else { |
| 274 | - $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( $page, 'single_paged' ); |
|
| 274 | + $redirect_url = trailingslashit($redirect_url).user_trailingslashit($page, 'single_paged'); |
|
| 275 | 275 | } |
| 276 | 276 | } |
| 277 | - $redirect['query'] = remove_query_arg( 'page', $redirect['query'] ); |
|
| 277 | + $redirect['query'] = remove_query_arg('page', $redirect['query']); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // paging and feeds |
| 281 | - if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { |
|
| 282 | - while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) { |
|
| 281 | + if (get_query_var('paged') || is_feed() || get_query_var('cpage')) { |
|
| 282 | + while (preg_match("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path']) || preg_match('#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path']) || preg_match("#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'])) { |
|
| 283 | 283 | // Strip off paging and feed |
| 284 | 284 | $redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging |
| 285 | 285 | $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings |
@@ -287,16 +287,16 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | $addl_path = ''; |
| 290 | - if ( is_feed() && in_array( get_query_var('feed'), $wp_rewrite->feeds ) ) { |
|
| 291 | - $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; |
|
| 292 | - if ( !is_singular() && get_query_var( 'withcomments' ) ) |
|
| 290 | + if (is_feed() && in_array(get_query_var('feed'), $wp_rewrite->feeds)) { |
|
| 291 | + $addl_path = ! empty($addl_path) ? trailingslashit($addl_path) : ''; |
|
| 292 | + if ( ! is_singular() && get_query_var('withcomments')) |
|
| 293 | 293 | $addl_path .= 'comments/'; |
| 294 | - if ( ( 'rss' == get_default_feed() && 'feed' == get_query_var('feed') ) || 'rss' == get_query_var('feed') ) |
|
| 295 | - $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == 'rss2' ) ? '' : 'rss2' ), 'feed' ); |
|
| 294 | + if (('rss' == get_default_feed() && 'feed' == get_query_var('feed')) || 'rss' == get_query_var('feed')) |
|
| 295 | + $addl_path .= user_trailingslashit('feed/'.((get_default_feed() == 'rss2') ? '' : 'rss2'), 'feed'); |
|
| 296 | 296 | else |
| 297 | - $addl_path .= user_trailingslashit( 'feed/' . ( ( get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); |
|
| 298 | - $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); |
|
| 299 | - } elseif ( is_feed() && 'old' == get_query_var('feed') ) { |
|
| 297 | + $addl_path .= user_trailingslashit('feed/'.((get_default_feed() == get_query_var('feed') || 'feed' == get_query_var('feed')) ? '' : get_query_var('feed')), 'feed'); |
|
| 298 | + $redirect['query'] = remove_query_arg('feed', $redirect['query']); |
|
| 299 | + } elseif (is_feed() && 'old' == get_query_var('feed')) { |
|
| 300 | 300 | $old_feed_files = array( |
| 301 | 301 | 'wp-atom.php' => 'atom', |
| 302 | 302 | 'wp-commentsrss2.php' => 'comments_rss2', |
@@ -305,178 +305,178 @@ discard block |
||
| 305 | 305 | 'wp-rss.php' => 'rss2', |
| 306 | 306 | 'wp-rss2.php' => 'rss2', |
| 307 | 307 | ); |
| 308 | - if ( isset( $old_feed_files[ basename( $redirect['path'] ) ] ) ) { |
|
| 309 | - $redirect_url = get_feed_link( $old_feed_files[ basename( $redirect['path'] ) ] ); |
|
| 310 | - wp_redirect( $redirect_url, 301 ); |
|
| 308 | + if (isset($old_feed_files[basename($redirect['path'])])) { |
|
| 309 | + $redirect_url = get_feed_link($old_feed_files[basename($redirect['path'])]); |
|
| 310 | + wp_redirect($redirect_url, 301); |
|
| 311 | 311 | die(); |
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( get_query_var('paged') > 0 ) { |
|
| 315 | + if (get_query_var('paged') > 0) { |
|
| 316 | 316 | $paged = get_query_var('paged'); |
| 317 | - $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); |
|
| 318 | - if ( !is_feed() ) { |
|
| 319 | - if ( $paged > 1 && !is_single() ) { |
|
| 320 | - $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit("$wp_rewrite->pagination_base/$paged", 'paged'); |
|
| 321 | - } elseif ( !is_single() ) { |
|
| 322 | - $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; |
|
| 317 | + $redirect['query'] = remove_query_arg('paged', $redirect['query']); |
|
| 318 | + if ( ! is_feed()) { |
|
| 319 | + if ($paged > 1 && ! is_single()) { |
|
| 320 | + $addl_path = ( ! empty($addl_path) ? trailingslashit($addl_path) : '').user_trailingslashit("$wp_rewrite->pagination_base/$paged", 'paged'); |
|
| 321 | + } elseif ( ! is_single()) { |
|
| 322 | + $addl_path = ! empty($addl_path) ? trailingslashit($addl_path) : ''; |
|
| 323 | 323 | } |
| 324 | - } elseif ( $paged > 1 ) { |
|
| 325 | - $redirect['query'] = add_query_arg( 'paged', $paged, $redirect['query'] ); |
|
| 324 | + } elseif ($paged > 1) { |
|
| 325 | + $redirect['query'] = add_query_arg('paged', $paged, $redirect['query']); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - if ( get_option( 'page_comments' ) && ( |
|
| 330 | - ( 'newest' == get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 0 ) || |
|
| 331 | - ( 'newest' != get_option( 'default_comments_page' ) && get_query_var( 'cpage' ) > 1 ) |
|
| 332 | - ) ) { |
|
| 333 | - $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' ); |
|
| 334 | - $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); |
|
| 329 | + if (get_option('page_comments') && ( |
|
| 330 | + ('newest' == get_option('default_comments_page') && get_query_var('cpage') > 0) || |
|
| 331 | + ('newest' != get_option('default_comments_page') && get_query_var('cpage') > 1) |
|
| 332 | + )) { |
|
| 333 | + $addl_path = ( ! empty($addl_path) ? trailingslashit($addl_path) : '').user_trailingslashit($wp_rewrite->comments_pagination_base.'-'.get_query_var('cpage'), 'commentpaged'); |
|
| 334 | + $redirect['query'] = remove_query_arg('cpage', $redirect['query']); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - $redirect['path'] = user_trailingslashit( preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path']) ); // strip off trailing /index.php/ |
|
| 338 | - if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/' . $wp_rewrite->index . '/') === false ) |
|
| 339 | - $redirect['path'] = trailingslashit($redirect['path']) . $wp_rewrite->index . '/'; |
|
| 340 | - if ( !empty( $addl_path ) ) |
|
| 341 | - $redirect['path'] = trailingslashit($redirect['path']) . $addl_path; |
|
| 342 | - $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; |
|
| 337 | + $redirect['path'] = user_trailingslashit(preg_replace('|/'.preg_quote($wp_rewrite->index, '|').'/?$|', '/', $redirect['path'])); // strip off trailing /index.php/ |
|
| 338 | + if ( ! empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/'.$wp_rewrite->index.'/') === false) |
|
| 339 | + $redirect['path'] = trailingslashit($redirect['path']).$wp_rewrite->index.'/'; |
|
| 340 | + if ( ! empty($addl_path)) |
|
| 341 | + $redirect['path'] = trailingslashit($redirect['path']).$addl_path; |
|
| 342 | + $redirect_url = $redirect['scheme'].'://'.$redirect['host'].$redirect['path']; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - if ( 'wp-register.php' == basename( $redirect['path'] ) ) { |
|
| 346 | - if ( is_multisite() ) { |
|
| 345 | + if ('wp-register.php' == basename($redirect['path'])) { |
|
| 346 | + if (is_multisite()) { |
|
| 347 | 347 | /** This filter is documented in wp-login.php */ |
| 348 | - $redirect_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); |
|
| 348 | + $redirect_url = apply_filters('wp_signup_location', network_site_url('wp-signup.php')); |
|
| 349 | 349 | } else { |
| 350 | 350 | $redirect_url = wp_registration_url(); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - wp_redirect( $redirect_url, 301 ); |
|
| 353 | + wp_redirect($redirect_url, 301); |
|
| 354 | 354 | die(); |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | // tack on any additional query vars |
| 359 | - $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); |
|
| 360 | - if ( $redirect_url && !empty($redirect['query']) ) { |
|
| 361 | - parse_str( $redirect['query'], $_parsed_query ); |
|
| 359 | + $redirect['query'] = preg_replace('#^\??&*?#', '', $redirect['query']); |
|
| 360 | + if ($redirect_url && ! empty($redirect['query'])) { |
|
| 361 | + parse_str($redirect['query'], $_parsed_query); |
|
| 362 | 362 | $redirect = @parse_url($redirect_url); |
| 363 | 363 | |
| 364 | - if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { |
|
| 365 | - parse_str( $redirect['query'], $_parsed_redirect_query ); |
|
| 364 | + if ( ! empty($_parsed_query['name']) && ! empty($redirect['query'])) { |
|
| 365 | + parse_str($redirect['query'], $_parsed_redirect_query); |
|
| 366 | 366 | |
| 367 | - if ( empty( $_parsed_redirect_query['name'] ) ) |
|
| 368 | - unset( $_parsed_query['name'] ); |
|
| 367 | + if (empty($_parsed_redirect_query['name'])) |
|
| 368 | + unset($_parsed_query['name']); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $_parsed_query = rawurlencode_deep( $_parsed_query ); |
|
| 372 | - $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); |
|
| 371 | + $_parsed_query = rawurlencode_deep($_parsed_query); |
|
| 372 | + $redirect_url = add_query_arg($_parsed_query, $redirect_url); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if ( $redirect_url ) |
|
| 375 | + if ($redirect_url) |
|
| 376 | 376 | $redirect = @parse_url($redirect_url); |
| 377 | 377 | |
| 378 | 378 | // www.example.com vs example.com |
| 379 | 379 | $user_home = @parse_url(home_url()); |
| 380 | - if ( !empty($user_home['host']) ) |
|
| 380 | + if ( ! empty($user_home['host'])) |
|
| 381 | 381 | $redirect['host'] = $user_home['host']; |
| 382 | - if ( empty($user_home['path']) ) |
|
| 382 | + if (empty($user_home['path'])) |
|
| 383 | 383 | $user_home['path'] = '/'; |
| 384 | 384 | |
| 385 | 385 | // Handle ports |
| 386 | - if ( !empty($user_home['port']) ) |
|
| 386 | + if ( ! empty($user_home['port'])) |
|
| 387 | 387 | $redirect['port'] = $user_home['port']; |
| 388 | 388 | else |
| 389 | 389 | unset($redirect['port']); |
| 390 | 390 | |
| 391 | 391 | // trailing /index.php |
| 392 | - $redirect['path'] = preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path']); |
|
| 392 | + $redirect['path'] = preg_replace('|/'.preg_quote($wp_rewrite->index, '|').'/*?$|', '/', $redirect['path']); |
|
| 393 | 393 | |
| 394 | 394 | // Remove trailing spaces from the path |
| 395 | - $redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] ); |
|
| 395 | + $redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']); |
|
| 396 | 396 | |
| 397 | - if ( !empty( $redirect['query'] ) ) { |
|
| 397 | + if ( ! empty($redirect['query'])) { |
|
| 398 | 398 | // Remove trailing spaces from certain terminating query string args |
| 399 | - $redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] ); |
|
| 399 | + $redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']); |
|
| 400 | 400 | |
| 401 | 401 | // Clean up empty query strings |
| 402 | - $redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); |
|
| 402 | + $redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&'); |
|
| 403 | 403 | |
| 404 | 404 | // Redirect obsolete feeds |
| 405 | - $redirect['query'] = preg_replace( '#(^|&)feed=rss(&|$)#', '$1feed=rss2$2', $redirect['query'] ); |
|
| 405 | + $redirect['query'] = preg_replace('#(^|&)feed=rss(&|$)#', '$1feed=rss2$2', $redirect['query']); |
|
| 406 | 406 | |
| 407 | 407 | // Remove redundant leading ampersands |
| 408 | - $redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] ); |
|
| 408 | + $redirect['query'] = preg_replace('#^\??&*?#', '', $redirect['query']); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | // strip /index.php/ when we're not using PATHINFO permalinks |
| 412 | - if ( !$wp_rewrite->using_index_permalinks() ) |
|
| 413 | - $redirect['path'] = str_replace( '/' . $wp_rewrite->index . '/', '/', $redirect['path'] ); |
|
| 412 | + if ( ! $wp_rewrite->using_index_permalinks()) |
|
| 413 | + $redirect['path'] = str_replace('/'.$wp_rewrite->index.'/', '/', $redirect['path']); |
|
| 414 | 414 | |
| 415 | 415 | // trailing slashes |
| 416 | - if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { |
|
| 416 | + if (is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && ! is_404() && ( ! is_front_page() || (is_front_page() && (get_query_var('paged') > 1)))) { |
|
| 417 | 417 | $user_ts_type = ''; |
| 418 | - if ( get_query_var('paged') > 0 ) { |
|
| 418 | + if (get_query_var('paged') > 0) { |
|
| 419 | 419 | $user_ts_type = 'paged'; |
| 420 | 420 | } else { |
| 421 | - foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) { |
|
| 422 | - $func = 'is_' . $type; |
|
| 423 | - if ( call_user_func($func) ) { |
|
| 421 | + foreach (array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type) { |
|
| 422 | + $func = 'is_'.$type; |
|
| 423 | + if (call_user_func($func)) { |
|
| 424 | 424 | $user_ts_type = $type; |
| 425 | 425 | break; |
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); |
| 430 | - } elseif ( is_front_page() ) { |
|
| 430 | + } elseif (is_front_page()) { |
|
| 431 | 431 | $redirect['path'] = trailingslashit($redirect['path']); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | // Strip multiple slashes out of the URL |
| 435 | - if ( strpos($redirect['path'], '//') > -1 ) |
|
| 435 | + if (strpos($redirect['path'], '//') > -1) |
|
| 436 | 436 | $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); |
| 437 | 437 | |
| 438 | 438 | // Always trailing slash the Front Page URL |
| 439 | - if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) |
|
| 439 | + if (trailingslashit($redirect['path']) == trailingslashit($user_home['path'])) |
|
| 440 | 440 | $redirect['path'] = trailingslashit($redirect['path']); |
| 441 | 441 | |
| 442 | 442 | // Ignore differences in host capitalization, as this can lead to infinite redirects |
| 443 | 443 | // Only redirect no-www <=> yes-www |
| 444 | - if ( strtolower($original['host']) == strtolower($redirect['host']) || |
|
| 445 | - ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) |
|
| 444 | + if (strtolower($original['host']) == strtolower($redirect['host']) || |
|
| 445 | + (strtolower($original['host']) != 'www.'.strtolower($redirect['host']) && 'www.'.strtolower($original['host']) != strtolower($redirect['host']))) |
|
| 446 | 446 | $redirect['host'] = $original['host']; |
| 447 | 447 | |
| 448 | - $compare_original = array( $original['host'], $original['path'] ); |
|
| 448 | + $compare_original = array($original['host'], $original['path']); |
|
| 449 | 449 | |
| 450 | - if ( !empty( $original['port'] ) ) |
|
| 450 | + if ( ! empty($original['port'])) |
|
| 451 | 451 | $compare_original[] = $original['port']; |
| 452 | 452 | |
| 453 | - if ( !empty( $original['query'] ) ) |
|
| 453 | + if ( ! empty($original['query'])) |
|
| 454 | 454 | $compare_original[] = $original['query']; |
| 455 | 455 | |
| 456 | - $compare_redirect = array( $redirect['host'], $redirect['path'] ); |
|
| 456 | + $compare_redirect = array($redirect['host'], $redirect['path']); |
|
| 457 | 457 | |
| 458 | - if ( !empty( $redirect['port'] ) ) |
|
| 458 | + if ( ! empty($redirect['port'])) |
|
| 459 | 459 | $compare_redirect[] = $redirect['port']; |
| 460 | 460 | |
| 461 | - if ( !empty( $redirect['query'] ) ) |
|
| 461 | + if ( ! empty($redirect['query'])) |
|
| 462 | 462 | $compare_redirect[] = $redirect['query']; |
| 463 | 463 | |
| 464 | - if ( $compare_original !== $compare_redirect ) { |
|
| 465 | - $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; |
|
| 466 | - if ( !empty($redirect['port']) ) |
|
| 467 | - $redirect_url .= ':' . $redirect['port']; |
|
| 464 | + if ($compare_original !== $compare_redirect) { |
|
| 465 | + $redirect_url = $redirect['scheme'].'://'.$redirect['host']; |
|
| 466 | + if ( ! empty($redirect['port'])) |
|
| 467 | + $redirect_url .= ':'.$redirect['port']; |
|
| 468 | 468 | $redirect_url .= $redirect['path']; |
| 469 | - if ( !empty($redirect['query']) ) |
|
| 470 | - $redirect_url .= '?' . $redirect['query']; |
|
| 469 | + if ( ! empty($redirect['query'])) |
|
| 470 | + $redirect_url .= '?'.$redirect['query']; |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - if ( ! $redirect_url || $redirect_url == $requested_url ) { |
|
| 473 | + if ( ! $redirect_url || $redirect_url == $requested_url) { |
|
| 474 | 474 | return; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | // Hex encoded octets are case-insensitive. |
| 478 | - if ( false !== strpos($requested_url, '%') ) { |
|
| 479 | - if ( !function_exists('lowercase_octets') ) { |
|
| 478 | + if (false !== strpos($requested_url, '%')) { |
|
| 479 | + if ( ! function_exists('lowercase_octets')) { |
|
| 480 | 480 | /** |
| 481 | 481 | * Converts the first hex-encoded octet match to lowercase. |
| 482 | 482 | * |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | * @return string Lowercased version of the first match. |
| 488 | 488 | */ |
| 489 | 489 | function lowercase_octets($matches) { |
| 490 | - return strtolower( $matches[0] ); |
|
| 490 | + return strtolower($matches[0]); |
|
| 491 | 491 | } |
| 492 | 492 | } |
| 493 | 493 | $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @param string $redirect_url The redirect URL. |
| 504 | 504 | * @param string $requested_url The requested URL. |
| 505 | 505 | */ |
| 506 | - $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url ); |
|
| 506 | + $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); |
|
| 507 | 507 | |
| 508 | 508 | // yes, again -- in case the filter aborted the request |
| 509 | - if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) { |
|
| 509 | + if ( ! $redirect_url || strip_fragment_from_url($redirect_url) == strip_fragment_from_url($requested_url)) { |
|
| 510 | 510 | return; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - if ( $do_redirect ) { |
|
| 513 | + if ($do_redirect) { |
|
| 514 | 514 | // protect against chained redirects |
| 515 | - if ( !redirect_canonical($redirect_url, false) ) { |
|
| 515 | + if ( ! redirect_canonical($redirect_url, false)) { |
|
| 516 | 516 | wp_redirect($redirect_url, 301); |
| 517 | 517 | exit(); |
| 518 | 518 | } else { |
@@ -537,16 +537,16 @@ discard block |
||
| 537 | 537 | * @param string $url |
| 538 | 538 | * @return string The altered query string |
| 539 | 539 | */ |
| 540 | -function _remove_qs_args_if_not_in_url( $query_string, Array $args_to_check, $url ) { |
|
| 541 | - $parsed_url = @parse_url( $url ); |
|
| 542 | - if ( ! empty( $parsed_url['query'] ) ) { |
|
| 543 | - parse_str( $parsed_url['query'], $parsed_query ); |
|
| 544 | - foreach ( $args_to_check as $qv ) { |
|
| 545 | - if ( !isset( $parsed_query[$qv] ) ) |
|
| 546 | - $query_string = remove_query_arg( $qv, $query_string ); |
|
| 540 | +function _remove_qs_args_if_not_in_url($query_string, Array $args_to_check, $url) { |
|
| 541 | + $parsed_url = @parse_url($url); |
|
| 542 | + if ( ! empty($parsed_url['query'])) { |
|
| 543 | + parse_str($parsed_url['query'], $parsed_query); |
|
| 544 | + foreach ($args_to_check as $qv) { |
|
| 545 | + if ( ! isset($parsed_query[$qv])) |
|
| 546 | + $query_string = remove_query_arg($qv, $query_string); |
|
| 547 | 547 | } |
| 548 | 548 | } else { |
| 549 | - $query_string = remove_query_arg( $args_to_check, $query_string ); |
|
| 549 | + $query_string = remove_query_arg($args_to_check, $query_string); |
|
| 550 | 550 | } |
| 551 | 551 | return $query_string; |
| 552 | 552 | } |
@@ -559,17 +559,17 @@ discard block |
||
| 559 | 559 | * @param string $url The URL to strip. |
| 560 | 560 | * @return string The altered URL. |
| 561 | 561 | */ |
| 562 | -function strip_fragment_from_url( $url ) { |
|
| 563 | - $parsed_url = @parse_url( $url ); |
|
| 564 | - if ( ! empty( $parsed_url['host'] ) ) { |
|
| 562 | +function strip_fragment_from_url($url) { |
|
| 563 | + $parsed_url = @parse_url($url); |
|
| 564 | + if ( ! empty($parsed_url['host'])) { |
|
| 565 | 565 | // This mirrors code in redirect_canonical(). It does not handle every case. |
| 566 | - $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
|
| 567 | - if ( ! empty( $parsed_url['port'] ) ) { |
|
| 568 | - $url .= ':' . $parsed_url['port']; |
|
| 566 | + $url = $parsed_url['scheme'].'://'.$parsed_url['host']; |
|
| 567 | + if ( ! empty($parsed_url['port'])) { |
|
| 568 | + $url .= ':'.$parsed_url['port']; |
|
| 569 | 569 | } |
| 570 | 570 | $url .= $parsed_url['path']; |
| 571 | - if ( ! empty( $parsed_url['query'] ) ) { |
|
| 572 | - $url .= '?' . $parsed_url['query']; |
|
| 571 | + if ( ! empty($parsed_url['query'])) { |
|
| 572 | + $url .= '?'.$parsed_url['query']; |
|
| 573 | 573 | } |
| 574 | 574 | } |
| 575 | 575 | |
@@ -588,31 +588,31 @@ discard block |
||
| 588 | 588 | function redirect_guess_404_permalink() { |
| 589 | 589 | global $wpdb; |
| 590 | 590 | |
| 591 | - if ( get_query_var('name') ) { |
|
| 592 | - $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like( get_query_var('name') ) . '%'); |
|
| 591 | + if (get_query_var('name')) { |
|
| 592 | + $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like(get_query_var('name')).'%'); |
|
| 593 | 593 | |
| 594 | 594 | // if any of post_type, year, monthnum, or day are set, use them to refine the query |
| 595 | - if ( get_query_var('post_type') ) |
|
| 595 | + if (get_query_var('post_type')) |
|
| 596 | 596 | $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type')); |
| 597 | 597 | else |
| 598 | - $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
|
| 598 | + $where .= " AND post_type IN ('".implode("', '", get_post_types(array('public' => true)))."')"; |
|
| 599 | 599 | |
| 600 | - if ( get_query_var('year') ) |
|
| 600 | + if (get_query_var('year')) |
|
| 601 | 601 | $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); |
| 602 | - if ( get_query_var('monthnum') ) |
|
| 602 | + if (get_query_var('monthnum')) |
|
| 603 | 603 | $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum')); |
| 604 | - if ( get_query_var('day') ) |
|
| 604 | + if (get_query_var('day')) |
|
| 605 | 605 | $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day')); |
| 606 | 606 | |
| 607 | 607 | $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'"); |
| 608 | - if ( ! $post_id ) |
|
| 608 | + if ( ! $post_id) |
|
| 609 | 609 | return false; |
| 610 | - if ( get_query_var( 'feed' ) ) |
|
| 611 | - return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); |
|
| 612 | - elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) |
|
| 613 | - return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); |
|
| 610 | + if (get_query_var('feed')) |
|
| 611 | + return get_post_comments_feed_link($post_id, get_query_var('feed')); |
|
| 612 | + elseif (get_query_var('page') && 1 < get_query_var('page')) |
|
| 613 | + return trailingslashit(get_permalink($post_id)).user_trailingslashit(get_query_var('page'), 'single_paged'); |
|
| 614 | 614 | else |
| 615 | - return get_permalink( $post_id ); |
|
| 615 | + return get_permalink($post_id); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | return false; |
@@ -630,28 +630,28 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | function wp_redirect_admin_locations() { |
| 632 | 632 | global $wp_rewrite; |
| 633 | - if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) |
|
| 633 | + if ( ! (is_404() && $wp_rewrite->using_permalinks())) |
|
| 634 | 634 | return; |
| 635 | 635 | |
| 636 | 636 | $admins = array( |
| 637 | - home_url( 'wp-admin', 'relative' ), |
|
| 638 | - home_url( 'dashboard', 'relative' ), |
|
| 639 | - home_url( 'admin', 'relative' ), |
|
| 640 | - site_url( 'dashboard', 'relative' ), |
|
| 641 | - site_url( 'admin', 'relative' ), |
|
| 637 | + home_url('wp-admin', 'relative'), |
|
| 638 | + home_url('dashboard', 'relative'), |
|
| 639 | + home_url('admin', 'relative'), |
|
| 640 | + site_url('dashboard', 'relative'), |
|
| 641 | + site_url('admin', 'relative'), |
|
| 642 | 642 | ); |
| 643 | - if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) ) { |
|
| 644 | - wp_redirect( admin_url() ); |
|
| 643 | + if (in_array(untrailingslashit($_SERVER['REQUEST_URI']), $admins)) { |
|
| 644 | + wp_redirect(admin_url()); |
|
| 645 | 645 | exit; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | $logins = array( |
| 649 | - home_url( 'wp-login.php', 'relative' ), |
|
| 650 | - home_url( 'login', 'relative' ), |
|
| 651 | - site_url( 'login', 'relative' ), |
|
| 649 | + home_url('wp-login.php', 'relative'), |
|
| 650 | + home_url('login', 'relative'), |
|
| 651 | + site_url('login', 'relative'), |
|
| 652 | 652 | ); |
| 653 | - if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) { |
|
| 654 | - wp_redirect( wp_login_url() ); |
|
| 653 | + if (in_array(untrailingslashit($_SERVER['REQUEST_URI']), $logins)) { |
|
| 654 | + wp_redirect(wp_login_url()); |
|
| 655 | 655 | exit; |
| 656 | 656 | } |
| 657 | 657 | } |
@@ -62,6 +62,9 @@ discard block |
||
| 62 | 62 | self::__construct( $iteration_count_log2, $portable_hashes ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /** |
|
| 66 | + * @param integer $count |
|
| 67 | + */ |
|
| 65 | 68 | function get_random_bytes($count) |
| 66 | 69 | { |
| 67 | 70 | $output = ''; |
@@ -85,6 +88,9 @@ discard block |
||
| 85 | 88 | return $output; |
| 86 | 89 | } |
| 87 | 90 | |
| 91 | + /** |
|
| 92 | + * @param integer $count |
|
| 93 | + */ |
|
| 88 | 94 | function encode64($input, $count) |
| 89 | 95 | { |
| 90 | 96 | $output = ''; |
@@ -108,6 +114,9 @@ discard block |
||
| 108 | 114 | return $output; |
| 109 | 115 | } |
| 110 | 116 | |
| 117 | + /** |
|
| 118 | + * @param string $input |
|
| 119 | + */ |
|
| 111 | 120 | function gensalt_private($input) |
| 112 | 121 | { |
| 113 | 122 | $output = '$P$'; |
@@ -163,6 +172,9 @@ discard block |
||
| 163 | 172 | return $output; |
| 164 | 173 | } |
| 165 | 174 | |
| 175 | + /** |
|
| 176 | + * @param string $input |
|
| 177 | + */ |
|
| 166 | 178 | function gensalt_extended($input) |
| 167 | 179 | { |
| 168 | 180 | $count_log2 = min($this->iteration_count_log2 + 8, 24); |
@@ -181,6 +193,9 @@ discard block |
||
| 181 | 193 | return $output; |
| 182 | 194 | } |
| 183 | 195 | |
| 196 | + /** |
|
| 197 | + * @param string $input |
|
| 198 | + */ |
|
| 184 | 199 | function gensalt_blowfish($input) |
| 185 | 200 | { |
| 186 | 201 | # This one needs to use a different order of characters and a |
@@ -222,6 +237,9 @@ discard block |
||
| 222 | 237 | return $output; |
| 223 | 238 | } |
| 224 | 239 | |
| 240 | + /** |
|
| 241 | + * @param string $password |
|
| 242 | + */ |
|
| 225 | 243 | function HashPassword($password) |
| 226 | 244 | { |
| 227 | 245 | if ( strlen( $password ) > 4096 ) { |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | /** |
| 43 | 43 | * PHP5 constructor. |
| 44 | 44 | */ |
| 45 | - function __construct( $iteration_count_log2, $portable_hashes ) |
|
| 45 | + function __construct($iteration_count_log2, $portable_hashes) |
|
| 46 | 46 | { |
| 47 | 47 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 48 | 48 | |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $this->portable_hashes = $portable_hashes; |
| 54 | 54 | |
| 55 | - $this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons |
|
| 55 | + $this->random_state = microtime().uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * PHP4 constructor. |
| 60 | 60 | */ |
| 61 | - public function PasswordHash( $iteration_count_log2, $portable_hashes ) { |
|
| 62 | - self::__construct( $iteration_count_log2, $portable_hashes ); |
|
| 61 | + public function PasswordHash($iteration_count_log2, $portable_hashes) { |
|
| 62 | + self::__construct($iteration_count_log2, $portable_hashes); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function get_random_bytes($count) |
| 66 | 66 | { |
| 67 | 67 | $output = ''; |
| 68 | - if ( @is_readable('/dev/urandom') && |
|
| 68 | + if (@is_readable('/dev/urandom') && |
|
| 69 | 69 | ($fh = @fopen('/dev/urandom', 'rb'))) { |
| 70 | 70 | $output = fread($fh, $count); |
| 71 | 71 | fclose($fh); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $output = ''; |
| 76 | 76 | for ($i = 0; $i < $count; $i += 16) { |
| 77 | 77 | $this->random_state = |
| 78 | - md5(microtime() . $this->random_state); |
|
| 78 | + md5(microtime().$this->random_state); |
|
| 79 | 79 | $output .= |
| 80 | 80 | pack('H*', md5($this->random_state)); |
| 81 | 81 | } |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | # consequently in lower iteration counts and hashes that are |
| 147 | 147 | # quicker to crack (by non-PHP code). |
| 148 | 148 | if (PHP_VERSION >= '5') { |
| 149 | - $hash = md5($salt . $password, TRUE); |
|
| 149 | + $hash = md5($salt.$password, TRUE); |
|
| 150 | 150 | do { |
| 151 | - $hash = md5($hash . $password, TRUE); |
|
| 151 | + $hash = md5($hash.$password, TRUE); |
|
| 152 | 152 | } while (--$count); |
| 153 | 153 | } else { |
| 154 | - $hash = pack('H*', md5($salt . $password)); |
|
| 154 | + $hash = pack('H*', md5($salt.$password)); |
|
| 155 | 155 | do { |
| 156 | - $hash = pack('H*', md5($hash . $password)); |
|
| 156 | + $hash = pack('H*', md5($hash.$password)); |
|
| 157 | 157 | } while (--$count); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -224,13 +224,13 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | function HashPassword($password) |
| 226 | 226 | { |
| 227 | - if ( strlen( $password ) > 4096 ) { |
|
| 227 | + if (strlen($password) > 4096) { |
|
| 228 | 228 | return '*'; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | $random = ''; |
| 232 | 232 | |
| 233 | - if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
|
| 233 | + if (CRYPT_BLOWFISH == 1 && ! $this->portable_hashes) { |
|
| 234 | 234 | $random = $this->get_random_bytes(16); |
| 235 | 235 | $hash = |
| 236 | 236 | crypt($password, $this->gensalt_blowfish($random)); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | return $hash; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
|
| 241 | + if (CRYPT_EXT_DES == 1 && ! $this->portable_hashes) { |
|
| 242 | 242 | if (strlen($random) < 3) |
| 243 | 243 | $random = $this->get_random_bytes(3); |
| 244 | 244 | $hash = |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | function CheckPassword($password, $stored_hash) |
| 265 | 265 | { |
| 266 | - if ( strlen( $password ) > 4096 ) { |
|
| 266 | + if (strlen($password) > 4096) { |
|
| 267 | 267 | return false; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -46,8 +46,9 @@ discard block |
||
| 46 | 46 | { |
| 47 | 47 | $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
| 48 | 48 | |
| 49 | - if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) |
|
| 50 | - $iteration_count_log2 = 8; |
|
| 49 | + if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) { |
|
| 50 | + $iteration_count_log2 = 8; |
|
| 51 | + } |
|
| 51 | 52 | $this->iteration_count_log2 = $iteration_count_log2; |
| 52 | 53 | |
| 53 | 54 | $this->portable_hashes = $portable_hashes; |
@@ -92,16 +93,20 @@ discard block |
||
| 92 | 93 | do { |
| 93 | 94 | $value = ord($input[$i++]); |
| 94 | 95 | $output .= $this->itoa64[$value & 0x3f]; |
| 95 | - if ($i < $count) |
|
| 96 | - $value |= ord($input[$i]) << 8; |
|
| 96 | + if ($i < $count) { |
|
| 97 | + $value |= ord($input[$i]) << 8; |
|
| 98 | + } |
|
| 97 | 99 | $output .= $this->itoa64[($value >> 6) & 0x3f]; |
| 98 | - if ($i++ >= $count) |
|
| 99 | - break; |
|
| 100 | - if ($i < $count) |
|
| 101 | - $value |= ord($input[$i]) << 16; |
|
| 100 | + if ($i++ >= $count) { |
|
| 101 | + break; |
|
| 102 | + } |
|
| 103 | + if ($i < $count) { |
|
| 104 | + $value |= ord($input[$i]) << 16; |
|
| 105 | + } |
|
| 102 | 106 | $output .= $this->itoa64[($value >> 12) & 0x3f]; |
| 103 | - if ($i++ >= $count) |
|
| 104 | - break; |
|
| 107 | + if ($i++ >= $count) { |
|
| 108 | + break; |
|
| 109 | + } |
|
| 105 | 110 | $output .= $this->itoa64[($value >> 18) & 0x3f]; |
| 106 | 111 | } while ($i < $count); |
| 107 | 112 | |
@@ -121,23 +126,27 @@ discard block |
||
| 121 | 126 | function crypt_private($password, $setting) |
| 122 | 127 | { |
| 123 | 128 | $output = '*0'; |
| 124 | - if (substr($setting, 0, 2) == $output) |
|
| 125 | - $output = '*1'; |
|
| 129 | + if (substr($setting, 0, 2) == $output) { |
|
| 130 | + $output = '*1'; |
|
| 131 | + } |
|
| 126 | 132 | |
| 127 | 133 | $id = substr($setting, 0, 3); |
| 128 | 134 | # We use "$P$", phpBB3 uses "$H$" for the same thing |
| 129 | - if ($id != '$P$' && $id != '$H$') |
|
| 130 | - return $output; |
|
| 135 | + if ($id != '$P$' && $id != '$H$') { |
|
| 136 | + return $output; |
|
| 137 | + } |
|
| 131 | 138 | |
| 132 | 139 | $count_log2 = strpos($this->itoa64, $setting[3]); |
| 133 | - if ($count_log2 < 7 || $count_log2 > 30) |
|
| 134 | - return $output; |
|
| 140 | + if ($count_log2 < 7 || $count_log2 > 30) { |
|
| 141 | + return $output; |
|
| 142 | + } |
|
| 135 | 143 | |
| 136 | 144 | $count = 1 << $count_log2; |
| 137 | 145 | |
| 138 | 146 | $salt = substr($setting, 4, 8); |
| 139 | - if (strlen($salt) != 8) |
|
| 140 | - return $output; |
|
| 147 | + if (strlen($salt) != 8) { |
|
| 148 | + return $output; |
|
| 149 | + } |
|
| 141 | 150 | |
| 142 | 151 | # We're kind of forced to use MD5 here since it's the only |
| 143 | 152 | # cryptographic primitive available in all versions of PHP |
@@ -234,26 +243,31 @@ discard block |
||
| 234 | 243 | $random = $this->get_random_bytes(16); |
| 235 | 244 | $hash = |
| 236 | 245 | crypt($password, $this->gensalt_blowfish($random)); |
| 237 | - if (strlen($hash) == 60) |
|
| 238 | - return $hash; |
|
| 246 | + if (strlen($hash) == 60) { |
|
| 247 | + return $hash; |
|
| 248 | + } |
|
| 239 | 249 | } |
| 240 | 250 | |
| 241 | 251 | if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { |
| 242 | - if (strlen($random) < 3) |
|
| 243 | - $random = $this->get_random_bytes(3); |
|
| 252 | + if (strlen($random) < 3) { |
|
| 253 | + $random = $this->get_random_bytes(3); |
|
| 254 | + } |
|
| 244 | 255 | $hash = |
| 245 | 256 | crypt($password, $this->gensalt_extended($random)); |
| 246 | - if (strlen($hash) == 20) |
|
| 247 | - return $hash; |
|
| 257 | + if (strlen($hash) == 20) { |
|
| 258 | + return $hash; |
|
| 259 | + } |
|
| 248 | 260 | } |
| 249 | 261 | |
| 250 | - if (strlen($random) < 6) |
|
| 251 | - $random = $this->get_random_bytes(6); |
|
| 262 | + if (strlen($random) < 6) { |
|
| 263 | + $random = $this->get_random_bytes(6); |
|
| 264 | + } |
|
| 252 | 265 | $hash = |
| 253 | 266 | $this->crypt_private($password, |
| 254 | 267 | $this->gensalt_private($random)); |
| 255 | - if (strlen($hash) == 34) |
|
| 256 | - return $hash; |
|
| 268 | + if (strlen($hash) == 34) { |
|
| 269 | + return $hash; |
|
| 270 | + } |
|
| 257 | 271 | |
| 258 | 272 | # Returning '*' on error is safe here, but would _not_ be safe |
| 259 | 273 | # in a crypt(3)-like function used _both_ for generating new |
@@ -268,8 +282,9 @@ discard block |
||
| 268 | 282 | } |
| 269 | 283 | |
| 270 | 284 | $hash = $this->crypt_private($password, $stored_hash); |
| 271 | - if ($hash[0] == '*') |
|
| 272 | - $hash = crypt($password, $stored_hash); |
|
| 285 | + if ($hash[0] == '*') { |
|
| 286 | + $hash = crypt($password, $stored_hash); |
|
| 287 | + } |
|
| 273 | 288 | |
| 274 | 289 | return $hash === $stored_hash; |
| 275 | 290 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $output = ''; |
| 68 | 68 | if ( @is_readable('/dev/urandom') && |
| 69 | - ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
| 69 | + ($fh = @fopen('/dev/urandom', 'rb'))) { |
|
| 70 | 70 | $output = fread($fh, $count); |
| 71 | 71 | fclose($fh); |
| 72 | 72 | } |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | $output = ''; |
| 76 | 76 | for ($i = 0; $i < $count; $i += 16) { |
| 77 | 77 | $this->random_state = |
| 78 | - md5(microtime() . $this->random_state); |
|
| 78 | + md5(microtime() . $this->random_state); |
|
| 79 | 79 | $output .= |
| 80 | - pack('H*', md5($this->random_state)); |
|
| 80 | + pack('H*', md5($this->random_state)); |
|
| 81 | 81 | } |
| 82 | 82 | $output = substr($output, 0, $count); |
| 83 | 83 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { |
| 234 | 234 | $random = $this->get_random_bytes(16); |
| 235 | 235 | $hash = |
| 236 | - crypt($password, $this->gensalt_blowfish($random)); |
|
| 236 | + crypt($password, $this->gensalt_blowfish($random)); |
|
| 237 | 237 | if (strlen($hash) == 60) |
| 238 | 238 | return $hash; |
| 239 | 239 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | if (strlen($random) < 3) |
| 243 | 243 | $random = $this->get_random_bytes(3); |
| 244 | 244 | $hash = |
| 245 | - crypt($password, $this->gensalt_extended($random)); |
|
| 245 | + crypt($password, $this->gensalt_extended($random)); |
|
| 246 | 246 | if (strlen($hash) == 20) |
| 247 | 247 | return $hash; |
| 248 | 248 | } |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | if (strlen($random) < 6) |
| 251 | 251 | $random = $this->get_random_bytes(6); |
| 252 | 252 | $hash = |
| 253 | - $this->crypt_private($password, |
|
| 254 | - $this->gensalt_private($random)); |
|
| 253 | + $this->crypt_private($password, |
|
| 254 | + $this->gensalt_private($random)); |
|
| 255 | 255 | if (strlen($hash) == 34) |
| 256 | 256 | return $hash; |
| 257 | 257 | |
@@ -626,6 +626,9 @@ |
||
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | + /** |
|
| 630 | + * @param string $server_text |
|
| 631 | + */ |
|
| 629 | 632 | function parse_banner ( $server_text ) { |
| 630 | 633 | $outside = true; |
| 631 | 634 | $banner = ""; |
@@ -17,53 +17,53 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | class POP3 { |
| 20 | - var $ERROR = ''; // Error string. |
|
| 20 | + var $ERROR = ''; // Error string. |
|
| 21 | 21 | |
| 22 | - var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | - // network operation. |
|
| 22 | + var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | + // network operation. |
|
| 24 | 24 | |
| 25 | - var $COUNT = -1; // Mailbox msg count |
|
| 25 | + var $COUNT = -1; // Mailbox msg count |
|
| 26 | 26 | |
| 27 | - var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | - // Per RFC 1939 the returned line a POP3 |
|
| 29 | - // server can send is 512 bytes. |
|
| 27 | + var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | + // Per RFC 1939 the returned line a POP3 |
|
| 29 | + // server can send is 512 bytes. |
|
| 30 | 30 | |
| 31 | - var $FP = ''; // The connection to the server's |
|
| 32 | - // file descriptor |
|
| 31 | + var $FP = ''; // The connection to the server's |
|
| 32 | + // file descriptor |
|
| 33 | 33 | |
| 34 | - var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 34 | + var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 35 | 35 | |
| 36 | - var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | - // commands and responses to error_log |
|
| 38 | - // this WILL log passwords! |
|
| 36 | + var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | + // commands and responses to error_log |
|
| 38 | + // this WILL log passwords! |
|
| 39 | 39 | |
| 40 | - var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | - // pop server - used for apop() |
|
| 40 | + var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | + // pop server - used for apop() |
|
| 42 | 42 | |
| 43 | - var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | - // This must be set to true |
|
| 45 | - // manually |
|
| 43 | + var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | + // This must be set to true |
|
| 45 | + // manually |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * PHP5 constructor. |
| 49 | 49 | */ |
| 50 | - function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | - settype($this->BUFFER,"integer"); |
|
| 52 | - if( !empty($server) ) { |
|
| 53 | - // Do not allow programs to alter MAILSERVER |
|
| 54 | - // if it is already specified. They can get around |
|
| 55 | - // this if they -really- want to, so don't count on it. |
|
| 56 | - if(empty($this->MAILSERVER)) |
|
| 57 | - $this->MAILSERVER = $server; |
|
| 58 | - } |
|
| 59 | - if(!empty($timeout)) { |
|
| 60 | - settype($timeout,"integer"); |
|
| 61 | - $this->TIMEOUT = $timeout; |
|
| 62 | - if (!ini_get('safe_mode')) |
|
| 63 | - set_time_limit($timeout); |
|
| 64 | - } |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 50 | + function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | + settype($this->BUFFER,"integer"); |
|
| 52 | + if( !empty($server) ) { |
|
| 53 | + // Do not allow programs to alter MAILSERVER |
|
| 54 | + // if it is already specified. They can get around |
|
| 55 | + // this if they -really- want to, so don't count on it. |
|
| 56 | + if(empty($this->MAILSERVER)) |
|
| 57 | + $this->MAILSERVER = $server; |
|
| 58 | + } |
|
| 59 | + if(!empty($timeout)) { |
|
| 60 | + settype($timeout,"integer"); |
|
| 61 | + $this->TIMEOUT = $timeout; |
|
| 62 | + if (!ini_get('safe_mode')) |
|
| 63 | + set_time_limit($timeout); |
|
| 64 | + } |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * PHP4 constructor. |
@@ -72,591 +72,591 @@ discard block |
||
| 72 | 72 | self::__construct( $server, $timeout ); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - function update_timer () { |
|
| 76 | - if (!ini_get('safe_mode')) |
|
| 77 | - set_time_limit($this->TIMEOUT); |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - function connect ($server, $port = 110) { |
|
| 82 | - // Opens a socket to the specified server. Unless overridden, |
|
| 83 | - // port defaults to 110. Returns true on success, false on fail |
|
| 84 | - |
|
| 85 | - // If MAILSERVER is set, override $server with its value. |
|
| 86 | - |
|
| 87 | - if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 89 | - $server = $this->MAILSERVER; |
|
| 90 | - |
|
| 91 | - if(empty($server)){ |
|
| 92 | - $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 93 | - unset($this->FP); |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $fp = @fsockopen("$server", $port, $errno, $errstr); |
|
| 98 | - |
|
| 99 | - if(!$fp) { |
|
| 100 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 101 | - unset($this->FP); |
|
| 102 | - return false; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - socket_set_blocking($fp,-1); |
|
| 106 | - $this->update_timer(); |
|
| 107 | - $reply = fgets($fp,$this->BUFFER); |
|
| 108 | - $reply = $this->strip_clf($reply); |
|
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | - if(!$this->is_ok($reply)) { |
|
| 112 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 113 | - unset($this->FP); |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 116 | - $this->FP = $fp; |
|
| 117 | - $this->BANNER = $this->parse_banner($reply); |
|
| 118 | - return true; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - function user ($user = "") { |
|
| 122 | - // Sends the USER command, returns true or false |
|
| 123 | - |
|
| 124 | - if( empty($user) ) { |
|
| 125 | - $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 126 | - return false; |
|
| 127 | - } elseif(!isset($this->FP)) { |
|
| 128 | - $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 129 | - return false; |
|
| 130 | - } else { |
|
| 131 | - $reply = $this->send_cmd("USER $user"); |
|
| 132 | - if(!$this->is_ok($reply)) { |
|
| 133 | - $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 134 | - return false; |
|
| 135 | - } else |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - function pass ($pass = "") { |
|
| 141 | - // Sends the PASS command, returns # of msgs in mailbox, |
|
| 142 | - // returns false (undef) on Auth failure |
|
| 143 | - |
|
| 144 | - if(empty($pass)) { |
|
| 145 | - $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 146 | - return false; |
|
| 147 | - } elseif(!isset($this->FP)) { |
|
| 148 | - $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 149 | - return false; |
|
| 150 | - } else { |
|
| 151 | - $reply = $this->send_cmd("PASS $pass"); |
|
| 152 | - if(!$this->is_ok($reply)) { |
|
| 153 | - $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 154 | - $this->quit(); |
|
| 155 | - return false; |
|
| 156 | - } else { |
|
| 157 | - // Auth successful. |
|
| 158 | - $count = $this->last("count"); |
|
| 159 | - $this->COUNT = $count; |
|
| 160 | - return $count; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - function apop ($login,$pass) { |
|
| 166 | - // Attempts an APOP login. If this fails, it'll |
|
| 167 | - // try a standard login. YOUR SERVER MUST SUPPORT |
|
| 168 | - // THE USE OF THE APOP COMMAND! |
|
| 169 | - // (apop is optional per rfc1939) |
|
| 170 | - |
|
| 171 | - if(!isset($this->FP)) { |
|
| 172 | - $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 173 | - return false; |
|
| 174 | - } elseif(!$this->ALLOWAPOP) { |
|
| 175 | - $retVal = $this->login($login,$pass); |
|
| 176 | - return $retVal; |
|
| 177 | - } elseif(empty($login)) { |
|
| 178 | - $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 179 | - return false; |
|
| 180 | - } elseif(empty($pass)) { |
|
| 181 | - $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 182 | - return false; |
|
| 183 | - } else { |
|
| 184 | - $banner = $this->BANNER; |
|
| 185 | - if( (!$banner) or (empty($banner)) ) { |
|
| 186 | - $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | - $retVal = $this->login($login,$pass); |
|
| 188 | - return $retVal; |
|
| 189 | - } else { |
|
| 190 | - $AuthString = $banner; |
|
| 191 | - $AuthString .= $pass; |
|
| 192 | - $APOPString = md5($AuthString); |
|
| 193 | - $cmd = "APOP $login $APOPString"; |
|
| 194 | - $reply = $this->send_cmd($cmd); |
|
| 195 | - if(!$this->is_ok($reply)) { |
|
| 196 | - $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | - $retVal = $this->login($login,$pass); |
|
| 198 | - return $retVal; |
|
| 199 | - } else { |
|
| 200 | - // Auth successful. |
|
| 201 | - $count = $this->last("count"); |
|
| 202 | - $this->COUNT = $count; |
|
| 203 | - return $count; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - function login ($login = "", $pass = "") { |
|
| 210 | - // Sends both user and pass. Returns # of msgs in mailbox or |
|
| 211 | - // false on failure (or -1, if the error occurs while getting |
|
| 212 | - // the number of messages.) |
|
| 213 | - |
|
| 214 | - if( !isset($this->FP) ) { |
|
| 215 | - $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 216 | - return false; |
|
| 217 | - } else { |
|
| 218 | - $fp = $this->FP; |
|
| 219 | - if( !$this->user( $login ) ) { |
|
| 220 | - // Preserve the error generated by user() |
|
| 221 | - return false; |
|
| 222 | - } else { |
|
| 223 | - $count = $this->pass($pass); |
|
| 224 | - if( (!$count) || ($count == -1) ) { |
|
| 225 | - // Preserve the error generated by last() and pass() |
|
| 226 | - return false; |
|
| 227 | - } else |
|
| 228 | - return $count; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - function top ($msgNum, $numLines = "0") { |
|
| 234 | - // Gets the header and first $numLines of the msg body |
|
| 235 | - // returns data in an array with each returned line being |
|
| 236 | - // an array element. If $numLines is empty, returns |
|
| 237 | - // only the header information, and none of the body. |
|
| 238 | - |
|
| 239 | - if(!isset($this->FP)) { |
|
| 240 | - $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 241 | - return false; |
|
| 242 | - } |
|
| 243 | - $this->update_timer(); |
|
| 244 | - |
|
| 245 | - $fp = $this->FP; |
|
| 246 | - $buffer = $this->BUFFER; |
|
| 247 | - $cmd = "TOP $msgNum $numLines"; |
|
| 248 | - fwrite($fp, "TOP $msgNum $numLines\r\n"); |
|
| 249 | - $reply = fgets($fp, $buffer); |
|
| 250 | - $reply = $this->strip_clf($reply); |
|
| 251 | - if($this->DEBUG) { |
|
| 252 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 253 | - } |
|
| 254 | - if(!$this->is_ok($reply)) |
|
| 255 | - { |
|
| 256 | - $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 257 | - return false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $count = 0; |
|
| 261 | - $MsgArray = array(); |
|
| 262 | - |
|
| 263 | - $line = fgets($fp,$buffer); |
|
| 264 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 265 | - { |
|
| 266 | - $MsgArray[$count] = $line; |
|
| 267 | - $count++; |
|
| 268 | - $line = fgets($fp,$buffer); |
|
| 269 | - if(empty($line)) { break; } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $MsgArray; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - function pop_list ($msgNum = "") { |
|
| 276 | - // If called with an argument, returns that msgs' size in octets |
|
| 277 | - // No argument returns an associative array of undeleted |
|
| 278 | - // msg numbers and their sizes in octets |
|
| 279 | - |
|
| 280 | - if(!isset($this->FP)) |
|
| 281 | - { |
|
| 282 | - $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - $fp = $this->FP; |
|
| 286 | - $Total = $this->COUNT; |
|
| 287 | - if( (!$Total) or ($Total == -1) ) |
|
| 288 | - { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - if($Total == 0) |
|
| 292 | - { |
|
| 293 | - return array("0","0"); |
|
| 294 | - // return -1; // mailbox empty |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $this->update_timer(); |
|
| 298 | - |
|
| 299 | - if(!empty($msgNum)) |
|
| 300 | - { |
|
| 301 | - $cmd = "LIST $msgNum"; |
|
| 302 | - fwrite($fp,"$cmd\r\n"); |
|
| 303 | - $reply = fgets($fp,$this->BUFFER); |
|
| 304 | - $reply = $this->strip_clf($reply); |
|
| 305 | - if($this->DEBUG) { |
|
| 306 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 307 | - } |
|
| 308 | - if(!$this->is_ok($reply)) |
|
| 309 | - { |
|
| 310 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 314 | - return $size; |
|
| 315 | - } |
|
| 316 | - $cmd = "LIST"; |
|
| 317 | - $reply = $this->send_cmd($cmd); |
|
| 318 | - if(!$this->is_ok($reply)) |
|
| 319 | - { |
|
| 320 | - $reply = $this->strip_clf($reply); |
|
| 321 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - $MsgArray = array(); |
|
| 325 | - $MsgArray[0] = $Total; |
|
| 326 | - for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 327 | - { |
|
| 328 | - if($msgC > $Total) { break; } |
|
| 329 | - $line = fgets($fp,$this->BUFFER); |
|
| 330 | - $line = $this->strip_clf($line); |
|
| 331 | - if(strpos($line, '.') === 0) |
|
| 332 | - { |
|
| 333 | - $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | - settype($thisMsg,"integer"); |
|
| 338 | - if($thisMsg != $msgC) |
|
| 339 | - { |
|
| 340 | - $MsgArray[$msgC] = "deleted"; |
|
| 341 | - } |
|
| 342 | - else |
|
| 343 | - { |
|
| 344 | - $MsgArray[$msgC] = $msgSize; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - return $MsgArray; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - function get ($msgNum) { |
|
| 351 | - // Retrieve the specified msg number. Returns an array |
|
| 352 | - // where each line of the msg is an array element. |
|
| 353 | - |
|
| 354 | - if(!isset($this->FP)) |
|
| 355 | - { |
|
| 356 | - $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 357 | - return false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $this->update_timer(); |
|
| 361 | - |
|
| 362 | - $fp = $this->FP; |
|
| 363 | - $buffer = $this->BUFFER; |
|
| 364 | - $cmd = "RETR $msgNum"; |
|
| 365 | - $reply = $this->send_cmd($cmd); |
|
| 366 | - |
|
| 367 | - if(!$this->is_ok($reply)) |
|
| 368 | - { |
|
| 369 | - $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 370 | - return false; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $count = 0; |
|
| 374 | - $MsgArray = array(); |
|
| 375 | - |
|
| 376 | - $line = fgets($fp,$buffer); |
|
| 377 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 378 | - { |
|
| 379 | - if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 380 | - $MsgArray[$count] = $line; |
|
| 381 | - $count++; |
|
| 382 | - $line = fgets($fp,$buffer); |
|
| 383 | - if(empty($line)) { break; } |
|
| 384 | - } |
|
| 385 | - return $MsgArray; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - function last ( $type = "count" ) { |
|
| 389 | - // Returns the highest msg number in the mailbox. |
|
| 390 | - // returns -1 on error, 0+ on success, if type != count |
|
| 391 | - // results in a popstat() call (2 element array returned) |
|
| 392 | - |
|
| 393 | - $last = -1; |
|
| 394 | - if(!isset($this->FP)) |
|
| 395 | - { |
|
| 396 | - $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 397 | - return $last; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - $reply = $this->send_cmd("STAT"); |
|
| 401 | - if(!$this->is_ok($reply)) |
|
| 402 | - { |
|
| 403 | - $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 404 | - return $last; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - $Vars = preg_split('/\s+/',$reply); |
|
| 408 | - $count = $Vars[1]; |
|
| 409 | - $size = $Vars[2]; |
|
| 410 | - settype($count,"integer"); |
|
| 411 | - settype($size,"integer"); |
|
| 412 | - if($type != "count") |
|
| 413 | - { |
|
| 414 | - return array($count,$size); |
|
| 415 | - } |
|
| 416 | - return $count; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - function reset () { |
|
| 420 | - // Resets the status of the remote server. This includes |
|
| 421 | - // resetting the status of ALL msgs to not be deleted. |
|
| 422 | - // This method automatically closes the connection to the server. |
|
| 423 | - |
|
| 424 | - if(!isset($this->FP)) |
|
| 425 | - { |
|
| 426 | - $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - $reply = $this->send_cmd("RSET"); |
|
| 430 | - if(!$this->is_ok($reply)) |
|
| 431 | - { |
|
| 432 | - // The POP3 RSET command -never- gives a -ERR |
|
| 433 | - // response - if it ever does, something truly |
|
| 434 | - // wild is going on. |
|
| 435 | - |
|
| 436 | - $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | - @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 438 | - } |
|
| 439 | - $this->quit(); |
|
| 440 | - return true; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - function send_cmd ( $cmd = "" ) |
|
| 444 | - { |
|
| 445 | - // Sends a user defined command string to the |
|
| 446 | - // POP server and returns the results. Useful for |
|
| 447 | - // non-compliant or custom POP servers. |
|
| 448 | - // Do NOT includ the \r\n as part of your command |
|
| 449 | - // string - it will be appended automatically. |
|
| 450 | - |
|
| 451 | - // The return value is a standard fgets() call, which |
|
| 452 | - // will read up to $this->BUFFER bytes of data, until it |
|
| 453 | - // encounters a new line, or EOF, whichever happens first. |
|
| 454 | - |
|
| 455 | - // This method works best if $cmd responds with only |
|
| 456 | - // one line of data. |
|
| 457 | - |
|
| 458 | - if(!isset($this->FP)) |
|
| 459 | - { |
|
| 460 | - $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - if(empty($cmd)) |
|
| 465 | - { |
|
| 466 | - $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 467 | - return ""; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $fp = $this->FP; |
|
| 471 | - $buffer = $this->BUFFER; |
|
| 472 | - $this->update_timer(); |
|
| 473 | - fwrite($fp,"$cmd\r\n"); |
|
| 474 | - $reply = fgets($fp,$buffer); |
|
| 475 | - $reply = $this->strip_clf($reply); |
|
| 476 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 477 | - return $reply; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - function quit() { |
|
| 481 | - // Closes the connection to the POP3 server, deleting |
|
| 482 | - // any msgs marked as deleted. |
|
| 483 | - |
|
| 484 | - if(!isset($this->FP)) |
|
| 485 | - { |
|
| 486 | - $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 487 | - return false; |
|
| 488 | - } |
|
| 489 | - $fp = $this->FP; |
|
| 490 | - $cmd = "QUIT"; |
|
| 491 | - fwrite($fp,"$cmd\r\n"); |
|
| 492 | - $reply = fgets($fp,$this->BUFFER); |
|
| 493 | - $reply = $this->strip_clf($reply); |
|
| 494 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 495 | - fclose($fp); |
|
| 496 | - unset($this->FP); |
|
| 497 | - return true; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - function popstat () { |
|
| 501 | - // Returns an array of 2 elements. The number of undeleted |
|
| 502 | - // msgs in the mailbox, and the size of the mbox in octets. |
|
| 503 | - |
|
| 504 | - $PopArray = $this->last("array"); |
|
| 505 | - |
|
| 506 | - if($PopArray == -1) { return false; } |
|
| 507 | - |
|
| 508 | - if( (!$PopArray) or (empty($PopArray)) ) |
|
| 509 | - { |
|
| 510 | - return false; |
|
| 511 | - } |
|
| 512 | - return $PopArray; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - function uidl ($msgNum = "") |
|
| 516 | - { |
|
| 517 | - // Returns the UIDL of the msg specified. If called with |
|
| 518 | - // no arguments, returns an associative array where each |
|
| 519 | - // undeleted msg num is a key, and the msg's uidl is the element |
|
| 520 | - // Array element 0 will contain the total number of msgs |
|
| 521 | - |
|
| 522 | - if(!isset($this->FP)) { |
|
| 523 | - $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 524 | - return false; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $fp = $this->FP; |
|
| 528 | - $buffer = $this->BUFFER; |
|
| 529 | - |
|
| 530 | - if(!empty($msgNum)) { |
|
| 531 | - $cmd = "UIDL $msgNum"; |
|
| 532 | - $reply = $this->send_cmd($cmd); |
|
| 533 | - if(!$this->is_ok($reply)) |
|
| 534 | - { |
|
| 535 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 539 | - return $myUidl; |
|
| 540 | - } else { |
|
| 541 | - $this->update_timer(); |
|
| 542 | - |
|
| 543 | - $UIDLArray = array(); |
|
| 544 | - $Total = $this->COUNT; |
|
| 545 | - $UIDLArray[0] = $Total; |
|
| 546 | - |
|
| 547 | - if ($Total < 1) |
|
| 548 | - { |
|
| 549 | - return $UIDLArray; |
|
| 550 | - } |
|
| 551 | - $cmd = "UIDL"; |
|
| 552 | - fwrite($fp, "UIDL\r\n"); |
|
| 553 | - $reply = fgets($fp, $buffer); |
|
| 554 | - $reply = $this->strip_clf($reply); |
|
| 555 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | - if(!$this->is_ok($reply)) |
|
| 557 | - { |
|
| 558 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - $line = ""; |
|
| 563 | - $count = 1; |
|
| 564 | - $line = fgets($fp,$buffer); |
|
| 565 | - while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | - list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 567 | - $msgUidl = $this->strip_clf($msgUidl); |
|
| 568 | - if($count == $msg) { |
|
| 569 | - $UIDLArray[$msg] = $msgUidl; |
|
| 570 | - } |
|
| 571 | - else |
|
| 572 | - { |
|
| 573 | - $UIDLArray[$count] = 'deleted'; |
|
| 574 | - } |
|
| 575 | - $count++; |
|
| 576 | - $line = fgets($fp,$buffer); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - return $UIDLArray; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - function delete ($msgNum = "") { |
|
| 583 | - // Flags a specified msg as deleted. The msg will not |
|
| 584 | - // be deleted until a quit() method is called. |
|
| 585 | - |
|
| 586 | - if(!isset($this->FP)) |
|
| 587 | - { |
|
| 588 | - $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 589 | - return false; |
|
| 590 | - } |
|
| 591 | - if(empty($msgNum)) |
|
| 592 | - { |
|
| 593 | - $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 594 | - return false; |
|
| 595 | - } |
|
| 596 | - $reply = $this->send_cmd("DELE $msgNum"); |
|
| 597 | - if(!$this->is_ok($reply)) |
|
| 598 | - { |
|
| 599 | - $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 600 | - return false; |
|
| 601 | - } |
|
| 602 | - return true; |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // ********************************************************* |
|
| 606 | - |
|
| 607 | - // The following methods are internal to the class. |
|
| 608 | - |
|
| 609 | - function is_ok ($cmd = "") { |
|
| 610 | - // Return true or false on +OK or -ERR |
|
| 611 | - |
|
| 612 | - if( empty($cmd) ) |
|
| 613 | - return false; |
|
| 614 | - else |
|
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - function strip_clf ($text = "") { |
|
| 619 | - // Strips \r\n from server responses |
|
| 620 | - |
|
| 621 | - if(empty($text)) |
|
| 622 | - return $text; |
|
| 623 | - else { |
|
| 624 | - $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 625 | - return $stripped; |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - function parse_banner ( $server_text ) { |
|
| 630 | - $outside = true; |
|
| 631 | - $banner = ""; |
|
| 632 | - $length = strlen($server_text); |
|
| 633 | - for($count =0; $count < $length; $count++) |
|
| 634 | - { |
|
| 635 | - $digit = substr($server_text,$count,1); |
|
| 636 | - if(!empty($digit)) { |
|
| 637 | - if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 638 | - { |
|
| 639 | - $banner .= $digit; |
|
| 640 | - } |
|
| 641 | - if ($digit == '<') |
|
| 642 | - { |
|
| 643 | - $outside = false; |
|
| 644 | - } |
|
| 645 | - if($digit == '>') |
|
| 646 | - { |
|
| 647 | - $outside = true; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | - return "<$banner>"; |
|
| 653 | - } |
|
| 75 | + function update_timer () { |
|
| 76 | + if (!ini_get('safe_mode')) |
|
| 77 | + set_time_limit($this->TIMEOUT); |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + function connect ($server, $port = 110) { |
|
| 82 | + // Opens a socket to the specified server. Unless overridden, |
|
| 83 | + // port defaults to 110. Returns true on success, false on fail |
|
| 84 | + |
|
| 85 | + // If MAILSERVER is set, override $server with its value. |
|
| 86 | + |
|
| 87 | + if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | + if(!empty($this->MAILSERVER)) |
|
| 89 | + $server = $this->MAILSERVER; |
|
| 90 | + |
|
| 91 | + if(empty($server)){ |
|
| 92 | + $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 93 | + unset($this->FP); |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $fp = @fsockopen("$server", $port, $errno, $errstr); |
|
| 98 | + |
|
| 99 | + if(!$fp) { |
|
| 100 | + $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 101 | + unset($this->FP); |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + socket_set_blocking($fp,-1); |
|
| 106 | + $this->update_timer(); |
|
| 107 | + $reply = fgets($fp,$this->BUFFER); |
|
| 108 | + $reply = $this->strip_clf($reply); |
|
| 109 | + if($this->DEBUG) |
|
| 110 | + error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | + if(!$this->is_ok($reply)) { |
|
| 112 | + $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 113 | + unset($this->FP); |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | + $this->FP = $fp; |
|
| 117 | + $this->BANNER = $this->parse_banner($reply); |
|
| 118 | + return true; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + function user ($user = "") { |
|
| 122 | + // Sends the USER command, returns true or false |
|
| 123 | + |
|
| 124 | + if( empty($user) ) { |
|
| 125 | + $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 126 | + return false; |
|
| 127 | + } elseif(!isset($this->FP)) { |
|
| 128 | + $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 129 | + return false; |
|
| 130 | + } else { |
|
| 131 | + $reply = $this->send_cmd("USER $user"); |
|
| 132 | + if(!$this->is_ok($reply)) { |
|
| 133 | + $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 134 | + return false; |
|
| 135 | + } else |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + function pass ($pass = "") { |
|
| 141 | + // Sends the PASS command, returns # of msgs in mailbox, |
|
| 142 | + // returns false (undef) on Auth failure |
|
| 143 | + |
|
| 144 | + if(empty($pass)) { |
|
| 145 | + $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 146 | + return false; |
|
| 147 | + } elseif(!isset($this->FP)) { |
|
| 148 | + $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 149 | + return false; |
|
| 150 | + } else { |
|
| 151 | + $reply = $this->send_cmd("PASS $pass"); |
|
| 152 | + if(!$this->is_ok($reply)) { |
|
| 153 | + $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 154 | + $this->quit(); |
|
| 155 | + return false; |
|
| 156 | + } else { |
|
| 157 | + // Auth successful. |
|
| 158 | + $count = $this->last("count"); |
|
| 159 | + $this->COUNT = $count; |
|
| 160 | + return $count; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + function apop ($login,$pass) { |
|
| 166 | + // Attempts an APOP login. If this fails, it'll |
|
| 167 | + // try a standard login. YOUR SERVER MUST SUPPORT |
|
| 168 | + // THE USE OF THE APOP COMMAND! |
|
| 169 | + // (apop is optional per rfc1939) |
|
| 170 | + |
|
| 171 | + if(!isset($this->FP)) { |
|
| 172 | + $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 173 | + return false; |
|
| 174 | + } elseif(!$this->ALLOWAPOP) { |
|
| 175 | + $retVal = $this->login($login,$pass); |
|
| 176 | + return $retVal; |
|
| 177 | + } elseif(empty($login)) { |
|
| 178 | + $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 179 | + return false; |
|
| 180 | + } elseif(empty($pass)) { |
|
| 181 | + $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 182 | + return false; |
|
| 183 | + } else { |
|
| 184 | + $banner = $this->BANNER; |
|
| 185 | + if( (!$banner) or (empty($banner)) ) { |
|
| 186 | + $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | + $retVal = $this->login($login,$pass); |
|
| 188 | + return $retVal; |
|
| 189 | + } else { |
|
| 190 | + $AuthString = $banner; |
|
| 191 | + $AuthString .= $pass; |
|
| 192 | + $APOPString = md5($AuthString); |
|
| 193 | + $cmd = "APOP $login $APOPString"; |
|
| 194 | + $reply = $this->send_cmd($cmd); |
|
| 195 | + if(!$this->is_ok($reply)) { |
|
| 196 | + $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | + $retVal = $this->login($login,$pass); |
|
| 198 | + return $retVal; |
|
| 199 | + } else { |
|
| 200 | + // Auth successful. |
|
| 201 | + $count = $this->last("count"); |
|
| 202 | + $this->COUNT = $count; |
|
| 203 | + return $count; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + function login ($login = "", $pass = "") { |
|
| 210 | + // Sends both user and pass. Returns # of msgs in mailbox or |
|
| 211 | + // false on failure (or -1, if the error occurs while getting |
|
| 212 | + // the number of messages.) |
|
| 213 | + |
|
| 214 | + if( !isset($this->FP) ) { |
|
| 215 | + $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 216 | + return false; |
|
| 217 | + } else { |
|
| 218 | + $fp = $this->FP; |
|
| 219 | + if( !$this->user( $login ) ) { |
|
| 220 | + // Preserve the error generated by user() |
|
| 221 | + return false; |
|
| 222 | + } else { |
|
| 223 | + $count = $this->pass($pass); |
|
| 224 | + if( (!$count) || ($count == -1) ) { |
|
| 225 | + // Preserve the error generated by last() and pass() |
|
| 226 | + return false; |
|
| 227 | + } else |
|
| 228 | + return $count; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + function top ($msgNum, $numLines = "0") { |
|
| 234 | + // Gets the header and first $numLines of the msg body |
|
| 235 | + // returns data in an array with each returned line being |
|
| 236 | + // an array element. If $numLines is empty, returns |
|
| 237 | + // only the header information, and none of the body. |
|
| 238 | + |
|
| 239 | + if(!isset($this->FP)) { |
|
| 240 | + $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 243 | + $this->update_timer(); |
|
| 244 | + |
|
| 245 | + $fp = $this->FP; |
|
| 246 | + $buffer = $this->BUFFER; |
|
| 247 | + $cmd = "TOP $msgNum $numLines"; |
|
| 248 | + fwrite($fp, "TOP $msgNum $numLines\r\n"); |
|
| 249 | + $reply = fgets($fp, $buffer); |
|
| 250 | + $reply = $this->strip_clf($reply); |
|
| 251 | + if($this->DEBUG) { |
|
| 252 | + @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 253 | + } |
|
| 254 | + if(!$this->is_ok($reply)) |
|
| 255 | + { |
|
| 256 | + $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 257 | + return false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $count = 0; |
|
| 261 | + $MsgArray = array(); |
|
| 262 | + |
|
| 263 | + $line = fgets($fp,$buffer); |
|
| 264 | + while ( !preg_match('/^\.\r\n/',$line)) |
|
| 265 | + { |
|
| 266 | + $MsgArray[$count] = $line; |
|
| 267 | + $count++; |
|
| 268 | + $line = fgets($fp,$buffer); |
|
| 269 | + if(empty($line)) { break; } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $MsgArray; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + function pop_list ($msgNum = "") { |
|
| 276 | + // If called with an argument, returns that msgs' size in octets |
|
| 277 | + // No argument returns an associative array of undeleted |
|
| 278 | + // msg numbers and their sizes in octets |
|
| 279 | + |
|
| 280 | + if(!isset($this->FP)) |
|
| 281 | + { |
|
| 282 | + $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + $fp = $this->FP; |
|
| 286 | + $Total = $this->COUNT; |
|
| 287 | + if( (!$Total) or ($Total == -1) ) |
|
| 288 | + { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + if($Total == 0) |
|
| 292 | + { |
|
| 293 | + return array("0","0"); |
|
| 294 | + // return -1; // mailbox empty |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $this->update_timer(); |
|
| 298 | + |
|
| 299 | + if(!empty($msgNum)) |
|
| 300 | + { |
|
| 301 | + $cmd = "LIST $msgNum"; |
|
| 302 | + fwrite($fp,"$cmd\r\n"); |
|
| 303 | + $reply = fgets($fp,$this->BUFFER); |
|
| 304 | + $reply = $this->strip_clf($reply); |
|
| 305 | + if($this->DEBUG) { |
|
| 306 | + @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 307 | + } |
|
| 308 | + if(!$this->is_ok($reply)) |
|
| 309 | + { |
|
| 310 | + $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 314 | + return $size; |
|
| 315 | + } |
|
| 316 | + $cmd = "LIST"; |
|
| 317 | + $reply = $this->send_cmd($cmd); |
|
| 318 | + if(!$this->is_ok($reply)) |
|
| 319 | + { |
|
| 320 | + $reply = $this->strip_clf($reply); |
|
| 321 | + $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + $MsgArray = array(); |
|
| 325 | + $MsgArray[0] = $Total; |
|
| 326 | + for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 327 | + { |
|
| 328 | + if($msgC > $Total) { break; } |
|
| 329 | + $line = fgets($fp,$this->BUFFER); |
|
| 330 | + $line = $this->strip_clf($line); |
|
| 331 | + if(strpos($line, '.') === 0) |
|
| 332 | + { |
|
| 333 | + $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | + settype($thisMsg,"integer"); |
|
| 338 | + if($thisMsg != $msgC) |
|
| 339 | + { |
|
| 340 | + $MsgArray[$msgC] = "deleted"; |
|
| 341 | + } |
|
| 342 | + else |
|
| 343 | + { |
|
| 344 | + $MsgArray[$msgC] = $msgSize; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + return $MsgArray; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + function get ($msgNum) { |
|
| 351 | + // Retrieve the specified msg number. Returns an array |
|
| 352 | + // where each line of the msg is an array element. |
|
| 353 | + |
|
| 354 | + if(!isset($this->FP)) |
|
| 355 | + { |
|
| 356 | + $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $this->update_timer(); |
|
| 361 | + |
|
| 362 | + $fp = $this->FP; |
|
| 363 | + $buffer = $this->BUFFER; |
|
| 364 | + $cmd = "RETR $msgNum"; |
|
| 365 | + $reply = $this->send_cmd($cmd); |
|
| 366 | + |
|
| 367 | + if(!$this->is_ok($reply)) |
|
| 368 | + { |
|
| 369 | + $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 370 | + return false; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $count = 0; |
|
| 374 | + $MsgArray = array(); |
|
| 375 | + |
|
| 376 | + $line = fgets($fp,$buffer); |
|
| 377 | + while ( !preg_match('/^\.\r\n/',$line)) |
|
| 378 | + { |
|
| 379 | + if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 380 | + $MsgArray[$count] = $line; |
|
| 381 | + $count++; |
|
| 382 | + $line = fgets($fp,$buffer); |
|
| 383 | + if(empty($line)) { break; } |
|
| 384 | + } |
|
| 385 | + return $MsgArray; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + function last ( $type = "count" ) { |
|
| 389 | + // Returns the highest msg number in the mailbox. |
|
| 390 | + // returns -1 on error, 0+ on success, if type != count |
|
| 391 | + // results in a popstat() call (2 element array returned) |
|
| 392 | + |
|
| 393 | + $last = -1; |
|
| 394 | + if(!isset($this->FP)) |
|
| 395 | + { |
|
| 396 | + $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 397 | + return $last; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + $reply = $this->send_cmd("STAT"); |
|
| 401 | + if(!$this->is_ok($reply)) |
|
| 402 | + { |
|
| 403 | + $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 404 | + return $last; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + $Vars = preg_split('/\s+/',$reply); |
|
| 408 | + $count = $Vars[1]; |
|
| 409 | + $size = $Vars[2]; |
|
| 410 | + settype($count,"integer"); |
|
| 411 | + settype($size,"integer"); |
|
| 412 | + if($type != "count") |
|
| 413 | + { |
|
| 414 | + return array($count,$size); |
|
| 415 | + } |
|
| 416 | + return $count; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + function reset () { |
|
| 420 | + // Resets the status of the remote server. This includes |
|
| 421 | + // resetting the status of ALL msgs to not be deleted. |
|
| 422 | + // This method automatically closes the connection to the server. |
|
| 423 | + |
|
| 424 | + if(!isset($this->FP)) |
|
| 425 | + { |
|
| 426 | + $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + $reply = $this->send_cmd("RSET"); |
|
| 430 | + if(!$this->is_ok($reply)) |
|
| 431 | + { |
|
| 432 | + // The POP3 RSET command -never- gives a -ERR |
|
| 433 | + // response - if it ever does, something truly |
|
| 434 | + // wild is going on. |
|
| 435 | + |
|
| 436 | + $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | + @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 438 | + } |
|
| 439 | + $this->quit(); |
|
| 440 | + return true; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + function send_cmd ( $cmd = "" ) |
|
| 444 | + { |
|
| 445 | + // Sends a user defined command string to the |
|
| 446 | + // POP server and returns the results. Useful for |
|
| 447 | + // non-compliant or custom POP servers. |
|
| 448 | + // Do NOT includ the \r\n as part of your command |
|
| 449 | + // string - it will be appended automatically. |
|
| 450 | + |
|
| 451 | + // The return value is a standard fgets() call, which |
|
| 452 | + // will read up to $this->BUFFER bytes of data, until it |
|
| 453 | + // encounters a new line, or EOF, whichever happens first. |
|
| 454 | + |
|
| 455 | + // This method works best if $cmd responds with only |
|
| 456 | + // one line of data. |
|
| 457 | + |
|
| 458 | + if(!isset($this->FP)) |
|
| 459 | + { |
|
| 460 | + $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + if(empty($cmd)) |
|
| 465 | + { |
|
| 466 | + $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 467 | + return ""; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $fp = $this->FP; |
|
| 471 | + $buffer = $this->BUFFER; |
|
| 472 | + $this->update_timer(); |
|
| 473 | + fwrite($fp,"$cmd\r\n"); |
|
| 474 | + $reply = fgets($fp,$buffer); |
|
| 475 | + $reply = $this->strip_clf($reply); |
|
| 476 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 477 | + return $reply; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + function quit() { |
|
| 481 | + // Closes the connection to the POP3 server, deleting |
|
| 482 | + // any msgs marked as deleted. |
|
| 483 | + |
|
| 484 | + if(!isset($this->FP)) |
|
| 485 | + { |
|
| 486 | + $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 487 | + return false; |
|
| 488 | + } |
|
| 489 | + $fp = $this->FP; |
|
| 490 | + $cmd = "QUIT"; |
|
| 491 | + fwrite($fp,"$cmd\r\n"); |
|
| 492 | + $reply = fgets($fp,$this->BUFFER); |
|
| 493 | + $reply = $this->strip_clf($reply); |
|
| 494 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 495 | + fclose($fp); |
|
| 496 | + unset($this->FP); |
|
| 497 | + return true; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + function popstat () { |
|
| 501 | + // Returns an array of 2 elements. The number of undeleted |
|
| 502 | + // msgs in the mailbox, and the size of the mbox in octets. |
|
| 503 | + |
|
| 504 | + $PopArray = $this->last("array"); |
|
| 505 | + |
|
| 506 | + if($PopArray == -1) { return false; } |
|
| 507 | + |
|
| 508 | + if( (!$PopArray) or (empty($PopArray)) ) |
|
| 509 | + { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 512 | + return $PopArray; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + function uidl ($msgNum = "") |
|
| 516 | + { |
|
| 517 | + // Returns the UIDL of the msg specified. If called with |
|
| 518 | + // no arguments, returns an associative array where each |
|
| 519 | + // undeleted msg num is a key, and the msg's uidl is the element |
|
| 520 | + // Array element 0 will contain the total number of msgs |
|
| 521 | + |
|
| 522 | + if(!isset($this->FP)) { |
|
| 523 | + $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 524 | + return false; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $fp = $this->FP; |
|
| 528 | + $buffer = $this->BUFFER; |
|
| 529 | + |
|
| 530 | + if(!empty($msgNum)) { |
|
| 531 | + $cmd = "UIDL $msgNum"; |
|
| 532 | + $reply = $this->send_cmd($cmd); |
|
| 533 | + if(!$this->is_ok($reply)) |
|
| 534 | + { |
|
| 535 | + $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 539 | + return $myUidl; |
|
| 540 | + } else { |
|
| 541 | + $this->update_timer(); |
|
| 542 | + |
|
| 543 | + $UIDLArray = array(); |
|
| 544 | + $Total = $this->COUNT; |
|
| 545 | + $UIDLArray[0] = $Total; |
|
| 546 | + |
|
| 547 | + if ($Total < 1) |
|
| 548 | + { |
|
| 549 | + return $UIDLArray; |
|
| 550 | + } |
|
| 551 | + $cmd = "UIDL"; |
|
| 552 | + fwrite($fp, "UIDL\r\n"); |
|
| 553 | + $reply = fgets($fp, $buffer); |
|
| 554 | + $reply = $this->strip_clf($reply); |
|
| 555 | + if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | + if(!$this->is_ok($reply)) |
|
| 557 | + { |
|
| 558 | + $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + $line = ""; |
|
| 563 | + $count = 1; |
|
| 564 | + $line = fgets($fp,$buffer); |
|
| 565 | + while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | + list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 567 | + $msgUidl = $this->strip_clf($msgUidl); |
|
| 568 | + if($count == $msg) { |
|
| 569 | + $UIDLArray[$msg] = $msgUidl; |
|
| 570 | + } |
|
| 571 | + else |
|
| 572 | + { |
|
| 573 | + $UIDLArray[$count] = 'deleted'; |
|
| 574 | + } |
|
| 575 | + $count++; |
|
| 576 | + $line = fgets($fp,$buffer); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + return $UIDLArray; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + function delete ($msgNum = "") { |
|
| 583 | + // Flags a specified msg as deleted. The msg will not |
|
| 584 | + // be deleted until a quit() method is called. |
|
| 585 | + |
|
| 586 | + if(!isset($this->FP)) |
|
| 587 | + { |
|
| 588 | + $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 589 | + return false; |
|
| 590 | + } |
|
| 591 | + if(empty($msgNum)) |
|
| 592 | + { |
|
| 593 | + $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 594 | + return false; |
|
| 595 | + } |
|
| 596 | + $reply = $this->send_cmd("DELE $msgNum"); |
|
| 597 | + if(!$this->is_ok($reply)) |
|
| 598 | + { |
|
| 599 | + $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 600 | + return false; |
|
| 601 | + } |
|
| 602 | + return true; |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // ********************************************************* |
|
| 606 | + |
|
| 607 | + // The following methods are internal to the class. |
|
| 608 | + |
|
| 609 | + function is_ok ($cmd = "") { |
|
| 610 | + // Return true or false on +OK or -ERR |
|
| 611 | + |
|
| 612 | + if( empty($cmd) ) |
|
| 613 | + return false; |
|
| 614 | + else |
|
| 615 | + return( stripos($cmd, '+OK') !== false ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + function strip_clf ($text = "") { |
|
| 619 | + // Strips \r\n from server responses |
|
| 620 | + |
|
| 621 | + if(empty($text)) |
|
| 622 | + return $text; |
|
| 623 | + else { |
|
| 624 | + $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 625 | + return $stripped; |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + function parse_banner ( $server_text ) { |
|
| 630 | + $outside = true; |
|
| 631 | + $banner = ""; |
|
| 632 | + $length = strlen($server_text); |
|
| 633 | + for($count =0; $count < $length; $count++) |
|
| 634 | + { |
|
| 635 | + $digit = substr($server_text,$count,1); |
|
| 636 | + if(!empty($digit)) { |
|
| 637 | + if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 638 | + { |
|
| 639 | + $banner .= $digit; |
|
| 640 | + } |
|
| 641 | + if ($digit == '<') |
|
| 642 | + { |
|
| 643 | + $outside = false; |
|
| 644 | + } |
|
| 645 | + if($digit == '>') |
|
| 646 | + { |
|
| 647 | + $outside = true; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | + return "<$banner>"; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | 655 | } // End class |
| 656 | 656 | |
| 657 | 657 | // For php4 compatibility |
| 658 | 658 | if (!function_exists("stripos")) { |
| 659 | - function stripos($haystack, $needle){ |
|
| 660 | - return strpos($haystack, stristr( $haystack, $needle )); |
|
| 661 | - } |
|
| 659 | + function stripos($haystack, $needle){ |
|
| 660 | + return strpos($haystack, stristr( $haystack, $needle )); |
|
| 661 | + } |
|
| 662 | 662 | } |
@@ -17,49 +17,49 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | class POP3 { |
| 20 | - var $ERROR = ''; // Error string. |
|
| 20 | + var $ERROR = ''; // Error string. |
|
| 21 | 21 | |
| 22 | - var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 22 | + var $TIMEOUT = 60; // Default timeout before giving up on a |
|
| 23 | 23 | // network operation. |
| 24 | 24 | |
| 25 | - var $COUNT = -1; // Mailbox msg count |
|
| 25 | + var $COUNT = -1; // Mailbox msg count |
|
| 26 | 26 | |
| 27 | - var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 27 | + var $BUFFER = 512; // Socket buffer for socket fgets() calls. |
|
| 28 | 28 | // Per RFC 1939 the returned line a POP3 |
| 29 | 29 | // server can send is 512 bytes. |
| 30 | 30 | |
| 31 | - var $FP = ''; // The connection to the server's |
|
| 31 | + var $FP = ''; // The connection to the server's |
|
| 32 | 32 | // file descriptor |
| 33 | 33 | |
| 34 | - var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 34 | + var $MAILSERVER = ''; // Set this to hard code the server name |
|
| 35 | 35 | |
| 36 | - var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 36 | + var $DEBUG = FALSE; // set to true to echo pop3 |
|
| 37 | 37 | // commands and responses to error_log |
| 38 | 38 | // this WILL log passwords! |
| 39 | 39 | |
| 40 | - var $BANNER = ''; // Holds the banner returned by the |
|
| 40 | + var $BANNER = ''; // Holds the banner returned by the |
|
| 41 | 41 | // pop server - used for apop() |
| 42 | 42 | |
| 43 | - var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 43 | + var $ALLOWAPOP = FALSE; // Allow or disallow apop() |
|
| 44 | 44 | // This must be set to true |
| 45 | 45 | // manually |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * PHP5 constructor. |
| 49 | 49 | */ |
| 50 | - function __construct ( $server = '', $timeout = '' ) { |
|
| 51 | - settype($this->BUFFER,"integer"); |
|
| 52 | - if( !empty($server) ) { |
|
| 50 | + function __construct($server = '', $timeout = '') { |
|
| 51 | + settype($this->BUFFER, "integer"); |
|
| 52 | + if ( ! empty($server)) { |
|
| 53 | 53 | // Do not allow programs to alter MAILSERVER |
| 54 | 54 | // if it is already specified. They can get around |
| 55 | 55 | // this if they -really- want to, so don't count on it. |
| 56 | - if(empty($this->MAILSERVER)) |
|
| 56 | + if (empty($this->MAILSERVER)) |
|
| 57 | 57 | $this->MAILSERVER = $server; |
| 58 | 58 | } |
| 59 | - if(!empty($timeout)) { |
|
| 60 | - settype($timeout,"integer"); |
|
| 59 | + if ( ! empty($timeout)) { |
|
| 60 | + settype($timeout, "integer"); |
|
| 61 | 61 | $this->TIMEOUT = $timeout; |
| 62 | - if (!ini_get('safe_mode')) |
|
| 62 | + if ( ! ini_get('safe_mode')) |
|
| 63 | 63 | set_time_limit($timeout); |
| 64 | 64 | } |
| 65 | 65 | return true; |
@@ -68,48 +68,48 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * PHP4 constructor. |
| 70 | 70 | */ |
| 71 | - public function POP3( $server = '', $timeout = '' ) { |
|
| 72 | - self::__construct( $server, $timeout ); |
|
| 71 | + public function POP3($server = '', $timeout = '') { |
|
| 72 | + self::__construct($server, $timeout); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - function update_timer () { |
|
| 76 | - if (!ini_get('safe_mode')) |
|
| 75 | + function update_timer() { |
|
| 76 | + if ( ! ini_get('safe_mode')) |
|
| 77 | 77 | set_time_limit($this->TIMEOUT); |
| 78 | 78 | return true; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - function connect ($server, $port = 110) { |
|
| 81 | + function connect($server, $port = 110) { |
|
| 82 | 82 | // Opens a socket to the specified server. Unless overridden, |
| 83 | 83 | // port defaults to 110. Returns true on success, false on fail |
| 84 | 84 | |
| 85 | 85 | // If MAILSERVER is set, override $server with its value. |
| 86 | 86 | |
| 87 | - if (!isset($port) || !$port) {$port = 110;} |
|
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 87 | + if ( ! isset($port) || ! $port) {$port = 110; } |
|
| 88 | + if ( ! empty($this->MAILSERVER)) |
|
| 89 | 89 | $server = $this->MAILSERVER; |
| 90 | 90 | |
| 91 | - if(empty($server)){ |
|
| 92 | - $this->ERROR = "POP3 connect: " . _("No server specified"); |
|
| 91 | + if (empty($server)) { |
|
| 92 | + $this->ERROR = "POP3 connect: "._("No server specified"); |
|
| 93 | 93 | unset($this->FP); |
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $fp = @fsockopen("$server", $port, $errno, $errstr); |
| 98 | 98 | |
| 99 | - if(!$fp) { |
|
| 100 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$errno] [$errstr]"; |
|
| 99 | + if ( ! $fp) { |
|
| 100 | + $this->ERROR = "POP3 connect: "._("Error ")."[$errno] [$errstr]"; |
|
| 101 | 101 | unset($this->FP); |
| 102 | 102 | return false; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - socket_set_blocking($fp,-1); |
|
| 105 | + socket_set_blocking($fp, -1); |
|
| 106 | 106 | $this->update_timer(); |
| 107 | - $reply = fgets($fp,$this->BUFFER); |
|
| 107 | + $reply = fgets($fp, $this->BUFFER); |
|
| 108 | 108 | $reply = $this->strip_clf($reply); |
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 111 | - if(!$this->is_ok($reply)) { |
|
| 112 | - $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
|
| 109 | + if ($this->DEBUG) |
|
| 110 | + error_log("POP3 SEND [connect: $server] GOT [$reply]", 0); |
|
| 111 | + if ( ! $this->is_ok($reply)) { |
|
| 112 | + $this->ERROR = "POP3 connect: "._("Error ")."[$reply]"; |
|
| 113 | 113 | unset($this->FP); |
| 114 | 114 | return false; |
| 115 | 115 | } |
@@ -118,39 +118,39 @@ discard block |
||
| 118 | 118 | return true; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - function user ($user = "") { |
|
| 121 | + function user($user = "") { |
|
| 122 | 122 | // Sends the USER command, returns true or false |
| 123 | 123 | |
| 124 | - if( empty($user) ) { |
|
| 125 | - $this->ERROR = "POP3 user: " . _("no login ID submitted"); |
|
| 124 | + if (empty($user)) { |
|
| 125 | + $this->ERROR = "POP3 user: "._("no login ID submitted"); |
|
| 126 | 126 | return false; |
| 127 | - } elseif(!isset($this->FP)) { |
|
| 128 | - $this->ERROR = "POP3 user: " . _("connection not established"); |
|
| 127 | + } elseif ( ! isset($this->FP)) { |
|
| 128 | + $this->ERROR = "POP3 user: "._("connection not established"); |
|
| 129 | 129 | return false; |
| 130 | 130 | } else { |
| 131 | 131 | $reply = $this->send_cmd("USER $user"); |
| 132 | - if(!$this->is_ok($reply)) { |
|
| 133 | - $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
|
| 132 | + if ( ! $this->is_ok($reply)) { |
|
| 133 | + $this->ERROR = "POP3 user: "._("Error ")."[$reply]"; |
|
| 134 | 134 | return false; |
| 135 | 135 | } else |
| 136 | 136 | return true; |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - function pass ($pass = "") { |
|
| 140 | + function pass($pass = "") { |
|
| 141 | 141 | // Sends the PASS command, returns # of msgs in mailbox, |
| 142 | 142 | // returns false (undef) on Auth failure |
| 143 | 143 | |
| 144 | - if(empty($pass)) { |
|
| 145 | - $this->ERROR = "POP3 pass: " . _("No password submitted"); |
|
| 144 | + if (empty($pass)) { |
|
| 145 | + $this->ERROR = "POP3 pass: "._("No password submitted"); |
|
| 146 | 146 | return false; |
| 147 | - } elseif(!isset($this->FP)) { |
|
| 148 | - $this->ERROR = "POP3 pass: " . _("connection not established"); |
|
| 147 | + } elseif ( ! isset($this->FP)) { |
|
| 148 | + $this->ERROR = "POP3 pass: "._("connection not established"); |
|
| 149 | 149 | return false; |
| 150 | 150 | } else { |
| 151 | 151 | $reply = $this->send_cmd("PASS $pass"); |
| 152 | - if(!$this->is_ok($reply)) { |
|
| 153 | - $this->ERROR = "POP3 pass: " . _("Authentication failed") . " [$reply]"; |
|
| 152 | + if ( ! $this->is_ok($reply)) { |
|
| 153 | + $this->ERROR = "POP3 pass: "._("Authentication failed")." [$reply]"; |
|
| 154 | 154 | $this->quit(); |
| 155 | 155 | return false; |
| 156 | 156 | } else { |
@@ -162,29 +162,29 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - function apop ($login,$pass) { |
|
| 165 | + function apop($login, $pass) { |
|
| 166 | 166 | // Attempts an APOP login. If this fails, it'll |
| 167 | 167 | // try a standard login. YOUR SERVER MUST SUPPORT |
| 168 | 168 | // THE USE OF THE APOP COMMAND! |
| 169 | 169 | // (apop is optional per rfc1939) |
| 170 | 170 | |
| 171 | - if(!isset($this->FP)) { |
|
| 172 | - $this->ERROR = "POP3 apop: " . _("No connection to server"); |
|
| 171 | + if ( ! isset($this->FP)) { |
|
| 172 | + $this->ERROR = "POP3 apop: "._("No connection to server"); |
|
| 173 | 173 | return false; |
| 174 | - } elseif(!$this->ALLOWAPOP) { |
|
| 175 | - $retVal = $this->login($login,$pass); |
|
| 174 | + } elseif ( ! $this->ALLOWAPOP) { |
|
| 175 | + $retVal = $this->login($login, $pass); |
|
| 176 | 176 | return $retVal; |
| 177 | - } elseif(empty($login)) { |
|
| 178 | - $this->ERROR = "POP3 apop: " . _("No login ID submitted"); |
|
| 177 | + } elseif (empty($login)) { |
|
| 178 | + $this->ERROR = "POP3 apop: "._("No login ID submitted"); |
|
| 179 | 179 | return false; |
| 180 | - } elseif(empty($pass)) { |
|
| 181 | - $this->ERROR = "POP3 apop: " . _("No password submitted"); |
|
| 180 | + } elseif (empty($pass)) { |
|
| 181 | + $this->ERROR = "POP3 apop: "._("No password submitted"); |
|
| 182 | 182 | return false; |
| 183 | 183 | } else { |
| 184 | 184 | $banner = $this->BANNER; |
| 185 | - if( (!$banner) or (empty($banner)) ) { |
|
| 186 | - $this->ERROR = "POP3 apop: " . _("No server banner") . ' - ' . _("abort"); |
|
| 187 | - $retVal = $this->login($login,$pass); |
|
| 185 | + if (( ! $banner) or (empty($banner))) { |
|
| 186 | + $this->ERROR = "POP3 apop: "._("No server banner").' - '._("abort"); |
|
| 187 | + $retVal = $this->login($login, $pass); |
|
| 188 | 188 | return $retVal; |
| 189 | 189 | } else { |
| 190 | 190 | $AuthString = $banner; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | $APOPString = md5($AuthString); |
| 193 | 193 | $cmd = "APOP $login $APOPString"; |
| 194 | 194 | $reply = $this->send_cmd($cmd); |
| 195 | - if(!$this->is_ok($reply)) { |
|
| 196 | - $this->ERROR = "POP3 apop: " . _("apop authentication failed") . ' - ' . _("abort"); |
|
| 197 | - $retVal = $this->login($login,$pass); |
|
| 195 | + if ( ! $this->is_ok($reply)) { |
|
| 196 | + $this->ERROR = "POP3 apop: "._("apop authentication failed").' - '._("abort"); |
|
| 197 | + $retVal = $this->login($login, $pass); |
|
| 198 | 198 | return $retVal; |
| 199 | 199 | } else { |
| 200 | 200 | // Auth successful. |
@@ -206,22 +206,22 @@ discard block |
||
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - function login ($login = "", $pass = "") { |
|
| 209 | + function login($login = "", $pass = "") { |
|
| 210 | 210 | // Sends both user and pass. Returns # of msgs in mailbox or |
| 211 | 211 | // false on failure (or -1, if the error occurs while getting |
| 212 | 212 | // the number of messages.) |
| 213 | 213 | |
| 214 | - if( !isset($this->FP) ) { |
|
| 215 | - $this->ERROR = "POP3 login: " . _("No connection to server"); |
|
| 214 | + if ( ! isset($this->FP)) { |
|
| 215 | + $this->ERROR = "POP3 login: "._("No connection to server"); |
|
| 216 | 216 | return false; |
| 217 | 217 | } else { |
| 218 | 218 | $fp = $this->FP; |
| 219 | - if( !$this->user( $login ) ) { |
|
| 219 | + if ( ! $this->user($login)) { |
|
| 220 | 220 | // Preserve the error generated by user() |
| 221 | 221 | return false; |
| 222 | 222 | } else { |
| 223 | 223 | $count = $this->pass($pass); |
| 224 | - if( (!$count) || ($count == -1) ) { |
|
| 224 | + if (( ! $count) || ($count == -1)) { |
|
| 225 | 225 | // Preserve the error generated by last() and pass() |
| 226 | 226 | return false; |
| 227 | 227 | } else |
@@ -230,14 +230,14 @@ discard block |
||
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - function top ($msgNum, $numLines = "0") { |
|
| 233 | + function top($msgNum, $numLines = "0") { |
|
| 234 | 234 | // Gets the header and first $numLines of the msg body |
| 235 | 235 | // returns data in an array with each returned line being |
| 236 | 236 | // an array element. If $numLines is empty, returns |
| 237 | 237 | // only the header information, and none of the body. |
| 238 | 238 | |
| 239 | - if(!isset($this->FP)) { |
|
| 240 | - $this->ERROR = "POP3 top: " . _("No connection to server"); |
|
| 239 | + if ( ! isset($this->FP)) { |
|
| 240 | + $this->ERROR = "POP3 top: "._("No connection to server"); |
|
| 241 | 241 | return false; |
| 242 | 242 | } |
| 243 | 243 | $this->update_timer(); |
@@ -248,94 +248,94 @@ discard block |
||
| 248 | 248 | fwrite($fp, "TOP $msgNum $numLines\r\n"); |
| 249 | 249 | $reply = fgets($fp, $buffer); |
| 250 | 250 | $reply = $this->strip_clf($reply); |
| 251 | - if($this->DEBUG) { |
|
| 252 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 251 | + if ($this->DEBUG) { |
|
| 252 | + @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); |
|
| 253 | 253 | } |
| 254 | - if(!$this->is_ok($reply)) |
|
| 254 | + if ( ! $this->is_ok($reply)) |
|
| 255 | 255 | { |
| 256 | - $this->ERROR = "POP3 top: " . _("Error ") . "[$reply]"; |
|
| 256 | + $this->ERROR = "POP3 top: "._("Error ")."[$reply]"; |
|
| 257 | 257 | return false; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $count = 0; |
| 261 | 261 | $MsgArray = array(); |
| 262 | 262 | |
| 263 | - $line = fgets($fp,$buffer); |
|
| 264 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 263 | + $line = fgets($fp, $buffer); |
|
| 264 | + while ( ! preg_match('/^\.\r\n/', $line)) |
|
| 265 | 265 | { |
| 266 | 266 | $MsgArray[$count] = $line; |
| 267 | 267 | $count++; |
| 268 | - $line = fgets($fp,$buffer); |
|
| 269 | - if(empty($line)) { break; } |
|
| 268 | + $line = fgets($fp, $buffer); |
|
| 269 | + if (empty($line)) { break; } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | return $MsgArray; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - function pop_list ($msgNum = "") { |
|
| 275 | + function pop_list($msgNum = "") { |
|
| 276 | 276 | // If called with an argument, returns that msgs' size in octets |
| 277 | 277 | // No argument returns an associative array of undeleted |
| 278 | 278 | // msg numbers and their sizes in octets |
| 279 | 279 | |
| 280 | - if(!isset($this->FP)) |
|
| 280 | + if ( ! isset($this->FP)) |
|
| 281 | 281 | { |
| 282 | - $this->ERROR = "POP3 pop_list: " . _("No connection to server"); |
|
| 282 | + $this->ERROR = "POP3 pop_list: "._("No connection to server"); |
|
| 283 | 283 | return false; |
| 284 | 284 | } |
| 285 | 285 | $fp = $this->FP; |
| 286 | 286 | $Total = $this->COUNT; |
| 287 | - if( (!$Total) or ($Total == -1) ) |
|
| 287 | + if (( ! $Total) or ($Total == -1)) |
|
| 288 | 288 | { |
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | - if($Total == 0) |
|
| 291 | + if ($Total == 0) |
|
| 292 | 292 | { |
| 293 | - return array("0","0"); |
|
| 293 | + return array("0", "0"); |
|
| 294 | 294 | // return -1; // mailbox empty |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | $this->update_timer(); |
| 298 | 298 | |
| 299 | - if(!empty($msgNum)) |
|
| 299 | + if ( ! empty($msgNum)) |
|
| 300 | 300 | { |
| 301 | 301 | $cmd = "LIST $msgNum"; |
| 302 | - fwrite($fp,"$cmd\r\n"); |
|
| 303 | - $reply = fgets($fp,$this->BUFFER); |
|
| 302 | + fwrite($fp, "$cmd\r\n"); |
|
| 303 | + $reply = fgets($fp, $this->BUFFER); |
|
| 304 | 304 | $reply = $this->strip_clf($reply); |
| 305 | - if($this->DEBUG) { |
|
| 306 | - @error_log("POP3 SEND [$cmd] GOT [$reply]",0); |
|
| 305 | + if ($this->DEBUG) { |
|
| 306 | + @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); |
|
| 307 | 307 | } |
| 308 | - if(!$this->is_ok($reply)) |
|
| 308 | + if ( ! $this->is_ok($reply)) |
|
| 309 | 309 | { |
| 310 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 310 | + $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]"; |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | - list($junk,$num,$size) = preg_split('/\s+/',$reply); |
|
| 313 | + list($junk, $num, $size) = preg_split('/\s+/', $reply); |
|
| 314 | 314 | return $size; |
| 315 | 315 | } |
| 316 | 316 | $cmd = "LIST"; |
| 317 | 317 | $reply = $this->send_cmd($cmd); |
| 318 | - if(!$this->is_ok($reply)) |
|
| 318 | + if ( ! $this->is_ok($reply)) |
|
| 319 | 319 | { |
| 320 | 320 | $reply = $this->strip_clf($reply); |
| 321 | - $this->ERROR = "POP3 pop_list: " . _("Error ") . "[$reply]"; |
|
| 321 | + $this->ERROR = "POP3 pop_list: "._("Error ")."[$reply]"; |
|
| 322 | 322 | return false; |
| 323 | 323 | } |
| 324 | 324 | $MsgArray = array(); |
| 325 | 325 | $MsgArray[0] = $Total; |
| 326 | - for($msgC=1;$msgC <= $Total; $msgC++) |
|
| 326 | + for ($msgC = 1; $msgC <= $Total; $msgC++) |
|
| 327 | 327 | { |
| 328 | - if($msgC > $Total) { break; } |
|
| 329 | - $line = fgets($fp,$this->BUFFER); |
|
| 328 | + if ($msgC > $Total) { break; } |
|
| 329 | + $line = fgets($fp, $this->BUFFER); |
|
| 330 | 330 | $line = $this->strip_clf($line); |
| 331 | - if(strpos($line, '.') === 0) |
|
| 331 | + if (strpos($line, '.') === 0) |
|
| 332 | 332 | { |
| 333 | - $this->ERROR = "POP3 pop_list: " . _("Premature end of list"); |
|
| 333 | + $this->ERROR = "POP3 pop_list: "._("Premature end of list"); |
|
| 334 | 334 | return false; |
| 335 | 335 | } |
| 336 | - list($thisMsg,$msgSize) = preg_split('/\s+/',$line); |
|
| 337 | - settype($thisMsg,"integer"); |
|
| 338 | - if($thisMsg != $msgC) |
|
| 336 | + list($thisMsg, $msgSize) = preg_split('/\s+/', $line); |
|
| 337 | + settype($thisMsg, "integer"); |
|
| 338 | + if ($thisMsg != $msgC) |
|
| 339 | 339 | { |
| 340 | 340 | $MsgArray[$msgC] = "deleted"; |
| 341 | 341 | } |
@@ -347,13 +347,13 @@ discard block |
||
| 347 | 347 | return $MsgArray; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - function get ($msgNum) { |
|
| 350 | + function get($msgNum) { |
|
| 351 | 351 | // Retrieve the specified msg number. Returns an array |
| 352 | 352 | // where each line of the msg is an array element. |
| 353 | 353 | |
| 354 | - if(!isset($this->FP)) |
|
| 354 | + if ( ! isset($this->FP)) |
|
| 355 | 355 | { |
| 356 | - $this->ERROR = "POP3 get: " . _("No connection to server"); |
|
| 356 | + $this->ERROR = "POP3 get: "._("No connection to server"); |
|
| 357 | 357 | return false; |
| 358 | 358 | } |
| 359 | 359 | |
@@ -364,83 +364,83 @@ discard block |
||
| 364 | 364 | $cmd = "RETR $msgNum"; |
| 365 | 365 | $reply = $this->send_cmd($cmd); |
| 366 | 366 | |
| 367 | - if(!$this->is_ok($reply)) |
|
| 367 | + if ( ! $this->is_ok($reply)) |
|
| 368 | 368 | { |
| 369 | - $this->ERROR = "POP3 get: " . _("Error ") . "[$reply]"; |
|
| 369 | + $this->ERROR = "POP3 get: "._("Error ")."[$reply]"; |
|
| 370 | 370 | return false; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $count = 0; |
| 374 | 374 | $MsgArray = array(); |
| 375 | 375 | |
| 376 | - $line = fgets($fp,$buffer); |
|
| 377 | - while ( !preg_match('/^\.\r\n/',$line)) |
|
| 376 | + $line = fgets($fp, $buffer); |
|
| 377 | + while ( ! preg_match('/^\.\r\n/', $line)) |
|
| 378 | 378 | { |
| 379 | - if ( $line{0} == '.' ) { $line = substr($line,1); } |
|
| 379 | + if ($line{0} == '.') { $line = substr($line, 1); } |
|
| 380 | 380 | $MsgArray[$count] = $line; |
| 381 | 381 | $count++; |
| 382 | - $line = fgets($fp,$buffer); |
|
| 383 | - if(empty($line)) { break; } |
|
| 382 | + $line = fgets($fp, $buffer); |
|
| 383 | + if (empty($line)) { break; } |
|
| 384 | 384 | } |
| 385 | 385 | return $MsgArray; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - function last ( $type = "count" ) { |
|
| 388 | + function last($type = "count") { |
|
| 389 | 389 | // Returns the highest msg number in the mailbox. |
| 390 | 390 | // returns -1 on error, 0+ on success, if type != count |
| 391 | 391 | // results in a popstat() call (2 element array returned) |
| 392 | 392 | |
| 393 | 393 | $last = -1; |
| 394 | - if(!isset($this->FP)) |
|
| 394 | + if ( ! isset($this->FP)) |
|
| 395 | 395 | { |
| 396 | - $this->ERROR = "POP3 last: " . _("No connection to server"); |
|
| 396 | + $this->ERROR = "POP3 last: "._("No connection to server"); |
|
| 397 | 397 | return $last; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | $reply = $this->send_cmd("STAT"); |
| 401 | - if(!$this->is_ok($reply)) |
|
| 401 | + if ( ! $this->is_ok($reply)) |
|
| 402 | 402 | { |
| 403 | - $this->ERROR = "POP3 last: " . _("Error ") . "[$reply]"; |
|
| 403 | + $this->ERROR = "POP3 last: "._("Error ")."[$reply]"; |
|
| 404 | 404 | return $last; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - $Vars = preg_split('/\s+/',$reply); |
|
| 407 | + $Vars = preg_split('/\s+/', $reply); |
|
| 408 | 408 | $count = $Vars[1]; |
| 409 | 409 | $size = $Vars[2]; |
| 410 | - settype($count,"integer"); |
|
| 411 | - settype($size,"integer"); |
|
| 412 | - if($type != "count") |
|
| 410 | + settype($count, "integer"); |
|
| 411 | + settype($size, "integer"); |
|
| 412 | + if ($type != "count") |
|
| 413 | 413 | { |
| 414 | - return array($count,$size); |
|
| 414 | + return array($count, $size); |
|
| 415 | 415 | } |
| 416 | 416 | return $count; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - function reset () { |
|
| 419 | + function reset() { |
|
| 420 | 420 | // Resets the status of the remote server. This includes |
| 421 | 421 | // resetting the status of ALL msgs to not be deleted. |
| 422 | 422 | // This method automatically closes the connection to the server. |
| 423 | 423 | |
| 424 | - if(!isset($this->FP)) |
|
| 424 | + if ( ! isset($this->FP)) |
|
| 425 | 425 | { |
| 426 | - $this->ERROR = "POP3 reset: " . _("No connection to server"); |
|
| 426 | + $this->ERROR = "POP3 reset: "._("No connection to server"); |
|
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | $reply = $this->send_cmd("RSET"); |
| 430 | - if(!$this->is_ok($reply)) |
|
| 430 | + if ( ! $this->is_ok($reply)) |
|
| 431 | 431 | { |
| 432 | 432 | // The POP3 RSET command -never- gives a -ERR |
| 433 | 433 | // response - if it ever does, something truly |
| 434 | 434 | // wild is going on. |
| 435 | 435 | |
| 436 | - $this->ERROR = "POP3 reset: " . _("Error ") . "[$reply]"; |
|
| 437 | - @error_log("POP3 reset: ERROR [$reply]",0); |
|
| 436 | + $this->ERROR = "POP3 reset: "._("Error ")."[$reply]"; |
|
| 437 | + @error_log("POP3 reset: ERROR [$reply]", 0); |
|
| 438 | 438 | } |
| 439 | 439 | $this->quit(); |
| 440 | 440 | return true; |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - function send_cmd ( $cmd = "" ) |
|
| 443 | + function send_cmd($cmd = "") |
|
| 444 | 444 | { |
| 445 | 445 | // Sends a user defined command string to the |
| 446 | 446 | // POP server and returns the results. Useful for |
@@ -455,25 +455,25 @@ discard block |
||
| 455 | 455 | // This method works best if $cmd responds with only |
| 456 | 456 | // one line of data. |
| 457 | 457 | |
| 458 | - if(!isset($this->FP)) |
|
| 458 | + if ( ! isset($this->FP)) |
|
| 459 | 459 | { |
| 460 | - $this->ERROR = "POP3 send_cmd: " . _("No connection to server"); |
|
| 460 | + $this->ERROR = "POP3 send_cmd: "._("No connection to server"); |
|
| 461 | 461 | return false; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if(empty($cmd)) |
|
| 464 | + if (empty($cmd)) |
|
| 465 | 465 | { |
| 466 | - $this->ERROR = "POP3 send_cmd: " . _("Empty command string"); |
|
| 466 | + $this->ERROR = "POP3 send_cmd: "._("Empty command string"); |
|
| 467 | 467 | return ""; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | $fp = $this->FP; |
| 471 | 471 | $buffer = $this->BUFFER; |
| 472 | 472 | $this->update_timer(); |
| 473 | - fwrite($fp,"$cmd\r\n"); |
|
| 474 | - $reply = fgets($fp,$buffer); |
|
| 473 | + fwrite($fp, "$cmd\r\n"); |
|
| 474 | + $reply = fgets($fp, $buffer); |
|
| 475 | 475 | $reply = $this->strip_clf($reply); |
| 476 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 476 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 477 | 477 | return $reply; |
| 478 | 478 | } |
| 479 | 479 | |
@@ -481,61 +481,61 @@ discard block |
||
| 481 | 481 | // Closes the connection to the POP3 server, deleting |
| 482 | 482 | // any msgs marked as deleted. |
| 483 | 483 | |
| 484 | - if(!isset($this->FP)) |
|
| 484 | + if ( ! isset($this->FP)) |
|
| 485 | 485 | { |
| 486 | - $this->ERROR = "POP3 quit: " . _("connection does not exist"); |
|
| 486 | + $this->ERROR = "POP3 quit: "._("connection does not exist"); |
|
| 487 | 487 | return false; |
| 488 | 488 | } |
| 489 | 489 | $fp = $this->FP; |
| 490 | 490 | $cmd = "QUIT"; |
| 491 | - fwrite($fp,"$cmd\r\n"); |
|
| 492 | - $reply = fgets($fp,$this->BUFFER); |
|
| 491 | + fwrite($fp, "$cmd\r\n"); |
|
| 492 | + $reply = fgets($fp, $this->BUFFER); |
|
| 493 | 493 | $reply = $this->strip_clf($reply); |
| 494 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 494 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 495 | 495 | fclose($fp); |
| 496 | 496 | unset($this->FP); |
| 497 | 497 | return true; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - function popstat () { |
|
| 500 | + function popstat() { |
|
| 501 | 501 | // Returns an array of 2 elements. The number of undeleted |
| 502 | 502 | // msgs in the mailbox, and the size of the mbox in octets. |
| 503 | 503 | |
| 504 | 504 | $PopArray = $this->last("array"); |
| 505 | 505 | |
| 506 | - if($PopArray == -1) { return false; } |
|
| 506 | + if ($PopArray == -1) { return false; } |
|
| 507 | 507 | |
| 508 | - if( (!$PopArray) or (empty($PopArray)) ) |
|
| 508 | + if (( ! $PopArray) or (empty($PopArray))) |
|
| 509 | 509 | { |
| 510 | 510 | return false; |
| 511 | 511 | } |
| 512 | 512 | return $PopArray; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - function uidl ($msgNum = "") |
|
| 515 | + function uidl($msgNum = "") |
|
| 516 | 516 | { |
| 517 | 517 | // Returns the UIDL of the msg specified. If called with |
| 518 | 518 | // no arguments, returns an associative array where each |
| 519 | 519 | // undeleted msg num is a key, and the msg's uidl is the element |
| 520 | 520 | // Array element 0 will contain the total number of msgs |
| 521 | 521 | |
| 522 | - if(!isset($this->FP)) { |
|
| 523 | - $this->ERROR = "POP3 uidl: " . _("No connection to server"); |
|
| 522 | + if ( ! isset($this->FP)) { |
|
| 523 | + $this->ERROR = "POP3 uidl: "._("No connection to server"); |
|
| 524 | 524 | return false; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | $fp = $this->FP; |
| 528 | 528 | $buffer = $this->BUFFER; |
| 529 | 529 | |
| 530 | - if(!empty($msgNum)) { |
|
| 530 | + if ( ! empty($msgNum)) { |
|
| 531 | 531 | $cmd = "UIDL $msgNum"; |
| 532 | 532 | $reply = $this->send_cmd($cmd); |
| 533 | - if(!$this->is_ok($reply)) |
|
| 533 | + if ( ! $this->is_ok($reply)) |
|
| 534 | 534 | { |
| 535 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 535 | + $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]"; |
|
| 536 | 536 | return false; |
| 537 | 537 | } |
| 538 | - list ($ok,$num,$myUidl) = preg_split('/\s+/',$reply); |
|
| 538 | + list ($ok, $num, $myUidl) = preg_split('/\s+/', $reply); |
|
| 539 | 539 | return $myUidl; |
| 540 | 540 | } else { |
| 541 | 541 | $this->update_timer(); |
@@ -552,20 +552,20 @@ discard block |
||
| 552 | 552 | fwrite($fp, "UIDL\r\n"); |
| 553 | 553 | $reply = fgets($fp, $buffer); |
| 554 | 554 | $reply = $this->strip_clf($reply); |
| 555 | - if($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]",0); } |
|
| 556 | - if(!$this->is_ok($reply)) |
|
| 555 | + if ($this->DEBUG) { @error_log("POP3 SEND [$cmd] GOT [$reply]", 0); } |
|
| 556 | + if ( ! $this->is_ok($reply)) |
|
| 557 | 557 | { |
| 558 | - $this->ERROR = "POP3 uidl: " . _("Error ") . "[$reply]"; |
|
| 558 | + $this->ERROR = "POP3 uidl: "._("Error ")."[$reply]"; |
|
| 559 | 559 | return false; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $line = ""; |
| 563 | 563 | $count = 1; |
| 564 | - $line = fgets($fp,$buffer); |
|
| 565 | - while ( !preg_match('/^\.\r\n/',$line)) { |
|
| 566 | - list ($msg,$msgUidl) = preg_split('/\s+/',$line); |
|
| 564 | + $line = fgets($fp, $buffer); |
|
| 565 | + while ( ! preg_match('/^\.\r\n/', $line)) { |
|
| 566 | + list ($msg, $msgUidl) = preg_split('/\s+/', $line); |
|
| 567 | 567 | $msgUidl = $this->strip_clf($msgUidl); |
| 568 | - if($count == $msg) { |
|
| 568 | + if ($count == $msg) { |
|
| 569 | 569 | $UIDLArray[$msg] = $msgUidl; |
| 570 | 570 | } |
| 571 | 571 | else |
@@ -573,30 +573,30 @@ discard block |
||
| 573 | 573 | $UIDLArray[$count] = 'deleted'; |
| 574 | 574 | } |
| 575 | 575 | $count++; |
| 576 | - $line = fgets($fp,$buffer); |
|
| 576 | + $line = fgets($fp, $buffer); |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | return $UIDLArray; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - function delete ($msgNum = "") { |
|
| 582 | + function delete($msgNum = "") { |
|
| 583 | 583 | // Flags a specified msg as deleted. The msg will not |
| 584 | 584 | // be deleted until a quit() method is called. |
| 585 | 585 | |
| 586 | - if(!isset($this->FP)) |
|
| 586 | + if ( ! isset($this->FP)) |
|
| 587 | 587 | { |
| 588 | - $this->ERROR = "POP3 delete: " . _("No connection to server"); |
|
| 588 | + $this->ERROR = "POP3 delete: "._("No connection to server"); |
|
| 589 | 589 | return false; |
| 590 | 590 | } |
| 591 | - if(empty($msgNum)) |
|
| 591 | + if (empty($msgNum)) |
|
| 592 | 592 | { |
| 593 | - $this->ERROR = "POP3 delete: " . _("No msg number submitted"); |
|
| 593 | + $this->ERROR = "POP3 delete: "._("No msg number submitted"); |
|
| 594 | 594 | return false; |
| 595 | 595 | } |
| 596 | 596 | $reply = $this->send_cmd("DELE $msgNum"); |
| 597 | - if(!$this->is_ok($reply)) |
|
| 597 | + if ( ! $this->is_ok($reply)) |
|
| 598 | 598 | { |
| 599 | - $this->ERROR = "POP3 delete: " . _("Command failed ") . "[$reply]"; |
|
| 599 | + $this->ERROR = "POP3 delete: "._("Command failed ")."[$reply]"; |
|
| 600 | 600 | return false; |
| 601 | 601 | } |
| 602 | 602 | return true; |
@@ -606,35 +606,35 @@ discard block |
||
| 606 | 606 | |
| 607 | 607 | // The following methods are internal to the class. |
| 608 | 608 | |
| 609 | - function is_ok ($cmd = "") { |
|
| 609 | + function is_ok($cmd = "") { |
|
| 610 | 610 | // Return true or false on +OK or -ERR |
| 611 | 611 | |
| 612 | - if( empty($cmd) ) |
|
| 612 | + if (empty($cmd)) |
|
| 613 | 613 | return false; |
| 614 | 614 | else |
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 615 | + return(stripos($cmd, '+OK') !== false); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - function strip_clf ($text = "") { |
|
| 618 | + function strip_clf($text = "") { |
|
| 619 | 619 | // Strips \r\n from server responses |
| 620 | 620 | |
| 621 | - if(empty($text)) |
|
| 621 | + if (empty($text)) |
|
| 622 | 622 | return $text; |
| 623 | 623 | else { |
| 624 | - $stripped = str_replace(array("\r","\n"),'',$text); |
|
| 624 | + $stripped = str_replace(array("\r", "\n"), '', $text); |
|
| 625 | 625 | return $stripped; |
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | - function parse_banner ( $server_text ) { |
|
| 629 | + function parse_banner($server_text) { |
|
| 630 | 630 | $outside = true; |
| 631 | 631 | $banner = ""; |
| 632 | 632 | $length = strlen($server_text); |
| 633 | - for($count =0; $count < $length; $count++) |
|
| 633 | + for ($count = 0; $count < $length; $count++) |
|
| 634 | 634 | { |
| 635 | - $digit = substr($server_text,$count,1); |
|
| 636 | - if(!empty($digit)) { |
|
| 637 | - if( (!$outside) && ($digit != '<') && ($digit != '>') ) |
|
| 635 | + $digit = substr($server_text, $count, 1); |
|
| 636 | + if ( ! empty($digit)) { |
|
| 637 | + if (( ! $outside) && ($digit != '<') && ($digit != '>')) |
|
| 638 | 638 | { |
| 639 | 639 | $banner .= $digit; |
| 640 | 640 | } |
@@ -642,21 +642,21 @@ discard block |
||
| 642 | 642 | { |
| 643 | 643 | $outside = false; |
| 644 | 644 | } |
| 645 | - if($digit == '>') |
|
| 645 | + if ($digit == '>') |
|
| 646 | 646 | { |
| 647 | 647 | $outside = true; |
| 648 | 648 | } |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | - $banner = $this->strip_clf($banner); // Just in case |
|
| 651 | + $banner = $this->strip_clf($banner); // Just in case |
|
| 652 | 652 | return "<$banner>"; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | } // End class |
| 656 | 656 | |
| 657 | 657 | // For php4 compatibility |
| 658 | -if (!function_exists("stripos")) { |
|
| 659 | - function stripos($haystack, $needle){ |
|
| 660 | - return strpos($haystack, stristr( $haystack, $needle )); |
|
| 658 | +if ( ! function_exists("stripos")) { |
|
| 659 | + function stripos($haystack, $needle) { |
|
| 660 | + return strpos($haystack, stristr($haystack, $needle)); |
|
| 661 | 661 | } |
| 662 | 662 | } |
@@ -53,14 +53,16 @@ discard block |
||
| 53 | 53 | // Do not allow programs to alter MAILSERVER |
| 54 | 54 | // if it is already specified. They can get around |
| 55 | 55 | // this if they -really- want to, so don't count on it. |
| 56 | - if(empty($this->MAILSERVER)) |
|
| 57 | - $this->MAILSERVER = $server; |
|
| 56 | + if(empty($this->MAILSERVER)) { |
|
| 57 | + $this->MAILSERVER = $server; |
|
| 58 | + } |
|
| 58 | 59 | } |
| 59 | 60 | if(!empty($timeout)) { |
| 60 | 61 | settype($timeout,"integer"); |
| 61 | 62 | $this->TIMEOUT = $timeout; |
| 62 | - if (!ini_get('safe_mode')) |
|
| 63 | - set_time_limit($timeout); |
|
| 63 | + if (!ini_get('safe_mode')) { |
|
| 64 | + set_time_limit($timeout); |
|
| 65 | + } |
|
| 64 | 66 | } |
| 65 | 67 | return true; |
| 66 | 68 | } |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | } |
| 74 | 76 | |
| 75 | 77 | function update_timer () { |
| 76 | - if (!ini_get('safe_mode')) |
|
| 77 | - set_time_limit($this->TIMEOUT); |
|
| 78 | + if (!ini_get('safe_mode')) { |
|
| 79 | + set_time_limit($this->TIMEOUT); |
|
| 80 | + } |
|
| 78 | 81 | return true; |
| 79 | 82 | } |
| 80 | 83 | |
@@ -85,8 +88,9 @@ discard block |
||
| 85 | 88 | // If MAILSERVER is set, override $server with its value. |
| 86 | 89 | |
| 87 | 90 | if (!isset($port) || !$port) {$port = 110;} |
| 88 | - if(!empty($this->MAILSERVER)) |
|
| 89 | - $server = $this->MAILSERVER; |
|
| 91 | + if(!empty($this->MAILSERVER)) { |
|
| 92 | + $server = $this->MAILSERVER; |
|
| 93 | + } |
|
| 90 | 94 | |
| 91 | 95 | if(empty($server)){ |
| 92 | 96 | $this->ERROR = "POP3 connect: " . _("No server specified"); |
@@ -106,8 +110,9 @@ discard block |
||
| 106 | 110 | $this->update_timer(); |
| 107 | 111 | $reply = fgets($fp,$this->BUFFER); |
| 108 | 112 | $reply = $this->strip_clf($reply); |
| 109 | - if($this->DEBUG) |
|
| 110 | - error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 113 | + if($this->DEBUG) { |
|
| 114 | + error_log("POP3 SEND [connect: $server] GOT [$reply]",0); |
|
| 115 | + } |
|
| 111 | 116 | if(!$this->is_ok($reply)) { |
| 112 | 117 | $this->ERROR = "POP3 connect: " . _("Error ") . "[$reply]"; |
| 113 | 118 | unset($this->FP); |
@@ -132,8 +137,9 @@ discard block |
||
| 132 | 137 | if(!$this->is_ok($reply)) { |
| 133 | 138 | $this->ERROR = "POP3 user: " . _("Error ") . "[$reply]"; |
| 134 | 139 | return false; |
| 135 | - } else |
|
| 136 | - return true; |
|
| 140 | + } else { |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 137 | 143 | } |
| 138 | 144 | } |
| 139 | 145 | |
@@ -224,8 +230,9 @@ discard block |
||
| 224 | 230 | if( (!$count) || ($count == -1) ) { |
| 225 | 231 | // Preserve the error generated by last() and pass() |
| 226 | 232 | return false; |
| 227 | - } else |
|
| 228 | - return $count; |
|
| 233 | + } else { |
|
| 234 | + return $count; |
|
| 235 | + } |
|
| 229 | 236 | } |
| 230 | 237 | } |
| 231 | 238 | } |
@@ -338,8 +345,7 @@ discard block |
||
| 338 | 345 | if($thisMsg != $msgC) |
| 339 | 346 | { |
| 340 | 347 | $MsgArray[$msgC] = "deleted"; |
| 341 | - } |
|
| 342 | - else |
|
| 348 | + } else |
|
| 343 | 349 | { |
| 344 | 350 | $MsgArray[$msgC] = $msgSize; |
| 345 | 351 | } |
@@ -567,8 +573,7 @@ discard block |
||
| 567 | 573 | $msgUidl = $this->strip_clf($msgUidl); |
| 568 | 574 | if($count == $msg) { |
| 569 | 575 | $UIDLArray[$msg] = $msgUidl; |
| 570 | - } |
|
| 571 | - else |
|
| 576 | + } else |
|
| 572 | 577 | { |
| 573 | 578 | $UIDLArray[$count] = 'deleted'; |
| 574 | 579 | } |
@@ -609,18 +614,19 @@ discard block |
||
| 609 | 614 | function is_ok ($cmd = "") { |
| 610 | 615 | // Return true or false on +OK or -ERR |
| 611 | 616 | |
| 612 | - if( empty($cmd) ) |
|
| 613 | - return false; |
|
| 614 | - else |
|
| 615 | - return( stripos($cmd, '+OK') !== false ); |
|
| 617 | + if( empty($cmd) ) { |
|
| 618 | + return false; |
|
| 619 | + } else { |
|
| 620 | + return( stripos($cmd, '+OK') !== false ); |
|
| 621 | + } |
|
| 616 | 622 | } |
| 617 | 623 | |
| 618 | 624 | function strip_clf ($text = "") { |
| 619 | 625 | // Strips \r\n from server responses |
| 620 | 626 | |
| 621 | - if(empty($text)) |
|
| 622 | - return $text; |
|
| 623 | - else { |
|
| 627 | + if(empty($text)) { |
|
| 628 | + return $text; |
|
| 629 | + } else { |
|
| 624 | 630 | $stripped = str_replace(array("\r","\n"),'',$text); |
| 625 | 631 | return $stripped; |
| 626 | 632 | } |
@@ -781,6 +781,9 @@ discard block |
||
| 781 | 781 | Output: |
| 782 | 782 | \*======================================================================*/ |
| 783 | 783 | |
| 784 | + /** |
|
| 785 | + * @param string $http_method |
|
| 786 | + */ |
|
| 784 | 787 | function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
| 785 | 788 | { |
| 786 | 789 | $cookie_headers = ''; |
@@ -944,6 +947,9 @@ discard block |
||
| 944 | 947 | Output: |
| 945 | 948 | \*======================================================================*/ |
| 946 | 949 | |
| 950 | + /** |
|
| 951 | + * @param string $http_method |
|
| 952 | + */ |
|
| 947 | 953 | function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
| 948 | 954 | { |
| 949 | 955 | if($this->passcookies && $this->_redirectaddr) |
@@ -1189,6 +1195,10 @@ discard block |
||
| 1189 | 1195 | Output: post body |
| 1190 | 1196 | \*======================================================================*/ |
| 1191 | 1197 | |
| 1198 | + /** |
|
| 1199 | + * @param string $formvars |
|
| 1200 | + * @param string $formfiles |
|
| 1201 | + */ |
|
| 1192 | 1202 | function _prepare_post_body($formvars, $formfiles) |
| 1193 | 1203 | { |
| 1194 | 1204 | settype($formvars, "array"); |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | if(!$this->curl_path) |
| 206 | 206 | return false; |
| 207 | 207 | if(function_exists("is_executable")) |
| 208 | - if (!is_executable($this->curl_path)) |
|
| 209 | - return false; |
|
| 208 | + if (!is_executable($this->curl_path)) |
|
| 209 | + return false; |
|
| 210 | 210 | $this->host = $URI_PARTS["host"]; |
| 211 | 211 | if(!empty($URI_PARTS["port"])) |
| 212 | 212 | $this->port = $URI_PARTS["port"]; |
@@ -364,8 +364,8 @@ discard block |
||
| 364 | 364 | if(!$this->curl_path) |
| 365 | 365 | return false; |
| 366 | 366 | if(function_exists("is_executable")) |
| 367 | - if (!is_executable($this->curl_path)) |
|
| 368 | - return false; |
|
| 367 | + if (!is_executable($this->curl_path)) |
|
| 368 | + return false; |
|
| 369 | 369 | $this->host = $URI_PARTS["host"]; |
| 370 | 370 | if(!empty($URI_PARTS["port"])) |
| 371 | 371 | $this->port = $URI_PARTS["port"]; |
@@ -885,10 +885,10 @@ discard block |
||
| 885 | 885 | |
| 886 | 886 | if(preg_match("|^HTTP/|",$currentHeader)) |
| 887 | 887 | { |
| 888 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 888 | + if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 889 | 889 | { |
| 890 | 890 | $this->status= $status[1]; |
| 891 | - } |
|
| 891 | + } |
|
| 892 | 892 | $this->response_code = $currentHeader; |
| 893 | 893 | } |
| 894 | 894 | |
@@ -897,11 +897,11 @@ discard block |
||
| 897 | 897 | |
| 898 | 898 | $results = ''; |
| 899 | 899 | do { |
| 900 | - $_data = fread($fp, $this->maxlength); |
|
| 901 | - if (strlen($_data) == 0) { |
|
| 902 | - break; |
|
| 903 | - } |
|
| 904 | - $results .= $_data; |
|
| 900 | + $_data = fread($fp, $this->maxlength); |
|
| 901 | + if (strlen($_data) == 0) { |
|
| 902 | + break; |
|
| 903 | + } |
|
| 904 | + $results .= $_data; |
|
| 905 | 905 | } while(true); |
| 906 | 906 | |
| 907 | 907 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
@@ -131,29 +131,33 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
| 133 | 133 | $URI_PARTS = parse_url($URI); |
| 134 | - if (!empty($URI_PARTS["user"])) |
|
| 135 | - $this->user = $URI_PARTS["user"]; |
|
| 136 | - if (!empty($URI_PARTS["pass"])) |
|
| 137 | - $this->pass = $URI_PARTS["pass"]; |
|
| 138 | - if (empty($URI_PARTS["query"])) |
|
| 139 | - $URI_PARTS["query"] = ''; |
|
| 140 | - if (empty($URI_PARTS["path"])) |
|
| 141 | - $URI_PARTS["path"] = ''; |
|
| 134 | + if (!empty($URI_PARTS["user"])) { |
|
| 135 | + $this->user = $URI_PARTS["user"]; |
|
| 136 | + } |
|
| 137 | + if (!empty($URI_PARTS["pass"])) { |
|
| 138 | + $this->pass = $URI_PARTS["pass"]; |
|
| 139 | + } |
|
| 140 | + if (empty($URI_PARTS["query"])) { |
|
| 141 | + $URI_PARTS["query"] = ''; |
|
| 142 | + } |
|
| 143 | + if (empty($URI_PARTS["path"])) { |
|
| 144 | + $URI_PARTS["path"] = ''; |
|
| 145 | + } |
|
| 142 | 146 | |
| 143 | 147 | switch(strtolower($URI_PARTS["scheme"])) |
| 144 | 148 | { |
| 145 | 149 | case "http": |
| 146 | 150 | $this->host = $URI_PARTS["host"]; |
| 147 | - if(!empty($URI_PARTS["port"])) |
|
| 148 | - $this->port = $URI_PARTS["port"]; |
|
| 151 | + if(!empty($URI_PARTS["port"])) { |
|
| 152 | + $this->port = $URI_PARTS["port"]; |
|
| 153 | + } |
|
| 149 | 154 | if($this->_connect($fp)) |
| 150 | 155 | { |
| 151 | 156 | if($this->_isproxy) |
| 152 | 157 | { |
| 153 | 158 | // using proxy, send entire URI |
| 154 | 159 | $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
| 155 | - } |
|
| 156 | - else |
|
| 160 | + } else |
|
| 157 | 161 | { |
| 158 | 162 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 159 | 163 | // no proxy, send only the path |
@@ -189,33 +193,34 @@ discard block |
||
| 189 | 193 | { |
| 190 | 194 | $this->fetch($frameurl); |
| 191 | 195 | $this->_framedepth++; |
| 196 | + } else { |
|
| 197 | + break; |
|
| 192 | 198 | } |
| 193 | - else |
|
| 194 | - break; |
|
| 195 | 199 | } |
| 196 | 200 | } |
| 197 | - } |
|
| 198 | - else |
|
| 201 | + } else |
|
| 199 | 202 | { |
| 200 | 203 | return false; |
| 201 | 204 | } |
| 202 | 205 | return true; |
| 203 | 206 | break; |
| 204 | 207 | case "https": |
| 205 | - if(!$this->curl_path) |
|
| 206 | - return false; |
|
| 207 | - if(function_exists("is_executable")) |
|
| 208 | - if (!is_executable($this->curl_path)) |
|
| 208 | + if(!$this->curl_path) { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + if(function_exists("is_executable")) { |
|
| 212 | + if (!is_executable($this->curl_path)) |
|
| 209 | 213 | return false; |
| 214 | + } |
|
| 210 | 215 | $this->host = $URI_PARTS["host"]; |
| 211 | - if(!empty($URI_PARTS["port"])) |
|
| 212 | - $this->port = $URI_PARTS["port"]; |
|
| 216 | + if(!empty($URI_PARTS["port"])) { |
|
| 217 | + $this->port = $URI_PARTS["port"]; |
|
| 218 | + } |
|
| 213 | 219 | if($this->_isproxy) |
| 214 | 220 | { |
| 215 | 221 | // using proxy, send entire URI |
| 216 | 222 | $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
| 217 | - } |
|
| 218 | - else |
|
| 223 | + } else |
|
| 219 | 224 | { |
| 220 | 225 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 221 | 226 | // no proxy, send only the path |
@@ -249,9 +254,9 @@ discard block |
||
| 249 | 254 | { |
| 250 | 255 | $this->fetch($frameurl); |
| 251 | 256 | $this->_framedepth++; |
| 257 | + } else { |
|
| 258 | + break; |
|
| 252 | 259 | } |
| 253 | - else |
|
| 254 | - break; |
|
| 255 | 260 | } |
| 256 | 261 | } |
| 257 | 262 | return true; |
@@ -283,29 +288,33 @@ discard block |
||
| 283 | 288 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 284 | 289 | |
| 285 | 290 | $URI_PARTS = parse_url($URI); |
| 286 | - if (!empty($URI_PARTS["user"])) |
|
| 287 | - $this->user = $URI_PARTS["user"]; |
|
| 288 | - if (!empty($URI_PARTS["pass"])) |
|
| 289 | - $this->pass = $URI_PARTS["pass"]; |
|
| 290 | - if (empty($URI_PARTS["query"])) |
|
| 291 | - $URI_PARTS["query"] = ''; |
|
| 292 | - if (empty($URI_PARTS["path"])) |
|
| 293 | - $URI_PARTS["path"] = ''; |
|
| 291 | + if (!empty($URI_PARTS["user"])) { |
|
| 292 | + $this->user = $URI_PARTS["user"]; |
|
| 293 | + } |
|
| 294 | + if (!empty($URI_PARTS["pass"])) { |
|
| 295 | + $this->pass = $URI_PARTS["pass"]; |
|
| 296 | + } |
|
| 297 | + if (empty($URI_PARTS["query"])) { |
|
| 298 | + $URI_PARTS["query"] = ''; |
|
| 299 | + } |
|
| 300 | + if (empty($URI_PARTS["path"])) { |
|
| 301 | + $URI_PARTS["path"] = ''; |
|
| 302 | + } |
|
| 294 | 303 | |
| 295 | 304 | switch(strtolower($URI_PARTS["scheme"])) |
| 296 | 305 | { |
| 297 | 306 | case "http": |
| 298 | 307 | $this->host = $URI_PARTS["host"]; |
| 299 | - if(!empty($URI_PARTS["port"])) |
|
| 300 | - $this->port = $URI_PARTS["port"]; |
|
| 308 | + if(!empty($URI_PARTS["port"])) { |
|
| 309 | + $this->port = $URI_PARTS["port"]; |
|
| 310 | + } |
|
| 301 | 311 | if($this->_connect($fp)) |
| 302 | 312 | { |
| 303 | 313 | if($this->_isproxy) |
| 304 | 314 | { |
| 305 | 315 | // using proxy, send entire URI |
| 306 | 316 | $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
| 307 | - } |
|
| 308 | - else |
|
| 317 | + } else |
|
| 309 | 318 | { |
| 310 | 319 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 311 | 320 | // no proxy, send only the path |
@@ -319,8 +328,9 @@ discard block |
||
| 319 | 328 | /* url was redirected, check if we've hit the max depth */ |
| 320 | 329 | if($this->maxredirs > $this->_redirectdepth) |
| 321 | 330 | { |
| 322 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 331 | + if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) { |
|
| 332 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 333 | + } |
|
| 324 | 334 | |
| 325 | 335 | // only follow redirect if it's on this site, or offsiteok is true |
| 326 | 336 | if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
@@ -328,10 +338,13 @@ discard block |
||
| 328 | 338 | /* follow the redirect */ |
| 329 | 339 | $this->_redirectdepth++; |
| 330 | 340 | $this->lastredirectaddr=$this->_redirectaddr; |
| 331 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 332 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 333 | - else |
|
| 334 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 341 | + if( strpos( $this->_redirectaddr, "?" ) > 0 ) { |
|
| 342 | + $this->fetch($this->_redirectaddr); |
|
| 343 | + } |
|
| 344 | + // the redirect has changed the request method from post to get |
|
| 345 | + else { |
|
| 346 | + $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 347 | + } |
|
| 335 | 348 | } |
| 336 | 349 | } |
| 337 | 350 | } |
@@ -347,34 +360,35 @@ discard block |
||
| 347 | 360 | { |
| 348 | 361 | $this->fetch($frameurl); |
| 349 | 362 | $this->_framedepth++; |
| 363 | + } else { |
|
| 364 | + break; |
|
| 350 | 365 | } |
| 351 | - else |
|
| 352 | - break; |
|
| 353 | 366 | } |
| 354 | 367 | } |
| 355 | 368 | |
| 356 | - } |
|
| 357 | - else |
|
| 369 | + } else |
|
| 358 | 370 | { |
| 359 | 371 | return false; |
| 360 | 372 | } |
| 361 | 373 | return true; |
| 362 | 374 | break; |
| 363 | 375 | case "https": |
| 364 | - if(!$this->curl_path) |
|
| 365 | - return false; |
|
| 366 | - if(function_exists("is_executable")) |
|
| 367 | - if (!is_executable($this->curl_path)) |
|
| 376 | + if(!$this->curl_path) { |
|
| 377 | + return false; |
|
| 378 | + } |
|
| 379 | + if(function_exists("is_executable")) { |
|
| 380 | + if (!is_executable($this->curl_path)) |
|
| 368 | 381 | return false; |
| 382 | + } |
|
| 369 | 383 | $this->host = $URI_PARTS["host"]; |
| 370 | - if(!empty($URI_PARTS["port"])) |
|
| 371 | - $this->port = $URI_PARTS["port"]; |
|
| 384 | + if(!empty($URI_PARTS["port"])) { |
|
| 385 | + $this->port = $URI_PARTS["port"]; |
|
| 386 | + } |
|
| 372 | 387 | if($this->_isproxy) |
| 373 | 388 | { |
| 374 | 389 | // using proxy, send entire URI |
| 375 | 390 | $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 376 | - } |
|
| 377 | - else |
|
| 391 | + } else |
|
| 378 | 392 | { |
| 379 | 393 | $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
| 380 | 394 | // no proxy, send only the path |
@@ -386,8 +400,9 @@ discard block |
||
| 386 | 400 | /* url was redirected, check if we've hit the max depth */ |
| 387 | 401 | if($this->maxredirs > $this->_redirectdepth) |
| 388 | 402 | { |
| 389 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 403 | + if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) { |
|
| 404 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 405 | + } |
|
| 391 | 406 | |
| 392 | 407 | // only follow redirect if it's on this site, or offsiteok is true |
| 393 | 408 | if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
@@ -395,10 +410,13 @@ discard block |
||
| 395 | 410 | /* follow the redirect */ |
| 396 | 411 | $this->_redirectdepth++; |
| 397 | 412 | $this->lastredirectaddr=$this->_redirectaddr; |
| 398 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 399 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 400 | - else |
|
| 401 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 413 | + if( strpos( $this->_redirectaddr, "?" ) > 0 ) { |
|
| 414 | + $this->fetch($this->_redirectaddr); |
|
| 415 | + } |
|
| 416 | + // the redirect has changed the request method from post to get |
|
| 417 | + else { |
|
| 418 | + $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 419 | + } |
|
| 402 | 420 | } |
| 403 | 421 | } |
| 404 | 422 | } |
@@ -414,9 +432,9 @@ discard block |
||
| 414 | 432 | { |
| 415 | 433 | $this->fetch($frameurl); |
| 416 | 434 | $this->_framedepth++; |
| 435 | + } else { |
|
| 436 | + break; |
|
| 417 | 437 | } |
| 418 | - else |
|
| 419 | - break; |
|
| 420 | 438 | } |
| 421 | 439 | } |
| 422 | 440 | return true; |
@@ -442,22 +460,25 @@ discard block |
||
| 442 | 460 | { |
| 443 | 461 | if ($this->fetch($URI)) |
| 444 | 462 | { |
| 445 | - if($this->lastredirectaddr) |
|
| 446 | - $URI = $this->lastredirectaddr; |
|
| 463 | + if($this->lastredirectaddr) { |
|
| 464 | + $URI = $this->lastredirectaddr; |
|
| 465 | + } |
|
| 447 | 466 | if(is_array($this->results)) |
| 448 | 467 | { |
| 449 | - for($x=0;$x<count($this->results);$x++) |
|
| 450 | - $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 468 | + for($x=0;$x<count($this->results);$x++) { |
|
| 469 | + $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + $this->results = $this->_striplinks($this->results); |
|
| 451 | 473 | } |
| 452 | - else |
|
| 453 | - $this->results = $this->_striplinks($this->results); |
|
| 454 | 474 | |
| 455 | - if($this->expandlinks) |
|
| 456 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 475 | + if($this->expandlinks) { |
|
| 476 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 477 | + } |
|
| 457 | 478 | return true; |
| 479 | + } else { |
|
| 480 | + return false; |
|
| 458 | 481 | } |
| 459 | - else |
|
| 460 | - return false; |
|
| 461 | 482 | } |
| 462 | 483 | |
| 463 | 484 | /*======================================================================*\ |
@@ -475,16 +496,17 @@ discard block |
||
| 475 | 496 | |
| 476 | 497 | if(is_array($this->results)) |
| 477 | 498 | { |
| 478 | - for($x=0;$x<count($this->results);$x++) |
|
| 479 | - $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 499 | + for($x=0;$x<count($this->results);$x++) { |
|
| 500 | + $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + $this->results = $this->_stripform($this->results); |
|
| 480 | 504 | } |
| 481 | - else |
|
| 482 | - $this->results = $this->_stripform($this->results); |
|
| 483 | 505 | |
| 484 | 506 | return true; |
| 507 | + } else { |
|
| 508 | + return false; |
|
| 485 | 509 | } |
| 486 | - else |
|
| 487 | - return false; |
|
| 488 | 510 | } |
| 489 | 511 | |
| 490 | 512 | |
@@ -501,15 +523,16 @@ discard block |
||
| 501 | 523 | { |
| 502 | 524 | if(is_array($this->results)) |
| 503 | 525 | { |
| 504 | - for($x=0;$x<count($this->results);$x++) |
|
| 505 | - $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 526 | + for($x=0;$x<count($this->results);$x++) { |
|
| 527 | + $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 528 | + } |
|
| 529 | + } else { |
|
| 530 | + $this->results = $this->_striptext($this->results); |
|
| 506 | 531 | } |
| 507 | - else |
|
| 508 | - $this->results = $this->_striptext($this->results); |
|
| 509 | 532 | return true; |
| 533 | + } else { |
|
| 534 | + return false; |
|
| 510 | 535 | } |
| 511 | - else |
|
| 512 | - return false; |
|
| 513 | 536 | } |
| 514 | 537 | |
| 515 | 538 | /*======================================================================*\ |
@@ -523,27 +546,29 @@ discard block |
||
| 523 | 546 | { |
| 524 | 547 | if($this->submit($URI,$formvars, $formfiles)) |
| 525 | 548 | { |
| 526 | - if($this->lastredirectaddr) |
|
| 527 | - $URI = $this->lastredirectaddr; |
|
| 549 | + if($this->lastredirectaddr) { |
|
| 550 | + $URI = $this->lastredirectaddr; |
|
| 551 | + } |
|
| 528 | 552 | if(is_array($this->results)) |
| 529 | 553 | { |
| 530 | 554 | for($x=0;$x<count($this->results);$x++) |
| 531 | 555 | { |
| 532 | 556 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 533 | - if($this->expandlinks) |
|
| 534 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 557 | + if($this->expandlinks) { |
|
| 558 | + $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 559 | + } |
|
| 535 | 560 | } |
| 536 | - } |
|
| 537 | - else |
|
| 561 | + } else |
|
| 538 | 562 | { |
| 539 | 563 | $this->results = $this->_striplinks($this->results); |
| 540 | - if($this->expandlinks) |
|
| 541 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 564 | + if($this->expandlinks) { |
|
| 565 | + $this->results = $this->_expandlinks($this->results,$URI); |
|
| 566 | + } |
|
| 542 | 567 | } |
| 543 | 568 | return true; |
| 569 | + } else { |
|
| 570 | + return false; |
|
| 544 | 571 | } |
| 545 | - else |
|
| 546 | - return false; |
|
| 547 | 572 | } |
| 548 | 573 | |
| 549 | 574 | /*======================================================================*\ |
@@ -557,27 +582,29 @@ discard block |
||
| 557 | 582 | { |
| 558 | 583 | if($this->submit($URI,$formvars, $formfiles)) |
| 559 | 584 | { |
| 560 | - if($this->lastredirectaddr) |
|
| 561 | - $URI = $this->lastredirectaddr; |
|
| 585 | + if($this->lastredirectaddr) { |
|
| 586 | + $URI = $this->lastredirectaddr; |
|
| 587 | + } |
|
| 562 | 588 | if(is_array($this->results)) |
| 563 | 589 | { |
| 564 | 590 | for($x=0;$x<count($this->results);$x++) |
| 565 | 591 | { |
| 566 | 592 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 567 | - if($this->expandlinks) |
|
| 568 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 593 | + if($this->expandlinks) { |
|
| 594 | + $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 595 | + } |
|
| 569 | 596 | } |
| 570 | - } |
|
| 571 | - else |
|
| 597 | + } else |
|
| 572 | 598 | { |
| 573 | 599 | $this->results = $this->_striptext($this->results); |
| 574 | - if($this->expandlinks) |
|
| 575 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 600 | + if($this->expandlinks) { |
|
| 601 | + $this->results = $this->_expandlinks($this->results,$URI); |
|
| 602 | + } |
|
| 576 | 603 | } |
| 577 | 604 | return true; |
| 605 | + } else { |
|
| 606 | + return false; |
|
| 578 | 607 | } |
| 579 | - else |
|
| 580 | - return false; |
|
| 581 | 608 | } |
| 582 | 609 | |
| 583 | 610 | |
@@ -631,14 +658,16 @@ discard block |
||
| 631 | 658 | |
| 632 | 659 | while(list($key,$val) = each($links[2])) |
| 633 | 660 | { |
| 634 | - if(!empty($val)) |
|
| 635 | - $match[] = $val; |
|
| 661 | + if(!empty($val)) { |
|
| 662 | + $match[] = $val; |
|
| 663 | + } |
|
| 636 | 664 | } |
| 637 | 665 | |
| 638 | 666 | while(list($key,$val) = each($links[3])) |
| 639 | 667 | { |
| 640 | - if(!empty($val)) |
|
| 641 | - $match[] = $val; |
|
| 668 | + if(!empty($val)) { |
|
| 669 | + $match[] = $val; |
|
| 670 | + } |
|
| 642 | 671 | } |
| 643 | 672 | |
| 644 | 673 | // return the links |
@@ -784,29 +813,36 @@ discard block |
||
| 784 | 813 | function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
| 785 | 814 | { |
| 786 | 815 | $cookie_headers = ''; |
| 787 | - if($this->passcookies && $this->_redirectaddr) |
|
| 788 | - $this->setcookies(); |
|
| 816 | + if($this->passcookies && $this->_redirectaddr) { |
|
| 817 | + $this->setcookies(); |
|
| 818 | + } |
|
| 789 | 819 | |
| 790 | 820 | $URI_PARTS = parse_url($URI); |
| 791 | - if(empty($url)) |
|
| 792 | - $url = "/"; |
|
| 821 | + if(empty($url)) { |
|
| 822 | + $url = "/"; |
|
| 823 | + } |
|
| 793 | 824 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
| 794 | - if(!empty($this->agent)) |
|
| 795 | - $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
| 825 | + if(!empty($this->agent)) { |
|
| 826 | + $headers .= "User-Agent: ".$this->agent."\r\n"; |
|
| 827 | + } |
|
| 796 | 828 | if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
| 797 | 829 | $headers .= "Host: ".$this->host; |
| 798 | - if(!empty($this->port) && $this->port != 80) |
|
| 799 | - $headers .= ":".$this->port; |
|
| 830 | + if(!empty($this->port) && $this->port != 80) { |
|
| 831 | + $headers .= ":".$this->port; |
|
| 832 | + } |
|
| 800 | 833 | $headers .= "\r\n"; |
| 801 | 834 | } |
| 802 | - if(!empty($this->accept)) |
|
| 803 | - $headers .= "Accept: ".$this->accept."\r\n"; |
|
| 804 | - if(!empty($this->referer)) |
|
| 805 | - $headers .= "Referer: ".$this->referer."\r\n"; |
|
| 835 | + if(!empty($this->accept)) { |
|
| 836 | + $headers .= "Accept: ".$this->accept."\r\n"; |
|
| 837 | + } |
|
| 838 | + if(!empty($this->referer)) { |
|
| 839 | + $headers .= "Referer: ".$this->referer."\r\n"; |
|
| 840 | + } |
|
| 806 | 841 | if(!empty($this->cookies)) |
| 807 | 842 | { |
| 808 | - if(!is_array($this->cookies)) |
|
| 809 | - $this->cookies = (array)$this->cookies; |
|
| 843 | + if(!is_array($this->cookies)) { |
|
| 844 | + $this->cookies = (array)$this->cookies; |
|
| 845 | + } |
|
| 810 | 846 | |
| 811 | 847 | reset($this->cookies); |
| 812 | 848 | if ( count($this->cookies) > 0 ) { |
@@ -819,32 +855,39 @@ discard block |
||
| 819 | 855 | } |
| 820 | 856 | if(!empty($this->rawheaders)) |
| 821 | 857 | { |
| 822 | - if(!is_array($this->rawheaders)) |
|
| 823 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 824 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 825 | - $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
| 858 | + if(!is_array($this->rawheaders)) { |
|
| 859 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 860 | + } |
|
| 861 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
| 862 | + $headers .= $headerKey.": ".$headerVal."\r\n"; |
|
| 863 | + } |
|
| 826 | 864 | } |
| 827 | 865 | if(!empty($content_type)) { |
| 828 | 866 | $headers .= "Content-type: $content_type"; |
| 829 | - if ($content_type == "multipart/form-data") |
|
| 830 | - $headers .= "; boundary=".$this->_mime_boundary; |
|
| 867 | + if ($content_type == "multipart/form-data") { |
|
| 868 | + $headers .= "; boundary=".$this->_mime_boundary; |
|
| 869 | + } |
|
| 831 | 870 | $headers .= "\r\n"; |
| 832 | 871 | } |
| 833 | - if(!empty($body)) |
|
| 834 | - $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
| 835 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 836 | - $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
| 872 | + if(!empty($body)) { |
|
| 873 | + $headers .= "Content-length: ".strlen($body)."\r\n"; |
|
| 874 | + } |
|
| 875 | + if(!empty($this->user) || !empty($this->pass)) { |
|
| 876 | + $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|
| 877 | + } |
|
| 837 | 878 | |
| 838 | 879 | //add proxy auth headers |
| 839 | - if(!empty($this->proxy_user)) |
|
| 840 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 880 | + if(!empty($this->proxy_user)) { |
|
| 881 | + $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 882 | + } |
|
| 841 | 883 | |
| 842 | 884 | |
| 843 | 885 | $headers .= "\r\n"; |
| 844 | 886 | |
| 845 | 887 | // set the read timeout if needed |
| 846 | - if ($this->read_timeout > 0) |
|
| 847 | - socket_set_timeout($fp, $this->read_timeout); |
|
| 888 | + if ($this->read_timeout > 0) { |
|
| 889 | + socket_set_timeout($fp, $this->read_timeout); |
|
| 890 | + } |
|
| 848 | 891 | $this->timed_out = false; |
| 849 | 892 | |
| 850 | 893 | fwrite($fp,$headers.$body,strlen($headers.$body)); |
@@ -860,8 +903,9 @@ discard block |
||
| 860 | 903 | return false; |
| 861 | 904 | } |
| 862 | 905 | |
| 863 | - if($currentHeader == "\r\n") |
|
| 864 | - break; |
|
| 906 | + if($currentHeader == "\r\n") { |
|
| 907 | + break; |
|
| 908 | + } |
|
| 865 | 909 | |
| 866 | 910 | // if a header begins with Location: or URI:, set the redirect |
| 867 | 911 | if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
@@ -874,13 +918,14 @@ discard block |
||
| 874 | 918 | // no host in the path, so prepend |
| 875 | 919 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 876 | 920 | // eliminate double slash |
| 877 | - if(!preg_match("|^/|",$matches[2])) |
|
| 878 | - $this->_redirectaddr .= "/".$matches[2]; |
|
| 879 | - else |
|
| 880 | - $this->_redirectaddr .= $matches[2]; |
|
| 921 | + if(!preg_match("|^/|",$matches[2])) { |
|
| 922 | + $this->_redirectaddr .= "/".$matches[2]; |
|
| 923 | + } else { |
|
| 924 | + $this->_redirectaddr .= $matches[2]; |
|
| 925 | + } |
|
| 926 | + } else { |
|
| 927 | + $this->_redirectaddr = $matches[2]; |
|
| 881 | 928 | } |
| 882 | - else |
|
| 883 | - $this->_redirectaddr = $matches[2]; |
|
| 884 | 929 | } |
| 885 | 930 | |
| 886 | 931 | if(preg_match("|^HTTP/|",$currentHeader)) |
@@ -922,15 +967,18 @@ discard block |
||
| 922 | 967 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
| 923 | 968 | { |
| 924 | 969 | $this->results[] = $results; |
| 925 | - for($x=0; $x<count($match[1]); $x++) |
|
| 926 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 970 | + for($x=0; $x<count($match[1]); $x++) { |
|
| 971 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 972 | + } |
|
| 927 | 973 | } |
| 928 | 974 | // have we already fetched framed content? |
| 929 | - elseif(is_array($this->results)) |
|
| 930 | - $this->results[] = $results; |
|
| 975 | + elseif(is_array($this->results)) { |
|
| 976 | + $this->results[] = $results; |
|
| 977 | + } |
|
| 931 | 978 | // no framed content |
| 932 | - else |
|
| 933 | - $this->results = $results; |
|
| 979 | + else { |
|
| 980 | + $this->results = $results; |
|
| 981 | + } |
|
| 934 | 982 | |
| 935 | 983 | return true; |
| 936 | 984 | } |
@@ -946,31 +994,38 @@ discard block |
||
| 946 | 994 | |
| 947 | 995 | function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
| 948 | 996 | { |
| 949 | - if($this->passcookies && $this->_redirectaddr) |
|
| 950 | - $this->setcookies(); |
|
| 997 | + if($this->passcookies && $this->_redirectaddr) { |
|
| 998 | + $this->setcookies(); |
|
| 999 | + } |
|
| 951 | 1000 | |
| 952 | 1001 | $headers = array(); |
| 953 | 1002 | |
| 954 | 1003 | $URI_PARTS = parse_url($URI); |
| 955 | - if(empty($url)) |
|
| 956 | - $url = "/"; |
|
| 1004 | + if(empty($url)) { |
|
| 1005 | + $url = "/"; |
|
| 1006 | + } |
|
| 957 | 1007 | // GET ... header not needed for curl |
| 958 | 1008 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
| 959 | - if(!empty($this->agent)) |
|
| 960 | - $headers[] = "User-Agent: ".$this->agent; |
|
| 961 | - if(!empty($this->host)) |
|
| 962 | - if(!empty($this->port)) |
|
| 1009 | + if(!empty($this->agent)) { |
|
| 1010 | + $headers[] = "User-Agent: ".$this->agent; |
|
| 1011 | + } |
|
| 1012 | + if(!empty($this->host)) { |
|
| 1013 | + if(!empty($this->port)) |
|
| 963 | 1014 | $headers[] = "Host: ".$this->host.":".$this->port; |
| 964 | - else |
|
| 965 | - $headers[] = "Host: ".$this->host; |
|
| 966 | - if(!empty($this->accept)) |
|
| 967 | - $headers[] = "Accept: ".$this->accept; |
|
| 968 | - if(!empty($this->referer)) |
|
| 969 | - $headers[] = "Referer: ".$this->referer; |
|
| 1015 | + } else { |
|
| 1016 | + $headers[] = "Host: ".$this->host; |
|
| 1017 | + } |
|
| 1018 | + if(!empty($this->accept)) { |
|
| 1019 | + $headers[] = "Accept: ".$this->accept; |
|
| 1020 | + } |
|
| 1021 | + if(!empty($this->referer)) { |
|
| 1022 | + $headers[] = "Referer: ".$this->referer; |
|
| 1023 | + } |
|
| 970 | 1024 | if(!empty($this->cookies)) |
| 971 | 1025 | { |
| 972 | - if(!is_array($this->cookies)) |
|
| 973 | - $this->cookies = (array)$this->cookies; |
|
| 1026 | + if(!is_array($this->cookies)) { |
|
| 1027 | + $this->cookies = (array)$this->cookies; |
|
| 1028 | + } |
|
| 974 | 1029 | |
| 975 | 1030 | reset($this->cookies); |
| 976 | 1031 | if ( count($this->cookies) > 0 ) { |
@@ -983,21 +1038,26 @@ discard block |
||
| 983 | 1038 | } |
| 984 | 1039 | if(!empty($this->rawheaders)) |
| 985 | 1040 | { |
| 986 | - if(!is_array($this->rawheaders)) |
|
| 987 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 988 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 989 | - $headers[] = $headerKey.": ".$headerVal; |
|
| 1041 | + if(!is_array($this->rawheaders)) { |
|
| 1042 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 1043 | + } |
|
| 1044 | + while(list($headerKey,$headerVal) = each($this->rawheaders)) { |
|
| 1045 | + $headers[] = $headerKey.": ".$headerVal; |
|
| 1046 | + } |
|
| 990 | 1047 | } |
| 991 | 1048 | if(!empty($content_type)) { |
| 992 | - if ($content_type == "multipart/form-data") |
|
| 993 | - $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
| 994 | - else |
|
| 995 | - $headers[] = "Content-type: $content_type"; |
|
| 1049 | + if ($content_type == "multipart/form-data") { |
|
| 1050 | + $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|
| 1051 | + } else { |
|
| 1052 | + $headers[] = "Content-type: $content_type"; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if(!empty($body)) { |
|
| 1056 | + $headers[] = "Content-length: ".strlen($body); |
|
| 1057 | + } |
|
| 1058 | + if(!empty($this->user) || !empty($this->pass)) { |
|
| 1059 | + $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
| 996 | 1060 | } |
| 997 | - if(!empty($body)) |
|
| 998 | - $headers[] = "Content-length: ".strlen($body); |
|
| 999 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 1000 | - $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|
| 1001 | 1061 | |
| 1002 | 1062 | $headerfile = tempnam( $this->temp_dir, "sno" ); |
| 1003 | 1063 | $cmdline_params = '-k -D ' . escapeshellarg( $headerfile ); |
@@ -1045,17 +1105,19 @@ discard block |
||
| 1045 | 1105 | // no host in the path, so prepend |
| 1046 | 1106 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 1047 | 1107 | // eliminate double slash |
| 1048 | - if(!preg_match("|^/|",$matches[2])) |
|
| 1049 | - $this->_redirectaddr .= "/".$matches[2]; |
|
| 1050 | - else |
|
| 1051 | - $this->_redirectaddr .= $matches[2]; |
|
| 1108 | + if(!preg_match("|^/|",$matches[2])) { |
|
| 1109 | + $this->_redirectaddr .= "/".$matches[2]; |
|
| 1110 | + } else { |
|
| 1111 | + $this->_redirectaddr .= $matches[2]; |
|
| 1112 | + } |
|
| 1113 | + } else { |
|
| 1114 | + $this->_redirectaddr = $matches[2]; |
|
| 1052 | 1115 | } |
| 1053 | - else |
|
| 1054 | - $this->_redirectaddr = $matches[2]; |
|
| 1055 | 1116 | } |
| 1056 | 1117 | |
| 1057 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
| 1058 | - $this->response_code = $result_headers[$currentHeader]; |
|
| 1118 | + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) { |
|
| 1119 | + $this->response_code = $result_headers[$currentHeader]; |
|
| 1120 | + } |
|
| 1059 | 1121 | |
| 1060 | 1122 | $this->headers[] = $result_headers[$currentHeader]; |
| 1061 | 1123 | } |
@@ -1071,15 +1133,18 @@ discard block |
||
| 1071 | 1133 | if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
| 1072 | 1134 | { |
| 1073 | 1135 | $this->results[] = $results; |
| 1074 | - for($x=0; $x<count($match[1]); $x++) |
|
| 1075 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1136 | + for($x=0; $x<count($match[1]); $x++) { |
|
| 1137 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1138 | + } |
|
| 1076 | 1139 | } |
| 1077 | 1140 | // have we already fetched framed content? |
| 1078 | - elseif(is_array($this->results)) |
|
| 1079 | - $this->results[] = $results; |
|
| 1141 | + elseif(is_array($this->results)) { |
|
| 1142 | + $this->results[] = $results; |
|
| 1143 | + } |
|
| 1080 | 1144 | // no framed content |
| 1081 | - else |
|
| 1082 | - $this->results = $results; |
|
| 1145 | + else { |
|
| 1146 | + $this->results = $results; |
|
| 1147 | + } |
|
| 1083 | 1148 | |
| 1084 | 1149 | unlink("$headerfile"); |
| 1085 | 1150 | |
@@ -1095,8 +1160,9 @@ discard block |
||
| 1095 | 1160 | { |
| 1096 | 1161 | for($x=0; $x<count($this->headers); $x++) |
| 1097 | 1162 | { |
| 1098 | - if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) |
|
| 1099 | - $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 1163 | + if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) { |
|
| 1164 | + $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 1165 | + } |
|
| 1100 | 1166 | } |
| 1101 | 1167 | } |
| 1102 | 1168 | |
@@ -1133,8 +1199,7 @@ discard block |
||
| 1133 | 1199 | |
| 1134 | 1200 | $host = $this->proxy_host; |
| 1135 | 1201 | $port = $this->proxy_port; |
| 1136 | - } |
|
| 1137 | - else |
|
| 1202 | + } else |
|
| 1138 | 1203 | { |
| 1139 | 1204 | $host = $this->host; |
| 1140 | 1205 | $port = $this->port; |
@@ -1153,8 +1218,7 @@ discard block |
||
| 1153 | 1218 | // socket connection succeeded |
| 1154 | 1219 | |
| 1155 | 1220 | return true; |
| 1156 | - } |
|
| 1157 | - else |
|
| 1221 | + } else |
|
| 1158 | 1222 | { |
| 1159 | 1223 | // socket connection failed |
| 1160 | 1224 | $this->status = $errno; |
@@ -1198,8 +1262,9 @@ discard block |
||
| 1198 | 1262 | settype($formfiles, "array"); |
| 1199 | 1263 | $postdata = ''; |
| 1200 | 1264 | |
| 1201 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
| 1202 | - return; |
|
| 1265 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
| 1266 | + return; |
|
| 1267 | + } |
|
| 1203 | 1268 | |
| 1204 | 1269 | switch ($this->_submit_type) { |
| 1205 | 1270 | case "application/x-www-form-urlencoded": |
@@ -1209,8 +1274,9 @@ discard block |
||
| 1209 | 1274 | while (list($cur_key, $cur_val) = each($val)) { |
| 1210 | 1275 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
| 1211 | 1276 | } |
| 1212 | - } else |
|
| 1213 | - $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
| 1277 | + } else { |
|
| 1278 | + $postdata .= urlencode($key)."=".urlencode($val)."&"; |
|
| 1279 | + } |
|
| 1214 | 1280 | } |
| 1215 | 1281 | break; |
| 1216 | 1282 | |
@@ -1236,7 +1302,9 @@ discard block |
||
| 1236 | 1302 | while (list($field_name, $file_names) = each($formfiles)) { |
| 1237 | 1303 | settype($file_names, "array"); |
| 1238 | 1304 | while (list(, $file_name) = each($file_names)) { |
| 1239 | - if (!is_readable($file_name)) continue; |
|
| 1305 | + if (!is_readable($file_name)) { |
|
| 1306 | + continue; |
|
| 1307 | + } |
|
| 1240 | 1308 | |
| 1241 | 1309 | $fp = fopen($file_name, "r"); |
| 1242 | 1310 | $file_content = fread($fp, filesize($file_name)); |
@@ -3,9 +3,9 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * Deprecated. Use WP_HTTP (http.php) instead. |
| 5 | 5 | */ |
| 6 | -_deprecated_file( basename( __FILE__ ), '3.0.0', WPINC . '/http.php' ); |
|
| 6 | +_deprecated_file(basename(__FILE__), '3.0.0', WPINC.'/http.php'); |
|
| 7 | 7 | |
| 8 | -if ( ! class_exists( 'Snoopy', false ) ) : |
|
| 8 | +if ( ! class_exists('Snoopy', false)) : |
|
| 9 | 9 | /************************************************* |
| 10 | 10 | |
| 11 | 11 | Snoopy - the PHP net client |
@@ -41,54 +41,54 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | /* user definable vars */ |
| 43 | 43 | |
| 44 | - var $host = "www.php.net"; // host name we are connecting to |
|
| 45 | - var $port = 80; // port we are connecting to |
|
| 46 | - var $proxy_host = ""; // proxy host to use |
|
| 47 | - var $proxy_port = ""; // proxy port to use |
|
| 48 | - var $proxy_user = ""; // proxy user to use |
|
| 49 | - var $proxy_pass = ""; // proxy password to use |
|
| 44 | + var $host = "www.php.net"; // host name we are connecting to |
|
| 45 | + var $port = 80; // port we are connecting to |
|
| 46 | + var $proxy_host = ""; // proxy host to use |
|
| 47 | + var $proxy_port = ""; // proxy port to use |
|
| 48 | + var $proxy_user = ""; // proxy user to use |
|
| 49 | + var $proxy_pass = ""; // proxy password to use |
|
| 50 | 50 | |
| 51 | - var $agent = "Snoopy v1.2.4"; // agent we masquerade as |
|
| 52 | - var $referer = ""; // referer info to pass |
|
| 53 | - var $cookies = array(); // array of cookies to pass |
|
| 51 | + var $agent = "Snoopy v1.2.4"; // agent we masquerade as |
|
| 52 | + var $referer = ""; // referer info to pass |
|
| 53 | + var $cookies = array(); // array of cookies to pass |
|
| 54 | 54 | // $cookies["username"]="joe"; |
| 55 | - var $rawheaders = array(); // array of raw headers to send |
|
| 55 | + var $rawheaders = array(); // array of raw headers to send |
|
| 56 | 56 | // $rawheaders["Content-type"]="text/html"; |
| 57 | 57 | |
| 58 | - var $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
| 59 | - var $lastredirectaddr = ""; // contains address of last redirected address |
|
| 60 | - var $offsiteok = true; // allows redirection off-site |
|
| 61 | - var $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
| 62 | - var $expandlinks = true; // expand links to fully qualified URLs. |
|
| 58 | + var $maxredirs = 5; // http redirection depth maximum. 0 = disallow |
|
| 59 | + var $lastredirectaddr = ""; // contains address of last redirected address |
|
| 60 | + var $offsiteok = true; // allows redirection off-site |
|
| 61 | + var $maxframes = 0; // frame content depth maximum. 0 = disallow |
|
| 62 | + var $expandlinks = true; // expand links to fully qualified URLs. |
|
| 63 | 63 | // this only applies to fetchlinks() |
| 64 | 64 | // submitlinks(), and submittext() |
| 65 | - var $passcookies = true; // pass set cookies back through redirects |
|
| 65 | + var $passcookies = true; // pass set cookies back through redirects |
|
| 66 | 66 | // NOTE: this currently does not respect |
| 67 | 67 | // dates, domains or paths. |
| 68 | 68 | |
| 69 | - var $user = ""; // user for http authentication |
|
| 70 | - var $pass = ""; // password for http authentication |
|
| 69 | + var $user = ""; // user for http authentication |
|
| 70 | + var $pass = ""; // password for http authentication |
|
| 71 | 71 | |
| 72 | 72 | // http accept types |
| 73 | - var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
| 73 | + var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|
| 74 | 74 | |
| 75 | - var $results = ""; // where the content is put |
|
| 75 | + var $results = ""; // where the content is put |
|
| 76 | 76 | |
| 77 | - var $error = ""; // error messages sent here |
|
| 78 | - var $response_code = ""; // response code returned from server |
|
| 79 | - var $headers = array(); // headers returned from server sent here |
|
| 80 | - var $maxlength = 500000; // max return data length (body) |
|
| 81 | - var $read_timeout = 0; // timeout on read operations, in seconds |
|
| 77 | + var $error = ""; // error messages sent here |
|
| 78 | + var $response_code = ""; // response code returned from server |
|
| 79 | + var $headers = array(); // headers returned from server sent here |
|
| 80 | + var $maxlength = 500000; // max return data length (body) |
|
| 81 | + var $read_timeout = 0; // timeout on read operations, in seconds |
|
| 82 | 82 | // supported only since PHP 4 Beta 4 |
| 83 | 83 | // set to 0 to disallow timeouts |
| 84 | - var $timed_out = false; // if a read operation timed out |
|
| 85 | - var $status = 0; // http request status |
|
| 84 | + var $timed_out = false; // if a read operation timed out |
|
| 85 | + var $status = 0; // http request status |
|
| 86 | 86 | |
| 87 | - var $temp_dir = "/tmp"; // temporary directory that the webserver |
|
| 87 | + var $temp_dir = "/tmp"; // temporary directory that the webserver |
|
| 88 | 88 | // has permission to write to. |
| 89 | 89 | // under Windows, this should be C:\temp |
| 90 | 90 | |
| 91 | - var $curl_path = "/usr/local/bin/curl"; |
|
| 91 | + var $curl_path = "/usr/local/bin/curl"; |
|
| 92 | 92 | // Snoopy will use cURL for fetching |
| 93 | 93 | // SSL content if a full system path to |
| 94 | 94 | // the cURL binary is supplied here. |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | |
| 103 | 103 | /**** Private variables ****/ |
| 104 | 104 | |
| 105 | - var $_maxlinelen = 4096; // max line length (headers) |
|
| 105 | + var $_maxlinelen = 4096; // max line length (headers) |
|
| 106 | 106 | |
| 107 | - var $_httpmethod = "GET"; // default http request method |
|
| 108 | - var $_httpversion = "HTTP/1.0"; // default http request version |
|
| 109 | - var $_submit_method = "POST"; // default submit method |
|
| 110 | - var $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
| 111 | - var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
| 112 | - var $_redirectaddr = false; // will be set if page fetched is a redirect |
|
| 113 | - var $_redirectdepth = 0; // increments on an http redirect |
|
| 114 | - var $_frameurls = array(); // frame src urls |
|
| 115 | - var $_framedepth = 0; // increments on frame depth |
|
| 107 | + var $_httpmethod = "GET"; // default http request method |
|
| 108 | + var $_httpversion = "HTTP/1.0"; // default http request version |
|
| 109 | + var $_submit_method = "POST"; // default submit method |
|
| 110 | + var $_submit_type = "application/x-www-form-urlencoded"; // default submit type |
|
| 111 | + var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type |
|
| 112 | + var $_redirectaddr = false; // will be set if page fetched is a redirect |
|
| 113 | + var $_redirectdepth = 0; // increments on an http redirect |
|
| 114 | + var $_frameurls = array(); // frame src urls |
|
| 115 | + var $_framedepth = 0; // increments on frame depth |
|
| 116 | 116 | |
| 117 | - var $_isproxy = false; // set if using a proxy server |
|
| 118 | - var $_fp_timeout = 30; // timeout for socket connection |
|
| 117 | + var $_isproxy = false; // set if using a proxy server |
|
| 118 | + var $_fp_timeout = 30; // timeout for socket connection |
|
| 119 | 119 | |
| 120 | 120 | /*======================================================================*\ |
| 121 | 121 | Function: fetch |
@@ -131,27 +131,27 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); |
| 133 | 133 | $URI_PARTS = parse_url($URI); |
| 134 | - if (!empty($URI_PARTS["user"])) |
|
| 134 | + if ( ! empty($URI_PARTS["user"])) |
|
| 135 | 135 | $this->user = $URI_PARTS["user"]; |
| 136 | - if (!empty($URI_PARTS["pass"])) |
|
| 136 | + if ( ! empty($URI_PARTS["pass"])) |
|
| 137 | 137 | $this->pass = $URI_PARTS["pass"]; |
| 138 | 138 | if (empty($URI_PARTS["query"])) |
| 139 | 139 | $URI_PARTS["query"] = ''; |
| 140 | 140 | if (empty($URI_PARTS["path"])) |
| 141 | 141 | $URI_PARTS["path"] = ''; |
| 142 | 142 | |
| 143 | - switch(strtolower($URI_PARTS["scheme"])) |
|
| 143 | + switch (strtolower($URI_PARTS["scheme"])) |
|
| 144 | 144 | { |
| 145 | 145 | case "http": |
| 146 | 146 | $this->host = $URI_PARTS["host"]; |
| 147 | - if(!empty($URI_PARTS["port"])) |
|
| 147 | + if ( ! empty($URI_PARTS["port"])) |
|
| 148 | 148 | $this->port = $URI_PARTS["port"]; |
| 149 | - if($this->_connect($fp)) |
|
| 149 | + if ($this->_connect($fp)) |
|
| 150 | 150 | { |
| 151 | - if($this->_isproxy) |
|
| 151 | + if ($this->_isproxy) |
|
| 152 | 152 | { |
| 153 | 153 | // using proxy, send entire URI |
| 154 | - $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|
| 154 | + $this->_httprequest($URI, $fp, $URI, $this->_httpmethod); |
|
| 155 | 155 | } |
| 156 | 156 | else |
| 157 | 157 | { |
@@ -162,30 +162,30 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $this->_disconnect($fp); |
| 164 | 164 | |
| 165 | - if($this->_redirectaddr) |
|
| 165 | + if ($this->_redirectaddr) |
|
| 166 | 166 | { |
| 167 | 167 | /* url was redirected, check if we've hit the max depth */ |
| 168 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 168 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 169 | 169 | { |
| 170 | 170 | // only follow redirect if it's on this site, or offsiteok is true |
| 171 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 171 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 172 | 172 | { |
| 173 | 173 | /* follow the redirect */ |
| 174 | 174 | $this->_redirectdepth++; |
| 175 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 175 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 176 | 176 | $this->fetch($this->_redirectaddr); |
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 181 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 182 | 182 | { |
| 183 | 183 | $frameurls = $this->_frameurls; |
| 184 | 184 | $this->_frameurls = array(); |
| 185 | 185 | |
| 186 | - while(list(,$frameurl) = each($frameurls)) |
|
| 186 | + while (list(,$frameurl) = each($frameurls)) |
|
| 187 | 187 | { |
| 188 | - if($this->_framedepth < $this->maxframes) |
|
| 188 | + if ($this->_framedepth < $this->maxframes) |
|
| 189 | 189 | { |
| 190 | 190 | $this->fetch($frameurl); |
| 191 | 191 | $this->_framedepth++; |
@@ -202,18 +202,18 @@ discard block |
||
| 202 | 202 | return true; |
| 203 | 203 | break; |
| 204 | 204 | case "https": |
| 205 | - if(!$this->curl_path) |
|
| 205 | + if ( ! $this->curl_path) |
|
| 206 | 206 | return false; |
| 207 | - if(function_exists("is_executable")) |
|
| 208 | - if (!is_executable($this->curl_path)) |
|
| 207 | + if (function_exists("is_executable")) |
|
| 208 | + if ( ! is_executable($this->curl_path)) |
|
| 209 | 209 | return false; |
| 210 | 210 | $this->host = $URI_PARTS["host"]; |
| 211 | - if(!empty($URI_PARTS["port"])) |
|
| 211 | + if ( ! empty($URI_PARTS["port"])) |
|
| 212 | 212 | $this->port = $URI_PARTS["port"]; |
| 213 | - if($this->_isproxy) |
|
| 213 | + if ($this->_isproxy) |
|
| 214 | 214 | { |
| 215 | 215 | // using proxy, send entire URI |
| 216 | - $this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|
| 216 | + $this->_httpsrequest($URI, $URI, $this->_httpmethod); |
|
| 217 | 217 | } |
| 218 | 218 | else |
| 219 | 219 | { |
@@ -222,30 +222,30 @@ discard block |
||
| 222 | 222 | $this->_httpsrequest($path, $URI, $this->_httpmethod); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - if($this->_redirectaddr) |
|
| 225 | + if ($this->_redirectaddr) |
|
| 226 | 226 | { |
| 227 | 227 | /* url was redirected, check if we've hit the max depth */ |
| 228 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 228 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 229 | 229 | { |
| 230 | 230 | // only follow redirect if it's on this site, or offsiteok is true |
| 231 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 231 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 232 | 232 | { |
| 233 | 233 | /* follow the redirect */ |
| 234 | 234 | $this->_redirectdepth++; |
| 235 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 235 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 236 | 236 | $this->fetch($this->_redirectaddr); |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 241 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 242 | 242 | { |
| 243 | 243 | $frameurls = $this->_frameurls; |
| 244 | 244 | $this->_frameurls = array(); |
| 245 | 245 | |
| 246 | - while(list(,$frameurl) = each($frameurls)) |
|
| 246 | + while (list(,$frameurl) = each($frameurls)) |
|
| 247 | 247 | { |
| 248 | - if($this->_framedepth < $this->maxframes) |
|
| 248 | + if ($this->_framedepth < $this->maxframes) |
|
| 249 | 249 | { |
| 250 | 250 | $this->fetch($frameurl); |
| 251 | 251 | $this->_framedepth++; |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | break; |
| 259 | 259 | default: |
| 260 | 260 | // not a valid protocol |
| 261 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 261 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 262 | 262 | return false; |
| 263 | 263 | break; |
| 264 | 264 | } |
@@ -276,34 +276,34 @@ discard block |
||
| 276 | 276 | Output: $this->results the text output from the post |
| 277 | 277 | \*======================================================================*/ |
| 278 | 278 | |
| 279 | - function submit($URI, $formvars="", $formfiles="") |
|
| 279 | + function submit($URI, $formvars = "", $formfiles = "") |
|
| 280 | 280 | { |
| 281 | 281 | unset($postdata); |
| 282 | 282 | |
| 283 | 283 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 284 | 284 | |
| 285 | 285 | $URI_PARTS = parse_url($URI); |
| 286 | - if (!empty($URI_PARTS["user"])) |
|
| 286 | + if ( ! empty($URI_PARTS["user"])) |
|
| 287 | 287 | $this->user = $URI_PARTS["user"]; |
| 288 | - if (!empty($URI_PARTS["pass"])) |
|
| 288 | + if ( ! empty($URI_PARTS["pass"])) |
|
| 289 | 289 | $this->pass = $URI_PARTS["pass"]; |
| 290 | 290 | if (empty($URI_PARTS["query"])) |
| 291 | 291 | $URI_PARTS["query"] = ''; |
| 292 | 292 | if (empty($URI_PARTS["path"])) |
| 293 | 293 | $URI_PARTS["path"] = ''; |
| 294 | 294 | |
| 295 | - switch(strtolower($URI_PARTS["scheme"])) |
|
| 295 | + switch (strtolower($URI_PARTS["scheme"])) |
|
| 296 | 296 | { |
| 297 | 297 | case "http": |
| 298 | 298 | $this->host = $URI_PARTS["host"]; |
| 299 | - if(!empty($URI_PARTS["port"])) |
|
| 299 | + if ( ! empty($URI_PARTS["port"])) |
|
| 300 | 300 | $this->port = $URI_PARTS["port"]; |
| 301 | - if($this->_connect($fp)) |
|
| 301 | + if ($this->_connect($fp)) |
|
| 302 | 302 | { |
| 303 | - if($this->_isproxy) |
|
| 303 | + if ($this->_isproxy) |
|
| 304 | 304 | { |
| 305 | 305 | // using proxy, send entire URI |
| 306 | - $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
|
| 306 | + $this->_httprequest($URI, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|
| 307 | 307 | } |
| 308 | 308 | else |
| 309 | 309 | { |
@@ -314,36 +314,36 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | $this->_disconnect($fp); |
| 316 | 316 | |
| 317 | - if($this->_redirectaddr) |
|
| 317 | + if ($this->_redirectaddr) |
|
| 318 | 318 | { |
| 319 | 319 | /* url was redirected, check if we've hit the max depth */ |
| 320 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 320 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 321 | 321 | { |
| 322 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 322 | + if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 323 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 324 | 324 | |
| 325 | 325 | // only follow redirect if it's on this site, or offsiteok is true |
| 326 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 326 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 327 | 327 | { |
| 328 | 328 | /* follow the redirect */ |
| 329 | 329 | $this->_redirectdepth++; |
| 330 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 331 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 330 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 331 | + if (strpos($this->_redirectaddr, "?") > 0) |
|
| 332 | 332 | $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
| 333 | 333 | else |
| 334 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 334 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 339 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 340 | 340 | { |
| 341 | 341 | $frameurls = $this->_frameurls; |
| 342 | 342 | $this->_frameurls = array(); |
| 343 | 343 | |
| 344 | - while(list(,$frameurl) = each($frameurls)) |
|
| 344 | + while (list(,$frameurl) = each($frameurls)) |
|
| 345 | 345 | { |
| 346 | - if($this->_framedepth < $this->maxframes) |
|
| 346 | + if ($this->_framedepth < $this->maxframes) |
|
| 347 | 347 | { |
| 348 | 348 | $this->fetch($frameurl); |
| 349 | 349 | $this->_framedepth++; |
@@ -361,15 +361,15 @@ discard block |
||
| 361 | 361 | return true; |
| 362 | 362 | break; |
| 363 | 363 | case "https": |
| 364 | - if(!$this->curl_path) |
|
| 364 | + if ( ! $this->curl_path) |
|
| 365 | 365 | return false; |
| 366 | - if(function_exists("is_executable")) |
|
| 367 | - if (!is_executable($this->curl_path)) |
|
| 366 | + if (function_exists("is_executable")) |
|
| 367 | + if ( ! is_executable($this->curl_path)) |
|
| 368 | 368 | return false; |
| 369 | 369 | $this->host = $URI_PARTS["host"]; |
| 370 | - if(!empty($URI_PARTS["port"])) |
|
| 370 | + if ( ! empty($URI_PARTS["port"])) |
|
| 371 | 371 | $this->port = $URI_PARTS["port"]; |
| 372 | - if($this->_isproxy) |
|
| 372 | + if ($this->_isproxy) |
|
| 373 | 373 | { |
| 374 | 374 | // using proxy, send entire URI |
| 375 | 375 | $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
@@ -381,36 +381,36 @@ discard block |
||
| 381 | 381 | $this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - if($this->_redirectaddr) |
|
| 384 | + if ($this->_redirectaddr) |
|
| 385 | 385 | { |
| 386 | 386 | /* url was redirected, check if we've hit the max depth */ |
| 387 | - if($this->maxredirs > $this->_redirectdepth) |
|
| 387 | + if ($this->maxredirs > $this->_redirectdepth) |
|
| 388 | 388 | { |
| 389 | - if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 389 | + if ( ! preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|
| 390 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|
| 391 | 391 | |
| 392 | 392 | // only follow redirect if it's on this site, or offsiteok is true |
| 393 | - if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|
| 393 | + if (preg_match("|^http://".preg_quote($this->host)."|i", $this->_redirectaddr) || $this->offsiteok) |
|
| 394 | 394 | { |
| 395 | 395 | /* follow the redirect */ |
| 396 | 396 | $this->_redirectdepth++; |
| 397 | - $this->lastredirectaddr=$this->_redirectaddr; |
|
| 398 | - if( strpos( $this->_redirectaddr, "?" ) > 0 ) |
|
| 397 | + $this->lastredirectaddr = $this->_redirectaddr; |
|
| 398 | + if (strpos($this->_redirectaddr, "?") > 0) |
|
| 399 | 399 | $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
| 400 | 400 | else |
| 401 | - $this->submit($this->_redirectaddr,$formvars, $formfiles); |
|
| 401 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 402 | 402 | } |
| 403 | 403 | } |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 406 | + if ($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|
| 407 | 407 | { |
| 408 | 408 | $frameurls = $this->_frameurls; |
| 409 | 409 | $this->_frameurls = array(); |
| 410 | 410 | |
| 411 | - while(list(,$frameurl) = each($frameurls)) |
|
| 411 | + while (list(,$frameurl) = each($frameurls)) |
|
| 412 | 412 | { |
| 413 | - if($this->_framedepth < $this->maxframes) |
|
| 413 | + if ($this->_framedepth < $this->maxframes) |
|
| 414 | 414 | { |
| 415 | 415 | $this->fetch($frameurl); |
| 416 | 416 | $this->_framedepth++; |
@@ -424,7 +424,7 @@ discard block |
||
| 424 | 424 | |
| 425 | 425 | default: |
| 426 | 426 | // not a valid protocol |
| 427 | - $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 427 | + $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|
| 428 | 428 | return false; |
| 429 | 429 | break; |
| 430 | 430 | } |
@@ -442,17 +442,17 @@ discard block |
||
| 442 | 442 | { |
| 443 | 443 | if ($this->fetch($URI)) |
| 444 | 444 | { |
| 445 | - if($this->lastredirectaddr) |
|
| 445 | + if ($this->lastredirectaddr) |
|
| 446 | 446 | $URI = $this->lastredirectaddr; |
| 447 | - if(is_array($this->results)) |
|
| 447 | + if (is_array($this->results)) |
|
| 448 | 448 | { |
| 449 | - for($x=0;$x<count($this->results);$x++) |
|
| 449 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 450 | 450 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 451 | 451 | } |
| 452 | 452 | else |
| 453 | 453 | $this->results = $this->_striplinks($this->results); |
| 454 | 454 | |
| 455 | - if($this->expandlinks) |
|
| 455 | + if ($this->expandlinks) |
|
| 456 | 456 | $this->results = $this->_expandlinks($this->results, $URI); |
| 457 | 457 | return true; |
| 458 | 458 | } |
@@ -473,9 +473,9 @@ discard block |
||
| 473 | 473 | if ($this->fetch($URI)) |
| 474 | 474 | { |
| 475 | 475 | |
| 476 | - if(is_array($this->results)) |
|
| 476 | + if (is_array($this->results)) |
|
| 477 | 477 | { |
| 478 | - for($x=0;$x<count($this->results);$x++) |
|
| 478 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 479 | 479 | $this->results[$x] = $this->_stripform($this->results[$x]); |
| 480 | 480 | } |
| 481 | 481 | else |
@@ -497,11 +497,11 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | function fetchtext($URI) |
| 499 | 499 | { |
| 500 | - if($this->fetch($URI)) |
|
| 500 | + if ($this->fetch($URI)) |
|
| 501 | 501 | { |
| 502 | - if(is_array($this->results)) |
|
| 502 | + if (is_array($this->results)) |
|
| 503 | 503 | { |
| 504 | - for($x=0;$x<count($this->results);$x++) |
|
| 504 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 505 | 505 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 506 | 506 | } |
| 507 | 507 | else |
@@ -519,26 +519,26 @@ discard block |
||
| 519 | 519 | Output: $this->results an array of the links from the post |
| 520 | 520 | \*======================================================================*/ |
| 521 | 521 | |
| 522 | - function submitlinks($URI, $formvars="", $formfiles="") |
|
| 522 | + function submitlinks($URI, $formvars = "", $formfiles = "") |
|
| 523 | 523 | { |
| 524 | - if($this->submit($URI,$formvars, $formfiles)) |
|
| 524 | + if ($this->submit($URI, $formvars, $formfiles)) |
|
| 525 | 525 | { |
| 526 | - if($this->lastredirectaddr) |
|
| 526 | + if ($this->lastredirectaddr) |
|
| 527 | 527 | $URI = $this->lastredirectaddr; |
| 528 | - if(is_array($this->results)) |
|
| 528 | + if (is_array($this->results)) |
|
| 529 | 529 | { |
| 530 | - for($x=0;$x<count($this->results);$x++) |
|
| 530 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 531 | 531 | { |
| 532 | 532 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 533 | - if($this->expandlinks) |
|
| 534 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 533 | + if ($this->expandlinks) |
|
| 534 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 535 | 535 | } |
| 536 | 536 | } |
| 537 | 537 | else |
| 538 | 538 | { |
| 539 | 539 | $this->results = $this->_striplinks($this->results); |
| 540 | - if($this->expandlinks) |
|
| 541 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 540 | + if ($this->expandlinks) |
|
| 541 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 542 | 542 | } |
| 543 | 543 | return true; |
| 544 | 544 | } |
@@ -555,24 +555,24 @@ discard block |
||
| 555 | 555 | |
| 556 | 556 | function submittext($URI, $formvars = "", $formfiles = "") |
| 557 | 557 | { |
| 558 | - if($this->submit($URI,$formvars, $formfiles)) |
|
| 558 | + if ($this->submit($URI, $formvars, $formfiles)) |
|
| 559 | 559 | { |
| 560 | - if($this->lastredirectaddr) |
|
| 560 | + if ($this->lastredirectaddr) |
|
| 561 | 561 | $URI = $this->lastredirectaddr; |
| 562 | - if(is_array($this->results)) |
|
| 562 | + if (is_array($this->results)) |
|
| 563 | 563 | { |
| 564 | - for($x=0;$x<count($this->results);$x++) |
|
| 564 | + for ($x = 0; $x < count($this->results); $x++) |
|
| 565 | 565 | { |
| 566 | 566 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 567 | - if($this->expandlinks) |
|
| 568 | - $this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|
| 567 | + if ($this->expandlinks) |
|
| 568 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | else |
| 572 | 572 | { |
| 573 | 573 | $this->results = $this->_striptext($this->results); |
| 574 | - if($this->expandlinks) |
|
| 575 | - $this->results = $this->_expandlinks($this->results,$URI); |
|
| 574 | + if ($this->expandlinks) |
|
| 575 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 576 | 576 | } |
| 577 | 577 | return true; |
| 578 | 578 | } |
@@ -624,20 +624,20 @@ discard block |
||
| 624 | 624 | ([\"\'])? # find single or double quote |
| 625 | 625 | (?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching |
| 626 | 626 | # quote, otherwise match up to next space |
| 627 | - 'isx",$document,$links); |
|
| 627 | + 'isx",$document, $links); |
|
| 628 | 628 | |
| 629 | 629 | |
| 630 | 630 | // catenate the non-empty matches from the conditional subpattern |
| 631 | 631 | |
| 632 | - while(list($key,$val) = each($links[2])) |
|
| 632 | + while (list($key, $val) = each($links[2])) |
|
| 633 | 633 | { |
| 634 | - if(!empty($val)) |
|
| 634 | + if ( ! empty($val)) |
|
| 635 | 635 | $match[] = $val; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - while(list($key,$val) = each($links[3])) |
|
| 638 | + while (list($key, $val) = each($links[3])) |
|
| 639 | 639 | { |
| 640 | - if(!empty($val)) |
|
| 640 | + if ( ! empty($val)) |
|
| 641 | 641 | $match[] = $val; |
| 642 | 642 | } |
| 643 | 643 | |
@@ -654,10 +654,10 @@ discard block |
||
| 654 | 654 | |
| 655 | 655 | function _stripform($document) |
| 656 | 656 | { |
| 657 | - preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|
| 657 | + preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi", $document, $elements); |
|
| 658 | 658 | |
| 659 | 659 | // catenate the matches |
| 660 | - $match = implode("\r\n",$elements[0]); |
|
| 660 | + $match = implode("\r\n", $elements[0]); |
|
| 661 | 661 | |
| 662 | 662 | // return the links |
| 663 | 663 | return $match; |
@@ -679,11 +679,11 @@ discard block |
||
| 679 | 679 | // so, list your entities one by one here. I included some of the |
| 680 | 680 | // more common ones. |
| 681 | 681 | |
| 682 | - $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
| 683 | - "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
| 684 | - "'([\r\n])[\s]+'", // strip out white space |
|
| 685 | - "'&(quot|#34|#034|#x22);'i", // replace html entities |
|
| 686 | - "'&(amp|#38|#038|#x26);'i", // added hexadecimal values |
|
| 682 | + $search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript |
|
| 683 | + "'<[\/\!]*?[^<>]*?>'si", // strip out html tags |
|
| 684 | + "'([\r\n])[\s]+'", // strip out white space |
|
| 685 | + "'&(quot|#34|#034|#x22);'i", // replace html entities |
|
| 686 | + "'&(amp|#38|#038|#x26);'i", // added hexadecimal values |
|
| 687 | 687 | "'&(lt|#60|#060|#x3c);'i", |
| 688 | 688 | "'&(gt|#62|#062|#x3e);'i", |
| 689 | 689 | "'&(nbsp|#160|#xa0);'i", |
@@ -694,8 +694,8 @@ discard block |
||
| 694 | 694 | "'&(reg|#174);'i", |
| 695 | 695 | "'&(deg|#176);'i", |
| 696 | 696 | "'&(#39|#039|#x27);'", |
| 697 | - "'&(euro|#8364);'i", // europe |
|
| 698 | - "'&a(uml|UML);'", // german |
|
| 697 | + "'&(euro|#8364);'i", // europe |
|
| 698 | + "'&a(uml|UML);'", // german |
|
| 699 | 699 | "'&o(uml|UML);'", |
| 700 | 700 | "'&u(uml|UML);'", |
| 701 | 701 | "'&A(uml|UML);'", |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | "'&U(uml|UML);'", |
| 704 | 704 | "'ß'i", |
| 705 | 705 | ); |
| 706 | - $replace = array( "", |
|
| 706 | + $replace = array("", |
|
| 707 | 707 | "", |
| 708 | 708 | "\\1", |
| 709 | 709 | "\"", |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | chr(0xDF), // ANSI ß |
| 729 | 729 | ); |
| 730 | 730 | |
| 731 | - $text = preg_replace($search,$replace,$document); |
|
| 731 | + $text = preg_replace($search, $replace, $document); |
|
| 732 | 732 | |
| 733 | 733 | return $text; |
| 734 | 734 | } |
@@ -741,32 +741,32 @@ discard block |
||
| 741 | 741 | Output: $expandedLinks the expanded links |
| 742 | 742 | \*======================================================================*/ |
| 743 | 743 | |
| 744 | - function _expandlinks($links,$URI) |
|
| 744 | + function _expandlinks($links, $URI) |
|
| 745 | 745 | { |
| 746 | 746 | |
| 747 | - preg_match("/^[^\?]+/",$URI,$match); |
|
| 747 | + preg_match("/^[^\?]+/", $URI, $match); |
|
| 748 | 748 | |
| 749 | - $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); |
|
| 750 | - $match = preg_replace("|/$|","",$match); |
|
| 749 | + $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|", "", $match[0]); |
|
| 750 | + $match = preg_replace("|/$|", "", $match); |
|
| 751 | 751 | $match_part = parse_url($match); |
| 752 | 752 | $match_root = |
| 753 | 753 | $match_part["scheme"]."://".$match_part["host"]; |
| 754 | 754 | |
| 755 | - $search = array( "|^http://".preg_quote($this->host)."|i", |
|
| 755 | + $search = array("|^http://".preg_quote($this->host)."|i", |
|
| 756 | 756 | "|^(\/)|i", |
| 757 | 757 | "|^(?!http://)(?!mailto:)|i", |
| 758 | 758 | "|/\./|", |
| 759 | 759 | "|/[^\/]+/\.\./|" |
| 760 | 760 | ); |
| 761 | 761 | |
| 762 | - $replace = array( "", |
|
| 762 | + $replace = array("", |
|
| 763 | 763 | $match_root."/", |
| 764 | 764 | $match."/", |
| 765 | 765 | "/", |
| 766 | 766 | "/" |
| 767 | 767 | ); |
| 768 | 768 | |
| 769 | - $expandedLinks = preg_replace($search,$replace,$links); |
|
| 769 | + $expandedLinks = preg_replace($search, $replace, $links); |
|
| 770 | 770 | |
| 771 | 771 | return $expandedLinks; |
| 772 | 772 | } |
@@ -781,63 +781,63 @@ discard block |
||
| 781 | 781 | Output: |
| 782 | 782 | \*======================================================================*/ |
| 783 | 783 | |
| 784 | - function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|
| 784 | + function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
|
| 785 | 785 | { |
| 786 | 786 | $cookie_headers = ''; |
| 787 | - if($this->passcookies && $this->_redirectaddr) |
|
| 787 | + if ($this->passcookies && $this->_redirectaddr) |
|
| 788 | 788 | $this->setcookies(); |
| 789 | 789 | |
| 790 | 790 | $URI_PARTS = parse_url($URI); |
| 791 | - if(empty($url)) |
|
| 791 | + if (empty($url)) |
|
| 792 | 792 | $url = "/"; |
| 793 | 793 | $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
| 794 | - if(!empty($this->agent)) |
|
| 794 | + if ( ! empty($this->agent)) |
|
| 795 | 795 | $headers .= "User-Agent: ".$this->agent."\r\n"; |
| 796 | - if(!empty($this->host) && !isset($this->rawheaders['Host'])) { |
|
| 796 | + if ( ! empty($this->host) && ! isset($this->rawheaders['Host'])) { |
|
| 797 | 797 | $headers .= "Host: ".$this->host; |
| 798 | - if(!empty($this->port) && $this->port != 80) |
|
| 798 | + if ( ! empty($this->port) && $this->port != 80) |
|
| 799 | 799 | $headers .= ":".$this->port; |
| 800 | 800 | $headers .= "\r\n"; |
| 801 | 801 | } |
| 802 | - if(!empty($this->accept)) |
|
| 802 | + if ( ! empty($this->accept)) |
|
| 803 | 803 | $headers .= "Accept: ".$this->accept."\r\n"; |
| 804 | - if(!empty($this->referer)) |
|
| 804 | + if ( ! empty($this->referer)) |
|
| 805 | 805 | $headers .= "Referer: ".$this->referer."\r\n"; |
| 806 | - if(!empty($this->cookies)) |
|
| 806 | + if ( ! empty($this->cookies)) |
|
| 807 | 807 | { |
| 808 | - if(!is_array($this->cookies)) |
|
| 809 | - $this->cookies = (array)$this->cookies; |
|
| 808 | + if ( ! is_array($this->cookies)) |
|
| 809 | + $this->cookies = (array) $this->cookies; |
|
| 810 | 810 | |
| 811 | 811 | reset($this->cookies); |
| 812 | - if ( count($this->cookies) > 0 ) { |
|
| 812 | + if (count($this->cookies) > 0) { |
|
| 813 | 813 | $cookie_headers .= 'Cookie: '; |
| 814 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
| 814 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
| 815 | 815 | $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
| 816 | 816 | } |
| 817 | - $headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|
| 817 | + $headers .= substr($cookie_headers, 0, -2)."\r\n"; |
|
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - if(!empty($this->rawheaders)) |
|
| 820 | + if ( ! empty($this->rawheaders)) |
|
| 821 | 821 | { |
| 822 | - if(!is_array($this->rawheaders)) |
|
| 823 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 824 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 822 | + if ( ! is_array($this->rawheaders)) |
|
| 823 | + $this->rawheaders = (array) $this->rawheaders; |
|
| 824 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 825 | 825 | $headers .= $headerKey.": ".$headerVal."\r\n"; |
| 826 | 826 | } |
| 827 | - if(!empty($content_type)) { |
|
| 827 | + if ( ! empty($content_type)) { |
|
| 828 | 828 | $headers .= "Content-type: $content_type"; |
| 829 | 829 | if ($content_type == "multipart/form-data") |
| 830 | 830 | $headers .= "; boundary=".$this->_mime_boundary; |
| 831 | 831 | $headers .= "\r\n"; |
| 832 | 832 | } |
| 833 | - if(!empty($body)) |
|
| 833 | + if ( ! empty($body)) |
|
| 834 | 834 | $headers .= "Content-length: ".strlen($body)."\r\n"; |
| 835 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 835 | + if ( ! empty($this->user) || ! empty($this->pass)) |
|
| 836 | 836 | $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
| 837 | 837 | |
| 838 | 838 | //add proxy auth headers |
| 839 | - if(!empty($this->proxy_user)) |
|
| 840 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|
| 839 | + if ( ! empty($this->proxy_user)) |
|
| 840 | + $headers .= 'Proxy-Authorization: '.'Basic '.base64_encode($this->proxy_user.':'.$this->proxy_pass)."\r\n"; |
|
| 841 | 841 | |
| 842 | 842 | |
| 843 | 843 | $headers .= "\r\n"; |
@@ -847,34 +847,34 @@ discard block |
||
| 847 | 847 | socket_set_timeout($fp, $this->read_timeout); |
| 848 | 848 | $this->timed_out = false; |
| 849 | 849 | |
| 850 | - fwrite($fp,$headers.$body,strlen($headers.$body)); |
|
| 850 | + fwrite($fp, $headers.$body, strlen($headers.$body)); |
|
| 851 | 851 | |
| 852 | 852 | $this->_redirectaddr = false; |
| 853 | 853 | unset($this->headers); |
| 854 | 854 | |
| 855 | - while($currentHeader = fgets($fp,$this->_maxlinelen)) |
|
| 855 | + while ($currentHeader = fgets($fp, $this->_maxlinelen)) |
|
| 856 | 856 | { |
| 857 | 857 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
| 858 | 858 | { |
| 859 | - $this->status=-100; |
|
| 859 | + $this->status = -100; |
|
| 860 | 860 | return false; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - if($currentHeader == "\r\n") |
|
| 863 | + if ($currentHeader == "\r\n") |
|
| 864 | 864 | break; |
| 865 | 865 | |
| 866 | 866 | // if a header begins with Location: or URI:, set the redirect |
| 867 | - if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|
| 867 | + if (preg_match("/^(Location:|URI:)/i", $currentHeader)) |
|
| 868 | 868 | { |
| 869 | 869 | // get URL portion of the redirect |
| 870 | - preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches); |
|
| 870 | + preg_match("/^(Location:|URI:)[ ]+(.*)/i", chop($currentHeader), $matches); |
|
| 871 | 871 | // look for :// in the Location header to see if hostname is included |
| 872 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
| 872 | + if ( ! preg_match("|\:\/\/|", $matches[2])) |
|
| 873 | 873 | { |
| 874 | 874 | // no host in the path, so prepend |
| 875 | 875 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 876 | 876 | // eliminate double slash |
| 877 | - if(!preg_match("|^/|",$matches[2])) |
|
| 877 | + if ( ! preg_match("|^/|", $matches[2])) |
|
| 878 | 878 | $this->_redirectaddr .= "/".$matches[2]; |
| 879 | 879 | else |
| 880 | 880 | $this->_redirectaddr .= $matches[2]; |
@@ -883,11 +883,11 @@ discard block |
||
| 883 | 883 | $this->_redirectaddr = $matches[2]; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - if(preg_match("|^HTTP/|",$currentHeader)) |
|
| 886 | + if (preg_match("|^HTTP/|", $currentHeader)) |
|
| 887 | 887 | { |
| 888 | - if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|
| 888 | + if (preg_match("|^HTTP/[^\s]*\s(.*?)\s|", $currentHeader, $status)) |
|
| 889 | 889 | { |
| 890 | - $this->status= $status[1]; |
|
| 890 | + $this->status = $status[1]; |
|
| 891 | 891 | } |
| 892 | 892 | $this->response_code = $currentHeader; |
| 893 | 893 | } |
@@ -902,31 +902,31 @@ discard block |
||
| 902 | 902 | break; |
| 903 | 903 | } |
| 904 | 904 | $results .= $_data; |
| 905 | - } while(true); |
|
| 905 | + } while (true); |
|
| 906 | 906 | |
| 907 | 907 | if ($this->read_timeout > 0 && $this->_check_timeout($fp)) |
| 908 | 908 | { |
| 909 | - $this->status=-100; |
|
| 909 | + $this->status = -100; |
|
| 910 | 910 | return false; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | // check if there is a redirect meta tag |
| 914 | 914 | |
| 915 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
| 915 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
| 916 | 916 | |
| 917 | 917 | { |
| 918 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
| 918 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | // have we hit our frame depth and is there frame src to fetch? |
| 922 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
| 922 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
| 923 | 923 | { |
| 924 | 924 | $this->results[] = $results; |
| 925 | - for($x=0; $x<count($match[1]); $x++) |
|
| 926 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 925 | + for ($x = 0; $x < count($match[1]); $x++) |
|
| 926 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
| 927 | 927 | } |
| 928 | 928 | // have we already fetched framed content? |
| 929 | - elseif(is_array($this->results)) |
|
| 929 | + elseif (is_array($this->results)) |
|
| 930 | 930 | $this->results[] = $results; |
| 931 | 931 | // no framed content |
| 932 | 932 | else |
@@ -944,108 +944,108 @@ discard block |
||
| 944 | 944 | Output: |
| 945 | 945 | \*======================================================================*/ |
| 946 | 946 | |
| 947 | - function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|
| 947 | + function _httpsrequest($url, $URI, $http_method, $content_type = "", $body = "") |
|
| 948 | 948 | { |
| 949 | - if($this->passcookies && $this->_redirectaddr) |
|
| 949 | + if ($this->passcookies && $this->_redirectaddr) |
|
| 950 | 950 | $this->setcookies(); |
| 951 | 951 | |
| 952 | 952 | $headers = array(); |
| 953 | 953 | |
| 954 | 954 | $URI_PARTS = parse_url($URI); |
| 955 | - if(empty($url)) |
|
| 955 | + if (empty($url)) |
|
| 956 | 956 | $url = "/"; |
| 957 | 957 | // GET ... header not needed for curl |
| 958 | 958 | //$headers[] = $http_method." ".$url." ".$this->_httpversion; |
| 959 | - if(!empty($this->agent)) |
|
| 959 | + if ( ! empty($this->agent)) |
|
| 960 | 960 | $headers[] = "User-Agent: ".$this->agent; |
| 961 | - if(!empty($this->host)) |
|
| 962 | - if(!empty($this->port)) |
|
| 961 | + if ( ! empty($this->host)) |
|
| 962 | + if ( ! empty($this->port)) |
|
| 963 | 963 | $headers[] = "Host: ".$this->host.":".$this->port; |
| 964 | 964 | else |
| 965 | 965 | $headers[] = "Host: ".$this->host; |
| 966 | - if(!empty($this->accept)) |
|
| 966 | + if ( ! empty($this->accept)) |
|
| 967 | 967 | $headers[] = "Accept: ".$this->accept; |
| 968 | - if(!empty($this->referer)) |
|
| 968 | + if ( ! empty($this->referer)) |
|
| 969 | 969 | $headers[] = "Referer: ".$this->referer; |
| 970 | - if(!empty($this->cookies)) |
|
| 970 | + if ( ! empty($this->cookies)) |
|
| 971 | 971 | { |
| 972 | - if(!is_array($this->cookies)) |
|
| 973 | - $this->cookies = (array)$this->cookies; |
|
| 972 | + if ( ! is_array($this->cookies)) |
|
| 973 | + $this->cookies = (array) $this->cookies; |
|
| 974 | 974 | |
| 975 | 975 | reset($this->cookies); |
| 976 | - if ( count($this->cookies) > 0 ) { |
|
| 976 | + if (count($this->cookies) > 0) { |
|
| 977 | 977 | $cookie_str = 'Cookie: '; |
| 978 | - foreach ( $this->cookies as $cookieKey => $cookieVal ) { |
|
| 978 | + foreach ($this->cookies as $cookieKey => $cookieVal) { |
|
| 979 | 979 | $cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
| 980 | 980 | } |
| 981 | - $headers[] = substr($cookie_str,0,-2); |
|
| 981 | + $headers[] = substr($cookie_str, 0, -2); |
|
| 982 | 982 | } |
| 983 | 983 | } |
| 984 | - if(!empty($this->rawheaders)) |
|
| 984 | + if ( ! empty($this->rawheaders)) |
|
| 985 | 985 | { |
| 986 | - if(!is_array($this->rawheaders)) |
|
| 987 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 988 | - while(list($headerKey,$headerVal) = each($this->rawheaders)) |
|
| 986 | + if ( ! is_array($this->rawheaders)) |
|
| 987 | + $this->rawheaders = (array) $this->rawheaders; |
|
| 988 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 989 | 989 | $headers[] = $headerKey.": ".$headerVal; |
| 990 | 990 | } |
| 991 | - if(!empty($content_type)) { |
|
| 991 | + if ( ! empty($content_type)) { |
|
| 992 | 992 | if ($content_type == "multipart/form-data") |
| 993 | 993 | $headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
| 994 | 994 | else |
| 995 | 995 | $headers[] = "Content-type: $content_type"; |
| 996 | 996 | } |
| 997 | - if(!empty($body)) |
|
| 997 | + if ( ! empty($body)) |
|
| 998 | 998 | $headers[] = "Content-length: ".strlen($body); |
| 999 | - if(!empty($this->user) || !empty($this->pass)) |
|
| 999 | + if ( ! empty($this->user) || ! empty($this->pass)) |
|
| 1000 | 1000 | $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
| 1001 | 1001 | |
| 1002 | - $headerfile = tempnam( $this->temp_dir, "sno" ); |
|
| 1003 | - $cmdline_params = '-k -D ' . escapeshellarg( $headerfile ); |
|
| 1002 | + $headerfile = tempnam($this->temp_dir, "sno"); |
|
| 1003 | + $cmdline_params = '-k -D '.escapeshellarg($headerfile); |
|
| 1004 | 1004 | |
| 1005 | - foreach ( $headers as $header ) { |
|
| 1006 | - $cmdline_params .= ' -H ' . escapeshellarg( $header ); |
|
| 1005 | + foreach ($headers as $header) { |
|
| 1006 | + $cmdline_params .= ' -H '.escapeshellarg($header); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if ( ! empty( $body ) ) { |
|
| 1010 | - $cmdline_params .= ' -d ' . escapeshellarg( $body ); |
|
| 1009 | + if ( ! empty($body)) { |
|
| 1010 | + $cmdline_params .= ' -d '.escapeshellarg($body); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | - if ( $this->read_timeout > 0 ) { |
|
| 1014 | - $cmdline_params .= ' -m ' . escapeshellarg( $this->read_timeout ); |
|
| 1013 | + if ($this->read_timeout > 0) { |
|
| 1014 | + $cmdline_params .= ' -m '.escapeshellarg($this->read_timeout); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | |
| 1018 | - exec( $this->curl_path . ' ' . $cmdline_params . ' ' . escapeshellarg( $URI ), $results, $return ); |
|
| 1018 | + exec($this->curl_path.' '.$cmdline_params.' '.escapeshellarg($URI), $results, $return); |
|
| 1019 | 1019 | |
| 1020 | - if($return) |
|
| 1020 | + if ($return) |
|
| 1021 | 1021 | { |
| 1022 | 1022 | $this->error = "Error: cURL could not retrieve the document, error $return."; |
| 1023 | 1023 | return false; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
| 1027 | - $results = implode("\r\n",$results); |
|
| 1027 | + $results = implode("\r\n", $results); |
|
| 1028 | 1028 | |
| 1029 | 1029 | $result_headers = file("$headerfile"); |
| 1030 | 1030 | |
| 1031 | 1031 | $this->_redirectaddr = false; |
| 1032 | 1032 | unset($this->headers); |
| 1033 | 1033 | |
| 1034 | - for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
| 1034 | + for ($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|
| 1035 | 1035 | { |
| 1036 | 1036 | |
| 1037 | 1037 | // if a header begins with Location: or URI:, set the redirect |
| 1038 | - if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|
| 1038 | + if (preg_match("/^(Location: |URI: )/i", $result_headers[$currentHeader])) |
|
| 1039 | 1039 | { |
| 1040 | 1040 | // get URL portion of the redirect |
| 1041 | - preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches); |
|
| 1041 | + preg_match("/^(Location: |URI:)\s+(.*)/", chop($result_headers[$currentHeader]), $matches); |
|
| 1042 | 1042 | // look for :// in the Location header to see if hostname is included |
| 1043 | - if(!preg_match("|\:\/\/|",$matches[2])) |
|
| 1043 | + if ( ! preg_match("|\:\/\/|", $matches[2])) |
|
| 1044 | 1044 | { |
| 1045 | 1045 | // no host in the path, so prepend |
| 1046 | 1046 | $this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
| 1047 | 1047 | // eliminate double slash |
| 1048 | - if(!preg_match("|^/|",$matches[2])) |
|
| 1048 | + if ( ! preg_match("|^/|", $matches[2])) |
|
| 1049 | 1049 | $this->_redirectaddr .= "/".$matches[2]; |
| 1050 | 1050 | else |
| 1051 | 1051 | $this->_redirectaddr .= $matches[2]; |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | $this->_redirectaddr = $matches[2]; |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|
| 1057 | + if (preg_match("|^HTTP/|", $result_headers[$currentHeader])) |
|
| 1058 | 1058 | $this->response_code = $result_headers[$currentHeader]; |
| 1059 | 1059 | |
| 1060 | 1060 | $this->headers[] = $result_headers[$currentHeader]; |
@@ -1062,20 +1062,20 @@ discard block |
||
| 1062 | 1062 | |
| 1063 | 1063 | // check if there is a redirect meta tag |
| 1064 | 1064 | |
| 1065 | - if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|
| 1065 | + if (preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i", $results, $match)) |
|
| 1066 | 1066 | { |
| 1067 | - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|
| 1067 | + $this->_redirectaddr = $this->_expandlinks($match[1], $URI); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | // have we hit our frame depth and is there frame src to fetch? |
| 1071 | - if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|
| 1071 | + if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) |
|
| 1072 | 1072 | { |
| 1073 | 1073 | $this->results[] = $results; |
| 1074 | - for($x=0; $x<count($match[1]); $x++) |
|
| 1075 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|
| 1074 | + for ($x = 0; $x < count($match[1]); $x++) |
|
| 1075 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"]."://".$this->host); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | // have we already fetched framed content? |
| 1078 | - elseif(is_array($this->results)) |
|
| 1078 | + elseif (is_array($this->results)) |
|
| 1079 | 1079 | $this->results[] = $results; |
| 1080 | 1080 | // no framed content |
| 1081 | 1081 | else |
@@ -1093,9 +1093,9 @@ discard block |
||
| 1093 | 1093 | |
| 1094 | 1094 | function setcookies() |
| 1095 | 1095 | { |
| 1096 | - for($x=0; $x<count($this->headers); $x++) |
|
| 1096 | + for ($x = 0; $x < count($this->headers); $x++) |
|
| 1097 | 1097 | { |
| 1098 | - if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) |
|
| 1098 | + if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) |
|
| 1099 | 1099 | $this->cookies[$match[1]] = urldecode($match[2]); |
| 1100 | 1100 | } |
| 1101 | 1101 | } |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | |
| 1128 | 1128 | function _connect(&$fp) |
| 1129 | 1129 | { |
| 1130 | - if(!empty($this->proxy_host) && !empty($this->proxy_port)) |
|
| 1130 | + if ( ! empty($this->proxy_host) && ! empty($this->proxy_port)) |
|
| 1131 | 1131 | { |
| 1132 | 1132 | $this->_isproxy = true; |
| 1133 | 1133 | |
@@ -1142,7 +1142,7 @@ discard block |
||
| 1142 | 1142 | |
| 1143 | 1143 | $this->status = 0; |
| 1144 | 1144 | |
| 1145 | - if($fp = fsockopen( |
|
| 1145 | + if ($fp = fsockopen( |
|
| 1146 | 1146 | $host, |
| 1147 | 1147 | $port, |
| 1148 | 1148 | $errno, |
@@ -1158,16 +1158,16 @@ discard block |
||
| 1158 | 1158 | { |
| 1159 | 1159 | // socket connection failed |
| 1160 | 1160 | $this->status = $errno; |
| 1161 | - switch($errno) |
|
| 1161 | + switch ($errno) |
|
| 1162 | 1162 | { |
| 1163 | 1163 | case -3: |
| 1164 | - $this->error="socket creation failed (-3)"; |
|
| 1164 | + $this->error = "socket creation failed (-3)"; |
|
| 1165 | 1165 | case -4: |
| 1166 | - $this->error="dns lookup failure (-4)"; |
|
| 1166 | + $this->error = "dns lookup failure (-4)"; |
|
| 1167 | 1167 | case -5: |
| 1168 | - $this->error="connection refused or timed out (-5)"; |
|
| 1168 | + $this->error = "connection refused or timed out (-5)"; |
|
| 1169 | 1169 | default: |
| 1170 | - $this->error="connection failed (".$errno.")"; |
|
| 1170 | + $this->error = "connection failed (".$errno.")"; |
|
| 1171 | 1171 | } |
| 1172 | 1172 | return false; |
| 1173 | 1173 | } |
@@ -1204,7 +1204,7 @@ discard block |
||
| 1204 | 1204 | switch ($this->_submit_type) { |
| 1205 | 1205 | case "application/x-www-form-urlencoded": |
| 1206 | 1206 | reset($formvars); |
| 1207 | - while(list($key,$val) = each($formvars)) { |
|
| 1207 | + while (list($key, $val) = each($formvars)) { |
|
| 1208 | 1208 | if (is_array($val) || is_object($val)) { |
| 1209 | 1209 | while (list($cur_key, $cur_val) = each($val)) { |
| 1210 | 1210 | $postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
@@ -1218,7 +1218,7 @@ discard block |
||
| 1218 | 1218 | $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
| 1219 | 1219 | |
| 1220 | 1220 | reset($formvars); |
| 1221 | - while(list($key,$val) = each($formvars)) { |
|
| 1221 | + while (list($key, $val) = each($formvars)) { |
|
| 1222 | 1222 | if (is_array($val) || is_object($val)) { |
| 1223 | 1223 | while (list($cur_key, $cur_val) = each($val)) { |
| 1224 | 1224 | $postdata .= "--".$this->_mime_boundary."\r\n"; |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | while (list($field_name, $file_names) = each($formfiles)) { |
| 1237 | 1237 | settype($file_names, "array"); |
| 1238 | 1238 | while (list(, $file_name) = each($file_names)) { |
| 1239 | - if (!is_readable($file_name)) continue; |
|
| 1239 | + if ( ! is_readable($file_name)) continue; |
|
| 1240 | 1240 | |
| 1241 | 1241 | $fp = fopen($file_name, "r"); |
| 1242 | 1242 | $file_content = fread($fp, filesize($file_name)); |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * |
| 136 | 136 | * @param int $width |
| 137 | 137 | * @param int $height |
| 138 | - * @return true |
|
| 138 | + * @return boolean |
|
| 139 | 139 | */ |
| 140 | 140 | protected function update_size( $width = false, $height = false ) { |
| 141 | 141 | if ( ! $width ) |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | protected $image; |
| 25 | 25 | |
| 26 | 26 | public function __destruct() { |
| 27 | - if ( $this->image ) { |
|
| 27 | + if ($this->image) { |
|
| 28 | 28 | // we don't need the original in memory anymore |
| 29 | - imagedestroy( $this->image ); |
|
| 29 | + imagedestroy($this->image); |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @param array $args |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public static function test( $args = array() ) { |
|
| 45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
| 44 | + public static function test($args = array()) { |
|
| 45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info')) |
|
| 46 | 46 | return false; |
| 47 | 47 | |
| 48 | 48 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
| 49 | - if ( isset( $args['methods'] ) && |
|
| 50 | - in_array( 'rotate', $args['methods'] ) && |
|
| 51 | - ! function_exists('imagerotate') ){ |
|
| 49 | + if (isset($args['methods']) && |
|
| 50 | + in_array('rotate', $args['methods']) && |
|
| 51 | + ! function_exists('imagerotate')) { |
|
| 52 | 52 | |
| 53 | 53 | return false; |
| 54 | 54 | } |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @param string $mime_type |
| 68 | 68 | * @return bool |
| 69 | 69 | */ |
| 70 | - public static function supports_mime_type( $mime_type ) { |
|
| 70 | + public static function supports_mime_type($mime_type) { |
|
| 71 | 71 | $image_types = imagetypes(); |
| 72 | - switch( $mime_type ) { |
|
| 72 | + switch ($mime_type) { |
|
| 73 | 73 | case 'image/jpeg': |
| 74 | 74 | return ($image_types & IMG_JPG) != 0; |
| 75 | 75 | case 'image/png': |
@@ -90,30 +90,30 @@ discard block |
||
| 90 | 90 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
| 91 | 91 | */ |
| 92 | 92 | public function load() { |
| 93 | - if ( $this->image ) |
|
| 93 | + if ($this->image) |
|
| 94 | 94 | return true; |
| 95 | 95 | |
| 96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
| 97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
| 96 | + if ( ! is_file($this->file) && ! preg_match('|^https?://|', $this->file)) |
|
| 97 | + return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file); |
|
| 98 | 98 | |
| 99 | 99 | // Set artificially high because GD uses uncompressed images in memory. |
| 100 | - wp_raise_memory_limit( 'image' ); |
|
| 100 | + wp_raise_memory_limit('image'); |
|
| 101 | 101 | |
| 102 | - $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
|
| 102 | + $this->image = @imagecreatefromstring(file_get_contents($this->file)); |
|
| 103 | 103 | |
| 104 | - if ( ! is_resource( $this->image ) ) |
|
| 105 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
| 104 | + if ( ! is_resource($this->image)) |
|
| 105 | + return new WP_Error('invalid_image', __('File is not an image.'), $this->file); |
|
| 106 | 106 | |
| 107 | - $size = @getimagesize( $this->file ); |
|
| 108 | - if ( ! $size ) |
|
| 109 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
| 107 | + $size = @getimagesize($this->file); |
|
| 108 | + if ( ! $size) |
|
| 109 | + return new WP_Error('invalid_image', __('Could not read image size.'), $this->file); |
|
| 110 | 110 | |
| 111 | - if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
|
| 112 | - imagealphablending( $this->image, false ); |
|
| 113 | - imagesavealpha( $this->image, true ); |
|
| 111 | + if (function_exists('imagealphablending') && function_exists('imagesavealpha')) { |
|
| 112 | + imagealphablending($this->image, false); |
|
| 113 | + imagesavealpha($this->image, true); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $this->update_size( $size[0], $size[1] ); |
|
| 116 | + $this->update_size($size[0], $size[1]); |
|
| 117 | 117 | $this->mime_type = $size['mime']; |
| 118 | 118 | |
| 119 | 119 | return $this->set_quality(); |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param int $height |
| 130 | 130 | * @return true |
| 131 | 131 | */ |
| 132 | - protected function update_size( $width = false, $height = false ) { |
|
| 133 | - if ( ! $width ) |
|
| 134 | - $width = imagesx( $this->image ); |
|
| 132 | + protected function update_size($width = false, $height = false) { |
|
| 133 | + if ( ! $width) |
|
| 134 | + $width = imagesx($this->image); |
|
| 135 | 135 | |
| 136 | - if ( ! $height ) |
|
| 137 | - $height = imagesy( $this->image ); |
|
| 136 | + if ( ! $height) |
|
| 137 | + $height = imagesy($this->image); |
|
| 138 | 138 | |
| 139 | - return parent::update_size( $width, $height ); |
|
| 139 | + return parent::update_size($width, $height); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -155,21 +155,21 @@ discard block |
||
| 155 | 155 | * @param bool $crop |
| 156 | 156 | * @return true|WP_Error |
| 157 | 157 | */ |
| 158 | - public function resize( $max_w, $max_h, $crop = false ) { |
|
| 159 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
| 158 | + public function resize($max_w, $max_h, $crop = false) { |
|
| 159 | + if (($this->size['width'] == $max_w) && ($this->size['height'] == $max_h)) |
|
| 160 | 160 | return true; |
| 161 | 161 | |
| 162 | - $resized = $this->_resize( $max_w, $max_h, $crop ); |
|
| 162 | + $resized = $this->_resize($max_w, $max_h, $crop); |
|
| 163 | 163 | |
| 164 | - if ( is_resource( $resized ) ) { |
|
| 165 | - imagedestroy( $this->image ); |
|
| 164 | + if (is_resource($resized)) { |
|
| 165 | + imagedestroy($this->image); |
|
| 166 | 166 | $this->image = $resized; |
| 167 | 167 | return true; |
| 168 | 168 | |
| 169 | - } elseif ( is_wp_error( $resized ) ) |
|
| 169 | + } elseif (is_wp_error($resized)) |
|
| 170 | 170 | return $resized; |
| 171 | 171 | |
| 172 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
| 172 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -179,22 +179,22 @@ discard block |
||
| 179 | 179 | * @param bool|array $crop |
| 180 | 180 | * @return resource|WP_Error |
| 181 | 181 | */ |
| 182 | - protected function _resize( $max_w, $max_h, $crop = false ) { |
|
| 183 | - $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
|
| 184 | - if ( ! $dims ) { |
|
| 185 | - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file ); |
|
| 182 | + protected function _resize($max_w, $max_h, $crop = false) { |
|
| 183 | + $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop); |
|
| 184 | + if ( ! $dims) { |
|
| 185 | + return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file); |
|
| 186 | 186 | } |
| 187 | - list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
|
| 187 | + list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; |
|
| 188 | 188 | |
| 189 | - $resized = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
| 190 | - imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
| 189 | + $resized = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
| 190 | + imagecopyresampled($resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
| 191 | 191 | |
| 192 | - if ( is_resource( $resized ) ) { |
|
| 193 | - $this->update_size( $dst_w, $dst_h ); |
|
| 192 | + if (is_resource($resized)) { |
|
| 193 | + $this->update_size($dst_w, $dst_h); |
|
| 194 | 194 | return $resized; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
| 197 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -220,36 +220,36 @@ discard block |
||
| 220 | 220 | * } |
| 221 | 221 | * @return array An array of resized images' metadata by size. |
| 222 | 222 | */ |
| 223 | - public function multi_resize( $sizes ) { |
|
| 223 | + public function multi_resize($sizes) { |
|
| 224 | 224 | $metadata = array(); |
| 225 | 225 | $orig_size = $this->size; |
| 226 | 226 | |
| 227 | - foreach ( $sizes as $size => $size_data ) { |
|
| 228 | - if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) { |
|
| 227 | + foreach ($sizes as $size => $size_data) { |
|
| 228 | + if ( ! isset($size_data['width']) && ! isset($size_data['height'])) { |
|
| 229 | 229 | continue; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - if ( ! isset( $size_data['width'] ) ) { |
|
| 232 | + if ( ! isset($size_data['width'])) { |
|
| 233 | 233 | $size_data['width'] = null; |
| 234 | 234 | } |
| 235 | - if ( ! isset( $size_data['height'] ) ) { |
|
| 235 | + if ( ! isset($size_data['height'])) { |
|
| 236 | 236 | $size_data['height'] = null; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( ! isset( $size_data['crop'] ) ) { |
|
| 239 | + if ( ! isset($size_data['crop'])) { |
|
| 240 | 240 | $size_data['crop'] = false; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
|
| 244 | - $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
|
| 243 | + $image = $this->_resize($size_data['width'], $size_data['height'], $size_data['crop']); |
|
| 244 | + $duplicate = (($orig_size['width'] == $size_data['width']) && ($orig_size['height'] == $size_data['height'])); |
|
| 245 | 245 | |
| 246 | - if ( ! is_wp_error( $image ) && ! $duplicate ) { |
|
| 247 | - $resized = $this->_save( $image ); |
|
| 246 | + if ( ! is_wp_error($image) && ! $duplicate) { |
|
| 247 | + $resized = $this->_save($image); |
|
| 248 | 248 | |
| 249 | - imagedestroy( $image ); |
|
| 249 | + imagedestroy($image); |
|
| 250 | 250 | |
| 251 | - if ( ! is_wp_error( $resized ) && $resized ) { |
|
| 252 | - unset( $resized['path'] ); |
|
| 251 | + if ( ! is_wp_error($resized) && $resized) { |
|
| 252 | + unset($resized['path']); |
|
| 253 | 253 | $metadata[$size] = $resized; |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -275,34 +275,34 @@ discard block |
||
| 275 | 275 | * @param bool $src_abs Optional. If the source crop points are absolute. |
| 276 | 276 | * @return bool|WP_Error |
| 277 | 277 | */ |
| 278 | - public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
|
| 278 | + public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false) { |
|
| 279 | 279 | // If destination width/height isn't specified, use same as |
| 280 | 280 | // width/height from source. |
| 281 | - if ( ! $dst_w ) |
|
| 281 | + if ( ! $dst_w) |
|
| 282 | 282 | $dst_w = $src_w; |
| 283 | - if ( ! $dst_h ) |
|
| 283 | + if ( ! $dst_h) |
|
| 284 | 284 | $dst_h = $src_h; |
| 285 | 285 | |
| 286 | - $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
| 286 | + $dst = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
| 287 | 287 | |
| 288 | - if ( $src_abs ) { |
|
| 288 | + if ($src_abs) { |
|
| 289 | 289 | $src_w -= $src_x; |
| 290 | 290 | $src_h -= $src_y; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ( function_exists( 'imageantialias' ) ) |
|
| 294 | - imageantialias( $dst, true ); |
|
| 293 | + if (function_exists('imageantialias')) |
|
| 294 | + imageantialias($dst, true); |
|
| 295 | 295 | |
| 296 | - imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
| 296 | + imagecopyresampled($dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
| 297 | 297 | |
| 298 | - if ( is_resource( $dst ) ) { |
|
| 299 | - imagedestroy( $this->image ); |
|
| 298 | + if (is_resource($dst)) { |
|
| 299 | + imagedestroy($this->image); |
|
| 300 | 300 | $this->image = $dst; |
| 301 | 301 | $this->update_size(); |
| 302 | 302 | return true; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - return new WP_Error( 'image_crop_error', __('Image crop failed.'), $this->file ); |
|
| 305 | + return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -315,21 +315,21 @@ discard block |
||
| 315 | 315 | * @param float $angle |
| 316 | 316 | * @return true|WP_Error |
| 317 | 317 | */ |
| 318 | - public function rotate( $angle ) { |
|
| 319 | - if ( function_exists('imagerotate') ) { |
|
| 320 | - $transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 ); |
|
| 321 | - $rotated = imagerotate( $this->image, $angle, $transparency ); |
|
| 322 | - |
|
| 323 | - if ( is_resource( $rotated ) ) { |
|
| 324 | - imagealphablending( $rotated, true ); |
|
| 325 | - imagesavealpha( $rotated, true ); |
|
| 326 | - imagedestroy( $this->image ); |
|
| 318 | + public function rotate($angle) { |
|
| 319 | + if (function_exists('imagerotate')) { |
|
| 320 | + $transparency = imagecolorallocatealpha($this->image, 255, 255, 255, 127); |
|
| 321 | + $rotated = imagerotate($this->image, $angle, $transparency); |
|
| 322 | + |
|
| 323 | + if (is_resource($rotated)) { |
|
| 324 | + imagealphablending($rotated, true); |
|
| 325 | + imagesavealpha($rotated, true); |
|
| 326 | + imagedestroy($this->image); |
|
| 327 | 327 | $this->image = $rotated; |
| 328 | 328 | $this->update_size(); |
| 329 | 329 | return true; |
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | - return new WP_Error( 'image_rotate_error', __('Image rotate failed.'), $this->file ); |
|
| 332 | + return new WP_Error('image_rotate_error', __('Image rotate failed.'), $this->file); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -342,24 +342,24 @@ discard block |
||
| 342 | 342 | * @param bool $vert Flip along Vertical Axis |
| 343 | 343 | * @return true|WP_Error |
| 344 | 344 | */ |
| 345 | - public function flip( $horz, $vert ) { |
|
| 345 | + public function flip($horz, $vert) { |
|
| 346 | 346 | $w = $this->size['width']; |
| 347 | 347 | $h = $this->size['height']; |
| 348 | - $dst = wp_imagecreatetruecolor( $w, $h ); |
|
| 348 | + $dst = wp_imagecreatetruecolor($w, $h); |
|
| 349 | 349 | |
| 350 | - if ( is_resource( $dst ) ) { |
|
| 350 | + if (is_resource($dst)) { |
|
| 351 | 351 | $sx = $vert ? ($w - 1) : 0; |
| 352 | 352 | $sy = $horz ? ($h - 1) : 0; |
| 353 | 353 | $sw = $vert ? -$w : $w; |
| 354 | 354 | $sh = $horz ? -$h : $h; |
| 355 | 355 | |
| 356 | - if ( imagecopyresampled( $dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) { |
|
| 357 | - imagedestroy( $this->image ); |
|
| 356 | + if (imagecopyresampled($dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh)) { |
|
| 357 | + imagedestroy($this->image); |
|
| 358 | 358 | $this->image = $dst; |
| 359 | 359 | return true; |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | - return new WP_Error( 'image_flip_error', __('Image flip failed.'), $this->file ); |
|
| 362 | + return new WP_Error('image_flip_error', __('Image flip failed.'), $this->file); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -372,10 +372,10 @@ discard block |
||
| 372 | 372 | * @param string|null $mime_type |
| 373 | 373 | * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
| 374 | 374 | */ |
| 375 | - public function save( $filename = null, $mime_type = null ) { |
|
| 376 | - $saved = $this->_save( $this->image, $filename, $mime_type ); |
|
| 375 | + public function save($filename = null, $mime_type = null) { |
|
| 376 | + $saved = $this->_save($this->image, $filename, $mime_type); |
|
| 377 | 377 | |
| 378 | - if ( ! is_wp_error( $saved ) ) { |
|
| 378 | + if ( ! is_wp_error($saved)) { |
|
| 379 | 379 | $this->file = $saved['path']; |
| 380 | 380 | $this->mime_type = $saved['mime-type']; |
| 381 | 381 | } |
@@ -389,36 +389,36 @@ discard block |
||
| 389 | 389 | * @param string|null $mime_type |
| 390 | 390 | * @return WP_Error|array |
| 391 | 391 | */ |
| 392 | - protected function _save( $image, $filename = null, $mime_type = null ) { |
|
| 393 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
|
| 392 | + protected function _save($image, $filename = null, $mime_type = null) { |
|
| 393 | + list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type); |
|
| 394 | 394 | |
| 395 | - if ( ! $filename ) |
|
| 396 | - $filename = $this->generate_filename( null, null, $extension ); |
|
| 395 | + if ( ! $filename) |
|
| 396 | + $filename = $this->generate_filename(null, null, $extension); |
|
| 397 | 397 | |
| 398 | - if ( 'image/gif' == $mime_type ) { |
|
| 399 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
| 400 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 398 | + if ('image/gif' == $mime_type) { |
|
| 399 | + if ( ! $this->make_image($filename, 'imagegif', array($image, $filename))) |
|
| 400 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
| 401 | 401 | } |
| 402 | - elseif ( 'image/png' == $mime_type ) { |
|
| 402 | + elseif ('image/png' == $mime_type) { |
|
| 403 | 403 | // convert from full colors to index colors, like original PNG. |
| 404 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
| 405 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
| 404 | + if (function_exists('imageistruecolor') && ! imageistruecolor($image)) |
|
| 405 | + imagetruecolortopalette($image, false, imagecolorstotal($image)); |
|
| 406 | 406 | |
| 407 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
| 408 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 407 | + if ( ! $this->make_image($filename, 'imagepng', array($image, $filename))) |
|
| 408 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
| 409 | 409 | } |
| 410 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
| 411 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
| 412 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 410 | + elseif ('image/jpeg' == $mime_type) { |
|
| 411 | + if ( ! $this->make_image($filename, 'imagejpeg', array($image, $filename, $this->get_quality()))) |
|
| 412 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
| 413 | 413 | } |
| 414 | 414 | else { |
| 415 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 415 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | // Set correct file permissions |
| 419 | - $stat = stat( dirname( $filename ) ); |
|
| 419 | + $stat = stat(dirname($filename)); |
|
| 420 | 420 | $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits |
| 421 | - @ chmod( $filename, $perms ); |
|
| 421 | + @ chmod($filename, $perms); |
|
| 422 | 422 | |
| 423 | 423 | /** |
| 424 | 424 | * Filters the name of the saved image file. |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | return array( |
| 431 | 431 | 'path' => $filename, |
| 432 | - 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
|
| 432 | + 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), |
|
| 433 | 433 | 'width' => $this->size['width'], |
| 434 | 434 | 'height' => $this->size['height'], |
| 435 | 435 | 'mime-type' => $mime_type, |
@@ -445,19 +445,19 @@ discard block |
||
| 445 | 445 | * @param string $mime_type |
| 446 | 446 | * @return bool |
| 447 | 447 | */ |
| 448 | - public function stream( $mime_type = null ) { |
|
| 449 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); |
|
| 448 | + public function stream($mime_type = null) { |
|
| 449 | + list($filename, $extension, $mime_type) = $this->get_output_format(null, $mime_type); |
|
| 450 | 450 | |
| 451 | - switch ( $mime_type ) { |
|
| 451 | + switch ($mime_type) { |
|
| 452 | 452 | case 'image/png': |
| 453 | - header( 'Content-Type: image/png' ); |
|
| 454 | - return imagepng( $this->image ); |
|
| 453 | + header('Content-Type: image/png'); |
|
| 454 | + return imagepng($this->image); |
|
| 455 | 455 | case 'image/gif': |
| 456 | - header( 'Content-Type: image/gif' ); |
|
| 457 | - return imagegif( $this->image ); |
|
| 456 | + header('Content-Type: image/gif'); |
|
| 457 | + return imagegif($this->image); |
|
| 458 | 458 | default: |
| 459 | - header( 'Content-Type: image/jpeg' ); |
|
| 460 | - return imagejpeg( $this->image, null, $this->get_quality() ); |
|
| 459 | + header('Content-Type: image/jpeg'); |
|
| 460 | + return imagejpeg($this->image, null, $this->get_quality()); |
|
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
@@ -472,10 +472,10 @@ discard block |
||
| 472 | 472 | * @param array $arguments |
| 473 | 473 | * @return bool |
| 474 | 474 | */ |
| 475 | - protected function make_image( $filename, $function, $arguments ) { |
|
| 476 | - if ( wp_is_stream( $filename ) ) |
|
| 475 | + protected function make_image($filename, $function, $arguments) { |
|
| 476 | + if (wp_is_stream($filename)) |
|
| 477 | 477 | $arguments[1] = null; |
| 478 | 478 | |
| 479 | - return parent::make_image( $filename, $function, $arguments ); |
|
| 479 | + return parent::make_image($filename, $function, $arguments); |
|
| 480 | 480 | } |
| 481 | 481 | } |
@@ -42,8 +42,9 @@ discard block |
||
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | 44 | public static function test( $args = array() ) { |
| 45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
| 46 | - return false; |
|
| 45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
| 49 | 50 | if ( isset( $args['methods'] ) && |
@@ -90,23 +91,27 @@ discard block |
||
| 90 | 91 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
| 91 | 92 | */ |
| 92 | 93 | public function load() { |
| 93 | - if ( $this->image ) |
|
| 94 | - return true; |
|
| 94 | + if ( $this->image ) { |
|
| 95 | + return true; |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
| 97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
| 98 | + if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) { |
|
| 99 | + return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
| 100 | + } |
|
| 98 | 101 | |
| 99 | 102 | // Set artificially high because GD uses uncompressed images in memory. |
| 100 | 103 | wp_raise_memory_limit( 'image' ); |
| 101 | 104 | |
| 102 | 105 | $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
| 103 | 106 | |
| 104 | - if ( ! is_resource( $this->image ) ) |
|
| 105 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
| 107 | + if ( ! is_resource( $this->image ) ) { |
|
| 108 | + return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
| 109 | + } |
|
| 106 | 110 | |
| 107 | 111 | $size = @getimagesize( $this->file ); |
| 108 | - if ( ! $size ) |
|
| 109 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
| 112 | + if ( ! $size ) { |
|
| 113 | + return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
| 114 | + } |
|
| 110 | 115 | |
| 111 | 116 | if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
| 112 | 117 | imagealphablending( $this->image, false ); |
@@ -130,11 +135,13 @@ discard block |
||
| 130 | 135 | * @return true |
| 131 | 136 | */ |
| 132 | 137 | protected function update_size( $width = false, $height = false ) { |
| 133 | - if ( ! $width ) |
|
| 134 | - $width = imagesx( $this->image ); |
|
| 138 | + if ( ! $width ) { |
|
| 139 | + $width = imagesx( $this->image ); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | - if ( ! $height ) |
|
| 137 | - $height = imagesy( $this->image ); |
|
| 142 | + if ( ! $height ) { |
|
| 143 | + $height = imagesy( $this->image ); |
|
| 144 | + } |
|
| 138 | 145 | |
| 139 | 146 | return parent::update_size( $width, $height ); |
| 140 | 147 | } |
@@ -156,8 +163,9 @@ discard block |
||
| 156 | 163 | * @return true|WP_Error |
| 157 | 164 | */ |
| 158 | 165 | public function resize( $max_w, $max_h, $crop = false ) { |
| 159 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
| 160 | - return true; |
|
| 166 | + if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
|
| 167 | + return true; |
|
| 168 | + } |
|
| 161 | 169 | |
| 162 | 170 | $resized = $this->_resize( $max_w, $max_h, $crop ); |
| 163 | 171 | |
@@ -166,8 +174,9 @@ discard block |
||
| 166 | 174 | $this->image = $resized; |
| 167 | 175 | return true; |
| 168 | 176 | |
| 169 | - } elseif ( is_wp_error( $resized ) ) |
|
| 170 | - return $resized; |
|
| 177 | + } elseif ( is_wp_error( $resized ) ) { |
|
| 178 | + return $resized; |
|
| 179 | + } |
|
| 171 | 180 | |
| 172 | 181 | return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
| 173 | 182 | } |
@@ -278,10 +287,12 @@ discard block |
||
| 278 | 287 | public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
| 279 | 288 | // If destination width/height isn't specified, use same as |
| 280 | 289 | // width/height from source. |
| 281 | - if ( ! $dst_w ) |
|
| 282 | - $dst_w = $src_w; |
|
| 283 | - if ( ! $dst_h ) |
|
| 284 | - $dst_h = $src_h; |
|
| 290 | + if ( ! $dst_w ) { |
|
| 291 | + $dst_w = $src_w; |
|
| 292 | + } |
|
| 293 | + if ( ! $dst_h ) { |
|
| 294 | + $dst_h = $src_h; |
|
| 295 | + } |
|
| 285 | 296 | |
| 286 | 297 | $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
| 287 | 298 | |
@@ -290,8 +301,9 @@ discard block |
||
| 290 | 301 | $src_h -= $src_y; |
| 291 | 302 | } |
| 292 | 303 | |
| 293 | - if ( function_exists( 'imageantialias' ) ) |
|
| 294 | - imageantialias( $dst, true ); |
|
| 304 | + if ( function_exists( 'imageantialias' ) ) { |
|
| 305 | + imageantialias( $dst, true ); |
|
| 306 | + } |
|
| 295 | 307 | |
| 296 | 308 | imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
| 297 | 309 | |
@@ -392,26 +404,28 @@ discard block |
||
| 392 | 404 | protected function _save( $image, $filename = null, $mime_type = null ) { |
| 393 | 405 | list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
| 394 | 406 | |
| 395 | - if ( ! $filename ) |
|
| 396 | - $filename = $this->generate_filename( null, null, $extension ); |
|
| 407 | + if ( ! $filename ) { |
|
| 408 | + $filename = $this->generate_filename( null, null, $extension ); |
|
| 409 | + } |
|
| 397 | 410 | |
| 398 | 411 | if ( 'image/gif' == $mime_type ) { |
| 399 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
| 400 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 401 | - } |
|
| 402 | - elseif ( 'image/png' == $mime_type ) { |
|
| 412 | + if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) { |
|
| 413 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 414 | + } |
|
| 415 | + } elseif ( 'image/png' == $mime_type ) { |
|
| 403 | 416 | // convert from full colors to index colors, like original PNG. |
| 404 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
| 405 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
| 417 | + if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) { |
|
| 418 | + imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
| 419 | + } |
|
| 406 | 420 | |
| 407 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
| 408 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 409 | - } |
|
| 410 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
| 411 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
| 412 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 413 | - } |
|
| 414 | - else { |
|
| 421 | + if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) { |
|
| 422 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 423 | + } |
|
| 424 | + } elseif ( 'image/jpeg' == $mime_type ) { |
|
| 425 | + if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) { |
|
| 426 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
| 427 | + } |
|
| 428 | + } else { |
|
| 415 | 429 | return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
| 416 | 430 | } |
| 417 | 431 | |
@@ -473,8 +487,9 @@ discard block |
||
| 473 | 487 | * @return bool |
| 474 | 488 | */ |
| 475 | 489 | protected function make_image( $filename, $function, $arguments ) { |
| 476 | - if ( wp_is_stream( $filename ) ) |
|
| 477 | - $arguments[1] = null; |
|
| 490 | + if ( wp_is_stream( $filename ) ) { |
|
| 491 | + $arguments[1] = null; |
|
| 492 | + } |
|
| 478 | 493 | |
| 479 | 494 | return parent::make_image( $filename, $function, $arguments ); |
| 480 | 495 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * |
| 198 | 198 | * @param int $width |
| 199 | 199 | * @param int $height |
| 200 | - * @return true |
|
| 200 | + * @return boolean |
|
| 201 | 201 | */ |
| 202 | 202 | protected function update_size( $width = null, $height = null ) { |
| 203 | 203 | $this->size = array( |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * @since 4.0.0 |
| 214 | 214 | * @access public |
| 215 | 215 | * |
| 216 | - * @return int $quality Compression Quality. Range: [1,100] |
|
| 216 | + * @return boolean $quality Compression Quality. Range: [1,100] |
|
| 217 | 217 | */ |
| 218 | 218 | public function get_quality() { |
| 219 | 219 | if ( ! $this->quality ) { |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param string $file Path to the file to load. |
| 26 | 26 | */ |
| 27 | - public function __construct( $file ) { |
|
| 27 | + public function __construct($file) { |
|
| 28 | 28 | $this->file = $file; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $args |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public static function test( $args = array() ) { |
|
| 44 | + public static function test($args = array()) { |
|
| 45 | 45 | return false; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param string $mime_type |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public static function supports_mime_type( $mime_type ) { |
|
| 61 | + public static function supports_mime_type($mime_type) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param string $mime_type |
| 85 | 85 | * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
| 86 | 86 | */ |
| 87 | - abstract public function save( $destfilename = null, $mime_type = null ); |
|
| 87 | + abstract public function save($destfilename = null, $mime_type = null); |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Resizes current image. |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @param bool $crop |
| 103 | 103 | * @return bool|WP_Error |
| 104 | 104 | */ |
| 105 | - abstract public function resize( $max_w, $max_h, $crop = false ); |
|
| 105 | + abstract public function resize($max_w, $max_h, $crop = false); |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * Resize multiple images from a single source. |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * } |
| 123 | 123 | * @return array An array of resized images metadata by size. |
| 124 | 124 | */ |
| 125 | - abstract public function multi_resize( $sizes ); |
|
| 125 | + abstract public function multi_resize($sizes); |
|
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * Crops Image. |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param bool $src_abs Optional. If the source crop points are absolute. |
| 141 | 141 | * @return bool|WP_Error |
| 142 | 142 | */ |
| 143 | - abstract public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ); |
|
| 143 | + abstract public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false); |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | 146 | * Rotates current image counter-clockwise by $angle. |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param float $angle |
| 153 | 153 | * @return bool|WP_Error |
| 154 | 154 | */ |
| 155 | - abstract public function rotate( $angle ); |
|
| 155 | + abstract public function rotate($angle); |
|
| 156 | 156 | |
| 157 | 157 | /** |
| 158 | 158 | * Flips current image. |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param bool $vert Flip along Vertical Axis |
| 166 | 166 | * @return bool|WP_Error |
| 167 | 167 | */ |
| 168 | - abstract public function flip( $horz, $vert ); |
|
| 168 | + abstract public function flip($horz, $vert); |
|
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * Streams current image to browser. |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @param string $mime_type |
| 178 | 178 | * @return bool|WP_Error |
| 179 | 179 | */ |
| 180 | - abstract public function stream( $mime_type = null ); |
|
| 180 | + abstract public function stream($mime_type = null); |
|
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * Gets dimensions of image. |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param int $height |
| 202 | 202 | * @return true |
| 203 | 203 | */ |
| 204 | - protected function update_size( $width = null, $height = null ) { |
|
| 204 | + protected function update_size($width = null, $height = null) { |
|
| 205 | 205 | $this->size = array( |
| 206 | 206 | 'width' => (int) $width, |
| 207 | 207 | 'height' => (int) $height |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @return int $quality Compression Quality. Range: [1,100] |
| 219 | 219 | */ |
| 220 | 220 | public function get_quality() { |
| 221 | - if ( ! $this->quality ) { |
|
| 221 | + if ( ! $this->quality) { |
|
| 222 | 222 | $this->set_quality(); |
| 223 | 223 | } |
| 224 | 224 | |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * @param int $quality Compression Quality. Range: [1,100] |
| 235 | 235 | * @return true|WP_Error True if set successfully; WP_Error on failure. |
| 236 | 236 | */ |
| 237 | - public function set_quality( $quality = null ) { |
|
| 238 | - if ( null === $quality ) { |
|
| 237 | + public function set_quality($quality = null) { |
|
| 238 | + if (null === $quality) { |
|
| 239 | 239 | /** |
| 240 | 240 | * Filters the default image compression quality setting. |
| 241 | 241 | * |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | * @param int $quality Quality level between 1 (low) and 100 (high). |
| 250 | 250 | * @param string $mime_type Image mime type. |
| 251 | 251 | */ |
| 252 | - $quality = apply_filters( 'wp_editor_set_quality', $this->default_quality, $this->mime_type ); |
|
| 252 | + $quality = apply_filters('wp_editor_set_quality', $this->default_quality, $this->mime_type); |
|
| 253 | 253 | |
| 254 | - if ( 'image/jpeg' == $this->mime_type ) { |
|
| 254 | + if ('image/jpeg' == $this->mime_type) { |
|
| 255 | 255 | /** |
| 256 | 256 | * Filters the JPEG compression quality for backward-compatibility. |
| 257 | 257 | * |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | * @param int $quality Quality level between 0 (low) and 100 (high) of the JPEG. |
| 269 | 269 | * @param string $context Context of the filter. |
| 270 | 270 | */ |
| 271 | - $quality = apply_filters( 'jpeg_quality', $quality, 'image_resize' ); |
|
| 271 | + $quality = apply_filters('jpeg_quality', $quality, 'image_resize'); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if ( $quality < 0 || $quality > 100 ) { |
|
| 274 | + if ($quality < 0 || $quality > 100) { |
|
| 275 | 275 | $quality = $this->default_quality; |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | // Allow 0, but squash to 1 due to identical images in GD, and for backward compatibility. |
| 280 | - if ( 0 === $quality ) { |
|
| 280 | + if (0 === $quality) { |
|
| 281 | 281 | $quality = 1; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if ( ( $quality >= 1 ) && ( $quality <= 100 ) ) { |
|
| 284 | + if (($quality >= 1) && ($quality <= 100)) { |
|
| 285 | 285 | $this->quality = $quality; |
| 286 | 286 | return true; |
| 287 | 287 | } else { |
| 288 | - return new WP_Error( 'invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].') ); |
|
| 288 | + return new WP_Error('invalid_image_quality', __('Attempted to set image quality outside of the range [1,100].')); |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
@@ -304,34 +304,34 @@ discard block |
||
| 304 | 304 | * @param string $mime_type |
| 305 | 305 | * @return array { filename|null, extension, mime-type } |
| 306 | 306 | */ |
| 307 | - protected function get_output_format( $filename = null, $mime_type = null ) { |
|
| 307 | + protected function get_output_format($filename = null, $mime_type = null) { |
|
| 308 | 308 | $new_ext = null; |
| 309 | 309 | |
| 310 | 310 | // By default, assume specified type takes priority |
| 311 | - if ( $mime_type ) { |
|
| 312 | - $new_ext = $this->get_extension( $mime_type ); |
|
| 311 | + if ($mime_type) { |
|
| 312 | + $new_ext = $this->get_extension($mime_type); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( $filename ) { |
|
| 316 | - $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); |
|
| 317 | - $file_mime = $this->get_mime_type( $file_ext ); |
|
| 315 | + if ($filename) { |
|
| 316 | + $file_ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); |
|
| 317 | + $file_mime = $this->get_mime_type($file_ext); |
|
| 318 | 318 | } |
| 319 | 319 | else { |
| 320 | 320 | // If no file specified, grab editor's current extension and mime-type. |
| 321 | - $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); |
|
| 321 | + $file_ext = strtolower(pathinfo($this->file, PATHINFO_EXTENSION)); |
|
| 322 | 322 | $file_mime = $this->mime_type; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Check to see if specified mime-type is the same as type implied by |
| 326 | 326 | // file extension. If so, prefer extension from file. |
| 327 | - if ( ! $mime_type || ( $file_mime == $mime_type ) ) { |
|
| 327 | + if ( ! $mime_type || ($file_mime == $mime_type)) { |
|
| 328 | 328 | $mime_type = $file_mime; |
| 329 | 329 | $new_ext = $file_ext; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // Double-check that the mime-type selected is supported by the editor. |
| 333 | 333 | // If not, choose a default instead. |
| 334 | - if ( ! $this->supports_mime_type( $mime_type ) ) { |
|
| 334 | + if ( ! $this->supports_mime_type($mime_type)) { |
|
| 335 | 335 | /** |
| 336 | 336 | * Filters default mime type prior to getting the file extension. |
| 337 | 337 | * |
@@ -341,18 +341,18 @@ discard block |
||
| 341 | 341 | * |
| 342 | 342 | * @param string $mime_type Mime type string. |
| 343 | 343 | */ |
| 344 | - $mime_type = apply_filters( 'image_editor_default_mime_type', $this->default_mime_type ); |
|
| 345 | - $new_ext = $this->get_extension( $mime_type ); |
|
| 344 | + $mime_type = apply_filters('image_editor_default_mime_type', $this->default_mime_type); |
|
| 345 | + $new_ext = $this->get_extension($mime_type); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if ( $filename ) { |
|
| 349 | - $dir = pathinfo( $filename, PATHINFO_DIRNAME ); |
|
| 350 | - $ext = pathinfo( $filename, PATHINFO_EXTENSION ); |
|
| 348 | + if ($filename) { |
|
| 349 | + $dir = pathinfo($filename, PATHINFO_DIRNAME); |
|
| 350 | + $ext = pathinfo($filename, PATHINFO_EXTENSION); |
|
| 351 | 351 | |
| 352 | - $filename = trailingslashit( $dir ) . wp_basename( $filename, ".$ext" ) . ".{$new_ext}"; |
|
| 352 | + $filename = trailingslashit($dir).wp_basename($filename, ".$ext").".{$new_ext}"; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return array( $filename, $new_ext, $mime_type ); |
|
| 355 | + return array($filename, $new_ext, $mime_type); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -366,21 +366,21 @@ discard block |
||
| 366 | 366 | * @param string $extension |
| 367 | 367 | * @return string filename |
| 368 | 368 | */ |
| 369 | - public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { |
|
| 369 | + public function generate_filename($suffix = null, $dest_path = null, $extension = null) { |
|
| 370 | 370 | // $suffix will be appended to the destination filename, just before the extension |
| 371 | - if ( ! $suffix ) |
|
| 371 | + if ( ! $suffix) |
|
| 372 | 372 | $suffix = $this->get_suffix(); |
| 373 | 373 | |
| 374 | - $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); |
|
| 375 | - $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); |
|
| 374 | + $dir = pathinfo($this->file, PATHINFO_DIRNAME); |
|
| 375 | + $ext = pathinfo($this->file, PATHINFO_EXTENSION); |
|
| 376 | 376 | |
| 377 | - $name = wp_basename( $this->file, ".$ext" ); |
|
| 378 | - $new_ext = strtolower( $extension ? $extension : $ext ); |
|
| 377 | + $name = wp_basename($this->file, ".$ext"); |
|
| 378 | + $new_ext = strtolower($extension ? $extension : $ext); |
|
| 379 | 379 | |
| 380 | - if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) |
|
| 380 | + if ( ! is_null($dest_path) && $_dest_path = realpath($dest_path)) |
|
| 381 | 381 | $dir = $_dest_path; |
| 382 | 382 | |
| 383 | - return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; |
|
| 383 | + return trailingslashit($dir)."{$name}-{$suffix}.{$new_ext}"; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @return false|string suffix |
| 393 | 393 | */ |
| 394 | 394 | public function get_suffix() { |
| 395 | - if ( ! $this->get_size() ) |
|
| 395 | + if ( ! $this->get_size()) |
|
| 396 | 396 | return false; |
| 397 | 397 | |
| 398 | 398 | return "{$this->size['width']}x{$this->size['height']}"; |
@@ -409,29 +409,29 @@ discard block |
||
| 409 | 409 | * @param array $arguments |
| 410 | 410 | * @return bool |
| 411 | 411 | */ |
| 412 | - protected function make_image( $filename, $function, $arguments ) { |
|
| 413 | - if ( $stream = wp_is_stream( $filename ) ) { |
|
| 412 | + protected function make_image($filename, $function, $arguments) { |
|
| 413 | + if ($stream = wp_is_stream($filename)) { |
|
| 414 | 414 | ob_start(); |
| 415 | 415 | } else { |
| 416 | 416 | // The directory containing the original file may no longer exist when using a replication plugin. |
| 417 | - wp_mkdir_p( dirname( $filename ) ); |
|
| 417 | + wp_mkdir_p(dirname($filename)); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - $result = call_user_func_array( $function, $arguments ); |
|
| 420 | + $result = call_user_func_array($function, $arguments); |
|
| 421 | 421 | |
| 422 | - if ( $result && $stream ) { |
|
| 422 | + if ($result && $stream) { |
|
| 423 | 423 | $contents = ob_get_contents(); |
| 424 | 424 | |
| 425 | - $fp = fopen( $filename, 'w' ); |
|
| 425 | + $fp = fopen($filename, 'w'); |
|
| 426 | 426 | |
| 427 | - if ( ! $fp ) |
|
| 427 | + if ( ! $fp) |
|
| 428 | 428 | return false; |
| 429 | 429 | |
| 430 | - fwrite( $fp, $contents ); |
|
| 431 | - fclose( $fp ); |
|
| 430 | + fwrite($fp, $contents); |
|
| 431 | + fclose($fp); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if ( $stream ) { |
|
| 434 | + if ($stream) { |
|
| 435 | 435 | ob_end_clean(); |
| 436 | 436 | } |
| 437 | 437 | |
@@ -450,15 +450,15 @@ discard block |
||
| 450 | 450 | * @param string $extension |
| 451 | 451 | * @return string|false |
| 452 | 452 | */ |
| 453 | - protected static function get_mime_type( $extension = null ) { |
|
| 454 | - if ( ! $extension ) |
|
| 453 | + protected static function get_mime_type($extension = null) { |
|
| 454 | + if ( ! $extension) |
|
| 455 | 455 | return false; |
| 456 | 456 | |
| 457 | 457 | $mime_types = wp_get_mime_types(); |
| 458 | - $extensions = array_keys( $mime_types ); |
|
| 458 | + $extensions = array_keys($mime_types); |
|
| 459 | 459 | |
| 460 | - foreach ( $extensions as $_extension ) { |
|
| 461 | - if ( preg_match( "/{$extension}/i", $_extension ) ) { |
|
| 460 | + foreach ($extensions as $_extension) { |
|
| 461 | + if (preg_match("/{$extension}/i", $_extension)) { |
|
| 462 | 462 | return $mime_types[$_extension]; |
| 463 | 463 | } |
| 464 | 464 | } |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | * @param string $mime_type |
| 479 | 479 | * @return string|false |
| 480 | 480 | */ |
| 481 | - protected static function get_extension( $mime_type = null ) { |
|
| 482 | - $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) ); |
|
| 481 | + protected static function get_extension($mime_type = null) { |
|
| 482 | + $extensions = explode('|', array_search($mime_type, wp_get_mime_types())); |
|
| 483 | 483 | |
| 484 | - if ( empty( $extensions[0] ) ) |
|
| 484 | + if (empty($extensions[0])) |
|
| 485 | 485 | return false; |
| 486 | 486 | |
| 487 | 487 | return $extensions[0]; |
@@ -315,8 +315,7 @@ discard block |
||
| 315 | 315 | if ( $filename ) { |
| 316 | 316 | $file_ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); |
| 317 | 317 | $file_mime = $this->get_mime_type( $file_ext ); |
| 318 | - } |
|
| 319 | - else { |
|
| 318 | + } else { |
|
| 320 | 319 | // If no file specified, grab editor's current extension and mime-type. |
| 321 | 320 | $file_ext = strtolower( pathinfo( $this->file, PATHINFO_EXTENSION ) ); |
| 322 | 321 | $file_mime = $this->mime_type; |
@@ -368,8 +367,9 @@ discard block |
||
| 368 | 367 | */ |
| 369 | 368 | public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { |
| 370 | 369 | // $suffix will be appended to the destination filename, just before the extension |
| 371 | - if ( ! $suffix ) |
|
| 372 | - $suffix = $this->get_suffix(); |
|
| 370 | + if ( ! $suffix ) { |
|
| 371 | + $suffix = $this->get_suffix(); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | 374 | $dir = pathinfo( $this->file, PATHINFO_DIRNAME ); |
| 375 | 375 | $ext = pathinfo( $this->file, PATHINFO_EXTENSION ); |
@@ -377,8 +377,9 @@ discard block |
||
| 377 | 377 | $name = wp_basename( $this->file, ".$ext" ); |
| 378 | 378 | $new_ext = strtolower( $extension ? $extension : $ext ); |
| 379 | 379 | |
| 380 | - if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) |
|
| 381 | - $dir = $_dest_path; |
|
| 380 | + if ( ! is_null( $dest_path ) && $_dest_path = realpath( $dest_path ) ) { |
|
| 381 | + $dir = $_dest_path; |
|
| 382 | + } |
|
| 382 | 383 | |
| 383 | 384 | return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; |
| 384 | 385 | } |
@@ -392,8 +393,9 @@ discard block |
||
| 392 | 393 | * @return false|string suffix |
| 393 | 394 | */ |
| 394 | 395 | public function get_suffix() { |
| 395 | - if ( ! $this->get_size() ) |
|
| 396 | - return false; |
|
| 396 | + if ( ! $this->get_size() ) { |
|
| 397 | + return false; |
|
| 398 | + } |
|
| 397 | 399 | |
| 398 | 400 | return "{$this->size['width']}x{$this->size['height']}"; |
| 399 | 401 | } |
@@ -424,8 +426,9 @@ discard block |
||
| 424 | 426 | |
| 425 | 427 | $fp = fopen( $filename, 'w' ); |
| 426 | 428 | |
| 427 | - if ( ! $fp ) |
|
| 428 | - return false; |
|
| 429 | + if ( ! $fp ) { |
|
| 430 | + return false; |
|
| 431 | + } |
|
| 429 | 432 | |
| 430 | 433 | fwrite( $fp, $contents ); |
| 431 | 434 | fclose( $fp ); |
@@ -451,8 +454,9 @@ discard block |
||
| 451 | 454 | * @return string|false |
| 452 | 455 | */ |
| 453 | 456 | protected static function get_mime_type( $extension = null ) { |
| 454 | - if ( ! $extension ) |
|
| 455 | - return false; |
|
| 457 | + if ( ! $extension ) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 456 | 460 | |
| 457 | 461 | $mime_types = wp_get_mime_types(); |
| 458 | 462 | $extensions = array_keys( $mime_types ); |
@@ -481,8 +485,9 @@ discard block |
||
| 481 | 485 | protected static function get_extension( $mime_type = null ) { |
| 482 | 486 | $extensions = explode( '|', array_search( $mime_type, wp_get_mime_types() ) ); |
| 483 | 487 | |
| 484 | - if ( empty( $extensions[0] ) ) |
|
| 485 | - return false; |
|
| 488 | + if ( empty( $extensions[0] ) ) { |
|
| 489 | + return false; |
|
| 490 | + } |
|
| 486 | 491 | |
| 487 | 492 | return $extensions[0]; |
| 488 | 493 | } |
@@ -524,7 +524,7 @@ |
||
| 524 | 524 | * @since 2.5.0 |
| 525 | 525 | * |
| 526 | 526 | * @param string $data Input string |
| 527 | - * @return array array(type, value) |
|
| 527 | + * @return string[] array(type, value) |
|
| 528 | 528 | */ |
| 529 | 529 | function prep_atom_text_construct($data) { |
| 530 | 530 | if (strpos($data, '<') === false && strpos($data, '&') === false) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param string $info Converted string value of the blog information. |
| 37 | 37 | * @param string $show The type of blog information to retrieve. |
| 38 | 38 | */ |
| 39 | - return apply_filters( 'get_bloginfo_rss', convert_chars( $info ), $show ); |
|
| 39 | + return apply_filters('get_bloginfo_rss', convert_chars($info), $show); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param string $rss_container RSS container for the blog information. |
| 63 | 63 | * @param string $show The type of blog information to retrieve. |
| 64 | 64 | */ |
| 65 | - echo apply_filters( 'bloginfo_rss', get_bloginfo_rss( $show ), $show ); |
|
| 65 | + echo apply_filters('bloginfo_rss', get_bloginfo_rss($show), $show); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @param string $feed_type Type of default feed. Possible values include 'rss2', 'atom'. |
| 85 | 85 | * Default 'rss2'. |
| 86 | 86 | */ |
| 87 | - $default_feed = apply_filters( 'default_feed', 'rss2' ); |
|
| 87 | + $default_feed = apply_filters('default_feed', 'rss2'); |
|
| 88 | 88 | return 'rss' == $default_feed ? 'rss2' : $default_feed; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | * @param string $deprecated Unused.. |
| 98 | 98 | * @return string The document title. |
| 99 | 99 | */ |
| 100 | -function get_wp_title_rss( $deprecated = '–' ) { |
|
| 101 | - if ( '–' !== $deprecated ) { |
|
| 100 | +function get_wp_title_rss($deprecated = '–') { |
|
| 101 | + if ('–' !== $deprecated) { |
|
| 102 | 102 | /* translators: %s: 'document_title_separator' filter name */ |
| 103 | - _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
|
| 103 | + _deprecated_argument(__FUNCTION__, '4.4.0', sprintf(__('Use the %s filter instead.'), '<code>document_title_separator</code>')); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @param string $title The current blog title. |
| 113 | 113 | * @param string $deprecated Unused. |
| 114 | 114 | */ |
| 115 | - return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated ); |
|
| 115 | + return apply_filters('get_wp_title_rss', wp_get_document_title(), $deprecated); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @param string $deprecated Unused. |
| 125 | 125 | */ |
| 126 | -function wp_title_rss( $deprecated = '–' ) { |
|
| 127 | - if ( '–' !== $deprecated ) { |
|
| 126 | +function wp_title_rss($deprecated = '–') { |
|
| 127 | + if ('–' !== $deprecated) { |
|
| 128 | 128 | /* translators: %s: 'document_title_separator' filter name */ |
| 129 | - _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
|
| 129 | + _deprecated_argument(__FUNCTION__, '4.4.0', sprintf(__('Use the %s filter instead.'), '<code>document_title_separator</code>')); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param string $wp_title_rss The current blog title. |
| 141 | 141 | * @param string $deprecated Unused. |
| 142 | 142 | */ |
| 143 | - echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated ); |
|
| 143 | + echo apply_filters('wp_title_rss', get_wp_title_rss(), $deprecated); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @param string $title The current post title. |
| 162 | 162 | */ |
| 163 | - $title = apply_filters( 'the_title_rss', $title ); |
|
| 163 | + $title = apply_filters('the_title_rss', $title); |
|
| 164 | 164 | return $title; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @return string The filtered content. |
| 184 | 184 | */ |
| 185 | 185 | function get_the_content_feed($feed_type = null) { |
| 186 | - if ( !$feed_type ) |
|
| 186 | + if ( ! $feed_type) |
|
| 187 | 187 | $feed_type = get_default_feed(); |
| 188 | 188 | |
| 189 | 189 | /** This filter is documented in wp-includes/post-template.php */ |
| 190 | - $content = apply_filters( 'the_content', get_the_content() ); |
|
| 190 | + $content = apply_filters('the_content', get_the_content()); |
|
| 191 | 191 | $content = str_replace(']]>', ']]>', $content); |
| 192 | 192 | /** |
| 193 | 193 | * Filters the post content for use in feeds. |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'. |
| 199 | 199 | * Default 'rss2'. |
| 200 | 200 | */ |
| 201 | - return apply_filters( 'the_content_feed', $content, $feed_type ); |
|
| 201 | + return apply_filters('the_content_feed', $content, $feed_type); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @param string $output The current post excerpt. |
| 228 | 228 | */ |
| 229 | - echo apply_filters( 'the_excerpt_rss', $output ); |
|
| 229 | + echo apply_filters('the_excerpt_rss', $output); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @param string $post_permalink The current post permalink. |
| 244 | 244 | */ |
| 245 | - echo esc_url( apply_filters( 'the_permalink_rss', get_permalink() ) ); |
|
| 245 | + echo esc_url(apply_filters('the_permalink_rss', get_permalink())); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * @param string $comment_permalink The current comment permalink with |
| 261 | 261 | * '#comments' appended. |
| 262 | 262 | */ |
| 263 | - echo esc_url( apply_filters( 'comments_link_feed', get_comments_link() ) ); |
|
| 263 | + echo esc_url(apply_filters('comments_link_feed', get_comments_link())); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @param int|WP_Comment $comment_id Optional comment object or id. Defaults to global comment object. |
| 272 | 272 | */ |
| 273 | 273 | function comment_guid($comment_id = null) { |
| 274 | - echo esc_url( get_comment_guid($comment_id) ); |
|
| 274 | + echo esc_url(get_comment_guid($comment_id)); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,10 +285,10 @@ discard block |
||
| 285 | 285 | function get_comment_guid($comment_id = null) { |
| 286 | 286 | $comment = get_comment($comment_id); |
| 287 | 287 | |
| 288 | - if ( !is_object($comment) ) |
|
| 288 | + if ( ! is_object($comment)) |
|
| 289 | 289 | return false; |
| 290 | 290 | |
| 291 | - return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID; |
|
| 291 | + return get_the_guid($comment->comment_post_ID).'#comment-'.$comment->comment_ID; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * |
| 300 | 300 | * @param int|WP_Comment $comment Optional. Comment object or id. Defaults to global comment object. |
| 301 | 301 | */ |
| 302 | -function comment_link( $comment = null ) { |
|
| 302 | +function comment_link($comment = null) { |
|
| 303 | 303 | /** |
| 304 | 304 | * Filters the current comment's permalink. |
| 305 | 305 | * |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @param string $comment_permalink The current comment permalink. |
| 311 | 311 | */ |
| 312 | - echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) ); |
|
| 312 | + echo esc_url(apply_filters('comment_link', get_comment_link($comment))); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * |
| 330 | 330 | * @param string $comment_author The current comment author. |
| 331 | 331 | */ |
| 332 | - return apply_filters( 'comment_author_rss', get_comment_author() ); |
|
| 332 | + return apply_filters('comment_author_rss', get_comment_author()); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | * |
| 356 | 356 | * @param string $comment_text The content of the current comment. |
| 357 | 357 | */ |
| 358 | - $comment_text = apply_filters( 'comment_text_rss', $comment_text ); |
|
| 358 | + $comment_text = apply_filters('comment_text_rss', $comment_text); |
|
| 359 | 359 | echo $comment_text; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * @return string All of the post categories for displaying in the feed. |
| 373 | 373 | */ |
| 374 | 374 | function get_the_category_rss($type = null) { |
| 375 | - if ( empty($type) ) |
|
| 375 | + if (empty($type)) |
|
| 376 | 376 | $type = get_default_feed(); |
| 377 | 377 | $categories = get_the_category(); |
| 378 | 378 | $tags = get_the_tags(); |
@@ -380,26 +380,26 @@ discard block |
||
| 380 | 380 | $cat_names = array(); |
| 381 | 381 | |
| 382 | 382 | $filter = 'rss'; |
| 383 | - if ( 'atom' == $type ) |
|
| 383 | + if ('atom' == $type) |
|
| 384 | 384 | $filter = 'raw'; |
| 385 | 385 | |
| 386 | - if ( !empty($categories) ) foreach ( (array) $categories as $category ) { |
|
| 386 | + if ( ! empty($categories)) foreach ((array) $categories as $category) { |
|
| 387 | 387 | $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { |
|
| 390 | + if ( ! empty($tags)) foreach ((array) $tags as $tag) { |
|
| 391 | 391 | $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | $cat_names = array_unique($cat_names); |
| 395 | 395 | |
| 396 | - foreach ( $cat_names as $cat_name ) { |
|
| 397 | - if ( 'rdf' == $type ) |
|
| 396 | + foreach ($cat_names as $cat_name) { |
|
| 397 | + if ('rdf' == $type) |
|
| 398 | 398 | $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; |
| 399 | - elseif ( 'atom' == $type ) |
|
| 400 | - $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); |
|
| 399 | + elseif ('atom' == $type) |
|
| 400 | + $the_list .= sprintf('<category scheme="%1$s" term="%2$s" />', esc_attr(get_bloginfo_rss('url')), esc_attr($cat_name)); |
|
| 401 | 401 | else |
| 402 | - $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; |
|
| 402 | + $the_list .= "\t\t<category><![CDATA[".@html_entity_decode($cat_name, ENT_COMPAT, get_option('blog_charset'))."]]></category>\n"; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @param string $type Type of feed. Possible values include 'rss2', 'atom'. |
| 412 | 412 | * Default 'rss2'. |
| 413 | 413 | */ |
| 414 | - return apply_filters( 'the_category_rss', $the_list, $type ); |
|
| 414 | + return apply_filters('the_category_rss', $the_list, $type); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -457,16 +457,16 @@ discard block |
||
| 457 | 457 | * @since 1.5.0 |
| 458 | 458 | */ |
| 459 | 459 | function rss_enclosure() { |
| 460 | - if ( post_password_required() ) |
|
| 460 | + if (post_password_required()) |
|
| 461 | 461 | return; |
| 462 | 462 | |
| 463 | - foreach ( (array) get_post_custom() as $key => $val) { |
|
| 463 | + foreach ((array) get_post_custom() as $key => $val) { |
|
| 464 | 464 | if ($key == 'enclosure') { |
| 465 | - foreach ( (array) $val as $enc ) { |
|
| 465 | + foreach ((array) $val as $enc) { |
|
| 466 | 466 | $enclosure = explode("\n", $enc); |
| 467 | 467 | |
| 468 | 468 | // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' |
| 469 | - $t = preg_split('/[ \t]/', trim($enclosure[2]) ); |
|
| 469 | + $t = preg_split('/[ \t]/', trim($enclosure[2])); |
|
| 470 | 470 | $type = $t[0]; |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | * |
| 477 | 477 | * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
| 478 | 478 | */ |
| 479 | - echo apply_filters( 'rss_enclosure', '<enclosure url="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" length="' . trim( $enclosure[1] ) . '" type="' . $type . '" />' . "\n" ); |
|
| 479 | + echo apply_filters('rss_enclosure', '<enclosure url="'.trim(htmlspecialchars($enclosure[0])).'" length="'.trim($enclosure[1]).'" type="'.$type.'" />'."\n"); |
|
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | } |
@@ -496,12 +496,12 @@ discard block |
||
| 496 | 496 | * @since 2.2.0 |
| 497 | 497 | */ |
| 498 | 498 | function atom_enclosure() { |
| 499 | - if ( post_password_required() ) |
|
| 499 | + if (post_password_required()) |
|
| 500 | 500 | return; |
| 501 | 501 | |
| 502 | - foreach ( (array) get_post_custom() as $key => $val ) { |
|
| 502 | + foreach ((array) get_post_custom() as $key => $val) { |
|
| 503 | 503 | if ($key == 'enclosure') { |
| 504 | - foreach ( (array) $val as $enc ) { |
|
| 504 | + foreach ((array) $val as $enc) { |
|
| 505 | 505 | $enclosure = explode("\n", $enc); |
| 506 | 506 | /** |
| 507 | 507 | * Filters the atom enclosure HTML link tag for the current post. |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | * |
| 511 | 511 | * @param string $html_link_tag The HTML link tag with a URI and other attributes. |
| 512 | 512 | */ |
| 513 | - echo apply_filters( 'atom_enclosure', '<link href="' . trim( htmlspecialchars( $enclosure[0] ) ) . '" rel="enclosure" length="' . trim( $enclosure[1] ) . '" type="' . trim( $enclosure[2] ) . '" />' . "\n" ); |
|
| 513 | + echo apply_filters('atom_enclosure', '<link href="'.trim(htmlspecialchars($enclosure[0])).'" rel="enclosure" length="'.trim($enclosure[1]).'" type="'.trim($enclosure[2]).'" />'."\n"); |
|
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | } |
@@ -538,18 +538,18 @@ discard block |
||
| 538 | 538 | return array('text', $data); |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - if ( ! function_exists( 'xml_parser_create' ) ) { |
|
| 542 | - trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
| 541 | + if ( ! function_exists('xml_parser_create')) { |
|
| 542 | + trigger_error(__("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.")); |
|
| 543 | 543 | |
| 544 | - return array( 'html', "<![CDATA[$data]]>" ); |
|
| 544 | + return array('html', "<![CDATA[$data]]>"); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | $parser = xml_parser_create(); |
| 548 | - xml_parse($parser, '<div>' . $data . '</div>', true); |
|
| 548 | + xml_parse($parser, '<div>'.$data.'</div>', true); |
|
| 549 | 549 | $code = xml_get_error_code($parser); |
| 550 | 550 | xml_parser_free($parser); |
| 551 | 551 | |
| 552 | - if (!$code) { |
|
| 552 | + if ( ! $code) { |
|
| 553 | 553 | if (strpos($data, '<') === false) { |
| 554 | 554 | return array('text', $data); |
| 555 | 555 | } else { |
@@ -573,8 +573,8 @@ discard block |
||
| 573 | 573 | * @see get_site_icon_url() |
| 574 | 574 | */ |
| 575 | 575 | function atom_site_icon() { |
| 576 | - $url = get_site_icon_url( 32 ); |
|
| 577 | - if ( $url ) { |
|
| 576 | + $url = get_site_icon_url(32); |
|
| 577 | + if ($url) { |
|
| 578 | 578 | echo "<icon>$url</icon>\n"; |
| 579 | 579 | } |
| 580 | 580 | } |
@@ -586,17 +586,17 @@ discard block |
||
| 586 | 586 | */ |
| 587 | 587 | function rss2_site_icon() { |
| 588 | 588 | $rss_title = get_wp_title_rss(); |
| 589 | - if ( empty( $rss_title ) ) { |
|
| 590 | - $rss_title = get_bloginfo_rss( 'name' ); |
|
| 589 | + if (empty($rss_title)) { |
|
| 590 | + $rss_title = get_bloginfo_rss('name'); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - $url = get_site_icon_url( 32 ); |
|
| 594 | - if ( $url ) { |
|
| 593 | + $url = get_site_icon_url(32); |
|
| 594 | + if ($url) { |
|
| 595 | 595 | echo ' |
| 596 | 596 | <image> |
| 597 | - <url>' . convert_chars( $url ) . '</url> |
|
| 598 | - <title>' . $rss_title . '</title> |
|
| 599 | - <link>' . get_bloginfo_rss( 'url' ) . '</link> |
|
| 597 | + <url>' . convert_chars($url).'</url> |
|
| 598 | + <title>' . $rss_title.'</title> |
|
| 599 | + <link>' . get_bloginfo_rss('url').'</link> |
|
| 600 | 600 | <width>32</width> |
| 601 | 601 | <height>32</height> |
| 602 | 602 | </image> ' . "\n"; |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | * |
| 623 | 623 | * @param string $feed_link The link for the feed with set URL scheme. |
| 624 | 624 | */ |
| 625 | - echo esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ); |
|
| 625 | + echo esc_url(apply_filters('self_link', set_url_scheme('http://'.$host['host'].wp_unslash($_SERVER['REQUEST_URI'])))); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | * |
| 633 | 633 | * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
| 634 | 634 | */ |
| 635 | -function feed_content_type( $type = '' ) { |
|
| 636 | - if ( empty($type) ) |
|
| 635 | +function feed_content_type($type = '') { |
|
| 636 | + if (empty($type)) |
|
| 637 | 637 | $type = get_default_feed(); |
| 638 | 638 | |
| 639 | 639 | $types = array( |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | 'rdf' => 'application/rdf+xml' |
| 645 | 645 | ); |
| 646 | 646 | |
| 647 | - $content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream'; |
|
| 647 | + $content_type = ( ! empty($types[$type])) ? $types[$type] : 'application/octet-stream'; |
|
| 648 | 648 | |
| 649 | 649 | /** |
| 650 | 650 | * Filters the content type for a specific feed type. |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @param string $content_type Content type indicating the type of data that a feed contains. |
| 655 | 655 | * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
| 656 | 656 | */ |
| 657 | - return apply_filters( 'feed_content_type', $content_type, $type ); |
|
| 657 | + return apply_filters('feed_content_type', $content_type, $type); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -668,29 +668,29 @@ discard block |
||
| 668 | 668 | * |
| 669 | 669 | * @return WP_Error|SimplePie WP_Error object on failure or SimplePie object on success |
| 670 | 670 | */ |
| 671 | -function fetch_feed( $url ) { |
|
| 672 | - if ( ! class_exists( 'SimplePie', false ) ) { |
|
| 673 | - require_once( ABSPATH . WPINC . '/class-simplepie.php' ); |
|
| 671 | +function fetch_feed($url) { |
|
| 672 | + if ( ! class_exists('SimplePie', false)) { |
|
| 673 | + require_once(ABSPATH.WPINC.'/class-simplepie.php'); |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | - require_once( ABSPATH . WPINC . '/class-wp-feed-cache.php' ); |
|
| 677 | - require_once( ABSPATH . WPINC . '/class-wp-feed-cache-transient.php' ); |
|
| 678 | - require_once( ABSPATH . WPINC . '/class-wp-simplepie-file.php' ); |
|
| 679 | - require_once( ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php' ); |
|
| 676 | + require_once(ABSPATH.WPINC.'/class-wp-feed-cache.php'); |
|
| 677 | + require_once(ABSPATH.WPINC.'/class-wp-feed-cache-transient.php'); |
|
| 678 | + require_once(ABSPATH.WPINC.'/class-wp-simplepie-file.php'); |
|
| 679 | + require_once(ABSPATH.WPINC.'/class-wp-simplepie-sanitize-kses.php'); |
|
| 680 | 680 | |
| 681 | 681 | $feed = new SimplePie(); |
| 682 | 682 | |
| 683 | - $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' ); |
|
| 683 | + $feed->set_sanitize_class('WP_SimplePie_Sanitize_KSES'); |
|
| 684 | 684 | // We must manually overwrite $feed->sanitize because SimplePie's |
| 685 | 685 | // constructor sets it before we have a chance to set the sanitization class |
| 686 | 686 | $feed->sanitize = new WP_SimplePie_Sanitize_KSES(); |
| 687 | 687 | |
| 688 | - $feed->set_cache_class( 'WP_Feed_Cache' ); |
|
| 689 | - $feed->set_file_class( 'WP_SimplePie_File' ); |
|
| 688 | + $feed->set_cache_class('WP_Feed_Cache'); |
|
| 689 | + $feed->set_file_class('WP_SimplePie_File'); |
|
| 690 | 690 | |
| 691 | - $feed->set_feed_url( $url ); |
|
| 691 | + $feed->set_feed_url($url); |
|
| 692 | 692 | /** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */ |
| 693 | - $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); |
|
| 693 | + $feed->set_cache_duration(apply_filters('wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url)); |
|
| 694 | 694 | /** |
| 695 | 695 | * Fires just before processing the SimplePie feed object. |
| 696 | 696 | * |
@@ -699,12 +699,12 @@ discard block |
||
| 699 | 699 | * @param object &$feed SimplePie feed object, passed by reference. |
| 700 | 700 | * @param mixed $url URL of feed to retrieve. If an array of URLs, the feeds are merged. |
| 701 | 701 | */ |
| 702 | - do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); |
|
| 702 | + do_action_ref_array('wp_feed_options', array(&$feed, $url)); |
|
| 703 | 703 | $feed->init(); |
| 704 | - $feed->set_output_encoding( get_option( 'blog_charset' ) ); |
|
| 704 | + $feed->set_output_encoding(get_option('blog_charset')); |
|
| 705 | 705 | |
| 706 | - if ( $feed->error() ) |
|
| 707 | - return new WP_Error( 'simplepie-error', $feed->error() ); |
|
| 706 | + if ($feed->error()) |
|
| 707 | + return new WP_Error('simplepie-error', $feed->error()); |
|
| 708 | 708 | |
| 709 | 709 | return $feed; |
| 710 | 710 | } |
@@ -183,8 +183,9 @@ discard block |
||
| 183 | 183 | * @return string The filtered content. |
| 184 | 184 | */ |
| 185 | 185 | function get_the_content_feed($feed_type = null) { |
| 186 | - if ( !$feed_type ) |
|
| 187 | - $feed_type = get_default_feed(); |
|
| 186 | + if ( !$feed_type ) { |
|
| 187 | + $feed_type = get_default_feed(); |
|
| 188 | + } |
|
| 188 | 189 | |
| 189 | 190 | /** This filter is documented in wp-includes/post-template.php */ |
| 190 | 191 | $content = apply_filters( 'the_content', get_the_content() ); |
@@ -285,8 +286,9 @@ discard block |
||
| 285 | 286 | function get_comment_guid($comment_id = null) { |
| 286 | 287 | $comment = get_comment($comment_id); |
| 287 | 288 | |
| 288 | - if ( !is_object($comment) ) |
|
| 289 | - return false; |
|
| 289 | + if ( !is_object($comment) ) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 290 | 292 | |
| 291 | 293 | return get_the_guid($comment->comment_post_ID) . '#comment-' . $comment->comment_ID; |
| 292 | 294 | } |
@@ -372,34 +374,41 @@ discard block |
||
| 372 | 374 | * @return string All of the post categories for displaying in the feed. |
| 373 | 375 | */ |
| 374 | 376 | function get_the_category_rss($type = null) { |
| 375 | - if ( empty($type) ) |
|
| 376 | - $type = get_default_feed(); |
|
| 377 | + if ( empty($type) ) { |
|
| 378 | + $type = get_default_feed(); |
|
| 379 | + } |
|
| 377 | 380 | $categories = get_the_category(); |
| 378 | 381 | $tags = get_the_tags(); |
| 379 | 382 | $the_list = ''; |
| 380 | 383 | $cat_names = array(); |
| 381 | 384 | |
| 382 | 385 | $filter = 'rss'; |
| 383 | - if ( 'atom' == $type ) |
|
| 384 | - $filter = 'raw'; |
|
| 386 | + if ( 'atom' == $type ) { |
|
| 387 | + $filter = 'raw'; |
|
| 388 | + } |
|
| 385 | 389 | |
| 386 | - if ( !empty($categories) ) foreach ( (array) $categories as $category ) { |
|
| 390 | + if ( !empty($categories) ) { |
|
| 391 | + foreach ( (array) $categories as $category ) { |
|
| 387 | 392 | $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); |
| 388 | 393 | } |
| 394 | + } |
|
| 389 | 395 | |
| 390 | - if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { |
|
| 396 | + if ( !empty($tags) ) { |
|
| 397 | + foreach ( (array) $tags as $tag ) { |
|
| 391 | 398 | $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); |
| 392 | 399 | } |
| 400 | + } |
|
| 393 | 401 | |
| 394 | 402 | $cat_names = array_unique($cat_names); |
| 395 | 403 | |
| 396 | 404 | foreach ( $cat_names as $cat_name ) { |
| 397 | - if ( 'rdf' == $type ) |
|
| 398 | - $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; |
|
| 399 | - elseif ( 'atom' == $type ) |
|
| 400 | - $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); |
|
| 401 | - else |
|
| 402 | - $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; |
|
| 405 | + if ( 'rdf' == $type ) { |
|
| 406 | + $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; |
|
| 407 | + } elseif ( 'atom' == $type ) { |
|
| 408 | + $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); |
|
| 409 | + } else { |
|
| 410 | + $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; |
|
| 411 | + } |
|
| 403 | 412 | } |
| 404 | 413 | |
| 405 | 414 | /** |
@@ -435,10 +444,11 @@ discard block |
||
| 435 | 444 | */ |
| 436 | 445 | function html_type_rss() { |
| 437 | 446 | $type = get_bloginfo('html_type'); |
| 438 | - if (strpos($type, 'xhtml') !== false) |
|
| 439 | - $type = 'xhtml'; |
|
| 440 | - else |
|
| 441 | - $type = 'html'; |
|
| 447 | + if (strpos($type, 'xhtml') !== false) { |
|
| 448 | + $type = 'xhtml'; |
|
| 449 | + } else { |
|
| 450 | + $type = 'html'; |
|
| 451 | + } |
|
| 442 | 452 | echo $type; |
| 443 | 453 | } |
| 444 | 454 | |
@@ -457,8 +467,9 @@ discard block |
||
| 457 | 467 | * @since 1.5.0 |
| 458 | 468 | */ |
| 459 | 469 | function rss_enclosure() { |
| 460 | - if ( post_password_required() ) |
|
| 461 | - return; |
|
| 470 | + if ( post_password_required() ) { |
|
| 471 | + return; |
|
| 472 | + } |
|
| 462 | 473 | |
| 463 | 474 | foreach ( (array) get_post_custom() as $key => $val) { |
| 464 | 475 | if ($key == 'enclosure') { |
@@ -496,8 +507,9 @@ discard block |
||
| 496 | 507 | * @since 2.2.0 |
| 497 | 508 | */ |
| 498 | 509 | function atom_enclosure() { |
| 499 | - if ( post_password_required() ) |
|
| 500 | - return; |
|
| 510 | + if ( post_password_required() ) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 501 | 513 | |
| 502 | 514 | foreach ( (array) get_post_custom() as $key => $val ) { |
| 503 | 515 | if ($key == 'enclosure') { |
@@ -633,8 +645,9 @@ discard block |
||
| 633 | 645 | * @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
| 634 | 646 | */ |
| 635 | 647 | function feed_content_type( $type = '' ) { |
| 636 | - if ( empty($type) ) |
|
| 637 | - $type = get_default_feed(); |
|
| 648 | + if ( empty($type) ) { |
|
| 649 | + $type = get_default_feed(); |
|
| 650 | + } |
|
| 638 | 651 | |
| 639 | 652 | $types = array( |
| 640 | 653 | 'rss' => 'application/rss+xml', |
@@ -703,8 +716,9 @@ discard block |
||
| 703 | 716 | $feed->init(); |
| 704 | 717 | $feed->set_output_encoding( get_option( 'blog_charset' ) ); |
| 705 | 718 | |
| 706 | - if ( $feed->error() ) |
|
| 707 | - return new WP_Error( 'simplepie-error', $feed->error() ); |
|
| 719 | + if ( $feed->error() ) { |
|
| 720 | + return new WP_Error( 'simplepie-error', $feed->error() ); |
|
| 721 | + } |
|
| 708 | 722 | |
| 709 | 723 | return $feed; |
| 710 | 724 | } |