| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: VdoCipher |
| 4 | 4 | * Plugin URI: https://www.vdocipher.com |
| 5 | - * Description: Secured video hosting for wordpress | |
| 6 | - * Version: 1.26 | |
| 5 | + * Description: Secured video hosting for WordPress | |
| 6 | + * Version: 1.28 | |
| 7 | 7 | * Author: VdoCipher |
| 8 | 8 | * Author URI: https://www.vdocipher.com |
| 9 | 9 | * License: GPL2 |
| 10 | 10 | */ |
| @@ -10,24 +10,28 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) { |
| 13 | 13 | header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); |
| 14 | - exit("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<html><head>\r\n<title>404 Not Found</title>\r\n". | |
| 14 | + exit("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<html lang='en'><head>\r\n<title>404 Not Found</title>\r\n". | |
| 15 | 15 | "</head><body>\r\n<h1>Not Found</h1>\r\n<p>The requested URL " . $_SERVER['SCRIPT_NAME'] . " was not found on ". |
| 16 | 16 | "this server.</p>\r\n</body></html>"); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | if (!defined('VDOCIPHER_PLUGIN_VERSION')) { |
| 20 | - define('VDOCIPHER_PLUGIN_VERSION', '1.25'); | |
| 20 | + define('VDOCIPHER_PLUGIN_VERSION', '1.28'); | |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('VDOCIPHER_PLAYER_VERSION')) { |
| 24 | - define('VDOCIPHER_PLAYER_VERSION', '1.6.10'); | |
| 24 | + define('VDOCIPHER_PLAYER_VERSION', 'v2'); | |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | +if (!defined('VDOCIPHER_DEFAULT_THEME')) { | |
| 28 | + define('VDOCIPHER_DEFAULT_THEME', ''); | |
| 29 | +} | |
| 30 | + | |
| 27 | 31 | function vdo_plugin_check_version() |
| 28 | 32 | { |
| 29 | -// This applies only for installs 1.24 and below | |
| 33 | + // This applies only for installs 1.24 and below | |
| 30 | 34 | if (!get_option('vdo_plugin_version')) { |
| 31 | 35 | if (preg_match('/^1\.[0123456]\.[0-9]{1,2}$/', get_option('vdo_embed_version'))) { |
| 32 | 36 | update_option('vdo_embed_version', VDOCIPHER_PLAYER_VERSION); |
| 33 | 37 | } |
| @@ -36,58 +40,27 @@ | ||
| 36 | 40 | } |
| 37 | 41 | update_option('vdo_plugin_version', VDOCIPHER_PLUGIN_VERSION); |
| 38 | 42 | return ; |
| 39 | 43 | } |
| 40 | - // This applies for all new installs after 1.25 | |
| 44 | + // This applies for all new installations after 1.25 | |
| 41 | 45 | if (VDOCIPHER_PLUGIN_VERSION !== get_option('vdo_plugin_version')) { |
| 42 | 46 | if (preg_match('/^1\.[0-9]{1,2}\.[0-9]{1,2}$/', get_option('vdo_embed_version'))) { |
| 43 | 47 | update_option('vdo_embed_version', VDOCIPHER_PLAYER_VERSION); |
| 44 | 48 | } |
| 45 | 49 | update_option('vdo_plugin_version', VDOCIPHER_PLUGIN_VERSION); |
| 46 | - return ; | |
| 47 | 50 | } |
| 48 | - return ; | |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | add_action('plugins_loaded', 'vdo_plugin_check_version'); |
| 52 | 54 | |
| 53 | -// Function called to retrieve id for when title given, starts | |
| 54 | -function vdo_retrieve_id($title) | |
| 55 | -{ | |
| 56 | - $client_key = get_option('vdo_client_key'); | |
| 57 | - if ($client_key == false || $client_key == "") { | |
| 58 | - return "Plugin not configured. Please set the API key to embed videos."; | |
| 59 | - } | |
| 60 | - $url = "https://dev.vdocipher.com/api/videos?q=$title"; | |
| 61 | - $headers = array( | |
| 62 | - 'Authorization'=>'Apisecret '.$client_key, | |
| 63 | - 'Content-Type'=>'application/json', | |
| 64 | - 'Accept'=>'application/json' | |
| 65 | - ); | |
| 66 | - $response = wp_remote_post($url, array( | |
| 67 | - 'method' => 'GET', | |
| 68 | - 'headers' => $headers | |
| 69 | - )); | |
| 70 | - if (is_wp_error($response)) { | |
| 71 | - $error_message = $response->get_error_message(); | |
| 72 | - echo "VdoCipher: Something went wrong: $error_message"; | |
| 73 | - return ""; | |
| 74 | - } | |
| 75 | - $video_json_response = $response['body']; | |
| 76 | - $video_list_object = json_decode($video_json_response); | |
| 77 | - $video_list = $video_list_object->rows; | |
| 78 | - $video_object = $video_list[0]; | |
| 79 | - $video_id = $video_object->id; | |
| 80 | - return $video_id; | |
| 81 | -} | |
| 82 | -// Function called to retrieve id for when title given, ends | |
| 83 | - | |
| 84 | 55 | // Function called to get OTP, starts |
| 85 | 56 | function vdo_otp($video, $otp_post_array = array()) |
| 86 | 57 | { |
| 87 | 58 | $client_key = get_option('vdo_client_key'); |
| 88 | 59 | if ($client_key == false || $client_key == "") { |
| 89 | - return "Plugin not configured. Please set the API key to embed videos."; | |
| 60 | + return (object)['message' => 'Plugin not configured. API Key missing.']; | |
| 61 | + } else if (strlen($client_key) !== 64) { | |
| 62 | + return (object)["message" => "Invalid API Key."]; | |
| 90 | 63 | } |
| 91 | 64 | $url = "https://dev.vdocipher.com/api/videos/$video/otp"; |
| 92 | 65 | $headers = array( |
| 93 | 66 | 'Authorization'=>'Apisecret '.$client_key, |
| @@ -104,13 +77,28 @@ | ||
| 104 | 77 | ) |
| 105 | 78 | ); |
| 106 | 79 | if (is_wp_error($response)) { |
| 107 | 80 | $error_message = $response->get_error_message(); |
| 108 | - echo "VdoCipher: Something went wrong: $error_message"; | |
| 109 | - return ""; | |
| 81 | + if (false !== stripos($error_message, 'Operation timed out')) { | |
| 82 | + $error_message = 'Operation timed out. Check your firewall at web host or try after sometime.'; | |
| 83 | + } else if (false !== stripos($error_message, 'Could not resolve host')) { | |
| 84 | + $error_message = 'Connectivity issue. Check firewall at web host.'; | |
| 85 | + } | |
| 86 | + return ["message" => $error_message]; | |
| 110 | 87 | } |
| 111 | - $OTP_Response = $response['body']; | |
| 112 | - return json_decode($OTP_Response); | |
| 88 | + | |
| 89 | + $responseCode = $response['response']['code']; | |
| 90 | + if ($responseCode === 404) { | |
| 91 | + return (object)["message" => "Video ID not found"]; | |
| 92 | + } | |
| 93 | + else if ($responseCode === 403) { | |
| 94 | + return (object)["message" => "API key does not have OTP creator permission"]; | |
| 95 | + } | |
| 96 | + else if ($responseCode === 400 || $responseCode === 401) { | |
| 97 | + return (object)["message" => "Incorrect API key"]; | |
| 98 | + } else { | |
| 99 | + return json_decode($response['body']); | |
| 100 | + } | |
| 113 | 101 | } |
| 114 | 102 | // Function called to get OTP, ends |
| 115 | 103 | |
| 116 | 104 | // VdoCipher Shortcode starts |
| @@ -117,29 +105,21 @@ | ||
| 117 | 105 | function vdo_shortcode($atts) |
| 118 | 106 | { |
| 119 | 107 | $vdo_args = shortcode_atts( |
| 120 | 108 | array( |
| 121 | - 'title' => 'TITLE_OF_VIDEO', | |
| 122 | 109 | 'width' => get_option('vdo_default_width'), |
| 123 | 110 | 'height' => get_option('vdo_default_height'), |
| 124 | 111 | 'id' => 'id', |
| 125 | 112 | 'no_annotate'=> false, |
| 126 | - 'version'=> 0, | |
| 127 | 113 | 'vdo_theme'=> false, |
| 128 | - 'vdo_version'=> false, | |
| 129 | - 'player_tech'=> '' | |
| 130 | 114 | ), |
| 131 | 115 | $atts |
| 132 | 116 | ); |
| 133 | - $title = $vdo_args['title']; | |
| 134 | 117 | $width = $vdo_args['width']; |
| 135 | 118 | $height = $vdo_args['height']; |
| 136 | 119 | $id = $vdo_args['id']; |
| 137 | 120 | $no_annotate = $vdo_args['no_annotate']; |
| 138 | - $version = $vdo_args['version']; | |
| 139 | 121 | $vdo_theme = $vdo_args['vdo_theme']; |
| 140 | - $vdo_version = $vdo_args['vdo_version']; | |
| 141 | - $player_tech = $vdo_args['player_tech']; | |
| 142 | 122 | |
| 143 | 123 | if (!preg_match('/.*px$/', $width)) { |
| 144 | 124 | $width = $width."px"; |
| 145 | 125 | } |
| @@ -148,16 +128,9 @@ | ||
| 148 | 128 | $height = $height."px"; |
| 149 | 129 | } |
| 150 | 130 | } |
| 151 | 131 | if (!$atts['id']) { |
| 152 | - if (!$atts['title']) { | |
| 153 | - return "Required argument id for embedded video not found."; | |
| 154 | - } else { | |
| 155 | - $video = vdo_retrieve_id($title); | |
| 156 | - if ($video == null) { | |
| 157 | - return "404. Video not found."; | |
| 158 | - } | |
| 159 | - } | |
| 132 | + return "Required argument id for embedded video not found."; | |
| 160 | 133 | } else { |
| 161 | 134 | $video = $id; |
| 162 | 135 | } |
| 163 | 136 | |
| @@ -179,9 +152,9 @@ | ||
| 179 | 152 | $vdo_annotate_code = str_replace('{username}', $current_user->user_login, $vdo_annotate_code); |
| 180 | 153 | $vdo_annotate_code = str_replace('{id}', $current_user->ID, $vdo_annotate_code); |
| 181 | 154 | } |
| 182 | 155 | $vdo_annotate_code = str_replace('{ip}', $_SERVER['REMOTE_ADDR'], $vdo_annotate_code); |
| 183 | - $vdo_annotate_code = preg_replace_callback('/\{date\.([^\}]+)\}/', "eval_date", $vdo_annotate_code); | |
| 156 | + $vdo_annotate_code = preg_replace_callback('/{date\.([^}]+)}/', "eval_date", $vdo_annotate_code); | |
| 184 | 157 | $vdo_annotate_code = apply_filters('vdocipher_annotate_postprocess', $vdo_annotate_code); |
| 185 | 158 | // Add annotate code to $otp_post_array, which will be |
| 186 | 159 | // converted to Json and then sent as POST body to API endpoint |
| 187 | 160 | if (!$no_annotate) { |
| @@ -189,14 +162,16 @@ | ||
| 189 | 162 | } |
| 190 | 163 | } |
| 191 | 164 | // OTP is requested via vdo_otp function |
| 192 | 165 | $OTP_Response = vdo_otp($video, $otp_post_array); |
| 193 | - $OTP = $OTP_Response->otp; | |
| 194 | - $playbackInfo = $OTP_Response->playbackInfo; | |
| 195 | 166 | |
| 167 | + // https://www.php.net/manual/en/function.isset.php#86313 | |
| 168 | + $message = (isset($OTP_Response->message)) ? $OTP_Response->message : null; | |
| 169 | + $OTP = (isset($OTP_Response->otp)) ? $OTP_Response->otp : null; | |
| 170 | + $playbackInfo = (isset($OTP_Response->playbackInfo)) ? $OTP_Response->playbackInfo : null; | |
| 171 | + | |
| 196 | 172 | if (is_null($OTP)) { |
| 197 | - $output = "<span id='vdo$OTP' style='background:#555555;color:#FFFFFF'><h4>Video not found</h4></span>"; | |
| 198 | - return $output; | |
| 173 | + return "<div id='vdo$OTP'><strong>VdoCipher Error: $message</strong></div>"; | |
| 199 | 174 | } |
| 200 | 175 | |
| 201 | 176 | // Version, legacy, for flash only |
| 202 | 177 | $version = 0; |
| @@ -204,104 +179,117 @@ | ||
| 204 | 179 | $version = $atts['version']; |
| 205 | 180 | } |
| 206 | 181 | |
| 207 | 182 | // Video Embed version is retrieved from options table or from shortcode attribute |
| 208 | - if ((get_option('vdo_embed_version')) == false) { | |
| 209 | - update_option('vdo_embed_version', VDOCIPHER_PLAYER_VERSION); | |
| 210 | - } | |
| 211 | - if (!$vdo_version) { | |
| 212 | - $vdo_embed_version_str = get_option('vdo_embed_version'); | |
| 213 | - } else { | |
| 214 | - $vdo_embed_version_str = $vdo_version; | |
| 215 | - } | |
| 183 | + $vdo_embed_version_str = get_option('vdo_embed_version'); | |
| 216 | 184 | |
| 217 | 185 | // Video Player theme, update and as shortcode attribute |
| 218 | - if ((get_option('vdo_player_theme')) == false) { | |
| 219 | - update_option('vdo_player_theme', '9ae8bbe8dd964ddc9bdb932cca1cb59a'); | |
| 220 | - } | |
| 221 | 186 | if (!$vdo_theme) { |
| 222 | 187 | $vdo_player_theme = get_option('vdo_player_theme'); |
| 223 | 188 | } else { |
| 224 | 189 | $vdo_player_theme = $vdo_theme; |
| 225 | 190 | } |
| 226 | - | |
| 227 | - // tech override custom names | |
| 228 | - switch ($player_tech) { | |
| 229 | - case "flash": | |
| 230 | - $player_tech = "*,-dash"; | |
| 231 | - break; | |
| 232 | - case "nohtml5": | |
| 233 | - $player_tech = "*,-dash"; | |
| 234 | - break; | |
| 235 | - case "noflash": | |
| 236 | - $player_tech = "*,-hss"; | |
| 237 | - break; | |
| 238 | - case "nozen": | |
| 239 | - $player_tech = "*,-zen"; | |
| 240 | - break; | |
| 241 | - case "noios": | |
| 242 | - $player_tech = "*,-hlse"; | |
| 243 | - break; | |
| 244 | - default: | |
| 245 | - break; | |
| 191 | + if (strpos($vdo_player_theme, 'v1/') === 0 || strlen($vdo_player_theme) === 32) { | |
| 192 | + $vdo_embed_version_str = '1.6.10'; | |
| 193 | + } else if (strlen($vdo_player_theme) === 16) { | |
| 194 | + $vdo_embed_version_str = 'v2'; | |
| 246 | 195 | } |
| 196 | + $speedOptions = esc_attr(get_option('vdo_player_speed')); | |
| 197 | + $speedPattern = '/^\d.\d{1,2}(,\d.\d{1,2})+$/'; | |
| 247 | 198 | |
| 248 | 199 | // Old Embed Code |
| 249 | - if ($vdo_embed_version_str === '0.5') { | |
| 250 | - $output = "<div id='vdo$OTP' style='height:$height;width:$width;max-width:100%' ></div>"; | |
| 251 | - $output .= "<script> (function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){". | |
| 252 | - " (v[o].d=v[o].d||[]).push(a);};"; | |
| 253 | - $output .= "if(!v[o].l) { v[o].l=1*new Date();a=i.createElement(d),m=i.getElementsByTagName(d)[0];a.async=1;". | |
| 254 | - "a.src=e; m.parentNode.insertBefore(a,m);}"; | |
| 255 | - $output .= " })(window,document,'script','//de122v0opjemw.cloudfront.net/vdo.js','vdo'); vdo.add({ "; | |
| 256 | - $output .= "o: '$OTP', "; | |
| 257 | - if ($version == 32) { | |
| 258 | - $output .= "version: '$version' "; | |
| 200 | + if ($vdo_embed_version_str === '1.6.10') { | |
| 201 | + //Old embed code | |
| 202 | + $output = <<<END | |
| 203 | + <div id='vdo$OTP' style='height:$height;width:$width;max-width:100%' ></div> | |
| 204 | + <script>(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){ | |
| 205 | + (v[o].d=v[o].d||[]).push(a);}; | |
| 206 | + if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0]; | |
| 207 | + a.async=1; a.src=e; m.parentNode.insertBefore(a,m);} | |
| 208 | + })(window,document,'script','https://d1z78r8i505acl.cloudfront.net/playerAssets/1.6.10/vdo.js','vdo'); | |
| 209 | + vdo.add({ | |
| 210 | + otp: '$OTP', | |
| 211 | + playbackInfo: '$playbackInfo', | |
| 212 | + theme: '$vdo_player_theme', | |
| 213 | + plugins: [{ | |
| 214 | + name: 'keyboard', | |
| 215 | + options: { | |
| 216 | + preset: 'default', | |
| 217 | + bindings: { | |
| 218 | + 'Left' : (player) => player.seek(player.currentTime - 15), | |
| 219 | + 'Right' : (player) => player.seek(player.currentTime + 15), | |
| 220 | + }, | |
| 221 | + } | |
| 222 | + }], | |
| 223 | + container: document.querySelector('#vdo$OTP'), | |
| 224 | + }) | |
| 225 | + </script> | |
| 226 | +END; | |
| 227 | + | |
| 228 | + if ($speedOptions !== false && preg_match($speedPattern, $speedOptions)) { | |
| 229 | + $output .= <<<END | |
| 230 | + <script> | |
| 231 | + (function () { | |
| 232 | + var originalReadyFunction = window.onVdoCipherAPIReady; | |
| 233 | + // private API; do not use anywhere else; might change without notice | |
| 234 | + var index = vdo.d.length - 1; | |
| 235 | + window.onVdoCipherAPIReady = () => { | |
| 236 | + if (originalReadyFunction) originalReadyFunction(); | |
| 237 | + var v_ = vdo.getObjects()[index]; | |
| 238 | + v_.addEventListener('load', () => { | |
| 239 | + v_.availablePlaybackRates = [$speedOptions] | |
| 240 | + }); | |
| 241 | + } | |
| 242 | + })() | |
| 243 | + </script> | |
| 244 | +END; | |
| 259 | 245 | } |
| 260 | - $output .= "}); </script>"; | |
| 246 | + } else if ($vdo_embed_version_str === 'v2') { | |
| 247 | + $uniq = 'u' . rand(); | |
| 248 | + $output = <<<END | |
| 249 | +<script src="https://player.vdocipher.com/v2/api.js"></script> | |
| 250 | +<iframe | |
| 251 | + src="https://player.vdocipher.com/v2/?otp=$OTP&playbackInfo=$playbackInfo" | |
| 252 | + id="$uniq" | |
| 253 | + style="height:$height;width:$width;max-width:100%;border:0;display: block;" | |
| 254 | + allow="encrypted-media" | |
| 255 | + allowfullscreen | |
| 256 | +></iframe> | |
| 257 | +<script> | |
| 258 | +(function() { | |
| 259 | + const iframe = document.querySelector('#$uniq'); | |
| 260 | + const player = VdoPlayer.getInstance(iframe); | |
| 261 | + player.video.addEventListener('loadstart', async () => { | |
| 262 | + const aspectRatio = (await player.api.getMetaData()).aspectRatio; | |
| 263 | + if (iframe.style.height === 'auto' && iframe.style.width.endsWith('px')) { | |
| 264 | + iframe.style.maxHeight = '100vh'; | |
| 265 | + if (CSS.supports('aspect-ratio', 1)) { | |
| 266 | + iframe.style.aspectRatio = aspectRatio; | |
| 267 | + } else { | |
| 268 | + const offsetWidth = iframe.offsetWidth; | |
| 269 | + iframe.style.height = Math.round(offsetWidth / aspectRatio) + 'px'; | |
| 270 | + } | |
| 271 | + } | |
| 272 | + }); | |
| 273 | +})(); | |
| 274 | +</script> | |
| 275 | +END; | |
| 276 | + if ($speedOptions !== false && preg_match($speedPattern, $speedOptions)) { | |
| 277 | + $output .= <<<END | |
| 278 | +<script> | |
| 279 | +(function() { | |
| 280 | + const iframe = document.querySelector('#$uniq') | |
| 281 | + const player = VdoPlayer.getInstance(iframe); | |
| 282 | + player.video.addEventListener('loadstart', async () => { | |
| 283 | + player.api.updatePlayerConfig({playbackSpeedOptions: [$speedOptions]}); | |
| 284 | + }); | |
| 285 | +})(); | |
| 286 | +</script> | |
| 287 | +END; | |
| 288 | + } | |
| 289 | + | |
| 261 | 290 | } else { |
| 262 | - //New embed code | |
| 263 | - if ($player_tech === '') { | |
| 264 | - if (get_option('vdo_watermark_flash_html') === 'flash') { | |
| 265 | - $player_tech = "*,-dash"; | |
| 266 | - } | |
| 267 | - } | |
| 268 | - $output = "<div id='vdo$OTP' style='height:$height;width:$width;max-width:100%' ></div>"; | |
| 269 | - $output .= "<script>(function(v,i,d,e,o){v[o]=v[o]||{}; v[o].add = v[o].add || function V(a){". | |
| 270 | - "(v[o].d=v[o].d||[]).push(a);};"; | |
| 271 | - $output .= "if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0];"; | |
| 272 | - $output .= "a.async=1; a.src=e; m.parentNode.insertBefore(a,m);}"; | |
| 273 | - $output .= "})(window,document,'script','https://d1z78r8i505acl.cloudfront.net/playerAssets/"; | |
| 274 | - $output .= "$vdo_embed_version_str"; | |
| 275 | - $output .= "/vdo.js','vdo');"; | |
| 276 | - $output .= "vdo.add({"; | |
| 277 | - $output .= "otp: '$OTP',"; | |
| 278 | - $output .= "playbackInfo: '$playbackInfo',"; | |
| 279 | - $output .= "theme: '$vdo_player_theme',"; | |
| 280 | - $output .= "plugins: [{"; | |
| 281 | - $output .= "name: 'keyboard',"; | |
| 282 | - $output .= "options: {"; | |
| 283 | - $output .= "preset: 'default',"; | |
| 284 | - $output .= "bindings: {"; | |
| 285 | - $output .= "'Left' : (player) => player.seek(player.currentTime - 15),"; | |
| 286 | - $output .= "'Right' : (player) => player.seek(player.currentTime + 15),"; | |
| 287 | - $output .= "},"; | |
| 288 | - $output .= "}"; | |
| 289 | - $output .= "}],"; | |
| 290 | - if ($player_tech !== '') { | |
| 291 | - $output .= "techoverride: [" ; | |
| 292 | - $techarray = explode(',', $player_tech); | |
| 293 | - for ($i = 0; $i < sizeof($techarray); $i++) { | |
| 294 | - $techStr = $techarray[$i]; | |
| 295 | - $output .= "'$techStr'"; | |
| 296 | - if ($i !== sizeof($techarray)-1) { | |
| 297 | - $output .= ", "; | |
| 298 | - } | |
| 299 | - } | |
| 300 | - $output .= "],"; | |
| 301 | - } | |
| 302 | - $output .= "container: document.querySelector('#vdo$OTP'),});"; | |
| 303 | - $output .= "</script>"; | |
| 291 | + $output = 'Invalid player selection: ' . $vdo_embed_version_str; | |
| 304 | 292 | } |
| 305 | 293 | return $output; |
| 306 | 294 | } |
| 307 | 295 | add_shortcode('vdo', 'vdo_shortcode'); |
| @@ -322,13 +310,20 @@ | ||
| 322 | 310 | // add the menu item and register settings (3 functions), starts |
| 323 | 311 | if (is_admin()) { // admin actions |
| 324 | 312 | add_action('admin_init', 'register_vdo_settings'); |
| 325 | 313 | add_action('admin_menu', 'vdo_menu'); |
| 326 | -} else { | |
| 327 | - // non-admin enqueues, actions, and filters | |
| 328 | 314 | } |
| 329 | 315 | function vdo_menu() |
| 330 | 316 | { |
| 317 | + if (get_option('vdo_show_plugin_in_sidebar') === "") { | |
| 318 | + add_options_page( | |
| 319 | + 'VdoCipher Options', | |
| 320 | + 'VdoCipher', | |
| 321 | + 'manage_options', | |
| 322 | + 'vdocipher', | |
| 323 | + 'vdo_options' | |
| 324 | + ); | |
| 325 | + } else { | |
| 331 | 326 | add_menu_page( |
| 332 | 327 | 'VdoCipher Options', |
| 333 | 328 | 'VdoCipher', |
| 334 | 329 | 'manage_options', |
| @@ -335,23 +330,11 @@ | ||
| 335 | 330 | 'vdocipher', |
| 336 | 331 | 'vdo_options', |
| 337 | 332 | plugin_dir_url(__FILE__).'images/logo.png' |
| 338 | 333 | ); |
| 339 | - add_submenu_page( | |
| 340 | - null, | |
| 341 | - 'Video Player Themes', | |
| 342 | - 'CustomPlayer', | |
| 343 | - 'manage_options', | |
| 344 | - 'themesvdo', | |
| 345 | - 'themesvdo' | |
| 346 | - ); | |
| 334 | + } | |
| 347 | 335 | } |
| 348 | 336 | |
| 349 | -function themesvdo() | |
| 350 | -{ | |
| 351 | - include('include/player_themes.php'); | |
| 352 | -} | |
| 353 | - | |
| 354 | 337 | function vdo_options() |
| 355 | 338 | { |
| 356 | 339 | if (!get_option('vdo_default_height')) { |
| 357 | 340 | update_option('vdo_default_height', 'auto'); |
| @@ -358,18 +341,15 @@ | ||
| 358 | 341 | } |
| 359 | 342 | if (!get_option('vdo_default_width')) { |
| 360 | 343 | update_option('vdo_default_width', '1280'); |
| 361 | 344 | } |
| 362 | - $vdo_client_key = get_option('vdo_client_key'); | |
| 363 | - if (!$vdo_client_key && strlen($vdo_client_key) != 64) { | |
| 364 | - vdo_show_form_client_key(); | |
| 365 | - return ""; | |
| 366 | - } | |
| 367 | 345 | if (!current_user_can('manage_options')) { |
| 368 | - wp_die(__('You do not have sufficient permissions to access this page.')); | |
| 346 | + wp_die(__('You do not have sufficient permissions to access this page.')); | |
| 369 | 347 | } |
| 370 | 348 | include('include/options.php'); |
| 349 | + return ""; | |
| 371 | 350 | } |
| 351 | + | |
| 372 | 352 | function register_vdo_settings() |
| 373 | 353 | { |
| 374 | 354 | // whitelist options |
| 375 | 355 | register_setting('vdo_option-group', 'vdo_client_key'); |
| @@ -377,42 +357,22 @@ | ||
| 377 | 357 | register_setting('vdo_option-group', 'vdo_default_width'); |
| 378 | 358 | register_setting('vdo_option-group', 'vdo_annotate_code'); |
| 379 | 359 | register_setting('vdo_option-group', 'vdo_embed_version'); |
| 380 | 360 | register_setting('vdo_option-group', 'vdo_player_theme'); |
| 381 | - register_setting('vdo_option-group', 'vdo_watermark_flash_html'); | |
| 382 | 361 | register_setting('vdo_option-group', 'vdo_plugin_version'); |
| 383 | - register_setting('vdo_custom_theme', 'vdo_player_theme_options'); | |
| 362 | + register_setting('vdo_option-group', 'vdo_player_speed'); | |
| 363 | + register_setting('vdo_option-group', 'vdo_show_plugin_in_sidebar'); | |
| 384 | 364 | } |
| 385 | 365 | // add the menu item and register settings (3 functions), ends |
| 386 | 366 | |
| 387 | -// section for client key for new users | |
| 388 | -function vdo_show_form_client_key() | |
| 389 | -{ | |
| 390 | - include('include/setting_form.php'); | |
| 391 | -} | |
| 392 | - | |
| 393 | 367 | // Activation Hook starts |
| 394 | 368 | function vdo_activate() |
| 395 | 369 | { |
| 396 | - if ((get_option('vdo_default_height')) == false) { | |
| 397 | - update_option('vdo_default_height', 'auto'); | |
| 398 | - } | |
| 399 | - if ((get_option('vdo_default_width')) == false) { | |
| 400 | - update_option('vdo_default_width', '1280'); | |
| 401 | - } | |
| 402 | - //https://stackoverflow.com/a/2173318/5022684 | |
| 403 | - if ((get_option('vdo_embed_version')) == false) { | |
| 404 | - update_option('vdo_embed_version', VDOCIPHER_PLAYER_VERSION); | |
| 405 | - } | |
| 406 | - if ((get_option('vdo_player_theme')) == false) { | |
| 407 | - update_option('vdo_player_theme', '9ae8bbe8dd964ddc9bdb932cca1cb59a'); | |
| 408 | - } | |
| 409 | - if ((get_option('vdo_watermark_flash_html')) == false) { | |
| 410 | - update_option('vdo_watermark_flash_html', 'html5'); | |
| 411 | - } | |
| 412 | - if ((get_option('vdo_plugin_version')) == false) { | |
| 413 | - update_option('vdo_plugin_version', VDOCIPHER_PLUGIN_VERSION); | |
| 414 | - } | |
| 370 | + add_option('vdo_default_height', 'auto'); | |
| 371 | + add_option('vdo_default_width', 1280); | |
| 372 | + add_option('vdo_embed_version', VDOCIPHER_PLAYER_VERSION); | |
| 373 | + add_option('vdo_player_theme', VDOCIPHER_DEFAULT_THEME); | |
| 374 | + add_option('vdo_show_plugin_in_sidebar', 'true'); | |
| 415 | 375 | } |
| 416 | 376 | register_activation_hook(__FILE__, 'vdo_activate'); |
| 417 | 377 | |
| 418 | 378 | // Registering and specifying Gutenberg block |
| @@ -470,9 +430,9 @@ | ||
| 470 | 430 | |
| 471 | 431 | add_action('init', 'vdo_register_block'); |
| 472 | 432 | |
| 473 | 433 | // Deactivation Hook starts |
| 474 | -function vdo_deactivate() | |
| 434 | +function vdo_uninstall() | |
| 475 | 435 | { |
| 476 | 436 | delete_option('vdo_client_key'); |
| 477 | 437 | delete_option('vdo_default_width'); |
| 478 | 438 | delete_option('vdo_default_height'); |
| @@ -478,13 +438,13 @@ | ||
| 478 | 438 | delete_option('vdo_default_height'); |
| 479 | 439 | delete_option('vdo_annotate_code'); |
| 480 | 440 | delete_option('vdo_embed_version'); |
| 481 | 441 | delete_option('vdo_player_theme'); |
| 482 | - delete_option('vdo_watermark_flash_html'); | |
| 483 | - delete_option('vdo_player_theme_options'); | |
| 484 | 442 | delete_option('vdo_plugin_version'); |
| 443 | + delete_option('vdo_player_speed'); | |
| 444 | + delete_option('vdo_show_plugin_in_sidebar'); | |
| 485 | 445 | } |
| 486 | -register_deactivation_hook(__FILE__, 'vdo_deactivate'); | |
| 446 | +register_uninstall_hook(__FILE__, 'vdo_uninstall'); | |
| 487 | 447 | |
| 488 | 448 | // Admin notice to configure plugin for new installs, starts |
| 489 | 449 | function vdo_admin_notice() |
| 490 | 450 | { |