| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: PlayerJS |
| 4 |
* 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 |
| 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.1'; |
| 32 |
|
| 33 |
function __construct() { |
| 34 |
define('PLAYERJS_VERSION', $this->plugin_version); |
| 35 |
$this->plugin_includes(); |
| 36 |
} |
| 37 |
|
| 38 |
function plugin_includes() { |
| 39 |
$path = get_option('playerjs_com_script_path'); |
| 40 |
$path = $path ? $path['input'] : ''; |
| 41 |
if(trim($path)==''){ |
| 42 |
$path = plugins_url('').'/playerjs/playerjs_default.js'; |
| 43 |
} |
| 44 |
|
| 45 |
wp_enqueue_script('playerjs-js', $path); |
| 46 |
|
| 47 |
add_filter('the_content', 'playerjs_content' ); |
| 48 |
add_shortcode('playerjs', 'playerjs_com_handler'); |
| 49 |
|
| 50 |
|
| 51 |
add_filter('widget_text', 'do_shortcode'); |
| 52 |
add_filter('the_excerpt', 'do_shortcode', 11); |
| 53 |
add_filter('the_content', 'do_shortcode', 11); |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
$GLOBALS['playerjs_player'] = new PLAYERJS_HTML5(); |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
function playerjs_com_action_links ( $links ) { |
| 65 |
$mylinks = array('<a href="' . admin_url( 'options-general.php?page=playerjs_com_admin' ) . '">Settings</a>'); return array_merge($links, $mylinks); |
| 66 |
} |
| 67 |
|
| 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 .= "["; |
| 79 |
} |
| 80 |
} else if ($str[$i] == "]") { |
| 81 |
if (count($stack) % 2) { |
| 82 |
$out .= "]"; |
| 83 |
} else { |
| 84 |
$out .= "]"; |
| 85 |
} |
| 86 |
array_pop($stack); |
| 87 |
} else { |
| 88 |
$out .= $str[$i]; |
| 89 |
} |
| 90 |
} |
| 91 |
return $out; |
| 92 |
} |
| 93 |
|
| 94 |
function playerjs_com_handler($atts) { |
| 95 |
$x=''; |
| 96 |
|
| 97 |
if(isset($atts['file'])){ |
| 98 |
|
| 99 |
$r = rand(10000,20000); |
| 100 |
|
| 101 |
$style = ''; |
| 102 |
|
| 103 |
$vars = ''; |
| 104 |
foreach ($atts as $k => $v){ |
| 105 |
if(gettype($k) == "integer" && isset($k0)){ |
| 106 |
$atts[$k0] .=' '.$v; |
| 107 |
unset($atts[$k]); |
| 108 |
}else{ |
| 109 |
$k0 = $k; |
| 110 |
} |
| 111 |
} |
| 112 |
foreach ($atts as $k => $v){ |
| 113 |
$v = str_replace("[","[",$v); |
| 114 |
$v = str_replace("]","]",$v); |
| 115 |
$v = str_replace("»","",$v); |
| 116 |
$v = str_replace("″","",$v); |
| 117 |
|
| 118 |
if($k!='align' && $k!='margin' && $k!='width' && $k!='height'){ |
| 119 |
$vars .= ','.$k.':"'.$v.'"'; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
$align = playerjs_com_get_option('align',0,''); |
| 124 |
|
| 125 |
if(isset($atts['align'])){ |
| 126 |
$atts['align']=='left'?$style='float:left;':''; |
| 127 |
$align = $atts['align']; |
| 128 |
} |
| 129 |
|
| 130 |
if(isset($atts['margin'])){ |
| 131 |
$style.='margin:'.$atts['margin'].'px;'; |
| 132 |
} |
| 133 |
|
| 134 |
// width |
| 135 |
|
| 136 |
$width = playerjs_com_get_option('width',0); |
| 137 |
|
| 138 |
isset($atts['width'])?$width = $atts['width']:''; |
| 139 |
|
| 140 |
if($width!=''){ |
| 141 |
$style.='width:'.(strpos($width,'%')>0?$width:(strpos($width,'px')>0?$width:$width.'px')).';'; |
| 142 |
} |
| 143 |
|
| 144 |
// height |
| 145 |
|
| 146 |
$height = ''; |
| 147 |
|
| 148 |
$customheight = playerjs_com_get_option('customheight',0,''); |
| 149 |
|
| 150 |
if($customheight=="custom"){ |
| 151 |
$height = playerjs_com_get_option('height',0,'280px'); |
| 152 |
} |
| 153 |
|
| 154 |
isset($atts['height'])?$height = $atts['height']:''; |
| 155 |
|
| 156 |
if($height!=''){ |
| 157 |
$style.='height:'.(strpos($height,'%')>0?$height:(strpos($height,'px')>0?$height:$height.'px')).';'; |
| 158 |
$vars .= ',aspect:"off"'; |
| 159 |
} |
| 160 |
|
| 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>'; |
| 164 |
|
| 165 |
} |
| 166 |
return $x; |
| 167 |
} |
| 168 |
|
| 169 |
function playerjs_com_get_option($x,$checkbox,$default){ |
| 170 |
$y = get_option('playerjs_com_'.$x); |
| 171 |
//echo($x.' '.gettype($y).' '.$y.'<br>'); |
| 172 |
$y = gettype($y)=="array" ? $y[($checkbox==1?'checkbox':'input')] : $default; |
| 173 |
if($checkbox==0){ |
| 174 |
if(trim($y)==''||trim($y)=='0'){ |
| 175 |
$y = $default; |
| 176 |
} |
| 177 |
} |
| 178 |
return $y; |
| 179 |
} |
| 180 |
|