-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutubefancybox.php
217 lines (188 loc) · 6.57 KB
/
youtubefancybox.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
/**
* Plugin Name: Video Lightbox for YouTube/Vimeo
* Plugin URI: https://wordpress.org/plugins/youtubefancybox/
* Description: Display thumbnail of Youtube and Vimeo videos and on clicking on thumbnail it will open in popupbox and play video.
* Author: Milind More
* Author URI: https://milindmore.wordpress.com/
* Version: 2.7.1
* Text Domain: ytubebox
* Domain Path: /languages/
* Requires PHP: 8.1
*
* @author milind
* @package ytubefancybox
*/
namespace YTubeFancy {
/**
* Video Lightbox main class.
*/
class Youtubefanybox {
/**
* Version Number.
*
* @var int.
*/
public $version;
/**
* Class Constructor.
*/
public function __construct() {
$this->version = '2.7.1';
/**
* If You are admin you will get admin settings
*/
if ( is_admin() ) {
/**
* Adding action calling plugin menu and loading header file
*/
add_action( 'admin_menu', array( $this, 'youtubefancybox_plugin_main_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'youtubefancybox_adminjs_file' ) );
}
/**
* Adding Shortcode action filter
*/
add_action( 'wp_enqueue_scripts', array( $this, 'youtubefancybox_js_file' ) );
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
}
/**
* Adds Menu page for Youtueb Fancybox.
*/
public function youtubefancybox_plugin_main_menu() {
add_menu_page( 'Video Lightbox for YouTube/Vimeo', 'Video Lightbox', 'manage_options', 'ytubefancybox', array( $this, 'ytubefancybox_default_settings' ), 'dashicons-format-video', 6 );
}
/**
* Function will make plugin translation ready.
*
* @todo created pdo or mo file for translation
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'ytubebox', false, basename( dirname( __FILE__ ) ) . '/languages/' );
}
/**
* Loading js and css files
*
* @param string $hook screen id.
*/
public function youtubefancybox_adminjs_file( $hook ) {
$youtubefancybox_admin_screens = array( 'video-lightbox_page_vimeo', 'video-lightbox_page_ytube', 'toplevel_page_ytubefancybox' );
if ( ! in_array( $hook, $youtubefancybox_admin_screens, true ) ) {
return;
}
wp_enqueue_script( 'jquery' );
wp_register_script( 'fancybox_admin', plugins_url( 'js/fancybox_admin.js', __FILE__ ), array( 'jquery' ), $this->version, true );
$translation_array = array(
'youtube_alert' => esc_html__( 'Youtube URL you entered might be wrong, Please enter correct URL!', 'ytubebox' ),
'viemo_alert' => esc_html__( 'Viemo URL you entered might be wrong, Please enter correct URL!', 'ytubebox' ),
);
wp_localize_script( 'fancybox_admin', 'fancybox_admin_obj', $translation_array );
wp_enqueue_script( 'fancybox_admin' );
}
/**
* Enqueue scritps js nessary.
*/
public function youtubefancybox_js_file() {
// Iif it's AMP page then We will be using AMP components instead.
if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
wp_enqueue_style( 'youtubefancybox-amp', plugins_url( 'css/youtubefancybox-amp.css', __FILE__ ), '', $this->version );
return;
}
wp_enqueue_style( 'colorbox-css', plugins_url( 'css/colorbox.css', __FILE__ ), '', $this->version );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'colorbox-js', plugins_url( 'js/jquery.colorbox.js', __FILE__ ), array( 'jquery' ), $this->version, true );
wp_enqueue_script( 'colorbox-caller', plugins_url( 'js/caller.js', __FILE__ ), array( 'jquery', 'colorbox-js' ), $this->version, true );
}
/**
* Sets Default settings.
*/
public function ytubefancybox_default_settings() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
}
if ( 'POST' === filter_input( INPUT_SERVER, 'REQUEST_METHOD' ) ) {
if ( get_option( 'youtube_height' ) ) {
update_option( 'youtube_height', filter_input( INPUT_POST, 'youtube_height' ) );
} else {
add_option( 'youtube_height', filter_input( INPUT_POST, 'youtube_height' ), '', 'yes' );
}
if ( get_option( 'youtube_width' ) ) {
update_option( 'youtube_width', filter_input( INPUT_POST, 'youtube_width' ) );
} else {
add_option( 'youtube_width', filter_input( INPUT_POST, 'youtube_width' ), '', 'yes' );
}
if ( get_option( 'autoplay' ) ) {
update_option( 'autoplay', filter_input( INPUT_POST, 'autoplay' ) );
} else {
add_option( 'autoplay', filter_input( INPUT_POST, 'autoplay' ), '', 'yes' );
}
}
?>
<style type="text/css">
fieldset { border: 1px solid; }
</style>
<div class="wrap">
<h1><?php esc_html_e( 'Video Lightbox', 'ytubebox' ); ?></h1>
<h2>Set Default Options</h2>
<hr />
<form action="" method="post">
<table class="form-table">
<tr>
<th align="left"><?php esc_html_e( 'Height', 'ytubebox' ); ?></th>
<td align="left">
<input type="text" name="youtube_height" value="<?php echo esc_attr( get_option( 'youtube_height' ) ); ?>" />
</td>
</tr>
<tr>
<th align="left"><?php esc_html_e( 'Width', 'ytubebox' ); ?></th>
<td align="left">
<input type="text" name="youtube_width" value="<?php echo esc_attr( get_option( 'youtube_width' ) ); ?>" />
</td>
</tr>
<tr>
<th align="left"><?php esc_html_e( 'Autoplay', 'ytubebox' ); ?></th>
<td align="left">
<input type="radio" name="autoplay" value="yes"
<?php
if ( 'yes' === get_option( 'autoplay' ) ) {
echo esc_attr( 'checked="checked"' );
}
?>
/>
<?php esc_html_e( 'Yes', 'ytubebox' ); ?>
<input type="radio" name="autoplay" value="no"
<?php
if ( 'no' === get_option( 'autoplay' ) ) {
echo esc_attr( 'checked="checked"' );
}
?>
/>
<?php esc_html_e( 'No', 'ytubebox' ); ?>
</td>
</tr>
<tr>
<th align="left"></th>
<td align="left">
<input type="submit" value="<?php esc_attr_e( 'Save', 'ytubebox' ); ?>" name="submit" class="button button-primary" />
</td>
</tr>
</table>
</form>
</div>
<?php
}
}
}
namespace {
/**
* Include lib files.
*/
foreach ( glob( plugin_dir_path( __FILE__ ) . '/lib/*.php' ) as $lib_filename ) {
require_once $lib_filename;
}
global $fancybox, $youtube, $viemo;
$fancybox = new \YTubeFancy\Youtubefanybox();
$youtube = new \YTubeFancy\Youtube();
$viemo = new \YTubeFancy\Vimeo();
}