| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Easy Video Player |
| 4 |
Version: 1.2.2.14 |
| 5 |
Plugin URI: https://noorsplugin.com/wordpress-video-plugin/ |
| 6 |
Author: naa986 |
| 7 |
Author URI: https://noorsplugin.com/ |
| 8 |
Description: Easily embed videos into your WordPress blog |
| 9 |
Text Domain: easy-video-player |
| 10 |
Domain Path: /languages |
| 11 |
*/ |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
if (!class_exists('EASY_VIDEO_PLAYER')) { |
| 17 |
|
| 18 |
class EASY_VIDEO_PLAYER { |
| 19 |
|
| 20 |
var $plugin_version = '1.2.2.14'; |
| 21 |
var $player_version = '3.6.7'; |
| 22 |
var $plugin_url; |
| 23 |
var $plugin_path; |
| 24 |
function __construct() { |
| 25 |
define('EASY_VIDEO_PLAYER_VERSION', $this->plugin_version); |
| 26 |
define('EASY_VIDEO_PLAYER_SITE_URL',site_url()); |
| 27 |
define('EASY_VIDEO_PLAYER_URL', $this->plugin_url()); |
| 28 |
define('EASY_VIDEO_PLAYER_PATH', $this->plugin_path()); |
| 29 |
$this->plugin_includes(); |
| 30 |
} |
| 31 |
|
| 32 |
function plugin_includes() { |
| 33 |
if(is_admin()) |
| 34 |
{ |
| 35 |
include_once('extensions/easy-video-player-extensions.php'); |
| 36 |
} |
| 37 |
add_action('plugins_loaded', array($this, 'plugins_loaded_handler')); |
| 38 |
add_action('wp_enqueue_scripts', 'easy_video_player_enqueue_scripts'); |
| 39 |
add_action('admin_menu', array($this, 'easy_video_player_add_options_menu')); |
| 40 |
//add_action('wp_head', 'easy_video_player_header'); |
| 41 |
add_shortcode('evp_embed_video', 'evp_embed_video_handler'); |
| 42 |
//allows shortcode execution in the widget, excerpt and content |
| 43 |
add_filter('widget_text', 'do_shortcode'); |
| 44 |
add_filter('the_excerpt', 'do_shortcode', 11); |
| 45 |
add_filter('the_content', 'do_shortcode', 11); |
| 46 |
} |
| 47 |
|
| 48 |
function plugin_url() { |
| 49 |
if ($this->plugin_url){ |
| 50 |
return $this->plugin_url; |
| 51 |
} |
| 52 |
return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)); |
| 53 |
} |
| 54 |
|
| 55 |
function plugin_path() { |
| 56 |
if ($this->plugin_path){ |
| 57 |
return $this->plugin_path; |
| 58 |
} |
| 59 |
return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__)); |
| 60 |
} |
| 61 |
|
| 62 |
function add_plugin_action_links($links, $file) |
| 63 |
{ |
| 64 |
if ( $file == plugin_basename( dirname( __FILE__ ) . '/easy-video-player.php' ) ) |
| 65 |
{ |
| 66 |
$links[] = '<a href="options-general.php?page=easy-video-player-settings">'.__('Settings', 'easy-video-player').'</a>'; |
| 67 |
} |
| 68 |
return $links; |
| 69 |
} |
| 70 |
|
| 71 |
function plugins_loaded_handler() |
| 72 |
{ |
| 73 |
if(is_admin() && current_user_can('manage_options')) |
| 74 |
{ |
| 75 |
add_filter('plugin_action_links', array($this,'add_plugin_action_links'), 10, 2 ); |
| 76 |
} |
| 77 |
load_plugin_textdomain('easy-video-player', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); |
| 78 |
} |
| 79 |
|
| 80 |
function easy_video_player_add_options_menu() { |
| 81 |
if (is_admin()) { |
| 82 |
add_options_page(__('Easy Video Player', 'easy-video-player'), __('Easy Video Player', 'easy-video-player'), 'manage_options', 'easy-video-player-settings', array($this, 'easy_video_player_options_page')); |
| 83 |
} |
| 84 |
add_action('admin_init', array(&$this, 'easy_video_player_add_settings')); |
| 85 |
} |
| 86 |
|
| 87 |
function easy_video_player_add_settings() { |
| 88 |
register_setting('easy-video-player-settings-group', 'evp_enable_jquery'); |
| 89 |
} |
| 90 |
|
| 91 |
function easy_video_player_options_page() |
| 92 |
{ |
| 93 |
$plugin_tabs = array( |
| 94 |
'easy-video-player-settings' => __('General', 'easy-video-player'), |
| 95 |
'easy-video-player-settings&action=extensions' => __('Add-ons', 'easy-video-player'), |
| 96 |
'easy-video-player-settings&action=advanced' => __('Advanced', 'easy-video-player'), |
| 97 |
); |
| 98 |
$url = "https://noorsplugin.com/wordpress-video-plugin/"; |
| 99 |
$link_text = sprintf(wp_kses(__('Please visit the <a target="_blank" href="%s">Easy Video Player</a> documentation page for usage instructions.', 'easy-video-player'), array('a' => array('href' => array(), 'target' => array()))), esc_url($url)); |
| 100 |
echo '<div class="wrap">'; |
| 101 |
echo '<h2>Easy Video Player - v'.$this->plugin_version.'</h2>'; |
| 102 |
echo '<div class="notice notice-info">'.$link_text.'</div>'; |
| 103 |
echo '<div id="poststuff"><div id="post-body">'; |
| 104 |
|
| 105 |
if (isset($_GET['page'])) { |
| 106 |
$current = sanitize_text_field($_GET['page']); |
| 107 |
if (isset($_GET['action'])) { |
| 108 |
$current .= "&action=" . sanitize_text_field($_GET['action']); |
| 109 |
} |
| 110 |
} |
| 111 |
$content = ''; |
| 112 |
$content .= '<h2 class="nav-tab-wrapper">'; |
| 113 |
foreach ($plugin_tabs as $location => $tabname) { |
| 114 |
if ($current == $location) { |
| 115 |
$class = ' nav-tab-active'; |
| 116 |
} else { |
| 117 |
$class = ''; |
| 118 |
} |
| 119 |
$content .= '<a class="nav-tab' . $class . '" href="?page=' . $location . '">' . $tabname . '</a>'; |
| 120 |
} |
| 121 |
$content .= '</h2>'; |
| 122 |
echo $content; |
| 123 |
|
| 124 |
if(isset($_GET['action'])) |
| 125 |
{ |
| 126 |
switch ($_GET['action']) |
| 127 |
{ |
| 128 |
case 'extensions': |
| 129 |
easy_video_player_display_extensions(); |
| 130 |
break; |
| 131 |
case 'advanced': |
| 132 |
$this->advanced_settings(); |
| 133 |
break; |
| 134 |
} |
| 135 |
} |
| 136 |
else |
| 137 |
{ |
| 138 |
$this->general_settings(); |
| 139 |
} |
| 140 |
|
| 141 |
echo '</div></div>'; |
| 142 |
echo '</div>'; |
| 143 |
} |
| 144 |
|
| 145 |
function general_settings() |
| 146 |
{ |
| 147 |
?> |
| 148 |
<form method="post" action="options.php"> |
| 149 |
<?php settings_fields('easy-video-player-settings-group'); ?> |
| 150 |
<table class="form-table"> |
| 151 |
<tr valign="top"> |
| 152 |
<th scope="row"><?php _e('Enable jQuery', 'easy-video-player')?></th> |
| 153 |
<td><input type="checkbox" id="evp_enable_jquery" name="evp_enable_jquery" value="1" <?php echo checked(1, get_option('evp_enable_jquery'), false) ?> /> |
| 154 |
<p><i><?php _e('By default this option should always be checked.', 'easy-video-player')?></i></p> |
| 155 |
</td> |
| 156 |
</tr> |
| 157 |
</table> |
| 158 |
|
| 159 |
<p class="submit"> |
| 160 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 161 |
</p> |
| 162 |
</form> |
| 163 |
<?php |
| 164 |
} |
| 165 |
|
| 166 |
function advanced_settings() { |
| 167 |
?> |
| 168 |
<div class="update-nag"><?php _e('Settings from add-ons will appear here.', 'easy-video-player');?></div> |
| 169 |
<?php |
| 170 |
if (isset($_POST['easy_video_player_update_advanced_settings'])) { |
| 171 |
$nonce = $_REQUEST['_wpnonce']; |
| 172 |
if (!wp_verify_nonce($nonce, 'easy_video_player_advanced_settings')) { |
| 173 |
wp_die('Error! Nonce Security Check Failed! please save the settings again.'); |
| 174 |
} |
| 175 |
$post = $_POST; |
| 176 |
do_action('easy_video_player_advanced_settings_submitted', $post); |
| 177 |
echo '<div id="message" class="updated fade"><p><strong>'; |
| 178 |
echo __('Settings Saved!', 'easy-video-player'); |
| 179 |
echo '</strong></p></div>'; |
| 180 |
} |
| 181 |
$settings_fields = ''; |
| 182 |
$settings_fields = apply_filters('easy_video_player_advanced_settings_fields', $settings_fields); |
| 183 |
if(empty($settings_fields)){ |
| 184 |
return; |
| 185 |
} |
| 186 |
?> |
| 187 |
<form method="post" action=""> |
| 188 |
<?php wp_nonce_field('easy_video_player_advanced_settings'); ?> |
| 189 |
|
| 190 |
<table class="form-table"> |
| 191 |
<tbody> |
| 192 |
<?php |
| 193 |
if(!empty($settings_fields)){ |
| 194 |
echo $settings_fields; |
| 195 |
} |
| 196 |
?> |
| 197 |
</tbody> |
| 198 |
|
| 199 |
</table> |
| 200 |
|
| 201 |
<p class="submit"><input type="submit" name="easy_video_player_update_advanced_settings" id="easy_video_player_update_advanced_settings" class="button button-primary" value="<?php _e('Save Changes', 'easy-video-player');?>"></p> |
| 202 |
</form> |
| 203 |
<?php |
| 204 |
} |
| 205 |
|
| 206 |
} |
| 207 |
|
| 208 |
$GLOBALS['easy_video_player'] = new EASY_VIDEO_PLAYER(); |
| 209 |
} |
| 210 |
|
| 211 |
function easy_video_player_enqueue_scripts() { |
| 212 |
if (!is_admin()) { |
| 213 |
$plugin_url = plugins_url('', __FILE__); |
| 214 |
$enable_jquery = get_option('evp_enable_jquery'); |
| 215 |
if ($enable_jquery) { |
| 216 |
wp_enqueue_script('jquery'); |
| 217 |
} |
| 218 |
//wp_register_style('plyr-css', 'https://cdn.plyr.io/3.6.7/plyr.css'); |
| 219 |
wp_register_style('plyr-css', $plugin_url . '/lib/plyr.css'); |
| 220 |
wp_enqueue_style('plyr-css'); |
| 221 |
//wp_register_script('plyr-js', 'https://cdn.plyr.io/3.6.7/plyr.js'); |
| 222 |
wp_register_script('plyr-js', $plugin_url . '/lib/plyr.js'); |
| 223 |
$easy_video_player = array( |
| 224 |
'plyr_iconUrl' => $plugin_url.'/lib/plyr.svg', |
| 225 |
'plyr_blankVideo' => $plugin_url.'/lib/blank.mp4', |
| 226 |
); |
| 227 |
wp_localize_script('plyr-js', 'easy_video_player', $easy_video_player); |
| 228 |
wp_enqueue_script('plyr-js'); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
function easy_video_player_header() { |
| 233 |
if (!is_admin()) { |
| 234 |
$fp_config = '<!-- This content is generated with the Easy Video Player plugin v' . EASY_VIDEO_PLAYER_VERSION . ' - https://noorsplugin.com/wordpress-video-plugin/ -->'; |
| 235 |
$fp_config .= '<!-- Easy Video Player plugin -->'; |
| 236 |
echo $fp_config; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
function evp_embed_video_handler($atts) { |
| 241 |
$atts = shortcode_atts(array( |
| 242 |
'url' => '', |
| 243 |
'width' => '', |
| 244 |
'height' => '', |
| 245 |
'ratio' => '', |
| 246 |
'autoplay' => 'false', |
| 247 |
'poster' => '', |
| 248 |
'loop' => '', |
| 249 |
'muted' => '', |
| 250 |
'controls' => 'controls', |
| 251 |
'preload' => 'metadata', |
| 252 |
'share' => 'true', |
| 253 |
'video_id' => '', |
| 254 |
'class' => '', |
| 255 |
'template' => '', |
| 256 |
'user_only_video' => '', |
| 257 |
'allowed_user_roles' => '', |
| 258 |
'schema' => '', |
| 259 |
'name' => '', |
| 260 |
'description' => '', |
| 261 |
'duration' => '', |
| 262 |
'uploaddate' => '', |
| 263 |
), $atts); |
| 264 |
$atts = array_map('sanitize_text_field', $atts); |
| 265 |
extract($atts); |
| 266 |
// |
| 267 |
$user_only_video_msg = ''; |
| 268 |
$user_only_video_msg = apply_filters('evp_user_only_video', $user_only_video_msg, $atts); |
| 269 |
if(!empty($user_only_video_msg)){ |
| 270 |
return $user_only_video_msg; |
| 271 |
} |
| 272 |
// |
| 273 |
if(!isset($url) || empty($url)){ |
| 274 |
return __('No video URL in the shortcode', 'easy-video-player'); |
| 275 |
} |
| 276 |
//check if mediaelement template is specified |
| 277 |
if($template=='mediaelement'){ |
| 278 |
$attr = array(); |
| 279 |
$attr['src'] = $url; |
| 280 |
if(is_numeric($width)){ |
| 281 |
$attr['width'] = $width; |
| 282 |
} |
| 283 |
if(is_numeric($height)){ |
| 284 |
$attr['height'] = $height; |
| 285 |
} |
| 286 |
if ($autoplay == "true"){ |
| 287 |
$attr['autoplay'] = 'on'; |
| 288 |
} |
| 289 |
if ($loop == "true"){ |
| 290 |
$attr['loop'] = 'on'; |
| 291 |
} |
| 292 |
if (!empty($poster)){ |
| 293 |
$attr['poster'] = $poster; |
| 294 |
} |
| 295 |
if (!empty($preload)){ |
| 296 |
$attr['preload'] = $preload; |
| 297 |
} |
| 298 |
$output = wp_video_shortcode($attr); |
| 299 |
$video_schema = ''; |
| 300 |
$video_schema = apply_filters('evp_schema', $video_schema, $atts); |
| 301 |
if(!empty($video_schema)){ |
| 302 |
$output .= $video_schema; |
| 303 |
} |
| 304 |
return $output; |
| 305 |
} |
| 306 |
else if($template=='1'){ |
| 307 |
$output = ''; |
| 308 |
$output = apply_filters('evp_template_1', $output, $atts); |
| 309 |
if(!empty($output)){ |
| 310 |
return $output; |
| 311 |
} |
| 312 |
} |
| 313 |
//width |
| 314 |
if(!empty($width)){ |
| 315 |
$width = ' style="'.esc_attr('max-width:'.$width.'px;').'"'; |
| 316 |
} |
| 317 |
else{ |
| 318 |
$width = ''; |
| 319 |
} |
| 320 |
//custom video id |
| 321 |
if(!empty($video_id)){ |
| 322 |
$video_id = ' id="'.esc_attr($video_id).'"'; |
| 323 |
} |
| 324 |
//autoplay |
| 325 |
if ($autoplay == "true") { |
| 326 |
$autoplay = " autoplay"; |
| 327 |
} else { |
| 328 |
$autoplay = ""; |
| 329 |
} |
| 330 |
//loop |
| 331 |
if ($loop == "true") { |
| 332 |
$loop= " loop"; |
| 333 |
} |
| 334 |
else{ |
| 335 |
$loop= ""; |
| 336 |
} |
| 337 |
//muted |
| 338 |
if($muted == "true"){ |
| 339 |
$muted = " muted"; |
| 340 |
} |
| 341 |
else{ |
| 342 |
$muted = ""; |
| 343 |
} |
| 344 |
//poster |
| 345 |
if(!empty($poster)){ |
| 346 |
$poster = ' data-poster="'.esc_url($poster).'"'; |
| 347 |
} |
| 348 |
else{ |
| 349 |
$poster = ''; |
| 350 |
} |
| 351 |
//controls |
| 352 |
if(isset($controls) && empty($controls)){ |
| 353 |
$controls = ""; |
| 354 |
} |
| 355 |
else{ |
| 356 |
$controls = " controls"; |
| 357 |
} |
| 358 |
//ratio only allows 16:9/4:3 |
| 359 |
/* |
| 360 |
if($ratio == "4:3"){ |
| 361 |
$ratio = "4:3"; |
| 362 |
} |
| 363 |
else{ |
| 364 |
$ratio = "16:9"; |
| 365 |
}*/ |
| 366 |
//class |
| 367 |
if(!empty($class)){ |
| 368 |
$class = ' class="easy-video-player '.esc_attr($class).'"'; |
| 369 |
} |
| 370 |
else{ |
| 371 |
$class = ' class="easy-video-player"'; |
| 372 |
} |
| 373 |
$esc_js = 'esc_js'; |
| 374 |
$icon_url = EASY_VIDEO_PLAYER_URL.'/lib/plyr.svg'; |
| 375 |
$blank_video = EASY_VIDEO_PLAYER_URL.'/lib/blank.mp4'; |
| 376 |
$video_id = "plyr" . uniqid(); |
| 377 |
$ratio_code = '16:9'; |
| 378 |
if(isset($ratio) && !empty($ratio)){ |
| 379 |
$ratio_code = $ratio; |
| 380 |
} |
| 381 |
$video_output = ' |
| 382 |
<div'.$width.'> |
| 383 |
<video id="'.$video_id.'"'.$autoplay.$loop.$muted.$poster.$controls.$class.'> |
| 384 |
<source src="'.esc_url($url).'" type="video/mp4" /> |
| 385 |
</video> |
| 386 |
</div>'; |
| 387 |
$script_output = <<<EOT |
| 388 |
<script> |
| 389 |
const evplayer{$video_id} = new Plyr(document.getElementById('$video_id')); |
| 390 |
evplayer{$video_id}.ratio = '{$esc_js($ratio_code)}'; |
| 391 |
evplayer{$video_id}.iconUrl = '{$icon_url}'; |
| 392 |
evplayer{$video_id}.blankVideo = '{$blank_video}'; |
| 393 |
</script> |
| 394 |
EOT; |
| 395 |
$output = $video_output.$script_output; |
| 396 |
$video_schema = ''; |
| 397 |
$video_schema = apply_filters('evp_schema', $video_schema, $atts); |
| 398 |
if(!empty($video_schema)){ |
| 399 |
$output .= $video_schema; |
| 400 |
} |
| 401 |
return $output; |
| 402 |
} |
| 403 |
|