Changeset 1848568
- Timestamp:
- 03/28/2018 01:53:23 PM (8 years ago)
- Location:
- fluid-player/trunk
- Files:
-
- 2 edited
-
FluidPlayerPlugin.php (modified) (18 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
fluid-player/trunk/FluidPlayerPlugin.php
r1839207 r1848568 1 1 <?php 2 class FluidPlayerPlugin 3 { 2 class FluidPlayerPlugin { 4 3 5 4 public static $index = 0; … … 28 27 29 28 //Disabling smart quotes filter for shortcode content 30 add_filter( 'no_texturize_shortcodes', function () {29 add_filter('no_texturize_shortcodes', function () { 31 30 $shortcodes[] = 'fluid-player-multi-res-video'; 32 31 $shortcodes[] = 'fluid-player-html-block'; 33 32 $shortcodes[] = 'fluid-player-extended'; 34 33 $shortcodes[] = 'fluid-player'; 34 35 35 return $shortcodes; 36 36 }); 37 37 38 38 //Disabling line breaks and paragraphs from shortcode content. Could have side effects! 39 remove_filter( 'the_content', 'wpautop');40 remove_filter( 'the_excerpt', 'wpautop');39 remove_filter('the_content', 'wpautop'); 40 remove_filter('the_excerpt', 'wpautop'); 41 41 } 42 42 … … 58 58 */ 59 59 public static function shortcodeSimple($attrs) 60 { 61 $params = shortcode_atts([ 62 //See https://exadsdev.atlassian.net/browse/ESR-1783 63 static::VAST_FILE => '', 64 static::VTT_FILE => '', 65 static::VTT_SPRITE => '', 66 static::FP_VIDEO_SOURCES => static::prepareVideoSources([ 67 [ 68 'label' => 'HD', 69 'url' => $attrs['video'] 70 ] 71 ], []), 72 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE, 73 ], $attrs); 74 75 return static::generateContent(static::SCRIPT_CONTENT, $params); 76 } 77 78 79 /** 80 * @param array $attrs 81 * @param string $content 82 * 83 * @return string 84 */ 85 public static function shortcodeExtended($attrs, $content) 60 86 { 61 87 $params = shortcode_atts([ 62 88 //See https://exadsdev.atlassian.net/browse/ESR-1783 63 89 static::VAST_FILE => '', 64 static::VTT_FILE => '',90 static::VTT_FILE => '', 65 91 static::VTT_SPRITE => '', 66 static::FP_VIDEO_SOURCES => static::prepareVideoSources([['label' => '720', 'url' => $attrs['video']]], []), 67 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE, 68 ], $attrs); 69 70 return static::generateContent(static::SCRIPT_SIMPLE, $params); 71 } 72 73 74 /** 75 * @param array $attrs 76 * @param string $content 77 * 78 * @return string 79 */ 80 public static function shortcodeExtended($attrs, $content) 81 { 82 $params = shortcode_atts([ 83 //See https://exadsdev.atlassian.net/browse/ESR-1783 84 static::VAST_FILE => '', 85 static::VTT_FILE => '', 86 87 static::VTT_SPRITE => '', 88 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE, 89 90 static::FP_OPTIONS_AUTOPLAY => 'false', 91 static::FP_OPTIONS_LOGO => plugin_dir_url(__FILE__) . 'web/images/yourlogo.png', 92 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE, 93 94 static::FP_OPTIONS_AUTOPLAY => 'false', 95 static::FP_OPTIONS_LOGO => plugin_dir_url(__FILE__) . 'web/images/yourlogo.png', 92 96 static::FP_OPTIONS_LOGO_POSITION => 'top left', 93 static::FP_OPTIONS_LOGO_OPACITY => '1', 94 static::FP_OPTIONS_AD_TEXT => '', 95 static::FP_OPTIONS_AD_TEXT_CTA => '', 96 static::FP_OPTIONS_RESPONSIVE => false, 97 static::FP_OPTIONS_LOGO_OPACITY => '1', 98 static::FP_OPTIONS_AD_TEXT => '', 99 static::FP_OPTIONS_AD_TEXT_CTA => '', 100 static::FP_OPTIONS_RESPONSIVE => false, 101 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH => 100, 102 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT => 100, 97 103 ], $attrs); 98 104 … … 114 120 ); 115 121 116 return static::generateContent(static::SCRIPT_ EXTENDED, $params);117 } 118 119 private static function get PlayerOptions($params)122 return static::generateContent(static::SCRIPT_CONTENT, $params); 123 } 124 125 private static function getLayoutOptions($params) 120 126 { 121 127 $options = static::getDefaultOptions(); … … 129 135 130 136 //Autoplay 131 if ( isset($params[static::FP_OPTIONS_AUTOPLAY_JS])) {132 $options[static::FP_OPTIONS_AUTOPLAY_JS] = false;137 if ($params[static::FP_OPTIONS_AUTOPLAY_JS] !== 'false') { 138 $options[static::FP_OPTIONS_AUTOPLAY_JS] = true; 133 139 } 134 140 135 141 //Logo 136 142 if (isset($params[static::FP_OPTIONS_LOGO_JS])) { 137 $options[static::FP_OPTIONS_LOGO_JS] = $params[static::FP_OPTIONS_LOGO_JS]; 143 $options[static::FP_OPTIONS_LOGO_JS] = []; 144 $options[static::FP_OPTIONS_LOGO_JS]['imageUrl'] = $params[static::FP_OPTIONS_LOGO_JS]; 138 145 139 146 //logoPosition 140 147 if (isset($params[static::FP_OPTIONS_LOGO_POSITION_JS])) { 141 $options[static::FP_OPTIONS_LOGO_ POSITION_JS] = $params[static::FP_OPTIONS_LOGO_POSITION_JS];148 $options[static::FP_OPTIONS_LOGO_JS]['position'] = $params[static::FP_OPTIONS_LOGO_POSITION_JS]; 142 149 } 143 150 144 151 //logoOpacity 145 152 if (isset($params[static::FP_OPTIONS_LOGO_OPACITY_JS])) { 146 $options[static::FP_OPTIONS_LOGO_ OPACITY_JS] = $params[static::FP_OPTIONS_LOGO_OPACITY_JS];153 $options[static::FP_OPTIONS_LOGO_JS]['opacity'] = $params[static::FP_OPTIONS_LOGO_OPACITY_JS]; 147 154 } 155 } 156 157 //htmlOnPauseBlock 158 if (isset($params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS])) { 159 $options[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS] = [ 160 'html' => $params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS], 161 ]; 162 163 if (isset($params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS])) { 164 $options[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS]['width'] = (int)$params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS]; 165 } 166 167 if (isset($params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT_JS])) { 168 $options[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS]['height'] = (int)$params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT_JS]; 169 } 170 } 171 172 //responsive 173 if ($params[static::FP_OPTIONS_RESPONSIVE_JS] !== 'false') { 174 $options[static::FP_OPTIONS_RESPONSIVE_JS] = true; 175 } 176 177 $options[static::FP_TIMELINE_OBJ][static::FP_TIMELINE_FILE] = $params[static::VTT_FILE]; 178 $options[static::FP_TIMELINE_OBJ][static::FP_TIMELINE_SPRITE] = $params[static::VTT_SPRITE]; 179 180 return $options; 181 } 182 183 private static function getVastOptions($params) 184 { 185 $options = static::getDefaultOptions(); 186 unset($options[static::FP_LAYOUT]); 187 unset($options[static::FP_TIMELINE_OBJ]); 188 189 //VAST 190 if (isset($params[static::VAST_FILE])) { 191 $options['adList'] = [ 192 [ 193 'roll' => 'preRoll', 194 'vastTag' => $params[static::VAST_FILE] 195 ], 196 ]; 148 197 } 149 198 … … 158 207 } 159 208 160 //htmlOnPauseBlock161 if (isset($params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS])) {162 $options[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS] = $params[static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS];163 }164 165 166 $options[static::FP_TIMELINE_OBJ][static::FP_TIMELINE_FILE] = $params[static::VTT_FILE];167 $options[static::FP_TIMELINE_OBJ][static::FP_TIMELINE_SPRITE] = $params[static::VTT_SPRITE];168 169 209 return $options; 170 210 } 171 211 172 public static function getDefaultOptions() { 212 public static function getDefaultOptions() 213 { 173 214 return [ 174 215 static::FP_TIMELINE_OBJ => [ 175 static::FP_TIMELINE_FILE => '',216 static::FP_TIMELINE_FILE => '', 176 217 static::FP_TIMELINE_SPRITE => '', 177 static::FP_TIMELINE_TYPE => 'VTT',218 static::FP_TIMELINE_TYPE => 'VTT', 178 219 ], 179 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE220 static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE 180 221 ]; 181 222 } … … 186 227 * @return array 187 228 */ 188 private static function extractVideos($content) { 189 $content = preg_replace('/\s+/', ' ',$content); 229 private static function extractVideos($content) 230 { 231 $content = preg_replace('/\s+/', ' ', $content); 190 232 preg_match('/(\[.*\])/s', $content, $matches); 233 191 234 return json_decode($matches[0], true); 192 235 } 193 236 194 private static function getVideoSourceString($video) { 237 private static function getVideoSourceString($video) 238 { 195 239 return '<source title="' . $video['label'] . '" src=' . $video['url'] . ' type="video/mp4" />'; 196 240 } … … 202 246 * @return string 203 247 */ 204 private static function prepareVideoSources( $videos , $fallbackVideo ) { 248 private static function prepareVideoSources($videos, $fallbackVideo) 249 { 205 250 206 251 if (is_null($videos)) { … … 222 267 * @return mixed 223 268 */ 224 private static function generateContent( $mold, $params ) { 269 private static function generateContent($mold, $params) 270 { 225 271 $shortcodeContent = str_replace( 226 272 [ … … 228 274 '{' . static::FP_VIDEO . '}', 229 275 '{' . static::FP_VIDEO_SOURCES . '}', 230 '{' . static::VAST_FILE . '}', 231 '{' . static::FP_OPTIONS . '}', 276 '{' . static::FP_LAYOUT_OPTIONS . '}', 277 '{' . static::FP_VAST_OPTIONS . '}', 278 //'{' . static::VAST_FILE . '}', 279 //'{' . static::FP_OPTIONS . '}', 232 280 ], 233 281 [ 234 static::$index ++,282 static::$index ++, 235 283 $params[static::FP_VIDEO], 236 284 $params[static::FP_VIDEO_SOURCES], 237 $params[static::VAST_FILE], 238 json_encode(static::getPlayerOptions(static::getRemappedParams($params))), 285 json_encode(static::getLayoutOptions(static::getRemappedParams($params))), 286 json_encode(static::getVastOptions(static::getRemappedParams($params))), 287 //$params[static::VAST_FILE], 288 //json_encode(static::getPlayerOptions(static::getRemappedParams($params))), 239 289 ], 240 290 $mold 241 291 ); 292 242 293 return $shortcodeContent; 243 294 } … … 249 300 * @return string 250 301 */ 251 private static function extractShortCode( $content, $shortcodeTag ) { 302 private static function extractShortCode($content, $shortcodeTag) 303 { 252 304 $content = trim(preg_replace('/\s\s+/', ' ', $content)); 253 preg_match("/\[" . $shortcodeTag. "\](.*)\[\/" . $shortcodeTag . "\]/", $content, $output_array); 305 preg_match("/\[" . $shortcodeTag . "\](.*)\[\/" . $shortcodeTag . "\]/", $content, $output_array); 306 254 307 return $output_array[1]; 255 308 } 256 309 257 private static function initShortcodeToJSMapping() { 310 private static function initShortcodeToJSMapping() 311 { 258 312 static::$shortcodeToJSMapping = [ 259 static::FP_LAYOUT => static::FP_LAYOUT,260 static::FP_OPTIONS_AUTOPLAY => static::FP_OPTIONS_AUTOPLAY_JS,261 static::FP_OPTIONS_LOGO => static::FP_OPTIONS_LOGO_JS,262 static::FP_OPTIONS_LOGO_POSITION => static::FP_OPTIONS_LOGO_POSITION_JS,263 static::FP_OPTIONS_LOGO_OPACITY => static::FP_OPTIONS_LOGO_OPACITY_JS,264 static::FP_OPTIONS_AD_TEXT => static::FP_OPTIONS_AD_TEXT_JS,265 static::FP_OPTIONS_AD_TEXT_CTA => static::FP_OPTIONS_AD_TEXT_CTA_JS,266 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK => static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS,267 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH => static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS,313 static::FP_LAYOUT => static::FP_LAYOUT, 314 static::FP_OPTIONS_AUTOPLAY => static::FP_OPTIONS_AUTOPLAY_JS, 315 static::FP_OPTIONS_LOGO => static::FP_OPTIONS_LOGO_JS, 316 static::FP_OPTIONS_LOGO_POSITION => static::FP_OPTIONS_LOGO_POSITION_JS, 317 static::FP_OPTIONS_LOGO_OPACITY => static::FP_OPTIONS_LOGO_OPACITY_JS, 318 static::FP_OPTIONS_AD_TEXT => static::FP_OPTIONS_AD_TEXT_JS, 319 static::FP_OPTIONS_AD_TEXT_CTA => static::FP_OPTIONS_AD_TEXT_CTA_JS, 320 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK => static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS, 321 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH => static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS, 268 322 static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT => static::FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT_JS, 269 static::FP_OPTIONS_RESPONSIVE => static::FP_OPTIONS_RESPONSIVE_JS, 323 static::FP_OPTIONS_RESPONSIVE => static::FP_OPTIONS_RESPONSIVE_JS, 324 static::FP_VAST_FILE => static::FP_VAST_FILE_JS, 270 325 ]; 271 326 } … … 276 331 * @return array 277 332 */ 278 private static function getRemappedParams( $params ) { 333 private static function getRemappedParams($params) 334 { 279 335 $remappedParams = []; 280 foreach ($params as $key => $value) {336 foreach ($params as $key => $value) { 281 337 $remappedParams[static::$shortcodeToJSMapping[$key]] = $value; 282 338 } … … 286 342 287 343 const FP_CDN_ROOT_URL = 'https://cdn.fluidplayer.com'; 288 const FP_CDN_CURRENT_URL = 'https://cdn.fluidplayer.com/v 1/current';344 const FP_CDN_CURRENT_URL = 'https://cdn.fluidplayer.com/v2/current'; 289 345 290 346 const FP_ID = 'id'; … … 293 349 const FP_LAYOUT = 'layout'; 294 350 const FP_LAYOUT_DEFAULT_VALUE = 'default'; 295 const FP_OPTIONS = 'fp_options'; 351 const FP_LAYOUT_OPTIONS = 'layout_options'; 352 const FP_VAST_OPTIONS = 'vast_options'; 296 353 297 354 const FP_OPTIONS_AUTOPLAY = 'auto-play'; … … 304 361 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH = 'html-on-pause-block-width'; 305 362 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT = 'html-on-pause-block-height'; 306 const FP_OPTIONS_RESPONSIVE = 'responsive'; 363 const FP_OPTIONS_RESPONSIVE = 'responsive'; //Keeping the old shortcode param for legacy reasons 364 const FP_VAST_FILE = 'vast_file'; 307 365 308 366 const FP_OPTIONS_AUTOPLAY_JS = 'autoPlay'; 309 const FP_OPTIONS_LOGO_JS = 'logo'; 310 const FP_OPTIONS_LOGO_POSITION_JS = 'logoPosition'; 311 const FP_OPTIONS_LOGO_OPACITY_JS = 'logoOpacity'; 312 const FP_OPTIONS_AD_TEXT_JS = 'adText'; 313 const FP_OPTIONS_AD_TEXT_CTA_JS = 'adCTAText'; 314 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS = 'htmlOnPauseBlock'; 315 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS = 'htmlOnPauseBlockWidth'; 316 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT_JS = 'htmlOnPauseBlockHeight'; 317 const FP_OPTIONS_RESPONSIVE_JS = 'responsive'; 367 const FP_OPTIONS_LOGO_JS = 'logo'; //TODO: update this 368 const FP_OPTIONS_LOGO_POSITION_JS = 'logoPosition';//TODO: update this 369 const FP_OPTIONS_LOGO_OPACITY_JS = 'logoOpacity';//TODO: update this 370 const FP_OPTIONS_AD_TEXT_JS = 'adText';//TODO: Move to Vast 371 const FP_OPTIONS_AD_TEXT_CTA_JS = 'adCTAText';//TODO: Move to Vast 372 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_JS = 'htmlOnPauseBlock';//TODO update this 373 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH_JS = 'htmlOnPauseBlockWidth';//TODO: Update this 374 const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_HEIGHT_JS = 'htmlOnPauseBlockHeight';//TODO: Update this 375 const FP_OPTIONS_RESPONSIVE_JS = 'fillToContainer'; 376 const FP_VAST_FILE_JS = 'vast_file'; 318 377 319 378 static $shortcodeToJSMapping = array(); … … 329 388 330 389 331 const SCRIPT_ SIMPLE= <<<SCRIPT332 <video id='fp-video-{id}' controls style="width: 100%;">390 const SCRIPT_CONTENT = <<<SCRIPT 391 <video id='fp-video-{id}' controls> 333 392 {video_sources} 334 393 </video> … … 339 398 var testVideo = fluidPlayer( 340 399 'fp-video-{id}', 341 '{vast_file}', 342 {fp_options} 400 /* '{vast_file}', fp_options} */ 401 { 402 layoutControls: {layout_options}, 403 vastOptions: {vast_options} 404 } 343 405 ); 344 406 }; … … 353 415 </script> 354 416 SCRIPT; 355 356 const SCRIPT_EXTENDED = <<<SCRIPT357 <video id='fp-video-{id}' controls style="width: 100%;">358 {video_sources}359 </video>360 361 <script id="fp-container-{id}" type="text/javascript">362 363 var fluidPlayerPluginExtended{id} = function() {364 var testVideo = fluidPlayer(365 'fp-video-{id}',366 '{vast_file}',367 {fp_options}368 );369 };370 (function defer() {371 if (typeof(fluidPlayer) != 'undefined') {372 fluidPlayerPluginExtended{id}();373 } else {374 setTimeout(defer, 50);375 }376 })();377 </script>378 SCRIPT;379 417 } -
fluid-player/trunk/readme.txt
r1839207 r1848568 6 6 Donate link: http://example.com/ 7 7 Tags: Fluid Player, html5 video player, VAST, thumbnails 8 Version: 1.38 Version: 2.0 9 9 Requires at least: 4.6 10 10 Tested up to: 4.9.4 … … 35 35 * vtt_file : path to VTT file (optional) 36 36 * vtt_sprite : path to VTT sprites file (optional) 37 * layout : any of the following themes are provided with the player: default/funky/metal, if no value is passed it will fall back to 'default'37 * layout : the following skins are provided with the player: default/browser, if no value is passed it will fall back to 'default' 38 38 * auto-play : toggle video autoplay, defaults to false 39 39 * logo : Logo url … … 54 54 [fluid-player-extended 55 55 vast_file="vast.xml" 56 layout=" funky"56 layout="default" 57 57 auto-play="autoPlay" 58 58 logo="https://www.fluidplayer.com/images/yourlogo.png" … … 63 63 html-on-pause-block-width="100" 64 64 html-on-pause-block-height="100" 65 responsive="responsive"] 66 65 responsive="true"] 67 66 68 67 [fluid-player-multi-res-video]
Note: See TracChangeset
for help on using the changeset viewer.