-
Notifications
You must be signed in to change notification settings - Fork 0
/
eko-video.php
170 lines (147 loc) · 4.45 KB
/
eko-video.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* "Security Note: Consider blocking direct access to your plugin PHP
* files by adding the following line at the top of each of them."
*/
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Plugin Name: eko-video
* Author: eko
* Author URI: https://eko.com
* Description: A plugin to assist on embedding eko videos in WordPress sites.
* Version: 1.0.8
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
// Plugin definintions
define( 'EKO_NAME', pathinfo( __FILE__ )['filename'] );
define( 'EKO_VERSION', '1.0.8' );
define( 'EKO_PLUGIN_URL', plugins_url( '', __FILE__ ) );
define( 'EKO_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'EKO_DFAULT_CPT_SLUG', 'eko-videos' );
// base name
define( 'EKO_BASE_NAME', plugin_basename( __FILE__ ) );
// main file
define( 'EKO_PLUGIN_FILE', __FILE__ );
// Include all other files
include_once( EKO_PLUGIN_PATH . 'includes/api.php' );
include_once( EKO_PLUGIN_PATH . 'includes/embed-api.php' );
//////////////////////////////////
/////// HELPING FUNCTIONS ////////
//////////////////////////////////
/**
* eko_get_embed_url
* returns the url for embedding an eko video by its id
* @param mixed $videoId
* @param mixed $password
* @param mixed $query_params
* @param mixed $embedapi
* @param mixed $events
* @return string src, the embed url of the video
*/
function eko_get_embed_url( string $videoId, string $password = '', bool $query_params = false, $embedapi = 'v1', array $events = array() ) {
$src = 'https://eko.com/v/' . esc_attr( $videoId ) . '/embed';
// add query params if wanted
if ( $query_params ) {
$src .= '?' . $_SERVER['QUERY_STRING'];
}
// add password if given
if ( $password ) {
$src .= ( $query_params ? '&password=' . esc_attr( $password ) : '?password=' . esc_attr( $password ) );
}
// add events if given
$src .= ( $query_params || $password ? '&embedapi=' . esc_attr( $embedapi ) : '?embedapi=' . esc_attr( $embedapi ) );
if ( $events ) {
$src .= '?events=' . implode( ',', $events );
}
return $src;
}
/**
* eko_get_the_post_id
*
* get $post->ID if $post_id not given
*
* @param mixed $post_id
* @return string
*/
function eko_get_the_post_id( $post_id = false ) {
global $post;
return $post_id ? $post_id : $post->ID;
}
/**
* eko_get_actual_field
*
* get the value of a certain video field
*
* @param mixed $field
* @return bool
*/
function eko_get_actual_field( array $field ) {
return isset( $field[0] ) ? $field[0] : null;
}
/**
* eko_get_option
*
* @param mixed $key
* @param mixed $default
* @return void
*/
function eko_get_option( $key, $default = '') {
$options = get_option( 'eko_plugin_options' );
return ( $options && $options[$key] ) ? $options[$key] : '';
}
/**
* eko_is_video
*
* @param mixed $post_id
* @return bool
*/
function eko_is_video( $post_id = null ) {
return strcmp( get_post_type( $post_id ), 'eko-video' ) === 0;
}
// register as oembed provider
function eko_register_as_oembed_provider() {
$endpoint = 'https://eko.com';
$format = 'https://eko.com/*';
wp_oembed_add_provider( $format, $endpoint );
}
class Eko_Plugin {
var $video;
var $eko_admin;
var $eko_frontend;
function __construct() {
require_once EKO_PLUGIN_PATH . 'includes/admin/class-video.php';
require_once EKO_PLUGIN_PATH . 'includes/admin/class-admin.php';
require_once EKO_PLUGIN_PATH . 'includes/frontend/class-frontend.php';
}
function setup() {
// register scripts & atyles
add_action( 'wp_loaded', [$this, 'register_eko_scripts'] );
// register post type
$this->video = new Eko_Video();
$this->video->setup();
if ( is_admin() ) {
add_action( 'plugins_loaded', array( $this, 'load_eko_admin' ) );
} else {
add_action( 'plugins_loaded', array( $this, 'load_eko_frontend' ) );
}
}
function register_eko_scripts() {
// for video post type
wp_register_script( 'eko-video-script', EKO_PLUGIN_URL . '/dist/js/videoPostType.js', array( 'jquery' ) );
// register eko sdk for embedding
wp_register_script( 'eko-js-sdk', EKO_PLUGIN_URL . '/eko-js-sdk-develop/dist/EkoPlayer.js' );
// to embed via shortcode
wp_register_script( 'eko-shortcode-script', EKO_PLUGIN_URL . '/dist/js/shortcodeIframe.js' );
}
function load_eko_admin() {
$this->eko_admin = new Eko_Admin();
$this->eko_admin->setup();
}
function load_eko_frontend() {
$this->eko_frontend = new Eko_Frontend();
$this->eko_frontend->setup();
}
}
$eko_plugin = new Eko_Plugin();
$eko_plugin->setup();