@@ -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,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,71 +165,71 @@ 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 | endif; // twentyeleven_setup |
| 231 | 231 | |
| 232 | -if ( ! function_exists( 'twentyeleven_header_style' ) ) : |
|
| 232 | +if ( ! function_exists('twentyeleven_header_style')) : |
|
| 233 | 233 | /** |
| 234 | 234 | * Styles the header image and text displayed on the blog. |
| 235 | 235 | * |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | $text_color = get_header_textcolor(); |
| 240 | 240 | |
| 241 | 241 | // If no custom options for text are set, let's bail. |
| 242 | - if ( $text_color == HEADER_TEXTCOLOR ) |
|
| 242 | + if ($text_color == HEADER_TEXTCOLOR) |
|
| 243 | 243 | return; |
| 244 | 244 | |
| 245 | 245 | // If we get this far, we have custom styles. Let's do this. |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | <style type="text/css" id="twentyeleven-header-css"> |
| 248 | 248 | <?php |
| 249 | 249 | // Has the text been hidden? |
| 250 | - if ( 'blank' == $text_color ) : |
|
| 250 | + if ('blank' == $text_color) : |
|
| 251 | 251 | ?> |
| 252 | 252 | #site-title, |
| 253 | 253 | #site-description { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | endif; // twentyeleven_header_style |
| 271 | 271 | |
| 272 | -if ( ! function_exists( 'twentyeleven_admin_header_style' ) ) : |
|
| 272 | +if ( ! function_exists('twentyeleven_admin_header_style')) : |
|
| 273 | 273 | /** |
| 274 | 274 | * Styles the header image displayed on the Appearance > Header admin panel. |
| 275 | 275 | * |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | <?php |
| 304 | 304 | // If the user has set a custom color for the text use that |
| 305 | - if ( get_header_textcolor() != HEADER_TEXTCOLOR ) : |
|
| 305 | + if (get_header_textcolor() != HEADER_TEXTCOLOR) : |
|
| 306 | 306 | ?> |
| 307 | 307 | #site-title a, |
| 308 | 308 | #site-description { |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | endif; // twentyeleven_admin_header_style |
| 321 | 321 | |
| 322 | -if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : |
|
| 322 | +if ( ! function_exists('twentyeleven_admin_header_image')) : |
|
| 323 | 323 | /** |
| 324 | 324 | * Custom header image markup displayed on the Appearance > Header admin panel. |
| 325 | 325 | * |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | $color = get_header_textcolor(); |
| 334 | 334 | $image = get_header_image(); |
| 335 | 335 | $style = 'display: none;'; |
| 336 | - if ( $color && $color != 'blank' ) { |
|
| 337 | - $style = 'color: #' . $color . ';'; |
|
| 336 | + if ($color && $color != 'blank') { |
|
| 337 | + $style = 'color: #'.$color.';'; |
|
| 338 | 338 | } |
| 339 | 339 | ?> |
| 340 | - <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> |
|
| 341 | - <div id="desc" class="displaying-header-text" style="<?php echo esc_attr( $style ); ?>"><?php bloginfo( 'description' ); ?></div> |
|
| 342 | - <?php if ( $image ) : ?> |
|
| 343 | - <img src="<?php echo esc_url( $image ); ?>" alt="" /> |
|
| 340 | + <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> |
|
| 341 | + <div id="desc" class="displaying-header-text" style="<?php echo esc_attr($style); ?>"><?php bloginfo('description'); ?></div> |
|
| 342 | + <?php if ($image) : ?> |
|
| 343 | + <img src="<?php echo esc_url($image); ?>" alt="" /> |
|
| 344 | 344 | <?php endif; ?> |
| 345 | 345 | </div> |
| 346 | 346 | <?php } |
@@ -358,12 +358,12 @@ discard block |
||
| 358 | 358 | * @param int $length The number of excerpt characters. |
| 359 | 359 | * @return int The filtered number of characters. |
| 360 | 360 | */ |
| 361 | -function twentyeleven_excerpt_length( $length ) { |
|
| 361 | +function twentyeleven_excerpt_length($length) { |
|
| 362 | 362 | return 40; |
| 363 | 363 | } |
| 364 | -add_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); |
|
| 364 | +add_filter('excerpt_length', 'twentyeleven_excerpt_length'); |
|
| 365 | 365 | |
| 366 | -if ( ! function_exists( 'twentyeleven_continue_reading_link' ) ) : |
|
| 366 | +if ( ! function_exists('twentyeleven_continue_reading_link')) : |
|
| 367 | 367 | /** |
| 368 | 368 | * Return a "Continue Reading" link for excerpts |
| 369 | 369 | * |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * @return string The "Continue Reading" HTML link. |
| 373 | 373 | */ |
| 374 | 374 | function twentyeleven_continue_reading_link() { |
| 375 | - return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) . '</a>'; |
|
| 375 | + return ' <a href="'.esc_url(get_permalink()).'">'.__('Continue reading <span class="meta-nav">→</span>', 'twentyeleven').'</a>'; |
|
| 376 | 376 | } |
| 377 | 377 | endif; // twentyeleven_continue_reading_link |
| 378 | 378 | |
@@ -389,13 +389,13 @@ discard block |
||
| 389 | 389 | * @param string $more The Read More text. |
| 390 | 390 | * @return The filtered Read More text. |
| 391 | 391 | */ |
| 392 | -function twentyeleven_auto_excerpt_more( $more ) { |
|
| 393 | - if ( ! is_admin() ) { |
|
| 394 | - return ' …' . twentyeleven_continue_reading_link(); |
|
| 392 | +function twentyeleven_auto_excerpt_more($more) { |
|
| 393 | + if ( ! is_admin()) { |
|
| 394 | + return ' …'.twentyeleven_continue_reading_link(); |
|
| 395 | 395 | } |
| 396 | 396 | return $more; |
| 397 | 397 | } |
| 398 | -add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' ); |
|
| 398 | +add_filter('excerpt_more', 'twentyeleven_auto_excerpt_more'); |
|
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | 401 | * Add a pretty "Continue Reading" link to custom post excerpts. |
@@ -408,13 +408,13 @@ discard block |
||
| 408 | 408 | * @param string $output The "Continue Reading" link. |
| 409 | 409 | * @return string The filtered "Continue Reading" link. |
| 410 | 410 | */ |
| 411 | -function twentyeleven_custom_excerpt_more( $output ) { |
|
| 412 | - if ( has_excerpt() && ! is_attachment() && ! is_admin() ) { |
|
| 411 | +function twentyeleven_custom_excerpt_more($output) { |
|
| 412 | + if (has_excerpt() && ! is_attachment() && ! is_admin()) { |
|
| 413 | 413 | $output .= twentyeleven_continue_reading_link(); |
| 414 | 414 | } |
| 415 | 415 | return $output; |
| 416 | 416 | } |
| 417 | -add_filter( 'get_the_excerpt', 'twentyeleven_custom_excerpt_more' ); |
|
| 417 | +add_filter('get_the_excerpt', 'twentyeleven_custom_excerpt_more'); |
|
| 418 | 418 | |
| 419 | 419 | /** |
| 420 | 420 | * Show a home link for the wp_nav_menu() fallback, wp_page_menu(). |
@@ -424,12 +424,12 @@ discard block |
||
| 424 | 424 | * @param array $args The page menu arguments. @see wp_page_menu() |
| 425 | 425 | * @return array The filtered page menu arguments. |
| 426 | 426 | */ |
| 427 | -function twentyeleven_page_menu_args( $args ) { |
|
| 428 | - if ( ! isset( $args['show_home'] ) ) |
|
| 427 | +function twentyeleven_page_menu_args($args) { |
|
| 428 | + if ( ! isset($args['show_home'])) |
|
| 429 | 429 | $args['show_home'] = true; |
| 430 | 430 | return $args; |
| 431 | 431 | } |
| 432 | -add_filter( 'wp_page_menu_args', 'twentyeleven_page_menu_args' ); |
|
| 432 | +add_filter('wp_page_menu_args', 'twentyeleven_page_menu_args'); |
|
| 433 | 433 | |
| 434 | 434 | /** |
| 435 | 435 | * Register sidebars and widgetized areas. |
@@ -440,60 +440,60 @@ discard block |
||
| 440 | 440 | */ |
| 441 | 441 | function twentyeleven_widgets_init() { |
| 442 | 442 | |
| 443 | - register_widget( 'Twenty_Eleven_Ephemera_Widget' ); |
|
| 443 | + register_widget('Twenty_Eleven_Ephemera_Widget'); |
|
| 444 | 444 | |
| 445 | - register_sidebar( array( |
|
| 446 | - 'name' => __( 'Main Sidebar', 'twentyeleven' ), |
|
| 445 | + register_sidebar(array( |
|
| 446 | + 'name' => __('Main Sidebar', 'twentyeleven'), |
|
| 447 | 447 | 'id' => 'sidebar-1', |
| 448 | 448 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 449 | 449 | 'after_widget' => '</aside>', |
| 450 | 450 | 'before_title' => '<h3 class="widget-title">', |
| 451 | 451 | 'after_title' => '</h3>', |
| 452 | - ) ); |
|
| 452 | + )); |
|
| 453 | 453 | |
| 454 | - register_sidebar( array( |
|
| 455 | - 'name' => __( 'Showcase Sidebar', 'twentyeleven' ), |
|
| 454 | + register_sidebar(array( |
|
| 455 | + 'name' => __('Showcase Sidebar', 'twentyeleven'), |
|
| 456 | 456 | 'id' => 'sidebar-2', |
| 457 | - 'description' => __( 'The sidebar for the optional Showcase Template', 'twentyeleven' ), |
|
| 457 | + 'description' => __('The sidebar for the optional Showcase Template', 'twentyeleven'), |
|
| 458 | 458 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 459 | 459 | 'after_widget' => '</aside>', |
| 460 | 460 | 'before_title' => '<h3 class="widget-title">', |
| 461 | 461 | 'after_title' => '</h3>', |
| 462 | - ) ); |
|
| 462 | + )); |
|
| 463 | 463 | |
| 464 | - register_sidebar( array( |
|
| 465 | - 'name' => __( 'Footer Area One', 'twentyeleven' ), |
|
| 464 | + register_sidebar(array( |
|
| 465 | + 'name' => __('Footer Area One', 'twentyeleven'), |
|
| 466 | 466 | 'id' => 'sidebar-3', |
| 467 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 467 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 468 | 468 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 469 | 469 | 'after_widget' => '</aside>', |
| 470 | 470 | 'before_title' => '<h3 class="widget-title">', |
| 471 | 471 | 'after_title' => '</h3>', |
| 472 | - ) ); |
|
| 472 | + )); |
|
| 473 | 473 | |
| 474 | - register_sidebar( array( |
|
| 475 | - 'name' => __( 'Footer Area Two', 'twentyeleven' ), |
|
| 474 | + register_sidebar(array( |
|
| 475 | + 'name' => __('Footer Area Two', 'twentyeleven'), |
|
| 476 | 476 | 'id' => 'sidebar-4', |
| 477 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 477 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 478 | 478 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 479 | 479 | 'after_widget' => '</aside>', |
| 480 | 480 | 'before_title' => '<h3 class="widget-title">', |
| 481 | 481 | 'after_title' => '</h3>', |
| 482 | - ) ); |
|
| 482 | + )); |
|
| 483 | 483 | |
| 484 | - register_sidebar( array( |
|
| 485 | - 'name' => __( 'Footer Area Three', 'twentyeleven' ), |
|
| 484 | + register_sidebar(array( |
|
| 485 | + 'name' => __('Footer Area Three', 'twentyeleven'), |
|
| 486 | 486 | 'id' => 'sidebar-5', |
| 487 | - 'description' => __( 'An optional widget area for your site footer', 'twentyeleven' ), |
|
| 487 | + 'description' => __('An optional widget area for your site footer', 'twentyeleven'), |
|
| 488 | 488 | 'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
| 489 | 489 | 'after_widget' => '</aside>', |
| 490 | 490 | 'before_title' => '<h3 class="widget-title">', |
| 491 | 491 | 'after_title' => '</h3>', |
| 492 | - ) ); |
|
| 492 | + )); |
|
| 493 | 493 | } |
| 494 | -add_action( 'widgets_init', 'twentyeleven_widgets_init' ); |
|
| 494 | +add_action('widgets_init', 'twentyeleven_widgets_init'); |
|
| 495 | 495 | |
| 496 | -if ( ! function_exists( 'twentyeleven_content_nav' ) ) : |
|
| 496 | +if ( ! function_exists('twentyeleven_content_nav')) : |
|
| 497 | 497 | /** |
| 498 | 498 | * Display navigation to next/previous pages when applicable. |
| 499 | 499 | * |
@@ -501,14 +501,14 @@ discard block |
||
| 501 | 501 | * |
| 502 | 502 | * @param string $html_id The HTML id attribute. |
| 503 | 503 | */ |
| 504 | -function twentyeleven_content_nav( $html_id ) { |
|
| 504 | +function twentyeleven_content_nav($html_id) { |
|
| 505 | 505 | global $wp_query; |
| 506 | 506 | |
| 507 | - if ( $wp_query->max_num_pages > 1 ) : ?> |
|
| 508 | - <nav id="<?php echo esc_attr( $html_id ); ?>"> |
|
| 509 | - <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3> |
|
| 510 | - <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyeleven' ) ); ?></div> |
|
| 511 | - <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></div> |
|
| 507 | + if ($wp_query->max_num_pages > 1) : ?> |
|
| 508 | + <nav id="<?php echo esc_attr($html_id); ?>"> |
|
| 509 | + <h3 class="assistive-text"><?php _e('Post navigation', 'twentyeleven'); ?></h3> |
|
| 510 | + <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">←</span> Older posts', 'twentyeleven')); ?></div> |
|
| 511 | + <div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">→</span>', 'twentyeleven')); ?></div> |
|
| 512 | 512 | </nav><!-- #nav-above --> |
| 513 | 513 | <?php endif; |
| 514 | 514 | } |
@@ -526,13 +526,13 @@ discard block |
||
| 526 | 526 | */ |
| 527 | 527 | function twentyeleven_get_first_url() { |
| 528 | 528 | $content = get_the_content(); |
| 529 | - $has_url = function_exists( 'get_url_in_content' ) ? get_url_in_content( $content ) : false; |
|
| 529 | + $has_url = function_exists('get_url_in_content') ? get_url_in_content($content) : false; |
|
| 530 | 530 | |
| 531 | - if ( ! $has_url ) |
|
| 531 | + if ( ! $has_url) |
|
| 532 | 532 | $has_url = twentyeleven_url_grabber(); |
| 533 | 533 | |
| 534 | 534 | /** This filter is documented in wp-includes/link-template.php */ |
| 535 | - return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); |
|
| 535 | + return ($has_url) ? $has_url : apply_filters('the_permalink', get_permalink()); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -543,10 +543,10 @@ discard block |
||
| 543 | 543 | * @return string|bool URL or false when no link is present. |
| 544 | 544 | */ |
| 545 | 545 | function twentyeleven_url_grabber() { |
| 546 | - if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) ) |
|
| 546 | + if ( ! preg_match('/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches)) |
|
| 547 | 547 | return false; |
| 548 | 548 | |
| 549 | - return esc_url_raw( $matches[1] ); |
|
| 549 | + return esc_url_raw($matches[1]); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -557,18 +557,18 @@ discard block |
||
| 557 | 557 | function twentyeleven_footer_sidebar_class() { |
| 558 | 558 | $count = 0; |
| 559 | 559 | |
| 560 | - if ( is_active_sidebar( 'sidebar-3' ) ) |
|
| 560 | + if (is_active_sidebar('sidebar-3')) |
|
| 561 | 561 | $count++; |
| 562 | 562 | |
| 563 | - if ( is_active_sidebar( 'sidebar-4' ) ) |
|
| 563 | + if (is_active_sidebar('sidebar-4')) |
|
| 564 | 564 | $count++; |
| 565 | 565 | |
| 566 | - if ( is_active_sidebar( 'sidebar-5' ) ) |
|
| 566 | + if (is_active_sidebar('sidebar-5')) |
|
| 567 | 567 | $count++; |
| 568 | 568 | |
| 569 | 569 | $class = ''; |
| 570 | 570 | |
| 571 | - switch ( $count ) { |
|
| 571 | + switch ($count) { |
|
| 572 | 572 | case '1': |
| 573 | 573 | $class = 'one'; |
| 574 | 574 | break; |
@@ -580,11 +580,11 @@ discard block |
||
| 580 | 580 | break; |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if ( $class ) |
|
| 584 | - echo 'class="' . esc_attr( $class ) . '"'; |
|
| 583 | + if ($class) |
|
| 584 | + echo 'class="'.esc_attr($class).'"'; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | -if ( ! function_exists( 'twentyeleven_comment' ) ) : |
|
| 587 | +if ( ! function_exists('twentyeleven_comment')) : |
|
| 588 | 588 | /** |
| 589 | 589 | * Template for comments and pingbacks. |
| 590 | 590 | * |
@@ -599,14 +599,14 @@ discard block |
||
| 599 | 599 | * @param array $args An array of comment arguments. @see get_comment_reply_link() |
| 600 | 600 | * @param int $depth The depth of the comment. |
| 601 | 601 | */ |
| 602 | -function twentyeleven_comment( $comment, $args, $depth ) { |
|
| 602 | +function twentyeleven_comment($comment, $args, $depth) { |
|
| 603 | 603 | $GLOBALS['comment'] = $comment; |
| 604 | - switch ( $comment->comment_type ) : |
|
| 604 | + switch ($comment->comment_type) : |
|
| 605 | 605 | case 'pingback' : |
| 606 | 606 | case 'trackback' : |
| 607 | 607 | ?> |
| 608 | 608 | <li class="post pingback"> |
| 609 | - <p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p> |
|
| 609 | + <p><?php _e('Pingback:', 'twentyeleven'); ?> <?php comment_author_link(); ?><?php edit_comment_link(__('Edit', 'twentyeleven'), '<span class="edit-link">', '</span>'); ?></p> |
|
| 610 | 610 | <?php |
| 611 | 611 | break; |
| 612 | 612 | default : |
@@ -617,28 +617,28 @@ discard block |
||
| 617 | 617 | <div class="comment-author vcard"> |
| 618 | 618 | <?php |
| 619 | 619 | $avatar_size = 68; |
| 620 | - if ( '0' != $comment->comment_parent ) |
|
| 620 | + if ('0' != $comment->comment_parent) |
|
| 621 | 621 | $avatar_size = 39; |
| 622 | 622 | |
| 623 | - echo get_avatar( $comment, $avatar_size ); |
|
| 623 | + echo get_avatar($comment, $avatar_size); |
|
| 624 | 624 | |
| 625 | 625 | /* translators: 1: comment author, 2: date and time */ |
| 626 | - printf( __( '%1$s on %2$s <span class="says">said:</span>', 'twentyeleven' ), |
|
| 627 | - sprintf( '<span class="fn">%s</span>', get_comment_author_link() ), |
|
| 628 | - sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', |
|
| 629 | - esc_url( get_comment_link( $comment->comment_ID ) ), |
|
| 630 | - get_comment_time( 'c' ), |
|
| 626 | + printf(__('%1$s on %2$s <span class="says">said:</span>', 'twentyeleven'), |
|
| 627 | + sprintf('<span class="fn">%s</span>', get_comment_author_link()), |
|
| 628 | + sprintf('<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', |
|
| 629 | + esc_url(get_comment_link($comment->comment_ID)), |
|
| 630 | + get_comment_time('c'), |
|
| 631 | 631 | /* translators: 1: date, 2: time */ |
| 632 | - sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time() ) |
|
| 632 | + sprintf(__('%1$s at %2$s', 'twentyeleven'), get_comment_date(), get_comment_time()) |
|
| 633 | 633 | ) |
| 634 | 634 | ); |
| 635 | 635 | ?> |
| 636 | 636 | |
| 637 | - <?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?> |
|
| 637 | + <?php edit_comment_link(__('Edit', 'twentyeleven'), '<span class="edit-link">', '</span>'); ?> |
|
| 638 | 638 | </div><!-- .comment-author .vcard --> |
| 639 | 639 | |
| 640 | - <?php if ( $comment->comment_approved == '0' ) : ?> |
|
| 641 | - <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em> |
|
| 640 | + <?php if ($comment->comment_approved == '0') : ?> |
|
| 641 | + <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'twentyeleven'); ?></em> |
|
| 642 | 642 | <br /> |
| 643 | 643 | <?php endif; ?> |
| 644 | 644 | |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | <div class="comment-content"><?php comment_text(); ?></div> |
| 648 | 648 | |
| 649 | 649 | <div class="reply"> |
| 650 | - <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>↓</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
|
| 650 | + <?php comment_reply_link(array_merge($args, array('reply_text' => __('Reply <span>↓</span>', 'twentyeleven'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?> |
|
| 651 | 651 | </div><!-- .reply --> |
| 652 | 652 | </article><!-- #comment-## --> |
| 653 | 653 | |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | } |
| 658 | 658 | endif; // ends check for twentyeleven_comment() |
| 659 | 659 | |
| 660 | -if ( ! function_exists( 'twentyeleven_posted_on' ) ) : |
|
| 660 | +if ( ! function_exists('twentyeleven_posted_on')) : |
|
| 661 | 661 | /** |
| 662 | 662 | * Print HTML with meta information for the current post-date/time and author. |
| 663 | 663 | * |
@@ -666,13 +666,13 @@ discard block |
||
| 666 | 666 | * @since Twenty Eleven 1.0 |
| 667 | 667 | */ |
| 668 | 668 | function twentyeleven_posted_on() { |
| 669 | - 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' ), |
|
| 670 | - esc_url( get_permalink() ), |
|
| 671 | - esc_attr( get_the_time() ), |
|
| 672 | - esc_attr( get_the_date( 'c' ) ), |
|
| 673 | - esc_html( get_the_date() ), |
|
| 674 | - esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
|
| 675 | - esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ), |
|
| 669 | + 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'), |
|
| 670 | + esc_url(get_permalink()), |
|
| 671 | + esc_attr(get_the_time()), |
|
| 672 | + esc_attr(get_the_date('c')), |
|
| 673 | + esc_html(get_the_date()), |
|
| 674 | + esc_url(get_author_posts_url(get_the_author_meta('ID'))), |
|
| 675 | + esc_attr(sprintf(__('View all posts by %s', 'twentyeleven'), get_the_author())), |
|
| 676 | 676 | get_the_author() |
| 677 | 677 | ); |
| 678 | 678 | } |
@@ -689,17 +689,17 @@ discard block |
||
| 689 | 689 | * @param array $classes Existing body classes. |
| 690 | 690 | * @return array The filtered array of body classes. |
| 691 | 691 | */ |
| 692 | -function twentyeleven_body_classes( $classes ) { |
|
| 692 | +function twentyeleven_body_classes($classes) { |
|
| 693 | 693 | |
| 694 | - if ( function_exists( 'is_multi_author' ) && ! is_multi_author() ) |
|
| 694 | + if (function_exists('is_multi_author') && ! is_multi_author()) |
|
| 695 | 695 | $classes[] = 'single-author'; |
| 696 | 696 | |
| 697 | - if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) ) |
|
| 697 | + if (is_singular() && ! is_home() && ! is_page_template('showcase.php') && ! is_page_template('sidebar-page.php')) |
|
| 698 | 698 | $classes[] = 'singular'; |
| 699 | 699 | |
| 700 | 700 | return $classes; |
| 701 | 701 | } |
| 702 | -add_filter( 'body_class', 'twentyeleven_body_classes' ); |
|
| 702 | +add_filter('body_class', 'twentyeleven_body_classes'); |
|
| 703 | 703 | |
| 704 | 704 | /** |
| 705 | 705 | * Retrieve the IDs for images in a gallery. |
@@ -714,20 +714,20 @@ discard block |
||
| 714 | 714 | function twentyeleven_get_gallery_images() { |
| 715 | 715 | $images = array(); |
| 716 | 716 | |
| 717 | - if ( function_exists( 'get_post_galleries' ) ) { |
|
| 718 | - $galleries = get_post_galleries( get_the_ID(), false ); |
|
| 719 | - if ( isset( $galleries[0]['ids'] ) ) |
|
| 720 | - $images = explode( ',', $galleries[0]['ids'] ); |
|
| 717 | + if (function_exists('get_post_galleries')) { |
|
| 718 | + $galleries = get_post_galleries(get_the_ID(), false); |
|
| 719 | + if (isset($galleries[0]['ids'])) |
|
| 720 | + $images = explode(',', $galleries[0]['ids']); |
|
| 721 | 721 | } else { |
| 722 | 722 | $pattern = get_shortcode_regex(); |
| 723 | - preg_match( "/$pattern/s", get_the_content(), $match ); |
|
| 724 | - $atts = shortcode_parse_atts( $match[3] ); |
|
| 725 | - if ( isset( $atts['ids'] ) ) |
|
| 726 | - $images = explode( ',', $atts['ids'] ); |
|
| 723 | + preg_match("/$pattern/s", get_the_content(), $match); |
|
| 724 | + $atts = shortcode_parse_atts($match[3]); |
|
| 725 | + if (isset($atts['ids'])) |
|
| 726 | + $images = explode(',', $atts['ids']); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - if ( ! $images ) { |
|
| 730 | - $images = get_posts( array( |
|
| 729 | + if ( ! $images) { |
|
| 730 | + $images = get_posts(array( |
|
| 731 | 731 | 'fields' => 'ids', |
| 732 | 732 | 'numberposts' => 999, |
| 733 | 733 | 'order' => 'ASC', |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | 'post_mime_type' => 'image', |
| 736 | 736 | 'post_parent' => get_the_ID(), |
| 737 | 737 | 'post_type' => 'attachment', |
| 738 | - ) ); |
|
| 738 | + )); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | return $images; |
@@ -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 ) { |
@@ -1,42 +1,42 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Twenty Eleven functions and definitions |
|
| 4 | - * |
|
| 5 | - * Sets up the theme and provides some helper functions. Some helper functions |
|
| 6 | - * are used in the theme as custom template tags. Others are attached to action and |
|
| 7 | - * filter hooks in WordPress to change core functionality. |
|
| 8 | - * |
|
| 9 | - * The first function, twentyeleven_setup(), sets up the theme by registering support |
|
| 10 | - * for various features in WordPress, such as post thumbnails, navigation menus, and the like. |
|
| 11 | - * |
|
| 12 | - * When using a child theme (see https://codex.wordpress.org/Theme_Development and |
|
| 13 | - * https://codex.wordpress.org/Child_Themes), you can override certain functions |
|
| 14 | - * (those wrapped in a function_exists() call) by defining them first in your child theme's |
|
| 15 | - * functions.php file. The child theme's functions.php file is included before the parent |
|
| 16 | - * theme's file, so the child theme functions would be used. |
|
| 17 | - * |
|
| 18 | - * Functions that are not pluggable (not wrapped in function_exists()) are instead attached |
|
| 19 | - * to a filter or action hook. The hook can be removed by using remove_action() or |
|
| 20 | - * remove_filter() and you can attach your own function to the hook. |
|
| 21 | - * |
|
| 22 | - * We can remove the parent theme's hook only after it is attached, which means we need to |
|
| 23 | - * wait until setting up the child theme: |
|
| 24 | - * |
|
| 25 | - * <code> |
|
| 26 | - * add_action( 'after_setup_theme', 'my_child_theme_setup' ); |
|
| 27 | - * function my_child_theme_setup() { |
|
| 28 | - * // We are providing our own filter for excerpt_length (or using the unfiltered value) |
|
| 29 | - * remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); |
|
| 30 | - * ... |
|
| 31 | - * } |
|
| 32 | - * </code> |
|
| 33 | - * |
|
| 34 | - * For more information on hooks, actions, and filters, see https://codex.wordpress.org/Plugin_API. |
|
| 35 | - * |
|
| 36 | - * @package WordPress |
|
| 37 | - * @subpackage Twenty_Eleven |
|
| 38 | - * @since Twenty Eleven 1.0 |
|
| 39 | - */ |
|
| 3 | + * Twenty Eleven functions and definitions |
|
| 4 | + * |
|
| 5 | + * Sets up the theme and provides some helper functions. Some helper functions |
|
| 6 | + * are used in the theme as custom template tags. Others are attached to action and |
|
| 7 | + * filter hooks in WordPress to change core functionality. |
|
| 8 | + * |
|
| 9 | + * The first function, twentyeleven_setup(), sets up the theme by registering support |
|
| 10 | + * for various features in WordPress, such as post thumbnails, navigation menus, and the like. |
|
| 11 | + * |
|
| 12 | + * When using a child theme (see https://codex.wordpress.org/Theme_Development and |
|
| 13 | + * https://codex.wordpress.org/Child_Themes), you can override certain functions |
|
| 14 | + * (those wrapped in a function_exists() call) by defining them first in your child theme's |
|
| 15 | + * functions.php file. The child theme's functions.php file is included before the parent |
|
| 16 | + * theme's file, so the child theme functions would be used. |
|
| 17 | + * |
|
| 18 | + * Functions that are not pluggable (not wrapped in function_exists()) are instead attached |
|
| 19 | + * to a filter or action hook. The hook can be removed by using remove_action() or |
|
| 20 | + * remove_filter() and you can attach your own function to the hook. |
|
| 21 | + * |
|
| 22 | + * We can remove the parent theme's hook only after it is attached, which means we need to |
|
| 23 | + * wait until setting up the child theme: |
|
| 24 | + * |
|
| 25 | + * <code> |
|
| 26 | + * add_action( 'after_setup_theme', 'my_child_theme_setup' ); |
|
| 27 | + * function my_child_theme_setup() { |
|
| 28 | + * // We are providing our own filter for excerpt_length (or using the unfiltered value) |
|
| 29 | + * remove_filter( 'excerpt_length', 'twentyeleven_excerpt_length' ); |
|
| 30 | + * ... |
|
| 31 | + * } |
|
| 32 | + * </code> |
|
| 33 | + * |
|
| 34 | + * For more information on hooks, actions, and filters, see https://codex.wordpress.org/Plugin_API. |
|
| 35 | + * |
|
| 36 | + * @package WordPress |
|
| 37 | + * @subpackage Twenty_Eleven |
|
| 38 | + * @since Twenty Eleven 1.0 |
|
| 39 | + */ |
|
| 40 | 40 | |
| 41 | 41 | // Set the content width based on the theme's design and stylesheet. |
| 42 | 42 | if ( ! isset( $content_width ) ) |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | * |
| 14 | 14 | * @global wpdb $wpdb WordPress database abstraction object. |
| 15 | 15 | * |
| 16 | - * @param int|stdClass $bookmark |
|
| 16 | + * @param integer|null $bookmark |
|
| 17 | 17 | * @param string $output Optional. Either OBJECT, ARRAY_N, or ARRAY_A constant |
| 18 | 18 | * @param string $filter Optional, default is 'raw'. |
| 19 | 19 | * @return array|object|null Type returned depends on $output value. |
@@ -354,24 +354,24 @@ |
||
| 354 | 354 | */ |
| 355 | 355 | function sanitize_bookmark_field($field, $value, $bookmark_id, $context) { |
| 356 | 356 | switch ( $field ) { |
| 357 | - case 'link_id' : // ints |
|
| 358 | - case 'link_rating' : |
|
| 359 | - $value = (int) $value; |
|
| 360 | - break; |
|
| 361 | - case 'link_category' : // array( ints ) |
|
| 362 | - $value = array_map('absint', (array) $value); |
|
| 363 | - // We return here so that the categories aren't filtered. |
|
| 364 | - // The 'link_category' filter is for the name of a link category, not an array of a link's link categories |
|
| 365 | - return $value; |
|
| 366 | - |
|
| 367 | - case 'link_visible' : // bool stored as Y|N |
|
| 368 | - $value = preg_replace('/[^YNyn]/', '', $value); |
|
| 369 | - break; |
|
| 370 | - case 'link_target' : // "enum" |
|
| 371 | - $targets = array('_top', '_blank'); |
|
| 372 | - if ( ! in_array($value, $targets) ) |
|
| 373 | - $value = ''; |
|
| 374 | - break; |
|
| 357 | + case 'link_id' : // ints |
|
| 358 | + case 'link_rating' : |
|
| 359 | + $value = (int) $value; |
|
| 360 | + break; |
|
| 361 | + case 'link_category' : // array( ints ) |
|
| 362 | + $value = array_map('absint', (array) $value); |
|
| 363 | + // We return here so that the categories aren't filtered. |
|
| 364 | + // The 'link_category' filter is for the name of a link category, not an array of a link's link categories |
|
| 365 | + return $value; |
|
| 366 | + |
|
| 367 | + case 'link_visible' : // bool stored as Y|N |
|
| 368 | + $value = preg_replace('/[^YNyn]/', '', $value); |
|
| 369 | + break; |
|
| 370 | + case 'link_target' : // "enum" |
|
| 371 | + $targets = array('_top', '_blank'); |
|
| 372 | + if ( ! in_array($value, $targets) ) |
|
| 373 | + $value = ''; |
|
| 374 | + break; |
|
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | if ( 'raw' == $context ) |
@@ -21,36 +21,36 @@ discard block |
||
| 21 | 21 | function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') { |
| 22 | 22 | global $wpdb; |
| 23 | 23 | |
| 24 | - if ( empty($bookmark) ) { |
|
| 25 | - if ( isset($GLOBALS['link']) ) |
|
| 24 | + if (empty($bookmark)) { |
|
| 25 | + if (isset($GLOBALS['link'])) |
|
| 26 | 26 | $_bookmark = & $GLOBALS['link']; |
| 27 | 27 | else |
| 28 | 28 | $_bookmark = null; |
| 29 | - } elseif ( is_object($bookmark) ) { |
|
| 29 | + } elseif (is_object($bookmark)) { |
|
| 30 | 30 | wp_cache_add($bookmark->link_id, $bookmark, 'bookmark'); |
| 31 | 31 | $_bookmark = $bookmark; |
| 32 | 32 | } else { |
| 33 | - if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) { |
|
| 33 | + if (isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark)) { |
|
| 34 | 34 | $_bookmark = & $GLOBALS['link']; |
| 35 | - } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) { |
|
| 35 | + } elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark')) { |
|
| 36 | 36 | $_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark)); |
| 37 | - if ( $_bookmark ) { |
|
| 38 | - $_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) ); |
|
| 39 | - wp_cache_add( $_bookmark->link_id, $_bookmark, 'bookmark' ); |
|
| 37 | + if ($_bookmark) { |
|
| 38 | + $_bookmark->link_category = array_unique(wp_get_object_terms($_bookmark->link_id, 'link_category', array('fields' => 'ids'))); |
|
| 39 | + wp_cache_add($_bookmark->link_id, $_bookmark, 'bookmark'); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( ! $_bookmark ) |
|
| 44 | + if ( ! $_bookmark) |
|
| 45 | 45 | return $_bookmark; |
| 46 | 46 | |
| 47 | 47 | $_bookmark = sanitize_bookmark($_bookmark, $filter); |
| 48 | 48 | |
| 49 | - if ( $output == OBJECT ) { |
|
| 49 | + if ($output == OBJECT) { |
|
| 50 | 50 | return $_bookmark; |
| 51 | - } elseif ( $output == ARRAY_A ) { |
|
| 51 | + } elseif ($output == ARRAY_A) { |
|
| 52 | 52 | return get_object_vars($_bookmark); |
| 53 | - } elseif ( $output == ARRAY_N ) { |
|
| 53 | + } elseif ($output == ARRAY_N) { |
|
| 54 | 54 | return array_values(get_object_vars($_bookmark)); |
| 55 | 55 | } else { |
| 56 | 56 | return $_bookmark; |
@@ -67,17 +67,17 @@ discard block |
||
| 67 | 67 | * @param string $context Optional. The context of how the field will be used. |
| 68 | 68 | * @return string|WP_Error |
| 69 | 69 | */ |
| 70 | -function get_bookmark_field( $field, $bookmark, $context = 'display' ) { |
|
| 70 | +function get_bookmark_field($field, $bookmark, $context = 'display') { |
|
| 71 | 71 | $bookmark = (int) $bookmark; |
| 72 | - $bookmark = get_bookmark( $bookmark ); |
|
| 72 | + $bookmark = get_bookmark($bookmark); |
|
| 73 | 73 | |
| 74 | - if ( is_wp_error($bookmark) ) |
|
| 74 | + if (is_wp_error($bookmark)) |
|
| 75 | 75 | return $bookmark; |
| 76 | 76 | |
| 77 | - if ( !is_object($bookmark) ) |
|
| 77 | + if ( ! is_object($bookmark)) |
|
| 78 | 78 | return ''; |
| 79 | 79 | |
| 80 | - if ( !isset($bookmark->$field) ) |
|
| 80 | + if ( ! isset($bookmark->$field)) |
|
| 81 | 81 | return ''; |
| 82 | 82 | |
| 83 | 83 | return sanitize_bookmark_field($field, $bookmark->$field, $bookmark->link_id, $context); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * } |
| 115 | 115 | * @return array List of bookmark row objects. |
| 116 | 116 | */ |
| 117 | -function get_bookmarks( $args = '' ) { |
|
| 117 | +function get_bookmarks($args = '') { |
|
| 118 | 118 | global $wpdb; |
| 119 | 119 | |
| 120 | 120 | $defaults = array( |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | 'exclude' => '', 'search' => '' |
| 126 | 126 | ); |
| 127 | 127 | |
| 128 | - $r = wp_parse_args( $args, $defaults ); |
|
| 128 | + $r = wp_parse_args($args, $defaults); |
|
| 129 | 129 | |
| 130 | - $key = md5( serialize( $r ) ); |
|
| 131 | - if ( $cache = wp_cache_get( 'get_bookmarks', 'bookmark' ) ) { |
|
| 132 | - if ( is_array( $cache ) && isset( $cache[ $key ] ) ) { |
|
| 133 | - $bookmarks = $cache[ $key ]; |
|
| 130 | + $key = md5(serialize($r)); |
|
| 131 | + if ($cache = wp_cache_get('get_bookmarks', 'bookmark')) { |
|
| 132 | + if (is_array($cache) && isset($cache[$key])) { |
|
| 133 | + $bookmarks = $cache[$key]; |
|
| 134 | 134 | /** |
| 135 | 135 | * Filter the returned list of bookmarks. |
| 136 | 136 | * |
@@ -146,98 +146,98 @@ discard block |
||
| 146 | 146 | * @param array $bookmarks List of the cached bookmarks. |
| 147 | 147 | * @param array $r An array of bookmark query arguments. |
| 148 | 148 | */ |
| 149 | - return apply_filters( 'get_bookmarks', $bookmarks, $r ); |
|
| 149 | + return apply_filters('get_bookmarks', $bookmarks, $r); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - if ( ! is_array( $cache ) ) { |
|
| 153 | + if ( ! is_array($cache)) { |
|
| 154 | 154 | $cache = array(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $inclusions = ''; |
| 158 | - if ( ! empty( $r['include'] ) ) { |
|
| 159 | - $r['exclude'] = ''; //ignore exclude, category, and category_name params if using include |
|
| 158 | + if ( ! empty($r['include'])) { |
|
| 159 | + $r['exclude'] = ''; //ignore exclude, category, and category_name params if using include |
|
| 160 | 160 | $r['category'] = ''; |
| 161 | 161 | $r['category_name'] = ''; |
| 162 | - $inclinks = preg_split( '/[\s,]+/', $r['include'] ); |
|
| 163 | - if ( count( $inclinks ) ) { |
|
| 164 | - foreach ( $inclinks as $inclink ) { |
|
| 165 | - if ( empty( $inclusions ) ) { |
|
| 166 | - $inclusions = ' AND ( link_id = ' . intval( $inclink ) . ' '; |
|
| 162 | + $inclinks = preg_split('/[\s,]+/', $r['include']); |
|
| 163 | + if (count($inclinks)) { |
|
| 164 | + foreach ($inclinks as $inclink) { |
|
| 165 | + if (empty($inclusions)) { |
|
| 166 | + $inclusions = ' AND ( link_id = '.intval($inclink).' '; |
|
| 167 | 167 | } else { |
| 168 | - $inclusions .= ' OR link_id = ' . intval( $inclink ) . ' '; |
|
| 168 | + $inclusions .= ' OR link_id = '.intval($inclink).' '; |
|
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | - if (! empty( $inclusions ) ) { |
|
| 173 | + if ( ! empty($inclusions)) { |
|
| 174 | 174 | $inclusions .= ')'; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | $exclusions = ''; |
| 178 | - if ( ! empty( $r['exclude'] ) ) { |
|
| 179 | - $exlinks = preg_split( '/[\s,]+/', $r['exclude'] ); |
|
| 180 | - if ( count( $exlinks ) ) { |
|
| 181 | - foreach ( $exlinks as $exlink ) { |
|
| 182 | - if ( empty( $exclusions ) ) { |
|
| 183 | - $exclusions = ' AND ( link_id <> ' . intval( $exlink ) . ' '; |
|
| 178 | + if ( ! empty($r['exclude'])) { |
|
| 179 | + $exlinks = preg_split('/[\s,]+/', $r['exclude']); |
|
| 180 | + if (count($exlinks)) { |
|
| 181 | + foreach ($exlinks as $exlink) { |
|
| 182 | + if (empty($exclusions)) { |
|
| 183 | + $exclusions = ' AND ( link_id <> '.intval($exlink).' '; |
|
| 184 | 184 | } else { |
| 185 | - $exclusions .= ' AND link_id <> ' . intval( $exlink ) . ' '; |
|
| 185 | + $exclusions .= ' AND link_id <> '.intval($exlink).' '; |
|
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | - if ( ! empty( $exclusions ) ) { |
|
| 190 | + if ( ! empty($exclusions)) { |
|
| 191 | 191 | $exclusions .= ')'; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( ! empty( $r['category_name'] ) ) { |
|
| 195 | - if ( $r['category'] = get_term_by('name', $r['category_name'], 'link_category') ) { |
|
| 194 | + if ( ! empty($r['category_name'])) { |
|
| 195 | + if ($r['category'] = get_term_by('name', $r['category_name'], 'link_category')) { |
|
| 196 | 196 | $r['category'] = $r['category']->term_id; |
| 197 | 197 | } else { |
| 198 | - $cache[ $key ] = array(); |
|
| 199 | - wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); |
|
| 198 | + $cache[$key] = array(); |
|
| 199 | + wp_cache_set('get_bookmarks', $cache, 'bookmark'); |
|
| 200 | 200 | /** This filter is documented in wp-includes/bookmark.php */ |
| 201 | - return apply_filters( 'get_bookmarks', array(), $r ); |
|
| 201 | + return apply_filters('get_bookmarks', array(), $r); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | $search = ''; |
| 206 | - if ( ! empty( $r['search'] ) ) { |
|
| 207 | - $like = '%' . $wpdb->esc_like( $r['search'] ) . '%'; |
|
| 208 | - $search = $wpdb->prepare(" AND ( (link_url LIKE %s) OR (link_name LIKE %s) OR (link_description LIKE %s) ) ", $like, $like, $like ); |
|
| 206 | + if ( ! empty($r['search'])) { |
|
| 207 | + $like = '%'.$wpdb->esc_like($r['search']).'%'; |
|
| 208 | + $search = $wpdb->prepare(" AND ( (link_url LIKE %s) OR (link_name LIKE %s) OR (link_description LIKE %s) ) ", $like, $like, $like); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | $category_query = ''; |
| 212 | 212 | $join = ''; |
| 213 | - if ( ! empty( $r['category'] ) ) { |
|
| 214 | - $incategories = preg_split( '/[\s,]+/', $r['category'] ); |
|
| 215 | - if ( count($incategories) ) { |
|
| 216 | - foreach ( $incategories as $incat ) { |
|
| 217 | - if ( empty( $category_query ) ) { |
|
| 218 | - $category_query = ' AND ( tt.term_id = ' . intval( $incat ) . ' '; |
|
| 213 | + if ( ! empty($r['category'])) { |
|
| 214 | + $incategories = preg_split('/[\s,]+/', $r['category']); |
|
| 215 | + if (count($incategories)) { |
|
| 216 | + foreach ($incategories as $incat) { |
|
| 217 | + if (empty($category_query)) { |
|
| 218 | + $category_query = ' AND ( tt.term_id = '.intval($incat).' '; |
|
| 219 | 219 | } else { |
| 220 | - $category_query .= ' OR tt.term_id = ' . intval( $incat ) . ' '; |
|
| 220 | + $category_query .= ' OR tt.term_id = '.intval($incat).' '; |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | } |
| 225 | - if ( ! empty( $category_query ) ) { |
|
| 225 | + if ( ! empty($category_query)) { |
|
| 226 | 226 | $category_query .= ") AND taxonomy = 'link_category'"; |
| 227 | 227 | $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - if ( $r['show_updated'] ) { |
|
| 230 | + if ($r['show_updated']) { |
|
| 231 | 231 | $recently_updated_test = ", IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) >= NOW(), 1,0) as recently_updated "; |
| 232 | 232 | } else { |
| 233 | 233 | $recently_updated_test = ''; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $get_updated = ( $r['show_updated'] ) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : ''; |
|
| 236 | + $get_updated = ($r['show_updated']) ? ', UNIX_TIMESTAMP(link_updated) AS link_updated_f ' : ''; |
|
| 237 | 237 | |
| 238 | - $orderby = strtolower( $r['orderby'] ); |
|
| 238 | + $orderby = strtolower($r['orderby']); |
|
| 239 | 239 | $length = ''; |
| 240 | - switch ( $orderby ) { |
|
| 240 | + switch ($orderby) { |
|
| 241 | 241 | case 'length': |
| 242 | 242 | $length = ", CHAR_LENGTH(link_name) AS length"; |
| 243 | 243 | break; |
@@ -249,47 +249,47 @@ discard block |
||
| 249 | 249 | break; |
| 250 | 250 | default: |
| 251 | 251 | $orderparams = array(); |
| 252 | - $keys = array( 'link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes', 'link_description' ); |
|
| 253 | - foreach ( explode( ',', $orderby ) as $ordparam ) { |
|
| 254 | - $ordparam = trim( $ordparam ); |
|
| 252 | + $keys = array('link_id', 'link_name', 'link_url', 'link_visible', 'link_rating', 'link_owner', 'link_updated', 'link_notes', 'link_description'); |
|
| 253 | + foreach (explode(',', $orderby) as $ordparam) { |
|
| 254 | + $ordparam = trim($ordparam); |
|
| 255 | 255 | |
| 256 | - if ( in_array( 'link_' . $ordparam, $keys ) ) { |
|
| 257 | - $orderparams[] = 'link_' . $ordparam; |
|
| 258 | - } elseif ( in_array( $ordparam, $keys ) ) { |
|
| 256 | + if (in_array('link_'.$ordparam, $keys)) { |
|
| 257 | + $orderparams[] = 'link_'.$ordparam; |
|
| 258 | + } elseif (in_array($ordparam, $keys)) { |
|
| 259 | 259 | $orderparams[] = $ordparam; |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - $orderby = implode( ',', $orderparams ); |
|
| 262 | + $orderby = implode(',', $orderparams); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( empty( $orderby ) ) { |
|
| 265 | + if (empty($orderby)) { |
|
| 266 | 266 | $orderby = 'link_name'; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $order = strtoupper( $r['order'] ); |
|
| 270 | - if ( '' !== $order && ! in_array( $order, array( 'ASC', 'DESC' ) ) ) { |
|
| 269 | + $order = strtoupper($r['order']); |
|
| 270 | + if ('' !== $order && ! in_array($order, array('ASC', 'DESC'))) { |
|
| 271 | 271 | $order = 'ASC'; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | $visible = ''; |
| 275 | - if ( $r['hide_invisible'] ) { |
|
| 275 | + if ($r['hide_invisible']) { |
|
| 276 | 276 | $visible = "AND link_visible = 'Y'"; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; |
| 280 | 280 | $query .= " $exclusions $inclusions $search"; |
| 281 | 281 | $query .= " ORDER BY $orderby $order"; |
| 282 | - if ( $r['limit'] != -1 ) { |
|
| 283 | - $query .= ' LIMIT ' . $r['limit']; |
|
| 282 | + if ($r['limit'] != -1) { |
|
| 283 | + $query .= ' LIMIT '.$r['limit']; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $results = $wpdb->get_results( $query ); |
|
| 286 | + $results = $wpdb->get_results($query); |
|
| 287 | 287 | |
| 288 | - $cache[ $key ] = $results; |
|
| 289 | - wp_cache_set( 'get_bookmarks', $cache, 'bookmark' ); |
|
| 288 | + $cache[$key] = $results; |
|
| 289 | + wp_cache_set('get_bookmarks', $cache, 'bookmark'); |
|
| 290 | 290 | |
| 291 | 291 | /** This filter is documented in wp-includes/bookmark.php */ |
| 292 | - return apply_filters( 'get_bookmarks', $results, $r ); |
|
| 292 | + return apply_filters('get_bookmarks', $results, $r); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -305,9 +305,9 @@ discard block |
||
| 305 | 305 | function sanitize_bookmark($bookmark, $context = 'display') { |
| 306 | 306 | $fields = array('link_id', 'link_url', 'link_name', 'link_image', 'link_target', 'link_category', |
| 307 | 307 | 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_updated', |
| 308 | - 'link_rel', 'link_notes', 'link_rss', ); |
|
| 308 | + 'link_rel', 'link_notes', 'link_rss',); |
|
| 309 | 309 | |
| 310 | - if ( is_object($bookmark) ) { |
|
| 310 | + if (is_object($bookmark)) { |
|
| 311 | 311 | $do_object = true; |
| 312 | 312 | $link_id = $bookmark->link_id; |
| 313 | 313 | } else { |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | $link_id = $bookmark['link_id']; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - foreach ( $fields as $field ) { |
|
| 319 | - if ( $do_object ) { |
|
| 320 | - if ( isset($bookmark->$field) ) |
|
| 318 | + foreach ($fields as $field) { |
|
| 319 | + if ($do_object) { |
|
| 320 | + if (isset($bookmark->$field)) |
|
| 321 | 321 | $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $link_id, $context); |
| 322 | 322 | } else { |
| 323 | - if ( isset($bookmark[$field]) ) |
|
| 323 | + if (isset($bookmark[$field])) |
|
| 324 | 324 | $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $link_id, $context); |
| 325 | 325 | } |
| 326 | 326 | } |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @return mixed The filtered value |
| 354 | 354 | */ |
| 355 | 355 | function sanitize_bookmark_field($field, $value, $bookmark_id, $context) { |
| 356 | - switch ( $field ) { |
|
| 356 | + switch ($field) { |
|
| 357 | 357 | case 'link_id' : // ints |
| 358 | 358 | case 'link_rating' : |
| 359 | 359 | $value = (int) $value; |
@@ -369,34 +369,34 @@ discard block |
||
| 369 | 369 | break; |
| 370 | 370 | case 'link_target' : // "enum" |
| 371 | 371 | $targets = array('_top', '_blank'); |
| 372 | - if ( ! in_array($value, $targets) ) |
|
| 372 | + if ( ! in_array($value, $targets)) |
|
| 373 | 373 | $value = ''; |
| 374 | 374 | break; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if ( 'raw' == $context ) |
|
| 377 | + if ('raw' == $context) |
|
| 378 | 378 | return $value; |
| 379 | 379 | |
| 380 | - if ( 'edit' == $context ) { |
|
| 380 | + if ('edit' == $context) { |
|
| 381 | 381 | /** This filter is documented in wp-includes/post.php */ |
| 382 | - $value = apply_filters( "edit_$field", $value, $bookmark_id ); |
|
| 382 | + $value = apply_filters("edit_$field", $value, $bookmark_id); |
|
| 383 | 383 | |
| 384 | - if ( 'link_notes' == $field ) { |
|
| 385 | - $value = esc_html( $value ); // textarea_escaped |
|
| 384 | + if ('link_notes' == $field) { |
|
| 385 | + $value = esc_html($value); // textarea_escaped |
|
| 386 | 386 | } else { |
| 387 | 387 | $value = esc_attr($value); |
| 388 | 388 | } |
| 389 | - } elseif ( 'db' == $context ) { |
|
| 389 | + } elseif ('db' == $context) { |
|
| 390 | 390 | /** This filter is documented in wp-includes/post.php */ |
| 391 | - $value = apply_filters( "pre_$field", $value ); |
|
| 391 | + $value = apply_filters("pre_$field", $value); |
|
| 392 | 392 | } else { |
| 393 | 393 | /** This filter is documented in wp-includes/post.php */ |
| 394 | - $value = apply_filters( $field, $value, $bookmark_id, $context ); |
|
| 394 | + $value = apply_filters($field, $value, $bookmark_id, $context); |
|
| 395 | 395 | |
| 396 | - if ( 'attribute' == $context ) { |
|
| 397 | - $value = esc_attr( $value ); |
|
| 398 | - } elseif ( 'js' == $context ) { |
|
| 399 | - $value = esc_js( $value ); |
|
| 396 | + if ('attribute' == $context) { |
|
| 397 | + $value = esc_attr($value); |
|
| 398 | + } elseif ('js' == $context) { |
|
| 399 | + $value = esc_js($value); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * |
| 409 | 409 | * @since 2.7.0 |
| 410 | 410 | */ |
| 411 | -function clean_bookmark_cache( $bookmark_id ) { |
|
| 412 | - wp_cache_delete( $bookmark_id, 'bookmark' ); |
|
| 413 | - wp_cache_delete( 'get_bookmarks', 'bookmark' ); |
|
| 414 | - clean_object_term_cache( $bookmark_id, 'link'); |
|
| 411 | +function clean_bookmark_cache($bookmark_id) { |
|
| 412 | + wp_cache_delete($bookmark_id, 'bookmark'); |
|
| 413 | + wp_cache_delete('get_bookmarks', 'bookmark'); |
|
| 414 | + clean_object_term_cache($bookmark_id, 'link'); |
|
| 415 | 415 | } |
@@ -22,10 +22,11 @@ discard block |
||
| 22 | 22 | global $wpdb; |
| 23 | 23 | |
| 24 | 24 | if ( empty($bookmark) ) { |
| 25 | - if ( isset($GLOBALS['link']) ) |
|
| 26 | - $_bookmark = & $GLOBALS['link']; |
|
| 27 | - else |
|
| 28 | - $_bookmark = null; |
|
| 25 | + if ( isset($GLOBALS['link']) ) { |
|
| 26 | + $_bookmark = & $GLOBALS['link']; |
|
| 27 | + } else { |
|
| 28 | + $_bookmark = null; |
|
| 29 | + } |
|
| 29 | 30 | } elseif ( is_object($bookmark) ) { |
| 30 | 31 | wp_cache_add($bookmark->link_id, $bookmark, 'bookmark'); |
| 31 | 32 | $_bookmark = $bookmark; |
@@ -41,8 +42,9 @@ discard block |
||
| 41 | 42 | } |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | - if ( ! $_bookmark ) |
|
| 45 | - return $_bookmark; |
|
| 45 | + if ( ! $_bookmark ) { |
|
| 46 | + return $_bookmark; |
|
| 47 | + } |
|
| 46 | 48 | |
| 47 | 49 | $_bookmark = sanitize_bookmark($_bookmark, $filter); |
| 48 | 50 | |
@@ -71,14 +73,17 @@ discard block |
||
| 71 | 73 | $bookmark = (int) $bookmark; |
| 72 | 74 | $bookmark = get_bookmark( $bookmark ); |
| 73 | 75 | |
| 74 | - if ( is_wp_error($bookmark) ) |
|
| 75 | - return $bookmark; |
|
| 76 | + if ( is_wp_error($bookmark) ) { |
|
| 77 | + return $bookmark; |
|
| 78 | + } |
|
| 76 | 79 | |
| 77 | - if ( !is_object($bookmark) ) |
|
| 78 | - return ''; |
|
| 80 | + if ( !is_object($bookmark) ) { |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 79 | 83 | |
| 80 | - if ( !isset($bookmark->$field) ) |
|
| 81 | - return ''; |
|
| 84 | + if ( !isset($bookmark->$field) ) { |
|
| 85 | + return ''; |
|
| 86 | + } |
|
| 82 | 87 | |
| 83 | 88 | return sanitize_bookmark_field($field, $bookmark->$field, $bookmark->link_id, $context); |
| 84 | 89 | } |
@@ -317,11 +322,13 @@ discard block |
||
| 317 | 322 | |
| 318 | 323 | foreach ( $fields as $field ) { |
| 319 | 324 | if ( $do_object ) { |
| 320 | - if ( isset($bookmark->$field) ) |
|
| 321 | - $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $link_id, $context); |
|
| 325 | + if ( isset($bookmark->$field) ) { |
|
| 326 | + $bookmark->$field = sanitize_bookmark_field($field, $bookmark->$field, $link_id, $context); |
|
| 327 | + } |
|
| 322 | 328 | } else { |
| 323 | - if ( isset($bookmark[$field]) ) |
|
| 324 | - $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $link_id, $context); |
|
| 329 | + if ( isset($bookmark[$field]) ) { |
|
| 330 | + $bookmark[$field] = sanitize_bookmark_field($field, $bookmark[$field], $link_id, $context); |
|
| 331 | + } |
|
| 325 | 332 | } |
| 326 | 333 | } |
| 327 | 334 | |
@@ -369,13 +376,15 @@ discard block |
||
| 369 | 376 | break; |
| 370 | 377 | case 'link_target' : // "enum" |
| 371 | 378 | $targets = array('_top', '_blank'); |
| 372 | - if ( ! in_array($value, $targets) ) |
|
| 373 | - $value = ''; |
|
| 379 | + if ( ! in_array($value, $targets) ) { |
|
| 380 | + $value = ''; |
|
| 381 | + } |
|
| 374 | 382 | break; |
| 375 | 383 | } |
| 376 | 384 | |
| 377 | - if ( 'raw' == $context ) |
|
| 378 | - return $value; |
|
| 385 | + if ( 'raw' == $context ) { |
|
| 386 | + return $value; |
|
| 387 | + } |
|
| 379 | 388 | |
| 380 | 389 | if ( 'edit' == $context ) { |
| 381 | 390 | /** This filter is documented in wp-includes/post.php */ |
@@ -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 | */ |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Canonical API to handle WordPress Redirecting |
|
| 4 | - * |
|
| 5 | - * Based on "Permalink Redirect" from Scott Yang and "Enforce www. Preference" |
|
| 6 | - * by Mark Jaquith |
|
| 7 | - * |
|
| 8 | - * @package WordPress |
|
| 9 | - * @since 2.3.0 |
|
| 10 | - */ |
|
| 3 | + * Canonical API to handle WordPress Redirecting |
|
| 4 | + * |
|
| 5 | + * Based on "Permalink Redirect" from Scott Yang and "Enforce www. Preference" |
|
| 6 | + * by Mark Jaquith |
|
| 7 | + * |
|
| 8 | + * @package WordPress |
|
| 9 | + * @since 2.3.0 |
|
| 10 | + */ |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Redirects incoming links to the proper URL based on the site url. |
@@ -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 ); |
|
| 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 | 259 | $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); |
| 260 | - if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) |
|
| 260 | + if (( ! $category || is_wp_error($category)) || ( ! is_wp_error($post_terms) && ! empty($post_terms) && ! in_array($category->term_taxonomy_id, $post_terms))) |
|
| 261 | 261 | $redirect_url = get_permalink($wp_query->get_queried_object_id()); |
| 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,180 +305,180 @@ 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 | function lowercase_octets($matches) { |
| 481 | - return strtolower( $matches[0] ); |
|
| 481 | + return strtolower($matches[0]); |
|
| 482 | 482 | } |
| 483 | 483 | } |
| 484 | 484 | $requested_url = preg_replace_callback('|%[a-fA-F0-9][a-fA-F0-9]|', 'lowercase_octets', $requested_url); |
@@ -494,16 +494,16 @@ discard block |
||
| 494 | 494 | * @param string $redirect_url The redirect URL. |
| 495 | 495 | * @param string $requested_url The requested URL. |
| 496 | 496 | */ |
| 497 | - $redirect_url = apply_filters( 'redirect_canonical', $redirect_url, $requested_url ); |
|
| 497 | + $redirect_url = apply_filters('redirect_canonical', $redirect_url, $requested_url); |
|
| 498 | 498 | |
| 499 | 499 | // yes, again -- in case the filter aborted the request |
| 500 | - if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) == strip_fragment_from_url( $requested_url ) ) { |
|
| 500 | + if ( ! $redirect_url || strip_fragment_from_url($redirect_url) == strip_fragment_from_url($requested_url)) { |
|
| 501 | 501 | return; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if ( $do_redirect ) { |
|
| 504 | + if ($do_redirect) { |
|
| 505 | 505 | // protect against chained redirects |
| 506 | - if ( !redirect_canonical($redirect_url, false) ) { |
|
| 506 | + if ( ! redirect_canonical($redirect_url, false)) { |
|
| 507 | 507 | wp_redirect($redirect_url, 301); |
| 508 | 508 | exit(); |
| 509 | 509 | } else { |
@@ -528,16 +528,16 @@ discard block |
||
| 528 | 528 | * @param string $url |
| 529 | 529 | * @return string The altered query string |
| 530 | 530 | */ |
| 531 | -function _remove_qs_args_if_not_in_url( $query_string, Array $args_to_check, $url ) { |
|
| 532 | - $parsed_url = @parse_url( $url ); |
|
| 533 | - if ( ! empty( $parsed_url['query'] ) ) { |
|
| 534 | - parse_str( $parsed_url['query'], $parsed_query ); |
|
| 535 | - foreach ( $args_to_check as $qv ) { |
|
| 536 | - if ( !isset( $parsed_query[$qv] ) ) |
|
| 537 | - $query_string = remove_query_arg( $qv, $query_string ); |
|
| 531 | +function _remove_qs_args_if_not_in_url($query_string, Array $args_to_check, $url) { |
|
| 532 | + $parsed_url = @parse_url($url); |
|
| 533 | + if ( ! empty($parsed_url['query'])) { |
|
| 534 | + parse_str($parsed_url['query'], $parsed_query); |
|
| 535 | + foreach ($args_to_check as $qv) { |
|
| 536 | + if ( ! isset($parsed_query[$qv])) |
|
| 537 | + $query_string = remove_query_arg($qv, $query_string); |
|
| 538 | 538 | } |
| 539 | 539 | } else { |
| 540 | - $query_string = remove_query_arg( $args_to_check, $query_string ); |
|
| 540 | + $query_string = remove_query_arg($args_to_check, $query_string); |
|
| 541 | 541 | } |
| 542 | 542 | return $query_string; |
| 543 | 543 | } |
@@ -550,17 +550,17 @@ discard block |
||
| 550 | 550 | * @param string $url The URL to strip. |
| 551 | 551 | * @return string The altered URL. |
| 552 | 552 | */ |
| 553 | -function strip_fragment_from_url( $url ) { |
|
| 554 | - $parsed_url = @parse_url( $url ); |
|
| 555 | - if ( ! empty( $parsed_url['host'] ) ) { |
|
| 553 | +function strip_fragment_from_url($url) { |
|
| 554 | + $parsed_url = @parse_url($url); |
|
| 555 | + if ( ! empty($parsed_url['host'])) { |
|
| 556 | 556 | // This mirrors code in redirect_canonical(). It does not handle every case. |
| 557 | - $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
|
| 558 | - if ( ! empty( $parsed_url['port'] ) ) { |
|
| 559 | - $url .= ':' . $parsed_url['port']; |
|
| 557 | + $url = $parsed_url['scheme'].'://'.$parsed_url['host']; |
|
| 558 | + if ( ! empty($parsed_url['port'])) { |
|
| 559 | + $url .= ':'.$parsed_url['port']; |
|
| 560 | 560 | } |
| 561 | 561 | $url .= $parsed_url['path']; |
| 562 | - if ( ! empty( $parsed_url['query'] ) ) { |
|
| 563 | - $url .= '?' . $parsed_url['query']; |
|
| 562 | + if ( ! empty($parsed_url['query'])) { |
|
| 563 | + $url .= '?'.$parsed_url['query']; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
@@ -579,31 +579,31 @@ discard block |
||
| 579 | 579 | function redirect_guess_404_permalink() { |
| 580 | 580 | global $wpdb; |
| 581 | 581 | |
| 582 | - if ( get_query_var('name') ) { |
|
| 583 | - $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like( get_query_var('name') ) . '%'); |
|
| 582 | + if (get_query_var('name')) { |
|
| 583 | + $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like(get_query_var('name')).'%'); |
|
| 584 | 584 | |
| 585 | 585 | // if any of post_type, year, monthnum, or day are set, use them to refine the query |
| 586 | - if ( get_query_var('post_type') ) |
|
| 586 | + if (get_query_var('post_type')) |
|
| 587 | 587 | $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type')); |
| 588 | 588 | else |
| 589 | - $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
|
| 589 | + $where .= " AND post_type IN ('".implode("', '", get_post_types(array('public' => true)))."')"; |
|
| 590 | 590 | |
| 591 | - if ( get_query_var('year') ) |
|
| 591 | + if (get_query_var('year')) |
|
| 592 | 592 | $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); |
| 593 | - if ( get_query_var('monthnum') ) |
|
| 593 | + if (get_query_var('monthnum')) |
|
| 594 | 594 | $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum')); |
| 595 | - if ( get_query_var('day') ) |
|
| 595 | + if (get_query_var('day')) |
|
| 596 | 596 | $where .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var('day')); |
| 597 | 597 | |
| 598 | 598 | $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'"); |
| 599 | - if ( ! $post_id ) |
|
| 599 | + if ( ! $post_id) |
|
| 600 | 600 | return false; |
| 601 | - if ( get_query_var( 'feed' ) ) |
|
| 602 | - return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); |
|
| 603 | - elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) |
|
| 604 | - return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); |
|
| 601 | + if (get_query_var('feed')) |
|
| 602 | + return get_post_comments_feed_link($post_id, get_query_var('feed')); |
|
| 603 | + elseif (get_query_var('page') && 1 < get_query_var('page')) |
|
| 604 | + return trailingslashit(get_permalink($post_id)).user_trailingslashit(get_query_var('page'), 'single_paged'); |
|
| 605 | 605 | else |
| 606 | - return get_permalink( $post_id ); |
|
| 606 | + return get_permalink($post_id); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | return false; |
@@ -621,28 +621,28 @@ discard block |
||
| 621 | 621 | */ |
| 622 | 622 | function wp_redirect_admin_locations() { |
| 623 | 623 | global $wp_rewrite; |
| 624 | - if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) |
|
| 624 | + if ( ! (is_404() && $wp_rewrite->using_permalinks())) |
|
| 625 | 625 | return; |
| 626 | 626 | |
| 627 | 627 | $admins = array( |
| 628 | - home_url( 'wp-admin', 'relative' ), |
|
| 629 | - home_url( 'dashboard', 'relative' ), |
|
| 630 | - home_url( 'admin', 'relative' ), |
|
| 631 | - site_url( 'dashboard', 'relative' ), |
|
| 632 | - site_url( 'admin', 'relative' ), |
|
| 628 | + home_url('wp-admin', 'relative'), |
|
| 629 | + home_url('dashboard', 'relative'), |
|
| 630 | + home_url('admin', 'relative'), |
|
| 631 | + site_url('dashboard', 'relative'), |
|
| 632 | + site_url('admin', 'relative'), |
|
| 633 | 633 | ); |
| 634 | - if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) ) { |
|
| 635 | - wp_redirect( admin_url() ); |
|
| 634 | + if (in_array(untrailingslashit($_SERVER['REQUEST_URI']), $admins)) { |
|
| 635 | + wp_redirect(admin_url()); |
|
| 636 | 636 | exit; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | $logins = array( |
| 640 | - home_url( 'wp-login.php', 'relative' ), |
|
| 641 | - home_url( 'login', 'relative' ), |
|
| 642 | - site_url( 'login', 'relative' ), |
|
| 640 | + home_url('wp-login.php', 'relative'), |
|
| 641 | + home_url('login', 'relative'), |
|
| 642 | + site_url('login', 'relative'), |
|
| 643 | 643 | ); |
| 644 | - if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) { |
|
| 645 | - wp_redirect( wp_login_url() ); |
|
| 644 | + if (in_array(untrailingslashit($_SERVER['REQUEST_URI']), $logins)) { |
|
| 645 | + wp_redirect(wp_login_url()); |
|
| 646 | 646 | exit; |
| 647 | 647 | } |
| 648 | 648 | } |
@@ -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 | } |
@@ -257,14 +273,16 @@ discard block |
||
| 257 | 273 | } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) { |
| 258 | 274 | $category = get_category_by_path( $cat ); |
| 259 | 275 | $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); |
| 260 | - if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) |
|
| 261 | - $redirect_url = get_permalink($wp_query->get_queried_object_id()); |
|
| 276 | + if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) { |
|
| 277 | + $redirect_url = get_permalink($wp_query->get_queried_object_id()); |
|
| 278 | + } |
|
| 262 | 279 | } |
| 263 | 280 | |
| 264 | 281 | // Post Paging |
| 265 | 282 | if ( is_singular() && get_query_var('page') ) { |
| 266 | - if ( !$redirect_url ) |
|
| 267 | - $redirect_url = get_permalink( get_queried_object_id() ); |
|
| 283 | + if ( !$redirect_url ) { |
|
| 284 | + $redirect_url = get_permalink( get_queried_object_id() ); |
|
| 285 | + } |
|
| 268 | 286 | |
| 269 | 287 | $page = get_query_var( 'page' ); |
| 270 | 288 | if ( $page > 1 ) { |
@@ -289,12 +307,14 @@ discard block |
||
| 289 | 307 | $addl_path = ''; |
| 290 | 308 | if ( is_feed() && in_array( get_query_var('feed'), $wp_rewrite->feeds ) ) { |
| 291 | 309 | $addl_path = !empty( $addl_path ) ? trailingslashit($addl_path) : ''; |
| 292 | - if ( !is_singular() && get_query_var( 'withcomments' ) ) |
|
| 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' ); |
|
| 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' ); |
|
| 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 | + } |
|
| 298 | 318 | $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); |
| 299 | 319 | } elseif ( is_feed() && 'old' == get_query_var('feed') ) { |
| 300 | 320 | $old_feed_files = array( |
@@ -335,10 +355,12 @@ discard block |
||
| 335 | 355 | } |
| 336 | 356 | |
| 337 | 357 | $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; |
|
| 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 | + } |
|
| 342 | 364 | $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; |
| 343 | 365 | } |
| 344 | 366 | |
@@ -364,29 +386,34 @@ discard block |
||
| 364 | 386 | if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) { |
| 365 | 387 | parse_str( $redirect['query'], $_parsed_redirect_query ); |
| 366 | 388 | |
| 367 | - if ( empty( $_parsed_redirect_query['name'] ) ) |
|
| 368 | - unset( $_parsed_query['name'] ); |
|
| 389 | + if ( empty( $_parsed_redirect_query['name'] ) ) { |
|
| 390 | + unset( $_parsed_query['name'] ); |
|
| 391 | + } |
|
| 369 | 392 | } |
| 370 | 393 | |
| 371 | 394 | $_parsed_query = rawurlencode_deep( $_parsed_query ); |
| 372 | 395 | $redirect_url = add_query_arg( $_parsed_query, $redirect_url ); |
| 373 | 396 | } |
| 374 | 397 | |
| 375 | - if ( $redirect_url ) |
|
| 376 | - $redirect = @parse_url($redirect_url); |
|
| 398 | + if ( $redirect_url ) { |
|
| 399 | + $redirect = @parse_url($redirect_url); |
|
| 400 | + } |
|
| 377 | 401 | |
| 378 | 402 | // www.example.com vs example.com |
| 379 | 403 | $user_home = @parse_url(home_url()); |
| 380 | - if ( !empty($user_home['host']) ) |
|
| 381 | - $redirect['host'] = $user_home['host']; |
|
| 382 | - if ( empty($user_home['path']) ) |
|
| 383 | - $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 | + } |
|
| 384 | 410 | |
| 385 | 411 | // Handle ports |
| 386 | - if ( !empty($user_home['port']) ) |
|
| 387 | - $redirect['port'] = $user_home['port']; |
|
| 388 | - else |
|
| 389 | - unset($redirect['port']); |
|
| 412 | + if ( !empty($user_home['port']) ) { |
|
| 413 | + $redirect['port'] = $user_home['port']; |
|
| 414 | + } else { |
|
| 415 | + unset($redirect['port']); |
|
| 416 | + } |
|
| 390 | 417 | |
| 391 | 418 | // trailing /index.php |
| 392 | 419 | $redirect['path'] = preg_replace('|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path']); |
@@ -409,8 +436,9 @@ discard block |
||
| 409 | 436 | } |
| 410 | 437 | |
| 411 | 438 | // 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'] ); |
|
| 439 | + if ( !$wp_rewrite->using_index_permalinks() ) { |
|
| 440 | + $redirect['path'] = str_replace( '/' . $wp_rewrite->index . '/', '/', $redirect['path'] ); |
|
| 441 | + } |
|
| 414 | 442 | |
| 415 | 443 | // trailing slashes |
| 416 | 444 | if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_front_page() || ( is_front_page() && (get_query_var('paged') > 1) ) ) ) { |
@@ -432,42 +460,51 @@ discard block |
||
| 432 | 460 | } |
| 433 | 461 | |
| 434 | 462 | // Strip multiple slashes out of the URL |
| 435 | - if ( strpos($redirect['path'], '//') > -1 ) |
|
| 436 | - $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); |
|
| 463 | + if ( strpos($redirect['path'], '//') > -1 ) { |
|
| 464 | + $redirect['path'] = preg_replace('|/+|', '/', $redirect['path']); |
|
| 465 | + } |
|
| 437 | 466 | |
| 438 | 467 | // Always trailing slash the Front Page URL |
| 439 | - if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) |
|
| 440 | - $redirect['path'] = trailingslashit($redirect['path']); |
|
| 468 | + if ( trailingslashit( $redirect['path'] ) == trailingslashit( $user_home['path'] ) ) { |
|
| 469 | + $redirect['path'] = trailingslashit($redirect['path']); |
|
| 470 | + } |
|
| 441 | 471 | |
| 442 | 472 | // Ignore differences in host capitalization, as this can lead to infinite redirects |
| 443 | 473 | // Only redirect no-www <=> yes-www |
| 444 | 474 | if ( strtolower($original['host']) == strtolower($redirect['host']) || |
| 445 | - ( strtolower($original['host']) != 'www.' . strtolower($redirect['host']) && 'www.' . strtolower($original['host']) != strtolower($redirect['host']) ) ) |
|
| 446 | - $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 | + } |
|
| 447 | 478 | |
| 448 | 479 | $compare_original = array( $original['host'], $original['path'] ); |
| 449 | 480 | |
| 450 | - if ( !empty( $original['port'] ) ) |
|
| 451 | - $compare_original[] = $original['port']; |
|
| 481 | + if ( !empty( $original['port'] ) ) { |
|
| 482 | + $compare_original[] = $original['port']; |
|
| 483 | + } |
|
| 452 | 484 | |
| 453 | - if ( !empty( $original['query'] ) ) |
|
| 454 | - $compare_original[] = $original['query']; |
|
| 485 | + if ( !empty( $original['query'] ) ) { |
|
| 486 | + $compare_original[] = $original['query']; |
|
| 487 | + } |
|
| 455 | 488 | |
| 456 | 489 | $compare_redirect = array( $redirect['host'], $redirect['path'] ); |
| 457 | 490 | |
| 458 | - if ( !empty( $redirect['port'] ) ) |
|
| 459 | - $compare_redirect[] = $redirect['port']; |
|
| 491 | + if ( !empty( $redirect['port'] ) ) { |
|
| 492 | + $compare_redirect[] = $redirect['port']; |
|
| 493 | + } |
|
| 460 | 494 | |
| 461 | - if ( !empty( $redirect['query'] ) ) |
|
| 462 | - $compare_redirect[] = $redirect['query']; |
|
| 495 | + if ( !empty( $redirect['query'] ) ) { |
|
| 496 | + $compare_redirect[] = $redirect['query']; |
|
| 497 | + } |
|
| 463 | 498 | |
| 464 | 499 | if ( $compare_original !== $compare_redirect ) { |
| 465 | 500 | $redirect_url = $redirect['scheme'] . '://' . $redirect['host']; |
| 466 | - if ( !empty($redirect['port']) ) |
|
| 467 | - $redirect_url .= ':' . $redirect['port']; |
|
| 501 | + if ( !empty($redirect['port']) ) { |
|
| 502 | + $redirect_url .= ':' . $redirect['port']; |
|
| 503 | + } |
|
| 468 | 504 | $redirect_url .= $redirect['path']; |
| 469 | - if ( !empty($redirect['query']) ) |
|
| 470 | - $redirect_url .= '?' . $redirect['query']; |
|
| 505 | + if ( !empty($redirect['query']) ) { |
|
| 506 | + $redirect_url .= '?' . $redirect['query']; |
|
| 507 | + } |
|
| 471 | 508 | } |
| 472 | 509 | |
| 473 | 510 | if ( ! $redirect_url || $redirect_url == $requested_url ) { |
@@ -533,8 +570,9 @@ discard block |
||
| 533 | 570 | if ( ! empty( $parsed_url['query'] ) ) { |
| 534 | 571 | parse_str( $parsed_url['query'], $parsed_query ); |
| 535 | 572 | foreach ( $args_to_check as $qv ) { |
| 536 | - if ( !isset( $parsed_query[$qv] ) ) |
|
| 537 | - $query_string = remove_query_arg( $qv, $query_string ); |
|
| 573 | + if ( !isset( $parsed_query[$qv] ) ) { |
|
| 574 | + $query_string = remove_query_arg( $qv, $query_string ); |
|
| 575 | + } |
|
| 538 | 576 | } |
| 539 | 577 | } else { |
| 540 | 578 | $query_string = remove_query_arg( $args_to_check, $query_string ); |
@@ -583,27 +621,33 @@ discard block |
||
| 583 | 621 | $where = $wpdb->prepare("post_name LIKE %s", $wpdb->esc_like( get_query_var('name') ) . '%'); |
| 584 | 622 | |
| 585 | 623 | // if any of post_type, year, monthnum, or day are set, use them to refine the query |
| 586 | - if ( get_query_var('post_type') ) |
|
| 587 | - $where .= $wpdb->prepare(" AND post_type = %s", get_query_var('post_type')); |
|
| 588 | - else |
|
| 589 | - $where .= " AND post_type IN ('" . implode( "', '", get_post_types( array( 'public' => true ) ) ) . "')"; |
|
| 590 | - |
|
| 591 | - if ( get_query_var('year') ) |
|
| 592 | - $where .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var('year')); |
|
| 593 | - if ( get_query_var('monthnum') ) |
|
| 594 | - $where .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var('monthnum')); |
|
| 595 | - if ( get_query_var('day') ) |
|
| 596 | - $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 | + } |
|
| 597 | 639 | |
| 598 | 640 | $post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'"); |
| 599 | - if ( ! $post_id ) |
|
| 600 | - return false; |
|
| 601 | - if ( get_query_var( 'feed' ) ) |
|
| 602 | - return get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) ); |
|
| 603 | - elseif ( get_query_var( 'page' ) && 1 < get_query_var( 'page' ) ) |
|
| 604 | - return trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' ); |
|
| 605 | - else |
|
| 606 | - 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 | + } |
|
| 607 | 651 | } |
| 608 | 652 | |
| 609 | 653 | return false; |
@@ -621,8 +665,9 @@ discard block |
||
| 621 | 665 | */ |
| 622 | 666 | function wp_redirect_admin_locations() { |
| 623 | 667 | global $wp_rewrite; |
| 624 | - if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) |
|
| 625 | - return; |
|
| 668 | + if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) { |
|
| 669 | + return; |
|
| 670 | + } |
|
| 626 | 671 | |
| 627 | 672 | $admins = array( |
| 628 | 673 | home_url( 'wp-admin', 'relative' ), |
@@ -686,7 +686,7 @@ |
||
| 686 | 686 | * Default topic count scaling for tag links |
| 687 | 687 | * |
| 688 | 688 | * @param int $count number of posts with that tag |
| 689 | - * @return int scaled count |
|
| 689 | + * @return double scaled count |
|
| 690 | 690 | */ |
| 691 | 691 | function default_topic_count_scale( $count ) { |
| 692 | 692 | return round(log10($count + 1) * 100); |
@@ -1,11 +1,11 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Taxonomy API: Core category-specific template tags |
|
| 4 | - * |
|
| 5 | - * @package WordPress |
|
| 6 | - * @subpackage Template |
|
| 7 | - * @since 1.2.0 |
|
| 8 | - */ |
|
| 3 | + * Taxonomy API: Core category-specific template tags |
|
| 4 | + * |
|
| 5 | + * @package WordPress |
|
| 6 | + * @subpackage Template |
|
| 7 | + * @since 1.2.0 |
|
| 8 | + */ |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Retrieve category link URL. |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | * @param int|object $category Category ID or object. |
| 17 | 17 | * @return string Link on success, empty string if category does not exist. |
| 18 | 18 | */ |
| 19 | -function get_category_link( $category ) { |
|
| 20 | - if ( ! is_object( $category ) ) |
|
| 19 | +function get_category_link($category) { |
|
| 20 | + if ( ! is_object($category)) |
|
| 21 | 21 | $category = (int) $category; |
| 22 | 22 | |
| 23 | - $category = get_term_link( $category, 'category' ); |
|
| 23 | + $category = get_term_link($category, 'category'); |
|
| 24 | 24 | |
| 25 | - if ( is_wp_error( $category ) ) |
|
| 25 | + if (is_wp_error($category)) |
|
| 26 | 26 | return ''; |
| 27 | 27 | |
| 28 | 28 | return $category; |
@@ -40,24 +40,24 @@ discard block |
||
| 40 | 40 | * @param array $visited Optional. Already linked to categories to prevent duplicates. |
| 41 | 41 | * @return string|WP_Error A list of category parents on success, WP_Error on failure. |
| 42 | 42 | */ |
| 43 | -function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { |
|
| 43 | +function get_category_parents($id, $link = false, $separator = '/', $nicename = false, $visited = array()) { |
|
| 44 | 44 | $chain = ''; |
| 45 | - $parent = get_term( $id, 'category' ); |
|
| 46 | - if ( is_wp_error( $parent ) ) |
|
| 45 | + $parent = get_term($id, 'category'); |
|
| 46 | + if (is_wp_error($parent)) |
|
| 47 | 47 | return $parent; |
| 48 | 48 | |
| 49 | - if ( $nicename ) |
|
| 49 | + if ($nicename) |
|
| 50 | 50 | $name = $parent->slug; |
| 51 | 51 | else |
| 52 | 52 | $name = $parent->name; |
| 53 | 53 | |
| 54 | - if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { |
|
| 54 | + if ($parent->parent && ($parent->parent != $parent->term_id) && ! in_array($parent->parent, $visited)) { |
|
| 55 | 55 | $visited[] = $parent->parent; |
| 56 | - $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited ); |
|
| 56 | + $chain .= get_category_parents($parent->parent, $link, $separator, $nicename, $visited); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( $link ) |
|
| 60 | - $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 59 | + if ($link) |
|
| 60 | + $chain .= '<a href="'.esc_url(get_category_link($parent->term_id)).'">'.$name.'</a>'.$separator; |
|
| 61 | 61 | else |
| 62 | 62 | $chain .= $name.$separator; |
| 63 | 63 | return $chain; |
@@ -76,15 +76,15 @@ discard block |
||
| 76 | 76 | * @param int $id Optional, default to current post ID. The post ID. |
| 77 | 77 | * @return array Array of objects, one for each category assigned to the post. |
| 78 | 78 | */ |
| 79 | -function get_the_category( $id = false ) { |
|
| 80 | - $categories = get_the_terms( $id, 'category' ); |
|
| 81 | - if ( ! $categories || is_wp_error( $categories ) ) |
|
| 79 | +function get_the_category($id = false) { |
|
| 80 | + $categories = get_the_terms($id, 'category'); |
|
| 81 | + if ( ! $categories || is_wp_error($categories)) |
|
| 82 | 82 | $categories = array(); |
| 83 | 83 | |
| 84 | - $categories = array_values( $categories ); |
|
| 84 | + $categories = array_values($categories); |
|
| 85 | 85 | |
| 86 | - foreach ( array_keys( $categories ) as $key ) { |
|
| 87 | - _make_cat_compat( $categories[$key] ); |
|
| 86 | + foreach (array_keys($categories) as $key) { |
|
| 87 | + _make_cat_compat($categories[$key]); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @param array $categories An array of categories to return for the post. |
| 97 | 97 | * @param int $id ID of the post. |
| 98 | 98 | */ |
| 99 | - return apply_filters( 'get_the_categories', $categories, $id ); |
|
| 99 | + return apply_filters('get_the_categories', $categories, $id); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | * @param object $b |
| 113 | 113 | * @return int |
| 114 | 114 | */ |
| 115 | -function _usort_terms_by_name( $a, $b ) { |
|
| 116 | - return strcmp( $a->name, $b->name ); |
|
| 115 | +function _usort_terms_by_name($a, $b) { |
|
| 116 | + return strcmp($a->name, $b->name); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,10 +129,10 @@ discard block |
||
| 129 | 129 | * @param object $b |
| 130 | 130 | * @return int |
| 131 | 131 | */ |
| 132 | -function _usort_terms_by_ID( $a, $b ) { |
|
| 133 | - if ( $a->term_id > $b->term_id ) |
|
| 132 | +function _usort_terms_by_ID($a, $b) { |
|
| 133 | + if ($a->term_id > $b->term_id) |
|
| 134 | 134 | return 1; |
| 135 | - elseif ( $a->term_id < $b->term_id ) |
|
| 135 | + elseif ($a->term_id < $b->term_id) |
|
| 136 | 136 | return -1; |
| 137 | 137 | else |
| 138 | 138 | return 0; |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | * @param int $cat_ID Category ID. |
| 147 | 147 | * @return string|WP_Error Category name on success, WP_Error on failure. |
| 148 | 148 | */ |
| 149 | -function get_the_category_by_ID( $cat_ID ) { |
|
| 149 | +function get_the_category_by_ID($cat_ID) { |
|
| 150 | 150 | $cat_ID = (int) $cat_ID; |
| 151 | - $category = get_term( $cat_ID, 'category' ); |
|
| 151 | + $category = get_term($cat_ID, 'category'); |
|
| 152 | 152 | |
| 153 | - if ( is_wp_error( $category ) ) |
|
| 153 | + if (is_wp_error($category)) |
|
| 154 | 154 | return $category; |
| 155 | 155 | |
| 156 | - return ( $category ) ? $category->name : ''; |
|
| 156 | + return ($category) ? $category->name : ''; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * @param int $post_id Optional. Post ID to retrieve categories. |
| 169 | 169 | * @return string |
| 170 | 170 | */ |
| 171 | -function get_the_category_list( $separator = '', $parents='', $post_id = false ) { |
|
| 171 | +function get_the_category_list($separator = '', $parents = '', $post_id = false) { |
|
| 172 | 172 | global $wp_rewrite; |
| 173 | - if ( ! is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) ) { |
|
| 173 | + if ( ! is_object_in_taxonomy(get_post_type($post_id), 'category')) { |
|
| 174 | 174 | /** This filter is documented in wp-includes/category-template.php */ |
| 175 | - return apply_filters( 'the_category', '', $separator, $parents ); |
|
| 175 | + return apply_filters('the_category', '', $separator, $parents); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -184,58 +184,58 @@ discard block |
||
| 184 | 184 | * @param int|bool $post_id ID of the post we're retrieving categories for. When `false`, we assume the |
| 185 | 185 | * current post in the loop. |
| 186 | 186 | */ |
| 187 | - $categories = apply_filters( 'the_category_list', get_the_category( $post_id ), $post_id ); |
|
| 187 | + $categories = apply_filters('the_category_list', get_the_category($post_id), $post_id); |
|
| 188 | 188 | |
| 189 | - if ( empty( $categories ) ) { |
|
| 189 | + if (empty($categories)) { |
|
| 190 | 190 | /** This filter is documented in wp-includes/category-template.php */ |
| 191 | - return apply_filters( 'the_category', __( 'Uncategorized' ), $separator, $parents ); |
|
| 191 | + return apply_filters('the_category', __('Uncategorized'), $separator, $parents); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $rel = ( is_object( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) ? 'rel="category tag"' : 'rel="category"'; |
|
| 194 | + $rel = (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) ? 'rel="category tag"' : 'rel="category"'; |
|
| 195 | 195 | |
| 196 | 196 | $thelist = ''; |
| 197 | - if ( '' == $separator ) { |
|
| 197 | + if ('' == $separator) { |
|
| 198 | 198 | $thelist .= '<ul class="post-categories">'; |
| 199 | - foreach ( $categories as $category ) { |
|
| 199 | + foreach ($categories as $category) { |
|
| 200 | 200 | $thelist .= "\n\t<li>"; |
| 201 | - switch ( strtolower( $parents ) ) { |
|
| 201 | + switch (strtolower($parents)) { |
|
| 202 | 202 | case 'multiple': |
| 203 | - if ( $category->parent ) |
|
| 204 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 205 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
|
| 203 | + if ($category->parent) |
|
| 204 | + $thelist .= get_category_parents($category->parent, true, $separator); |
|
| 205 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a></li>'; |
|
| 206 | 206 | break; |
| 207 | 207 | case 'single': |
| 208 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
|
| 209 | - if ( $category->parent ) |
|
| 210 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 208 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'; |
|
| 209 | + if ($category->parent) |
|
| 210 | + $thelist .= get_category_parents($category->parent, false, $separator); |
|
| 211 | 211 | $thelist .= $category->name.'</a></li>'; |
| 212 | 212 | break; |
| 213 | 213 | case '': |
| 214 | 214 | default: |
| 215 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
|
| 215 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a></li>'; |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | $thelist .= '</ul>'; |
| 219 | 219 | } else { |
| 220 | 220 | $i = 0; |
| 221 | - foreach ( $categories as $category ) { |
|
| 222 | - if ( 0 < $i ) |
|
| 221 | + foreach ($categories as $category) { |
|
| 222 | + if (0 < $i) |
|
| 223 | 223 | $thelist .= $separator; |
| 224 | - switch ( strtolower( $parents ) ) { |
|
| 224 | + switch (strtolower($parents)) { |
|
| 225 | 225 | case 'multiple': |
| 226 | - if ( $category->parent ) |
|
| 227 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 228 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
|
| 226 | + if ($category->parent) |
|
| 227 | + $thelist .= get_category_parents($category->parent, true, $separator); |
|
| 228 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a>'; |
|
| 229 | 229 | break; |
| 230 | 230 | case 'single': |
| 231 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
|
| 232 | - if ( $category->parent ) |
|
| 233 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 231 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'; |
|
| 232 | + if ($category->parent) |
|
| 233 | + $thelist .= get_category_parents($category->parent, false, $separator); |
|
| 234 | 234 | $thelist .= "$category->name</a>"; |
| 235 | 235 | break; |
| 236 | 236 | case '': |
| 237 | 237 | default: |
| 238 | - $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
|
| 238 | + $thelist .= '<a href="'.esc_url(get_category_link($category->term_id)).'" '.$rel.'>'.$category->name.'</a>'; |
|
| 239 | 239 | } |
| 240 | 240 | ++$i; |
| 241 | 241 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @param string $parents How to display the category parents. Accepts 'multiple', |
| 252 | 252 | * 'single', or empty. |
| 253 | 253 | */ |
| 254 | - return apply_filters( 'the_category', $thelist, $separator, $parents ); |
|
| 254 | + return apply_filters('the_category', $thelist, $separator, $parents); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -272,11 +272,11 @@ discard block |
||
| 272 | 272 | * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) |
| 273 | 273 | * @return bool True if the current post is in any of the given categories. |
| 274 | 274 | */ |
| 275 | -function in_category( $category, $post = null ) { |
|
| 276 | - if ( empty( $category ) ) |
|
| 275 | +function in_category($category, $post = null) { |
|
| 276 | + if (empty($category)) |
|
| 277 | 277 | return false; |
| 278 | 278 | |
| 279 | - return has_category( $category, $post ); |
|
| 279 | + return has_category($category, $post); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -288,8 +288,8 @@ discard block |
||
| 288 | 288 | * @param string $parents Optional. How to display the parents. |
| 289 | 289 | * @param int $post_id Optional. Post ID to retrieve categories. |
| 290 | 290 | */ |
| 291 | -function the_category( $separator = '', $parents='', $post_id = false ) { |
|
| 292 | - echo get_the_category_list( $separator, $parents, $post_id ); |
|
| 291 | +function the_category($separator = '', $parents = '', $post_id = false) { |
|
| 292 | + echo get_the_category_list($separator, $parents, $post_id); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | * @param int $category Optional. Category ID. Will use global category ID by default. |
| 301 | 301 | * @return string Category description, available. |
| 302 | 302 | */ |
| 303 | -function category_description( $category = 0 ) { |
|
| 304 | - return term_description( $category, 'category' ); |
|
| 303 | +function category_description($category = 0) { |
|
| 304 | + return term_description($category, 'category'); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * } |
| 355 | 355 | * @return string HTML content only if 'echo' argument is 0. |
| 356 | 356 | */ |
| 357 | -function wp_dropdown_categories( $args = '' ) { |
|
| 357 | +function wp_dropdown_categories($args = '') { |
|
| 358 | 358 | $defaults = array( |
| 359 | 359 | 'show_option_all' => '', 'show_option_none' => '', |
| 360 | 360 | 'orderby' => 'id', 'order' => 'ASC', |
@@ -369,13 +369,13 @@ discard block |
||
| 369 | 369 | 'value_field' => 'term_id', |
| 370 | 370 | ); |
| 371 | 371 | |
| 372 | - $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0; |
|
| 372 | + $defaults['selected'] = (is_category()) ? get_query_var('cat') : 0; |
|
| 373 | 373 | |
| 374 | 374 | // Back compat. |
| 375 | - if ( isset( $args['type'] ) && 'link' == $args['type'] ) { |
|
| 375 | + if (isset($args['type']) && 'link' == $args['type']) { |
|
| 376 | 376 | /* translators: 1: "type => link", 2: "taxonomy => link_category" alternative */ |
| 377 | - _deprecated_argument( __FUNCTION__, '3.0', |
|
| 378 | - sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), |
|
| 377 | + _deprecated_argument(__FUNCTION__, '3.0', |
|
| 378 | + sprintf(__('%1$s is deprecated. Use %2$s instead.'), |
|
| 379 | 379 | '<code>type => link</code>', |
| 380 | 380 | '<code>taxonomy => link_category</code>' |
| 381 | 381 | ) |
@@ -383,35 +383,35 @@ discard block |
||
| 383 | 383 | $args['taxonomy'] = 'link_category'; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - $r = wp_parse_args( $args, $defaults ); |
|
| 386 | + $r = wp_parse_args($args, $defaults); |
|
| 387 | 387 | $option_none_value = $r['option_none_value']; |
| 388 | 388 | |
| 389 | - if ( ! isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
|
| 389 | + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) { |
|
| 390 | 390 | $r['pad_counts'] = true; |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | $tab_index = $r['tab_index']; |
| 394 | 394 | |
| 395 | 395 | $tab_index_attribute = ''; |
| 396 | - if ( (int) $tab_index > 0 ) { |
|
| 396 | + if ((int) $tab_index > 0) { |
|
| 397 | 397 | $tab_index_attribute = " tabindex=\"$tab_index\""; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | // Avoid clashes with the 'name' param of get_terms(). |
| 401 | 401 | $get_terms_args = $r; |
| 402 | - unset( $get_terms_args['name'] ); |
|
| 403 | - $categories = get_terms( $r['taxonomy'], $get_terms_args ); |
|
| 402 | + unset($get_terms_args['name']); |
|
| 403 | + $categories = get_terms($r['taxonomy'], $get_terms_args); |
|
| 404 | 404 | |
| 405 | - $name = esc_attr( $r['name'] ); |
|
| 406 | - $class = esc_attr( $r['class'] ); |
|
| 407 | - $id = $r['id'] ? esc_attr( $r['id'] ) : $name; |
|
| 405 | + $name = esc_attr($r['name']); |
|
| 406 | + $class = esc_attr($r['class']); |
|
| 407 | + $id = $r['id'] ? esc_attr($r['id']) : $name; |
|
| 408 | 408 | |
| 409 | - if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
|
| 409 | + if ( ! $r['hide_if_empty'] || ! empty($categories)) { |
|
| 410 | 410 | $output = "<select name='$name' id='$id' class='$class' $tab_index_attribute>\n"; |
| 411 | 411 | } else { |
| 412 | 412 | $output = ''; |
| 413 | 413 | } |
| 414 | - if ( empty( $categories ) && ! $r['hide_if_empty'] && ! empty( $r['show_option_none'] ) ) { |
|
| 414 | + if (empty($categories) && ! $r['hide_if_empty'] && ! empty($r['show_option_none'])) { |
|
| 415 | 415 | |
| 416 | 416 | /** |
| 417 | 417 | * Filter a taxonomy drop-down display element. |
@@ -427,37 +427,37 @@ discard block |
||
| 427 | 427 | * |
| 428 | 428 | * @param string $element Taxonomy element to list. |
| 429 | 429 | */ |
| 430 | - $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
|
| 431 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "' selected='selected'>$show_option_none</option>\n"; |
|
| 430 | + $show_option_none = apply_filters('list_cats', $r['show_option_none']); |
|
| 431 | + $output .= "\t<option value='".esc_attr($option_none_value)."' selected='selected'>$show_option_none</option>\n"; |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if ( ! empty( $categories ) ) { |
|
| 434 | + if ( ! empty($categories)) { |
|
| 435 | 435 | |
| 436 | - if ( $r['show_option_all'] ) { |
|
| 436 | + if ($r['show_option_all']) { |
|
| 437 | 437 | |
| 438 | 438 | /** This filter is documented in wp-includes/category-template.php */ |
| 439 | - $show_option_all = apply_filters( 'list_cats', $r['show_option_all'] ); |
|
| 440 | - $selected = ( '0' === strval($r['selected']) ) ? " selected='selected'" : ''; |
|
| 439 | + $show_option_all = apply_filters('list_cats', $r['show_option_all']); |
|
| 440 | + $selected = ('0' === strval($r['selected'])) ? " selected='selected'" : ''; |
|
| 441 | 441 | $output .= "\t<option value='0'$selected>$show_option_all</option>\n"; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if ( $r['show_option_none'] ) { |
|
| 444 | + if ($r['show_option_none']) { |
|
| 445 | 445 | |
| 446 | 446 | /** This filter is documented in wp-includes/category-template.php */ |
| 447 | - $show_option_none = apply_filters( 'list_cats', $r['show_option_none'] ); |
|
| 448 | - $selected = selected( $option_none_value, $r['selected'], false ); |
|
| 449 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$selected>$show_option_none</option>\n"; |
|
| 447 | + $show_option_none = apply_filters('list_cats', $r['show_option_none']); |
|
| 448 | + $selected = selected($option_none_value, $r['selected'], false); |
|
| 449 | + $output .= "\t<option value='".esc_attr($option_none_value)."'$selected>$show_option_none</option>\n"; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - if ( $r['hierarchical'] ) { |
|
| 453 | - $depth = $r['depth']; // Walk the full depth. |
|
| 452 | + if ($r['hierarchical']) { |
|
| 453 | + $depth = $r['depth']; // Walk the full depth. |
|
| 454 | 454 | } else { |
| 455 | 455 | $depth = -1; // Flat. |
| 456 | 456 | } |
| 457 | - $output .= walk_category_dropdown_tree( $categories, $depth, $r ); |
|
| 457 | + $output .= walk_category_dropdown_tree($categories, $depth, $r); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( ! $r['hide_if_empty'] || ! empty( $categories ) ) { |
|
| 460 | + if ( ! $r['hide_if_empty'] || ! empty($categories)) { |
|
| 461 | 461 | $output .= "</select>\n"; |
| 462 | 462 | } |
| 463 | 463 | /** |
@@ -468,9 +468,9 @@ discard block |
||
| 468 | 468 | * @param string $output HTML output. |
| 469 | 469 | * @param array $r Arguments used to build the drop-down. |
| 470 | 470 | */ |
| 471 | - $output = apply_filters( 'wp_dropdown_cats', $output, $r ); |
|
| 471 | + $output = apply_filters('wp_dropdown_cats', $output, $r); |
|
| 472 | 472 | |
| 473 | - if ( $r['echo'] ) { |
|
| 473 | + if ($r['echo']) { |
|
| 474 | 474 | echo $output; |
| 475 | 475 | } |
| 476 | 476 | return $output; |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | * } |
| 525 | 525 | * @return false|string HTML content only if 'echo' argument is 0. |
| 526 | 526 | */ |
| 527 | -function wp_list_categories( $args = '' ) { |
|
| 527 | +function wp_list_categories($args = '') { |
|
| 528 | 528 | $defaults = array( |
| 529 | 529 | 'child_of' => 0, |
| 530 | 530 | 'current_category' => 0, |
@@ -543,110 +543,110 @@ discard block |
||
| 543 | 543 | 'separator' => '<br />', |
| 544 | 544 | 'show_count' => 0, |
| 545 | 545 | 'show_option_all' => '', |
| 546 | - 'show_option_none' => __( 'No categories' ), |
|
| 546 | + 'show_option_none' => __('No categories'), |
|
| 547 | 547 | 'style' => 'list', |
| 548 | 548 | 'taxonomy' => 'category', |
| 549 | - 'title_li' => __( 'Categories' ), |
|
| 549 | + 'title_li' => __('Categories'), |
|
| 550 | 550 | 'use_desc_for_title' => 1, |
| 551 | 551 | ); |
| 552 | 552 | |
| 553 | - $r = wp_parse_args( $args, $defaults ); |
|
| 553 | + $r = wp_parse_args($args, $defaults); |
|
| 554 | 554 | |
| 555 | - if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) |
|
| 555 | + if ( ! isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) |
|
| 556 | 556 | $r['pad_counts'] = true; |
| 557 | 557 | |
| 558 | 558 | // Descendants of exclusions should be excluded too. |
| 559 | - if ( true == $r['hierarchical'] ) { |
|
| 559 | + if (true == $r['hierarchical']) { |
|
| 560 | 560 | $exclude_tree = array(); |
| 561 | 561 | |
| 562 | - if ( $r['exclude_tree'] ) { |
|
| 563 | - $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) ); |
|
| 562 | + if ($r['exclude_tree']) { |
|
| 563 | + $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude_tree'])); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - if ( $r['exclude'] ) { |
|
| 567 | - $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) ); |
|
| 566 | + if ($r['exclude']) { |
|
| 567 | + $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude'])); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | $r['exclude_tree'] = $exclude_tree; |
| 571 | 571 | $r['exclude'] = ''; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - if ( ! isset( $r['class'] ) ) |
|
| 575 | - $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 574 | + if ( ! isset($r['class'])) |
|
| 575 | + $r['class'] = ('category' == $r['taxonomy']) ? 'categories' : $r['taxonomy']; |
|
| 576 | 576 | |
| 577 | - if ( ! taxonomy_exists( $r['taxonomy'] ) ) { |
|
| 577 | + if ( ! taxonomy_exists($r['taxonomy'])) { |
|
| 578 | 578 | return false; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | $show_option_all = $r['show_option_all']; |
| 582 | 582 | $show_option_none = $r['show_option_none']; |
| 583 | 583 | |
| 584 | - $categories = get_categories( $r ); |
|
| 584 | + $categories = get_categories($r); |
|
| 585 | 585 | |
| 586 | 586 | $output = ''; |
| 587 | - if ( $r['title_li'] && 'list' == $r['style'] && ( ! empty( $categories ) || ! $r['hide_title_if_empty'] ) ) { |
|
| 588 | - $output = '<li class="' . esc_attr( $r['class'] ) . '">' . $r['title_li'] . '<ul>'; |
|
| 587 | + if ($r['title_li'] && 'list' == $r['style'] && ( ! empty($categories) || ! $r['hide_title_if_empty'])) { |
|
| 588 | + $output = '<li class="'.esc_attr($r['class']).'">'.$r['title_li'].'<ul>'; |
|
| 589 | 589 | } |
| 590 | - if ( empty( $categories ) ) { |
|
| 591 | - if ( ! empty( $show_option_none ) ) { |
|
| 592 | - if ( 'list' == $r['style'] ) { |
|
| 593 | - $output .= '<li class="cat-item-none">' . $show_option_none . '</li>'; |
|
| 590 | + if (empty($categories)) { |
|
| 591 | + if ( ! empty($show_option_none)) { |
|
| 592 | + if ('list' == $r['style']) { |
|
| 593 | + $output .= '<li class="cat-item-none">'.$show_option_none.'</li>'; |
|
| 594 | 594 | } else { |
| 595 | 595 | $output .= $show_option_none; |
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | } else { |
| 599 | - if ( ! empty( $show_option_all ) ) { |
|
| 599 | + if ( ! empty($show_option_all)) { |
|
| 600 | 600 | |
| 601 | 601 | $posts_page = ''; |
| 602 | 602 | |
| 603 | 603 | // For taxonomies that belong only to custom post types, point to a valid archive. |
| 604 | - $taxonomy_object = get_taxonomy( $r['taxonomy'] ); |
|
| 605 | - if ( ! in_array( 'post', $taxonomy_object->object_type ) && ! in_array( 'page', $taxonomy_object->object_type ) ) { |
|
| 606 | - foreach ( $taxonomy_object->object_type as $object_type ) { |
|
| 607 | - $_object_type = get_post_type_object( $object_type ); |
|
| 604 | + $taxonomy_object = get_taxonomy($r['taxonomy']); |
|
| 605 | + if ( ! in_array('post', $taxonomy_object->object_type) && ! in_array('page', $taxonomy_object->object_type)) { |
|
| 606 | + foreach ($taxonomy_object->object_type as $object_type) { |
|
| 607 | + $_object_type = get_post_type_object($object_type); |
|
| 608 | 608 | |
| 609 | 609 | // Grab the first one. |
| 610 | - if ( ! empty( $_object_type->has_archive ) ) { |
|
| 611 | - $posts_page = get_post_type_archive_link( $object_type ); |
|
| 610 | + if ( ! empty($_object_type->has_archive)) { |
|
| 611 | + $posts_page = get_post_type_archive_link($object_type); |
|
| 612 | 612 | break; |
| 613 | 613 | } |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | // Fallback for the 'All' link is the posts page. |
| 618 | - if ( ! $posts_page ) { |
|
| 619 | - if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) { |
|
| 620 | - $posts_page = get_permalink( get_option( 'page_for_posts' ) ); |
|
| 618 | + if ( ! $posts_page) { |
|
| 619 | + if ('page' == get_option('show_on_front') && get_option('page_for_posts')) { |
|
| 620 | + $posts_page = get_permalink(get_option('page_for_posts')); |
|
| 621 | 621 | } else { |
| 622 | - $posts_page = home_url( '/' ); |
|
| 622 | + $posts_page = home_url('/'); |
|
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | - $posts_page = esc_url( $posts_page ); |
|
| 627 | - if ( 'list' == $r['style'] ) { |
|
| 626 | + $posts_page = esc_url($posts_page); |
|
| 627 | + if ('list' == $r['style']) { |
|
| 628 | 628 | $output .= "<li class='cat-item-all'><a href='$posts_page'>$show_option_all</a></li>"; |
| 629 | 629 | } else { |
| 630 | 630 | $output .= "<a href='$posts_page'>$show_option_all</a>"; |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) { |
|
| 634 | + if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) { |
|
| 635 | 635 | $current_term_object = get_queried_object(); |
| 636 | - if ( $current_term_object && $r['taxonomy'] === $current_term_object->taxonomy ) { |
|
| 636 | + if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) { |
|
| 637 | 637 | $r['current_category'] = get_queried_object_id(); |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - if ( $r['hierarchical'] ) { |
|
| 641 | + if ($r['hierarchical']) { |
|
| 642 | 642 | $depth = $r['depth']; |
| 643 | 643 | } else { |
| 644 | 644 | $depth = -1; // Flat. |
| 645 | 645 | } |
| 646 | - $output .= walk_category_tree( $categories, $depth, $r ); |
|
| 646 | + $output .= walk_category_tree($categories, $depth, $r); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | - if ( $r['title_li'] && 'list' == $r['style'] ) |
|
| 649 | + if ($r['title_li'] && 'list' == $r['style']) |
|
| 650 | 650 | $output .= '</ul></li>'; |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -657,9 +657,9 @@ discard block |
||
| 657 | 657 | * @param string $output HTML output. |
| 658 | 658 | * @param array $args An array of taxonomy-listing arguments. |
| 659 | 659 | */ |
| 660 | - $html = apply_filters( 'wp_list_categories', $output, $args ); |
|
| 660 | + $html = apply_filters('wp_list_categories', $output, $args); |
|
| 661 | 661 | |
| 662 | - if ( $r['echo'] ) { |
|
| 662 | + if ($r['echo']) { |
|
| 663 | 663 | echo $html; |
| 664 | 664 | } else { |
| 665 | 665 | return $html; |
@@ -701,32 +701,32 @@ discard block |
||
| 701 | 701 | * @return void|array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument. |
| 702 | 702 | * Otherwise, this function outputs the tag cloud. |
| 703 | 703 | */ |
| 704 | -function wp_tag_cloud( $args = '' ) { |
|
| 704 | +function wp_tag_cloud($args = '') { |
|
| 705 | 705 | $defaults = array( |
| 706 | 706 | 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, |
| 707 | 707 | 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
| 708 | 708 | 'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'post_type' => '', 'echo' => true |
| 709 | 709 | ); |
| 710 | - $args = wp_parse_args( $args, $defaults ); |
|
| 710 | + $args = wp_parse_args($args, $defaults); |
|
| 711 | 711 | |
| 712 | - $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
|
| 712 | + $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); // Always query top tags |
|
| 713 | 713 | |
| 714 | - if ( empty( $tags ) || is_wp_error( $tags ) ) |
|
| 714 | + if (empty($tags) || is_wp_error($tags)) |
|
| 715 | 715 | return; |
| 716 | 716 | |
| 717 | - foreach ( $tags as $key => $tag ) { |
|
| 718 | - if ( 'edit' == $args['link'] ) |
|
| 719 | - $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 717 | + foreach ($tags as $key => $tag) { |
|
| 718 | + if ('edit' == $args['link']) |
|
| 719 | + $link = get_edit_term_link($tag->term_id, $tag->taxonomy, $args['post_type']); |
|
| 720 | 720 | else |
| 721 | - $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 722 | - if ( is_wp_error( $link ) ) |
|
| 721 | + $link = get_term_link(intval($tag->term_id), $tag->taxonomy); |
|
| 722 | + if (is_wp_error($link)) |
|
| 723 | 723 | return; |
| 724 | 724 | |
| 725 | - $tags[ $key ]->link = $link; |
|
| 726 | - $tags[ $key ]->id = $tag->term_id; |
|
| 725 | + $tags[$key]->link = $link; |
|
| 726 | + $tags[$key]->id = $tag->term_id; |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args |
|
| 729 | + $return = wp_generate_tag_cloud($tags, $args); // Here's where those top tags get sorted according to $args |
|
| 730 | 730 | |
| 731 | 731 | /** |
| 732 | 732 | * Filter the tag cloud output. |
@@ -736,9 +736,9 @@ discard block |
||
| 736 | 736 | * @param string $return HTML output of the tag cloud. |
| 737 | 737 | * @param array $args An array of tag cloud arguments. |
| 738 | 738 | */ |
| 739 | - $return = apply_filters( 'wp_tag_cloud', $return, $args ); |
|
| 739 | + $return = apply_filters('wp_tag_cloud', $return, $args); |
|
| 740 | 740 | |
| 741 | - if ( 'array' == $args['format'] || empty($args['echo']) ) |
|
| 741 | + if ('array' == $args['format'] || empty($args['echo'])) |
|
| 742 | 742 | return $return; |
| 743 | 743 | |
| 744 | 744 | echo $return; |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @param int $count number of posts with that tag |
| 751 | 751 | * @return int scaled count |
| 752 | 752 | */ |
| 753 | -function default_topic_count_scale( $count ) { |
|
| 753 | +function default_topic_count_scale($count) { |
|
| 754 | 754 | return round(log10($count + 1) * 100); |
| 755 | 755 | } |
| 756 | 756 | |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | * @param string|array $args Optional, override default arguments. |
| 789 | 789 | * @return string|array Tag cloud as a string or an array, depending on 'format' argument. |
| 790 | 790 | */ |
| 791 | -function wp_generate_tag_cloud( $tags, $args = '' ) { |
|
| 791 | +function wp_generate_tag_cloud($tags, $args = '') { |
|
| 792 | 792 | $defaults = array( |
| 793 | 793 | 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 0, |
| 794 | 794 | 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', |
@@ -796,31 +796,31 @@ discard block |
||
| 796 | 796 | 'topic_count_scale_callback' => 'default_topic_count_scale', 'filter' => 1, |
| 797 | 797 | ); |
| 798 | 798 | |
| 799 | - $args = wp_parse_args( $args, $defaults ); |
|
| 799 | + $args = wp_parse_args($args, $defaults); |
|
| 800 | 800 | |
| 801 | - $return = ( 'array' === $args['format'] ) ? array() : ''; |
|
| 801 | + $return = ('array' === $args['format']) ? array() : ''; |
|
| 802 | 802 | |
| 803 | - if ( empty( $tags ) ) { |
|
| 803 | + if (empty($tags)) { |
|
| 804 | 804 | return $return; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | // Juggle topic count tooltips: |
| 808 | - if ( isset( $args['topic_count_text'] ) ) { |
|
| 808 | + if (isset($args['topic_count_text'])) { |
|
| 809 | 809 | // First look for nooped plural support via topic_count_text. |
| 810 | 810 | $translate_nooped_plural = $args['topic_count_text']; |
| 811 | - } elseif ( ! empty( $args['topic_count_text_callback'] ) ) { |
|
| 811 | + } elseif ( ! empty($args['topic_count_text_callback'])) { |
|
| 812 | 812 | // Look for the alternative callback style. Ignore the previous default. |
| 813 | - if ( $args['topic_count_text_callback'] === 'default_topic_count_text' ) { |
|
| 814 | - $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
| 813 | + if ($args['topic_count_text_callback'] === 'default_topic_count_text') { |
|
| 814 | + $translate_nooped_plural = _n_noop('%s topic', '%s topics'); |
|
| 815 | 815 | } else { |
| 816 | 816 | $translate_nooped_plural = false; |
| 817 | 817 | } |
| 818 | - } elseif ( isset( $args['single_text'] ) && isset( $args['multiple_text'] ) ) { |
|
| 818 | + } elseif (isset($args['single_text']) && isset($args['multiple_text'])) { |
|
| 819 | 819 | // If no callback exists, look for the old-style single_text and multiple_text arguments. |
| 820 | - $translate_nooped_plural = _n_noop( $args['single_text'], $args['multiple_text'] ); |
|
| 820 | + $translate_nooped_plural = _n_noop($args['single_text'], $args['multiple_text']); |
|
| 821 | 821 | } else { |
| 822 | 822 | // This is the default for when no callback, plural, or argument is passed in. |
| 823 | - $translate_nooped_plural = _n_noop( '%s topic', '%s topics' ); |
|
| 823 | + $translate_nooped_plural = _n_noop('%s topic', '%s topics'); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -831,62 +831,62 @@ discard block |
||
| 831 | 831 | * @param array $tags Ordered array of terms. |
| 832 | 832 | * @param array $args An array of tag cloud arguments. |
| 833 | 833 | */ |
| 834 | - $tags_sorted = apply_filters( 'tag_cloud_sort', $tags, $args ); |
|
| 835 | - if ( empty( $tags_sorted ) ) { |
|
| 834 | + $tags_sorted = apply_filters('tag_cloud_sort', $tags, $args); |
|
| 835 | + if (empty($tags_sorted)) { |
|
| 836 | 836 | return $return; |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | - if ( $tags_sorted !== $tags ) { |
|
| 839 | + if ($tags_sorted !== $tags) { |
|
| 840 | 840 | $tags = $tags_sorted; |
| 841 | - unset( $tags_sorted ); |
|
| 841 | + unset($tags_sorted); |
|
| 842 | 842 | } else { |
| 843 | - if ( 'RAND' === $args['order'] ) { |
|
| 844 | - shuffle( $tags ); |
|
| 843 | + if ('RAND' === $args['order']) { |
|
| 844 | + shuffle($tags); |
|
| 845 | 845 | } else { |
| 846 | 846 | // SQL cannot save you; this is a second (potentially different) sort on a subset of data. |
| 847 | - if ( 'name' === $args['orderby'] ) { |
|
| 848 | - uasort( $tags, '_wp_object_name_sort_cb' ); |
|
| 847 | + if ('name' === $args['orderby']) { |
|
| 848 | + uasort($tags, '_wp_object_name_sort_cb'); |
|
| 849 | 849 | } else { |
| 850 | - uasort( $tags, '_wp_object_count_sort_cb' ); |
|
| 850 | + uasort($tags, '_wp_object_count_sort_cb'); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | - if ( 'DESC' === $args['order'] ) { |
|
| 854 | - $tags = array_reverse( $tags, true ); |
|
| 853 | + if ('DESC' === $args['order']) { |
|
| 854 | + $tags = array_reverse($tags, true); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | - if ( $args['number'] > 0 ) |
|
| 860 | - $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 859 | + if ($args['number'] > 0) |
|
| 860 | + $tags = array_slice($tags, 0, $args['number']); |
|
| 861 | 861 | |
| 862 | 862 | $counts = array(); |
| 863 | 863 | $real_counts = array(); // For the alt tag |
| 864 | - foreach ( (array) $tags as $key => $tag ) { |
|
| 865 | - $real_counts[ $key ] = $tag->count; |
|
| 866 | - $counts[ $key ] = call_user_func( $args['topic_count_scale_callback'], $tag->count ); |
|
| 864 | + foreach ((array) $tags as $key => $tag) { |
|
| 865 | + $real_counts[$key] = $tag->count; |
|
| 866 | + $counts[$key] = call_user_func($args['topic_count_scale_callback'], $tag->count); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | - $min_count = min( $counts ); |
|
| 870 | - $spread = max( $counts ) - $min_count; |
|
| 871 | - if ( $spread <= 0 ) |
|
| 869 | + $min_count = min($counts); |
|
| 870 | + $spread = max($counts) - $min_count; |
|
| 871 | + if ($spread <= 0) |
|
| 872 | 872 | $spread = 1; |
| 873 | 873 | $font_spread = $args['largest'] - $args['smallest']; |
| 874 | - if ( $font_spread < 0 ) |
|
| 874 | + if ($font_spread < 0) |
|
| 875 | 875 | $font_spread = 1; |
| 876 | 876 | $font_step = $font_spread / $spread; |
| 877 | 877 | |
| 878 | 878 | // Assemble the data that will be used to generate the tag cloud markup. |
| 879 | 879 | $tags_data = array(); |
| 880 | - foreach ( $tags as $key => $tag ) { |
|
| 881 | - $tag_id = isset( $tag->id ) ? $tag->id : $key; |
|
| 880 | + foreach ($tags as $key => $tag) { |
|
| 881 | + $tag_id = isset($tag->id) ? $tag->id : $key; |
|
| 882 | 882 | |
| 883 | - $count = $counts[ $key ]; |
|
| 884 | - $real_count = $real_counts[ $key ]; |
|
| 883 | + $count = $counts[$key]; |
|
| 884 | + $real_count = $real_counts[$key]; |
|
| 885 | 885 | |
| 886 | - if ( $translate_nooped_plural ) { |
|
| 887 | - $title = sprintf( translate_nooped_plural( $translate_nooped_plural, $real_count ), number_format_i18n( $real_count ) ); |
|
| 886 | + if ($translate_nooped_plural) { |
|
| 887 | + $title = sprintf(translate_nooped_plural($translate_nooped_plural, $real_count), number_format_i18n($real_count)); |
|
| 888 | 888 | } else { |
| 889 | - $title = call_user_func( $args['topic_count_text_callback'], $real_count, $tag, $args ); |
|
| 889 | + $title = call_user_func($args['topic_count_text_callback'], $real_count, $tag, $args); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | $tags_data[] = array( |
@@ -896,8 +896,8 @@ discard block |
||
| 896 | 896 | 'title' => $title, |
| 897 | 897 | 'slug' => $tag->slug, |
| 898 | 898 | 'real_count' => $real_count, |
| 899 | - 'class' => 'tag-link-' . $tag_id, |
|
| 900 | - 'font_size' => $args['smallest'] + ( $count - $min_count ) * $font_step, |
|
| 899 | + 'class' => 'tag-link-'.$tag_id, |
|
| 900 | + 'font_size' => $args['smallest'] + ($count - $min_count) * $font_step, |
|
| 901 | 901 | ); |
| 902 | 902 | } |
| 903 | 903 | |
@@ -908,31 +908,31 @@ discard block |
||
| 908 | 908 | * |
| 909 | 909 | * @param array $tags_data An array of term data for term used to generate the tag cloud. |
| 910 | 910 | */ |
| 911 | - $tags_data = apply_filters( 'wp_generate_tag_cloud_data', $tags_data ); |
|
| 911 | + $tags_data = apply_filters('wp_generate_tag_cloud_data', $tags_data); |
|
| 912 | 912 | |
| 913 | 913 | $a = array(); |
| 914 | 914 | |
| 915 | 915 | // generate the output links array |
| 916 | - foreach ( $tags_data as $key => $tag_data ) { |
|
| 917 | - $class = $tag_data['class'] . ' tag-link-position-' . ( $key + 1 ); |
|
| 918 | - $a[] = "<a href='" . esc_url( $tag_data['url'] ) . "' class='" . esc_attr( $class ) . "' title='" . esc_attr( $tag_data['title'] ) . "' style='font-size: " . esc_attr( str_replace( ',', '.', $tag_data['font_size'] ) . $args['unit'] ) . ";'>" . esc_html( $tag_data['name'] ) . "</a>"; |
|
| 916 | + foreach ($tags_data as $key => $tag_data) { |
|
| 917 | + $class = $tag_data['class'].' tag-link-position-'.($key + 1); |
|
| 918 | + $a[] = "<a href='".esc_url($tag_data['url'])."' class='".esc_attr($class)."' title='".esc_attr($tag_data['title'])."' style='font-size: ".esc_attr(str_replace(',', '.', $tag_data['font_size']).$args['unit']).";'>".esc_html($tag_data['name'])."</a>"; |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | - switch ( $args['format'] ) { |
|
| 921 | + switch ($args['format']) { |
|
| 922 | 922 | case 'array' : |
| 923 | - $return =& $a; |
|
| 923 | + $return = & $a; |
|
| 924 | 924 | break; |
| 925 | 925 | case 'list' : |
| 926 | 926 | $return = "<ul class='wp-tag-cloud'>\n\t<li>"; |
| 927 | - $return .= join( "</li>\n\t<li>", $a ); |
|
| 927 | + $return .= join("</li>\n\t<li>", $a); |
|
| 928 | 928 | $return .= "</li>\n</ul>\n"; |
| 929 | 929 | break; |
| 930 | 930 | default : |
| 931 | - $return = join( $args['separator'], $a ); |
|
| 931 | + $return = join($args['separator'], $a); |
|
| 932 | 932 | break; |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - if ( $args['filter'] ) { |
|
| 935 | + if ($args['filter']) { |
|
| 936 | 936 | /** |
| 937 | 937 | * Filter the generated output of a tag cloud. |
| 938 | 938 | * |
@@ -949,7 +949,7 @@ discard block |
||
| 949 | 949 | * @param array $tags An array of terms used in the tag cloud. |
| 950 | 950 | * @param array $args An array of wp_generate_tag_cloud() arguments. |
| 951 | 951 | */ |
| 952 | - return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
|
| 952 | + return apply_filters('wp_generate_tag_cloud', $return, $tags, $args); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | else |
@@ -969,8 +969,8 @@ discard block |
||
| 969 | 969 | * @return int Negative number if `$a->name` is less than `$b->name`, zero if they are equal, |
| 970 | 970 | * or greater than zero if `$a->name` is greater than `$b->name`. |
| 971 | 971 | */ |
| 972 | -function _wp_object_name_sort_cb( $a, $b ) { |
|
| 973 | - return strnatcasecmp( $a->name, $b->name ); |
|
| 972 | +function _wp_object_name_sort_cb($a, $b) { |
|
| 973 | + return strnatcasecmp($a->name, $b->name); |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -985,8 +985,8 @@ discard block |
||
| 985 | 985 | * @param object $b The second object to compare. |
| 986 | 986 | * @return bool Whether the count value for `$a` is greater than the count value for `$b`. |
| 987 | 987 | */ |
| 988 | -function _wp_object_count_sort_cb( $a, $b ) { |
|
| 989 | - return ( $a->count > $b->count ); |
|
| 988 | +function _wp_object_count_sort_cb($a, $b) { |
|
| 989 | + return ($a->count > $b->count); |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | // |
@@ -1004,12 +1004,12 @@ discard block |
||
| 1004 | 1004 | function walk_category_tree() { |
| 1005 | 1005 | $args = func_get_args(); |
| 1006 | 1006 | // the user's options are the third parameter |
| 1007 | - if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
|
| 1007 | + if (empty($args[2]['walker']) || ! ($args[2]['walker'] instanceof Walker)) { |
|
| 1008 | 1008 | $walker = new Walker_Category; |
| 1009 | 1009 | } else { |
| 1010 | 1010 | $walker = $args[2]['walker']; |
| 1011 | 1011 | } |
| 1012 | - return call_user_func_array( array( $walker, 'walk' ), $args ); |
|
| 1012 | + return call_user_func_array(array($walker, 'walk'), $args); |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | /** |
@@ -1023,12 +1023,12 @@ discard block |
||
| 1023 | 1023 | function walk_category_dropdown_tree() { |
| 1024 | 1024 | $args = func_get_args(); |
| 1025 | 1025 | // the user's options are the third parameter |
| 1026 | - if ( empty( $args[2]['walker'] ) || ! ( $args[2]['walker'] instanceof Walker ) ) { |
|
| 1026 | + if (empty($args[2]['walker']) || ! ($args[2]['walker'] instanceof Walker)) { |
|
| 1027 | 1027 | $walker = new Walker_CategoryDropdown; |
| 1028 | 1028 | } else { |
| 1029 | 1029 | $walker = $args[2]['walker']; |
| 1030 | 1030 | } |
| 1031 | - return call_user_func_array( array( $walker, 'walk' ), $args ); |
|
| 1031 | + return call_user_func_array(array($walker, 'walk'), $args); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | // |
@@ -1044,13 +1044,13 @@ discard block |
||
| 1044 | 1044 | * @param int|object $tag Tag ID or object. |
| 1045 | 1045 | * @return string Link on success, empty string if tag does not exist. |
| 1046 | 1046 | */ |
| 1047 | -function get_tag_link( $tag ) { |
|
| 1048 | - if ( ! is_object( $tag ) ) |
|
| 1047 | +function get_tag_link($tag) { |
|
| 1048 | + if ( ! is_object($tag)) |
|
| 1049 | 1049 | $tag = (int) $tag; |
| 1050 | 1050 | |
| 1051 | - $tag = get_term_link( $tag, 'post_tag' ); |
|
| 1051 | + $tag = get_term_link($tag, 'post_tag'); |
|
| 1052 | 1052 | |
| 1053 | - if ( is_wp_error( $tag ) ) |
|
| 1053 | + if (is_wp_error($tag)) |
|
| 1054 | 1054 | return ''; |
| 1055 | 1055 | |
| 1056 | 1056 | return $tag; |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | * @param int $id Post ID. |
| 1065 | 1065 | * @return array|false|WP_Error Array of tag objects on success, false on failure. |
| 1066 | 1066 | */ |
| 1067 | -function get_the_tags( $id = 0 ) { |
|
| 1067 | +function get_the_tags($id = 0) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | /** |
| 1070 | 1070 | * Filter the array of tags for the given post. |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | * |
| 1076 | 1076 | * @param array $terms An array of tags for the given post. |
| 1077 | 1077 | */ |
| 1078 | - return apply_filters( 'get_the_tags', get_the_terms( $id, 'post_tag' ) ); |
|
| 1078 | + return apply_filters('get_the_tags', get_the_terms($id, 'post_tag')); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | * @param int $id Optional. Post ID. Defaults to the current post. |
| 1090 | 1090 | * @return string|false|WP_Error A list of tags on success, false if there are no terms, WP_Error on failure. |
| 1091 | 1091 | */ |
| 1092 | -function get_the_tag_list( $before = '', $sep = '', $after = '', $id = 0 ) { |
|
| 1092 | +function get_the_tag_list($before = '', $sep = '', $after = '', $id = 0) { |
|
| 1093 | 1093 | |
| 1094 | 1094 | /** |
| 1095 | 1095 | * Filter the tags list for a given post. |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | * @param string $after String to use after tags. |
| 1103 | 1103 | * @param int $id Post ID. |
| 1104 | 1104 | */ |
| 1105 | - return apply_filters( 'the_tags', get_the_term_list( $id, 'post_tag', $before, $sep, $after ), $before, $sep, $after, $id ); |
|
| 1105 | + return apply_filters('the_tags', get_the_term_list($id, 'post_tag', $before, $sep, $after), $before, $sep, $after, $id); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1114,8 +1114,8 @@ discard block |
||
| 1114 | 1114 | * @param string $sep Optional. Separate items using this. |
| 1115 | 1115 | * @param string $after Optional. After list. |
| 1116 | 1116 | */ |
| 1117 | -function the_tags( $before = null, $sep = ', ', $after = '' ) { |
|
| 1118 | - if ( null === $before ) |
|
| 1117 | +function the_tags($before = null, $sep = ', ', $after = '') { |
|
| 1118 | + if (null === $before) |
|
| 1119 | 1119 | $before = __('Tags: '); |
| 1120 | 1120 | echo get_the_tag_list($before, $sep, $after); |
| 1121 | 1121 | } |
@@ -1128,8 +1128,8 @@ discard block |
||
| 1128 | 1128 | * @param int $tag Optional. Tag ID. Will use global tag ID by default. |
| 1129 | 1129 | * @return string Tag description, available. |
| 1130 | 1130 | */ |
| 1131 | -function tag_description( $tag = 0 ) { |
|
| 1132 | - return term_description( $tag ); |
|
| 1131 | +function tag_description($tag = 0) { |
|
| 1132 | + return term_description($tag); |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | /** |
@@ -1141,16 +1141,16 @@ discard block |
||
| 1141 | 1141 | * @param string $taxonomy Optional taxonomy name. Defaults to 'post_tag'. |
| 1142 | 1142 | * @return string Term description, available. |
| 1143 | 1143 | */ |
| 1144 | -function term_description( $term = 0, $taxonomy = 'post_tag' ) { |
|
| 1145 | - if ( ! $term && ( is_tax() || is_tag() || is_category() ) ) { |
|
| 1144 | +function term_description($term = 0, $taxonomy = 'post_tag') { |
|
| 1145 | + if ( ! $term && (is_tax() || is_tag() || is_category())) { |
|
| 1146 | 1146 | $term = get_queried_object(); |
| 1147 | - if ( $term ) { |
|
| 1147 | + if ($term) { |
|
| 1148 | 1148 | $taxonomy = $term->taxonomy; |
| 1149 | 1149 | $term = $term->term_id; |
| 1150 | 1150 | } |
| 1151 | 1151 | } |
| 1152 | - $description = get_term_field( 'description', $term, $taxonomy ); |
|
| 1153 | - return is_wp_error( $description ) ? '' : $description; |
|
| 1152 | + $description = get_term_field('description', $term, $taxonomy); |
|
| 1153 | + return is_wp_error($description) ? '' : $description; |
|
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | /** |
@@ -1163,24 +1163,24 @@ discard block |
||
| 1163 | 1163 | * @return array|false|WP_Error Array of term objects on success, false if there are no terms |
| 1164 | 1164 | * or the post does not exist, WP_Error on failure. |
| 1165 | 1165 | */ |
| 1166 | -function get_the_terms( $post, $taxonomy ) { |
|
| 1167 | - if ( ! $post = get_post( $post ) ) |
|
| 1166 | +function get_the_terms($post, $taxonomy) { |
|
| 1167 | + if ( ! $post = get_post($post)) |
|
| 1168 | 1168 | return false; |
| 1169 | 1169 | |
| 1170 | - $terms = get_object_term_cache( $post->ID, $taxonomy ); |
|
| 1171 | - if ( false === $terms ) { |
|
| 1172 | - $terms = wp_get_object_terms( $post->ID, $taxonomy ); |
|
| 1173 | - if ( ! is_wp_error( $terms ) ) { |
|
| 1170 | + $terms = get_object_term_cache($post->ID, $taxonomy); |
|
| 1171 | + if (false === $terms) { |
|
| 1172 | + $terms = wp_get_object_terms($post->ID, $taxonomy); |
|
| 1173 | + if ( ! is_wp_error($terms)) { |
|
| 1174 | 1174 | $to_cache = array(); |
| 1175 | - foreach ( $terms as $key => $term ) { |
|
| 1176 | - $to_cache[ $key ] = $term->data; |
|
| 1175 | + foreach ($terms as $key => $term) { |
|
| 1176 | + $to_cache[$key] = $term->data; |
|
| 1177 | 1177 | } |
| 1178 | - wp_cache_add( $post->ID, $to_cache, $taxonomy . '_relationships' ); |
|
| 1178 | + wp_cache_add($post->ID, $to_cache, $taxonomy.'_relationships'); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - if ( ! is_wp_error( $terms ) ) { |
|
| 1183 | - $terms = array_map( 'get_term', $terms ); |
|
| 1182 | + if ( ! is_wp_error($terms)) { |
|
| 1183 | + $terms = array_map('get_term', $terms); |
|
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | 1186 | /** |
@@ -1192,9 +1192,9 @@ discard block |
||
| 1192 | 1192 | * @param int $post_id Post ID. |
| 1193 | 1193 | * @param string $taxonomy Name of the taxonomy. |
| 1194 | 1194 | */ |
| 1195 | - $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); |
|
| 1195 | + $terms = apply_filters('get_the_terms', $terms, $post->ID, $taxonomy); |
|
| 1196 | 1196 | |
| 1197 | - if ( empty( $terms ) ) |
|
| 1197 | + if (empty($terms)) |
|
| 1198 | 1198 | return false; |
| 1199 | 1199 | |
| 1200 | 1200 | return $terms; |
@@ -1212,23 +1212,23 @@ discard block |
||
| 1212 | 1212 | * @param string $after Optional. After list. |
| 1213 | 1213 | * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure. |
| 1214 | 1214 | */ |
| 1215 | -function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
|
| 1216 | - $terms = get_the_terms( $id, $taxonomy ); |
|
| 1215 | +function get_the_term_list($id, $taxonomy, $before = '', $sep = '', $after = '') { |
|
| 1216 | + $terms = get_the_terms($id, $taxonomy); |
|
| 1217 | 1217 | |
| 1218 | - if ( is_wp_error( $terms ) ) |
|
| 1218 | + if (is_wp_error($terms)) |
|
| 1219 | 1219 | return $terms; |
| 1220 | 1220 | |
| 1221 | - if ( empty( $terms ) ) |
|
| 1221 | + if (empty($terms)) |
|
| 1222 | 1222 | return false; |
| 1223 | 1223 | |
| 1224 | 1224 | $links = array(); |
| 1225 | 1225 | |
| 1226 | - foreach ( $terms as $term ) { |
|
| 1227 | - $link = get_term_link( $term, $taxonomy ); |
|
| 1228 | - if ( is_wp_error( $link ) ) { |
|
| 1226 | + foreach ($terms as $term) { |
|
| 1227 | + $link = get_term_link($term, $taxonomy); |
|
| 1228 | + if (is_wp_error($link)) { |
|
| 1229 | 1229 | return $link; |
| 1230 | 1230 | } |
| 1231 | - $links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; |
|
| 1231 | + $links[] = '<a href="'.esc_url($link).'" rel="tag">'.$term->name.'</a>'; |
|
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | /** |
@@ -1241,9 +1241,9 @@ discard block |
||
| 1241 | 1241 | * |
| 1242 | 1242 | * @param array $links An array of term links. |
| 1243 | 1243 | */ |
| 1244 | - $term_links = apply_filters( "term_links-$taxonomy", $links ); |
|
| 1244 | + $term_links = apply_filters("term_links-$taxonomy", $links); |
|
| 1245 | 1245 | |
| 1246 | - return $before . join( $sep, $term_links ) . $after; |
|
| 1246 | + return $before.join($sep, $term_links).$after; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1258,10 +1258,10 @@ discard block |
||
| 1258 | 1258 | * @param string $after Optional. After list. |
| 1259 | 1259 | * @return false|void False on WordPress error. |
| 1260 | 1260 | */ |
| 1261 | -function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
|
| 1262 | - $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
|
| 1261 | +function the_terms($id, $taxonomy, $before = '', $sep = ', ', $after = '') { |
|
| 1262 | + $term_list = get_the_term_list($id, $taxonomy, $before, $sep, $after); |
|
| 1263 | 1263 | |
| 1264 | - if ( is_wp_error( $term_list ) ) |
|
| 1264 | + if (is_wp_error($term_list)) |
|
| 1265 | 1265 | return false; |
| 1266 | 1266 | |
| 1267 | 1267 | /** |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | * @param string $sep String to use between the terms. |
| 1276 | 1276 | * @param string $after String to use after the terms. |
| 1277 | 1277 | */ |
| 1278 | - echo apply_filters( 'the_terms', $term_list, $taxonomy, $before, $sep, $after ); |
|
| 1278 | + echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after); |
|
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | /** |
@@ -1287,8 +1287,8 @@ discard block |
||
| 1287 | 1287 | * @param int|object $post Optional. Post to check instead of the current post. |
| 1288 | 1288 | * @return bool True if the current post has any of the given categories (or any category, if no category specified). |
| 1289 | 1289 | */ |
| 1290 | -function has_category( $category = '', $post = null ) { |
|
| 1291 | - return has_term( $category, 'category', $post ); |
|
| 1290 | +function has_category($category = '', $post = null) { |
|
| 1291 | + return has_term($category, 'category', $post); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | /** |
@@ -1308,8 +1308,8 @@ discard block |
||
| 1308 | 1308 | * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0) |
| 1309 | 1309 | * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). |
| 1310 | 1310 | */ |
| 1311 | -function has_tag( $tag = '', $post = null ) { |
|
| 1312 | - return has_term( $tag, 'post_tag', $post ); |
|
| 1311 | +function has_tag($tag = '', $post = null) { |
|
| 1312 | + return has_term($tag, 'post_tag', $post); |
|
| 1313 | 1313 | } |
| 1314 | 1314 | |
| 1315 | 1315 | /** |
@@ -1326,14 +1326,14 @@ discard block |
||
| 1326 | 1326 | * @param int|object $post Optional. Post to check instead of the current post. |
| 1327 | 1327 | * @return bool True if the current post has any of the given tags (or any tag, if no tag specified). |
| 1328 | 1328 | */ |
| 1329 | -function has_term( $term = '', $taxonomy = '', $post = null ) { |
|
| 1329 | +function has_term($term = '', $taxonomy = '', $post = null) { |
|
| 1330 | 1330 | $post = get_post($post); |
| 1331 | 1331 | |
| 1332 | - if ( !$post ) |
|
| 1332 | + if ( ! $post) |
|
| 1333 | 1333 | return false; |
| 1334 | 1334 | |
| 1335 | - $r = is_object_in_term( $post->ID, $taxonomy, $term ); |
|
| 1336 | - if ( is_wp_error( $r ) ) |
|
| 1335 | + $r = is_object_in_term($post->ID, $taxonomy, $term); |
|
| 1336 | + if (is_wp_error($r)) |
|
| 1337 | 1337 | return false; |
| 1338 | 1338 | |
| 1339 | 1339 | return $r; |
@@ -17,13 +17,15 @@ discard block |
||
| 17 | 17 | * @return string Link on success, empty string if category does not exist. |
| 18 | 18 | */ |
| 19 | 19 | function get_category_link( $category ) { |
| 20 | - if ( ! is_object( $category ) ) |
|
| 21 | - $category = (int) $category; |
|
| 20 | + if ( ! is_object( $category ) ) { |
|
| 21 | + $category = (int) $category; |
|
| 22 | + } |
|
| 22 | 23 | |
| 23 | 24 | $category = get_term_link( $category, 'category' ); |
| 24 | 25 | |
| 25 | - if ( is_wp_error( $category ) ) |
|
| 26 | - return ''; |
|
| 26 | + if ( is_wp_error( $category ) ) { |
|
| 27 | + return ''; |
|
| 28 | + } |
|
| 27 | 29 | |
| 28 | 30 | return $category; |
| 29 | 31 | } |
@@ -43,23 +45,26 @@ discard block |
||
| 43 | 45 | function get_category_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { |
| 44 | 46 | $chain = ''; |
| 45 | 47 | $parent = get_term( $id, 'category' ); |
| 46 | - if ( is_wp_error( $parent ) ) |
|
| 47 | - return $parent; |
|
| 48 | + if ( is_wp_error( $parent ) ) { |
|
| 49 | + return $parent; |
|
| 50 | + } |
|
| 48 | 51 | |
| 49 | - if ( $nicename ) |
|
| 50 | - $name = $parent->slug; |
|
| 51 | - else |
|
| 52 | - $name = $parent->name; |
|
| 52 | + if ( $nicename ) { |
|
| 53 | + $name = $parent->slug; |
|
| 54 | + } else { |
|
| 55 | + $name = $parent->name; |
|
| 56 | + } |
|
| 53 | 57 | |
| 54 | 58 | if ( $parent->parent && ( $parent->parent != $parent->term_id ) && !in_array( $parent->parent, $visited ) ) { |
| 55 | 59 | $visited[] = $parent->parent; |
| 56 | 60 | $chain .= get_category_parents( $parent->parent, $link, $separator, $nicename, $visited ); |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | - if ( $link ) |
|
| 60 | - $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 61 | - else |
|
| 62 | - $chain .= $name.$separator; |
|
| 63 | + if ( $link ) { |
|
| 64 | + $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">'.$name.'</a>' . $separator; |
|
| 65 | + } else { |
|
| 66 | + $chain .= $name.$separator; |
|
| 67 | + } |
|
| 63 | 68 | return $chain; |
| 64 | 69 | } |
| 65 | 70 | |
@@ -78,8 +83,9 @@ discard block |
||
| 78 | 83 | */ |
| 79 | 84 | function get_the_category( $id = false ) { |
| 80 | 85 | $categories = get_the_terms( $id, 'category' ); |
| 81 | - if ( ! $categories || is_wp_error( $categories ) ) |
|
| 82 | - $categories = array(); |
|
| 86 | + if ( ! $categories || is_wp_error( $categories ) ) { |
|
| 87 | + $categories = array(); |
|
| 88 | + } |
|
| 83 | 89 | |
| 84 | 90 | $categories = array_values( $categories ); |
| 85 | 91 | |
@@ -130,13 +136,14 @@ discard block |
||
| 130 | 136 | * @return int |
| 131 | 137 | */ |
| 132 | 138 | function _usort_terms_by_ID( $a, $b ) { |
| 133 | - if ( $a->term_id > $b->term_id ) |
|
| 134 | - return 1; |
|
| 135 | - elseif ( $a->term_id < $b->term_id ) |
|
| 136 | - return -1; |
|
| 137 | - else |
|
| 138 | - return 0; |
|
| 139 | -} |
|
| 139 | + if ( $a->term_id > $b->term_id ) { |
|
| 140 | + return 1; |
|
| 141 | + } elseif ( $a->term_id < $b->term_id ) { |
|
| 142 | + return -1; |
|
| 143 | + } else { |
|
| 144 | + return 0; |
|
| 145 | + } |
|
| 146 | + } |
|
| 140 | 147 | |
| 141 | 148 | /** |
| 142 | 149 | * Retrieve category name based on category ID. |
@@ -150,8 +157,9 @@ discard block |
||
| 150 | 157 | $cat_ID = (int) $cat_ID; |
| 151 | 158 | $category = get_term( $cat_ID, 'category' ); |
| 152 | 159 | |
| 153 | - if ( is_wp_error( $category ) ) |
|
| 154 | - return $category; |
|
| 160 | + if ( is_wp_error( $category ) ) { |
|
| 161 | + return $category; |
|
| 162 | + } |
|
| 155 | 163 | |
| 156 | 164 | return ( $category ) ? $category->name : ''; |
| 157 | 165 | } |
@@ -200,14 +208,16 @@ discard block |
||
| 200 | 208 | $thelist .= "\n\t<li>"; |
| 201 | 209 | switch ( strtolower( $parents ) ) { |
| 202 | 210 | case 'multiple': |
| 203 | - if ( $category->parent ) |
|
| 204 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 211 | + if ( $category->parent ) { |
|
| 212 | + $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 213 | + } |
|
| 205 | 214 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a></li>'; |
| 206 | 215 | break; |
| 207 | 216 | case 'single': |
| 208 | 217 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
| 209 | - if ( $category->parent ) |
|
| 210 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 218 | + if ( $category->parent ) { |
|
| 219 | + $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 220 | + } |
|
| 211 | 221 | $thelist .= $category->name.'</a></li>'; |
| 212 | 222 | break; |
| 213 | 223 | case '': |
@@ -219,18 +229,21 @@ discard block |
||
| 219 | 229 | } else { |
| 220 | 230 | $i = 0; |
| 221 | 231 | foreach ( $categories as $category ) { |
| 222 | - if ( 0 < $i ) |
|
| 223 | - $thelist .= $separator; |
|
| 232 | + if ( 0 < $i ) { |
|
| 233 | + $thelist .= $separator; |
|
| 234 | + } |
|
| 224 | 235 | switch ( strtolower( $parents ) ) { |
| 225 | 236 | case 'multiple': |
| 226 | - if ( $category->parent ) |
|
| 227 | - $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 237 | + if ( $category->parent ) { |
|
| 238 | + $thelist .= get_category_parents( $category->parent, true, $separator ); |
|
| 239 | + } |
|
| 228 | 240 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>' . $category->name.'</a>'; |
| 229 | 241 | break; |
| 230 | 242 | case 'single': |
| 231 | 243 | $thelist .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" ' . $rel . '>'; |
| 232 | - if ( $category->parent ) |
|
| 233 | - $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 244 | + if ( $category->parent ) { |
|
| 245 | + $thelist .= get_category_parents( $category->parent, false, $separator ); |
|
| 246 | + } |
|
| 234 | 247 | $thelist .= "$category->name</a>"; |
| 235 | 248 | break; |
| 236 | 249 | case '': |
@@ -273,8 +286,9 @@ discard block |
||
| 273 | 286 | * @return bool True if the current post is in any of the given categories. |
| 274 | 287 | */ |
| 275 | 288 | function in_category( $category, $post = null ) { |
| 276 | - if ( empty( $category ) ) |
|
| 277 | - return false; |
|
| 289 | + if ( empty( $category ) ) { |
|
| 290 | + return false; |
|
| 291 | + } |
|
| 278 | 292 | |
| 279 | 293 | return has_category( $category, $post ); |
| 280 | 294 | } |
@@ -552,8 +566,9 @@ discard block |
||
| 552 | 566 | |
| 553 | 567 | $r = wp_parse_args( $args, $defaults ); |
| 554 | 568 | |
| 555 | - if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) |
|
| 556 | - $r['pad_counts'] = true; |
|
| 569 | + if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] ) { |
|
| 570 | + $r['pad_counts'] = true; |
|
| 571 | + } |
|
| 557 | 572 | |
| 558 | 573 | // Descendants of exclusions should be excluded too. |
| 559 | 574 | if ( true == $r['hierarchical'] ) { |
@@ -571,8 +586,9 @@ discard block |
||
| 571 | 586 | $r['exclude'] = ''; |
| 572 | 587 | } |
| 573 | 588 | |
| 574 | - if ( ! isset( $r['class'] ) ) |
|
| 575 | - $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 589 | + if ( ! isset( $r['class'] ) ) { |
|
| 590 | + $r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy']; |
|
| 591 | + } |
|
| 576 | 592 | |
| 577 | 593 | if ( ! taxonomy_exists( $r['taxonomy'] ) ) { |
| 578 | 594 | return false; |
@@ -646,8 +662,9 @@ discard block |
||
| 646 | 662 | $output .= walk_category_tree( $categories, $depth, $r ); |
| 647 | 663 | } |
| 648 | 664 | |
| 649 | - if ( $r['title_li'] && 'list' == $r['style'] ) |
|
| 650 | - $output .= '</ul></li>'; |
|
| 665 | + if ( $r['title_li'] && 'list' == $r['style'] ) { |
|
| 666 | + $output .= '</ul></li>'; |
|
| 667 | + } |
|
| 651 | 668 | |
| 652 | 669 | /** |
| 653 | 670 | * Filter the HTML output of a taxonomy list. |
@@ -711,16 +728,19 @@ discard block |
||
| 711 | 728 | |
| 712 | 729 | $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags |
| 713 | 730 | |
| 714 | - if ( empty( $tags ) || is_wp_error( $tags ) ) |
|
| 715 | - return; |
|
| 731 | + if ( empty( $tags ) || is_wp_error( $tags ) ) { |
|
| 732 | + return; |
|
| 733 | + } |
|
| 716 | 734 | |
| 717 | 735 | foreach ( $tags as $key => $tag ) { |
| 718 | - if ( 'edit' == $args['link'] ) |
|
| 719 | - $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 720 | - else |
|
| 721 | - $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 722 | - if ( is_wp_error( $link ) ) |
|
| 723 | - return; |
|
| 736 | + if ( 'edit' == $args['link'] ) { |
|
| 737 | + $link = get_edit_term_link( $tag->term_id, $tag->taxonomy, $args['post_type'] ); |
|
| 738 | + } else { |
|
| 739 | + $link = get_term_link( intval($tag->term_id), $tag->taxonomy ); |
|
| 740 | + } |
|
| 741 | + if ( is_wp_error( $link ) ) { |
|
| 742 | + return; |
|
| 743 | + } |
|
| 724 | 744 | |
| 725 | 745 | $tags[ $key ]->link = $link; |
| 726 | 746 | $tags[ $key ]->id = $tag->term_id; |
@@ -738,8 +758,9 @@ discard block |
||
| 738 | 758 | */ |
| 739 | 759 | $return = apply_filters( 'wp_tag_cloud', $return, $args ); |
| 740 | 760 | |
| 741 | - if ( 'array' == $args['format'] || empty($args['echo']) ) |
|
| 742 | - return $return; |
|
| 761 | + if ( 'array' == $args['format'] || empty($args['echo']) ) { |
|
| 762 | + return $return; |
|
| 763 | + } |
|
| 743 | 764 | |
| 744 | 765 | echo $return; |
| 745 | 766 | } |
@@ -856,8 +877,9 @@ discard block |
||
| 856 | 877 | } |
| 857 | 878 | } |
| 858 | 879 | |
| 859 | - if ( $args['number'] > 0 ) |
|
| 860 | - $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 880 | + if ( $args['number'] > 0 ) { |
|
| 881 | + $tags = array_slice( $tags, 0, $args['number'] ); |
|
| 882 | + } |
|
| 861 | 883 | |
| 862 | 884 | $counts = array(); |
| 863 | 885 | $real_counts = array(); // For the alt tag |
@@ -868,11 +890,13 @@ discard block |
||
| 868 | 890 | |
| 869 | 891 | $min_count = min( $counts ); |
| 870 | 892 | $spread = max( $counts ) - $min_count; |
| 871 | - if ( $spread <= 0 ) |
|
| 872 | - $spread = 1; |
|
| 893 | + if ( $spread <= 0 ) { |
|
| 894 | + $spread = 1; |
|
| 895 | + } |
|
| 873 | 896 | $font_spread = $args['largest'] - $args['smallest']; |
| 874 | - if ( $font_spread < 0 ) |
|
| 875 | - $font_spread = 1; |
|
| 897 | + if ( $font_spread < 0 ) { |
|
| 898 | + $font_spread = 1; |
|
| 899 | + } |
|
| 876 | 900 | $font_step = $font_spread / $spread; |
| 877 | 901 | |
| 878 | 902 | // Assemble the data that will be used to generate the tag cloud markup. |
@@ -950,11 +974,10 @@ discard block |
||
| 950 | 974 | * @param array $args An array of wp_generate_tag_cloud() arguments. |
| 951 | 975 | */ |
| 952 | 976 | return apply_filters( 'wp_generate_tag_cloud', $return, $tags, $args ); |
| 977 | + } else { |
|
| 978 | + return $return; |
|
| 979 | + } |
|
| 953 | 980 | } |
| 954 | - |
|
| 955 | - else |
|
| 956 | - return $return; |
|
| 957 | -} |
|
| 958 | 981 | |
| 959 | 982 | /** |
| 960 | 983 | * Serves as a callback for comparing objects based on name. |
@@ -1045,13 +1068,15 @@ discard block |
||
| 1045 | 1068 | * @return string Link on success, empty string if tag does not exist. |
| 1046 | 1069 | */ |
| 1047 | 1070 | function get_tag_link( $tag ) { |
| 1048 | - if ( ! is_object( $tag ) ) |
|
| 1049 | - $tag = (int) $tag; |
|
| 1071 | + if ( ! is_object( $tag ) ) { |
|
| 1072 | + $tag = (int) $tag; |
|
| 1073 | + } |
|
| 1050 | 1074 | |
| 1051 | 1075 | $tag = get_term_link( $tag, 'post_tag' ); |
| 1052 | 1076 | |
| 1053 | - if ( is_wp_error( $tag ) ) |
|
| 1054 | - return ''; |
|
| 1077 | + if ( is_wp_error( $tag ) ) { |
|
| 1078 | + return ''; |
|
| 1079 | + } |
|
| 1055 | 1080 | |
| 1056 | 1081 | return $tag; |
| 1057 | 1082 | } |
@@ -1115,8 +1140,9 @@ discard block |
||
| 1115 | 1140 | * @param string $after Optional. After list. |
| 1116 | 1141 | */ |
| 1117 | 1142 | function the_tags( $before = null, $sep = ', ', $after = '' ) { |
| 1118 | - if ( null === $before ) |
|
| 1119 | - $before = __('Tags: '); |
|
| 1143 | + if ( null === $before ) { |
|
| 1144 | + $before = __('Tags: '); |
|
| 1145 | + } |
|
| 1120 | 1146 | echo get_the_tag_list($before, $sep, $after); |
| 1121 | 1147 | } |
| 1122 | 1148 | |
@@ -1164,8 +1190,9 @@ discard block |
||
| 1164 | 1190 | * or the post does not exist, WP_Error on failure. |
| 1165 | 1191 | */ |
| 1166 | 1192 | function get_the_terms( $post, $taxonomy ) { |
| 1167 | - if ( ! $post = get_post( $post ) ) |
|
| 1168 | - return false; |
|
| 1193 | + if ( ! $post = get_post( $post ) ) { |
|
| 1194 | + return false; |
|
| 1195 | + } |
|
| 1169 | 1196 | |
| 1170 | 1197 | $terms = get_object_term_cache( $post->ID, $taxonomy ); |
| 1171 | 1198 | if ( false === $terms ) { |
@@ -1194,8 +1221,9 @@ discard block |
||
| 1194 | 1221 | */ |
| 1195 | 1222 | $terms = apply_filters( 'get_the_terms', $terms, $post->ID, $taxonomy ); |
| 1196 | 1223 | |
| 1197 | - if ( empty( $terms ) ) |
|
| 1198 | - return false; |
|
| 1224 | + if ( empty( $terms ) ) { |
|
| 1225 | + return false; |
|
| 1226 | + } |
|
| 1199 | 1227 | |
| 1200 | 1228 | return $terms; |
| 1201 | 1229 | } |
@@ -1215,11 +1243,13 @@ discard block |
||
| 1215 | 1243 | function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = '' ) { |
| 1216 | 1244 | $terms = get_the_terms( $id, $taxonomy ); |
| 1217 | 1245 | |
| 1218 | - if ( is_wp_error( $terms ) ) |
|
| 1219 | - return $terms; |
|
| 1246 | + if ( is_wp_error( $terms ) ) { |
|
| 1247 | + return $terms; |
|
| 1248 | + } |
|
| 1220 | 1249 | |
| 1221 | - if ( empty( $terms ) ) |
|
| 1222 | - return false; |
|
| 1250 | + if ( empty( $terms ) ) { |
|
| 1251 | + return false; |
|
| 1252 | + } |
|
| 1223 | 1253 | |
| 1224 | 1254 | $links = array(); |
| 1225 | 1255 | |
@@ -1261,8 +1291,9 @@ discard block |
||
| 1261 | 1291 | function the_terms( $id, $taxonomy, $before = '', $sep = ', ', $after = '' ) { |
| 1262 | 1292 | $term_list = get_the_term_list( $id, $taxonomy, $before, $sep, $after ); |
| 1263 | 1293 | |
| 1264 | - if ( is_wp_error( $term_list ) ) |
|
| 1265 | - return false; |
|
| 1294 | + if ( is_wp_error( $term_list ) ) { |
|
| 1295 | + return false; |
|
| 1296 | + } |
|
| 1266 | 1297 | |
| 1267 | 1298 | /** |
| 1268 | 1299 | * Filter the list of terms to display. |
@@ -1329,12 +1360,14 @@ discard block |
||
| 1329 | 1360 | function has_term( $term = '', $taxonomy = '', $post = null ) { |
| 1330 | 1361 | $post = get_post($post); |
| 1331 | 1362 | |
| 1332 | - if ( !$post ) |
|
| 1333 | - return false; |
|
| 1363 | + if ( !$post ) { |
|
| 1364 | + return false; |
|
| 1365 | + } |
|
| 1334 | 1366 | |
| 1335 | 1367 | $r = is_object_in_term( $post->ID, $taxonomy, $term ); |
| 1336 | - if ( is_wp_error( $r ) ) |
|
| 1337 | - return false; |
|
| 1368 | + if ( is_wp_error( $r ) ) { |
|
| 1369 | + return false; |
|
| 1370 | + } |
|
| 1338 | 1371 | |
| 1339 | 1372 | return $r; |
| 1340 | 1373 | } |
@@ -1048,6 +1048,12 @@ |
||
| 1048 | 1048 | self::__construct(); |
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | + /** |
|
| 1052 | + * @param string $method |
|
| 1053 | + * @param string $callback |
|
| 1054 | + * @param string[] $args |
|
| 1055 | + * @param string $help |
|
| 1056 | + */ |
|
| 1051 | 1057 | function addCallback($method, $callback, $args, $help) |
| 1052 | 1058 | { |
| 1053 | 1059 | $this->callbacks[$method] = $callback; |
@@ -534,17 +534,19 @@ |
||
| 534 | 534 | function output($xml) |
| 535 | 535 | { |
| 536 | 536 | $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
| 537 | - if ($charset) |
|
| 538 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | - else |
|
| 540 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 537 | + if ($charset) { |
|
| 538 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 539 | + } else { |
|
| 540 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 541 | + } |
|
| 541 | 542 | $length = strlen($xml); |
| 542 | 543 | header('Connection: close'); |
| 543 | 544 | header('Content-Length: '.$length); |
| 544 | - if ($charset) |
|
| 545 | - header('Content-Type: text/xml; charset='.$charset); |
|
| 546 | - else |
|
| 547 | - header('Content-Type: text/xml'); |
|
| 545 | + if ($charset) { |
|
| 546 | + header('Content-Type: text/xml; charset='.$charset); |
|
| 547 | + } else { |
|
| 548 | + header('Content-Type: text/xml'); |
|
| 549 | + } |
|
| 548 | 550 | header('Date: '.date('r')); |
| 549 | 551 | echo $xml; |
| 550 | 552 | exit; |
@@ -1,43 +1,43 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * IXR - The Incutio XML-RPC Library |
|
| 4 | - * |
|
| 5 | - * Copyright (c) 2010, Incutio Ltd. |
|
| 6 | - * All rights reserved. |
|
| 7 | - * |
|
| 8 | - * Redistribution and use in source and binary forms, with or without |
|
| 9 | - * modification, are permitted provided that the following conditions are met: |
|
| 10 | - * |
|
| 11 | - * - Redistributions of source code must retain the above copyright notice, |
|
| 12 | - * this list of conditions and the following disclaimer. |
|
| 13 | - * - Redistributions in binary form must reproduce the above copyright |
|
| 14 | - * notice, this list of conditions and the following disclaimer in the |
|
| 15 | - * documentation and/or other materials provided with the distribution. |
|
| 16 | - * - Neither the name of Incutio Ltd. nor the names of its contributors |
|
| 17 | - * may be used to endorse or promote products derived from this software |
|
| 18 | - * without specific prior written permission. |
|
| 19 | - * |
|
| 20 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 21 | - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 22 | - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 23 | - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
| 24 | - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 25 | - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 26 | - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 27 | - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 28 | - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 29 | - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
| 30 | - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 31 | - * |
|
| 32 | - * @package IXR |
|
| 33 | - * @since 1.5.0 |
|
| 34 | - * |
|
| 35 | - * @copyright Incutio Ltd 2010 (http://www.incutio.com) |
|
| 36 | - * @version 1.7.4 7th September 2010 |
|
| 37 | - * @author Simon Willison |
|
| 38 | - * @link http://scripts.incutio.com/xmlrpc/ Site/manual |
|
| 39 | - * @license http://www.opensource.org/licenses/bsd-license.php BSD |
|
| 40 | - */ |
|
| 3 | + * IXR - The Incutio XML-RPC Library |
|
| 4 | + * |
|
| 5 | + * Copyright (c) 2010, Incutio Ltd. |
|
| 6 | + * All rights reserved. |
|
| 7 | + * |
|
| 8 | + * Redistribution and use in source and binary forms, with or without |
|
| 9 | + * modification, are permitted provided that the following conditions are met: |
|
| 10 | + * |
|
| 11 | + * - Redistributions of source code must retain the above copyright notice, |
|
| 12 | + * this list of conditions and the following disclaimer. |
|
| 13 | + * - Redistributions in binary form must reproduce the above copyright |
|
| 14 | + * notice, this list of conditions and the following disclaimer in the |
|
| 15 | + * documentation and/or other materials provided with the distribution. |
|
| 16 | + * - Neither the name of Incutio Ltd. nor the names of its contributors |
|
| 17 | + * may be used to endorse or promote products derived from this software |
|
| 18 | + * without specific prior written permission. |
|
| 19 | + * |
|
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
|
| 21 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
|
| 22 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
| 23 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
|
| 24 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
| 25 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
| 26 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
| 27 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
| 28 | + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
| 29 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
|
| 30 | + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
| 31 | + * |
|
| 32 | + * @package IXR |
|
| 33 | + * @since 1.5.0 |
|
| 34 | + * |
|
| 35 | + * @copyright Incutio Ltd 2010 (http://www.incutio.com) |
|
| 36 | + * @version 1.7.4 7th September 2010 |
|
| 37 | + * @author Simon Willison |
|
| 38 | + * @link http://scripts.incutio.com/xmlrpc/ Site/manual |
|
| 39 | + * @license http://www.opensource.org/licenses/bsd-license.php BSD |
|
| 40 | + */ |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * IXR_Value |
@@ -46,31 +46,31 @@ discard block |
||
| 46 | 46 | * @since 1.5.0 |
| 47 | 47 | */ |
| 48 | 48 | class IXR_Value { |
| 49 | - var $data; |
|
| 50 | - var $type; |
|
| 49 | + var $data; |
|
| 50 | + var $type; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * PHP5 constructor. |
| 54 | 54 | */ |
| 55 | 55 | function __construct( $data, $type = false ) |
| 56 | - { |
|
| 57 | - $this->data = $data; |
|
| 58 | - if (!$type) { |
|
| 59 | - $type = $this->calculateType(); |
|
| 60 | - } |
|
| 61 | - $this->type = $type; |
|
| 62 | - if ($type == 'struct') { |
|
| 63 | - // Turn all the values in the array in to new IXR_Value objects |
|
| 64 | - foreach ($this->data as $key => $value) { |
|
| 65 | - $this->data[$key] = new IXR_Value($value); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - if ($type == 'array') { |
|
| 69 | - for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
| 70 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 56 | + { |
|
| 57 | + $this->data = $data; |
|
| 58 | + if (!$type) { |
|
| 59 | + $type = $this->calculateType(); |
|
| 60 | + } |
|
| 61 | + $this->type = $type; |
|
| 62 | + if ($type == 'struct') { |
|
| 63 | + // Turn all the values in the array in to new IXR_Value objects |
|
| 64 | + foreach ($this->data as $key => $value) { |
|
| 65 | + $this->data[$key] = new IXR_Value($value); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + if ($type == 'array') { |
|
| 69 | + for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
| 70 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | 75 | /** |
| 76 | 76 | * PHP4 constructor. |
@@ -79,102 +79,102 @@ discard block |
||
| 79 | 79 | self::__construct( $data, $type ); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - function calculateType() |
|
| 83 | - { |
|
| 84 | - if ($this->data === true || $this->data === false) { |
|
| 85 | - return 'boolean'; |
|
| 86 | - } |
|
| 87 | - if (is_integer($this->data)) { |
|
| 88 | - return 'int'; |
|
| 89 | - } |
|
| 90 | - if (is_double($this->data)) { |
|
| 91 | - return 'double'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Deal with IXR object types base64 and date |
|
| 95 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 96 | - return 'date'; |
|
| 97 | - } |
|
| 98 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 99 | - return 'base64'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // If it is a normal PHP object convert it in to a struct |
|
| 103 | - if (is_object($this->data)) { |
|
| 104 | - $this->data = get_object_vars($this->data); |
|
| 105 | - return 'struct'; |
|
| 106 | - } |
|
| 107 | - if (!is_array($this->data)) { |
|
| 108 | - return 'string'; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // We have an array - is it an array or a struct? |
|
| 112 | - if ($this->isStruct($this->data)) { |
|
| 113 | - return 'struct'; |
|
| 114 | - } else { |
|
| 115 | - return 'array'; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - function getXml() |
|
| 120 | - { |
|
| 121 | - // Return XML for this value |
|
| 122 | - switch ($this->type) { |
|
| 123 | - case 'boolean': |
|
| 124 | - return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
| 125 | - break; |
|
| 126 | - case 'int': |
|
| 127 | - return '<int>'.$this->data.'</int>'; |
|
| 128 | - break; |
|
| 129 | - case 'double': |
|
| 130 | - return '<double>'.$this->data.'</double>'; |
|
| 131 | - break; |
|
| 132 | - case 'string': |
|
| 133 | - return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
| 134 | - break; |
|
| 135 | - case 'array': |
|
| 136 | - $return = '<array><data>'."\n"; |
|
| 137 | - foreach ($this->data as $item) { |
|
| 138 | - $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
| 139 | - } |
|
| 140 | - $return .= '</data></array>'; |
|
| 141 | - return $return; |
|
| 142 | - break; |
|
| 143 | - case 'struct': |
|
| 144 | - $return = '<struct>'."\n"; |
|
| 145 | - foreach ($this->data as $name => $value) { |
|
| 82 | + function calculateType() |
|
| 83 | + { |
|
| 84 | + if ($this->data === true || $this->data === false) { |
|
| 85 | + return 'boolean'; |
|
| 86 | + } |
|
| 87 | + if (is_integer($this->data)) { |
|
| 88 | + return 'int'; |
|
| 89 | + } |
|
| 90 | + if (is_double($this->data)) { |
|
| 91 | + return 'double'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Deal with IXR object types base64 and date |
|
| 95 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 96 | + return 'date'; |
|
| 97 | + } |
|
| 98 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 99 | + return 'base64'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // If it is a normal PHP object convert it in to a struct |
|
| 103 | + if (is_object($this->data)) { |
|
| 104 | + $this->data = get_object_vars($this->data); |
|
| 105 | + return 'struct'; |
|
| 106 | + } |
|
| 107 | + if (!is_array($this->data)) { |
|
| 108 | + return 'string'; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // We have an array - is it an array or a struct? |
|
| 112 | + if ($this->isStruct($this->data)) { |
|
| 113 | + return 'struct'; |
|
| 114 | + } else { |
|
| 115 | + return 'array'; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + function getXml() |
|
| 120 | + { |
|
| 121 | + // Return XML for this value |
|
| 122 | + switch ($this->type) { |
|
| 123 | + case 'boolean': |
|
| 124 | + return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
| 125 | + break; |
|
| 126 | + case 'int': |
|
| 127 | + return '<int>'.$this->data.'</int>'; |
|
| 128 | + break; |
|
| 129 | + case 'double': |
|
| 130 | + return '<double>'.$this->data.'</double>'; |
|
| 131 | + break; |
|
| 132 | + case 'string': |
|
| 133 | + return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
| 134 | + break; |
|
| 135 | + case 'array': |
|
| 136 | + $return = '<array><data>'."\n"; |
|
| 137 | + foreach ($this->data as $item) { |
|
| 138 | + $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
| 139 | + } |
|
| 140 | + $return .= '</data></array>'; |
|
| 141 | + return $return; |
|
| 142 | + break; |
|
| 143 | + case 'struct': |
|
| 144 | + $return = '<struct>'."\n"; |
|
| 145 | + foreach ($this->data as $name => $value) { |
|
| 146 | 146 | $name = htmlspecialchars($name); |
| 147 | - $return .= " <member><name>$name</name><value>"; |
|
| 148 | - $return .= $value->getXml()."</value></member>\n"; |
|
| 149 | - } |
|
| 150 | - $return .= '</struct>'; |
|
| 151 | - return $return; |
|
| 152 | - break; |
|
| 153 | - case 'date': |
|
| 154 | - case 'base64': |
|
| 155 | - return $this->data->getXml(); |
|
| 156 | - break; |
|
| 157 | - } |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Checks whether or not the supplied array is a struct or not |
|
| 163 | - * |
|
| 164 | - * @param array $array |
|
| 165 | - * @return bool |
|
| 166 | - */ |
|
| 167 | - function isStruct($array) |
|
| 168 | - { |
|
| 169 | - $expected = 0; |
|
| 170 | - foreach ($array as $key => $value) { |
|
| 171 | - if ((string)$key != (string)$expected) { |
|
| 172 | - return true; |
|
| 173 | - } |
|
| 174 | - $expected++; |
|
| 175 | - } |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 147 | + $return .= " <member><name>$name</name><value>"; |
|
| 148 | + $return .= $value->getXml()."</value></member>\n"; |
|
| 149 | + } |
|
| 150 | + $return .= '</struct>'; |
|
| 151 | + return $return; |
|
| 152 | + break; |
|
| 153 | + case 'date': |
|
| 154 | + case 'base64': |
|
| 155 | + return $this->data->getXml(); |
|
| 156 | + break; |
|
| 157 | + } |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Checks whether or not the supplied array is a struct or not |
|
| 163 | + * |
|
| 164 | + * @param array $array |
|
| 165 | + * @return bool |
|
| 166 | + */ |
|
| 167 | + function isStruct($array) |
|
| 168 | + { |
|
| 169 | + $expected = 0; |
|
| 170 | + foreach ($array as $key => $value) { |
|
| 171 | + if ((string)$key != (string)$expected) { |
|
| 172 | + return true; |
|
| 173 | + } |
|
| 174 | + $expected++; |
|
| 175 | + } |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -186,31 +186,31 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | class IXR_Message |
| 188 | 188 | { |
| 189 | - var $message; |
|
| 190 | - var $messageType; // methodCall / methodResponse / fault |
|
| 191 | - var $faultCode; |
|
| 192 | - var $faultString; |
|
| 193 | - var $methodName; |
|
| 194 | - var $params; |
|
| 195 | - |
|
| 196 | - // Current variable stacks |
|
| 197 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | - var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 199 | - var $_currentStructName = array(); // A stack as well |
|
| 200 | - var $_param; |
|
| 201 | - var $_value; |
|
| 202 | - var $_currentTag; |
|
| 203 | - var $_currentTagContents; |
|
| 204 | - // The XML parser |
|
| 205 | - var $_parser; |
|
| 189 | + var $message; |
|
| 190 | + var $messageType; // methodCall / methodResponse / fault |
|
| 191 | + var $faultCode; |
|
| 192 | + var $faultString; |
|
| 193 | + var $methodName; |
|
| 194 | + var $params; |
|
| 195 | + |
|
| 196 | + // Current variable stacks |
|
| 197 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | + var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 199 | + var $_currentStructName = array(); // A stack as well |
|
| 200 | + var $_param; |
|
| 201 | + var $_value; |
|
| 202 | + var $_currentTag; |
|
| 203 | + var $_currentTagContents; |
|
| 204 | + // The XML parser |
|
| 205 | + var $_parser; |
|
| 206 | 206 | |
| 207 | 207 | /** |
| 208 | 208 | * PHP5 constructor. |
| 209 | 209 | */ |
| 210 | - function __construct( $message ) |
|
| 211 | - { |
|
| 212 | - $this->message =& $message; |
|
| 213 | - } |
|
| 210 | + function __construct( $message ) |
|
| 211 | + { |
|
| 212 | + $this->message =& $message; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * PHP4 constructor. |
@@ -219,190 +219,190 @@ discard block |
||
| 219 | 219 | self::__construct( $message ); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - function parse() |
|
| 223 | - { |
|
| 224 | - // first remove the XML declaration |
|
| 225 | - // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
| 226 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | - if ( '' == $this->message ) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Then remove the DOCTYPE |
|
| 233 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | - if ( '' == $this->message ) { |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - // Check that the root tag is valid |
|
| 240 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // Bail if there are too many elements to parse |
|
| 249 | - $element_limit = 30000; |
|
| 250 | - if ( function_exists( 'apply_filters' ) ) { |
|
| 251 | - /** |
|
| 252 | - * Filter the number of elements to parse in an XML-RPC response. |
|
| 253 | - * |
|
| 254 | - * @since 4.0.0 |
|
| 255 | - * |
|
| 256 | - * @param int $element_limit Default elements limit. |
|
| 257 | - */ |
|
| 258 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 259 | - } |
|
| 260 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $this->_parser = xml_parser_create(); |
|
| 265 | - // Set XML parser to take the case of tags in to account |
|
| 266 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 267 | - // Set XML parser callback functions |
|
| 268 | - xml_set_object($this->_parser, $this); |
|
| 269 | - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 270 | - xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 271 | - |
|
| 272 | - // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
| 273 | - $chunk_size = 262144; |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Filter the chunk size that can be used to parse an XML-RPC reponse message. |
|
| 277 | - * |
|
| 278 | - * @since 4.4.0 |
|
| 279 | - * |
|
| 280 | - * @param int $chunk_size Chunk size to parse in bytes. |
|
| 281 | - */ |
|
| 282 | - $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
| 283 | - |
|
| 284 | - $final = false; |
|
| 285 | - do { |
|
| 286 | - if (strlen($this->message) <= $chunk_size) { |
|
| 287 | - $final = true; |
|
| 288 | - } |
|
| 289 | - $part = substr($this->message, 0, $chunk_size); |
|
| 290 | - $this->message = substr($this->message, $chunk_size); |
|
| 291 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
| 292 | - return false; |
|
| 293 | - } |
|
| 294 | - if ($final) { |
|
| 295 | - break; |
|
| 296 | - } |
|
| 297 | - } while (true); |
|
| 298 | - xml_parser_free($this->_parser); |
|
| 299 | - |
|
| 300 | - // Grab the error messages, if any |
|
| 301 | - if ($this->messageType == 'fault') { |
|
| 302 | - $this->faultCode = $this->params[0]['faultCode']; |
|
| 303 | - $this->faultString = $this->params[0]['faultString']; |
|
| 304 | - } |
|
| 305 | - return true; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - function tag_open($parser, $tag, $attr) |
|
| 309 | - { |
|
| 310 | - $this->_currentTagContents = ''; |
|
| 311 | - $this->currentTag = $tag; |
|
| 312 | - switch($tag) { |
|
| 313 | - case 'methodCall': |
|
| 314 | - case 'methodResponse': |
|
| 315 | - case 'fault': |
|
| 316 | - $this->messageType = $tag; |
|
| 317 | - break; |
|
| 318 | - /* Deal with stacks of arrays and structs */ |
|
| 319 | - case 'data': // data is to all intents and puposes more interesting than array |
|
| 320 | - $this->_arraystructstypes[] = 'array'; |
|
| 321 | - $this->_arraystructs[] = array(); |
|
| 322 | - break; |
|
| 323 | - case 'struct': |
|
| 324 | - $this->_arraystructstypes[] = 'struct'; |
|
| 325 | - $this->_arraystructs[] = array(); |
|
| 326 | - break; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - function cdata($parser, $cdata) |
|
| 331 | - { |
|
| 332 | - $this->_currentTagContents .= $cdata; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - function tag_close($parser, $tag) |
|
| 336 | - { |
|
| 337 | - $valueFlag = false; |
|
| 338 | - switch($tag) { |
|
| 339 | - case 'int': |
|
| 340 | - case 'i4': |
|
| 341 | - $value = (int)trim($this->_currentTagContents); |
|
| 342 | - $valueFlag = true; |
|
| 343 | - break; |
|
| 344 | - case 'double': |
|
| 345 | - $value = (double)trim($this->_currentTagContents); |
|
| 346 | - $valueFlag = true; |
|
| 347 | - break; |
|
| 348 | - case 'string': |
|
| 349 | - $value = (string)trim($this->_currentTagContents); |
|
| 350 | - $valueFlag = true; |
|
| 351 | - break; |
|
| 352 | - case 'dateTime.iso8601': |
|
| 353 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 354 | - $valueFlag = true; |
|
| 355 | - break; |
|
| 356 | - case 'value': |
|
| 357 | - // "If no type is indicated, the type is string." |
|
| 358 | - if (trim($this->_currentTagContents) != '') { |
|
| 359 | - $value = (string)$this->_currentTagContents; |
|
| 360 | - $valueFlag = true; |
|
| 361 | - } |
|
| 362 | - break; |
|
| 363 | - case 'boolean': |
|
| 364 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 365 | - $valueFlag = true; |
|
| 366 | - break; |
|
| 367 | - case 'base64': |
|
| 368 | - $value = base64_decode($this->_currentTagContents); |
|
| 369 | - $valueFlag = true; |
|
| 370 | - break; |
|
| 371 | - /* Deal with stacks of arrays and structs */ |
|
| 372 | - case 'data': |
|
| 373 | - case 'struct': |
|
| 374 | - $value = array_pop($this->_arraystructs); |
|
| 375 | - array_pop($this->_arraystructstypes); |
|
| 376 | - $valueFlag = true; |
|
| 377 | - break; |
|
| 378 | - case 'member': |
|
| 379 | - array_pop($this->_currentStructName); |
|
| 380 | - break; |
|
| 381 | - case 'name': |
|
| 382 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 383 | - break; |
|
| 384 | - case 'methodName': |
|
| 385 | - $this->methodName = trim($this->_currentTagContents); |
|
| 386 | - break; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - if ($valueFlag) { |
|
| 390 | - if (count($this->_arraystructs) > 0) { |
|
| 391 | - // Add value to struct or array |
|
| 392 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 393 | - // Add to struct |
|
| 394 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 395 | - } else { |
|
| 396 | - // Add to array |
|
| 397 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 398 | - } |
|
| 399 | - } else { |
|
| 400 | - // Just add as a parameter |
|
| 401 | - $this->params[] = $value; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - $this->_currentTagContents = ''; |
|
| 405 | - } |
|
| 222 | + function parse() |
|
| 223 | + { |
|
| 224 | + // first remove the XML declaration |
|
| 225 | + // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
| 226 | + $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | + $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | + if ( '' == $this->message ) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Then remove the DOCTYPE |
|
| 233 | + $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | + $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | + if ( '' == $this->message ) { |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + // Check that the root tag is valid |
|
| 240 | + $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | + if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // Bail if there are too many elements to parse |
|
| 249 | + $element_limit = 30000; |
|
| 250 | + if ( function_exists( 'apply_filters' ) ) { |
|
| 251 | + /** |
|
| 252 | + * Filter the number of elements to parse in an XML-RPC response. |
|
| 253 | + * |
|
| 254 | + * @since 4.0.0 |
|
| 255 | + * |
|
| 256 | + * @param int $element_limit Default elements limit. |
|
| 257 | + */ |
|
| 258 | + $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 259 | + } |
|
| 260 | + if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $this->_parser = xml_parser_create(); |
|
| 265 | + // Set XML parser to take the case of tags in to account |
|
| 266 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 267 | + // Set XML parser callback functions |
|
| 268 | + xml_set_object($this->_parser, $this); |
|
| 269 | + xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 270 | + xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 271 | + |
|
| 272 | + // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
| 273 | + $chunk_size = 262144; |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Filter the chunk size that can be used to parse an XML-RPC reponse message. |
|
| 277 | + * |
|
| 278 | + * @since 4.4.0 |
|
| 279 | + * |
|
| 280 | + * @param int $chunk_size Chunk size to parse in bytes. |
|
| 281 | + */ |
|
| 282 | + $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
| 283 | + |
|
| 284 | + $final = false; |
|
| 285 | + do { |
|
| 286 | + if (strlen($this->message) <= $chunk_size) { |
|
| 287 | + $final = true; |
|
| 288 | + } |
|
| 289 | + $part = substr($this->message, 0, $chunk_size); |
|
| 290 | + $this->message = substr($this->message, $chunk_size); |
|
| 291 | + if (!xml_parse($this->_parser, $part, $final)) { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 294 | + if ($final) { |
|
| 295 | + break; |
|
| 296 | + } |
|
| 297 | + } while (true); |
|
| 298 | + xml_parser_free($this->_parser); |
|
| 299 | + |
|
| 300 | + // Grab the error messages, if any |
|
| 301 | + if ($this->messageType == 'fault') { |
|
| 302 | + $this->faultCode = $this->params[0]['faultCode']; |
|
| 303 | + $this->faultString = $this->params[0]['faultString']; |
|
| 304 | + } |
|
| 305 | + return true; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + function tag_open($parser, $tag, $attr) |
|
| 309 | + { |
|
| 310 | + $this->_currentTagContents = ''; |
|
| 311 | + $this->currentTag = $tag; |
|
| 312 | + switch($tag) { |
|
| 313 | + case 'methodCall': |
|
| 314 | + case 'methodResponse': |
|
| 315 | + case 'fault': |
|
| 316 | + $this->messageType = $tag; |
|
| 317 | + break; |
|
| 318 | + /* Deal with stacks of arrays and structs */ |
|
| 319 | + case 'data': // data is to all intents and puposes more interesting than array |
|
| 320 | + $this->_arraystructstypes[] = 'array'; |
|
| 321 | + $this->_arraystructs[] = array(); |
|
| 322 | + break; |
|
| 323 | + case 'struct': |
|
| 324 | + $this->_arraystructstypes[] = 'struct'; |
|
| 325 | + $this->_arraystructs[] = array(); |
|
| 326 | + break; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + function cdata($parser, $cdata) |
|
| 331 | + { |
|
| 332 | + $this->_currentTagContents .= $cdata; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + function tag_close($parser, $tag) |
|
| 336 | + { |
|
| 337 | + $valueFlag = false; |
|
| 338 | + switch($tag) { |
|
| 339 | + case 'int': |
|
| 340 | + case 'i4': |
|
| 341 | + $value = (int)trim($this->_currentTagContents); |
|
| 342 | + $valueFlag = true; |
|
| 343 | + break; |
|
| 344 | + case 'double': |
|
| 345 | + $value = (double)trim($this->_currentTagContents); |
|
| 346 | + $valueFlag = true; |
|
| 347 | + break; |
|
| 348 | + case 'string': |
|
| 349 | + $value = (string)trim($this->_currentTagContents); |
|
| 350 | + $valueFlag = true; |
|
| 351 | + break; |
|
| 352 | + case 'dateTime.iso8601': |
|
| 353 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 354 | + $valueFlag = true; |
|
| 355 | + break; |
|
| 356 | + case 'value': |
|
| 357 | + // "If no type is indicated, the type is string." |
|
| 358 | + if (trim($this->_currentTagContents) != '') { |
|
| 359 | + $value = (string)$this->_currentTagContents; |
|
| 360 | + $valueFlag = true; |
|
| 361 | + } |
|
| 362 | + break; |
|
| 363 | + case 'boolean': |
|
| 364 | + $value = (boolean)trim($this->_currentTagContents); |
|
| 365 | + $valueFlag = true; |
|
| 366 | + break; |
|
| 367 | + case 'base64': |
|
| 368 | + $value = base64_decode($this->_currentTagContents); |
|
| 369 | + $valueFlag = true; |
|
| 370 | + break; |
|
| 371 | + /* Deal with stacks of arrays and structs */ |
|
| 372 | + case 'data': |
|
| 373 | + case 'struct': |
|
| 374 | + $value = array_pop($this->_arraystructs); |
|
| 375 | + array_pop($this->_arraystructstypes); |
|
| 376 | + $valueFlag = true; |
|
| 377 | + break; |
|
| 378 | + case 'member': |
|
| 379 | + array_pop($this->_currentStructName); |
|
| 380 | + break; |
|
| 381 | + case 'name': |
|
| 382 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 383 | + break; |
|
| 384 | + case 'methodName': |
|
| 385 | + $this->methodName = trim($this->_currentTagContents); |
|
| 386 | + break; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + if ($valueFlag) { |
|
| 390 | + if (count($this->_arraystructs) > 0) { |
|
| 391 | + // Add value to struct or array |
|
| 392 | + if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 393 | + // Add to struct |
|
| 394 | + $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 395 | + } else { |
|
| 396 | + // Add to array |
|
| 397 | + $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 398 | + } |
|
| 399 | + } else { |
|
| 400 | + // Just add as a parameter |
|
| 401 | + $this->params[] = $value; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + $this->_currentTagContents = ''; |
|
| 405 | + } |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -413,25 +413,25 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | class IXR_Server |
| 415 | 415 | { |
| 416 | - var $data; |
|
| 417 | - var $callbacks = array(); |
|
| 418 | - var $message; |
|
| 419 | - var $capabilities; |
|
| 416 | + var $data; |
|
| 417 | + var $callbacks = array(); |
|
| 418 | + var $message; |
|
| 419 | + var $capabilities; |
|
| 420 | 420 | |
| 421 | 421 | /** |
| 422 | 422 | * PHP5 constructor. |
| 423 | 423 | */ |
| 424 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 425 | - { |
|
| 426 | - $this->setCapabilities(); |
|
| 427 | - if ($callbacks) { |
|
| 428 | - $this->callbacks = $callbacks; |
|
| 429 | - } |
|
| 430 | - $this->setCallbacks(); |
|
| 431 | - if (!$wait) { |
|
| 432 | - $this->serve($data); |
|
| 433 | - } |
|
| 434 | - } |
|
| 424 | + function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 425 | + { |
|
| 426 | + $this->setCapabilities(); |
|
| 427 | + if ($callbacks) { |
|
| 428 | + $this->callbacks = $callbacks; |
|
| 429 | + } |
|
| 430 | + $this->setCallbacks(); |
|
| 431 | + if (!$wait) { |
|
| 432 | + $this->serve($data); |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | 436 | /** |
| 437 | 437 | * PHP4 constructor. |
@@ -440,46 +440,46 @@ discard block |
||
| 440 | 440 | self::__construct( $callbacks, $data, $wait ); |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - function serve($data = false) |
|
| 444 | - { |
|
| 445 | - if (!$data) { |
|
| 446 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
| 447 | - if ( function_exists( 'status_header' ) ) { |
|
| 448 | - status_header( 405 ); // WP #20986 |
|
| 449 | - header( 'Allow: POST' ); |
|
| 450 | - } |
|
| 451 | - header('Content-Type: text/plain'); // merged from WP #9093 |
|
| 452 | - die('XML-RPC server accepts POST requests only.'); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - global $HTTP_RAW_POST_DATA; |
|
| 456 | - if (empty($HTTP_RAW_POST_DATA)) { |
|
| 457 | - // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
| 458 | - $data = file_get_contents('php://input'); |
|
| 459 | - } else { |
|
| 460 | - $data =& $HTTP_RAW_POST_DATA; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - $this->message = new IXR_Message($data); |
|
| 464 | - if (!$this->message->parse()) { |
|
| 465 | - $this->error(-32700, 'parse error. not well formed'); |
|
| 466 | - } |
|
| 467 | - if ($this->message->messageType != 'methodCall') { |
|
| 468 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 469 | - } |
|
| 470 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
| 471 | - |
|
| 472 | - // Is the result an error? |
|
| 473 | - if (is_a($result, 'IXR_Error')) { |
|
| 474 | - $this->error($result); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - // Encode the result |
|
| 478 | - $r = new IXR_Value($result); |
|
| 479 | - $resultxml = $r->getXml(); |
|
| 480 | - |
|
| 481 | - // Create the XML |
|
| 482 | - $xml = <<<EOD |
|
| 443 | + function serve($data = false) |
|
| 444 | + { |
|
| 445 | + if (!$data) { |
|
| 446 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
| 447 | + if ( function_exists( 'status_header' ) ) { |
|
| 448 | + status_header( 405 ); // WP #20986 |
|
| 449 | + header( 'Allow: POST' ); |
|
| 450 | + } |
|
| 451 | + header('Content-Type: text/plain'); // merged from WP #9093 |
|
| 452 | + die('XML-RPC server accepts POST requests only.'); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + global $HTTP_RAW_POST_DATA; |
|
| 456 | + if (empty($HTTP_RAW_POST_DATA)) { |
|
| 457 | + // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
| 458 | + $data = file_get_contents('php://input'); |
|
| 459 | + } else { |
|
| 460 | + $data =& $HTTP_RAW_POST_DATA; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + $this->message = new IXR_Message($data); |
|
| 464 | + if (!$this->message->parse()) { |
|
| 465 | + $this->error(-32700, 'parse error. not well formed'); |
|
| 466 | + } |
|
| 467 | + if ($this->message->messageType != 'methodCall') { |
|
| 468 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 469 | + } |
|
| 470 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
| 471 | + |
|
| 472 | + // Is the result an error? |
|
| 473 | + if (is_a($result, 'IXR_Error')) { |
|
| 474 | + $this->error($result); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + // Encode the result |
|
| 478 | + $r = new IXR_Value($result); |
|
| 479 | + $resultxml = $r->getXml(); |
|
| 480 | + |
|
| 481 | + // Create the XML |
|
| 482 | + $xml = <<<EOD |
|
| 483 | 483 | <methodResponse> |
| 484 | 484 | <params> |
| 485 | 485 | <param> |
@@ -491,142 +491,142 @@ discard block |
||
| 491 | 491 | </methodResponse> |
| 492 | 492 | |
| 493 | 493 | EOD; |
| 494 | - // Send it |
|
| 495 | - $this->output($xml); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - function call($methodname, $args) |
|
| 499 | - { |
|
| 500 | - if (!$this->hasMethod($methodname)) { |
|
| 501 | - return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
| 502 | - } |
|
| 503 | - $method = $this->callbacks[$methodname]; |
|
| 504 | - |
|
| 505 | - // Perform the callback and send the response |
|
| 506 | - if (count($args) == 1) { |
|
| 507 | - // If only one parameter just send that instead of the whole array |
|
| 508 | - $args = $args[0]; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - // Are we dealing with a function or a method? |
|
| 512 | - if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
| 513 | - // It's a class method - check it exists |
|
| 514 | - $method = substr($method, 5); |
|
| 515 | - if (!method_exists($this, $method)) { |
|
| 516 | - return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - //Call the method |
|
| 520 | - $result = $this->$method($args); |
|
| 521 | - } else { |
|
| 522 | - // It's a function - does it exist? |
|
| 523 | - if (is_array($method)) { |
|
| 524 | - if (!is_callable(array($method[0], $method[1]))) { |
|
| 525 | - return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
| 526 | - } |
|
| 527 | - } else if (!function_exists($method)) { |
|
| 528 | - return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - // Call the function |
|
| 532 | - $result = call_user_func($method, $args); |
|
| 533 | - } |
|
| 534 | - return $result; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - function error($error, $message = false) |
|
| 538 | - { |
|
| 539 | - // Accepts either an error object or an error code and message |
|
| 540 | - if ($message && !is_object($error)) { |
|
| 541 | - $error = new IXR_Error($error, $message); |
|
| 542 | - } |
|
| 543 | - $this->output($error->getXml()); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - function output($xml) |
|
| 547 | - { |
|
| 548 | - $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
| 549 | - if ($charset) |
|
| 550 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 551 | - else |
|
| 552 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 553 | - $length = strlen($xml); |
|
| 554 | - header('Connection: close'); |
|
| 555 | - if ($charset) |
|
| 556 | - header('Content-Type: text/xml; charset='.$charset); |
|
| 557 | - else |
|
| 558 | - header('Content-Type: text/xml'); |
|
| 559 | - header('Date: '.date('r')); |
|
| 560 | - echo $xml; |
|
| 561 | - exit; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - function hasMethod($method) |
|
| 565 | - { |
|
| 566 | - return in_array($method, array_keys($this->callbacks)); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - function setCapabilities() |
|
| 570 | - { |
|
| 571 | - // Initialises capabilities array |
|
| 572 | - $this->capabilities = array( |
|
| 573 | - 'xmlrpc' => array( |
|
| 574 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 575 | - 'specVersion' => 1 |
|
| 576 | - ), |
|
| 577 | - 'faults_interop' => array( |
|
| 578 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 579 | - 'specVersion' => 20010516 |
|
| 580 | - ), |
|
| 581 | - 'system.multicall' => array( |
|
| 582 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 583 | - 'specVersion' => 1 |
|
| 584 | - ), |
|
| 585 | - ); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - function getCapabilities($args) |
|
| 589 | - { |
|
| 590 | - return $this->capabilities; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - function setCallbacks() |
|
| 594 | - { |
|
| 595 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 596 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 597 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - function listMethods($args) |
|
| 601 | - { |
|
| 602 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 603 | - // methods are listed before server defined methods |
|
| 604 | - return array_reverse(array_keys($this->callbacks)); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - function multiCall($methodcalls) |
|
| 608 | - { |
|
| 609 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 610 | - $return = array(); |
|
| 611 | - foreach ($methodcalls as $call) { |
|
| 612 | - $method = $call['methodName']; |
|
| 613 | - $params = $call['params']; |
|
| 614 | - if ($method == 'system.multicall') { |
|
| 615 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 616 | - } else { |
|
| 617 | - $result = $this->call($method, $params); |
|
| 618 | - } |
|
| 619 | - if (is_a($result, 'IXR_Error')) { |
|
| 620 | - $return[] = array( |
|
| 621 | - 'faultCode' => $result->code, |
|
| 622 | - 'faultString' => $result->message |
|
| 623 | - ); |
|
| 624 | - } else { |
|
| 625 | - $return[] = array($result); |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - return $return; |
|
| 629 | - } |
|
| 494 | + // Send it |
|
| 495 | + $this->output($xml); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + function call($methodname, $args) |
|
| 499 | + { |
|
| 500 | + if (!$this->hasMethod($methodname)) { |
|
| 501 | + return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
| 502 | + } |
|
| 503 | + $method = $this->callbacks[$methodname]; |
|
| 504 | + |
|
| 505 | + // Perform the callback and send the response |
|
| 506 | + if (count($args) == 1) { |
|
| 507 | + // If only one parameter just send that instead of the whole array |
|
| 508 | + $args = $args[0]; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + // Are we dealing with a function or a method? |
|
| 512 | + if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
| 513 | + // It's a class method - check it exists |
|
| 514 | + $method = substr($method, 5); |
|
| 515 | + if (!method_exists($this, $method)) { |
|
| 516 | + return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + //Call the method |
|
| 520 | + $result = $this->$method($args); |
|
| 521 | + } else { |
|
| 522 | + // It's a function - does it exist? |
|
| 523 | + if (is_array($method)) { |
|
| 524 | + if (!is_callable(array($method[0], $method[1]))) { |
|
| 525 | + return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
| 526 | + } |
|
| 527 | + } else if (!function_exists($method)) { |
|
| 528 | + return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + // Call the function |
|
| 532 | + $result = call_user_func($method, $args); |
|
| 533 | + } |
|
| 534 | + return $result; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + function error($error, $message = false) |
|
| 538 | + { |
|
| 539 | + // Accepts either an error object or an error code and message |
|
| 540 | + if ($message && !is_object($error)) { |
|
| 541 | + $error = new IXR_Error($error, $message); |
|
| 542 | + } |
|
| 543 | + $this->output($error->getXml()); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + function output($xml) |
|
| 547 | + { |
|
| 548 | + $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
| 549 | + if ($charset) |
|
| 550 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
| 551 | + else |
|
| 552 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
| 553 | + $length = strlen($xml); |
|
| 554 | + header('Connection: close'); |
|
| 555 | + if ($charset) |
|
| 556 | + header('Content-Type: text/xml; charset='.$charset); |
|
| 557 | + else |
|
| 558 | + header('Content-Type: text/xml'); |
|
| 559 | + header('Date: '.date('r')); |
|
| 560 | + echo $xml; |
|
| 561 | + exit; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + function hasMethod($method) |
|
| 565 | + { |
|
| 566 | + return in_array($method, array_keys($this->callbacks)); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + function setCapabilities() |
|
| 570 | + { |
|
| 571 | + // Initialises capabilities array |
|
| 572 | + $this->capabilities = array( |
|
| 573 | + 'xmlrpc' => array( |
|
| 574 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 575 | + 'specVersion' => 1 |
|
| 576 | + ), |
|
| 577 | + 'faults_interop' => array( |
|
| 578 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 579 | + 'specVersion' => 20010516 |
|
| 580 | + ), |
|
| 581 | + 'system.multicall' => array( |
|
| 582 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 583 | + 'specVersion' => 1 |
|
| 584 | + ), |
|
| 585 | + ); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + function getCapabilities($args) |
|
| 589 | + { |
|
| 590 | + return $this->capabilities; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + function setCallbacks() |
|
| 594 | + { |
|
| 595 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 596 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 597 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + function listMethods($args) |
|
| 601 | + { |
|
| 602 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 603 | + // methods are listed before server defined methods |
|
| 604 | + return array_reverse(array_keys($this->callbacks)); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + function multiCall($methodcalls) |
|
| 608 | + { |
|
| 609 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 610 | + $return = array(); |
|
| 611 | + foreach ($methodcalls as $call) { |
|
| 612 | + $method = $call['methodName']; |
|
| 613 | + $params = $call['params']; |
|
| 614 | + if ($method == 'system.multicall') { |
|
| 615 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 616 | + } else { |
|
| 617 | + $result = $this->call($method, $params); |
|
| 618 | + } |
|
| 619 | + if (is_a($result, 'IXR_Error')) { |
|
| 620 | + $return[] = array( |
|
| 621 | + 'faultCode' => $result->code, |
|
| 622 | + 'faultString' => $result->message |
|
| 623 | + ); |
|
| 624 | + } else { |
|
| 625 | + $return[] = array($result); |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + return $return; |
|
| 629 | + } |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -637,32 +637,32 @@ discard block |
||
| 637 | 637 | */ |
| 638 | 638 | class IXR_Request |
| 639 | 639 | { |
| 640 | - var $method; |
|
| 641 | - var $args; |
|
| 642 | - var $xml; |
|
| 640 | + var $method; |
|
| 641 | + var $args; |
|
| 642 | + var $xml; |
|
| 643 | 643 | |
| 644 | 644 | /** |
| 645 | 645 | * PHP5 constructor. |
| 646 | 646 | */ |
| 647 | - function __construct($method, $args) |
|
| 648 | - { |
|
| 649 | - $this->method = $method; |
|
| 650 | - $this->args = $args; |
|
| 651 | - $this->xml = <<<EOD |
|
| 647 | + function __construct($method, $args) |
|
| 648 | + { |
|
| 649 | + $this->method = $method; |
|
| 650 | + $this->args = $args; |
|
| 651 | + $this->xml = <<<EOD |
|
| 652 | 652 | <?xml version="1.0"?> |
| 653 | 653 | <methodCall> |
| 654 | 654 | <methodName>{$this->method}</methodName> |
| 655 | 655 | <params> |
| 656 | 656 | |
| 657 | 657 | EOD; |
| 658 | - foreach ($this->args as $arg) { |
|
| 659 | - $this->xml .= '<param><value>'; |
|
| 660 | - $v = new IXR_Value($arg); |
|
| 661 | - $this->xml .= $v->getXml(); |
|
| 662 | - $this->xml .= "</value></param>\n"; |
|
| 663 | - } |
|
| 664 | - $this->xml .= '</params></methodCall>'; |
|
| 665 | - } |
|
| 658 | + foreach ($this->args as $arg) { |
|
| 659 | + $this->xml .= '<param><value>'; |
|
| 660 | + $v = new IXR_Value($arg); |
|
| 661 | + $this->xml .= $v->getXml(); |
|
| 662 | + $this->xml .= "</value></param>\n"; |
|
| 663 | + } |
|
| 664 | + $this->xml .= '</params></methodCall>'; |
|
| 665 | + } |
|
| 666 | 666 | |
| 667 | 667 | /** |
| 668 | 668 | * PHP4 constructor. |
@@ -671,15 +671,15 @@ discard block |
||
| 671 | 671 | self::__construct( $method, $args ); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - function getLength() |
|
| 675 | - { |
|
| 676 | - return strlen($this->xml); |
|
| 677 | - } |
|
| 674 | + function getLength() |
|
| 675 | + { |
|
| 676 | + return strlen($this->xml); |
|
| 677 | + } |
|
| 678 | 678 | |
| 679 | - function getXml() |
|
| 680 | - { |
|
| 681 | - return $this->xml; |
|
| 682 | - } |
|
| 679 | + function getXml() |
|
| 680 | + { |
|
| 681 | + return $this->xml; |
|
| 682 | + } |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -691,47 +691,47 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | class IXR_Client |
| 693 | 693 | { |
| 694 | - var $server; |
|
| 695 | - var $port; |
|
| 696 | - var $path; |
|
| 697 | - var $useragent; |
|
| 698 | - var $response; |
|
| 699 | - var $message = false; |
|
| 700 | - var $debug = false; |
|
| 701 | - var $timeout; |
|
| 702 | - var $headers = array(); |
|
| 703 | - |
|
| 704 | - // Storage place for an error message |
|
| 705 | - var $error = false; |
|
| 694 | + var $server; |
|
| 695 | + var $port; |
|
| 696 | + var $path; |
|
| 697 | + var $useragent; |
|
| 698 | + var $response; |
|
| 699 | + var $message = false; |
|
| 700 | + var $debug = false; |
|
| 701 | + var $timeout; |
|
| 702 | + var $headers = array(); |
|
| 703 | + |
|
| 704 | + // Storage place for an error message |
|
| 705 | + var $error = false; |
|
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | 708 | * PHP5 constructor. |
| 709 | 709 | */ |
| 710 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 711 | - { |
|
| 712 | - if (!$path) { |
|
| 713 | - // Assume we have been given a URL instead |
|
| 714 | - $bits = parse_url($server); |
|
| 715 | - $this->server = $bits['host']; |
|
| 716 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 717 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 718 | - |
|
| 719 | - // Make absolutely sure we have a path |
|
| 720 | - if (!$this->path) { |
|
| 721 | - $this->path = '/'; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - if ( ! empty( $bits['query'] ) ) { |
|
| 725 | - $this->path .= '?' . $bits['query']; |
|
| 726 | - } |
|
| 727 | - } else { |
|
| 728 | - $this->server = $server; |
|
| 729 | - $this->path = $path; |
|
| 730 | - $this->port = $port; |
|
| 731 | - } |
|
| 732 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 733 | - $this->timeout = $timeout; |
|
| 734 | - } |
|
| 710 | + function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 711 | + { |
|
| 712 | + if (!$path) { |
|
| 713 | + // Assume we have been given a URL instead |
|
| 714 | + $bits = parse_url($server); |
|
| 715 | + $this->server = $bits['host']; |
|
| 716 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 717 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 718 | + |
|
| 719 | + // Make absolutely sure we have a path |
|
| 720 | + if (!$this->path) { |
|
| 721 | + $this->path = '/'; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + if ( ! empty( $bits['query'] ) ) { |
|
| 725 | + $this->path .= '?' . $bits['query']; |
|
| 726 | + } |
|
| 727 | + } else { |
|
| 728 | + $this->server = $server; |
|
| 729 | + $this->path = $path; |
|
| 730 | + $this->port = $port; |
|
| 731 | + } |
|
| 732 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 733 | + $this->timeout = $timeout; |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | 736 | /** |
| 737 | 737 | * PHP4 constructor. |
@@ -740,111 +740,111 @@ discard block |
||
| 740 | 740 | self::__construct( $server, $path, $port, $timeout ); |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | - function query() |
|
| 744 | - { |
|
| 745 | - $args = func_get_args(); |
|
| 746 | - $method = array_shift($args); |
|
| 747 | - $request = new IXR_Request($method, $args); |
|
| 748 | - $length = $request->getLength(); |
|
| 749 | - $xml = $request->getXml(); |
|
| 750 | - $r = "\r\n"; |
|
| 751 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 752 | - |
|
| 753 | - // Merged from WP #8145 - allow custom headers |
|
| 754 | - $this->headers['Host'] = $this->server; |
|
| 755 | - $this->headers['Content-Type'] = 'text/xml'; |
|
| 756 | - $this->headers['User-Agent'] = $this->useragent; |
|
| 757 | - $this->headers['Content-Length']= $length; |
|
| 758 | - |
|
| 759 | - foreach( $this->headers as $header => $value ) { |
|
| 760 | - $request .= "{$header}: {$value}{$r}"; |
|
| 761 | - } |
|
| 762 | - $request .= $r; |
|
| 763 | - |
|
| 764 | - $request .= $xml; |
|
| 765 | - |
|
| 766 | - // Now send the request |
|
| 767 | - if ($this->debug) { |
|
| 768 | - echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - if ($this->timeout) { |
|
| 772 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 773 | - } else { |
|
| 774 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
| 775 | - } |
|
| 776 | - if (!$fp) { |
|
| 777 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 778 | - return false; |
|
| 779 | - } |
|
| 780 | - fputs($fp, $request); |
|
| 781 | - $contents = ''; |
|
| 782 | - $debugContents = ''; |
|
| 783 | - $gotFirstLine = false; |
|
| 784 | - $gettingHeaders = true; |
|
| 785 | - while (!feof($fp)) { |
|
| 786 | - $line = fgets($fp, 4096); |
|
| 787 | - if (!$gotFirstLine) { |
|
| 788 | - // Check line for '200' |
|
| 789 | - if (strstr($line, '200') === false) { |
|
| 790 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - $gotFirstLine = true; |
|
| 794 | - } |
|
| 795 | - if (trim($line) == '') { |
|
| 796 | - $gettingHeaders = false; |
|
| 797 | - } |
|
| 798 | - if (!$gettingHeaders) { |
|
| 799 | - // merged from WP #12559 - remove trim |
|
| 800 | - $contents .= $line; |
|
| 801 | - } |
|
| 802 | - if ($this->debug) { |
|
| 803 | - $debugContents .= $line; |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - if ($this->debug) { |
|
| 807 | - echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - // Now parse what we've got back |
|
| 811 | - $this->message = new IXR_Message($contents); |
|
| 812 | - if (!$this->message->parse()) { |
|
| 813 | - // XML error |
|
| 814 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - // Is the message a fault? |
|
| 819 | - if ($this->message->messageType == 'fault') { |
|
| 820 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 821 | - return false; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - // Message must be OK |
|
| 825 | - return true; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - function getResponse() |
|
| 829 | - { |
|
| 830 | - // methodResponses can only have one param - return that |
|
| 831 | - return $this->message->params[0]; |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - function isError() |
|
| 835 | - { |
|
| 836 | - return (is_object($this->error)); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - function getErrorCode() |
|
| 840 | - { |
|
| 841 | - return $this->error->code; |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - function getErrorMessage() |
|
| 845 | - { |
|
| 846 | - return $this->error->message; |
|
| 847 | - } |
|
| 743 | + function query() |
|
| 744 | + { |
|
| 745 | + $args = func_get_args(); |
|
| 746 | + $method = array_shift($args); |
|
| 747 | + $request = new IXR_Request($method, $args); |
|
| 748 | + $length = $request->getLength(); |
|
| 749 | + $xml = $request->getXml(); |
|
| 750 | + $r = "\r\n"; |
|
| 751 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 752 | + |
|
| 753 | + // Merged from WP #8145 - allow custom headers |
|
| 754 | + $this->headers['Host'] = $this->server; |
|
| 755 | + $this->headers['Content-Type'] = 'text/xml'; |
|
| 756 | + $this->headers['User-Agent'] = $this->useragent; |
|
| 757 | + $this->headers['Content-Length']= $length; |
|
| 758 | + |
|
| 759 | + foreach( $this->headers as $header => $value ) { |
|
| 760 | + $request .= "{$header}: {$value}{$r}"; |
|
| 761 | + } |
|
| 762 | + $request .= $r; |
|
| 763 | + |
|
| 764 | + $request .= $xml; |
|
| 765 | + |
|
| 766 | + // Now send the request |
|
| 767 | + if ($this->debug) { |
|
| 768 | + echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + if ($this->timeout) { |
|
| 772 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 773 | + } else { |
|
| 774 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
| 775 | + } |
|
| 776 | + if (!$fp) { |
|
| 777 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 778 | + return false; |
|
| 779 | + } |
|
| 780 | + fputs($fp, $request); |
|
| 781 | + $contents = ''; |
|
| 782 | + $debugContents = ''; |
|
| 783 | + $gotFirstLine = false; |
|
| 784 | + $gettingHeaders = true; |
|
| 785 | + while (!feof($fp)) { |
|
| 786 | + $line = fgets($fp, 4096); |
|
| 787 | + if (!$gotFirstLine) { |
|
| 788 | + // Check line for '200' |
|
| 789 | + if (strstr($line, '200') === false) { |
|
| 790 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + $gotFirstLine = true; |
|
| 794 | + } |
|
| 795 | + if (trim($line) == '') { |
|
| 796 | + $gettingHeaders = false; |
|
| 797 | + } |
|
| 798 | + if (!$gettingHeaders) { |
|
| 799 | + // merged from WP #12559 - remove trim |
|
| 800 | + $contents .= $line; |
|
| 801 | + } |
|
| 802 | + if ($this->debug) { |
|
| 803 | + $debugContents .= $line; |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + if ($this->debug) { |
|
| 807 | + echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + // Now parse what we've got back |
|
| 811 | + $this->message = new IXR_Message($contents); |
|
| 812 | + if (!$this->message->parse()) { |
|
| 813 | + // XML error |
|
| 814 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + // Is the message a fault? |
|
| 819 | + if ($this->message->messageType == 'fault') { |
|
| 820 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 821 | + return false; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + // Message must be OK |
|
| 825 | + return true; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + function getResponse() |
|
| 829 | + { |
|
| 830 | + // methodResponses can only have one param - return that |
|
| 831 | + return $this->message->params[0]; |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + function isError() |
|
| 835 | + { |
|
| 836 | + return (is_object($this->error)); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + function getErrorCode() |
|
| 840 | + { |
|
| 841 | + return $this->error->code; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + function getErrorMessage() |
|
| 845 | + { |
|
| 846 | + return $this->error->message; |
|
| 847 | + } |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -856,17 +856,17 @@ discard block |
||
| 856 | 856 | */ |
| 857 | 857 | class IXR_Error |
| 858 | 858 | { |
| 859 | - var $code; |
|
| 860 | - var $message; |
|
| 859 | + var $code; |
|
| 860 | + var $message; |
|
| 861 | 861 | |
| 862 | 862 | /** |
| 863 | 863 | * PHP5 constructor. |
| 864 | 864 | */ |
| 865 | - function __construct( $code, $message ) |
|
| 866 | - { |
|
| 867 | - $this->code = $code; |
|
| 868 | - $this->message = htmlspecialchars($message); |
|
| 869 | - } |
|
| 865 | + function __construct( $code, $message ) |
|
| 866 | + { |
|
| 867 | + $this->code = $code; |
|
| 868 | + $this->message = htmlspecialchars($message); |
|
| 869 | + } |
|
| 870 | 870 | |
| 871 | 871 | /** |
| 872 | 872 | * PHP4 constructor. |
@@ -875,9 +875,9 @@ discard block |
||
| 875 | 875 | self::__construct( $code, $message ); |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - function getXml() |
|
| 879 | - { |
|
| 880 | - $xml = <<<EOD |
|
| 878 | + function getXml() |
|
| 879 | + { |
|
| 880 | + $xml = <<<EOD |
|
| 881 | 881 | <methodResponse> |
| 882 | 882 | <fault> |
| 883 | 883 | <value> |
@@ -896,8 +896,8 @@ discard block |
||
| 896 | 896 | </methodResponse> |
| 897 | 897 | |
| 898 | 898 | EOD; |
| 899 | - return $xml; |
|
| 900 | - } |
|
| 899 | + return $xml; |
|
| 900 | + } |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -907,26 +907,26 @@ discard block |
||
| 907 | 907 | * @since 1.5.0 |
| 908 | 908 | */ |
| 909 | 909 | class IXR_Date { |
| 910 | - var $year; |
|
| 911 | - var $month; |
|
| 912 | - var $day; |
|
| 913 | - var $hour; |
|
| 914 | - var $minute; |
|
| 915 | - var $second; |
|
| 916 | - var $timezone; |
|
| 910 | + var $year; |
|
| 911 | + var $month; |
|
| 912 | + var $day; |
|
| 913 | + var $hour; |
|
| 914 | + var $minute; |
|
| 915 | + var $second; |
|
| 916 | + var $timezone; |
|
| 917 | 917 | |
| 918 | 918 | /** |
| 919 | 919 | * PHP5 constructor. |
| 920 | 920 | */ |
| 921 | - function __construct( $time ) |
|
| 922 | - { |
|
| 923 | - // $time can be a PHP timestamp or an ISO one |
|
| 924 | - if (is_numeric($time)) { |
|
| 925 | - $this->parseTimestamp($time); |
|
| 926 | - } else { |
|
| 927 | - $this->parseIso($time); |
|
| 928 | - } |
|
| 929 | - } |
|
| 921 | + function __construct( $time ) |
|
| 922 | + { |
|
| 923 | + // $time can be a PHP timestamp or an ISO one |
|
| 924 | + if (is_numeric($time)) { |
|
| 925 | + $this->parseTimestamp($time); |
|
| 926 | + } else { |
|
| 927 | + $this->parseIso($time); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | 930 | |
| 931 | 931 | /** |
| 932 | 932 | * PHP4 constructor. |
@@ -935,42 +935,42 @@ discard block |
||
| 935 | 935 | self::__construct( $time ); |
| 936 | 936 | } |
| 937 | 937 | |
| 938 | - function parseTimestamp($timestamp) |
|
| 939 | - { |
|
| 940 | - $this->year = date('Y', $timestamp); |
|
| 941 | - $this->month = date('m', $timestamp); |
|
| 942 | - $this->day = date('d', $timestamp); |
|
| 943 | - $this->hour = date('H', $timestamp); |
|
| 944 | - $this->minute = date('i', $timestamp); |
|
| 945 | - $this->second = date('s', $timestamp); |
|
| 946 | - $this->timezone = ''; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - function parseIso($iso) |
|
| 950 | - { |
|
| 951 | - $this->year = substr($iso, 0, 4); |
|
| 952 | - $this->month = substr($iso, 4, 2); |
|
| 953 | - $this->day = substr($iso, 6, 2); |
|
| 954 | - $this->hour = substr($iso, 9, 2); |
|
| 955 | - $this->minute = substr($iso, 12, 2); |
|
| 956 | - $this->second = substr($iso, 15, 2); |
|
| 957 | - $this->timezone = substr($iso, 17); |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - function getIso() |
|
| 961 | - { |
|
| 962 | - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - function getXml() |
|
| 966 | - { |
|
| 967 | - return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - function getTimestamp() |
|
| 971 | - { |
|
| 972 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 973 | - } |
|
| 938 | + function parseTimestamp($timestamp) |
|
| 939 | + { |
|
| 940 | + $this->year = date('Y', $timestamp); |
|
| 941 | + $this->month = date('m', $timestamp); |
|
| 942 | + $this->day = date('d', $timestamp); |
|
| 943 | + $this->hour = date('H', $timestamp); |
|
| 944 | + $this->minute = date('i', $timestamp); |
|
| 945 | + $this->second = date('s', $timestamp); |
|
| 946 | + $this->timezone = ''; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + function parseIso($iso) |
|
| 950 | + { |
|
| 951 | + $this->year = substr($iso, 0, 4); |
|
| 952 | + $this->month = substr($iso, 4, 2); |
|
| 953 | + $this->day = substr($iso, 6, 2); |
|
| 954 | + $this->hour = substr($iso, 9, 2); |
|
| 955 | + $this->minute = substr($iso, 12, 2); |
|
| 956 | + $this->second = substr($iso, 15, 2); |
|
| 957 | + $this->timezone = substr($iso, 17); |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + function getIso() |
|
| 961 | + { |
|
| 962 | + return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + function getXml() |
|
| 966 | + { |
|
| 967 | + return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + function getTimestamp() |
|
| 971 | + { |
|
| 972 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 973 | + } |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -981,15 +981,15 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | class IXR_Base64 |
| 983 | 983 | { |
| 984 | - var $data; |
|
| 984 | + var $data; |
|
| 985 | 985 | |
| 986 | 986 | /** |
| 987 | 987 | * PHP5 constructor. |
| 988 | 988 | */ |
| 989 | - function __construct( $data ) |
|
| 990 | - { |
|
| 991 | - $this->data = $data; |
|
| 992 | - } |
|
| 989 | + function __construct( $data ) |
|
| 990 | + { |
|
| 991 | + $this->data = $data; |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | 994 | /** |
| 995 | 995 | * PHP4 constructor. |
@@ -998,10 +998,10 @@ discard block |
||
| 998 | 998 | self::__construct( $data ); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - function getXml() |
|
| 1002 | - { |
|
| 1003 | - return '<base64>'.base64_encode($this->data).'</base64>'; |
|
| 1004 | - } |
|
| 1001 | + function getXml() |
|
| 1002 | + { |
|
| 1003 | + return '<base64>'.base64_encode($this->data).'</base64>'; |
|
| 1004 | + } |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | /** |
@@ -1012,45 +1012,45 @@ discard block |
||
| 1012 | 1012 | */ |
| 1013 | 1013 | class IXR_IntrospectionServer extends IXR_Server |
| 1014 | 1014 | { |
| 1015 | - var $signatures; |
|
| 1016 | - var $help; |
|
| 1015 | + var $signatures; |
|
| 1016 | + var $help; |
|
| 1017 | 1017 | |
| 1018 | 1018 | /** |
| 1019 | 1019 | * PHP5 constructor. |
| 1020 | 1020 | */ |
| 1021 | - function __construct() |
|
| 1022 | - { |
|
| 1023 | - $this->setCallbacks(); |
|
| 1024 | - $this->setCapabilities(); |
|
| 1025 | - $this->capabilities['introspection'] = array( |
|
| 1026 | - 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 1027 | - 'specVersion' => 1 |
|
| 1028 | - ); |
|
| 1029 | - $this->addCallback( |
|
| 1030 | - 'system.methodSignature', |
|
| 1031 | - 'this:methodSignature', |
|
| 1032 | - array('array', 'string'), |
|
| 1033 | - 'Returns an array describing the return type and required parameters of a method' |
|
| 1034 | - ); |
|
| 1035 | - $this->addCallback( |
|
| 1036 | - 'system.getCapabilities', |
|
| 1037 | - 'this:getCapabilities', |
|
| 1038 | - array('struct'), |
|
| 1039 | - 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
| 1040 | - ); |
|
| 1041 | - $this->addCallback( |
|
| 1042 | - 'system.listMethods', |
|
| 1043 | - 'this:listMethods', |
|
| 1044 | - array('array'), |
|
| 1045 | - 'Returns an array of available methods on this server' |
|
| 1046 | - ); |
|
| 1047 | - $this->addCallback( |
|
| 1048 | - 'system.methodHelp', |
|
| 1049 | - 'this:methodHelp', |
|
| 1050 | - array('string', 'string'), |
|
| 1051 | - 'Returns a documentation string for the specified method' |
|
| 1052 | - ); |
|
| 1053 | - } |
|
| 1021 | + function __construct() |
|
| 1022 | + { |
|
| 1023 | + $this->setCallbacks(); |
|
| 1024 | + $this->setCapabilities(); |
|
| 1025 | + $this->capabilities['introspection'] = array( |
|
| 1026 | + 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 1027 | + 'specVersion' => 1 |
|
| 1028 | + ); |
|
| 1029 | + $this->addCallback( |
|
| 1030 | + 'system.methodSignature', |
|
| 1031 | + 'this:methodSignature', |
|
| 1032 | + array('array', 'string'), |
|
| 1033 | + 'Returns an array describing the return type and required parameters of a method' |
|
| 1034 | + ); |
|
| 1035 | + $this->addCallback( |
|
| 1036 | + 'system.getCapabilities', |
|
| 1037 | + 'this:getCapabilities', |
|
| 1038 | + array('struct'), |
|
| 1039 | + 'Returns a struct describing the XML-RPC specifications supported by this server' |
|
| 1040 | + ); |
|
| 1041 | + $this->addCallback( |
|
| 1042 | + 'system.listMethods', |
|
| 1043 | + 'this:listMethods', |
|
| 1044 | + array('array'), |
|
| 1045 | + 'Returns an array of available methods on this server' |
|
| 1046 | + ); |
|
| 1047 | + $this->addCallback( |
|
| 1048 | + 'system.methodHelp', |
|
| 1049 | + 'this:methodHelp', |
|
| 1050 | + array('string', 'string'), |
|
| 1051 | + 'Returns a documentation string for the specified method' |
|
| 1052 | + ); |
|
| 1053 | + } |
|
| 1054 | 1054 | |
| 1055 | 1055 | /** |
| 1056 | 1056 | * PHP4 constructor. |
@@ -1059,122 +1059,122 @@ discard block |
||
| 1059 | 1059 | self::__construct(); |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | - function addCallback($method, $callback, $args, $help) |
|
| 1063 | - { |
|
| 1064 | - $this->callbacks[$method] = $callback; |
|
| 1065 | - $this->signatures[$method] = $args; |
|
| 1066 | - $this->help[$method] = $help; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - function call($methodname, $args) |
|
| 1070 | - { |
|
| 1071 | - // Make sure it's in an array |
|
| 1072 | - if ($args && !is_array($args)) { |
|
| 1073 | - $args = array($args); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - // Over-rides default call method, adds signature check |
|
| 1077 | - if (!$this->hasMethod($methodname)) { |
|
| 1078 | - return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
| 1079 | - } |
|
| 1080 | - $method = $this->callbacks[$methodname]; |
|
| 1081 | - $signature = $this->signatures[$methodname]; |
|
| 1082 | - $returnType = array_shift($signature); |
|
| 1083 | - |
|
| 1084 | - // Check the number of arguments |
|
| 1085 | - if (count($args) != count($signature)) { |
|
| 1086 | - return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - // Check the argument types |
|
| 1090 | - $ok = true; |
|
| 1091 | - $argsbackup = $args; |
|
| 1092 | - for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
| 1093 | - $arg = array_shift($args); |
|
| 1094 | - $type = array_shift($signature); |
|
| 1095 | - switch ($type) { |
|
| 1096 | - case 'int': |
|
| 1097 | - case 'i4': |
|
| 1098 | - if (is_array($arg) || !is_int($arg)) { |
|
| 1099 | - $ok = false; |
|
| 1100 | - } |
|
| 1101 | - break; |
|
| 1102 | - case 'base64': |
|
| 1103 | - case 'string': |
|
| 1104 | - if (!is_string($arg)) { |
|
| 1105 | - $ok = false; |
|
| 1106 | - } |
|
| 1107 | - break; |
|
| 1108 | - case 'boolean': |
|
| 1109 | - if ($arg !== false && $arg !== true) { |
|
| 1110 | - $ok = false; |
|
| 1111 | - } |
|
| 1112 | - break; |
|
| 1113 | - case 'float': |
|
| 1114 | - case 'double': |
|
| 1115 | - if (!is_float($arg)) { |
|
| 1116 | - $ok = false; |
|
| 1117 | - } |
|
| 1118 | - break; |
|
| 1119 | - case 'date': |
|
| 1120 | - case 'dateTime.iso8601': |
|
| 1121 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 1122 | - $ok = false; |
|
| 1123 | - } |
|
| 1124 | - break; |
|
| 1125 | - } |
|
| 1126 | - if (!$ok) { |
|
| 1127 | - return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - // It passed the test - run the "real" method call |
|
| 1131 | - return parent::call($methodname, $argsbackup); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - function methodSignature($method) |
|
| 1135 | - { |
|
| 1136 | - if (!$this->hasMethod($method)) { |
|
| 1137 | - return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
| 1138 | - } |
|
| 1139 | - // We should be returning an array of types |
|
| 1140 | - $types = $this->signatures[$method]; |
|
| 1141 | - $return = array(); |
|
| 1142 | - foreach ($types as $type) { |
|
| 1143 | - switch ($type) { |
|
| 1144 | - case 'string': |
|
| 1145 | - $return[] = 'string'; |
|
| 1146 | - break; |
|
| 1147 | - case 'int': |
|
| 1148 | - case 'i4': |
|
| 1149 | - $return[] = 42; |
|
| 1150 | - break; |
|
| 1151 | - case 'double': |
|
| 1152 | - $return[] = 3.1415; |
|
| 1153 | - break; |
|
| 1154 | - case 'dateTime.iso8601': |
|
| 1155 | - $return[] = new IXR_Date(time()); |
|
| 1156 | - break; |
|
| 1157 | - case 'boolean': |
|
| 1158 | - $return[] = true; |
|
| 1159 | - break; |
|
| 1160 | - case 'base64': |
|
| 1161 | - $return[] = new IXR_Base64('base64'); |
|
| 1162 | - break; |
|
| 1163 | - case 'array': |
|
| 1164 | - $return[] = array('array'); |
|
| 1165 | - break; |
|
| 1166 | - case 'struct': |
|
| 1167 | - $return[] = array('struct' => 'struct'); |
|
| 1168 | - break; |
|
| 1169 | - } |
|
| 1170 | - } |
|
| 1171 | - return $return; |
|
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - function methodHelp($method) |
|
| 1175 | - { |
|
| 1176 | - return $this->help[$method]; |
|
| 1177 | - } |
|
| 1062 | + function addCallback($method, $callback, $args, $help) |
|
| 1063 | + { |
|
| 1064 | + $this->callbacks[$method] = $callback; |
|
| 1065 | + $this->signatures[$method] = $args; |
|
| 1066 | + $this->help[$method] = $help; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + function call($methodname, $args) |
|
| 1070 | + { |
|
| 1071 | + // Make sure it's in an array |
|
| 1072 | + if ($args && !is_array($args)) { |
|
| 1073 | + $args = array($args); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + // Over-rides default call method, adds signature check |
|
| 1077 | + if (!$this->hasMethod($methodname)) { |
|
| 1078 | + return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
|
| 1079 | + } |
|
| 1080 | + $method = $this->callbacks[$methodname]; |
|
| 1081 | + $signature = $this->signatures[$methodname]; |
|
| 1082 | + $returnType = array_shift($signature); |
|
| 1083 | + |
|
| 1084 | + // Check the number of arguments |
|
| 1085 | + if (count($args) != count($signature)) { |
|
| 1086 | + return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + // Check the argument types |
|
| 1090 | + $ok = true; |
|
| 1091 | + $argsbackup = $args; |
|
| 1092 | + for ($i = 0, $j = count($args); $i < $j; $i++) { |
|
| 1093 | + $arg = array_shift($args); |
|
| 1094 | + $type = array_shift($signature); |
|
| 1095 | + switch ($type) { |
|
| 1096 | + case 'int': |
|
| 1097 | + case 'i4': |
|
| 1098 | + if (is_array($arg) || !is_int($arg)) { |
|
| 1099 | + $ok = false; |
|
| 1100 | + } |
|
| 1101 | + break; |
|
| 1102 | + case 'base64': |
|
| 1103 | + case 'string': |
|
| 1104 | + if (!is_string($arg)) { |
|
| 1105 | + $ok = false; |
|
| 1106 | + } |
|
| 1107 | + break; |
|
| 1108 | + case 'boolean': |
|
| 1109 | + if ($arg !== false && $arg !== true) { |
|
| 1110 | + $ok = false; |
|
| 1111 | + } |
|
| 1112 | + break; |
|
| 1113 | + case 'float': |
|
| 1114 | + case 'double': |
|
| 1115 | + if (!is_float($arg)) { |
|
| 1116 | + $ok = false; |
|
| 1117 | + } |
|
| 1118 | + break; |
|
| 1119 | + case 'date': |
|
| 1120 | + case 'dateTime.iso8601': |
|
| 1121 | + if (!is_a($arg, 'IXR_Date')) { |
|
| 1122 | + $ok = false; |
|
| 1123 | + } |
|
| 1124 | + break; |
|
| 1125 | + } |
|
| 1126 | + if (!$ok) { |
|
| 1127 | + return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + // It passed the test - run the "real" method call |
|
| 1131 | + return parent::call($methodname, $argsbackup); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + function methodSignature($method) |
|
| 1135 | + { |
|
| 1136 | + if (!$this->hasMethod($method)) { |
|
| 1137 | + return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
|
| 1138 | + } |
|
| 1139 | + // We should be returning an array of types |
|
| 1140 | + $types = $this->signatures[$method]; |
|
| 1141 | + $return = array(); |
|
| 1142 | + foreach ($types as $type) { |
|
| 1143 | + switch ($type) { |
|
| 1144 | + case 'string': |
|
| 1145 | + $return[] = 'string'; |
|
| 1146 | + break; |
|
| 1147 | + case 'int': |
|
| 1148 | + case 'i4': |
|
| 1149 | + $return[] = 42; |
|
| 1150 | + break; |
|
| 1151 | + case 'double': |
|
| 1152 | + $return[] = 3.1415; |
|
| 1153 | + break; |
|
| 1154 | + case 'dateTime.iso8601': |
|
| 1155 | + $return[] = new IXR_Date(time()); |
|
| 1156 | + break; |
|
| 1157 | + case 'boolean': |
|
| 1158 | + $return[] = true; |
|
| 1159 | + break; |
|
| 1160 | + case 'base64': |
|
| 1161 | + $return[] = new IXR_Base64('base64'); |
|
| 1162 | + break; |
|
| 1163 | + case 'array': |
|
| 1164 | + $return[] = array('array'); |
|
| 1165 | + break; |
|
| 1166 | + case 'struct': |
|
| 1167 | + $return[] = array('struct' => 'struct'); |
|
| 1168 | + break; |
|
| 1169 | + } |
|
| 1170 | + } |
|
| 1171 | + return $return; |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + function methodHelp($method) |
|
| 1175 | + { |
|
| 1176 | + return $this->help[$method]; |
|
| 1177 | + } |
|
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | /** |
@@ -1185,16 +1185,16 @@ discard block |
||
| 1185 | 1185 | */ |
| 1186 | 1186 | class IXR_ClientMulticall extends IXR_Client |
| 1187 | 1187 | { |
| 1188 | - var $calls = array(); |
|
| 1188 | + var $calls = array(); |
|
| 1189 | 1189 | |
| 1190 | 1190 | /** |
| 1191 | 1191 | * PHP5 constructor. |
| 1192 | 1192 | */ |
| 1193 | - function __construct( $server, $path = false, $port = 80 ) |
|
| 1194 | - { |
|
| 1195 | - parent::IXR_Client($server, $path, $port); |
|
| 1196 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1197 | - } |
|
| 1193 | + function __construct( $server, $path = false, $port = 80 ) |
|
| 1194 | + { |
|
| 1195 | + parent::IXR_Client($server, $path, $port); |
|
| 1196 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1197 | + } |
|
| 1198 | 1198 | |
| 1199 | 1199 | /** |
| 1200 | 1200 | * PHP4 constructor. |
@@ -1203,20 +1203,20 @@ discard block |
||
| 1203 | 1203 | self::__construct( $server, $path, $port ); |
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | - function addCall() |
|
| 1207 | - { |
|
| 1208 | - $args = func_get_args(); |
|
| 1209 | - $methodName = array_shift($args); |
|
| 1210 | - $struct = array( |
|
| 1211 | - 'methodName' => $methodName, |
|
| 1212 | - 'params' => $args |
|
| 1213 | - ); |
|
| 1214 | - $this->calls[] = $struct; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - function query() |
|
| 1218 | - { |
|
| 1219 | - // Prepare multicall, then call the parent::query() method |
|
| 1220 | - return parent::query('system.multicall', $this->calls); |
|
| 1221 | - } |
|
| 1206 | + function addCall() |
|
| 1207 | + { |
|
| 1208 | + $args = func_get_args(); |
|
| 1209 | + $methodName = array_shift($args); |
|
| 1210 | + $struct = array( |
|
| 1211 | + 'methodName' => $methodName, |
|
| 1212 | + 'params' => $args |
|
| 1213 | + ); |
|
| 1214 | + $this->calls[] = $struct; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + function query() |
|
| 1218 | + { |
|
| 1219 | + // Prepare multicall, then call the parent::query() method |
|
| 1220 | + return parent::query('system.multicall', $this->calls); |
|
| 1221 | + } |
|
| 1222 | 1222 | } |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | /** |
| 53 | 53 | * PHP5 constructor. |
| 54 | 54 | */ |
| 55 | - function __construct( $data, $type = false ) |
|
| 55 | + function __construct($data, $type = false) |
|
| 56 | 56 | { |
| 57 | 57 | $this->data = $data; |
| 58 | - if (!$type) { |
|
| 58 | + if ( ! $type) { |
|
| 59 | 59 | $type = $this->calculateType(); |
| 60 | 60 | } |
| 61 | 61 | $this->type = $type; |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | /** |
| 76 | 76 | * PHP4 constructor. |
| 77 | 77 | */ |
| 78 | - public function IXR_Value( $data, $type = false ) { |
|
| 79 | - self::__construct( $data, $type ); |
|
| 78 | + public function IXR_Value($data, $type = false) { |
|
| 79 | + self::__construct($data, $type); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | function calculateType() |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $this->data = get_object_vars($this->data); |
| 105 | 105 | return 'struct'; |
| 106 | 106 | } |
| 107 | - if (!is_array($this->data)) { |
|
| 107 | + if ( ! is_array($this->data)) { |
|
| 108 | 108 | return 'string'; |
| 109 | 109 | } |
| 110 | 110 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | { |
| 169 | 169 | $expected = 0; |
| 170 | 170 | foreach ($array as $key => $value) { |
| 171 | - if ((string)$key != (string)$expected) { |
|
| 171 | + if ((string) $key != (string) $expected) { |
|
| 172 | 172 | return true; |
| 173 | 173 | } |
| 174 | 174 | $expected++; |
@@ -187,16 +187,16 @@ discard block |
||
| 187 | 187 | class IXR_Message |
| 188 | 188 | { |
| 189 | 189 | var $message; |
| 190 | - var $messageType; // methodCall / methodResponse / fault |
|
| 190 | + var $messageType; // methodCall / methodResponse / fault |
|
| 191 | 191 | var $faultCode; |
| 192 | 192 | var $faultString; |
| 193 | 193 | var $methodName; |
| 194 | 194 | var $params; |
| 195 | 195 | |
| 196 | 196 | // Current variable stacks |
| 197 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 197 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 198 | 198 | var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
| 199 | - var $_currentStructName = array(); // A stack as well |
|
| 199 | + var $_currentStructName = array(); // A stack as well |
|
| 200 | 200 | var $_param; |
| 201 | 201 | var $_value; |
| 202 | 202 | var $_currentTag; |
@@ -207,47 +207,47 @@ discard block |
||
| 207 | 207 | /** |
| 208 | 208 | * PHP5 constructor. |
| 209 | 209 | */ |
| 210 | - function __construct( $message ) |
|
| 210 | + function __construct($message) |
|
| 211 | 211 | { |
| 212 | - $this->message =& $message; |
|
| 212 | + $this->message = & $message; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * PHP4 constructor. |
| 217 | 217 | */ |
| 218 | - public function IXR_Message( $message ) { |
|
| 219 | - self::__construct( $message ); |
|
| 218 | + public function IXR_Message($message) { |
|
| 219 | + self::__construct($message); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | function parse() |
| 223 | 223 | { |
| 224 | 224 | // first remove the XML declaration |
| 225 | 225 | // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
| 226 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
| 227 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
| 228 | - if ( '' == $this->message ) { |
|
| 226 | + $header = preg_replace('/<\?xml.*?\?'.'>/s', '', substr($this->message, 0, 100), 1); |
|
| 227 | + $this->message = trim(substr_replace($this->message, $header, 0, 100)); |
|
| 228 | + if ('' == $this->message) { |
|
| 229 | 229 | return false; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Then remove the DOCTYPE |
| 233 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
| 234 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
| 235 | - if ( '' == $this->message ) { |
|
| 233 | + $header = preg_replace('/^<!DOCTYPE[^>]*+>/i', '', substr($this->message, 0, 200), 1); |
|
| 234 | + $this->message = trim(substr_replace($this->message, $header, 0, 200)); |
|
| 235 | + if ('' == $this->message) { |
|
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // Check that the root tag is valid |
| 240 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
| 241 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
| 240 | + $root_tag = substr($this->message, 0, strcspn(substr($this->message, 0, 20), "> \t\r\n")); |
|
| 241 | + if ('<!DOCTYPE' === strtoupper($root_tag)) { |
|
| 242 | 242 | return false; |
| 243 | 243 | } |
| 244 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
| 244 | + if ( ! in_array($root_tag, array('<methodCall', '<methodResponse', '<fault'))) { |
|
| 245 | 245 | return false; |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Bail if there are too many elements to parse |
| 249 | 249 | $element_limit = 30000; |
| 250 | - if ( function_exists( 'apply_filters' ) ) { |
|
| 250 | + if (function_exists('apply_filters')) { |
|
| 251 | 251 | /** |
| 252 | 252 | * Filter the number of elements to parse in an XML-RPC response. |
| 253 | 253 | * |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @param int $element_limit Default elements limit. |
| 257 | 257 | */ |
| 258 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
| 258 | + $element_limit = apply_filters('xmlrpc_element_limit', $element_limit); |
|
| 259 | 259 | } |
| 260 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
| 260 | + if ($element_limit && 2 * $element_limit < substr_count($this->message, '<')) { |
|
| 261 | 261 | return false; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @param int $chunk_size Chunk size to parse in bytes. |
| 281 | 281 | */ |
| 282 | - $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
| 282 | + $chunk_size = apply_filters('xmlrpc_chunk_parsing_size', $chunk_size); |
|
| 283 | 283 | |
| 284 | 284 | $final = false; |
| 285 | 285 | do { |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | } |
| 289 | 289 | $part = substr($this->message, 0, $chunk_size); |
| 290 | 290 | $this->message = substr($this->message, $chunk_size); |
| 291 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
| 291 | + if ( ! xml_parse($this->_parser, $part, $final)) { |
|
| 292 | 292 | return false; |
| 293 | 293 | } |
| 294 | 294 | if ($final) { |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | { |
| 310 | 310 | $this->_currentTagContents = ''; |
| 311 | 311 | $this->currentTag = $tag; |
| 312 | - switch($tag) { |
|
| 312 | + switch ($tag) { |
|
| 313 | 313 | case 'methodCall': |
| 314 | 314 | case 'methodResponse': |
| 315 | 315 | case 'fault': |
@@ -335,18 +335,18 @@ discard block |
||
| 335 | 335 | function tag_close($parser, $tag) |
| 336 | 336 | { |
| 337 | 337 | $valueFlag = false; |
| 338 | - switch($tag) { |
|
| 338 | + switch ($tag) { |
|
| 339 | 339 | case 'int': |
| 340 | 340 | case 'i4': |
| 341 | - $value = (int)trim($this->_currentTagContents); |
|
| 341 | + $value = (int) trim($this->_currentTagContents); |
|
| 342 | 342 | $valueFlag = true; |
| 343 | 343 | break; |
| 344 | 344 | case 'double': |
| 345 | - $value = (double)trim($this->_currentTagContents); |
|
| 345 | + $value = (double) trim($this->_currentTagContents); |
|
| 346 | 346 | $valueFlag = true; |
| 347 | 347 | break; |
| 348 | 348 | case 'string': |
| 349 | - $value = (string)trim($this->_currentTagContents); |
|
| 349 | + $value = (string) trim($this->_currentTagContents); |
|
| 350 | 350 | $valueFlag = true; |
| 351 | 351 | break; |
| 352 | 352 | case 'dateTime.iso8601': |
@@ -356,12 +356,12 @@ discard block |
||
| 356 | 356 | case 'value': |
| 357 | 357 | // "If no type is indicated, the type is string." |
| 358 | 358 | if (trim($this->_currentTagContents) != '') { |
| 359 | - $value = (string)$this->_currentTagContents; |
|
| 359 | + $value = (string) $this->_currentTagContents; |
|
| 360 | 360 | $valueFlag = true; |
| 361 | 361 | } |
| 362 | 362 | break; |
| 363 | 363 | case 'boolean': |
| 364 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 364 | + $value = (boolean) trim($this->_currentTagContents); |
|
| 365 | 365 | $valueFlag = true; |
| 366 | 366 | break; |
| 367 | 367 | case 'base64': |
@@ -389,12 +389,12 @@ discard block |
||
| 389 | 389 | if ($valueFlag) { |
| 390 | 390 | if (count($this->_arraystructs) > 0) { |
| 391 | 391 | // Add value to struct or array |
| 392 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
| 392 | + if ($this->_arraystructstypes[count($this->_arraystructstypes) - 1] == 'struct') { |
|
| 393 | 393 | // Add to struct |
| 394 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
| 394 | + $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 395 | 395 | } else { |
| 396 | 396 | // Add to array |
| 397 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
| 397 | + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 398 | 398 | } |
| 399 | 399 | } else { |
| 400 | 400 | // Just add as a parameter |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | /** |
| 422 | 422 | * PHP5 constructor. |
| 423 | 423 | */ |
| 424 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
| 424 | + function __construct($callbacks = false, $data = false, $wait = false) |
|
| 425 | 425 | { |
| 426 | 426 | $this->setCapabilities(); |
| 427 | 427 | if ($callbacks) { |
| 428 | 428 | $this->callbacks = $callbacks; |
| 429 | 429 | } |
| 430 | 430 | $this->setCallbacks(); |
| 431 | - if (!$wait) { |
|
| 431 | + if ( ! $wait) { |
|
| 432 | 432 | $this->serve($data); |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -436,17 +436,17 @@ discard block |
||
| 436 | 436 | /** |
| 437 | 437 | * PHP4 constructor. |
| 438 | 438 | */ |
| 439 | - public function IXR_Server( $callbacks = false, $data = false, $wait = false ) { |
|
| 440 | - self::__construct( $callbacks, $data, $wait ); |
|
| 439 | + public function IXR_Server($callbacks = false, $data = false, $wait = false) { |
|
| 440 | + self::__construct($callbacks, $data, $wait); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | function serve($data = false) |
| 444 | 444 | { |
| 445 | - if (!$data) { |
|
| 445 | + if ( ! $data) { |
|
| 446 | 446 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
| 447 | - if ( function_exists( 'status_header' ) ) { |
|
| 448 | - status_header( 405 ); // WP #20986 |
|
| 449 | - header( 'Allow: POST' ); |
|
| 447 | + if (function_exists('status_header')) { |
|
| 448 | + status_header(405); // WP #20986 |
|
| 449 | + header('Allow: POST'); |
|
| 450 | 450 | } |
| 451 | 451 | header('Content-Type: text/plain'); // merged from WP #9093 |
| 452 | 452 | die('XML-RPC server accepts POST requests only.'); |
@@ -457,11 +457,11 @@ discard block |
||
| 457 | 457 | // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
| 458 | 458 | $data = file_get_contents('php://input'); |
| 459 | 459 | } else { |
| 460 | - $data =& $HTTP_RAW_POST_DATA; |
|
| 460 | + $data = & $HTTP_RAW_POST_DATA; |
|
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | $this->message = new IXR_Message($data); |
| 464 | - if (!$this->message->parse()) { |
|
| 464 | + if ( ! $this->message->parse()) { |
|
| 465 | 465 | $this->error(-32700, 'parse error. not well formed'); |
| 466 | 466 | } |
| 467 | 467 | if ($this->message->messageType != 'methodCall') { |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | function call($methodname, $args) |
| 499 | 499 | { |
| 500 | - if (!$this->hasMethod($methodname)) { |
|
| 500 | + if ( ! $this->hasMethod($methodname)) { |
|
| 501 | 501 | return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
| 502 | 502 | } |
| 503 | 503 | $method = $this->callbacks[$methodname]; |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | if (is_string($method) && substr($method, 0, 5) == 'this:') { |
| 513 | 513 | // It's a class method - check it exists |
| 514 | 514 | $method = substr($method, 5); |
| 515 | - if (!method_exists($this, $method)) { |
|
| 515 | + if ( ! method_exists($this, $method)) { |
|
| 516 | 516 | return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
| 517 | 517 | } |
| 518 | 518 | |
@@ -521,10 +521,10 @@ discard block |
||
| 521 | 521 | } else { |
| 522 | 522 | // It's a function - does it exist? |
| 523 | 523 | if (is_array($method)) { |
| 524 | - if (!is_callable(array($method[0], $method[1]))) { |
|
| 524 | + if ( ! is_callable(array($method[0], $method[1]))) { |
|
| 525 | 525 | return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
| 526 | 526 | } |
| 527 | - } else if (!function_exists($method)) { |
|
| 527 | + } else if ( ! function_exists($method)) { |
|
| 528 | 528 | return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | function error($error, $message = false) |
| 538 | 538 | { |
| 539 | 539 | // Accepts either an error object or an error code and message |
| 540 | - if ($message && !is_object($error)) { |
|
| 540 | + if ($message && ! is_object($error)) { |
|
| 541 | 541 | $error = new IXR_Error($error, $message); |
| 542 | 542 | } |
| 543 | 543 | $this->output($error->getXml()); |
@@ -667,8 +667,8 @@ discard block |
||
| 667 | 667 | /** |
| 668 | 668 | * PHP4 constructor. |
| 669 | 669 | */ |
| 670 | - public function IXR_Request( $method, $args ) { |
|
| 671 | - self::__construct( $method, $args ); |
|
| 670 | + public function IXR_Request($method, $args) { |
|
| 671 | + self::__construct($method, $args); |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | function getLength() |
@@ -707,9 +707,9 @@ discard block |
||
| 707 | 707 | /** |
| 708 | 708 | * PHP5 constructor. |
| 709 | 709 | */ |
| 710 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
| 710 | + function __construct($server, $path = false, $port = 80, $timeout = 15) |
|
| 711 | 711 | { |
| 712 | - if (!$path) { |
|
| 712 | + if ( ! $path) { |
|
| 713 | 713 | // Assume we have been given a URL instead |
| 714 | 714 | $bits = parse_url($server); |
| 715 | 715 | $this->server = $bits['host']; |
@@ -717,12 +717,12 @@ discard block |
||
| 717 | 717 | $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
| 718 | 718 | |
| 719 | 719 | // Make absolutely sure we have a path |
| 720 | - if (!$this->path) { |
|
| 720 | + if ( ! $this->path) { |
|
| 721 | 721 | $this->path = '/'; |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - if ( ! empty( $bits['query'] ) ) { |
|
| 725 | - $this->path .= '?' . $bits['query']; |
|
| 724 | + if ( ! empty($bits['query'])) { |
|
| 725 | + $this->path .= '?'.$bits['query']; |
|
| 726 | 726 | } |
| 727 | 727 | } else { |
| 728 | 728 | $this->server = $server; |
@@ -736,8 +736,8 @@ discard block |
||
| 736 | 736 | /** |
| 737 | 737 | * PHP4 constructor. |
| 738 | 738 | */ |
| 739 | - public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) { |
|
| 740 | - self::__construct( $server, $path, $port, $timeout ); |
|
| 739 | + public function IXR_Client($server, $path = false, $port = 80, $timeout = 15) { |
|
| 740 | + self::__construct($server, $path, $port, $timeout); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | function query() |
@@ -748,15 +748,15 @@ discard block |
||
| 748 | 748 | $length = $request->getLength(); |
| 749 | 749 | $xml = $request->getXml(); |
| 750 | 750 | $r = "\r\n"; |
| 751 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 751 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 752 | 752 | |
| 753 | 753 | // Merged from WP #8145 - allow custom headers |
| 754 | 754 | $this->headers['Host'] = $this->server; |
| 755 | 755 | $this->headers['Content-Type'] = 'text/xml'; |
| 756 | 756 | $this->headers['User-Agent'] = $this->useragent; |
| 757 | - $this->headers['Content-Length']= $length; |
|
| 757 | + $this->headers['Content-Length'] = $length; |
|
| 758 | 758 | |
| 759 | - foreach( $this->headers as $header => $value ) { |
|
| 759 | + foreach ($this->headers as $header => $value) { |
|
| 760 | 760 | $request .= "{$header}: {$value}{$r}"; |
| 761 | 761 | } |
| 762 | 762 | $request .= $r; |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | } else { |
| 774 | 774 | $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
| 775 | 775 | } |
| 776 | - if (!$fp) { |
|
| 776 | + if ( ! $fp) { |
|
| 777 | 777 | $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
| 778 | 778 | return false; |
| 779 | 779 | } |
@@ -782,9 +782,9 @@ discard block |
||
| 782 | 782 | $debugContents = ''; |
| 783 | 783 | $gotFirstLine = false; |
| 784 | 784 | $gettingHeaders = true; |
| 785 | - while (!feof($fp)) { |
|
| 785 | + while ( ! feof($fp)) { |
|
| 786 | 786 | $line = fgets($fp, 4096); |
| 787 | - if (!$gotFirstLine) { |
|
| 787 | + if ( ! $gotFirstLine) { |
|
| 788 | 788 | // Check line for '200' |
| 789 | 789 | if (strstr($line, '200') === false) { |
| 790 | 790 | $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | if (trim($line) == '') { |
| 796 | 796 | $gettingHeaders = false; |
| 797 | 797 | } |
| 798 | - if (!$gettingHeaders) { |
|
| 798 | + if ( ! $gettingHeaders) { |
|
| 799 | 799 | // merged from WP #12559 - remove trim |
| 800 | 800 | $contents .= $line; |
| 801 | 801 | } |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | |
| 810 | 810 | // Now parse what we've got back |
| 811 | 811 | $this->message = new IXR_Message($contents); |
| 812 | - if (!$this->message->parse()) { |
|
| 812 | + if ( ! $this->message->parse()) { |
|
| 813 | 813 | // XML error |
| 814 | 814 | $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
| 815 | 815 | return false; |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | /** |
| 863 | 863 | * PHP5 constructor. |
| 864 | 864 | */ |
| 865 | - function __construct( $code, $message ) |
|
| 865 | + function __construct($code, $message) |
|
| 866 | 866 | { |
| 867 | 867 | $this->code = $code; |
| 868 | 868 | $this->message = htmlspecialchars($message); |
@@ -871,8 +871,8 @@ discard block |
||
| 871 | 871 | /** |
| 872 | 872 | * PHP4 constructor. |
| 873 | 873 | */ |
| 874 | - public function IXR_Error( $code, $message ) { |
|
| 875 | - self::__construct( $code, $message ); |
|
| 874 | + public function IXR_Error($code, $message) { |
|
| 875 | + self::__construct($code, $message); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | function getXml() |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | /** |
| 919 | 919 | * PHP5 constructor. |
| 920 | 920 | */ |
| 921 | - function __construct( $time ) |
|
| 921 | + function __construct($time) |
|
| 922 | 922 | { |
| 923 | 923 | // $time can be a PHP timestamp or an ISO one |
| 924 | 924 | if (is_numeric($time)) { |
@@ -931,8 +931,8 @@ discard block |
||
| 931 | 931 | /** |
| 932 | 932 | * PHP4 constructor. |
| 933 | 933 | */ |
| 934 | - public function IXR_Date( $time ) { |
|
| 935 | - self::__construct( $time ); |
|
| 934 | + public function IXR_Date($time) { |
|
| 935 | + self::__construct($time); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | function parseTimestamp($timestamp) |
@@ -986,7 +986,7 @@ discard block |
||
| 986 | 986 | /** |
| 987 | 987 | * PHP5 constructor. |
| 988 | 988 | */ |
| 989 | - function __construct( $data ) |
|
| 989 | + function __construct($data) |
|
| 990 | 990 | { |
| 991 | 991 | $this->data = $data; |
| 992 | 992 | } |
@@ -994,8 +994,8 @@ discard block |
||
| 994 | 994 | /** |
| 995 | 995 | * PHP4 constructor. |
| 996 | 996 | */ |
| 997 | - public function IXR_Base64( $data ) { |
|
| 998 | - self::__construct( $data ); |
|
| 997 | + public function IXR_Base64($data) { |
|
| 998 | + self::__construct($data); |
|
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | function getXml() |
@@ -1069,12 +1069,12 @@ discard block |
||
| 1069 | 1069 | function call($methodname, $args) |
| 1070 | 1070 | { |
| 1071 | 1071 | // Make sure it's in an array |
| 1072 | - if ($args && !is_array($args)) { |
|
| 1072 | + if ($args && ! is_array($args)) { |
|
| 1073 | 1073 | $args = array($args); |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | // Over-rides default call method, adds signature check |
| 1077 | - if (!$this->hasMethod($methodname)) { |
|
| 1077 | + if ( ! $this->hasMethod($methodname)) { |
|
| 1078 | 1078 | return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.'); |
| 1079 | 1079 | } |
| 1080 | 1080 | $method = $this->callbacks[$methodname]; |
@@ -1095,13 +1095,13 @@ discard block |
||
| 1095 | 1095 | switch ($type) { |
| 1096 | 1096 | case 'int': |
| 1097 | 1097 | case 'i4': |
| 1098 | - if (is_array($arg) || !is_int($arg)) { |
|
| 1098 | + if (is_array($arg) || ! is_int($arg)) { |
|
| 1099 | 1099 | $ok = false; |
| 1100 | 1100 | } |
| 1101 | 1101 | break; |
| 1102 | 1102 | case 'base64': |
| 1103 | 1103 | case 'string': |
| 1104 | - if (!is_string($arg)) { |
|
| 1104 | + if ( ! is_string($arg)) { |
|
| 1105 | 1105 | $ok = false; |
| 1106 | 1106 | } |
| 1107 | 1107 | break; |
@@ -1112,18 +1112,18 @@ discard block |
||
| 1112 | 1112 | break; |
| 1113 | 1113 | case 'float': |
| 1114 | 1114 | case 'double': |
| 1115 | - if (!is_float($arg)) { |
|
| 1115 | + if ( ! is_float($arg)) { |
|
| 1116 | 1116 | $ok = false; |
| 1117 | 1117 | } |
| 1118 | 1118 | break; |
| 1119 | 1119 | case 'date': |
| 1120 | 1120 | case 'dateTime.iso8601': |
| 1121 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 1121 | + if ( ! is_a($arg, 'IXR_Date')) { |
|
| 1122 | 1122 | $ok = false; |
| 1123 | 1123 | } |
| 1124 | 1124 | break; |
| 1125 | 1125 | } |
| 1126 | - if (!$ok) { |
|
| 1126 | + if ( ! $ok) { |
|
| 1127 | 1127 | return new IXR_Error(-32602, 'server error. invalid method parameters'); |
| 1128 | 1128 | } |
| 1129 | 1129 | } |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | |
| 1134 | 1134 | function methodSignature($method) |
| 1135 | 1135 | { |
| 1136 | - if (!$this->hasMethod($method)) { |
|
| 1136 | + if ( ! $this->hasMethod($method)) { |
|
| 1137 | 1137 | return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); |
| 1138 | 1138 | } |
| 1139 | 1139 | // We should be returning an array of types |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | /** |
| 1191 | 1191 | * PHP5 constructor. |
| 1192 | 1192 | */ |
| 1193 | - function __construct( $server, $path = false, $port = 80 ) |
|
| 1193 | + function __construct($server, $path = false, $port = 80) |
|
| 1194 | 1194 | { |
| 1195 | 1195 | parent::IXR_Client($server, $path, $port); |
| 1196 | 1196 | $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
@@ -1199,8 +1199,8 @@ discard block |
||
| 1199 | 1199 | /** |
| 1200 | 1200 | * PHP4 constructor. |
| 1201 | 1201 | */ |
| 1202 | - public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) { |
|
| 1203 | - self::__construct( $server, $path, $port ); |
|
| 1202 | + public function IXR_ClientMulticall($server, $path = false, $port = 80) { |
|
| 1203 | + self::__construct($server, $path, $port); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | function addCall() |
@@ -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,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 it's 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 truely |
| 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 it's 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 | } |
@@ -1,69 +1,69 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * mail_fetch/setup.php |
|
| 4 | - * |
|
| 5 | - * Copyright (c) 1999-2011 CDI ([email protected]) All Rights Reserved |
|
| 6 | - * Modified by Philippe Mingo 2001-2009 [email protected] |
|
| 7 | - * An RFC 1939 compliant wrapper class for the POP3 protocol. |
|
| 8 | - * |
|
| 9 | - * Licensed under the GNU GPL. For full terms see the file COPYING. |
|
| 10 | - * |
|
| 11 | - * POP3 class |
|
| 12 | - * |
|
| 13 | - * @copyright 1999-2011 The SquirrelMail Project Team |
|
| 14 | - * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
| 15 | - * @package plugins |
|
| 16 | - * @subpackage mail_fetch |
|
| 17 | - */ |
|
| 3 | + * mail_fetch/setup.php |
|
| 4 | + * |
|
| 5 | + * Copyright (c) 1999-2011 CDI ([email protected]) All Rights Reserved |
|
| 6 | + * Modified by Philippe Mingo 2001-2009 [email protected] |
|
| 7 | + * An RFC 1939 compliant wrapper class for the POP3 protocol. |
|
| 8 | + * |
|
| 9 | + * Licensed under the GNU GPL. For full terms see the file COPYING. |
|
| 10 | + * |
|
| 11 | + * POP3 class |
|
| 12 | + * |
|
| 13 | + * @copyright 1999-2011 The SquirrelMail Project Team |
|
| 14 | + * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
| 15 | + * @package plugins |
|
| 16 | + * @subpackage mail_fetch |
|
| 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 truely |
|
| 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 truely |
|
| 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 | } |
@@ -1614,7 +1614,7 @@ discard block |
||
| 1614 | 1614 | /** |
| 1615 | 1615 | * Get the error message for the occurred error. |
| 1616 | 1616 | * |
| 1617 | - * @return string|array Error message, or array of messages for multifeeds |
|
| 1617 | + * @return string Error message, or array of messages for multifeeds |
|
| 1618 | 1618 | */ |
| 1619 | 1619 | public function error() |
| 1620 | 1620 | { |
@@ -1627,7 +1627,7 @@ discard block |
||
| 1627 | 1627 | * This is the same as the old `$feed->enable_xml_dump(true)`, but returns |
| 1628 | 1628 | * the data instead of printing it. |
| 1629 | 1629 | * |
| 1630 | - * @return string|boolean Raw XML data, false if the cache is used |
|
| 1630 | + * @return string Raw XML data, false if the cache is used |
|
| 1631 | 1631 | */ |
| 1632 | 1632 | public function get_raw_data() |
| 1633 | 1633 | { |
@@ -2607,7 +2607,7 @@ discard block |
||
| 2607 | 2607 | * @since 1.0 |
| 2608 | 2608 | * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo |
| 2609 | 2609 | * @link http://www.georss.org/ GeoRSS |
| 2610 | - * @return string|null |
|
| 2610 | + * @return double|null |
|
| 2611 | 2611 | */ |
| 2612 | 2612 | public function get_latitude() |
| 2613 | 2613 | { |
@@ -2636,7 +2636,7 @@ discard block |
||
| 2636 | 2636 | * @since 1.0 |
| 2637 | 2637 | * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo |
| 2638 | 2638 | * @link http://www.georss.org/ GeoRSS |
| 2639 | - * @return string|null |
|
| 2639 | + * @return double|null |
|
| 2640 | 2640 | */ |
| 2641 | 2641 | public function get_longitude() |
| 2642 | 2642 | { |
@@ -2778,7 +2778,7 @@ discard block |
||
| 2778 | 2778 | * Uses `<image><width>` or defaults to 88.0 if no width is specified and |
| 2779 | 2779 | * the feed is an RSS 2.0 feed. |
| 2780 | 2780 | * |
| 2781 | - * @return int|float|null |
|
| 2781 | + * @return double|null |
|
| 2782 | 2782 | */ |
| 2783 | 2783 | public function get_image_width() |
| 2784 | 2784 | { |
@@ -2804,7 +2804,7 @@ discard block |
||
| 2804 | 2804 | * Uses `<image><height>` or defaults to 31.0 if no height is specified and |
| 2805 | 2805 | * the feed is an RSS 2.0 feed. |
| 2806 | 2806 | * |
| 2807 | - * @return int|float|null |
|
| 2807 | + * @return double|null |
|
| 2808 | 2808 | */ |
| 2809 | 2809 | public function get_image_height() |
| 2810 | 2810 | { |
@@ -22,8 +22,9 @@ discard block |
||
| 22 | 22 | * @since 3.5.0 |
| 23 | 23 | */ |
| 24 | 24 | function wp_simplepie_autoload( $class ) { |
| 25 | - if ( 0 !== strpos( $class, 'SimplePie_' ) ) |
|
| 26 | - return; |
|
| 25 | + if ( 0 !== strpos( $class, 'SimplePie_' ) ) { |
|
| 26 | + return; |
|
| 27 | + } |
|
| 27 | 28 | |
| 28 | 29 | $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; |
| 29 | 30 | include( $file ); |
@@ -784,8 +785,7 @@ discard block |
||
| 784 | 785 | { |
| 785 | 786 | $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1)); |
| 786 | 787 | } |
| 787 | - } |
|
| 788 | - else |
|
| 788 | + } else |
|
| 789 | 789 | { |
| 790 | 790 | $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1)); |
| 791 | 791 | } |
@@ -920,8 +920,7 @@ discard block |
||
| 920 | 920 | if ($encoding) |
| 921 | 921 | { |
| 922 | 922 | $this->input_encoding = (string) $encoding; |
| 923 | - } |
|
| 924 | - else |
|
| 923 | + } else |
|
| 925 | 924 | { |
| 926 | 925 | $this->input_encoding = false; |
| 927 | 926 | } |
@@ -1238,8 +1237,7 @@ discard block |
||
| 1238 | 1237 | if ($page !== false) |
| 1239 | 1238 | { |
| 1240 | 1239 | $this->sanitize->set_image_handler($page . '?' . $qs . '='); |
| 1241 | - } |
|
| 1242 | - else |
|
| 1240 | + } else |
|
| 1243 | 1241 | { |
| 1244 | 1242 | $this->image_handler = ''; |
| 1245 | 1243 | } |
@@ -1317,8 +1315,7 @@ discard block |
||
| 1317 | 1315 | $i++; |
| 1318 | 1316 | } |
| 1319 | 1317 | return (bool) $success; |
| 1320 | - } |
|
| 1321 | - elseif ($this->feed_url === null && $this->raw_data === null) |
|
| 1318 | + } elseif ($this->feed_url === null && $this->raw_data === null) |
|
| 1322 | 1319 | { |
| 1323 | 1320 | return false; |
| 1324 | 1321 | } |
@@ -1342,8 +1339,7 @@ discard block |
||
| 1342 | 1339 | if (($fetched = $this->fetch_data($cache)) === true) |
| 1343 | 1340 | { |
| 1344 | 1341 | return true; |
| 1345 | - } |
|
| 1346 | - elseif ($fetched === false) { |
|
| 1342 | + } elseif ($fetched === false) { |
|
| 1347 | 1343 | return false; |
| 1348 | 1344 | } |
| 1349 | 1345 | |
@@ -1373,8 +1369,7 @@ discard block |
||
| 1373 | 1369 | } |
| 1374 | 1370 | $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); |
| 1375 | 1371 | $encodings[] = 'UTF-8'; |
| 1376 | - } |
|
| 1377 | - elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') |
|
| 1372 | + } elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') |
|
| 1378 | 1373 | { |
| 1379 | 1374 | if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) |
| 1380 | 1375 | { |
@@ -1437,8 +1432,7 @@ discard block |
||
| 1437 | 1432 | { |
| 1438 | 1433 | // We have an error, just set SimplePie_Misc::error to it and quit |
| 1439 | 1434 | $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); |
| 1440 | - } |
|
| 1441 | - else |
|
| 1435 | + } else |
|
| 1442 | 1436 | { |
| 1443 | 1437 | $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.'; |
| 1444 | 1438 | } |
@@ -1520,8 +1514,7 @@ discard block |
||
| 1520 | 1514 | $cache->touch(); |
| 1521 | 1515 | return true; |
| 1522 | 1516 | } |
| 1523 | - } |
|
| 1524 | - else |
|
| 1517 | + } else |
|
| 1525 | 1518 | { |
| 1526 | 1519 | unset($file); |
| 1527 | 1520 | } |
@@ -1547,8 +1540,7 @@ discard block |
||
| 1547 | 1540 | if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) |
| 1548 | 1541 | { |
| 1549 | 1542 | $file =& $this->file; |
| 1550 | - } |
|
| 1551 | - else |
|
| 1543 | + } else |
|
| 1552 | 1544 | { |
| 1553 | 1545 | $headers = array( |
| 1554 | 1546 | 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', |
@@ -1580,8 +1572,7 @@ discard block |
||
| 1580 | 1572 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
| 1581 | 1573 | return false; |
| 1582 | 1574 | } |
| 1583 | - } |
|
| 1584 | - catch (SimplePie_Exception $e) |
|
| 1575 | + } catch (SimplePie_Exception $e) |
|
| 1585 | 1576 | { |
| 1586 | 1577 | // This is usually because DOMDocument doesn't exist |
| 1587 | 1578 | $this->error = $e->getMessage(); |
@@ -1672,8 +1663,7 @@ discard block |
||
| 1672 | 1663 | if ($this->get_encoding()) |
| 1673 | 1664 | { |
| 1674 | 1665 | $header .= ' charset=' . $this->get_encoding(); |
| 1675 | - } |
|
| 1676 | - else |
|
| 1666 | + } else |
|
| 1677 | 1667 | { |
| 1678 | 1668 | $header .= ' charset=UTF-8'; |
| 1679 | 1669 | } |
@@ -1715,12 +1705,10 @@ discard block |
||
| 1715 | 1705 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) |
| 1716 | 1706 | { |
| 1717 | 1707 | $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; |
| 1718 | - } |
|
| 1719 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) |
|
| 1708 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) |
|
| 1720 | 1709 | { |
| 1721 | 1710 | $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; |
| 1722 | - } |
|
| 1723 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) |
|
| 1711 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) |
|
| 1724 | 1712 | { |
| 1725 | 1713 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) |
| 1726 | 1714 | || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) |
@@ -1736,8 +1724,7 @@ discard block |
||
| 1736 | 1724 | { |
| 1737 | 1725 | $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; |
| 1738 | 1726 | } |
| 1739 | - } |
|
| 1740 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) |
|
| 1727 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) |
|
| 1741 | 1728 | { |
| 1742 | 1729 | $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; |
| 1743 | 1730 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) |
@@ -1778,8 +1765,7 @@ discard block |
||
| 1778 | 1765 | break; |
| 1779 | 1766 | } |
| 1780 | 1767 | } |
| 1781 | - } |
|
| 1782 | - else |
|
| 1768 | + } else |
|
| 1783 | 1769 | { |
| 1784 | 1770 | $this->data['type'] = SIMPLEPIE_TYPE_NONE; |
| 1785 | 1771 | } |
@@ -1804,8 +1790,7 @@ discard block |
||
| 1804 | 1790 | if ($this->feed_url !== null) |
| 1805 | 1791 | { |
| 1806 | 1792 | return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); |
| 1807 | - } |
|
| 1808 | - else |
|
| 1793 | + } else |
|
| 1809 | 1794 | { |
| 1810 | 1795 | return null; |
| 1811 | 1796 | } |
@@ -2000,12 +1985,10 @@ discard block |
||
| 2000 | 1985 | if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
| 2001 | 1986 | { |
| 2002 | 1987 | return $element['xml_base']; |
| 2003 | - } |
|
| 2004 | - elseif ($this->get_link() !== null) |
|
| 1988 | + } elseif ($this->get_link() !== null) |
|
| 2005 | 1989 | { |
| 2006 | 1990 | return $this->get_link(); |
| 2007 | - } |
|
| 2008 | - else |
|
| 1991 | + } else |
|
| 2009 | 1992 | { |
| 2010 | 1993 | return $this->subscribe_url(); |
| 2011 | 1994 | } |
@@ -2039,32 +2022,25 @@ discard block |
||
| 2039 | 2022 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) |
| 2040 | 2023 | { |
| 2041 | 2024 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2042 | - } |
|
| 2043 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) |
|
| 2025 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) |
|
| 2044 | 2026 | { |
| 2045 | 2027 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2046 | - } |
|
| 2047 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
|
| 2028 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
|
| 2048 | 2029 | { |
| 2049 | 2030 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2050 | - } |
|
| 2051 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2031 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2052 | 2032 | { |
| 2053 | 2033 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2054 | - } |
|
| 2055 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2034 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2056 | 2035 | { |
| 2057 | 2036 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2058 | - } |
|
| 2059 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2037 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2060 | 2038 | { |
| 2061 | 2039 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2062 | - } |
|
| 2063 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2040 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2064 | 2041 | { |
| 2065 | 2042 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2066 | - } |
|
| 2067 | - else |
|
| 2043 | + } else |
|
| 2068 | 2044 | { |
| 2069 | 2045 | return null; |
| 2070 | 2046 | } |
@@ -2083,8 +2059,7 @@ discard block |
||
| 2083 | 2059 | if (isset($categories[$key])) |
| 2084 | 2060 | { |
| 2085 | 2061 | return $categories[$key]; |
| 2086 | - } |
|
| 2087 | - else |
|
| 2062 | + } else |
|
| 2088 | 2063 | { |
| 2089 | 2064 | return null; |
| 2090 | 2065 | } |
@@ -2129,8 +2104,7 @@ discard block |
||
| 2129 | 2104 | if (isset($category['attribs']['']['domain'])) |
| 2130 | 2105 | { |
| 2131 | 2106 | $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2132 | - } |
|
| 2133 | - else |
|
| 2107 | + } else |
|
| 2134 | 2108 | { |
| 2135 | 2109 | $scheme = null; |
| 2136 | 2110 | } |
@@ -2148,8 +2122,7 @@ discard block |
||
| 2148 | 2122 | if (!empty($categories)) |
| 2149 | 2123 | { |
| 2150 | 2124 | return array_unique($categories); |
| 2151 | - } |
|
| 2152 | - else |
|
| 2125 | + } else |
|
| 2153 | 2126 | { |
| 2154 | 2127 | return null; |
| 2155 | 2128 | } |
@@ -2168,8 +2141,7 @@ discard block |
||
| 2168 | 2141 | if (isset($authors[$key])) |
| 2169 | 2142 | { |
| 2170 | 2143 | return $authors[$key]; |
| 2171 | - } |
|
| 2172 | - else |
|
| 2144 | + } else |
|
| 2173 | 2145 | { |
| 2174 | 2146 | return null; |
| 2175 | 2147 | } |
@@ -2246,8 +2218,7 @@ discard block |
||
| 2246 | 2218 | if (!empty($authors)) |
| 2247 | 2219 | { |
| 2248 | 2220 | return array_unique($authors); |
| 2249 | - } |
|
| 2250 | - else |
|
| 2221 | + } else |
|
| 2251 | 2222 | { |
| 2252 | 2223 | return null; |
| 2253 | 2224 | } |
@@ -2266,8 +2237,7 @@ discard block |
||
| 2266 | 2237 | if (isset($contributors[$key])) |
| 2267 | 2238 | { |
| 2268 | 2239 | return $contributors[$key]; |
| 2269 | - } |
|
| 2270 | - else |
|
| 2240 | + } else |
|
| 2271 | 2241 | { |
| 2272 | 2242 | return null; |
| 2273 | 2243 | } |
@@ -2332,8 +2302,7 @@ discard block |
||
| 2332 | 2302 | if (!empty($contributors)) |
| 2333 | 2303 | { |
| 2334 | 2304 | return array_unique($contributors); |
| 2335 | - } |
|
| 2336 | - else |
|
| 2305 | + } else |
|
| 2337 | 2306 | { |
| 2338 | 2307 | return null; |
| 2339 | 2308 | } |
@@ -2353,8 +2322,7 @@ discard block |
||
| 2353 | 2322 | if (isset($links[$key])) |
| 2354 | 2323 | { |
| 2355 | 2324 | return $links[$key]; |
| 2356 | - } |
|
| 2357 | - else |
|
| 2325 | + } else |
|
| 2358 | 2326 | { |
| 2359 | 2327 | return null; |
| 2360 | 2328 | } |
@@ -2435,13 +2403,11 @@ discard block |
||
| 2435 | 2403 | { |
| 2436 | 2404 | $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); |
| 2437 | 2405 | $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; |
| 2438 | - } |
|
| 2439 | - else |
|
| 2406 | + } else |
|
| 2440 | 2407 | { |
| 2441 | 2408 | $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; |
| 2442 | 2409 | } |
| 2443 | - } |
|
| 2444 | - elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
|
| 2410 | + } elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
|
| 2445 | 2411 | { |
| 2446 | 2412 | $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; |
| 2447 | 2413 | } |
@@ -2452,8 +2418,7 @@ discard block |
||
| 2452 | 2418 | if (isset($this->data['links'][$rel])) |
| 2453 | 2419 | { |
| 2454 | 2420 | return $this->data['links'][$rel]; |
| 2455 | - } |
|
| 2456 | - else |
|
| 2421 | + } else |
|
| 2457 | 2422 | { |
| 2458 | 2423 | return null; |
| 2459 | 2424 | } |
@@ -2478,40 +2443,31 @@ discard block |
||
| 2478 | 2443 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) |
| 2479 | 2444 | { |
| 2480 | 2445 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2481 | - } |
|
| 2482 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) |
|
| 2446 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) |
|
| 2483 | 2447 | { |
| 2484 | 2448 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2485 | - } |
|
| 2486 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) |
|
| 2449 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) |
|
| 2487 | 2450 | { |
| 2488 | 2451 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2489 | - } |
|
| 2490 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) |
|
| 2452 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) |
|
| 2491 | 2453 | { |
| 2492 | 2454 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); |
| 2493 | - } |
|
| 2494 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) |
|
| 2455 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) |
|
| 2495 | 2456 | { |
| 2496 | 2457 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2497 | - } |
|
| 2498 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) |
|
| 2458 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) |
|
| 2499 | 2459 | { |
| 2500 | 2460 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2501 | - } |
|
| 2502 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) |
|
| 2461 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) |
|
| 2503 | 2462 | { |
| 2504 | 2463 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2505 | - } |
|
| 2506 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) |
|
| 2464 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) |
|
| 2507 | 2465 | { |
| 2508 | 2466 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2509 | - } |
|
| 2510 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) |
|
| 2467 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) |
|
| 2511 | 2468 | { |
| 2512 | 2469 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); |
| 2513 | - } |
|
| 2514 | - else |
|
| 2470 | + } else |
|
| 2515 | 2471 | { |
| 2516 | 2472 | return null; |
| 2517 | 2473 | } |
@@ -2530,24 +2486,19 @@ discard block |
||
| 2530 | 2486 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) |
| 2531 | 2487 | { |
| 2532 | 2488 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2533 | - } |
|
| 2534 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) |
|
| 2489 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) |
|
| 2535 | 2490 | { |
| 2536 | 2491 | return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); |
| 2537 | - } |
|
| 2538 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) |
|
| 2492 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) |
|
| 2539 | 2493 | { |
| 2540 | 2494 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2541 | - } |
|
| 2542 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) |
|
| 2495 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) |
|
| 2543 | 2496 | { |
| 2544 | 2497 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2545 | - } |
|
| 2546 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) |
|
| 2498 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) |
|
| 2547 | 2499 | { |
| 2548 | 2500 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2549 | - } |
|
| 2550 | - else |
|
| 2501 | + } else |
|
| 2551 | 2502 | { |
| 2552 | 2503 | return null; |
| 2553 | 2504 | } |
@@ -2566,32 +2517,25 @@ discard block |
||
| 2566 | 2517 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) |
| 2567 | 2518 | { |
| 2568 | 2519 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2569 | - } |
|
| 2570 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) |
|
| 2520 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) |
|
| 2571 | 2521 | { |
| 2572 | 2522 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2573 | - } |
|
| 2574 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) |
|
| 2523 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) |
|
| 2575 | 2524 | { |
| 2576 | 2525 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2577 | - } |
|
| 2578 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) |
|
| 2526 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) |
|
| 2579 | 2527 | { |
| 2580 | 2528 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2581 | - } |
|
| 2582 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) |
|
| 2529 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) |
|
| 2583 | 2530 | { |
| 2584 | 2531 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2585 | - } |
|
| 2586 | - elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) |
|
| 2532 | + } elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) |
|
| 2587 | 2533 | { |
| 2588 | 2534 | return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2589 | - } |
|
| 2590 | - elseif (isset($this->data['headers']['content-language'])) |
|
| 2535 | + } elseif (isset($this->data['headers']['content-language'])) |
|
| 2591 | 2536 | { |
| 2592 | 2537 | return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2593 | - } |
|
| 2594 | - else |
|
| 2538 | + } else |
|
| 2595 | 2539 | { |
| 2596 | 2540 | return null; |
| 2597 | 2541 | } |
@@ -2615,12 +2559,10 @@ discard block |
||
| 2615 | 2559 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) |
| 2616 | 2560 | { |
| 2617 | 2561 | return (float) $return[0]['data']; |
| 2618 | - } |
|
| 2619 | - elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2562 | + } elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2620 | 2563 | { |
| 2621 | 2564 | return (float) $match[1]; |
| 2622 | - } |
|
| 2623 | - else |
|
| 2565 | + } else |
|
| 2624 | 2566 | { |
| 2625 | 2567 | return null; |
| 2626 | 2568 | } |
@@ -2643,16 +2585,13 @@ discard block |
||
| 2643 | 2585 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) |
| 2644 | 2586 | { |
| 2645 | 2587 | return (float) $return[0]['data']; |
| 2646 | - } |
|
| 2647 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) |
|
| 2588 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) |
|
| 2648 | 2589 | { |
| 2649 | 2590 | return (float) $return[0]['data']; |
| 2650 | - } |
|
| 2651 | - elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2591 | + } elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) |
|
| 2652 | 2592 | { |
| 2653 | 2593 | return (float) $match[2]; |
| 2654 | - } |
|
| 2655 | - else |
|
| 2594 | + } else |
|
| 2656 | 2595 | { |
| 2657 | 2596 | return null; |
| 2658 | 2597 | } |
@@ -2672,24 +2611,19 @@ discard block |
||
| 2672 | 2611 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) |
| 2673 | 2612 | { |
| 2674 | 2613 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2675 | - } |
|
| 2676 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2614 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) |
|
| 2677 | 2615 | { |
| 2678 | 2616 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2679 | - } |
|
| 2680 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2617 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) |
|
| 2681 | 2618 | { |
| 2682 | 2619 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2683 | - } |
|
| 2684 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2620 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) |
|
| 2685 | 2621 | { |
| 2686 | 2622 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2687 | - } |
|
| 2688 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2623 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) |
|
| 2689 | 2624 | { |
| 2690 | 2625 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); |
| 2691 | - } |
|
| 2692 | - else |
|
| 2626 | + } else |
|
| 2693 | 2627 | { |
| 2694 | 2628 | return null; |
| 2695 | 2629 | } |
@@ -2711,28 +2645,22 @@ discard block |
||
| 2711 | 2645 | if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) |
| 2712 | 2646 | { |
| 2713 | 2647 | return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); |
| 2714 | - } |
|
| 2715 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) |
|
| 2648 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) |
|
| 2716 | 2649 | { |
| 2717 | 2650 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2718 | - } |
|
| 2719 | - elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) |
|
| 2651 | + } elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) |
|
| 2720 | 2652 | { |
| 2721 | 2653 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2722 | - } |
|
| 2723 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) |
|
| 2654 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) |
|
| 2724 | 2655 | { |
| 2725 | 2656 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2726 | - } |
|
| 2727 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) |
|
| 2657 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) |
|
| 2728 | 2658 | { |
| 2729 | 2659 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2730 | - } |
|
| 2731 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2660 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2732 | 2661 | { |
| 2733 | 2662 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2734 | - } |
|
| 2735 | - else |
|
| 2663 | + } else |
|
| 2736 | 2664 | { |
| 2737 | 2665 | return null; |
| 2738 | 2666 | } |
@@ -2755,16 +2683,13 @@ discard block |
||
| 2755 | 2683 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) |
| 2756 | 2684 | { |
| 2757 | 2685 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2758 | - } |
|
| 2759 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) |
|
| 2686 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) |
|
| 2760 | 2687 | { |
| 2761 | 2688 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2762 | - } |
|
| 2763 | - elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) |
|
| 2689 | + } elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) |
|
| 2764 | 2690 | { |
| 2765 | 2691 | return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); |
| 2766 | - } |
|
| 2767 | - else |
|
| 2692 | + } else |
|
| 2768 | 2693 | { |
| 2769 | 2694 | return null; |
| 2770 | 2695 | } |
@@ -2785,12 +2710,10 @@ discard block |
||
| 2785 | 2710 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) |
| 2786 | 2711 | { |
| 2787 | 2712 | return round($return[0]['data']); |
| 2788 | - } |
|
| 2789 | - elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2713 | + } elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2790 | 2714 | { |
| 2791 | 2715 | return 88.0; |
| 2792 | - } |
|
| 2793 | - else |
|
| 2716 | + } else |
|
| 2794 | 2717 | { |
| 2795 | 2718 | return null; |
| 2796 | 2719 | } |
@@ -2811,12 +2734,10 @@ discard block |
||
| 2811 | 2734 | if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) |
| 2812 | 2735 | { |
| 2813 | 2736 | return round($return[0]['data']); |
| 2814 | - } |
|
| 2815 | - elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2737 | + } elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) |
|
| 2816 | 2738 | { |
| 2817 | 2739 | return 31.0; |
| 2818 | - } |
|
| 2819 | - else |
|
| 2740 | + } else |
|
| 2820 | 2741 | { |
| 2821 | 2742 | return null; |
| 2822 | 2743 | } |
@@ -2838,8 +2759,7 @@ discard block |
||
| 2838 | 2759 | if ($max === 0) |
| 2839 | 2760 | { |
| 2840 | 2761 | return $qty; |
| 2841 | - } |
|
| 2842 | - else |
|
| 2762 | + } else |
|
| 2843 | 2763 | { |
| 2844 | 2764 | return ($qty > $max) ? $max : $qty; |
| 2845 | 2765 | } |
@@ -2863,8 +2783,7 @@ discard block |
||
| 2863 | 2783 | if (isset($items[$key])) |
| 2864 | 2784 | { |
| 2865 | 2785 | return $items[$key]; |
| 2866 | - } |
|
| 2867 | - else |
|
| 2786 | + } else |
|
| 2868 | 2787 | { |
| 2869 | 2788 | return null; |
| 2870 | 2789 | } |
@@ -2890,8 +2809,7 @@ discard block |
||
| 2890 | 2809 | if (!empty($this->multifeed_objects)) |
| 2891 | 2810 | { |
| 2892 | 2811 | $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); |
| 2893 | - } |
|
| 2894 | - else |
|
| 2812 | + } else |
|
| 2895 | 2813 | { |
| 2896 | 2814 | $this->data['items'] = array(); |
| 2897 | 2815 | if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) |
@@ -2961,8 +2879,7 @@ discard block |
||
| 2961 | 2879 | } |
| 2962 | 2880 | } |
| 2963 | 2881 | $items = $this->data['ordered_items']; |
| 2964 | - } |
|
| 2965 | - else |
|
| 2882 | + } else |
|
| 2966 | 2883 | { |
| 2967 | 2884 | $items = $this->data['items']; |
| 2968 | 2885 | } |
@@ -2971,13 +2888,11 @@ discard block |
||
| 2971 | 2888 | if ($end === 0) |
| 2972 | 2889 | { |
| 2973 | 2890 | return array_slice($items, $start); |
| 2974 | - } |
|
| 2975 | - else |
|
| 2891 | + } else |
|
| 2976 | 2892 | { |
| 2977 | 2893 | return array_slice($items, $start, $end); |
| 2978 | 2894 | } |
| 2979 | - } |
|
| 2980 | - else |
|
| 2895 | + } else |
|
| 2981 | 2896 | { |
| 2982 | 2897 | return array(); |
| 2983 | 2898 | } |
@@ -3078,8 +2993,7 @@ discard block |
||
| 3078 | 2993 | if ($arg instanceof SimplePie) |
| 3079 | 2994 | { |
| 3080 | 2995 | $items = array_merge($items, $arg->get_items(0, $limit)); |
| 3081 | - } |
|
| 3082 | - else |
|
| 2996 | + } else |
|
| 3083 | 2997 | { |
| 3084 | 2998 | trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); |
| 3085 | 2999 | } |
@@ -3103,13 +3017,11 @@ discard block |
||
| 3103 | 3017 | if ($end === 0) |
| 3104 | 3018 | { |
| 3105 | 3019 | return array_slice($items, $start); |
| 3106 | - } |
|
| 3107 | - else |
|
| 3020 | + } else |
|
| 3108 | 3021 | { |
| 3109 | 3022 | return array_slice($items, $start, $end); |
| 3110 | 3023 | } |
| 3111 | - } |
|
| 3112 | - else |
|
| 3024 | + } else |
|
| 3113 | 3025 | { |
| 3114 | 3026 | trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); |
| 3115 | 3027 | return array(); |
@@ -1,35 +1,35 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! class_exists( 'SimplePie', false ) ) : |
|
| 2 | +if ( ! class_exists('SimplePie', false)) : |
|
| 3 | 3 | |
| 4 | 4 | // Load classes we will need. |
| 5 | -require ABSPATH . WPINC . '/SimplePie/Misc.php'; |
|
| 6 | -require ABSPATH . WPINC . '/SimplePie/Cache.php'; |
|
| 7 | -require ABSPATH . WPINC . '/SimplePie/File.php'; |
|
| 8 | -require ABSPATH . WPINC . '/SimplePie/Sanitize.php'; |
|
| 9 | -require ABSPATH . WPINC . '/SimplePie/Registry.php'; |
|
| 10 | -require ABSPATH . WPINC . '/SimplePie/IRI.php'; |
|
| 11 | -require ABSPATH . WPINC . '/SimplePie/Locator.php'; |
|
| 12 | -require ABSPATH . WPINC . '/SimplePie/Content/Type/Sniffer.php'; |
|
| 13 | -require ABSPATH . WPINC . '/SimplePie/XML/Declaration/Parser.php'; |
|
| 14 | -require ABSPATH . WPINC . '/SimplePie/Parser.php'; |
|
| 15 | -require ABSPATH . WPINC . '/SimplePie/Item.php'; |
|
| 16 | -require ABSPATH . WPINC . '/SimplePie/Parse/Date.php'; |
|
| 17 | -require ABSPATH . WPINC . '/SimplePie/Author.php'; |
|
| 5 | +require ABSPATH.WPINC.'/SimplePie/Misc.php'; |
|
| 6 | +require ABSPATH.WPINC.'/SimplePie/Cache.php'; |
|
| 7 | +require ABSPATH.WPINC.'/SimplePie/File.php'; |
|
| 8 | +require ABSPATH.WPINC.'/SimplePie/Sanitize.php'; |
|
| 9 | +require ABSPATH.WPINC.'/SimplePie/Registry.php'; |
|
| 10 | +require ABSPATH.WPINC.'/SimplePie/IRI.php'; |
|
| 11 | +require ABSPATH.WPINC.'/SimplePie/Locator.php'; |
|
| 12 | +require ABSPATH.WPINC.'/SimplePie/Content/Type/Sniffer.php'; |
|
| 13 | +require ABSPATH.WPINC.'/SimplePie/XML/Declaration/Parser.php'; |
|
| 14 | +require ABSPATH.WPINC.'/SimplePie/Parser.php'; |
|
| 15 | +require ABSPATH.WPINC.'/SimplePie/Item.php'; |
|
| 16 | +require ABSPATH.WPINC.'/SimplePie/Parse/Date.php'; |
|
| 17 | +require ABSPATH.WPINC.'/SimplePie/Author.php'; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * WordPress autoloader for SimplePie. |
| 21 | 21 | * |
| 22 | 22 | * @since 3.5.0 |
| 23 | 23 | */ |
| 24 | -function wp_simplepie_autoload( $class ) { |
|
| 25 | - if ( 0 !== strpos( $class, 'SimplePie_' ) ) |
|
| 24 | +function wp_simplepie_autoload($class) { |
|
| 25 | + if (0 !== strpos($class, 'SimplePie_')) |
|
| 26 | 26 | return; |
| 27 | 27 | |
| 28 | - $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; |
|
| 29 | - include( $file ); |
|
| 28 | + $file = ABSPATH.WPINC.'/'.str_replace('_', '/', $class).'.php'; |
|
| 29 | + include($file); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | -if ( function_exists( 'spl_autoload_register' ) ) { |
|
| 32 | +if (function_exists('spl_autoload_register')) { |
|
| 33 | 33 | /** |
| 34 | 34 | * We autoload classes we may not need. |
| 35 | 35 | * |
@@ -38,25 +38,25 @@ discard block |
||
| 38 | 38 | * Core.php is not loaded manually, because SimplePie_Core (a deprecated class) |
| 39 | 39 | * was never included in WordPress core. |
| 40 | 40 | */ |
| 41 | - spl_autoload_register( 'wp_simplepie_autoload' ); |
|
| 41 | + spl_autoload_register('wp_simplepie_autoload'); |
|
| 42 | 42 | } else { |
| 43 | - require ABSPATH . WPINC . '/SimplePie/Cache/Base.php'; |
|
| 44 | - require ABSPATH . WPINC . '/SimplePie/Cache/DB.php'; |
|
| 45 | - require ABSPATH . WPINC . '/SimplePie/Cache/File.php'; |
|
| 46 | - require ABSPATH . WPINC . '/SimplePie/Cache/Memcache.php'; |
|
| 47 | - require ABSPATH . WPINC . '/SimplePie/Cache/MySQL.php'; |
|
| 48 | - require ABSPATH . WPINC . '/SimplePie/Caption.php'; |
|
| 49 | - require ABSPATH . WPINC . '/SimplePie/Category.php'; |
|
| 50 | - require ABSPATH . WPINC . '/SimplePie/Copyright.php'; |
|
| 51 | - require ABSPATH . WPINC . '/SimplePie/Credit.php'; |
|
| 52 | - require ABSPATH . WPINC . '/SimplePie/Decode/HTML/Entities.php'; |
|
| 53 | - require ABSPATH . WPINC . '/SimplePie/Enclosure.php'; |
|
| 54 | - require ABSPATH . WPINC . '/SimplePie/gzdecode.php'; |
|
| 55 | - require ABSPATH . WPINC . '/SimplePie/HTTP/Parser.php'; |
|
| 56 | - require ABSPATH . WPINC . '/SimplePie/Net/IPv6.php'; |
|
| 57 | - require ABSPATH . WPINC . '/SimplePie/Rating.php'; |
|
| 58 | - require ABSPATH . WPINC . '/SimplePie/Restriction.php'; |
|
| 59 | - require ABSPATH . WPINC . '/SimplePie/Source.php'; |
|
| 43 | + require ABSPATH.WPINC.'/SimplePie/Cache/Base.php'; |
|
| 44 | + require ABSPATH.WPINC.'/SimplePie/Cache/DB.php'; |
|
| 45 | + require ABSPATH.WPINC.'/SimplePie/Cache/File.php'; |
|
| 46 | + require ABSPATH.WPINC.'/SimplePie/Cache/Memcache.php'; |
|
| 47 | + require ABSPATH.WPINC.'/SimplePie/Cache/MySQL.php'; |
|
| 48 | + require ABSPATH.WPINC.'/SimplePie/Caption.php'; |
|
| 49 | + require ABSPATH.WPINC.'/SimplePie/Category.php'; |
|
| 50 | + require ABSPATH.WPINC.'/SimplePie/Copyright.php'; |
|
| 51 | + require ABSPATH.WPINC.'/SimplePie/Credit.php'; |
|
| 52 | + require ABSPATH.WPINC.'/SimplePie/Decode/HTML/Entities.php'; |
|
| 53 | + require ABSPATH.WPINC.'/SimplePie/Enclosure.php'; |
|
| 54 | + require ABSPATH.WPINC.'/SimplePie/gzdecode.php'; |
|
| 55 | + require ABSPATH.WPINC.'/SimplePie/HTTP/Parser.php'; |
|
| 56 | + require ABSPATH.WPINC.'/SimplePie/Net/IPv6.php'; |
|
| 57 | + require ABSPATH.WPINC.'/SimplePie/Rating.php'; |
|
| 58 | + require ABSPATH.WPINC.'/SimplePie/Restriction.php'; |
|
| 59 | + require ABSPATH.WPINC.'/SimplePie/Source.php'; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | * SimplePie Useragent |
| 128 | 128 | * @see SimplePie::set_useragent() |
| 129 | 129 | */ |
| 130 | -define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); |
|
| 130 | +define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION.' (Feed Parser; '.SIMPLEPIE_URL.'; Allow like Gecko) Build/'.SIMPLEPIE_BUILD); |
|
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * SimplePie Linkback |
| 134 | 134 | */ |
| 135 | -define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); |
|
| 135 | +define('SIMPLEPIE_LINKBACK', '<a href="'.SIMPLEPIE_URL.'" title="'.SIMPLEPIE_NAME.' '.SIMPLEPIE_VERSION.'">'.SIMPLEPIE_NAME.'</a>'); |
|
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * No Autodiscovery |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | */ |
| 726 | 726 | public function __destruct() |
| 727 | 727 | { |
| 728 | - if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) |
|
| 728 | + if ((version_compare(PHP_VERSION, '5.3', '<') || ! gc_enabled()) && ! ini_get('zend.ze1_compatibility_mode')) |
|
| 729 | 729 | { |
| 730 | - if (!empty($this->data['items'])) |
|
| 730 | + if ( ! empty($this->data['items'])) |
|
| 731 | 731 | { |
| 732 | 732 | foreach ($this->data['items'] as $item) |
| 733 | 733 | { |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | } |
| 736 | 736 | unset($item, $this->data['items']); |
| 737 | 737 | } |
| 738 | - if (!empty($this->data['ordered_items'])) |
|
| 738 | + if ( ! empty($this->data['ordered_items'])) |
|
| 739 | 739 | { |
| 740 | 740 | foreach ($this->data['ordered_items'] as $item) |
| 741 | 741 | { |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | if ($file instanceof SimplePie_File) |
| 803 | 803 | { |
| 804 | 804 | $this->feed_url = $file->url; |
| 805 | - $this->file =& $file; |
|
| 805 | + $this->file = & $file; |
|
| 806 | 806 | return true; |
| 807 | 807 | } |
| 808 | 808 | return false; |
@@ -1237,7 +1237,7 @@ discard block |
||
| 1237 | 1237 | { |
| 1238 | 1238 | if ($page !== false) |
| 1239 | 1239 | { |
| 1240 | - $this->sanitize->set_image_handler($page . '?' . $qs . '='); |
|
| 1240 | + $this->sanitize->set_image_handler($page.'?'.$qs.'='); |
|
| 1241 | 1241 | } |
| 1242 | 1242 | else |
| 1243 | 1243 | { |
@@ -1267,12 +1267,12 @@ discard block |
||
| 1267 | 1267 | public function init() |
| 1268 | 1268 | { |
| 1269 | 1269 | // Check absolute bare minimum requirements. |
| 1270 | - if (!extension_loaded('xml') || !extension_loaded('pcre')) |
|
| 1270 | + if ( ! extension_loaded('xml') || ! extension_loaded('pcre')) |
|
| 1271 | 1271 | { |
| 1272 | 1272 | return false; |
| 1273 | 1273 | } |
| 1274 | 1274 | // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader. |
| 1275 | - elseif (!extension_loaded('xmlreader')) |
|
| 1275 | + elseif ( ! extension_loaded('xmlreader')) |
|
| 1276 | 1276 | { |
| 1277 | 1277 | static $xml_is_sane = null; |
| 1278 | 1278 | if ($xml_is_sane === null) |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | xml_parser_free($parser_check); |
| 1283 | 1283 | $xml_is_sane = isset($values[0]['value']); |
| 1284 | 1284 | } |
| 1285 | - if (!$xml_is_sane) |
|
| 1285 | + if ( ! $xml_is_sane) |
|
| 1286 | 1286 | { |
| 1287 | 1287 | return false; |
| 1288 | 1288 | } |
@@ -1298,7 +1298,7 @@ discard block |
||
| 1298 | 1298 | $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); |
| 1299 | 1299 | $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen); |
| 1300 | 1300 | |
| 1301 | - if (!empty($this->multifeed_url)) |
|
| 1301 | + if ( ! empty($this->multifeed_url)) |
|
| 1302 | 1302 | { |
| 1303 | 1303 | $i = 0; |
| 1304 | 1304 | $success = 0; |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | $this->multifeed_objects[$i]->set_feed_url($url); |
| 1311 | 1311 | $single_success = $this->multifeed_objects[$i]->init(); |
| 1312 | 1312 | $success |= $single_success; |
| 1313 | - if (!$single_success) |
|
| 1313 | + if ( ! $single_success) |
|
| 1314 | 1314 | { |
| 1315 | 1315 | $this->error[$i] = $this->multifeed_objects[$i]->error(); |
| 1316 | 1316 | } |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | if ($parser->parse($utf8_data, 'UTF-8')) |
| 1411 | 1411 | { |
| 1412 | 1412 | $this->data = $parser->get_data(); |
| 1413 | - if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) |
|
| 1413 | + if ( ! ($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) |
|
| 1414 | 1414 | { |
| 1415 | 1415 | $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed."; |
| 1416 | 1416 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
@@ -1424,7 +1424,7 @@ discard block |
||
| 1424 | 1424 | $this->data['build'] = SIMPLEPIE_BUILD; |
| 1425 | 1425 | |
| 1426 | 1426 | // Cache the file if caching is enabled |
| 1427 | - if ($cache && !$cache->save($this)) |
|
| 1427 | + if ($cache && ! $cache->save($this)) |
|
| 1428 | 1428 | { |
| 1429 | 1429 | trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); |
| 1430 | 1430 | } |
@@ -1462,10 +1462,10 @@ discard block |
||
| 1462 | 1462 | { |
| 1463 | 1463 | // Load the Cache |
| 1464 | 1464 | $this->data = $cache->load(); |
| 1465 | - if (!empty($this->data)) |
|
| 1465 | + if ( ! empty($this->data)) |
|
| 1466 | 1466 | { |
| 1467 | 1467 | // If the cache is for an outdated build of SimplePie |
| 1468 | - if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) |
|
| 1468 | + if ( ! isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) |
|
| 1469 | 1469 | { |
| 1470 | 1470 | $cache->unlink(); |
| 1471 | 1471 | $this->data = array(); |
@@ -1511,7 +1511,7 @@ discard block |
||
| 1511 | 1511 | $headers['if-none-match'] = $this->data['headers']['etag']; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | - $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen)); |
|
| 1514 | + $file = $this->registry->create('File', array($this->feed_url, $this->timeout / 10, 5, $headers, $this->useragent, $this->force_fsockopen)); |
|
| 1515 | 1515 | |
| 1516 | 1516 | if ($file->success) |
| 1517 | 1517 | { |
@@ -1542,11 +1542,11 @@ discard block |
||
| 1542 | 1542 | } |
| 1543 | 1543 | } |
| 1544 | 1544 | // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it. |
| 1545 | - if (!isset($file)) |
|
| 1545 | + if ( ! isset($file)) |
|
| 1546 | 1546 | { |
| 1547 | 1547 | if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) |
| 1548 | 1548 | { |
| 1549 | - $file =& $this->file; |
|
| 1549 | + $file = & $this->file; |
|
| 1550 | 1550 | } |
| 1551 | 1551 | else |
| 1552 | 1552 | { |
@@ -1557,26 +1557,26 @@ discard block |
||
| 1557 | 1557 | } |
| 1558 | 1558 | } |
| 1559 | 1559 | // If the file connection has an error, set SimplePie::error to that and quit |
| 1560 | - if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) |
|
| 1560 | + if ( ! $file->success && ! ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) |
|
| 1561 | 1561 | { |
| 1562 | 1562 | $this->error = $file->error; |
| 1563 | - return !empty($this->data); |
|
| 1563 | + return ! empty($this->data); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - if (!$this->force_feed) |
|
| 1566 | + if ( ! $this->force_feed) |
|
| 1567 | 1567 | { |
| 1568 | 1568 | // Check if the supplied URL is a feed, if it isn't, look for it. |
| 1569 | 1569 | $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds)); |
| 1570 | 1570 | |
| 1571 | - if (!$locate->is_feed($file)) |
|
| 1571 | + if ( ! $locate->is_feed($file)) |
|
| 1572 | 1572 | { |
| 1573 | 1573 | // We need to unset this so that if SimplePie::set_file() has been called that object is untouched |
| 1574 | 1574 | unset($file); |
| 1575 | 1575 | try |
| 1576 | 1576 | { |
| 1577 | - if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) |
|
| 1577 | + if ( ! ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) |
|
| 1578 | 1578 | { |
| 1579 | - $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; |
|
| 1579 | + $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or ".SIMPLEPIE_NAME." was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; |
|
| 1580 | 1580 | $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); |
| 1581 | 1581 | return false; |
| 1582 | 1582 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | if ($cache) |
| 1592 | 1592 | { |
| 1593 | 1593 | $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); |
| 1594 | - if (!$cache->save($this)) |
|
| 1594 | + if ( ! $cache->save($this)) |
|
| 1595 | 1595 | { |
| 1596 | 1596 | trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); |
| 1597 | 1597 | } |
@@ -1666,12 +1666,12 @@ discard block |
||
| 1666 | 1666 | */ |
| 1667 | 1667 | public function handle_content_type($mime = 'text/html') |
| 1668 | 1668 | { |
| 1669 | - if (!headers_sent()) |
|
| 1669 | + if ( ! headers_sent()) |
|
| 1670 | 1670 | { |
| 1671 | 1671 | $header = "Content-type: $mime;"; |
| 1672 | 1672 | if ($this->get_encoding()) |
| 1673 | 1673 | { |
| 1674 | - $header .= ' charset=' . $this->get_encoding(); |
|
| 1674 | + $header .= ' charset='.$this->get_encoding(); |
|
| 1675 | 1675 | } |
| 1676 | 1676 | else |
| 1677 | 1677 | { |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | */ |
| 1710 | 1710 | public function get_type() |
| 1711 | 1711 | { |
| 1712 | - if (!isset($this->data['type'])) |
|
| 1712 | + if ( ! isset($this->data['type'])) |
|
| 1713 | 1713 | { |
| 1714 | 1714 | $this->data['type'] = SIMPLEPIE_TYPE_ALL; |
| 1715 | 1715 | if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) |
@@ -1997,7 +1997,7 @@ discard block |
||
| 1997 | 1997 | */ |
| 1998 | 1998 | public function get_base($element = array()) |
| 1999 | 1999 | { |
| 2000 | - if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
|
| 2000 | + if ( ! ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && ! empty($element['xml_base_explicit']) && isset($element['xml_base'])) |
|
| 2001 | 2001 | { |
| 2002 | 2002 | return $element['xml_base']; |
| 2003 | 2003 | } |
@@ -2145,7 +2145,7 @@ discard block |
||
| 2145 | 2145 | $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); |
| 2146 | 2146 | } |
| 2147 | 2147 | |
| 2148 | - if (!empty($categories)) |
|
| 2148 | + if ( ! empty($categories)) |
|
| 2149 | 2149 | { |
| 2150 | 2150 | return array_unique($categories); |
| 2151 | 2151 | } |
@@ -2243,7 +2243,7 @@ discard block |
||
| 2243 | 2243 | $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); |
| 2244 | 2244 | } |
| 2245 | 2245 | |
| 2246 | - if (!empty($authors)) |
|
| 2246 | + if ( ! empty($authors)) |
|
| 2247 | 2247 | { |
| 2248 | 2248 | return array_unique($authors); |
| 2249 | 2249 | } |
@@ -2329,7 +2329,7 @@ discard block |
||
| 2329 | 2329 | } |
| 2330 | 2330 | } |
| 2331 | 2331 | |
| 2332 | - if (!empty($contributors)) |
|
| 2332 | + if ( ! empty($contributors)) |
|
| 2333 | 2333 | { |
| 2334 | 2334 | return array_unique($contributors); |
| 2335 | 2335 | } |
@@ -2387,7 +2387,7 @@ discard block |
||
| 2387 | 2387 | */ |
| 2388 | 2388 | public function get_links($rel = 'alternate') |
| 2389 | 2389 | { |
| 2390 | - if (!isset($this->data['links'])) |
|
| 2390 | + if ( ! isset($this->data['links'])) |
|
| 2391 | 2391 | { |
| 2392 | 2392 | $this->data['links'] = array(); |
| 2393 | 2393 | if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) |
@@ -2431,19 +2431,19 @@ discard block |
||
| 2431 | 2431 | { |
| 2432 | 2432 | if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) |
| 2433 | 2433 | { |
| 2434 | - if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) |
|
| 2434 | + if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key])) |
|
| 2435 | 2435 | { |
| 2436 | - $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); |
|
| 2437 | - $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; |
|
| 2436 | + $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]); |
|
| 2437 | + $this->data['links'][$key] = & $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key]; |
|
| 2438 | 2438 | } |
| 2439 | 2439 | else |
| 2440 | 2440 | { |
| 2441 | - $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; |
|
| 2441 | + $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY.$key] = & $this->data['links'][$key]; |
|
| 2442 | 2442 | } |
| 2443 | 2443 | } |
| 2444 | 2444 | elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) |
| 2445 | 2445 | { |
| 2446 | - $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; |
|
| 2446 | + $this->data['links'][substr($key, 41)] = & $this->data['links'][$key]; |
|
| 2447 | 2447 | } |
| 2448 | 2448 | $this->data['links'][$key] = array_unique($this->data['links'][$key]); |
| 2449 | 2449 | } |
@@ -2885,9 +2885,9 @@ discard block |
||
| 2885 | 2885 | */ |
| 2886 | 2886 | public function get_items($start = 0, $end = 0) |
| 2887 | 2887 | { |
| 2888 | - if (!isset($this->data['items'])) |
|
| 2888 | + if ( ! isset($this->data['items'])) |
|
| 2889 | 2889 | { |
| 2890 | - if (!empty($this->multifeed_objects)) |
|
| 2890 | + if ( ! empty($this->multifeed_objects)) |
|
| 2891 | 2891 | { |
| 2892 | 2892 | $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); |
| 2893 | 2893 | } |
@@ -2937,17 +2937,17 @@ discard block |
||
| 2937 | 2937 | } |
| 2938 | 2938 | } |
| 2939 | 2939 | |
| 2940 | - if (!empty($this->data['items'])) |
|
| 2940 | + if ( ! empty($this->data['items'])) |
|
| 2941 | 2941 | { |
| 2942 | 2942 | // If we want to order it by date, check if all items have a date, and then sort it |
| 2943 | 2943 | if ($this->order_by_date && empty($this->multifeed_objects)) |
| 2944 | 2944 | { |
| 2945 | - if (!isset($this->data['ordered_items'])) |
|
| 2945 | + if ( ! isset($this->data['ordered_items'])) |
|
| 2946 | 2946 | { |
| 2947 | 2947 | $do_sort = true; |
| 2948 | 2948 | foreach ($this->data['items'] as $item) |
| 2949 | 2949 | { |
| 2950 | - if (!$item->get_date('U')) |
|
| 2950 | + if ( ! $item->get_date('U')) |
|
| 2951 | 2951 | { |
| 2952 | 2952 | $do_sort = false; |
| 2953 | 2953 | break; |
@@ -3007,7 +3007,7 @@ discard block |
||
| 3007 | 3007 | |
| 3008 | 3008 | if (($url = $this->get_link()) !== null) |
| 3009 | 3009 | { |
| 3010 | - return 'http://g.etfv.co/' . urlencode($url); |
|
| 3010 | + return 'http://g.etfv.co/'.urlencode($url); |
|
| 3011 | 3011 | } |
| 3012 | 3012 | |
| 3013 | 3013 | return false; |
@@ -3088,7 +3088,7 @@ discard block |
||
| 3088 | 3088 | $do_sort = true; |
| 3089 | 3089 | foreach ($items as $item) |
| 3090 | 3090 | { |
| 3091 | - if (!$item->get_date('U')) |
|
| 3091 | + if ( ! $item->get_date('U')) |
|
| 3092 | 3092 | { |
| 3093 | 3093 | $do_sort = false; |
| 3094 | 3094 | break; |
@@ -879,7 +879,7 @@ |
||
| 879 | 879 | * Send raw data to the server. |
| 880 | 880 | * @param string $data The data to send |
| 881 | 881 | * @access public |
| 882 | - * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 882 | + * @return integer The number of bytes sent to the server or false on error |
|
| 883 | 883 | */ |
| 884 | 884 | public function client_send($data) |
| 885 | 885 | { |
@@ -1,21 +1,21 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * PHPMailer RFC821 SMTP email transport class. |
|
| 4 | - * PHP Version 5 |
|
| 5 | - * @package PHPMailer |
|
| 6 | - * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project |
|
| 7 | - * @author Marcus Bointon (Synchro/coolbru) <[email protected]> |
|
| 8 | - * @author Jim Jagielski (jimjag) <[email protected]> |
|
| 9 | - * @author Andy Prevost (codeworxtech) <[email protected]> |
|
| 10 | - * @author Brent R. Matzelle (original founder) |
|
| 11 | - * @copyright 2014 Marcus Bointon |
|
| 12 | - * @copyright 2010 - 2012 Jim Jagielski |
|
| 13 | - * @copyright 2004 - 2009 Andy Prevost |
|
| 14 | - * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
|
| 15 | - * @note This program is distributed in the hope that it will be useful - WITHOUT |
|
| 16 | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
| 17 | - * FITNESS FOR A PARTICULAR PURPOSE. |
|
| 18 | - */ |
|
| 3 | + * PHPMailer RFC821 SMTP email transport class. |
|
| 4 | + * PHP Version 5 |
|
| 5 | + * @package PHPMailer |
|
| 6 | + * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project |
|
| 7 | + * @author Marcus Bointon (Synchro/coolbru) <[email protected]> |
|
| 8 | + * @author Jim Jagielski (jimjag) <[email protected]> |
|
| 9 | + * @author Andy Prevost (codeworxtech) <[email protected]> |
|
| 10 | + * @author Brent R. Matzelle (original founder) |
|
| 11 | + * @copyright 2014 Marcus Bointon |
|
| 12 | + * @copyright 2010 - 2012 Jim Jagielski |
|
| 13 | + * @copyright 2004 - 2009 Andy Prevost |
|
| 14 | + * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License |
|
| 15 | + * @note This program is distributed in the hope that it will be useful - WITHOUT |
|
| 16 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE. |
|
| 18 | + */ |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * PHPMailer RFC821 SMTP email transport class. |
@@ -26,536 +26,536 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | class SMTP |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * The PHPMailer SMTP version number. |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - const VERSION = '5.2.14'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * SMTP line break constant. |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - const CRLF = "\r\n"; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The SMTP port to use if one is not specified. |
|
| 43 | - * @var integer |
|
| 44 | - */ |
|
| 45 | - const DEFAULT_SMTP_PORT = 25; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * The maximum line length allowed by RFC 2822 section 2.1.1 |
|
| 49 | - * @var integer |
|
| 50 | - */ |
|
| 51 | - const MAX_LINE_LENGTH = 998; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Debug level for no output |
|
| 55 | - */ |
|
| 56 | - const DEBUG_OFF = 0; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Debug level to show client -> server messages |
|
| 60 | - */ |
|
| 61 | - const DEBUG_CLIENT = 1; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Debug level to show client -> server and server -> client messages |
|
| 65 | - */ |
|
| 66 | - const DEBUG_SERVER = 2; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Debug level to show connection status, client -> server and server -> client messages |
|
| 70 | - */ |
|
| 71 | - const DEBUG_CONNECTION = 3; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Debug level to show all messages |
|
| 75 | - */ |
|
| 76 | - const DEBUG_LOWLEVEL = 4; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The PHPMailer SMTP Version number. |
|
| 80 | - * @var string |
|
| 81 | - * @deprecated Use the `VERSION` constant instead |
|
| 82 | - * @see SMTP::VERSION |
|
| 83 | - */ |
|
| 84 | - public $Version = '5.2.14'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * SMTP server port number. |
|
| 88 | - * @var integer |
|
| 89 | - * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead |
|
| 90 | - * @see SMTP::DEFAULT_SMTP_PORT |
|
| 91 | - */ |
|
| 92 | - public $SMTP_PORT = 25; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * SMTP reply line ending. |
|
| 96 | - * @var string |
|
| 97 | - * @deprecated Use the `CRLF` constant instead |
|
| 98 | - * @see SMTP::CRLF |
|
| 99 | - */ |
|
| 100 | - public $CRLF = "\r\n"; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Debug output level. |
|
| 104 | - * Options: |
|
| 105 | - * * self::DEBUG_OFF (`0`) No debug output, default |
|
| 106 | - * * self::DEBUG_CLIENT (`1`) Client commands |
|
| 107 | - * * self::DEBUG_SERVER (`2`) Client commands and server responses |
|
| 108 | - * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status |
|
| 109 | - * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages |
|
| 110 | - * @var integer |
|
| 111 | - */ |
|
| 112 | - public $do_debug = self::DEBUG_OFF; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * How to handle debug output. |
|
| 116 | - * Options: |
|
| 117 | - * * `echo` Output plain-text as-is, appropriate for CLI |
|
| 118 | - * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
|
| 119 | - * * `error_log` Output to error log as configured in php.ini |
|
| 120 | - * |
|
| 121 | - * Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
|
| 122 | - * <code> |
|
| 123 | - * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
|
| 124 | - * </code> |
|
| 125 | - * @var string|callable |
|
| 126 | - */ |
|
| 127 | - public $Debugoutput = 'echo'; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Whether to use VERP. |
|
| 131 | - * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path |
|
| 132 | - * @link http://www.postfix.org/VERP_README.html Info on VERP |
|
| 133 | - * @var boolean |
|
| 134 | - */ |
|
| 135 | - public $do_verp = false; |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * The timeout value for connection, in seconds. |
|
| 139 | - * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 140 | - * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure. |
|
| 141 | - * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2 |
|
| 142 | - * @var integer |
|
| 143 | - */ |
|
| 144 | - public $Timeout = 300; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * How long to wait for commands to complete, in seconds. |
|
| 148 | - * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 149 | - * @var integer |
|
| 150 | - */ |
|
| 151 | - public $Timelimit = 300; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * The socket for the server connection. |
|
| 155 | - * @var resource |
|
| 156 | - */ |
|
| 157 | - protected $smtp_conn; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Error information, if any, for the last SMTP command. |
|
| 161 | - * @var array |
|
| 162 | - */ |
|
| 163 | - protected $error = array( |
|
| 164 | - 'error' => '', |
|
| 165 | - 'detail' => '', |
|
| 166 | - 'smtp_code' => '', |
|
| 167 | - 'smtp_code_ex' => '' |
|
| 168 | - ); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * The reply the server sent to us for HELO. |
|
| 172 | - * If null, no HELO string has yet been received. |
|
| 173 | - * @var string|null |
|
| 174 | - */ |
|
| 175 | - protected $helo_rply = null; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * The set of SMTP extensions sent in reply to EHLO command. |
|
| 179 | - * Indexes of the array are extension names. |
|
| 180 | - * Value at index 'HELO' or 'EHLO' (according to command that was sent) |
|
| 181 | - * represents the server name. In case of HELO it is the only element of the array. |
|
| 182 | - * Other values can be boolean TRUE or an array containing extension options. |
|
| 183 | - * If null, no HELO/EHLO string has yet been received. |
|
| 184 | - * @var array|null |
|
| 185 | - */ |
|
| 186 | - protected $server_caps = null; |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * The most recent reply received from the server. |
|
| 190 | - * @var string |
|
| 191 | - */ |
|
| 192 | - protected $last_reply = ''; |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Output debugging info via a user-selected method. |
|
| 196 | - * @see SMTP::$Debugoutput |
|
| 197 | - * @see SMTP::$do_debug |
|
| 198 | - * @param string $str Debug string to output |
|
| 199 | - * @param integer $level The debug level of this message; see DEBUG_* constants |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function edebug($str, $level = 0) |
|
| 203 | - { |
|
| 204 | - if ($level > $this->do_debug) { |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - //Avoid clash with built-in function names |
|
| 208 | - if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | - call_user_func($this->Debugoutput, $str, $this->do_debug); |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - switch ($this->Debugoutput) { |
|
| 213 | - case 'error_log': |
|
| 214 | - //Don't output, just log |
|
| 215 | - error_log($str); |
|
| 216 | - break; |
|
| 217 | - case 'html': |
|
| 218 | - //Cleans up output a bit for a better looking, HTML-safe output |
|
| 219 | - echo htmlentities( |
|
| 220 | - preg_replace('/[\r\n]+/', '', $str), |
|
| 221 | - ENT_QUOTES, |
|
| 222 | - 'UTF-8' |
|
| 223 | - ) |
|
| 224 | - . "<br>\n"; |
|
| 225 | - break; |
|
| 226 | - case 'echo': |
|
| 227 | - default: |
|
| 228 | - //Normalize line breaks |
|
| 229 | - $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
|
| 230 | - echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 231 | - "\n", |
|
| 232 | - "\n \t ", |
|
| 233 | - trim($str) |
|
| 234 | - )."\n"; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Connect to an SMTP server. |
|
| 240 | - * @param string $host SMTP server IP or host name |
|
| 241 | - * @param integer $port The port number to connect to |
|
| 242 | - * @param integer $timeout How long to wait for the connection to open |
|
| 243 | - * @param array $options An array of options for stream_context_create() |
|
| 244 | - * @access public |
|
| 245 | - * @return boolean |
|
| 246 | - */ |
|
| 247 | - public function connect($host, $port = null, $timeout = 30, $options = array()) |
|
| 248 | - { |
|
| 249 | - static $streamok; |
|
| 250 | - //This is enabled by default since 5.0.0 but some providers disable it |
|
| 251 | - //Check this once and cache the result |
|
| 252 | - if (is_null($streamok)) { |
|
| 253 | - $streamok = function_exists('stream_socket_client'); |
|
| 254 | - } |
|
| 255 | - // Clear errors to avoid confusion |
|
| 256 | - $this->setError(''); |
|
| 257 | - // Make sure we are __not__ connected |
|
| 258 | - if ($this->connected()) { |
|
| 259 | - // Already connected, generate error |
|
| 260 | - $this->setError('Already connected to a server'); |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - if (empty($port)) { |
|
| 264 | - $port = self::DEFAULT_SMTP_PORT; |
|
| 265 | - } |
|
| 266 | - // Connect to the SMTP server |
|
| 267 | - $this->edebug( |
|
| 268 | - "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true), |
|
| 269 | - self::DEBUG_CONNECTION |
|
| 270 | - ); |
|
| 271 | - $errno = 0; |
|
| 272 | - $errstr = ''; |
|
| 273 | - if ($streamok) { |
|
| 274 | - $socket_context = stream_context_create($options); |
|
| 275 | - //Suppress errors; connection failures are handled at a higher level |
|
| 276 | - $this->smtp_conn = @stream_socket_client( |
|
| 277 | - $host . ":" . $port, |
|
| 278 | - $errno, |
|
| 279 | - $errstr, |
|
| 280 | - $timeout, |
|
| 281 | - STREAM_CLIENT_CONNECT, |
|
| 282 | - $socket_context |
|
| 283 | - ); |
|
| 284 | - } else { |
|
| 285 | - //Fall back to fsockopen which should work in more places, but is missing some features |
|
| 286 | - $this->edebug( |
|
| 287 | - "Connection: stream_socket_client not available, falling back to fsockopen", |
|
| 288 | - self::DEBUG_CONNECTION |
|
| 289 | - ); |
|
| 290 | - $this->smtp_conn = fsockopen( |
|
| 291 | - $host, |
|
| 292 | - $port, |
|
| 293 | - $errno, |
|
| 294 | - $errstr, |
|
| 295 | - $timeout |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - // Verify we connected properly |
|
| 299 | - if (!is_resource($this->smtp_conn)) { |
|
| 300 | - $this->setError( |
|
| 301 | - 'Failed to connect to server', |
|
| 302 | - $errno, |
|
| 303 | - $errstr |
|
| 304 | - ); |
|
| 305 | - $this->edebug( |
|
| 306 | - 'SMTP ERROR: ' . $this->error['error'] |
|
| 307 | - . ": $errstr ($errno)", |
|
| 308 | - self::DEBUG_CLIENT |
|
| 309 | - ); |
|
| 310 | - return false; |
|
| 311 | - } |
|
| 312 | - $this->edebug('Connection: opened', self::DEBUG_CONNECTION); |
|
| 313 | - // SMTP server can take longer to respond, give longer timeout for first read |
|
| 314 | - // Windows does not have support for this timeout function |
|
| 315 | - if (substr(PHP_OS, 0, 3) != 'WIN') { |
|
| 316 | - $max = ini_get('max_execution_time'); |
|
| 317 | - // Don't bother if unlimited |
|
| 318 | - if ($max != 0 && $timeout > $max) { |
|
| 319 | - @set_time_limit($timeout); |
|
| 320 | - } |
|
| 321 | - stream_set_timeout($this->smtp_conn, $timeout, 0); |
|
| 322 | - } |
|
| 323 | - // Get any announcement |
|
| 324 | - $announce = $this->get_lines(); |
|
| 325 | - $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 326 | - return true; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Initiate a TLS (encrypted) session. |
|
| 331 | - * @access public |
|
| 332 | - * @return boolean |
|
| 333 | - */ |
|
| 334 | - public function startTLS() |
|
| 335 | - { |
|
| 336 | - if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | - return false; |
|
| 338 | - } |
|
| 339 | - // Begin encrypted connection |
|
| 340 | - if (!stream_socket_enable_crypto( |
|
| 341 | - $this->smtp_conn, |
|
| 342 | - true, |
|
| 343 | - STREAM_CRYPTO_METHOD_TLS_CLIENT |
|
| 344 | - )) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - return true; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Perform SMTP authentication. |
|
| 352 | - * Must be run after hello(). |
|
| 353 | - * @see hello() |
|
| 354 | - * @param string $username The user name |
|
| 355 | - * @param string $password The password |
|
| 356 | - * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2) |
|
| 357 | - * @param string $realm The auth realm for NTLM |
|
| 358 | - * @param string $workstation The auth workstation for NTLM |
|
| 359 | - * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth) |
|
| 360 | - * @return bool True if successfully authenticated.* @access public |
|
| 361 | - */ |
|
| 362 | - public function authenticate( |
|
| 363 | - $username, |
|
| 364 | - $password, |
|
| 365 | - $authtype = null, |
|
| 366 | - $realm = '', |
|
| 367 | - $workstation = '', |
|
| 368 | - $OAuth = null |
|
| 369 | - ) { |
|
| 370 | - if (!$this->server_caps) { |
|
| 371 | - $this->setError('Authentication is not allowed before HELO/EHLO'); |
|
| 372 | - return false; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if (array_key_exists('EHLO', $this->server_caps)) { |
|
| 376 | - // SMTP extensions are available. Let's try to find a proper authentication method |
|
| 377 | - |
|
| 378 | - if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 379 | - $this->setError('Authentication is not allowed at this stage'); |
|
| 380 | - // 'at this stage' means that auth may be allowed after the stage changes |
|
| 381 | - // e.g. after STARTTLS |
|
| 382 | - return false; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 386 | - self::edebug( |
|
| 387 | - 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 388 | - self::DEBUG_LOWLEVEL |
|
| 389 | - ); |
|
| 390 | - |
|
| 391 | - if (empty($authtype)) { |
|
| 392 | - foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) { |
|
| 393 | - if (in_array($method, $this->server_caps['AUTH'])) { |
|
| 394 | - $authtype = $method; |
|
| 395 | - break; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - if (empty($authtype)) { |
|
| 399 | - $this->setError('No supported authentication methods found'); |
|
| 400 | - return false; |
|
| 401 | - } |
|
| 402 | - self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 406 | - $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
|
| 407 | - return false; |
|
| 408 | - } |
|
| 409 | - } elseif (empty($authtype)) { |
|
| 410 | - $authtype = 'LOGIN'; |
|
| 411 | - } |
|
| 412 | - switch ($authtype) { |
|
| 413 | - case 'PLAIN': |
|
| 414 | - // Start authentication |
|
| 415 | - if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - // Send encoded username and password |
|
| 419 | - if (!$this->sendCommand( |
|
| 420 | - 'User & Password', |
|
| 421 | - base64_encode("\0" . $username . "\0" . $password), |
|
| 422 | - 235 |
|
| 423 | - ) |
|
| 424 | - ) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - break; |
|
| 428 | - case 'LOGIN': |
|
| 429 | - // Start authentication |
|
| 430 | - if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 434 | - return false; |
|
| 435 | - } |
|
| 436 | - if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 437 | - return false; |
|
| 438 | - } |
|
| 439 | - break; |
|
| 440 | - case 'CRAM-MD5': |
|
| 441 | - // Start authentication |
|
| 442 | - if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - // Get the challenge |
|
| 446 | - $challenge = base64_decode(substr($this->last_reply, 4)); |
|
| 447 | - |
|
| 448 | - // Build the response |
|
| 449 | - $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 450 | - |
|
| 451 | - // send encoded credentials |
|
| 452 | - return $this->sendCommand('Username', base64_encode($response), 235); |
|
| 453 | - default: |
|
| 454 | - $this->setError("Authentication method \"$authtype\" is not supported"); |
|
| 455 | - return false; |
|
| 456 | - } |
|
| 457 | - return true; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Calculate an MD5 HMAC hash. |
|
| 462 | - * Works like hash_hmac('md5', $data, $key) |
|
| 463 | - * in case that function is not available |
|
| 464 | - * @param string $data The data to hash |
|
| 465 | - * @param string $key The key to hash with |
|
| 466 | - * @access protected |
|
| 467 | - * @return string |
|
| 468 | - */ |
|
| 469 | - protected function hmac($data, $key) |
|
| 470 | - { |
|
| 471 | - if (function_exists('hash_hmac')) { |
|
| 472 | - return hash_hmac('md5', $data, $key); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // The following borrowed from |
|
| 476 | - // http://php.net/manual/en/function.mhash.php#27225 |
|
| 477 | - |
|
| 478 | - // RFC 2104 HMAC implementation for php. |
|
| 479 | - // Creates an md5 HMAC. |
|
| 480 | - // Eliminates the need to install mhash to compute a HMAC |
|
| 481 | - // by Lance Rushing |
|
| 482 | - |
|
| 483 | - $bytelen = 64; // byte length for md5 |
|
| 484 | - if (strlen($key) > $bytelen) { |
|
| 485 | - $key = pack('H*', md5($key)); |
|
| 486 | - } |
|
| 487 | - $key = str_pad($key, $bytelen, chr(0x00)); |
|
| 488 | - $ipad = str_pad('', $bytelen, chr(0x36)); |
|
| 489 | - $opad = str_pad('', $bytelen, chr(0x5c)); |
|
| 490 | - $k_ipad = $key ^ $ipad; |
|
| 491 | - $k_opad = $key ^ $opad; |
|
| 492 | - |
|
| 493 | - return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Check connection state. |
|
| 498 | - * @access public |
|
| 499 | - * @return boolean True if connected. |
|
| 500 | - */ |
|
| 501 | - public function connected() |
|
| 502 | - { |
|
| 503 | - if (is_resource($this->smtp_conn)) { |
|
| 504 | - $sock_status = stream_get_meta_data($this->smtp_conn); |
|
| 505 | - if ($sock_status['eof']) { |
|
| 506 | - // The socket is valid but we are not connected |
|
| 507 | - $this->edebug( |
|
| 508 | - 'SMTP NOTICE: EOF caught while checking if connected', |
|
| 509 | - self::DEBUG_CLIENT |
|
| 510 | - ); |
|
| 511 | - $this->close(); |
|
| 512 | - return false; |
|
| 513 | - } |
|
| 514 | - return true; // everything looks good |
|
| 515 | - } |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Close the socket and clean up the state of the class. |
|
| 521 | - * Don't use this function without first trying to use QUIT. |
|
| 522 | - * @see quit() |
|
| 523 | - * @access public |
|
| 524 | - * @return void |
|
| 525 | - */ |
|
| 526 | - public function close() |
|
| 527 | - { |
|
| 528 | - $this->setError(''); |
|
| 529 | - $this->server_caps = null; |
|
| 530 | - $this->helo_rply = null; |
|
| 531 | - if (is_resource($this->smtp_conn)) { |
|
| 532 | - // close the connection and cleanup |
|
| 533 | - fclose($this->smtp_conn); |
|
| 534 | - $this->smtp_conn = null; //Makes for cleaner serialization |
|
| 535 | - $this->edebug('Connection: closed', self::DEBUG_CONNECTION); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Send an SMTP DATA command. |
|
| 541 | - * Issues a data command and sends the msg_data to the server, |
|
| 542 | - * finializing the mail transaction. $msg_data is the message |
|
| 543 | - * that is to be send with the headers. Each header needs to be |
|
| 544 | - * on a single line followed by a <CRLF> with the message headers |
|
| 545 | - * and the message body being separated by and additional <CRLF>. |
|
| 546 | - * Implements rfc 821: DATA <CRLF> |
|
| 547 | - * @param string $msg_data Message data to send |
|
| 548 | - * @access public |
|
| 549 | - * @return boolean |
|
| 550 | - */ |
|
| 551 | - public function data($msg_data) |
|
| 552 | - { |
|
| 553 | - //This will use the standard timelimit |
|
| 554 | - if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /* The server is ready to accept data! |
|
| 29 | + /** |
|
| 30 | + * The PHPMailer SMTP version number. |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + const VERSION = '5.2.14'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * SMTP line break constant. |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + const CRLF = "\r\n"; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The SMTP port to use if one is not specified. |
|
| 43 | + * @var integer |
|
| 44 | + */ |
|
| 45 | + const DEFAULT_SMTP_PORT = 25; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * The maximum line length allowed by RFC 2822 section 2.1.1 |
|
| 49 | + * @var integer |
|
| 50 | + */ |
|
| 51 | + const MAX_LINE_LENGTH = 998; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Debug level for no output |
|
| 55 | + */ |
|
| 56 | + const DEBUG_OFF = 0; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Debug level to show client -> server messages |
|
| 60 | + */ |
|
| 61 | + const DEBUG_CLIENT = 1; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Debug level to show client -> server and server -> client messages |
|
| 65 | + */ |
|
| 66 | + const DEBUG_SERVER = 2; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Debug level to show connection status, client -> server and server -> client messages |
|
| 70 | + */ |
|
| 71 | + const DEBUG_CONNECTION = 3; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Debug level to show all messages |
|
| 75 | + */ |
|
| 76 | + const DEBUG_LOWLEVEL = 4; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The PHPMailer SMTP Version number. |
|
| 80 | + * @var string |
|
| 81 | + * @deprecated Use the `VERSION` constant instead |
|
| 82 | + * @see SMTP::VERSION |
|
| 83 | + */ |
|
| 84 | + public $Version = '5.2.14'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * SMTP server port number. |
|
| 88 | + * @var integer |
|
| 89 | + * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead |
|
| 90 | + * @see SMTP::DEFAULT_SMTP_PORT |
|
| 91 | + */ |
|
| 92 | + public $SMTP_PORT = 25; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * SMTP reply line ending. |
|
| 96 | + * @var string |
|
| 97 | + * @deprecated Use the `CRLF` constant instead |
|
| 98 | + * @see SMTP::CRLF |
|
| 99 | + */ |
|
| 100 | + public $CRLF = "\r\n"; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Debug output level. |
|
| 104 | + * Options: |
|
| 105 | + * * self::DEBUG_OFF (`0`) No debug output, default |
|
| 106 | + * * self::DEBUG_CLIENT (`1`) Client commands |
|
| 107 | + * * self::DEBUG_SERVER (`2`) Client commands and server responses |
|
| 108 | + * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status |
|
| 109 | + * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages |
|
| 110 | + * @var integer |
|
| 111 | + */ |
|
| 112 | + public $do_debug = self::DEBUG_OFF; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * How to handle debug output. |
|
| 116 | + * Options: |
|
| 117 | + * * `echo` Output plain-text as-is, appropriate for CLI |
|
| 118 | + * * `html` Output escaped, line breaks converted to `<br>`, appropriate for browser output |
|
| 119 | + * * `error_log` Output to error log as configured in php.ini |
|
| 120 | + * |
|
| 121 | + * Alternatively, you can provide a callable expecting two params: a message string and the debug level: |
|
| 122 | + * <code> |
|
| 123 | + * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; |
|
| 124 | + * </code> |
|
| 125 | + * @var string|callable |
|
| 126 | + */ |
|
| 127 | + public $Debugoutput = 'echo'; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Whether to use VERP. |
|
| 131 | + * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path |
|
| 132 | + * @link http://www.postfix.org/VERP_README.html Info on VERP |
|
| 133 | + * @var boolean |
|
| 134 | + */ |
|
| 135 | + public $do_verp = false; |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * The timeout value for connection, in seconds. |
|
| 139 | + * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 140 | + * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure. |
|
| 141 | + * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2 |
|
| 142 | + * @var integer |
|
| 143 | + */ |
|
| 144 | + public $Timeout = 300; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * How long to wait for commands to complete, in seconds. |
|
| 148 | + * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 |
|
| 149 | + * @var integer |
|
| 150 | + */ |
|
| 151 | + public $Timelimit = 300; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * The socket for the server connection. |
|
| 155 | + * @var resource |
|
| 156 | + */ |
|
| 157 | + protected $smtp_conn; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Error information, if any, for the last SMTP command. |
|
| 161 | + * @var array |
|
| 162 | + */ |
|
| 163 | + protected $error = array( |
|
| 164 | + 'error' => '', |
|
| 165 | + 'detail' => '', |
|
| 166 | + 'smtp_code' => '', |
|
| 167 | + 'smtp_code_ex' => '' |
|
| 168 | + ); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * The reply the server sent to us for HELO. |
|
| 172 | + * If null, no HELO string has yet been received. |
|
| 173 | + * @var string|null |
|
| 174 | + */ |
|
| 175 | + protected $helo_rply = null; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * The set of SMTP extensions sent in reply to EHLO command. |
|
| 179 | + * Indexes of the array are extension names. |
|
| 180 | + * Value at index 'HELO' or 'EHLO' (according to command that was sent) |
|
| 181 | + * represents the server name. In case of HELO it is the only element of the array. |
|
| 182 | + * Other values can be boolean TRUE or an array containing extension options. |
|
| 183 | + * If null, no HELO/EHLO string has yet been received. |
|
| 184 | + * @var array|null |
|
| 185 | + */ |
|
| 186 | + protected $server_caps = null; |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * The most recent reply received from the server. |
|
| 190 | + * @var string |
|
| 191 | + */ |
|
| 192 | + protected $last_reply = ''; |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Output debugging info via a user-selected method. |
|
| 196 | + * @see SMTP::$Debugoutput |
|
| 197 | + * @see SMTP::$do_debug |
|
| 198 | + * @param string $str Debug string to output |
|
| 199 | + * @param integer $level The debug level of this message; see DEBUG_* constants |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function edebug($str, $level = 0) |
|
| 203 | + { |
|
| 204 | + if ($level > $this->do_debug) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + //Avoid clash with built-in function names |
|
| 208 | + if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | + call_user_func($this->Debugoutput, $str, $this->do_debug); |
|
| 210 | + return; |
|
| 211 | + } |
|
| 212 | + switch ($this->Debugoutput) { |
|
| 213 | + case 'error_log': |
|
| 214 | + //Don't output, just log |
|
| 215 | + error_log($str); |
|
| 216 | + break; |
|
| 217 | + case 'html': |
|
| 218 | + //Cleans up output a bit for a better looking, HTML-safe output |
|
| 219 | + echo htmlentities( |
|
| 220 | + preg_replace('/[\r\n]+/', '', $str), |
|
| 221 | + ENT_QUOTES, |
|
| 222 | + 'UTF-8' |
|
| 223 | + ) |
|
| 224 | + . "<br>\n"; |
|
| 225 | + break; |
|
| 226 | + case 'echo': |
|
| 227 | + default: |
|
| 228 | + //Normalize line breaks |
|
| 229 | + $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
|
| 230 | + echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 231 | + "\n", |
|
| 232 | + "\n \t ", |
|
| 233 | + trim($str) |
|
| 234 | + )."\n"; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Connect to an SMTP server. |
|
| 240 | + * @param string $host SMTP server IP or host name |
|
| 241 | + * @param integer $port The port number to connect to |
|
| 242 | + * @param integer $timeout How long to wait for the connection to open |
|
| 243 | + * @param array $options An array of options for stream_context_create() |
|
| 244 | + * @access public |
|
| 245 | + * @return boolean |
|
| 246 | + */ |
|
| 247 | + public function connect($host, $port = null, $timeout = 30, $options = array()) |
|
| 248 | + { |
|
| 249 | + static $streamok; |
|
| 250 | + //This is enabled by default since 5.0.0 but some providers disable it |
|
| 251 | + //Check this once and cache the result |
|
| 252 | + if (is_null($streamok)) { |
|
| 253 | + $streamok = function_exists('stream_socket_client'); |
|
| 254 | + } |
|
| 255 | + // Clear errors to avoid confusion |
|
| 256 | + $this->setError(''); |
|
| 257 | + // Make sure we are __not__ connected |
|
| 258 | + if ($this->connected()) { |
|
| 259 | + // Already connected, generate error |
|
| 260 | + $this->setError('Already connected to a server'); |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + if (empty($port)) { |
|
| 264 | + $port = self::DEFAULT_SMTP_PORT; |
|
| 265 | + } |
|
| 266 | + // Connect to the SMTP server |
|
| 267 | + $this->edebug( |
|
| 268 | + "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true), |
|
| 269 | + self::DEBUG_CONNECTION |
|
| 270 | + ); |
|
| 271 | + $errno = 0; |
|
| 272 | + $errstr = ''; |
|
| 273 | + if ($streamok) { |
|
| 274 | + $socket_context = stream_context_create($options); |
|
| 275 | + //Suppress errors; connection failures are handled at a higher level |
|
| 276 | + $this->smtp_conn = @stream_socket_client( |
|
| 277 | + $host . ":" . $port, |
|
| 278 | + $errno, |
|
| 279 | + $errstr, |
|
| 280 | + $timeout, |
|
| 281 | + STREAM_CLIENT_CONNECT, |
|
| 282 | + $socket_context |
|
| 283 | + ); |
|
| 284 | + } else { |
|
| 285 | + //Fall back to fsockopen which should work in more places, but is missing some features |
|
| 286 | + $this->edebug( |
|
| 287 | + "Connection: stream_socket_client not available, falling back to fsockopen", |
|
| 288 | + self::DEBUG_CONNECTION |
|
| 289 | + ); |
|
| 290 | + $this->smtp_conn = fsockopen( |
|
| 291 | + $host, |
|
| 292 | + $port, |
|
| 293 | + $errno, |
|
| 294 | + $errstr, |
|
| 295 | + $timeout |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + // Verify we connected properly |
|
| 299 | + if (!is_resource($this->smtp_conn)) { |
|
| 300 | + $this->setError( |
|
| 301 | + 'Failed to connect to server', |
|
| 302 | + $errno, |
|
| 303 | + $errstr |
|
| 304 | + ); |
|
| 305 | + $this->edebug( |
|
| 306 | + 'SMTP ERROR: ' . $this->error['error'] |
|
| 307 | + . ": $errstr ($errno)", |
|
| 308 | + self::DEBUG_CLIENT |
|
| 309 | + ); |
|
| 310 | + return false; |
|
| 311 | + } |
|
| 312 | + $this->edebug('Connection: opened', self::DEBUG_CONNECTION); |
|
| 313 | + // SMTP server can take longer to respond, give longer timeout for first read |
|
| 314 | + // Windows does not have support for this timeout function |
|
| 315 | + if (substr(PHP_OS, 0, 3) != 'WIN') { |
|
| 316 | + $max = ini_get('max_execution_time'); |
|
| 317 | + // Don't bother if unlimited |
|
| 318 | + if ($max != 0 && $timeout > $max) { |
|
| 319 | + @set_time_limit($timeout); |
|
| 320 | + } |
|
| 321 | + stream_set_timeout($this->smtp_conn, $timeout, 0); |
|
| 322 | + } |
|
| 323 | + // Get any announcement |
|
| 324 | + $announce = $this->get_lines(); |
|
| 325 | + $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 326 | + return true; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Initiate a TLS (encrypted) session. |
|
| 331 | + * @access public |
|
| 332 | + * @return boolean |
|
| 333 | + */ |
|
| 334 | + public function startTLS() |
|
| 335 | + { |
|
| 336 | + if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 339 | + // Begin encrypted connection |
|
| 340 | + if (!stream_socket_enable_crypto( |
|
| 341 | + $this->smtp_conn, |
|
| 342 | + true, |
|
| 343 | + STREAM_CRYPTO_METHOD_TLS_CLIENT |
|
| 344 | + )) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + return true; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Perform SMTP authentication. |
|
| 352 | + * Must be run after hello(). |
|
| 353 | + * @see hello() |
|
| 354 | + * @param string $username The user name |
|
| 355 | + * @param string $password The password |
|
| 356 | + * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2) |
|
| 357 | + * @param string $realm The auth realm for NTLM |
|
| 358 | + * @param string $workstation The auth workstation for NTLM |
|
| 359 | + * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth) |
|
| 360 | + * @return bool True if successfully authenticated.* @access public |
|
| 361 | + */ |
|
| 362 | + public function authenticate( |
|
| 363 | + $username, |
|
| 364 | + $password, |
|
| 365 | + $authtype = null, |
|
| 366 | + $realm = '', |
|
| 367 | + $workstation = '', |
|
| 368 | + $OAuth = null |
|
| 369 | + ) { |
|
| 370 | + if (!$this->server_caps) { |
|
| 371 | + $this->setError('Authentication is not allowed before HELO/EHLO'); |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if (array_key_exists('EHLO', $this->server_caps)) { |
|
| 376 | + // SMTP extensions are available. Let's try to find a proper authentication method |
|
| 377 | + |
|
| 378 | + if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 379 | + $this->setError('Authentication is not allowed at this stage'); |
|
| 380 | + // 'at this stage' means that auth may be allowed after the stage changes |
|
| 381 | + // e.g. after STARTTLS |
|
| 382 | + return false; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 386 | + self::edebug( |
|
| 387 | + 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 388 | + self::DEBUG_LOWLEVEL |
|
| 389 | + ); |
|
| 390 | + |
|
| 391 | + if (empty($authtype)) { |
|
| 392 | + foreach (array('LOGIN', 'CRAM-MD5', 'PLAIN') as $method) { |
|
| 393 | + if (in_array($method, $this->server_caps['AUTH'])) { |
|
| 394 | + $authtype = $method; |
|
| 395 | + break; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + if (empty($authtype)) { |
|
| 399 | + $this->setError('No supported authentication methods found'); |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 406 | + $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
|
| 407 | + return false; |
|
| 408 | + } |
|
| 409 | + } elseif (empty($authtype)) { |
|
| 410 | + $authtype = 'LOGIN'; |
|
| 411 | + } |
|
| 412 | + switch ($authtype) { |
|
| 413 | + case 'PLAIN': |
|
| 414 | + // Start authentication |
|
| 415 | + if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + // Send encoded username and password |
|
| 419 | + if (!$this->sendCommand( |
|
| 420 | + 'User & Password', |
|
| 421 | + base64_encode("\0" . $username . "\0" . $password), |
|
| 422 | + 235 |
|
| 423 | + ) |
|
| 424 | + ) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + break; |
|
| 428 | + case 'LOGIN': |
|
| 429 | + // Start authentication |
|
| 430 | + if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 434 | + return false; |
|
| 435 | + } |
|
| 436 | + if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 437 | + return false; |
|
| 438 | + } |
|
| 439 | + break; |
|
| 440 | + case 'CRAM-MD5': |
|
| 441 | + // Start authentication |
|
| 442 | + if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + // Get the challenge |
|
| 446 | + $challenge = base64_decode(substr($this->last_reply, 4)); |
|
| 447 | + |
|
| 448 | + // Build the response |
|
| 449 | + $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 450 | + |
|
| 451 | + // send encoded credentials |
|
| 452 | + return $this->sendCommand('Username', base64_encode($response), 235); |
|
| 453 | + default: |
|
| 454 | + $this->setError("Authentication method \"$authtype\" is not supported"); |
|
| 455 | + return false; |
|
| 456 | + } |
|
| 457 | + return true; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Calculate an MD5 HMAC hash. |
|
| 462 | + * Works like hash_hmac('md5', $data, $key) |
|
| 463 | + * in case that function is not available |
|
| 464 | + * @param string $data The data to hash |
|
| 465 | + * @param string $key The key to hash with |
|
| 466 | + * @access protected |
|
| 467 | + * @return string |
|
| 468 | + */ |
|
| 469 | + protected function hmac($data, $key) |
|
| 470 | + { |
|
| 471 | + if (function_exists('hash_hmac')) { |
|
| 472 | + return hash_hmac('md5', $data, $key); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // The following borrowed from |
|
| 476 | + // http://php.net/manual/en/function.mhash.php#27225 |
|
| 477 | + |
|
| 478 | + // RFC 2104 HMAC implementation for php. |
|
| 479 | + // Creates an md5 HMAC. |
|
| 480 | + // Eliminates the need to install mhash to compute a HMAC |
|
| 481 | + // by Lance Rushing |
|
| 482 | + |
|
| 483 | + $bytelen = 64; // byte length for md5 |
|
| 484 | + if (strlen($key) > $bytelen) { |
|
| 485 | + $key = pack('H*', md5($key)); |
|
| 486 | + } |
|
| 487 | + $key = str_pad($key, $bytelen, chr(0x00)); |
|
| 488 | + $ipad = str_pad('', $bytelen, chr(0x36)); |
|
| 489 | + $opad = str_pad('', $bytelen, chr(0x5c)); |
|
| 490 | + $k_ipad = $key ^ $ipad; |
|
| 491 | + $k_opad = $key ^ $opad; |
|
| 492 | + |
|
| 493 | + return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Check connection state. |
|
| 498 | + * @access public |
|
| 499 | + * @return boolean True if connected. |
|
| 500 | + */ |
|
| 501 | + public function connected() |
|
| 502 | + { |
|
| 503 | + if (is_resource($this->smtp_conn)) { |
|
| 504 | + $sock_status = stream_get_meta_data($this->smtp_conn); |
|
| 505 | + if ($sock_status['eof']) { |
|
| 506 | + // The socket is valid but we are not connected |
|
| 507 | + $this->edebug( |
|
| 508 | + 'SMTP NOTICE: EOF caught while checking if connected', |
|
| 509 | + self::DEBUG_CLIENT |
|
| 510 | + ); |
|
| 511 | + $this->close(); |
|
| 512 | + return false; |
|
| 513 | + } |
|
| 514 | + return true; // everything looks good |
|
| 515 | + } |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Close the socket and clean up the state of the class. |
|
| 521 | + * Don't use this function without first trying to use QUIT. |
|
| 522 | + * @see quit() |
|
| 523 | + * @access public |
|
| 524 | + * @return void |
|
| 525 | + */ |
|
| 526 | + public function close() |
|
| 527 | + { |
|
| 528 | + $this->setError(''); |
|
| 529 | + $this->server_caps = null; |
|
| 530 | + $this->helo_rply = null; |
|
| 531 | + if (is_resource($this->smtp_conn)) { |
|
| 532 | + // close the connection and cleanup |
|
| 533 | + fclose($this->smtp_conn); |
|
| 534 | + $this->smtp_conn = null; //Makes for cleaner serialization |
|
| 535 | + $this->edebug('Connection: closed', self::DEBUG_CONNECTION); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Send an SMTP DATA command. |
|
| 541 | + * Issues a data command and sends the msg_data to the server, |
|
| 542 | + * finializing the mail transaction. $msg_data is the message |
|
| 543 | + * that is to be send with the headers. Each header needs to be |
|
| 544 | + * on a single line followed by a <CRLF> with the message headers |
|
| 545 | + * and the message body being separated by and additional <CRLF>. |
|
| 546 | + * Implements rfc 821: DATA <CRLF> |
|
| 547 | + * @param string $msg_data Message data to send |
|
| 548 | + * @access public |
|
| 549 | + * @return boolean |
|
| 550 | + */ |
|
| 551 | + public function data($msg_data) |
|
| 552 | + { |
|
| 553 | + //This will use the standard timelimit |
|
| 554 | + if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /* The server is ready to accept data! |
|
| 559 | 559 | * According to rfc821 we should not send more than 1000 characters on a single line (including the CRLF) |
| 560 | 560 | * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into |
| 561 | 561 | * smaller lines to fit within the limit. |
@@ -563,556 +563,556 @@ discard block |
||
| 563 | 563 | * NOTE: this does not count towards line-length limit. |
| 564 | 564 | */ |
| 565 | 565 | |
| 566 | - // Normalize line breaks before exploding |
|
| 567 | - $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); |
|
| 566 | + // Normalize line breaks before exploding |
|
| 567 | + $lines = explode("\n", str_replace(array("\r\n", "\r"), "\n", $msg_data)); |
|
| 568 | 568 | |
| 569 | - /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field |
|
| 569 | + /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field |
|
| 570 | 570 | * of the first line (':' separated) does not contain a space then it _should_ be a header and we will |
| 571 | 571 | * process all lines before a blank line as headers. |
| 572 | 572 | */ |
| 573 | 573 | |
| 574 | - $field = substr($lines[0], 0, strpos($lines[0], ':')); |
|
| 575 | - $in_headers = false; |
|
| 576 | - if (!empty($field) && strpos($field, ' ') === false) { |
|
| 577 | - $in_headers = true; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - foreach ($lines as $line) { |
|
| 581 | - $lines_out = array(); |
|
| 582 | - if ($in_headers and $line == '') { |
|
| 583 | - $in_headers = false; |
|
| 584 | - } |
|
| 585 | - //Break this line up into several smaller lines if it's too long |
|
| 586 | - //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len), |
|
| 587 | - while (isset($line[self::MAX_LINE_LENGTH])) { |
|
| 588 | - //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on |
|
| 589 | - //so as to avoid breaking in the middle of a word |
|
| 590 | - $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
|
| 591 | - //Deliberately matches both false and 0 |
|
| 592 | - if (!$pos) { |
|
| 593 | - //No nice break found, add a hard break |
|
| 594 | - $pos = self::MAX_LINE_LENGTH - 1; |
|
| 595 | - $lines_out[] = substr($line, 0, $pos); |
|
| 596 | - $line = substr($line, $pos); |
|
| 597 | - } else { |
|
| 598 | - //Break at the found point |
|
| 599 | - $lines_out[] = substr($line, 0, $pos); |
|
| 600 | - //Move along by the amount we dealt with |
|
| 601 | - $line = substr($line, $pos + 1); |
|
| 602 | - } |
|
| 603 | - //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
|
| 604 | - if ($in_headers) { |
|
| 605 | - $line = "\t" . $line; |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - $lines_out[] = $line; |
|
| 609 | - |
|
| 610 | - //Send the lines to the server |
|
| 611 | - foreach ($lines_out as $line_out) { |
|
| 612 | - //RFC2821 section 4.5.2 |
|
| 613 | - if (!empty($line_out) and $line_out[0] == '.') { |
|
| 614 | - $line_out = '.' . $line_out; |
|
| 615 | - } |
|
| 616 | - $this->client_send($line_out . self::CRLF); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - //Message data has been sent, complete the command |
|
| 621 | - //Increase timelimit for end of DATA command |
|
| 622 | - $savetimelimit = $this->Timelimit; |
|
| 623 | - $this->Timelimit = $this->Timelimit * 2; |
|
| 624 | - $result = $this->sendCommand('DATA END', '.', 250); |
|
| 625 | - //Restore timelimit |
|
| 626 | - $this->Timelimit = $savetimelimit; |
|
| 627 | - return $result; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Send an SMTP HELO or EHLO command. |
|
| 632 | - * Used to identify the sending server to the receiving server. |
|
| 633 | - * This makes sure that client and server are in a known state. |
|
| 634 | - * Implements RFC 821: HELO <SP> <domain> <CRLF> |
|
| 635 | - * and RFC 2821 EHLO. |
|
| 636 | - * @param string $host The host name or IP to connect to |
|
| 637 | - * @access public |
|
| 638 | - * @return boolean |
|
| 639 | - */ |
|
| 640 | - public function hello($host = '') |
|
| 641 | - { |
|
| 642 | - //Try extended hello first (RFC 2821) |
|
| 643 | - return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * Send an SMTP HELO or EHLO command. |
|
| 648 | - * Low-level implementation used by hello() |
|
| 649 | - * @see hello() |
|
| 650 | - * @param string $hello The HELO string |
|
| 651 | - * @param string $host The hostname to say we are |
|
| 652 | - * @access protected |
|
| 653 | - * @return boolean |
|
| 654 | - */ |
|
| 655 | - protected function sendHello($hello, $host) |
|
| 656 | - { |
|
| 657 | - $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 658 | - $this->helo_rply = $this->last_reply; |
|
| 659 | - if ($noerror) { |
|
| 660 | - $this->parseHelloFields($hello); |
|
| 661 | - } else { |
|
| 662 | - $this->server_caps = null; |
|
| 663 | - } |
|
| 664 | - return $noerror; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Parse a reply to HELO/EHLO command to discover server extensions. |
|
| 669 | - * In case of HELO, the only parameter that can be discovered is a server name. |
|
| 670 | - * @access protected |
|
| 671 | - * @param string $type - 'HELO' or 'EHLO' |
|
| 672 | - */ |
|
| 673 | - protected function parseHelloFields($type) |
|
| 674 | - { |
|
| 675 | - $this->server_caps = array(); |
|
| 676 | - $lines = explode("\n", $this->last_reply); |
|
| 677 | - |
|
| 678 | - foreach ($lines as $n => $s) { |
|
| 679 | - //First 4 chars contain response code followed by - or space |
|
| 680 | - $s = trim(substr($s, 4)); |
|
| 681 | - if (empty($s)) { |
|
| 682 | - continue; |
|
| 683 | - } |
|
| 684 | - $fields = explode(' ', $s); |
|
| 685 | - if (!empty($fields)) { |
|
| 686 | - if (!$n) { |
|
| 687 | - $name = $type; |
|
| 688 | - $fields = $fields[0]; |
|
| 689 | - } else { |
|
| 690 | - $name = array_shift($fields); |
|
| 691 | - switch ($name) { |
|
| 692 | - case 'SIZE': |
|
| 693 | - $fields = ($fields ? $fields[0] : 0); |
|
| 694 | - break; |
|
| 695 | - case 'AUTH': |
|
| 696 | - if (!is_array($fields)) { |
|
| 697 | - $fields = array(); |
|
| 698 | - } |
|
| 699 | - break; |
|
| 700 | - default: |
|
| 701 | - $fields = true; |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - $this->server_caps[$name] = $fields; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Send an SMTP MAIL command. |
|
| 711 | - * Starts a mail transaction from the email address specified in |
|
| 712 | - * $from. Returns true if successful or false otherwise. If True |
|
| 713 | - * the mail transaction is started and then one or more recipient |
|
| 714 | - * commands may be called followed by a data command. |
|
| 715 | - * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
| 716 | - * @param string $from Source address of this message |
|
| 717 | - * @access public |
|
| 718 | - * @return boolean |
|
| 719 | - */ |
|
| 720 | - public function mail($from) |
|
| 721 | - { |
|
| 722 | - $useVerp = ($this->do_verp ? ' XVERP' : ''); |
|
| 723 | - return $this->sendCommand( |
|
| 724 | - 'MAIL FROM', |
|
| 725 | - 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 726 | - 250 |
|
| 727 | - ); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Send an SMTP QUIT command. |
|
| 732 | - * Closes the socket if there is no error or the $close_on_error argument is true. |
|
| 733 | - * Implements from rfc 821: QUIT <CRLF> |
|
| 734 | - * @param boolean $close_on_error Should the connection close if an error occurs? |
|
| 735 | - * @access public |
|
| 736 | - * @return boolean |
|
| 737 | - */ |
|
| 738 | - public function quit($close_on_error = true) |
|
| 739 | - { |
|
| 740 | - $noerror = $this->sendCommand('QUIT', 'QUIT', 221); |
|
| 741 | - $err = $this->error; //Save any error |
|
| 742 | - if ($noerror or $close_on_error) { |
|
| 743 | - $this->close(); |
|
| 744 | - $this->error = $err; //Restore any error from the quit command |
|
| 745 | - } |
|
| 746 | - return $noerror; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - /** |
|
| 750 | - * Send an SMTP RCPT command. |
|
| 751 | - * Sets the TO argument to $toaddr. |
|
| 752 | - * Returns true if the recipient was accepted false if it was rejected. |
|
| 753 | - * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
| 754 | - * @param string $address The address the message is being sent to |
|
| 755 | - * @access public |
|
| 756 | - * @return boolean |
|
| 757 | - */ |
|
| 758 | - public function recipient($address) |
|
| 759 | - { |
|
| 760 | - return $this->sendCommand( |
|
| 761 | - 'RCPT TO', |
|
| 762 | - 'RCPT TO:<' . $address . '>', |
|
| 763 | - array(250, 251) |
|
| 764 | - ); |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * Send an SMTP RSET command. |
|
| 769 | - * Abort any transaction that is currently in progress. |
|
| 770 | - * Implements rfc 821: RSET <CRLF> |
|
| 771 | - * @access public |
|
| 772 | - * @return boolean True on success. |
|
| 773 | - */ |
|
| 774 | - public function reset() |
|
| 775 | - { |
|
| 776 | - return $this->sendCommand('RSET', 'RSET', 250); |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Send a command to an SMTP server and check its return code. |
|
| 781 | - * @param string $command The command name - not sent to the server |
|
| 782 | - * @param string $commandstring The actual command to send |
|
| 783 | - * @param integer|array $expect One or more expected integer success codes |
|
| 784 | - * @access protected |
|
| 785 | - * @return boolean True on success. |
|
| 786 | - */ |
|
| 787 | - protected function sendCommand($command, $commandstring, $expect) |
|
| 788 | - { |
|
| 789 | - if (!$this->connected()) { |
|
| 790 | - $this->setError("Called $command without being connected"); |
|
| 791 | - return false; |
|
| 792 | - } |
|
| 793 | - //Reject line breaks in all commands |
|
| 794 | - if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) { |
|
| 795 | - $this->setError("Command '$command' contained line breaks"); |
|
| 796 | - return false; |
|
| 797 | - } |
|
| 798 | - $this->client_send($commandstring . self::CRLF); |
|
| 799 | - |
|
| 800 | - $this->last_reply = $this->get_lines(); |
|
| 801 | - // Fetch SMTP code and possible error code explanation |
|
| 802 | - $matches = array(); |
|
| 803 | - if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) { |
|
| 804 | - $code = $matches[1]; |
|
| 805 | - $code_ex = (count($matches) > 2 ? $matches[2] : null); |
|
| 806 | - // Cut off error code from each response line |
|
| 807 | - $detail = preg_replace( |
|
| 808 | - "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m", |
|
| 809 | - '', |
|
| 810 | - $this->last_reply |
|
| 811 | - ); |
|
| 812 | - } else { |
|
| 813 | - // Fall back to simple parsing if regex fails |
|
| 814 | - $code = substr($this->last_reply, 0, 3); |
|
| 815 | - $code_ex = null; |
|
| 816 | - $detail = substr($this->last_reply, 4); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 820 | - |
|
| 821 | - if (!in_array($code, (array)$expect)) { |
|
| 822 | - $this->setError( |
|
| 823 | - "$command command failed", |
|
| 824 | - $detail, |
|
| 825 | - $code, |
|
| 826 | - $code_ex |
|
| 827 | - ); |
|
| 828 | - $this->edebug( |
|
| 829 | - 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 830 | - self::DEBUG_CLIENT |
|
| 831 | - ); |
|
| 832 | - return false; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - $this->setError(''); |
|
| 836 | - return true; |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * Send an SMTP SAML command. |
|
| 841 | - * Starts a mail transaction from the email address specified in $from. |
|
| 842 | - * Returns true if successful or false otherwise. If True |
|
| 843 | - * the mail transaction is started and then one or more recipient |
|
| 844 | - * commands may be called followed by a data command. This command |
|
| 845 | - * will send the message to the users terminal if they are logged |
|
| 846 | - * in and send them an email. |
|
| 847 | - * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|
| 848 | - * @param string $from The address the message is from |
|
| 849 | - * @access public |
|
| 850 | - * @return boolean |
|
| 851 | - */ |
|
| 852 | - public function sendAndMail($from) |
|
| 853 | - { |
|
| 854 | - return $this->sendCommand('SAML', "SAML FROM:$from", 250); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Send an SMTP VRFY command. |
|
| 859 | - * @param string $name The name to verify |
|
| 860 | - * @access public |
|
| 861 | - * @return boolean |
|
| 862 | - */ |
|
| 863 | - public function verify($name) |
|
| 864 | - { |
|
| 865 | - return $this->sendCommand('VRFY', "VRFY $name", array(250, 251)); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * Send an SMTP NOOP command. |
|
| 870 | - * Used to keep keep-alives alive, doesn't actually do anything |
|
| 871 | - * @access public |
|
| 872 | - * @return boolean |
|
| 873 | - */ |
|
| 874 | - public function noop() |
|
| 875 | - { |
|
| 876 | - return $this->sendCommand('NOOP', 'NOOP', 250); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /** |
|
| 880 | - * Send an SMTP TURN command. |
|
| 881 | - * This is an optional command for SMTP that this class does not support. |
|
| 882 | - * This method is here to make the RFC821 Definition complete for this class |
|
| 883 | - * and _may_ be implemented in future |
|
| 884 | - * Implements from rfc 821: TURN <CRLF> |
|
| 885 | - * @access public |
|
| 886 | - * @return boolean |
|
| 887 | - */ |
|
| 888 | - public function turn() |
|
| 889 | - { |
|
| 890 | - $this->setError('The SMTP TURN command is not implemented'); |
|
| 891 | - $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * Send raw data to the server. |
|
| 897 | - * @param string $data The data to send |
|
| 898 | - * @access public |
|
| 899 | - * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 900 | - */ |
|
| 901 | - public function client_send($data) |
|
| 902 | - { |
|
| 903 | - $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT); |
|
| 904 | - return fwrite($this->smtp_conn, $data); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * Get the latest error. |
|
| 909 | - * @access public |
|
| 910 | - * @return array |
|
| 911 | - */ |
|
| 912 | - public function getError() |
|
| 913 | - { |
|
| 914 | - return $this->error; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Get SMTP extensions available on the server |
|
| 919 | - * @access public |
|
| 920 | - * @return array|null |
|
| 921 | - */ |
|
| 922 | - public function getServerExtList() |
|
| 923 | - { |
|
| 924 | - return $this->server_caps; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * A multipurpose method |
|
| 929 | - * The method works in three ways, dependent on argument value and current state |
|
| 930 | - * 1. HELO/EHLO was not sent - returns null and set up $this->error |
|
| 931 | - * 2. HELO was sent |
|
| 932 | - * $name = 'HELO': returns server name |
|
| 933 | - * $name = 'EHLO': returns boolean false |
|
| 934 | - * $name = any string: returns null and set up $this->error |
|
| 935 | - * 3. EHLO was sent |
|
| 936 | - * $name = 'HELO'|'EHLO': returns server name |
|
| 937 | - * $name = any string: if extension $name exists, returns boolean True |
|
| 938 | - * or its options. Otherwise returns boolean False |
|
| 939 | - * In other words, one can use this method to detect 3 conditions: |
|
| 940 | - * - null returned: handshake was not or we don't know about ext (refer to $this->error) |
|
| 941 | - * - false returned: the requested feature exactly not exists |
|
| 942 | - * - positive value returned: the requested feature exists |
|
| 943 | - * @param string $name Name of SMTP extension or 'HELO'|'EHLO' |
|
| 944 | - * @return mixed |
|
| 945 | - */ |
|
| 946 | - public function getServerExt($name) |
|
| 947 | - { |
|
| 948 | - if (!$this->server_caps) { |
|
| 949 | - $this->setError('No HELO/EHLO was sent'); |
|
| 950 | - return null; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - // the tight logic knot ;) |
|
| 954 | - if (!array_key_exists($name, $this->server_caps)) { |
|
| 955 | - if ($name == 'HELO') { |
|
| 956 | - return $this->server_caps['EHLO']; |
|
| 957 | - } |
|
| 958 | - if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) { |
|
| 959 | - return false; |
|
| 960 | - } |
|
| 961 | - $this->setError('HELO handshake was used. Client knows nothing about server extensions'); |
|
| 962 | - return null; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - return $this->server_caps[$name]; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - /** |
|
| 969 | - * Get the last reply from the server. |
|
| 970 | - * @access public |
|
| 971 | - * @return string |
|
| 972 | - */ |
|
| 973 | - public function getLastReply() |
|
| 974 | - { |
|
| 975 | - return $this->last_reply; |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Read the SMTP server's response. |
|
| 980 | - * Either before eof or socket timeout occurs on the operation. |
|
| 981 | - * With SMTP we can tell if we have more lines to read if the |
|
| 982 | - * 4th character is '-' symbol. If it is a space then we don't |
|
| 983 | - * need to read anything else. |
|
| 984 | - * @access protected |
|
| 985 | - * @return string |
|
| 986 | - */ |
|
| 987 | - protected function get_lines() |
|
| 988 | - { |
|
| 989 | - // If the connection is bad, give up straight away |
|
| 990 | - if (!is_resource($this->smtp_conn)) { |
|
| 991 | - return ''; |
|
| 992 | - } |
|
| 993 | - $data = ''; |
|
| 994 | - $endtime = 0; |
|
| 995 | - stream_set_timeout($this->smtp_conn, $this->Timeout); |
|
| 996 | - if ($this->Timelimit > 0) { |
|
| 997 | - $endtime = time() + $this->Timelimit; |
|
| 998 | - } |
|
| 999 | - while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 1000 | - $str = @fgets($this->smtp_conn, 515); |
|
| 1001 | - $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 1002 | - $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
|
| 1003 | - $data .= $str; |
|
| 1004 | - // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen |
|
| 1005 | - if ((isset($str[3]) and $str[3] == ' ')) { |
|
| 1006 | - break; |
|
| 1007 | - } |
|
| 1008 | - // Timed-out? Log and break |
|
| 1009 | - $info = stream_get_meta_data($this->smtp_conn); |
|
| 1010 | - if ($info['timed_out']) { |
|
| 1011 | - $this->edebug( |
|
| 1012 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 1013 | - self::DEBUG_LOWLEVEL |
|
| 1014 | - ); |
|
| 1015 | - break; |
|
| 1016 | - } |
|
| 1017 | - // Now check if reads took too long |
|
| 1018 | - if ($endtime and time() > $endtime) { |
|
| 1019 | - $this->edebug( |
|
| 1020 | - 'SMTP -> get_lines(): timelimit reached ('. |
|
| 1021 | - $this->Timelimit . ' sec)', |
|
| 1022 | - self::DEBUG_LOWLEVEL |
|
| 1023 | - ); |
|
| 1024 | - break; |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - return $data; |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Enable or disable VERP address generation. |
|
| 1032 | - * @param boolean $enabled |
|
| 1033 | - */ |
|
| 1034 | - public function setVerp($enabled = false) |
|
| 1035 | - { |
|
| 1036 | - $this->do_verp = $enabled; |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - /** |
|
| 1040 | - * Get VERP address generation mode. |
|
| 1041 | - * @return boolean |
|
| 1042 | - */ |
|
| 1043 | - public function getVerp() |
|
| 1044 | - { |
|
| 1045 | - return $this->do_verp; |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - /** |
|
| 1049 | - * Set error messages and codes. |
|
| 1050 | - * @param string $message The error message |
|
| 1051 | - * @param string $detail Further detail on the error |
|
| 1052 | - * @param string $smtp_code An associated SMTP error code |
|
| 1053 | - * @param string $smtp_code_ex Extended SMTP code |
|
| 1054 | - */ |
|
| 1055 | - protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') |
|
| 1056 | - { |
|
| 1057 | - $this->error = array( |
|
| 1058 | - 'error' => $message, |
|
| 1059 | - 'detail' => $detail, |
|
| 1060 | - 'smtp_code' => $smtp_code, |
|
| 1061 | - 'smtp_code_ex' => $smtp_code_ex |
|
| 1062 | - ); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - /** |
|
| 1066 | - * Set debug output method. |
|
| 1067 | - * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it. |
|
| 1068 | - */ |
|
| 1069 | - public function setDebugOutput($method = 'echo') |
|
| 1070 | - { |
|
| 1071 | - $this->Debugoutput = $method; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * Get debug output method. |
|
| 1076 | - * @return string |
|
| 1077 | - */ |
|
| 1078 | - public function getDebugOutput() |
|
| 1079 | - { |
|
| 1080 | - return $this->Debugoutput; |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Set debug output level. |
|
| 1085 | - * @param integer $level |
|
| 1086 | - */ |
|
| 1087 | - public function setDebugLevel($level = 0) |
|
| 1088 | - { |
|
| 1089 | - $this->do_debug = $level; |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - /** |
|
| 1093 | - * Get debug output level. |
|
| 1094 | - * @return integer |
|
| 1095 | - */ |
|
| 1096 | - public function getDebugLevel() |
|
| 1097 | - { |
|
| 1098 | - return $this->do_debug; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * Set SMTP timeout. |
|
| 1103 | - * @param integer $timeout |
|
| 1104 | - */ |
|
| 1105 | - public function setTimeout($timeout = 0) |
|
| 1106 | - { |
|
| 1107 | - $this->Timeout = $timeout; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - /** |
|
| 1111 | - * Get SMTP timeout. |
|
| 1112 | - * @return integer |
|
| 1113 | - */ |
|
| 1114 | - public function getTimeout() |
|
| 1115 | - { |
|
| 1116 | - return $this->Timeout; |
|
| 1117 | - } |
|
| 574 | + $field = substr($lines[0], 0, strpos($lines[0], ':')); |
|
| 575 | + $in_headers = false; |
|
| 576 | + if (!empty($field) && strpos($field, ' ') === false) { |
|
| 577 | + $in_headers = true; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + foreach ($lines as $line) { |
|
| 581 | + $lines_out = array(); |
|
| 582 | + if ($in_headers and $line == '') { |
|
| 583 | + $in_headers = false; |
|
| 584 | + } |
|
| 585 | + //Break this line up into several smaller lines if it's too long |
|
| 586 | + //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len), |
|
| 587 | + while (isset($line[self::MAX_LINE_LENGTH])) { |
|
| 588 | + //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on |
|
| 589 | + //so as to avoid breaking in the middle of a word |
|
| 590 | + $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
|
| 591 | + //Deliberately matches both false and 0 |
|
| 592 | + if (!$pos) { |
|
| 593 | + //No nice break found, add a hard break |
|
| 594 | + $pos = self::MAX_LINE_LENGTH - 1; |
|
| 595 | + $lines_out[] = substr($line, 0, $pos); |
|
| 596 | + $line = substr($line, $pos); |
|
| 597 | + } else { |
|
| 598 | + //Break at the found point |
|
| 599 | + $lines_out[] = substr($line, 0, $pos); |
|
| 600 | + //Move along by the amount we dealt with |
|
| 601 | + $line = substr($line, $pos + 1); |
|
| 602 | + } |
|
| 603 | + //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
|
| 604 | + if ($in_headers) { |
|
| 605 | + $line = "\t" . $line; |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + $lines_out[] = $line; |
|
| 609 | + |
|
| 610 | + //Send the lines to the server |
|
| 611 | + foreach ($lines_out as $line_out) { |
|
| 612 | + //RFC2821 section 4.5.2 |
|
| 613 | + if (!empty($line_out) and $line_out[0] == '.') { |
|
| 614 | + $line_out = '.' . $line_out; |
|
| 615 | + } |
|
| 616 | + $this->client_send($line_out . self::CRLF); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + //Message data has been sent, complete the command |
|
| 621 | + //Increase timelimit for end of DATA command |
|
| 622 | + $savetimelimit = $this->Timelimit; |
|
| 623 | + $this->Timelimit = $this->Timelimit * 2; |
|
| 624 | + $result = $this->sendCommand('DATA END', '.', 250); |
|
| 625 | + //Restore timelimit |
|
| 626 | + $this->Timelimit = $savetimelimit; |
|
| 627 | + return $result; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Send an SMTP HELO or EHLO command. |
|
| 632 | + * Used to identify the sending server to the receiving server. |
|
| 633 | + * This makes sure that client and server are in a known state. |
|
| 634 | + * Implements RFC 821: HELO <SP> <domain> <CRLF> |
|
| 635 | + * and RFC 2821 EHLO. |
|
| 636 | + * @param string $host The host name or IP to connect to |
|
| 637 | + * @access public |
|
| 638 | + * @return boolean |
|
| 639 | + */ |
|
| 640 | + public function hello($host = '') |
|
| 641 | + { |
|
| 642 | + //Try extended hello first (RFC 2821) |
|
| 643 | + return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * Send an SMTP HELO or EHLO command. |
|
| 648 | + * Low-level implementation used by hello() |
|
| 649 | + * @see hello() |
|
| 650 | + * @param string $hello The HELO string |
|
| 651 | + * @param string $host The hostname to say we are |
|
| 652 | + * @access protected |
|
| 653 | + * @return boolean |
|
| 654 | + */ |
|
| 655 | + protected function sendHello($hello, $host) |
|
| 656 | + { |
|
| 657 | + $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 658 | + $this->helo_rply = $this->last_reply; |
|
| 659 | + if ($noerror) { |
|
| 660 | + $this->parseHelloFields($hello); |
|
| 661 | + } else { |
|
| 662 | + $this->server_caps = null; |
|
| 663 | + } |
|
| 664 | + return $noerror; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Parse a reply to HELO/EHLO command to discover server extensions. |
|
| 669 | + * In case of HELO, the only parameter that can be discovered is a server name. |
|
| 670 | + * @access protected |
|
| 671 | + * @param string $type - 'HELO' or 'EHLO' |
|
| 672 | + */ |
|
| 673 | + protected function parseHelloFields($type) |
|
| 674 | + { |
|
| 675 | + $this->server_caps = array(); |
|
| 676 | + $lines = explode("\n", $this->last_reply); |
|
| 677 | + |
|
| 678 | + foreach ($lines as $n => $s) { |
|
| 679 | + //First 4 chars contain response code followed by - or space |
|
| 680 | + $s = trim(substr($s, 4)); |
|
| 681 | + if (empty($s)) { |
|
| 682 | + continue; |
|
| 683 | + } |
|
| 684 | + $fields = explode(' ', $s); |
|
| 685 | + if (!empty($fields)) { |
|
| 686 | + if (!$n) { |
|
| 687 | + $name = $type; |
|
| 688 | + $fields = $fields[0]; |
|
| 689 | + } else { |
|
| 690 | + $name = array_shift($fields); |
|
| 691 | + switch ($name) { |
|
| 692 | + case 'SIZE': |
|
| 693 | + $fields = ($fields ? $fields[0] : 0); |
|
| 694 | + break; |
|
| 695 | + case 'AUTH': |
|
| 696 | + if (!is_array($fields)) { |
|
| 697 | + $fields = array(); |
|
| 698 | + } |
|
| 699 | + break; |
|
| 700 | + default: |
|
| 701 | + $fields = true; |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + $this->server_caps[$name] = $fields; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Send an SMTP MAIL command. |
|
| 711 | + * Starts a mail transaction from the email address specified in |
|
| 712 | + * $from. Returns true if successful or false otherwise. If True |
|
| 713 | + * the mail transaction is started and then one or more recipient |
|
| 714 | + * commands may be called followed by a data command. |
|
| 715 | + * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF> |
|
| 716 | + * @param string $from Source address of this message |
|
| 717 | + * @access public |
|
| 718 | + * @return boolean |
|
| 719 | + */ |
|
| 720 | + public function mail($from) |
|
| 721 | + { |
|
| 722 | + $useVerp = ($this->do_verp ? ' XVERP' : ''); |
|
| 723 | + return $this->sendCommand( |
|
| 724 | + 'MAIL FROM', |
|
| 725 | + 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 726 | + 250 |
|
| 727 | + ); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Send an SMTP QUIT command. |
|
| 732 | + * Closes the socket if there is no error or the $close_on_error argument is true. |
|
| 733 | + * Implements from rfc 821: QUIT <CRLF> |
|
| 734 | + * @param boolean $close_on_error Should the connection close if an error occurs? |
|
| 735 | + * @access public |
|
| 736 | + * @return boolean |
|
| 737 | + */ |
|
| 738 | + public function quit($close_on_error = true) |
|
| 739 | + { |
|
| 740 | + $noerror = $this->sendCommand('QUIT', 'QUIT', 221); |
|
| 741 | + $err = $this->error; //Save any error |
|
| 742 | + if ($noerror or $close_on_error) { |
|
| 743 | + $this->close(); |
|
| 744 | + $this->error = $err; //Restore any error from the quit command |
|
| 745 | + } |
|
| 746 | + return $noerror; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + /** |
|
| 750 | + * Send an SMTP RCPT command. |
|
| 751 | + * Sets the TO argument to $toaddr. |
|
| 752 | + * Returns true if the recipient was accepted false if it was rejected. |
|
| 753 | + * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> |
|
| 754 | + * @param string $address The address the message is being sent to |
|
| 755 | + * @access public |
|
| 756 | + * @return boolean |
|
| 757 | + */ |
|
| 758 | + public function recipient($address) |
|
| 759 | + { |
|
| 760 | + return $this->sendCommand( |
|
| 761 | + 'RCPT TO', |
|
| 762 | + 'RCPT TO:<' . $address . '>', |
|
| 763 | + array(250, 251) |
|
| 764 | + ); |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * Send an SMTP RSET command. |
|
| 769 | + * Abort any transaction that is currently in progress. |
|
| 770 | + * Implements rfc 821: RSET <CRLF> |
|
| 771 | + * @access public |
|
| 772 | + * @return boolean True on success. |
|
| 773 | + */ |
|
| 774 | + public function reset() |
|
| 775 | + { |
|
| 776 | + return $this->sendCommand('RSET', 'RSET', 250); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Send a command to an SMTP server and check its return code. |
|
| 781 | + * @param string $command The command name - not sent to the server |
|
| 782 | + * @param string $commandstring The actual command to send |
|
| 783 | + * @param integer|array $expect One or more expected integer success codes |
|
| 784 | + * @access protected |
|
| 785 | + * @return boolean True on success. |
|
| 786 | + */ |
|
| 787 | + protected function sendCommand($command, $commandstring, $expect) |
|
| 788 | + { |
|
| 789 | + if (!$this->connected()) { |
|
| 790 | + $this->setError("Called $command without being connected"); |
|
| 791 | + return false; |
|
| 792 | + } |
|
| 793 | + //Reject line breaks in all commands |
|
| 794 | + if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) { |
|
| 795 | + $this->setError("Command '$command' contained line breaks"); |
|
| 796 | + return false; |
|
| 797 | + } |
|
| 798 | + $this->client_send($commandstring . self::CRLF); |
|
| 799 | + |
|
| 800 | + $this->last_reply = $this->get_lines(); |
|
| 801 | + // Fetch SMTP code and possible error code explanation |
|
| 802 | + $matches = array(); |
|
| 803 | + if (preg_match("/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/", $this->last_reply, $matches)) { |
|
| 804 | + $code = $matches[1]; |
|
| 805 | + $code_ex = (count($matches) > 2 ? $matches[2] : null); |
|
| 806 | + // Cut off error code from each response line |
|
| 807 | + $detail = preg_replace( |
|
| 808 | + "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m", |
|
| 809 | + '', |
|
| 810 | + $this->last_reply |
|
| 811 | + ); |
|
| 812 | + } else { |
|
| 813 | + // Fall back to simple parsing if regex fails |
|
| 814 | + $code = substr($this->last_reply, 0, 3); |
|
| 815 | + $code_ex = null; |
|
| 816 | + $detail = substr($this->last_reply, 4); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 820 | + |
|
| 821 | + if (!in_array($code, (array)$expect)) { |
|
| 822 | + $this->setError( |
|
| 823 | + "$command command failed", |
|
| 824 | + $detail, |
|
| 825 | + $code, |
|
| 826 | + $code_ex |
|
| 827 | + ); |
|
| 828 | + $this->edebug( |
|
| 829 | + 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 830 | + self::DEBUG_CLIENT |
|
| 831 | + ); |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + $this->setError(''); |
|
| 836 | + return true; |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * Send an SMTP SAML command. |
|
| 841 | + * Starts a mail transaction from the email address specified in $from. |
|
| 842 | + * Returns true if successful or false otherwise. If True |
|
| 843 | + * the mail transaction is started and then one or more recipient |
|
| 844 | + * commands may be called followed by a data command. This command |
|
| 845 | + * will send the message to the users terminal if they are logged |
|
| 846 | + * in and send them an email. |
|
| 847 | + * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF> |
|
| 848 | + * @param string $from The address the message is from |
|
| 849 | + * @access public |
|
| 850 | + * @return boolean |
|
| 851 | + */ |
|
| 852 | + public function sendAndMail($from) |
|
| 853 | + { |
|
| 854 | + return $this->sendCommand('SAML', "SAML FROM:$from", 250); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Send an SMTP VRFY command. |
|
| 859 | + * @param string $name The name to verify |
|
| 860 | + * @access public |
|
| 861 | + * @return boolean |
|
| 862 | + */ |
|
| 863 | + public function verify($name) |
|
| 864 | + { |
|
| 865 | + return $this->sendCommand('VRFY', "VRFY $name", array(250, 251)); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * Send an SMTP NOOP command. |
|
| 870 | + * Used to keep keep-alives alive, doesn't actually do anything |
|
| 871 | + * @access public |
|
| 872 | + * @return boolean |
|
| 873 | + */ |
|
| 874 | + public function noop() |
|
| 875 | + { |
|
| 876 | + return $this->sendCommand('NOOP', 'NOOP', 250); |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + /** |
|
| 880 | + * Send an SMTP TURN command. |
|
| 881 | + * This is an optional command for SMTP that this class does not support. |
|
| 882 | + * This method is here to make the RFC821 Definition complete for this class |
|
| 883 | + * and _may_ be implemented in future |
|
| 884 | + * Implements from rfc 821: TURN <CRLF> |
|
| 885 | + * @access public |
|
| 886 | + * @return boolean |
|
| 887 | + */ |
|
| 888 | + public function turn() |
|
| 889 | + { |
|
| 890 | + $this->setError('The SMTP TURN command is not implemented'); |
|
| 891 | + $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * Send raw data to the server. |
|
| 897 | + * @param string $data The data to send |
|
| 898 | + * @access public |
|
| 899 | + * @return integer|boolean The number of bytes sent to the server or false on error |
|
| 900 | + */ |
|
| 901 | + public function client_send($data) |
|
| 902 | + { |
|
| 903 | + $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT); |
|
| 904 | + return fwrite($this->smtp_conn, $data); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * Get the latest error. |
|
| 909 | + * @access public |
|
| 910 | + * @return array |
|
| 911 | + */ |
|
| 912 | + public function getError() |
|
| 913 | + { |
|
| 914 | + return $this->error; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Get SMTP extensions available on the server |
|
| 919 | + * @access public |
|
| 920 | + * @return array|null |
|
| 921 | + */ |
|
| 922 | + public function getServerExtList() |
|
| 923 | + { |
|
| 924 | + return $this->server_caps; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * A multipurpose method |
|
| 929 | + * The method works in three ways, dependent on argument value and current state |
|
| 930 | + * 1. HELO/EHLO was not sent - returns null and set up $this->error |
|
| 931 | + * 2. HELO was sent |
|
| 932 | + * $name = 'HELO': returns server name |
|
| 933 | + * $name = 'EHLO': returns boolean false |
|
| 934 | + * $name = any string: returns null and set up $this->error |
|
| 935 | + * 3. EHLO was sent |
|
| 936 | + * $name = 'HELO'|'EHLO': returns server name |
|
| 937 | + * $name = any string: if extension $name exists, returns boolean True |
|
| 938 | + * or its options. Otherwise returns boolean False |
|
| 939 | + * In other words, one can use this method to detect 3 conditions: |
|
| 940 | + * - null returned: handshake was not or we don't know about ext (refer to $this->error) |
|
| 941 | + * - false returned: the requested feature exactly not exists |
|
| 942 | + * - positive value returned: the requested feature exists |
|
| 943 | + * @param string $name Name of SMTP extension or 'HELO'|'EHLO' |
|
| 944 | + * @return mixed |
|
| 945 | + */ |
|
| 946 | + public function getServerExt($name) |
|
| 947 | + { |
|
| 948 | + if (!$this->server_caps) { |
|
| 949 | + $this->setError('No HELO/EHLO was sent'); |
|
| 950 | + return null; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + // the tight logic knot ;) |
|
| 954 | + if (!array_key_exists($name, $this->server_caps)) { |
|
| 955 | + if ($name == 'HELO') { |
|
| 956 | + return $this->server_caps['EHLO']; |
|
| 957 | + } |
|
| 958 | + if ($name == 'EHLO' || array_key_exists('EHLO', $this->server_caps)) { |
|
| 959 | + return false; |
|
| 960 | + } |
|
| 961 | + $this->setError('HELO handshake was used. Client knows nothing about server extensions'); |
|
| 962 | + return null; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + return $this->server_caps[$name]; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + /** |
|
| 969 | + * Get the last reply from the server. |
|
| 970 | + * @access public |
|
| 971 | + * @return string |
|
| 972 | + */ |
|
| 973 | + public function getLastReply() |
|
| 974 | + { |
|
| 975 | + return $this->last_reply; |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Read the SMTP server's response. |
|
| 980 | + * Either before eof or socket timeout occurs on the operation. |
|
| 981 | + * With SMTP we can tell if we have more lines to read if the |
|
| 982 | + * 4th character is '-' symbol. If it is a space then we don't |
|
| 983 | + * need to read anything else. |
|
| 984 | + * @access protected |
|
| 985 | + * @return string |
|
| 986 | + */ |
|
| 987 | + protected function get_lines() |
|
| 988 | + { |
|
| 989 | + // If the connection is bad, give up straight away |
|
| 990 | + if (!is_resource($this->smtp_conn)) { |
|
| 991 | + return ''; |
|
| 992 | + } |
|
| 993 | + $data = ''; |
|
| 994 | + $endtime = 0; |
|
| 995 | + stream_set_timeout($this->smtp_conn, $this->Timeout); |
|
| 996 | + if ($this->Timelimit > 0) { |
|
| 997 | + $endtime = time() + $this->Timelimit; |
|
| 998 | + } |
|
| 999 | + while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 1000 | + $str = @fgets($this->smtp_conn, 515); |
|
| 1001 | + $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); |
|
| 1002 | + $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
|
| 1003 | + $data .= $str; |
|
| 1004 | + // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen |
|
| 1005 | + if ((isset($str[3]) and $str[3] == ' ')) { |
|
| 1006 | + break; |
|
| 1007 | + } |
|
| 1008 | + // Timed-out? Log and break |
|
| 1009 | + $info = stream_get_meta_data($this->smtp_conn); |
|
| 1010 | + if ($info['timed_out']) { |
|
| 1011 | + $this->edebug( |
|
| 1012 | + 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 1013 | + self::DEBUG_LOWLEVEL |
|
| 1014 | + ); |
|
| 1015 | + break; |
|
| 1016 | + } |
|
| 1017 | + // Now check if reads took too long |
|
| 1018 | + if ($endtime and time() > $endtime) { |
|
| 1019 | + $this->edebug( |
|
| 1020 | + 'SMTP -> get_lines(): timelimit reached ('. |
|
| 1021 | + $this->Timelimit . ' sec)', |
|
| 1022 | + self::DEBUG_LOWLEVEL |
|
| 1023 | + ); |
|
| 1024 | + break; |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + return $data; |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Enable or disable VERP address generation. |
|
| 1032 | + * @param boolean $enabled |
|
| 1033 | + */ |
|
| 1034 | + public function setVerp($enabled = false) |
|
| 1035 | + { |
|
| 1036 | + $this->do_verp = $enabled; |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + /** |
|
| 1040 | + * Get VERP address generation mode. |
|
| 1041 | + * @return boolean |
|
| 1042 | + */ |
|
| 1043 | + public function getVerp() |
|
| 1044 | + { |
|
| 1045 | + return $this->do_verp; |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + /** |
|
| 1049 | + * Set error messages and codes. |
|
| 1050 | + * @param string $message The error message |
|
| 1051 | + * @param string $detail Further detail on the error |
|
| 1052 | + * @param string $smtp_code An associated SMTP error code |
|
| 1053 | + * @param string $smtp_code_ex Extended SMTP code |
|
| 1054 | + */ |
|
| 1055 | + protected function setError($message, $detail = '', $smtp_code = '', $smtp_code_ex = '') |
|
| 1056 | + { |
|
| 1057 | + $this->error = array( |
|
| 1058 | + 'error' => $message, |
|
| 1059 | + 'detail' => $detail, |
|
| 1060 | + 'smtp_code' => $smtp_code, |
|
| 1061 | + 'smtp_code_ex' => $smtp_code_ex |
|
| 1062 | + ); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + /** |
|
| 1066 | + * Set debug output method. |
|
| 1067 | + * @param string|callable $method The name of the mechanism to use for debugging output, or a callable to handle it. |
|
| 1068 | + */ |
|
| 1069 | + public function setDebugOutput($method = 'echo') |
|
| 1070 | + { |
|
| 1071 | + $this->Debugoutput = $method; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * Get debug output method. |
|
| 1076 | + * @return string |
|
| 1077 | + */ |
|
| 1078 | + public function getDebugOutput() |
|
| 1079 | + { |
|
| 1080 | + return $this->Debugoutput; |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Set debug output level. |
|
| 1085 | + * @param integer $level |
|
| 1086 | + */ |
|
| 1087 | + public function setDebugLevel($level = 0) |
|
| 1088 | + { |
|
| 1089 | + $this->do_debug = $level; |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + /** |
|
| 1093 | + * Get debug output level. |
|
| 1094 | + * @return integer |
|
| 1095 | + */ |
|
| 1096 | + public function getDebugLevel() |
|
| 1097 | + { |
|
| 1098 | + return $this->do_debug; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * Set SMTP timeout. |
|
| 1103 | + * @param integer $timeout |
|
| 1104 | + */ |
|
| 1105 | + public function setTimeout($timeout = 0) |
|
| 1106 | + { |
|
| 1107 | + $this->Timeout = $timeout; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + /** |
|
| 1111 | + * Get SMTP timeout. |
|
| 1112 | + * @return integer |
|
| 1113 | + */ |
|
| 1114 | + public function getTimeout() |
|
| 1115 | + { |
|
| 1116 | + return $this->Timeout; |
|
| 1117 | + } |
|
| 1118 | 1118 | } |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | return; |
| 206 | 206 | } |
| 207 | 207 | //Avoid clash with built-in function names |
| 208 | - if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 208 | + if ( ! in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { |
|
| 209 | 209 | call_user_func($this->Debugoutput, $str, $this->do_debug); |
| 210 | 210 | return; |
| 211 | 211 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | default: |
| 228 | 228 | //Normalize line breaks |
| 229 | 229 | $str = preg_replace('/(\r\n|\r|\n)/ms', "\n", $str); |
| 230 | - echo gmdate('Y-m-d H:i:s') . "\t" . str_replace( |
|
| 230 | + echo gmdate('Y-m-d H:i:s')."\t".str_replace( |
|
| 231 | 231 | "\n", |
| 232 | 232 | "\n \t ", |
| 233 | 233 | trim($str) |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $socket_context = stream_context_create($options); |
| 275 | 275 | //Suppress errors; connection failures are handled at a higher level |
| 276 | 276 | $this->smtp_conn = @stream_socket_client( |
| 277 | - $host . ":" . $port, |
|
| 277 | + $host.":".$port, |
|
| 278 | 278 | $errno, |
| 279 | 279 | $errstr, |
| 280 | 280 | $timeout, |
@@ -296,14 +296,14 @@ discard block |
||
| 296 | 296 | ); |
| 297 | 297 | } |
| 298 | 298 | // Verify we connected properly |
| 299 | - if (!is_resource($this->smtp_conn)) { |
|
| 299 | + if ( ! is_resource($this->smtp_conn)) { |
|
| 300 | 300 | $this->setError( |
| 301 | 301 | 'Failed to connect to server', |
| 302 | 302 | $errno, |
| 303 | 303 | $errstr |
| 304 | 304 | ); |
| 305 | 305 | $this->edebug( |
| 306 | - 'SMTP ERROR: ' . $this->error['error'] |
|
| 306 | + 'SMTP ERROR: '.$this->error['error'] |
|
| 307 | 307 | . ": $errstr ($errno)", |
| 308 | 308 | self::DEBUG_CLIENT |
| 309 | 309 | ); |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | // Get any announcement |
| 324 | 324 | $announce = $this->get_lines(); |
| 325 | - $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER); |
|
| 325 | + $this->edebug('SERVER -> CLIENT: '.$announce, self::DEBUG_SERVER); |
|
| 326 | 326 | return true; |
| 327 | 327 | } |
| 328 | 328 | |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | public function startTLS() |
| 335 | 335 | { |
| 336 | - if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 336 | + if ( ! $this->sendCommand('STARTTLS', 'STARTTLS', 220)) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | // Begin encrypted connection |
| 340 | - if (!stream_socket_enable_crypto( |
|
| 340 | + if ( ! stream_socket_enable_crypto( |
|
| 341 | 341 | $this->smtp_conn, |
| 342 | 342 | true, |
| 343 | 343 | STREAM_CRYPTO_METHOD_TLS_CLIENT |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | $workstation = '', |
| 368 | 368 | $OAuth = null |
| 369 | 369 | ) { |
| 370 | - if (!$this->server_caps) { |
|
| 370 | + if ( ! $this->server_caps) { |
|
| 371 | 371 | $this->setError('Authentication is not allowed before HELO/EHLO'); |
| 372 | 372 | return false; |
| 373 | 373 | } |
@@ -375,16 +375,16 @@ discard block |
||
| 375 | 375 | if (array_key_exists('EHLO', $this->server_caps)) { |
| 376 | 376 | // SMTP extensions are available. Let's try to find a proper authentication method |
| 377 | 377 | |
| 378 | - if (!array_key_exists('AUTH', $this->server_caps)) { |
|
| 378 | + if ( ! array_key_exists('AUTH', $this->server_caps)) { |
|
| 379 | 379 | $this->setError('Authentication is not allowed at this stage'); |
| 380 | 380 | // 'at this stage' means that auth may be allowed after the stage changes |
| 381 | 381 | // e.g. after STARTTLS |
| 382 | 382 | return false; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - self::edebug('Auth method requested: ' . ($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 385 | + self::edebug('Auth method requested: '.($authtype ? $authtype : 'UNKNOWN'), self::DEBUG_LOWLEVEL); |
|
| 386 | 386 | self::edebug( |
| 387 | - 'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']), |
|
| 387 | + 'Auth methods available on the server: '.implode(',', $this->server_caps['AUTH']), |
|
| 388 | 388 | self::DEBUG_LOWLEVEL |
| 389 | 389 | ); |
| 390 | 390 | |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - if (!in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 405 | + if ( ! in_array($authtype, $this->server_caps['AUTH'])) { |
|
| 406 | 406 | $this->setError("The requested authentication method \"$authtype\" is not supported by the server"); |
| 407 | 407 | return false; |
| 408 | 408 | } |
@@ -412,13 +412,13 @@ discard block |
||
| 412 | 412 | switch ($authtype) { |
| 413 | 413 | case 'PLAIN': |
| 414 | 414 | // Start authentication |
| 415 | - if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 415 | + if ( ! $this->sendCommand('AUTH', 'AUTH PLAIN', 334)) { |
|
| 416 | 416 | return false; |
| 417 | 417 | } |
| 418 | 418 | // Send encoded username and password |
| 419 | - if (!$this->sendCommand( |
|
| 419 | + if ( ! $this->sendCommand( |
|
| 420 | 420 | 'User & Password', |
| 421 | - base64_encode("\0" . $username . "\0" . $password), |
|
| 421 | + base64_encode("\0".$username."\0".$password), |
|
| 422 | 422 | 235 |
| 423 | 423 | ) |
| 424 | 424 | ) { |
@@ -427,26 +427,26 @@ discard block |
||
| 427 | 427 | break; |
| 428 | 428 | case 'LOGIN': |
| 429 | 429 | // Start authentication |
| 430 | - if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 430 | + if ( ! $this->sendCommand('AUTH', 'AUTH LOGIN', 334)) { |
|
| 431 | 431 | return false; |
| 432 | 432 | } |
| 433 | - if (!$this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 433 | + if ( ! $this->sendCommand("Username", base64_encode($username), 334)) { |
|
| 434 | 434 | return false; |
| 435 | 435 | } |
| 436 | - if (!$this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 436 | + if ( ! $this->sendCommand("Password", base64_encode($password), 235)) { |
|
| 437 | 437 | return false; |
| 438 | 438 | } |
| 439 | 439 | break; |
| 440 | 440 | case 'CRAM-MD5': |
| 441 | 441 | // Start authentication |
| 442 | - if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 442 | + if ( ! $this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) { |
|
| 443 | 443 | return false; |
| 444 | 444 | } |
| 445 | 445 | // Get the challenge |
| 446 | 446 | $challenge = base64_decode(substr($this->last_reply, 4)); |
| 447 | 447 | |
| 448 | 448 | // Build the response |
| 449 | - $response = $username . ' ' . $this->hmac($challenge, $password); |
|
| 449 | + $response = $username.' '.$this->hmac($challenge, $password); |
|
| 450 | 450 | |
| 451 | 451 | // send encoded credentials |
| 452 | 452 | return $this->sendCommand('Username', base64_encode($response), 235); |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | $k_ipad = $key ^ $ipad; |
| 491 | 491 | $k_opad = $key ^ $opad; |
| 492 | 492 | |
| 493 | - return md5($k_opad . pack('H*', md5($k_ipad . $data))); |
|
| 493 | + return md5($k_opad.pack('H*', md5($k_ipad.$data))); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | public function data($msg_data) |
| 552 | 552 | { |
| 553 | 553 | //This will use the standard timelimit |
| 554 | - if (!$this->sendCommand('DATA', 'DATA', 354)) { |
|
| 554 | + if ( ! $this->sendCommand('DATA', 'DATA', 354)) { |
|
| 555 | 555 | return false; |
| 556 | 556 | } |
| 557 | 557 | |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | |
| 574 | 574 | $field = substr($lines[0], 0, strpos($lines[0], ':')); |
| 575 | 575 | $in_headers = false; |
| 576 | - if (!empty($field) && strpos($field, ' ') === false) { |
|
| 576 | + if ( ! empty($field) && strpos($field, ' ') === false) { |
|
| 577 | 577 | $in_headers = true; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | //so as to avoid breaking in the middle of a word |
| 590 | 590 | $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' '); |
| 591 | 591 | //Deliberately matches both false and 0 |
| 592 | - if (!$pos) { |
|
| 592 | + if ( ! $pos) { |
|
| 593 | 593 | //No nice break found, add a hard break |
| 594 | 594 | $pos = self::MAX_LINE_LENGTH - 1; |
| 595 | 595 | $lines_out[] = substr($line, 0, $pos); |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | } |
| 603 | 603 | //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1 |
| 604 | 604 | if ($in_headers) { |
| 605 | - $line = "\t" . $line; |
|
| 605 | + $line = "\t".$line; |
|
| 606 | 606 | } |
| 607 | 607 | } |
| 608 | 608 | $lines_out[] = $line; |
@@ -610,10 +610,10 @@ discard block |
||
| 610 | 610 | //Send the lines to the server |
| 611 | 611 | foreach ($lines_out as $line_out) { |
| 612 | 612 | //RFC2821 section 4.5.2 |
| 613 | - if (!empty($line_out) and $line_out[0] == '.') { |
|
| 614 | - $line_out = '.' . $line_out; |
|
| 613 | + if ( ! empty($line_out) and $line_out[0] == '.') { |
|
| 614 | + $line_out = '.'.$line_out; |
|
| 615 | 615 | } |
| 616 | - $this->client_send($line_out . self::CRLF); |
|
| 616 | + $this->client_send($line_out.self::CRLF); |
|
| 617 | 617 | } |
| 618 | 618 | } |
| 619 | 619 | |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | public function hello($host = '') |
| 641 | 641 | { |
| 642 | 642 | //Try extended hello first (RFC 2821) |
| 643 | - return (boolean)($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 643 | + return (boolean) ($this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host)); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | */ |
| 655 | 655 | protected function sendHello($hello, $host) |
| 656 | 656 | { |
| 657 | - $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250); |
|
| 657 | + $noerror = $this->sendCommand($hello, $hello.' '.$host, 250); |
|
| 658 | 658 | $this->helo_rply = $this->last_reply; |
| 659 | 659 | if ($noerror) { |
| 660 | 660 | $this->parseHelloFields($hello); |
@@ -682,8 +682,8 @@ discard block |
||
| 682 | 682 | continue; |
| 683 | 683 | } |
| 684 | 684 | $fields = explode(' ', $s); |
| 685 | - if (!empty($fields)) { |
|
| 686 | - if (!$n) { |
|
| 685 | + if ( ! empty($fields)) { |
|
| 686 | + if ( ! $n) { |
|
| 687 | 687 | $name = $type; |
| 688 | 688 | $fields = $fields[0]; |
| 689 | 689 | } else { |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | $fields = ($fields ? $fields[0] : 0); |
| 694 | 694 | break; |
| 695 | 695 | case 'AUTH': |
| 696 | - if (!is_array($fields)) { |
|
| 696 | + if ( ! is_array($fields)) { |
|
| 697 | 697 | $fields = array(); |
| 698 | 698 | } |
| 699 | 699 | break; |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | $useVerp = ($this->do_verp ? ' XVERP' : ''); |
| 723 | 723 | return $this->sendCommand( |
| 724 | 724 | 'MAIL FROM', |
| 725 | - 'MAIL FROM:<' . $from . '>' . $useVerp, |
|
| 725 | + 'MAIL FROM:<'.$from.'>'.$useVerp, |
|
| 726 | 726 | 250 |
| 727 | 727 | ); |
| 728 | 728 | } |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | { |
| 760 | 760 | return $this->sendCommand( |
| 761 | 761 | 'RCPT TO', |
| 762 | - 'RCPT TO:<' . $address . '>', |
|
| 762 | + 'RCPT TO:<'.$address.'>', |
|
| 763 | 763 | array(250, 251) |
| 764 | 764 | ); |
| 765 | 765 | } |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | */ |
| 787 | 787 | protected function sendCommand($command, $commandstring, $expect) |
| 788 | 788 | { |
| 789 | - if (!$this->connected()) { |
|
| 789 | + if ( ! $this->connected()) { |
|
| 790 | 790 | $this->setError("Called $command without being connected"); |
| 791 | 791 | return false; |
| 792 | 792 | } |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | $this->setError("Command '$command' contained line breaks"); |
| 796 | 796 | return false; |
| 797 | 797 | } |
| 798 | - $this->client_send($commandstring . self::CRLF); |
|
| 798 | + $this->client_send($commandstring.self::CRLF); |
|
| 799 | 799 | |
| 800 | 800 | $this->last_reply = $this->get_lines(); |
| 801 | 801 | // Fetch SMTP code and possible error code explanation |
@@ -816,9 +816,9 @@ discard block |
||
| 816 | 816 | $detail = substr($this->last_reply, 4); |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | - $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER); |
|
| 819 | + $this->edebug('SERVER -> CLIENT: '.$this->last_reply, self::DEBUG_SERVER); |
|
| 820 | 820 | |
| 821 | - if (!in_array($code, (array)$expect)) { |
|
| 821 | + if ( ! in_array($code, (array) $expect)) { |
|
| 822 | 822 | $this->setError( |
| 823 | 823 | "$command command failed", |
| 824 | 824 | $detail, |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | $code_ex |
| 827 | 827 | ); |
| 828 | 828 | $this->edebug( |
| 829 | - 'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply, |
|
| 829 | + 'SMTP ERROR: '.$this->error['error'].': '.$this->last_reply, |
|
| 830 | 830 | self::DEBUG_CLIENT |
| 831 | 831 | ); |
| 832 | 832 | return false; |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | public function turn() |
| 889 | 889 | { |
| 890 | 890 | $this->setError('The SMTP TURN command is not implemented'); |
| 891 | - $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT); |
|
| 891 | + $this->edebug('SMTP NOTICE: '.$this->error['error'], self::DEBUG_CLIENT); |
|
| 892 | 892 | return false; |
| 893 | 893 | } |
| 894 | 894 | |
@@ -945,13 +945,13 @@ discard block |
||
| 945 | 945 | */ |
| 946 | 946 | public function getServerExt($name) |
| 947 | 947 | { |
| 948 | - if (!$this->server_caps) { |
|
| 948 | + if ( ! $this->server_caps) { |
|
| 949 | 949 | $this->setError('No HELO/EHLO was sent'); |
| 950 | 950 | return null; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | // the tight logic knot ;) |
| 954 | - if (!array_key_exists($name, $this->server_caps)) { |
|
| 954 | + if ( ! array_key_exists($name, $this->server_caps)) { |
|
| 955 | 955 | if ($name == 'HELO') { |
| 956 | 956 | return $this->server_caps['EHLO']; |
| 957 | 957 | } |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | protected function get_lines() |
| 988 | 988 | { |
| 989 | 989 | // If the connection is bad, give up straight away |
| 990 | - if (!is_resource($this->smtp_conn)) { |
|
| 990 | + if ( ! is_resource($this->smtp_conn)) { |
|
| 991 | 991 | return ''; |
| 992 | 992 | } |
| 993 | 993 | $data = ''; |
@@ -996,7 +996,7 @@ discard block |
||
| 996 | 996 | if ($this->Timelimit > 0) { |
| 997 | 997 | $endtime = time() + $this->Timelimit; |
| 998 | 998 | } |
| 999 | - while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { |
|
| 999 | + while (is_resource($this->smtp_conn) && ! feof($this->smtp_conn)) { |
|
| 1000 | 1000 | $str = @fgets($this->smtp_conn, 515); |
| 1001 | 1001 | $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); |
| 1002 | 1002 | $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | $info = stream_get_meta_data($this->smtp_conn); |
| 1010 | 1010 | if ($info['timed_out']) { |
| 1011 | 1011 | $this->edebug( |
| 1012 | - 'SMTP -> get_lines(): timed-out (' . $this->Timeout . ' sec)', |
|
| 1012 | + 'SMTP -> get_lines(): timed-out ('.$this->Timeout.' sec)', |
|
| 1013 | 1013 | self::DEBUG_LOWLEVEL |
| 1014 | 1014 | ); |
| 1015 | 1015 | break; |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | if ($endtime and time() > $endtime) { |
| 1019 | 1019 | $this->edebug( |
| 1020 | 1020 | 'SMTP -> get_lines(): timelimit reached ('. |
| 1021 | - $this->Timelimit . ' sec)', |
|
| 1021 | + $this->Timelimit.' sec)', |
|
| 1022 | 1022 | self::DEBUG_LOWLEVEL |
| 1023 | 1023 | ); |
| 1024 | 1024 | break; |