| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: PlayerJS - Free Custom HTML5 Video and Audio Player Builder |
| 4 |
* Plugin URI: https://playerjs.com/docs/q=wordpress |
| 5 |
* Description: Build custom HTML5 video and audio players with the free PlayerJS online builder and embed them in WordPress using a simple shortcode |
| 6 |
* Version: 2.25 |
| 7 |
* Author: Playerjs.com |
| 8 |
* Author URI: https://playerjs.com |
| 9 |
* License: GPL-2.0+ |
| 10 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 11 |
* Text Domain: playerjs |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
if (!defined('ABSPATH')) { |
| 16 |
exit; |
| 17 |
} |
| 18 |
|
| 19 |
if(is_admin()) { |
| 20 |
|
| 21 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'playerjs_com_action_links' ); |
| 22 |
|
| 23 |
include( dirname( __FILE__ ) . '/admin/playerjs_com_admin.php' ); |
| 24 |
|
| 25 |
}else{ |
| 26 |
|
| 27 |
if (!class_exists('PLAYERJS_HTML5')) { |
| 28 |
|
| 29 |
class PLAYERJS_HTML5 { |
| 30 |
|
| 31 |
var $plugin_version = '2.25'; |
| 32 |
|
| 33 |
function __construct() { |
| 34 |
define('PLAYERJS_VERSION', $this->plugin_version); |
| 35 |
add_action('wp_enqueue_scripts',array($this, 'plugin_script')); |
| 36 |
$this->plugin_includes(); |
| 37 |
} |
| 38 |
|
| 39 |
function plugin_script() { |
| 40 |
$path = get_option('playerjs_com_script_path'); |
| 41 |
$path = $path ? $path['input'] : ''; |
| 42 |
if(trim($path)==''){ |
| 43 |
$path = plugins_url('').'/playerjs/playerjs_default.js'; |
| 44 |
} |
| 45 |
wp_enqueue_script('playerjs-js', $path); |
| 46 |
} |
| 47 |
|
| 48 |
function plugin_includes() { |
| 49 |
add_filter('the_content', 'playerjs_content'); |
| 50 |
add_shortcode('playerjs', 'playerjs_com_handler'); |
| 51 |
add_filter('widget_text', 'do_shortcode'); |
| 52 |
add_filter('the_excerpt', 'do_shortcode', 11); |
| 53 |
add_filter('the_content', 'do_shortcode', 11); |
| 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(); |
| 60 |
$GLOBALS['playerjs_player'] = new PLAYERJS_HTML5(); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
function playerjs_async( $tag, $handle ) { |
| 67 |
if ( 'playerjs-js' !== $handle ) { |
| 68 |
return $tag; |
| 69 |
} |
| 70 |
return str_replace( ' src', ' async="async" src', $tag ); |
| 71 |
} |
| 72 |
|
| 73 |
function playerjs_com_action_links ( $links ) { |
| 74 |
$mylinks = array('<a href="' . admin_url( 'options-general.php?page=playerjs_com_admin' ) . '">Settings</a>'); return array_merge($links, $mylinks); |
| 75 |
} |
| 76 |
|
| 77 |
function playerjs_content($x){ |
| 78 |
$y = strpos($x,'[playerjs'); |
| 79 |
if($y!==FALSE){ |
| 80 |
$z = explode('[playerjs',$x); |
| 81 |
for ($i = ($y===0?0:1); $i < count($z); $i++) { |
| 82 |
$open=0; |
| 83 |
$x1 = 'playerjs'; |
| 84 |
for ($j = 0; $j < strlen($z[$i]); $j++) { |
| 85 |
|
| 86 |
if ($z[$i][$j] == "]" && $open==0) { |
| 87 |
break; |
| 88 |
}else{ |
| 89 |
if($z[$i][$j] == "["){ |
| 90 |
$open++; |
| 91 |
} |
| 92 |
if($z[$i][$j] == "]"){ |
| 93 |
$open--; |
| 94 |
} |
| 95 |
$x1.= $z[$i][$j]; |
| 96 |
} |
| 97 |
} |
| 98 |
if($x1!=''){ |
| 99 |
$x2 = str_replace('[','[',$x1); |
| 100 |
$x2 = str_replace(']',']',$x2); |
| 101 |
$x2 = str_replace("'",'‘',$x2); |
| 102 |
$x = str_replace("[".$x1."]","[".$x2."]",$x); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
return $x; |
| 107 |
} |
| 108 |
|
| 109 |
function playerjs_content2($x){ |
| 110 |
if (empty($GLOBALS['playerjs_configs'])) { |
| 111 |
return $x; |
| 112 |
} |
| 113 |
|
| 114 |
$p = $GLOBALS['playerjs_configs']; |
| 115 |
$x .= '<script>function PlayerjsAsync(){'; |
| 116 |
|
| 117 |
foreach ($p as $k => $v){ |
| 118 |
$var_name = preg_replace('/[^a-zA-Z0-9_]/', '', (string) $k); |
| 119 |
|
| 120 |
if ($var_name === '') { |
| 121 |
continue; |
| 122 |
} |
| 123 |
|
| 124 |
$x .= 'var ' . $var_name . ' = new Playerjs({' . $v . '});'; |
| 125 |
} |
| 126 |
|
| 127 |
return $x . '} if(window["Playerjs"]){PlayerjsAsync();}</script>'; |
| 128 |
} |
| 129 |
|
| 130 |
function playerjs_com_handler($atts) { |
| 131 |
$x = ''; |
| 132 |
$u = wp_get_current_user(); |
| 133 |
|
| 134 |
if(isset($atts['file'])||isset($atts['replace'])){ |
| 135 |
|
| 136 |
$r = wp_rand(10000,20000); |
| 137 |
|
| 138 |
$style = ''; |
| 139 |
|
| 140 |
foreach ($atts as $k => $v){ |
| 141 |
if(gettype($k) == "integer" && isset($k0)){ |
| 142 |
$atts[$k0] .=' '.$v; |
| 143 |
unset($atts[$k]); |
| 144 |
}else{ |
| 145 |
$k0 = $k; |
| 146 |
} |
| 147 |
} |
| 148 |
$vars = ''; |
| 149 |
foreach ($atts as $k => $v){ |
| 150 |
$v = str_replace("[","[",$v); |
| 151 |
$v = str_replace("]","]",$v); |
| 152 |
$v = str_replace("»","",$v); |
| 153 |
$v = str_replace("″","",$v); |
| 154 |
$v = str_replace("”","",$v); |
| 155 |
|
| 156 |
if(strpos($v,"[")!==false && strpos($v,"{")!==false){ |
| 157 |
$v = str_replace("‘","pjs'qt",$v); |
| 158 |
$v = str_replace("’","pjs'qt",$v); |
| 159 |
$v = str_replace("′","pjs'qt",$v); |
| 160 |
} |
| 161 |
|
| 162 |
if($k=="file"){ |
| 163 |
//$r = md5($v); |
| 164 |
$base = dirname( __FILE__ ) . '/admin/playerjs_base64.php'; |
| 165 |
if(file_exists($base)){ |
| 166 |
include_once($base); |
| 167 |
$v = pjsBase64Encrypt($v); |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
$dont = false; |
| 174 |
if($k=="watermark" && $v==1){ |
| 175 |
if($u){ |
| 176 |
if($u->data->ID>0){ |
| 177 |
$vars .= ',' . wp_json_encode('wid') . ':' . wp_json_encode((string) $u->data->user_login); |
| 178 |
$dont = true; |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
if(!$dont && $k!='align' && $k!='margin' && $k!='width' && $k!='height'){ |
| 184 |
$vars .= ',' . wp_json_encode((string) $k) . ':' . wp_json_encode((string) $v); |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
if(!isset($atts['replace'])){ |
| 189 |
$vars .= ',' . wp_json_encode('id') . ':' . wp_json_encode('playerjs' . $r); |
| 190 |
} |
| 191 |
|
| 192 |
$align = playerjs_com_get_option('align',0,''); |
| 193 |
|
| 194 |
if(isset($atts['align'])){ |
| 195 |
$atts['align']=='left'?$style='float:left;':''; |
| 196 |
$align = $atts['align']; |
| 197 |
} |
| 198 |
|
| 199 |
if(isset($atts['margin'])){ |
| 200 |
$style.='margin:'.intval($atts['margin']).'px;'; |
| 201 |
} |
| 202 |
|
| 203 |
// width |
| 204 |
|
| 205 |
$width = playerjs_com_get_option('width',0,''); |
| 206 |
|
| 207 |
isset($atts['width'])?$width = $atts['width']:''; |
| 208 |
|
| 209 |
if($width!=''){ |
| 210 |
$width_ext = 'px'; |
| 211 |
if(strpos($width,'%')>0){ |
| 212 |
$width_ext = '%'; |
| 213 |
} |
| 214 |
$width = str_replace('%','',$width); |
| 215 |
$width = str_replace('px','',$width); |
| 216 |
$style.='width:'.intval($width).$width_ext.';'; |
| 217 |
} |
| 218 |
|
| 219 |
// height |
| 220 |
|
| 221 |
$height = ''; |
| 222 |
|
| 223 |
$customheight = playerjs_com_get_option('customheight',0,''); |
| 224 |
|
| 225 |
if($customheight=="custom"){ |
| 226 |
$height = playerjs_com_get_option('height',0,'280px'); |
| 227 |
} |
| 228 |
|
| 229 |
isset($atts['height'])?$height = $atts['height']:''; |
| 230 |
|
| 231 |
if($height!=''){ |
| 232 |
$height_ext = 'px'; |
| 233 |
if(strpos($height,'%')>0){ |
| 234 |
$height_ext = '%'; |
| 235 |
} |
| 236 |
$height = str_replace('%','',$height); |
| 237 |
$height = str_replace('px','',$height); |
| 238 |
$style.='height:'.intval($height).$height_ext.';'; |
| 239 |
$vars .= ',' . wp_json_encode('aspect') . ':' . wp_json_encode('off'); |
| 240 |
} |
| 241 |
} |
| 242 |
if(substr($vars,0,1)==","){ |
| 243 |
$vars = substr($vars,1); |
| 244 |
} |
| 245 |
if(!isset($atts['replace'])){ |
| 246 |
$x = ($align=='center'?'<center>':'').'<div id="playerjs'.$r.'" '.($style!=''?'style="'.esc_attr($style).'"':'').'></div>'.($align=='center'?'</center>':''); |
| 247 |
}else{ |
| 248 |
$x = ''; |
| 249 |
} |
| 250 |
$GLOBALS['playerjs_configs']->{'player'.$r} = $vars; |
| 251 |
return $x; |
| 252 |
} |
| 253 |
|
| 254 |
function playerjs_com_get_option($x,$checkbox,$default){ |
| 255 |
$y = get_option('playerjs_com_'.$x); |
| 256 |
//echo($x.' '.gettype($y).' '.$y.'<br>'); |
| 257 |
$y = gettype($y)=="array" ? $y[($checkbox==1?'checkbox':'input')] : $default; |
| 258 |
if($checkbox==0){ |
| 259 |
if(trim($y)==''||trim($y)=='0'){ |
| 260 |
$y = $default; |
| 261 |
} |
| 262 |
} |
| 263 |
return $y; |
| 264 |
} |
| 265 |
|