Plugin Directory

Changeset 1848568


Ignore:
Timestamp:
03/28/2018 01:53:23 PM (8 years ago)
Author:
fluidplayer
Message:

Bringing WP plugin to V2 of Fluid Player

Location:
fluid-player/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fluid-player/trunk/FluidPlayerPlugin.php

    r1839207 r1848568  
    11<?php
    2 class FluidPlayerPlugin
    3 {
     2class FluidPlayerPlugin {
    43
    54    public static $index = 0;
     
    2827
    2928        //Disabling smart quotes filter for shortcode content
    30         add_filter( 'no_texturize_shortcodes', function () {
     29        add_filter('no_texturize_shortcodes', function () {
    3130            $shortcodes[] = 'fluid-player-multi-res-video';
    3231            $shortcodes[] = 'fluid-player-html-block';
    3332            $shortcodes[] = 'fluid-player-extended';
    3433            $shortcodes[] = 'fluid-player';
     34
    3535            return $shortcodes;
    3636        });
    3737
    3838        //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');
    4141    }
    4242
     
    5858     */
    5959    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)
    6086    {
    6187        $params = shortcode_atts([
    6288            //See https://exadsdev.atlassian.net/browse/ESR-1783
    6389            static::VAST_FILE => '',
    64             static::VTT_FILE => '',
     90            static::VTT_FILE  => '',
    6591            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',
    9296            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,
    97103        ], $attrs);
    98104
     
    114120        );
    115121
    116         return static::generateContent(static::SCRIPT_EXTENDED, $params);
    117     }
    118 
    119     private static function getPlayerOptions($params)
     122        return static::generateContent(static::SCRIPT_CONTENT, $params);
     123    }
     124
     125    private static function getLayoutOptions($params)
    120126    {
    121127        $options = static::getDefaultOptions();
     
    129135
    130136        //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;
    133139        }
    134140
    135141        //Logo
    136142        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];
    138145
    139146            //logoPosition
    140147            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];
    142149            }
    143150
    144151            //logoOpacity
    145152            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];
    147154            }
     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            ];
    148197        }
    149198
     
    158207        }
    159208
    160         //htmlOnPauseBlock
    161         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 
    169209        return $options;
    170210    }
    171211
    172     public static function getDefaultOptions() {
     212    public static function getDefaultOptions()
     213    {
    173214        return [
    174215            static::FP_TIMELINE_OBJ => [
    175                 static::FP_TIMELINE_FILE => '',
     216                static::FP_TIMELINE_FILE   => '',
    176217                static::FP_TIMELINE_SPRITE => '',
    177                 static::FP_TIMELINE_TYPE => 'VTT',
     218                static::FP_TIMELINE_TYPE   => 'VTT',
    178219            ],
    179             static::FP_LAYOUT => static::FP_LAYOUT_DEFAULT_VALUE
     220            static::FP_LAYOUT       => static::FP_LAYOUT_DEFAULT_VALUE
    180221        ];
    181222    }
     
    186227     * @return array
    187228     */
    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);
    190232        preg_match('/(\[.*\])/s', $content, $matches);
     233
    191234        return json_decode($matches[0], true);
    192235    }
    193236
    194     private static function getVideoSourceString($video) {
     237    private static function getVideoSourceString($video)
     238    {
    195239        return '<source title="' . $video['label'] . '" src=' . $video['url'] . ' type="video/mp4" />';
    196240    }
     
    202246     * @return string
    203247     */
    204     private static function prepareVideoSources( $videos , $fallbackVideo ) {
     248    private static function prepareVideoSources($videos, $fallbackVideo)
     249    {
    205250
    206251        if (is_null($videos)) {
     
    222267     * @return mixed
    223268     */
    224     private static function generateContent( $mold, $params ) {
     269    private static function generateContent($mold, $params)
     270    {
    225271        $shortcodeContent = str_replace(
    226272            [
     
    228274                '{' . static::FP_VIDEO . '}',
    229275                '{' . 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 . '}',
    232280            ],
    233281            [
    234                 static::$index++,
     282                static::$index ++,
    235283                $params[static::FP_VIDEO],
    236284                $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))),
    239289            ],
    240290            $mold
    241291        );
     292
    242293        return $shortcodeContent;
    243294    }
     
    249300     * @return string
    250301     */
    251     private static function extractShortCode( $content, $shortcodeTag ) {
     302    private static function extractShortCode($content, $shortcodeTag)
     303    {
    252304        $content = trim(preg_replace('/\s\s+/', ' ', $content));
    253         preg_match("/\[" . $shortcodeTag. "\](.*)\[\/" . $shortcodeTag . "\]/", $content, $output_array);
     305        preg_match("/\[" . $shortcodeTag . "\](.*)\[\/" . $shortcodeTag . "\]/", $content, $output_array);
     306
    254307        return $output_array[1];
    255308    }
    256309
    257     private static function initShortcodeToJSMapping() {
     310    private static function initShortcodeToJSMapping()
     311    {
    258312        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,
    268322            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,
    270325        ];
    271326    }
     
    276331     * @return array
    277332     */
    278     private static function getRemappedParams( $params ) {
     333    private static function getRemappedParams($params)
     334    {
    279335        $remappedParams = [];
    280         foreach($params as $key => $value) {
     336        foreach ($params as $key => $value) {
    281337            $remappedParams[static::$shortcodeToJSMapping[$key]] = $value;
    282338        }
     
    286342
    287343    const FP_CDN_ROOT_URL = 'https://cdn.fluidplayer.com';
    288     const FP_CDN_CURRENT_URL = 'https://cdn.fluidplayer.com/v1/current';
     344    const FP_CDN_CURRENT_URL = 'https://cdn.fluidplayer.com/v2/current';
    289345
    290346    const FP_ID = 'id';
     
    293349    const FP_LAYOUT = 'layout';
    294350    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';
    296353
    297354    const FP_OPTIONS_AUTOPLAY = 'auto-play';
     
    304361    const FP_OPTIONS_HTML_ON_PAUSE_BLOCK_WIDTH = 'html-on-pause-block-width';
    305362    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';
    307365
    308366    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';
    318377
    319378    static $shortcodeToJSMapping = array();
     
    329388
    330389
    331     const SCRIPT_SIMPLE = <<<SCRIPT
    332 <video id='fp-video-{id}' controls style="width: 100%;">
     390    const SCRIPT_CONTENT = <<<SCRIPT
     391<video id='fp-video-{id}' controls>
    333392    {video_sources}
    334393</video>
     
    339398    var testVideo = fluidPlayer(
    340399        'fp-video-{id}',
    341         '{vast_file}',
    342         {fp_options}
     400        /* '{vast_file}', fp_options} */
     401        {
     402            layoutControls: {layout_options},
     403            vastOptions: {vast_options}
     404        }
    343405    );
    344406};
     
    353415</script>
    354416SCRIPT;
    355 
    356 const SCRIPT_EXTENDED = <<<SCRIPT
    357 <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;
    379417}
  • fluid-player/trunk/readme.txt

    r1839207 r1848568  
    66Donate link: http://example.com/
    77Tags: Fluid Player, html5 video player, VAST, thumbnails
    8 Version: 1.3
     8Version: 2.0
    99Requires at least: 4.6
    1010Tested up to: 4.9.4
     
    3535* vtt_file : path to VTT file (optional)
    3636* 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'
    3838* auto-play : toggle video autoplay, defaults to false
    3939* logo : Logo url
     
    5454[fluid-player-extended
    5555    vast_file="vast.xml"
    56     layout="funky"
     56    layout="default"
    5757    auto-play="autoPlay"
    5858    logo="https://www.fluidplayer.com/images/yourlogo.png"
     
    6363    html-on-pause-block-width="100"
    6464    html-on-pause-block-height="100"
    65     responsive="responsive"]
    66 
     65    responsive="true"]
    6766
    6867    [fluid-player-multi-res-video]
Note: See TracChangeset for help on using the changeset viewer.