Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like VideoPress_Player often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use VideoPress_Player, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class VideoPress_Player { |
||
| 8 | /** |
||
| 9 | * Video data for the requested guid and maximum width |
||
| 10 | * |
||
| 11 | * @since 1.3 |
||
| 12 | * @var VideoPress_Video |
||
| 13 | */ |
||
| 14 | protected $video; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * DOM identifier of the video container |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | * @since 1.3 |
||
| 21 | */ |
||
| 22 | protected $video_container_id; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * DOM identifier of the video element (video, object, embed) |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | * @since 1.3 |
||
| 29 | */ |
||
| 30 | protected $video_id; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Array of playback options: force_flash or freedom |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | * @since 1.3 |
||
| 37 | */ |
||
| 38 | protected $options; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Array of video GUIDs shown and their counts, |
||
| 42 | * moved from the old VideoPress class. |
||
| 43 | */ |
||
| 44 | public static $shown = array(); |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Initiate a player object based on shortcode values and possible blog-level option overrides |
||
| 48 | * |
||
| 49 | * @since 1.3 |
||
| 50 | * @var string $guid VideoPress unique identifier |
||
| 51 | * @var int $maxwidth maximum desired width of the video player if specified |
||
| 52 | * @var array $options player customizations |
||
| 53 | */ |
||
| 54 | public function __construct( $guid, $maxwidth = 0, $options = array() ) { |
||
| 55 | if ( empty( self::$shown[ $guid ] ) ) |
||
| 56 | self::$shown[ $guid ] = 0; |
||
| 57 | |||
| 58 | self::$shown[ $guid ]++; |
||
| 59 | |||
| 60 | $this->video_container_id = 'v-' . $guid . '-' . self::$shown[ $guid ]; |
||
| 61 | $this->video_id = $this->video_container_id . '-video'; |
||
| 62 | |||
| 63 | if ( is_array( $options ) ) |
||
| 64 | $this->options = $options; |
||
| 65 | else |
||
| 66 | $this->options = array(); |
||
| 67 | |||
| 68 | // set up the video |
||
| 69 | $cache_key = null; |
||
| 70 | |||
| 71 | // disable cache in debug mode |
||
| 72 | if ( defined('WP_DEBUG') && WP_DEBUG === true ) { |
||
| 73 | $cached_video = null; |
||
| 74 | } else { |
||
| 75 | $cache_key_pieces = array( 'video' ); |
||
| 76 | |||
| 77 | if ( is_multisite() && is_subdomain_install() ) |
||
| 78 | $cache_key_pieces[] = get_current_blog_id(); |
||
| 79 | |||
| 80 | $cache_key_pieces[] = $guid; |
||
| 81 | if ( $maxwidth > 0 ) |
||
| 82 | $cache_key_pieces[] = $maxwidth; |
||
| 83 | if ( is_ssl() ) |
||
| 84 | $cache_key_pieces[] = 'ssl'; |
||
| 85 | $cache_key = implode( '-', $cache_key_pieces ); |
||
| 86 | unset( $cache_key_pieces ); |
||
| 87 | $cached_video = wp_cache_get( $cache_key, 'video' ); |
||
| 88 | } |
||
| 89 | if ( empty( $cached_video ) ) { |
||
| 90 | $video = new VideoPress_Video( $guid, $maxwidth ); |
||
| 91 | if ( empty( $video ) ) { |
||
| 92 | return; |
||
| 93 | } elseif ( isset( $video->error ) ) { |
||
| 94 | $this->video = $video->error; |
||
|
|
|||
| 95 | return; |
||
| 96 | } elseif ( is_wp_error( $video ) ) { |
||
| 97 | $this->video = $video; |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->video = $video; |
||
| 102 | unset( $video ); |
||
| 103 | |||
| 104 | if ( ! defined( 'WP_DEBUG' ) || WP_DEBUG !== true ) { |
||
| 105 | $expire = 3600; |
||
| 106 | if ( isset( $video->expires ) && is_int( $video->expires ) ) { |
||
| 107 | $expires_diff = time() - $video->expires; |
||
| 108 | if ( $expires_diff > 0 && $expires_diff < 86400 ) // allowed range: 1 second to 1 day |
||
| 109 | $expire = $expires_diff; |
||
| 110 | unset( $expires_diff ); |
||
| 111 | } |
||
| 112 | |||
| 113 | wp_cache_set( $cache_key, serialize( $this->video ), 'video', $expire ); |
||
| 114 | unset( $expire ); |
||
| 115 | } |
||
| 116 | } else { |
||
| 117 | $this->video = unserialize( $cached_video ); |
||
| 118 | } |
||
| 119 | unset( $cache_key ); |
||
| 120 | unset( $cached_video ); |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Wrap output in a VideoPress player container |
||
| 125 | * |
||
| 126 | * @since 1.3 |
||
| 127 | * @var string $content HTML string |
||
| 128 | * @return string HTML string or blank string if nothing to wrap |
||
| 129 | */ |
||
| 130 | private function html_wrapper( $content ) { |
||
| 131 | if ( empty( $content ) ) |
||
| 132 | return ''; |
||
| 133 | else |
||
| 134 | return '<div id="' . esc_attr( $this->video_container_id ) . '" class="video-player">' . $content . '</div>'; |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Output content suitable for a feed reader displaying RSS or Atom feeds |
||
| 139 | * We do not display error messages in the feed view due to caching concerns. |
||
| 140 | * Flash content presented using <embed> markup for feed reader compatibility. |
||
| 141 | * |
||
| 142 | * @since 1.3 |
||
| 143 | * @return string HTML string or empty string if error |
||
| 144 | */ |
||
| 145 | public function asXML() { |
||
| 146 | if ( empty( $this->video ) || is_wp_error( $this->video ) ) |
||
| 147 | return ''; |
||
| 148 | |||
| 149 | View Code Duplication | if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) |
|
| 150 | $content = $this->html5_static(); |
||
| 151 | else |
||
| 152 | $content = $this->flash_embed(); |
||
| 153 | |||
| 154 | return $this->html_wrapper( $content ); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Video player markup for best matching the current request and publisher options |
||
| 159 | * @since 1.3 |
||
| 160 | * @return string HTML markup string or empty string if no video property found |
||
| 161 | */ |
||
| 162 | public function asHTML() { |
||
| 163 | if ( empty( $this->video ) ) { |
||
| 164 | $content = ''; |
||
| 165 | } elseif ( is_wp_error( $this->video ) ) { |
||
| 166 | $content = $this->error_message( $this->video ); |
||
| 167 | } elseif ( isset( $this->options['force_flash'] ) && $this->options['force_flash'] === true ) { |
||
| 168 | $content = $this->flash_object(); |
||
| 169 | } elseif ( isset( $this->video->restricted_embed ) && $this->video->restricted_embed === true ) { |
||
| 170 | if( $this->options['forcestatic'] ) |
||
| 171 | $content = $this->flash_object(); |
||
| 172 | else |
||
| 173 | $content = $this->html5_dynamic(); |
||
| 174 | View Code Duplication | } elseif ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) { |
|
| 175 | $content = $this->html5_static(); |
||
| 176 | } else { |
||
| 177 | $content = $this->html5_dynamic(); |
||
| 178 | } |
||
| 179 | return $this->html_wrapper( $content ); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Display an error message to users capable of doing something about the error |
||
| 184 | * |
||
| 185 | * @since 1.3 |
||
| 186 | * @uses current_user_can() to test if current user has edit_posts capability |
||
| 187 | * @var WP_Error $error WordPress error |
||
| 188 | * @return string HTML string |
||
| 189 | */ |
||
| 190 | private function error_message( $error ) { |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Rating agencies and industry associations require a potential viewer verify his or her age before a video or its poster frame are displayed. |
||
| 205 | * Content rated for audiences 17 years of age or older requires such verification across multiple rating agencies and industry associations |
||
| 206 | * |
||
| 207 | * @since 1.3 |
||
| 208 | * @return bool true if video requires the viewer verify he or she is 17 years of age or older |
||
| 209 | */ |
||
| 210 | private function age_gate_required() { |
||
| 211 | if ( isset( $this->video->age_rating ) && $this->video->age_rating >= 17 ) |
||
| 212 | return true; |
||
| 213 | else |
||
| 214 | return false; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Select a date of birth using HTML form elements. |
||
| 219 | * |
||
| 220 | * @since 1.5 |
||
| 221 | * @return string HTML markup |
||
| 222 | */ |
||
| 223 | private function html_age_gate() { |
||
| 224 | global $wp_locale; |
||
| 225 | $text_align = 'left'; |
||
| 226 | if ( $this->video->text_direction === 'rtl' ) |
||
| 227 | $text_align = 'right'; |
||
| 228 | |||
| 229 | $html = '<div class="videopress-age-gate" style="margin:0 60px">'; |
||
| 230 | $html .= '<p class="instructions" style="color:rgb(255, 255, 255);font-size:21px;padding-top:60px;padding-bottom:20px;text-align:' . $text_align . '">' . esc_html( __( 'This video is intended for mature audiences.', 'jetpack' ) ) . '<br />' . esc_html( __( 'Please verify your birthday.', 'jetpack' ) ) . '</p>'; |
||
| 231 | $html .= '<fieldset id="birthday" style="border:0 none;text-align:' . $text_align . ';padding:0;">'; |
||
| 232 | $inputs_style = 'border:1px solid #444;margin-'; |
||
| 233 | if ( $this->video->text_direction === 'rtl' ) |
||
| 234 | $inputs_style .= 'left'; |
||
| 235 | else |
||
| 236 | $inputs_style .= 'right'; |
||
| 237 | $inputs_style .= ':10px;background-color:rgb(0, 0, 0);font-size:14px;color:rgb(255,255,255);padding:4px 6px;line-height: 2em;vertical-align: middle'; |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Display a list of months in the Gregorian calendar. |
||
| 241 | * Set values to 0-based to match JavaScript Date. |
||
| 242 | * @link https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date Mozilla JavaScript Reference: Date |
||
| 243 | */ |
||
| 244 | $html .= '<select name="month" style="' . $inputs_style . '">'; |
||
| 245 | |||
| 246 | for( $i=0; $i<12; $i++ ) { |
||
| 247 | $html .= '<option value="' . esc_attr( $i ) . '">' . esc_html( $wp_locale->get_month( $i + 1 ) ) . '</option>'; |
||
| 248 | } |
||
| 249 | $html .= '</select>'; |
||
| 250 | |||
| 251 | /** |
||
| 252 | * todo: numdays variance by month |
||
| 253 | */ |
||
| 254 | $html .= '<select name="day" style="' . $inputs_style . '">'; |
||
| 255 | for ( $i=1; $i<32; $i++ ) { |
||
| 256 | $html .= '<option>' . $i . '</option>'; |
||
| 257 | } |
||
| 258 | $html .= '</select>'; |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Current record for human life is 122. Go back 130 years and no one is left out. |
||
| 262 | * Don't ask infants younger than 2 for their birthday |
||
| 263 | * Default to 13 |
||
| 264 | */ |
||
| 265 | $html .= '<select name="year" style="' . $inputs_style . '">'; |
||
| 266 | $start_year = date('Y') - 2; |
||
| 267 | $default_year = $start_year - 11; |
||
| 268 | $end_year = $start_year - 128; |
||
| 269 | for ( $year=$start_year; $year>$end_year; $year-- ) { |
||
| 270 | $html .= '<option'; |
||
| 271 | if ( $year === $default_year ) |
||
| 272 | $html .= ' selected="selected"'; |
||
| 273 | $html .= '>' . $year . '</option>'; |
||
| 274 | } |
||
| 275 | unset( $start_year ); |
||
| 276 | unset( $default_year ); |
||
| 277 | unset( $end_year ); |
||
| 278 | $html .= '</select>'; |
||
| 279 | |||
| 280 | $html .= '<input type="submit" value="' . __( 'Submit', 'jetpack' ) . '" style="cursor:pointer;border-radius: 1em;border:1px solid #333;background-color:#333;background:-webkit-gradient( linear, left top, left bottom, color-stop(0.0, #444), color-stop(1, #111) );background:-moz-linear-gradient(center top, #444 0%, #111 100%);font-size:13px;padding:4px 10px 5px;line-height:1em;vertical-align:top;color:white;text-decoration:none;margin:0" />'; |
||
| 281 | |||
| 282 | $html .= '</fieldset>'; |
||
| 283 | $html .= '<p style="padding-top:20px;padding-bottom:60px;text-align:' . $text_align . ';"><a rel="nofollow" href="http://videopress.com/" style="color:rgb(128,128,128);text-decoration:underline;font-size:15px">' . __( 'More information', 'jetpack' ) . '</a></p>'; |
||
| 284 | |||
| 285 | $html .= '</div>'; |
||
| 286 | return $html; |
||
| 287 | } |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Return HTML5 video static markup for the given video parameters. |
||
| 291 | * Use default browser player controls. |
||
| 292 | * No Flash fallback. |
||
| 293 | * |
||
| 294 | * @since 1.2 |
||
| 295 | * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html HTML5 video |
||
| 296 | * @return string HTML5 video element and children |
||
| 297 | */ |
||
| 298 | private function html5_static() { |
||
| 299 | wp_enqueue_script( 'videopress' ); |
||
| 300 | $thumbnail = esc_url( $this->video->poster_frame_uri ); |
||
| 301 | $html = "<video id=\"{$this->video_id}\" width=\"{$this->video->calculated_width}\" height=\"{$this->video->calculated_height}\" poster=\"$thumbnail\" controls=\"true\""; |
||
| 302 | View Code Duplication | if ( isset( $this->options['autoplay'] ) && $this->options['autoplay'] === true ) |
|
| 303 | $html .= ' autoplay="true"'; |
||
| 304 | else |
||
| 305 | $html .= ' preload="metadata"'; |
||
| 306 | if ( isset( $this->video->text_direction ) ) |
||
| 307 | $html .= ' dir="' . esc_attr( $this->video->text_direction ) . '"'; |
||
| 308 | View Code Duplication | if ( isset( $this->video->language ) ) |
|
| 309 | $html .= ' lang="' . esc_attr( $this->video->language ) . '"'; |
||
| 310 | $html .= '>'; |
||
| 311 | if ( ! isset( $this->options['freedom'] ) || $this->options['freedom'] === false ) { |
||
| 312 | $mp4 = $this->video->videos->mp4->url; |
||
| 313 | View Code Duplication | if ( ! empty( $mp4 ) ) |
|
| 314 | $html .= '<source src="' . esc_url( $mp4 ) . '" type="video/mp4; codecs="' . esc_attr( $this->video->videos->mp4->codecs ) . '"" />'; |
||
| 315 | unset( $mp4 ); |
||
| 316 | } |
||
| 317 | $ogg = $this->video->videos->ogv->url; |
||
| 318 | View Code Duplication | if ( ! empty( $ogg ) ) |
|
| 319 | $html .= '<source src="' . esc_url( $ogg ) . '" type="video/ogg; codecs="' . esc_attr( $this->video->videos->ogv->codecs ) . '"" />'; |
||
| 320 | unset( $ogg ); |
||
| 321 | |||
| 322 | $html .= '<div><img alt="'; |
||
| 323 | if ( isset( $this->video->title ) ) |
||
| 324 | $html .= esc_attr( $this->video->title ); |
||
| 325 | $html .= '" src="' . $thumbnail . '" width="' . $this->video->calculated_width . '" height="' . $this->video->calculated_height . '" /></div>'; |
||
| 326 | if ( isset( $this->options['freedom'] ) && $this->options['freedom'] === true ) |
||
| 327 | $html .= '<p class="robots-nocontent">' . sprintf( __( 'You do not have sufficient <a rel="nofollow" href="%s">freedom levels</a> to view this video. Support free software and upgrade.', 'jetpack' ), 'http://www.gnu.org/philosophy/free-sw.html' ) . '</p>'; |
||
| 328 | elseif ( isset( $this->video->title ) ) |
||
| 329 | $html .= '<p>' . esc_html( $this->video->title ) . '</p>'; |
||
| 330 | $html .= '</video>'; |
||
| 331 | return $html; |
||
| 332 | } |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Click to play dynamic HTML5-capable player. |
||
| 336 | * The player displays a video preview section including poster frame, |
||
| 337 | * video title, play button and watermark on the original page load |
||
| 338 | * and calculates the playback capabilities of the browser. The video player |
||
| 339 | * is loaded when the visitor clicks on the video preview area. |
||
| 340 | * If Flash Player 10 or above is available the browser will display |
||
| 341 | * the Flash version of the video. If HTML5 video appears to be supported |
||
| 342 | * and the browser may be capable of MP4 (H.264, AAC) or OGV (Theora, Vorbis) |
||
| 343 | * playback the browser will display its native HTML5 player. |
||
| 344 | * |
||
| 345 | * @since 1.5 |
||
| 346 | * @return string HTML markup |
||
| 347 | */ |
||
| 348 | private function html5_dynamic() { |
||
| 536 | |||
| 537 | function html5_dynamic_next() { |
||
| 538 | $video_container_id = 'v-' . $this->video->guid; |
||
| 539 | |||
| 540 | // Must not use iframes for IE11 due to a fullscreen bug |
||
| 541 | if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && stristr( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0' ) ) { |
||
| 542 | $iframe_embed = false; |
||
| 543 | } else { |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Filter the VideoPress iframe embed |
||
| 547 | * |
||
| 548 | * This filter allows you to control whether the videos will be embedded using an iframe. |
||
| 549 | * Set this to false in order to use an in-page embed rather than an iframe. |
||
| 550 | * |
||
| 551 | * @module videopress |
||
| 552 | * |
||
| 553 | * @since 3.7.0 |
||
| 554 | * |
||
| 555 | * @param boolean $videopress_player_use_iframe |
||
| 556 | */ |
||
| 557 | $iframe_embed = apply_filters( 'jetpack_videopress_player_use_iframe', true ); |
||
| 558 | } |
||
| 559 | |||
| 560 | if ( ! array_key_exists( 'hd', $this->options ) ) { |
||
| 561 | $this->options['hd'] = (bool) get_option( 'video_player_high_quality', false ); |
||
| 562 | } |
||
| 563 | |||
| 564 | $videopress_options = array( |
||
| 565 | 'width' => absint( $this->video->calculated_width ), |
||
| 566 | 'height' => absint( $this->video->calculated_height ), |
||
| 567 | ); |
||
| 568 | foreach ( $this->options as $option => $value ) { |
||
| 569 | switch ( $option ) { |
||
| 570 | case 'at': |
||
| 571 | if ( intval( $value ) ) { |
||
| 572 | $videopress_options[ $option ] = intval( $value ); |
||
| 573 | } |
||
| 574 | break; |
||
| 575 | case 'autoplay': |
||
| 576 | $option = 'autoPlay'; |
||
| 577 | case 'hd': |
||
| 578 | case 'loop': |
||
| 579 | case 'permalink': |
||
| 580 | if ( in_array( $value, array( 1, 'true' ) ) ) { |
||
| 581 | $videopress_options[ $option ] = true; |
||
| 582 | } elseif ( in_array( $value, array( 0, 'false' ) ) ) { |
||
| 583 | $videopress_options[ $option ] = false; |
||
| 584 | } |
||
| 585 | break; |
||
| 586 | case 'defaultlangcode': |
||
| 587 | $option = 'defaultLangCode'; |
||
| 588 | if ( $value ) { |
||
| 589 | $videopress_options[ $option ] = $value; |
||
| 590 | } |
||
| 591 | break; |
||
| 592 | } |
||
| 593 | } |
||
| 594 | |||
| 595 | if ( $iframe_embed ) { |
||
| 596 | $iframe_url = "https://videopress.com/embed/{$this->video->guid}"; |
||
| 597 | |||
| 598 | foreach ( $videopress_options as $option => $value ) { |
||
| 599 | if ( ! in_array( $option, array( 'width', 'height' ) ) ) { |
||
| 600 | |||
| 601 | // add_query_arg ignores false as a value, so replacing it with 0 |
||
| 602 | $iframe_url = add_query_arg( $option, ( false === $value ) ? 0 : $value, $iframe_url ); |
||
| 603 | } |
||
| 604 | } |
||
| 605 | |||
| 606 | $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress-iframe.js'; |
||
| 607 | $js_url = add_query_arg( 'jetpack_version', JETPACK__VERSION, $js_url ); |
||
| 608 | |||
| 609 | return "<iframe width='" . esc_attr( $videopress_options['width'] ) |
||
| 610 | . "' height='" . esc_attr( $videopress_options['height'] ) |
||
| 611 | . "' src='" . esc_attr( $iframe_url ) |
||
| 612 | . "' frameborder='0' allowfullscreen></iframe>" |
||
| 613 | . "<script src='" . esc_attr( $js_url ) . "'></script>"; |
||
| 614 | |||
| 615 | } else { |
||
| 616 | $videopress_options = json_encode( $videopress_options ); |
||
| 617 | $js_url = 'https://s0.wp.com/wp-content/plugins/video/assets/js/next/videopress.js'; |
||
| 618 | $js_url = add_query_arg( 'jetpack_version', JETPACK__VERSION, $js_url ); |
||
| 619 | |||
| 620 | return "<div id='{$video_container_id}'></div> |
||
| 621 | <script src='{$js_url}'></script> |
||
| 622 | <script> |
||
| 623 | videopress('{$this->video->guid}', document.querySelector('#{$video_container_id}'), {$videopress_options}); |
||
| 624 | </script>"; |
||
| 625 | } |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Only allow legitimate Flash parameters and their values |
||
| 630 | * |
||
| 631 | * @since 1.2 |
||
| 632 | * @link http://kb2.adobe.com/cps/127/tn_12701.html Flash object and embed attributes |
||
| 633 | * @link http://kb2.adobe.com/cps/133/tn_13331.html devicefont |
||
| 634 | * @link http://kb2.adobe.com/cps/164/tn_16494.html allowscriptaccess |
||
| 635 | * @link http://www.adobe.com/devnet/flashplayer/articles/full_screen_mode.html full screen mode |
||
| 636 | * @link http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001079.html allownetworking |
||
| 637 | * @param array $flash_params Flash parameters expressed in key-value form |
||
| 638 | * @return array validated Flash parameters |
||
| 639 | */ |
||
| 640 | public static function esc_flash_params( $flash_params ) { |
||
| 641 | $allowed_params = array( |
||
| 642 | 'swliveconnect' => array('true', 'false'), |
||
| 643 | 'play' => array('true', 'false'), |
||
| 644 | 'loop' => array('true', 'false'), |
||
| 645 | 'menu' => array('true', 'false'), |
||
| 646 | 'quality' => array('low', 'autolow', 'autohigh', 'medium', 'high', 'best'), |
||
| 647 | 'scale' => array('default', 'noborder', 'exactfit', 'noscale'), |
||
| 648 | 'align' => array('l', 'r', 't'), |
||
| 649 | 'salign' => array('l', 'r', 't', 'tl', 'tr', 'bl', 'br'), |
||
| 650 | 'wmode' => array('window', 'opaque', 'transparent','direct','gpu'), |
||
| 651 | 'devicefont' => array('_sans', '_serif', '_typewriter'), |
||
| 652 | 'allowscriptaccess' => array('always', 'samedomain', 'never'), |
||
| 653 | 'allownetworking' => array('all','internal', 'none'), |
||
| 654 | 'seamlesstabbing' => array('true', 'false'), |
||
| 655 | 'allowfullscreen' => array('true', 'false'), |
||
| 656 | 'fullScreenAspectRatio' => array('portrait', 'landscape'), |
||
| 657 | 'base', |
||
| 658 | 'bgcolor', |
||
| 659 | 'flashvars' |
||
| 660 | ); |
||
| 661 | |||
| 662 | $allowed_params_keys = array_keys( $allowed_params ); |
||
| 663 | |||
| 664 | $filtered_params = array(); |
||
| 665 | foreach( $flash_params as $param=>$value ) { |
||
| 666 | if ( empty($param) || empty($value) ) |
||
| 667 | continue; |
||
| 668 | $param = strtolower($param); |
||
| 669 | if ( in_array($param, $allowed_params_keys) ) { |
||
| 670 | if ( isset( $allowed_params[$param] ) && is_array( $allowed_params[$param] ) ) { |
||
| 671 | $value = strtolower($value); |
||
| 672 | if ( in_array( $value, $allowed_params[$param] ) ) |
||
| 673 | $filtered_params[$param] = $value; |
||
| 674 | } else { |
||
| 675 | $filtered_params[$param] = $value; |
||
| 676 | } |
||
| 677 | } |
||
| 678 | } |
||
| 679 | unset( $allowed_params_keys ); |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Flash specifies sameDomain, not samedomain. change from lowercase value for preciseness |
||
| 683 | */ |
||
| 684 | if ( isset( $filtered_params['allowscriptaccess'] ) && $filtered_params['allowscriptaccess'] === 'samedomain' ) |
||
| 685 | $filtered_params['allowscriptaccess'] = 'sameDomain'; |
||
| 686 | |||
| 687 | return $filtered_params; |
||
| 688 | } |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Filter Flash variables from the response, taking into consideration player options. |
||
| 692 | * |
||
| 693 | * @since 1.3 |
||
| 694 | * @return array Flash variable key value pairs |
||
| 695 | */ |
||
| 696 | private function get_flash_variables() { |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Validate and filter Flash parameters |
||
| 708 | * |
||
| 709 | * @since 1.3 |
||
| 710 | * @return array Flash parameters passed through key and value validation |
||
| 711 | */ |
||
| 712 | private function get_flash_parameters() { |
||
| 713 | if ( ! isset( $this->video->players->swf->params ) ) |
||
| 714 | return array(); |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Flash player markup in a HTML embed element. |
||
| 732 | * |
||
| 733 | * @since 1.1 |
||
| 734 | * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/the-iframe-element.html#the-embed-element embed element |
||
| 735 | * @link http://www.google.com/support/reader/bin/answer.py?answer=70664 Google Reader markup support |
||
| 736 | * @return string HTML markup. Embed element with no children |
||
| 737 | */ |
||
| 738 | private function flash_embed() { |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Double-baked Flash object markup for Internet Explorer and more standards-friendly consuming agents. |
||
| 765 | * |
||
| 766 | * @since 1.1 |
||
| 767 | * @return HTML markup. Object and children. |
||
| 768 | */ |
||
| 769 | private function flash_object() { |
||
| 811 | } |
||
| 812 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.