| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Easy Video Player |
| 4 |
Version: 1.1.1 |
| 5 |
Plugin URI: http://noorsplugin.com/wordpress-video-plugin/ |
| 6 |
Author: naa986 |
| 7 |
Author URI: http://noorsplugin.com/ |
| 8 |
Description: Easily embed videos into your WordPress blog |
| 9 |
*/ |
| 10 |
|
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
if (!class_exists('EASY_VIDEO_PLAYER')) { |
| 15 |
|
| 16 |
class EASY_VIDEO_PLAYER { |
| 17 |
|
| 18 |
var $plugin_version = '1.1.1'; |
| 19 |
|
| 20 |
function __construct() { |
| 21 |
define('EASY_VIDEO_PLAYER_VERSION', $this->plugin_version); |
| 22 |
$this->plugin_includes(); |
| 23 |
} |
| 24 |
|
| 25 |
function plugin_includes() { |
| 26 |
if (is_admin()) { |
| 27 |
add_filter('plugin_action_links', array(&$this, 'easy_video_player_plugin_action_links'), 10, 2); |
| 28 |
} |
| 29 |
add_action('wp_enqueue_scripts', 'easy_video_player_enqueue_scripts'); |
| 30 |
add_action('admin_menu', array(&$this, 'easy_video_player_add_options_menu')); |
| 31 |
add_action('wp_head', 'easy_video_player_header'); |
| 32 |
add_shortcode('evp_embed_video', 'evp_embed_video_handler'); |
| 33 |
//allows shortcode execution in the widget, excerpt and content |
| 34 |
add_filter('widget_text', 'do_shortcode'); |
| 35 |
add_filter('the_excerpt', 'do_shortcode', 11); |
| 36 |
add_filter('the_content', 'do_shortcode', 11); |
| 37 |
} |
| 38 |
|
| 39 |
function plugin_url() { |
| 40 |
if ($this->plugin_url) |
| 41 |
return $this->plugin_url; |
| 42 |
return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)); |
| 43 |
} |
| 44 |
|
| 45 |
function easy_video_player_plugin_action_links($links, $file) { |
| 46 |
if ($file == plugin_basename(dirname(__FILE__) . '/easy-video-player.php')) { |
| 47 |
$links[] = '<a href="options-general.php?page=easy-video-player-settings">Settings</a>'; |
| 48 |
} |
| 49 |
return $links; |
| 50 |
} |
| 51 |
|
| 52 |
function easy_video_player_add_options_menu() { |
| 53 |
if (is_admin()) { |
| 54 |
add_options_page('Easy Video Player Settings', 'Easy Video Player', 'manage_options', 'easy-video-player-settings', array(&$this, 'easy_video_player_options_page')); |
| 55 |
} |
| 56 |
add_action('admin_init', array(&$this, 'easy_video_player_add_settings')); |
| 57 |
} |
| 58 |
|
| 59 |
function easy_video_player_add_settings() { |
| 60 |
register_setting('easy-video-player-settings-group', 'evp_enable_jquery'); |
| 61 |
} |
| 62 |
|
| 63 |
function easy_video_player_options_page() { |
| 64 |
?> |
| 65 |
<div class="wrap"> |
| 66 |
<div id="poststuff"><div id="post-body"> |
| 67 |
|
| 68 |
<h2>Easy Video Player - v<?php echo $this->plugin_version; ?></h2> |
| 69 |
<div class="postbox"> |
| 70 |
<h3><label for="title">Setup Guide</label></h3> |
| 71 |
<div class="inside"> |
| 72 |
<p>For detailed documentation please visit the plugin homepage <a href="http://noorsplugin.com/wordpress-video-plugin/" target="_blank">here</a></p> |
| 73 |
</div></div> |
| 74 |
<div class="postbox"> |
| 75 |
<h3><label for="title">General Settings</label></h3> |
| 76 |
<div class="inside"> |
| 77 |
<form method="post" action="options.php"> |
| 78 |
<?php settings_fields('easy-video-player-settings-group'); ?> |
| 79 |
<table class="form-table"> |
| 80 |
<tr valign="top"> |
| 81 |
<th scope="row">Enable jQuery</th> |
| 82 |
<td><input type="checkbox" id="evp_enable_jquery" name="evp_enable_jquery" value="1" <?php echo checked(1, get_option('evp_enable_jquery'), false) ?> /> |
| 83 |
<p><i>By default this option should always be checked.</i></p> |
| 84 |
</td> |
| 85 |
</tr> |
| 86 |
</table> |
| 87 |
|
| 88 |
<p class="submit"> |
| 89 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 90 |
</p> |
| 91 |
</form> |
| 92 |
</div></div> |
| 93 |
|
| 94 |
</div></div> |
| 95 |
</div> |
| 96 |
<?php |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
$GLOBALS['easy_video_player'] = new EASY_VIDEO_PLAYER(); |
| 102 |
} |
| 103 |
|
| 104 |
function easy_video_player_enqueue_scripts() { |
| 105 |
if (!is_admin()) { |
| 106 |
$plugin_url = plugins_url('', __FILE__); |
| 107 |
$enable_jquery = get_option('evp_enable_jquery'); |
| 108 |
if ($enable_jquery) { |
| 109 |
wp_enqueue_script('jquery'); |
| 110 |
} |
| 111 |
wp_register_script('flowplayer-js', $plugin_url . '/lib/flowplayer.min.js'); |
| 112 |
wp_enqueue_script('flowplayer-js'); |
| 113 |
wp_register_style('flowplayer-css', $plugin_url . '/lib/skin/all-skins.css'); |
| 114 |
wp_enqueue_style('flowplayer-css'); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
function easy_video_player_header() { |
| 119 |
if (!is_admin()) { |
| 120 |
$fp_config = '<!-- This content is generated with the Easy Video Player plugin v' . EASY_VIDEO_PLAYER_VERSION . ' - http://noorsplugin.com/wordpress-video-plugin/ -->'; |
| 121 |
$fp_config .= '<script>'; |
| 122 |
$fp_config .= 'flowplayer.conf.embed = false;'; |
| 123 |
$fp_config .= 'flowplayer.conf.keyboard = false;'; |
| 124 |
$fp_config .= '</script>'; |
| 125 |
$fp_config .= '<!-- Easy Video Player plugin -->'; |
| 126 |
echo $fp_config; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
function evp_embed_video_handler($atts) { |
| 131 |
extract(shortcode_atts(array( |
| 132 |
'url' => '', |
| 133 |
'width' => '', |
| 134 |
'height' => '', |
| 135 |
'ratio' => '0.417', |
| 136 |
'autoplay' => 'false', |
| 137 |
'poster' => '', |
| 138 |
'loop' => '', |
| 139 |
'muted' => '', |
| 140 |
'class' => '', |
| 141 |
'template' => '', |
| 142 |
), $atts)); |
| 143 |
//check if mediaelement template is specified |
| 144 |
if($template=='mediaelement'){ |
| 145 |
$attr = array(); |
| 146 |
$attr['src'] = $url; |
| 147 |
if(is_numeric($width)){ |
| 148 |
$attr['width'] = $width; |
| 149 |
} |
| 150 |
if(is_numeric($height)){ |
| 151 |
$attr['height'] = $height; |
| 152 |
} |
| 153 |
if ($autoplay == "true"){ |
| 154 |
$attr['autoplay'] = 'on'; |
| 155 |
} |
| 156 |
if ($loop == "true"){ |
| 157 |
$attr['loop'] = 'on'; |
| 158 |
} |
| 159 |
if (!empty($poster)){ |
| 160 |
$attr['poster'] = $poster; |
| 161 |
} |
| 162 |
return wp_video_shortcode($attr); |
| 163 |
} |
| 164 |
//autoplay |
| 165 |
if ($autoplay == "true") { |
| 166 |
$autoplay = " autoplay"; |
| 167 |
} else { |
| 168 |
$autoplay = ""; |
| 169 |
} |
| 170 |
//loop |
| 171 |
if ($loop == "true") { |
| 172 |
$loop= " loop"; |
| 173 |
} |
| 174 |
else{ |
| 175 |
$loop= ""; |
| 176 |
} |
| 177 |
//muted |
| 178 |
if($muted == "true"){ |
| 179 |
$muted = " muted"; |
| 180 |
} |
| 181 |
else{ |
| 182 |
$muted = ""; |
| 183 |
} |
| 184 |
$player = "fp" . uniqid(); |
| 185 |
$color = ''; |
| 186 |
if (!empty($poster)) { |
| 187 |
$color = 'background: #000 url('.$poster.') 0 0 no-repeat;background-size: 100%;'; |
| 188 |
} else { |
| 189 |
$color = 'background-color: #000;'; |
| 190 |
} |
| 191 |
$size_attr = ""; |
| 192 |
if (!empty($width)) { |
| 193 |
$size_attr = "max-width: {$width}px;max-height: auto;"; |
| 194 |
} |
| 195 |
$class_array = array('flowplayer', 'minimalist'); |
| 196 |
if(!empty($class)){ |
| 197 |
$shortcode_class_array = array_map('trim', explode(' ', $class)); |
| 198 |
$shortcode_class_array = array_filter( $shortcode_class_array, 'strlen' ); |
| 199 |
$shortcode_class_array = array_values($shortcode_class_array); |
| 200 |
if(in_array("functional", $shortcode_class_array) || in_array("playful", $shortcode_class_array)){ |
| 201 |
$class_array = array_diff($class_array, array('minimalist')); |
| 202 |
} |
| 203 |
$class_array = array_merge($class_array, $shortcode_class_array); |
| 204 |
$class_array = array_unique($class_array); |
| 205 |
$class_array = array_values($class_array); |
| 206 |
} |
| 207 |
|
| 208 |
$classes = implode(" ", $class_array); |
| 209 |
$styles = <<<EOT |
| 210 |
<style> |
| 211 |
#$player { |
| 212 |
$size_attr |
| 213 |
$color |
| 214 |
} |
| 215 |
</style> |
| 216 |
EOT; |
| 217 |
|
| 218 |
$output = <<<EOT |
| 219 |
<div id="$player" data-ratio="$ratio" class="{$classes}"> |
| 220 |
<video{$autoplay}{$loop}{$muted}> |
| 221 |
<source type="video/mp4" src="$url"/> |
| 222 |
</video> |
| 223 |
</div> |
| 224 |
$styles |
| 225 |
EOT; |
| 226 |
return $output; |
| 227 |
} |
| 228 |
|