Plugin Directory

Changeset 2981712


Ignore:
Timestamp:
10/20/2023 01:32:52 PM (2 years ago)
Author:
playerjs
Message:

2.22 Asynchronous script loading

Location:
playerjs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • playerjs/tags/2.2/playerjs.php

    r1979095 r2981712  
    33 * Plugin Name:       PlayerJS
    44 * Plugin URI:        https://playerjs.com/docs/q=wordpress
    5  * Description:       Embed your player from PlayerJS Builder and play HTML5 Video, Audio, HLS, DASH, YouTube, Vimeo
    6  * Version:           2.2
     5 * Description:       Embed your created player in PlayerJS Builder and play HTML5 Video, Audio, HLS, DASH, YouTube, Vimeo
     6 * Version:           2.21
    77 * Author:            Playerjs.com
    88 * Author URI:        https://playerjs.com
     
    2929        class PLAYERJS_HTML5 {
    3030
    31             var $plugin_version = '2.1';
     31            var $plugin_version = '2.21';
    3232
    3333            function __construct() {
    3434                define('PLAYERJS_VERSION', $this->plugin_version);
     35                add_action('wp_enqueue_scripts',array($this, 'plugin_script'));
    3536                $this->plugin_includes();
    3637            }
    3738
    38             function plugin_includes() {
     39            function plugin_script() {
    3940                $path = get_option('playerjs_com_script_path');
    4041                $path = $path ? $path['input'] : '';
     
    4243                    $path = plugins_url('').'/playerjs/playerjs_default.js';
    4344                }
    44 
    4545                wp_enqueue_script('playerjs-js', $path);
    46 
     46            }
     47
     48            function plugin_includes() {
    4749                add_filter('the_content', 'playerjs_content' );
    4850                add_shortcode('playerjs', 'playerjs_com_handler');
    49 
    50 
    5151                add_filter('widget_text', 'do_shortcode');
    5252                add_filter('the_excerpt', 'do_shortcode', 11);
     
    6666}
    6767
    68 function playerjs_content($str){
    69     $stack = array();
    70     $out = '';
    71     for ($i = 0, $l = strlen($str); $i < $l; ++$i) {
    72         if ($str[$i] == "[") {
    73             $stack[] = true;
    74 
    75             if (count($stack) % 2) { // alternate between ( and [
    76                 $out .= "[";
    77             } else {
    78                 $out .= "&#91;";
    79             }
    80         } else if ($str[$i] == "]") {
    81             if (count($stack) % 2) {
    82                 $out .= "]";
    83             } else {
    84                 $out .= "&#93;";
    85             }
    86             array_pop($stack);
    87         } else {
    88             $out .= $str[$i];
    89         }
    90     }
    91     return $out;
     68function playerjs_content($x){
     69    $y = strpos($x,'[playerjs');
     70    if($y!==FALSE){
     71        $z = explode('[playerjs',$x);
     72        for ($i = ($y===0?0:1); $i < count($z); $i++) {
     73            $open=0;
     74            $x1 = 'playerjs';
     75            for ($j = 0; $j < strlen($z[$i]); $j++) {
     76
     77                if ($z[$i][$j] == "]" && $open==0) {
     78                    break;
     79                }else{
     80                    if($z[$i][$j] == "["){
     81                        $open++;
     82                    }
     83                    if($z[$i][$j] == "]"){
     84                        $open--;
     85                    }
     86                    $x1.= $z[$i][$j];
     87                }
     88            }
     89            if($x1!=''){
     90                $x2 = str_replace('[','&#91;',$x1);
     91                $x2 = str_replace(']','&#93;',$x2);
     92                $x2 = str_replace("'",'&#8216;',$x2);
     93                $x = str_replace("[".$x1."]","[".$x2."]",$x);
     94            }
     95        }
     96    }
     97    return $x;
    9298}
    9399
    94100function playerjs_com_handler($atts) {
    95     $x='';
    96 
    97     if(isset($atts['file'])){
     101    $x = '';
     102    $u = wp_get_current_user();
     103
     104    if(isset($atts['file'])||isset($atts['replace'])){
    98105
    99106        $r = rand(10000,20000);
     
    101108        $style = '';
    102109
    103         $vars = '';
    104110        foreach ($atts as $k => $v){
    105111            if(gettype($k) == "integer" && isset($k0)){
     
    111117        }
    112118        foreach ($atts as $k => $v){
     119            $vars = '';
    113120            $v = str_replace("&#091;","[",$v);
    114121            $v = str_replace("&#093;","]",$v);
    115122            $v = str_replace("&#187;","",$v);
    116123            $v = str_replace("&#8243;","",$v);
    117 
    118             if($k!='align' && $k!='margin' && $k!='width' && $k!='height'){
     124            $v = str_replace("&#8221;","",$v);
     125
     126            if(strpos($v,"[")!==false && strpos($v,"{")!==false){
     127                $v = str_replace("&#8216;","pjs'qt",$v);
     128                $v = str_replace("&#8217;","pjs'qt",$v);
     129                $v = str_replace("&#8242;","pjs'qt",$v);
     130            }
     131
     132            if($k=="file"){
     133                $r = md5($v);
     134                $base = dirname( __FILE__ ) . '/admin/playerjs_base64.php';
     135                if(file_exists($base)){
     136                    include_once($base);
     137                    $v = pjsBase64Encrypt($v);
     138                }
     139            }
     140
     141           
     142
     143            $dont = false;
     144            if($k=="watermark" && $v==1){
     145                if($u){
     146                    if($u->data->ID>0){
     147                        $vars.=',wid:"'.$u->data->user_login.'"';
     148                        $dont = true;
     149                    }
     150                }
     151            }
     152
     153            if(!$dont && $k!='align' && $k!='margin' && $k!='width' && $k!='height'){
    119154                $vars .= ','.$k.':"'.$v.'"';
    120155            }
     156        }
     157
     158        if(!isset($atts['replace'])){
     159            $vars.= ',id:"playerjs'.$r.'"';
    121160        }
    122161
     
    134173        // width
    135174
    136         $width = playerjs_com_get_option('width',0);
     175        $width = playerjs_com_get_option('width',0,'');
    137176
    138177        isset($atts['width'])?$width = $atts['width']:'';
     
    159198        }
    160199
    161 
    162 
    163         $x = $height.($align=='center'?'<center>':'').'<div id="playerjs'.$r.'" '.($style!=''?'style="'.$style.'"':'').'></div>'.($align=='center'?'</center>':'').'<script>var player'.$r.' = new Playerjs({id:"playerjs'.$r.'"'.$vars.'});</script>';
     200        if(!isset($atts['replace'])){
     201            $x = ($align=='center'?'<center>':'').'<div id="playerjs'.$r.'" '.($style!=''?'style="'.$style.'"':'').'></div>'.($align=='center'?'</center>':'');
     202        }else{
     203            $x = '';
     204        }
     205
     206        if(substr($vars,0,1)==","){
     207            $vars = substr($vars,1);
     208        }
     209
     210        $x.='<script>var player'.$r.' = new Playerjs({'.$vars.'});</script>';
    164211
    165212    }
  • playerjs/trunk/playerjs.php

    r2979265 r2981712  
    44 * Plugin URI:        https://playerjs.com/docs/q=wordpress
    55 * Description:       Embed your created player in PlayerJS Builder and play HTML5 Video, Audio, HLS, DASH, YouTube, Vimeo
    6  * Version:           2.21
     6 * Version:           2.22
    77 * Author:            Playerjs.com
    88 * Author URI:        https://playerjs.com
     
    2929        class PLAYERJS_HTML5 {
    3030
    31             var $plugin_version = '2.21';
     31            var $plugin_version = '2.22';
    3232
    3333            function __construct() {
     
    4747
    4848            function plugin_includes() {
    49                 add_filter('the_content', 'playerjs_content' );
     49                add_filter('the_content', 'playerjs_content');
    5050                add_shortcode('playerjs', 'playerjs_com_handler');
    5151                add_filter('widget_text', 'do_shortcode');
    5252                add_filter('the_excerpt', 'do_shortcode', 11);
    5353                add_filter('the_content', 'do_shortcode', 11);
    54             }
    55 
    56         }
    57 
     54                add_filter('the_content', 'playerjs_content2',12);
     55                add_filter( 'script_loader_tag', 'playerjs_async', 11, 2);
     56            }
     57
     58        }
     59        $GLOBALS['playerjs_configs'] = new stdClass();
    5860        $GLOBALS['playerjs_player'] = new PLAYERJS_HTML5();
    5961
    6062    }
    6163
     64}
     65 
     66function playerjs_async( $tag, $handle ) {
     67    if ( 'playerjs-js' !== $handle ) {
     68        return $tag;
     69    }
     70    return str_replace( ' src', ' async="async" src', $tag );
    6271}
    6372
     
    98107}
    99108
     109function playerjs_content2($x){
     110    $p = $GLOBALS['playerjs_configs'];
     111    if(isset($p)){
     112        $x.= '<script>function PlayerjsAsync(){';
     113        foreach ($p as $k => $v){
     114            $x.='var '.$k.' = new Playerjs({'.$v.'});';
     115        }
     116    }
     117    return $x.'} if(window["Playerjs"]){PlayerjsAsync();}</script>';
     118}
     119
    100120function playerjs_com_handler($atts) {
    101121    $x = '';
     
    207227            $vars = substr($vars,1);
    208228        }
    209 
    210         $x.='<script>var player'.$r.' = new Playerjs({'.$vars.'});</script>';
    211 
     229        $GLOBALS['playerjs_configs']->{'player'.$r} = $vars;
    212230    }
    213231    return $x;
  • playerjs/trunk/readme.txt

    r2979249 r2981712  
    146146= 2.20-2.21 =
    147147* Bug fixed
     148
     149= 2.22 =
     150* Asynchronous script loading
Note: See TracChangeset for help on using the changeset viewer.