# vdocipher/1.6/vdocipher.php

VdoCipher: Secure Video Player and Hosting, version 1.6. 193 lines.

- Page: https://pluginprobe.com/plugins/vdocipher/1.6/code/vdocipher.php
- Raw: https://pluginprobe.com/plugins/vdocipher/1.6/raw/vdocipher.php
- Modified: 2015-10-10T08:44:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/vdocipher/1.6/code/vdocipher.php#L10-L20`.

```php
<?php
/**
 * Plugin Name: VdoCipher
 * Plugin URI: http://www.vdocipher.com
 * Description: Secured video hosting for wordpress
 * Version: 1.6
 * Author: VdoCipher
 * Author URI: http://www.vdocipher.com
 * License: GPL2
 */


if (__FILE__ == $_SERVER['SCRIPT_FILENAME']) {
    header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
    exit("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n<html><head>\r\n<title>404 Not Found</title>\r\n</head><body>\r\n<h1>Not Found</h1>\r\n<p>The requested URL " . $_SERVER['SCRIPT_NAME'] . " was not found on this server.</p>\r\n</body></html>");
}

function vdo_send($action, $params, $posts = false){
	$client_key = get_option('vdo_client_key');
	if ($client_key == false || $client_key == "") {
		return "Plugin not configured. Please set the key to embed videos.";
	}
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_FAILONERROR, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl, CURLOPT_VERBOSE, true);
	curl_setopt($curl, CURLOPT_FAILONERROR, false);    
	//curl_setopt($curl, CURLOPT_PROXY, "xxxxxxxxxxxxxxxxx:xxxx");

	$getData = http_build_query($params);
	curl_setopt($curl, CURLOPT_POST, true); 
	$postData = "clientSecretKey=$client_key";
	if ($posts) {
		$postData .= "&". $posts;
	}
	curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
	$url = "http://api.vdocipher.com/v2/$action/?$getData";
	curl_setopt($curl, CURLOPT_URL,$url);
	$html = curl_exec($curl);
	if (!$html) {
		echo curl_error($curl);
	}
	curl_close($curl);
	return $html;
}
function vdo_shortcode( $atts ) {
	extract( shortcode_atts(
				array(
					'title' => 'TITLE_OF_VIDEO',
					'width' => get_option('vdo_default_width'),
					'height' => get_option('vdo_default_height'),
					'id'	=> 'id',
					'no_annotate'=> false
					), $atts )
		   );
	if(!$atts['id']){
		if(!$atts['title'])
			return "Required argument id for embedded video not found.";
		$params = array(
				'search'=>array(
					'title'=>$title
					),  
				'page'=>1,
				'limit'=>30,
				'type'=>'json'
				);
		$video = vdo_send("videos", $params);
		$video = json_decode($video);
		if($video == null)
			return "404. Video not found.";
		$video = $video[0]->id;
		if ($video == null) {
			return "No video with given title found.";
		}
	}
	else
		$video = $id;

	$params = array(
		'video'=>$video
	);
	$anno = false;
	if (!function_exists("eval_date")) {
		function eval_date($matches){
			return date($matches[1]);
		}
	}
	if (get_option('vdo_annotate_code') != "") {
		$current_user = wp_get_current_user();
		$vdo_annotate_code = get_option('vdo_annotate_code');
		$vdo_annotate_code = apply_filters('vdocipher_annotate_preprocess', $vdo_annotate_code);
		if (is_user_logged_in()) {
			$vdo_annotate_code = str_replace('{name}', $current_user->display_name , $vdo_annotate_code);
			$vdo_annotate_code = str_replace('{email}', $current_user->user_email , $vdo_annotate_code);
			$vdo_annotate_code = str_replace('{username}', $current_user->user_login , $vdo_annotate_code);
			$vdo_annotate_code = str_replace('{id}', $current_user->ID , $vdo_annotate_code);
		}
		$vdo_annotate_code = str_replace('{ip}', $_SERVER['REMOTE_ADDR'] , $vdo_annotate_code);
		$vdo_annotate_code = preg_replace_callback('/\{date\.([^\}]+)\}/', "eval_date" , $vdo_annotate_code);
		$vdo_annotate_code = apply_filters('vdocipher_annotate_postprocess', $vdo_annotate_code);
		if(!$no_annotate)
			$anno = "annotate=". urlencode($vdo_annotate_code);
	}
	$OTP = vdo_send("otp", $params, $anno);
	$OTP = json_decode($OTP);
	if(is_null($OTP)){
		$output = "<span id='vdo$OTP' style='background:#555555;color:#FFFFFF'><h4>Video not found</h4></span>";
		return $output;
	}
	$OTP = $OTP->otp;

	$output = "<span id='vdo$OTP'></span>";
	$output .= "<script src='https://de122v0opjemw.cloudfront.net/utils/playerInit.php?otp=$OTP&height=$height&width=$width&'></script>";
	return $output;
}

add_shortcode( 'vdo', 'vdo_shortcode' );


/// adding the settings link
$plugin = plugin_basename(__FILE__); 
add_filter("plugin_action_links_$plugin", 'vdo_settings_link' );

function vdo_settings_link($links) { 
	$settings_link = '<a href="options-general.php?page=vdocipher.php">Settings</a>'; 
	array_unshift($links, $settings_link); 
	return $links; 
}


/// add the menu item and register settings
if ( is_admin() ){ // admin actions
	add_action( 'admin_menu', 'vdo_menu' );
	add_action( 'admin_init', 'register_vdo_settings' );
} else {
	  // non-admin enqueues, actions, and filters
}
function vdo_menu(){
	add_options_page( 'VdoCipher Options', 'VdoCipher', 'manage_options', 'vdocipher', 'vdo_options' );
}
function vdo_options(){
	if (!get_option('vdo_default_height'))
		update_option('vdo_default_height', '360');
	if (!get_option('vdo_default_width'))
		update_option('vdo_default_width', '640');
	$vdo_client_key = get_option('vdo_client_key');
	if (!$vdo_client_key && strlen($vdo_client_key) != 64) {
		vdo_show_form_client_key();
		return "";
	}
	if ( !current_user_can( 'manage_options' ) )  {
			wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
		}
	include('include/options.php');
}
function register_vdo_settings() { // whitelist options
  register_setting( 'vdo_option-group', 'vdo_client_key' );
  register_setting( 'vdo_option-group', 'vdo_default_height' );
  register_setting( 'vdo_option-group', 'vdo_default_width' );
  register_setting( 'vdo_option-group', 'vdo_annotate_code' );
}

/// adding a section for asking for the client key
function vdo_show_form_client_key(){
	include('include/setting_form.php');
}
register_deactivation_hook(__FILE__, 'vdo_deactivate');
function vdo_deactivate(){
	delete_option( 'vdo_client_key' );
	delete_option('vdo_default_width');
	delete_option('vdo_default_height');
	delete_option('vdo_annotate_code');
}
function vdo_activate() {
	if (!get_option('vdo_default_height'))
		update_option('vdo_default_height', '400');
	if (!get_option('vdo_default_width'))
		update_option('vdo_default_width', '640');
}
register_activation_hook( __FILE__, 'vdo_activate' );
function vdo_admin_notice() {
	if((!get_option('vdo_client_key') || strlen(get_option('vdo_client_key')) != 64) && basename($_SERVER['PHP_SELF']) == "plugins.php" ){
		?>
		<div class="error">
			<p>The VdoCipher plugin is not ready. <a href="options-general.php?page=vdocipher">Click here to configure</a>
			</p>
		</div>
		<?php
	}
}
add_action( 'admin_notices', 'vdo_admin_notice' );

```
