PluginProbe ʕ •ᴥ•ʔ
Video Playlist for YouTube / 6.0
Video Playlist for YouTube v6.0
trunk 1.0 2.0 3.0 4.0 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.7.1 6.8 6.9
video-playlist-for-youtube / video-playlist-ytb-plugin.php
video-playlist-for-youtube Last commit date
includes 2 years ago index.php 2 years ago readme.txt 2 years ago video-playlist-ytb-plugin.php 2 years ago vpfy-api-playlist-shortcode.php 2 years ago vpfy-settings-pg.php 2 years ago vpfy-vplaylist-functions.php 2 years ago
video-playlist-ytb-plugin.php
443 lines
1 <?php
2 /* Plugin Name: Video Playlist for YouTube
3 * Plugin URI: https://wordpress.org/plugins/video-playlist-for-youtube
4 * Description: It is a very nifty responsive video playlist for youtube that helps you display youtube channels and videos on your website. By using this plugin you can create unlimited playlist while setting up many options and arrange them in any order using drag n drop features.
5 * Author: Galaxy Weblinks
6 * Author URI: https://www.galaxyweblinks.com/
7 * Text Domain: video-playlist-for-youtube
8 * Licence: GPL2
9 * Version: 6.0
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly
14 }
15
16 if(!defined('VID_PLYLST_PLUGINURL')){
17 define('VID_PLYLST_PLUGINURL', plugin_dir_url(__FILE__));
18 }
19 if(!defined('VID_PLYLST_PLUGINPATH')){
20 define('VID_PLYLST_PLUGINPATH', plugin_dir_path(__FILE__));
21 }
22
23
24 //echo "path ".VID_PLYLST_PLUGINPATH;
25 require_once(VID_PLYLST_PLUGINPATH.'vpfy-vplaylist-functions.php');
26 require_once(VID_PLYLST_PLUGINPATH.'vpfy-settings-pg.php');
27 require_once(VID_PLYLST_PLUGINPATH.'vpfy-api-playlist-shortcode.php');
28 //admin notice when activate plugin
29 register_activation_hook(__FILE__, 'uvfy_vplay_adminnotice');
30 function uvfy_vplay_adminnotice(){
31 update_option('video_plylst_admin_notice','enabled');
32 }
33 function uvfy_vplay_admin_notice__success() {
34 if(get_option('video_plylst_admin_notice') == 'enabled'){
35 ?>
36
37 <div class="notice notice-success is-dismissible">
38 <p><?php _e( 'To view setting please ', 'video-playlist-for-youtube' ); ?><a href="<?php echo admin_url('edit.php?post_type=vid_playlist_ytub'); ?>"><?php _e( 'click here', 'video-playlist-for-youtube' ); ?></a></p>
39 </div>
40 <?php
41 delete_option('video_plylst_admin_notice');
42 }
43 }
44 add_action( 'admin_notices', 'uvfy_vplay_admin_notice__success' );
45
46 //Add Menu Page
47 add_action('admin_menu', 'vpfu_vplay_add_menu');
48 function vpfu_vplay_add_menu(){
49 add_menu_page('video playlist', __('Video Playlist','video-playlist-for-youtube'), 'manage_options', 'edit.php?post_type=vid_playlist_ytub', NULL);
50 add_submenu_page('edit.php?post_type=vid_playlist_ytub','settings', __('Settings','video-playlist-for-youtube'), 'manage_options', 'vpfy_settings_menu', 'vpfy_submenu_settings_page');
51 add_action('admin_init', 'vpfyt_settings_api_forytub');
52 }
53 /*Register setting api*/
54 function vpfyt_settings_api_forytub(){
55 register_setting('vpfy_reg_groupname','vpfy_reg_ytubapi_key');
56 }
57
58 add_action( 'init', 'vpfy_vplaylist_custompt', 0 );
59 /*
60 * Creating a function to create our CPT
61 */
62
63 function vpfy_vplaylist_custompt() {
64
65 // Set UI labels for Custom Post Type
66 $labels = array(
67 'name' => _x( 'Playlists', 'Post Type General Name', 'video-playlist-for-youtube' ),
68 'singular_name' => _x( 'Playlist', 'Post Type Singular Name', 'video-playlist-for-youtube' ),
69 'menu_name' => __( 'Playlists', 'video-playlist-for-youtube' ),
70 'parent_item_colon' => __( 'Parent Playlist', 'video-playlist-for-youtube' ),
71 'all_items' => __( 'All Playlists', 'video-playlist-for-youtube' ),
72 'view_item' => __( 'View Playlist', 'video-playlist-for-youtube' ),
73 'add_new_item' => __( 'Add New Playlist', 'video-playlist-for-youtube' ),
74 'add_new' => __( 'Add New', 'video-playlist-for-youtube' ),
75 'edit_item' => __( 'Edit Playlist', 'video-playlist-for-youtube' ),
76 'update_item' => __( 'Update Playlist', 'video-playlist-for-youtube' ),
77 'search_items' => __( 'Search Playlist', 'video-playlist-for-youtube' ),
78 'not_found' => __( 'Not Found', 'video-playlist-for-youtube' ),
79 'not_found_in_trash' => __( 'Not found in Trash', 'video-playlist-for-youtube' ),
80 );
81
82 // Set other options for Custom Post Type
83
84 $args = array(
85 'label' => __( 'Playlists', 'video-playlist-for-youtube' ),
86 'description' => __( 'Playlist for youtube videos', 'video-playlist-for-youtube' ),
87 'labels' => $labels,
88 // Features this CPT supports in Post Editor
89 'supports' => array( 'title' ),
90 'hierarchical' => false,
91 'public' => false,
92 'show_ui' => true,
93 'show_in_menu' => 'edit.php?post_type=vid_playlist_ytub',
94 'show_in_nav_menus' => false,
95 'show_in_admin_bar' => true,
96 'menu_position' => null,
97 'can_export' => true,
98 'has_archive' => true,
99 'exclude_from_search' => false,
100 'publicly_queryable' => false,
101 'capability_type' => 'post',
102 'show_in_rest' => true,
103
104 );
105
106 // Registering Custom Post Type
107 register_post_type( 'vid_playlist_ytub', $args );
108 }
109 /* Add Meta box for shortcode*/
110 add_action('admin_init', 'vpfy_vplaylist_add_meta_boxes_for_shortcode', 2);
111
112 function vpfy_vplaylist_add_meta_boxes_for_shortcode() {
113 add_meta_box( 'vpfy-vplay-gallery-for-shortcode', __('Shortcode','video-playlist-for-youtube'), 'vpfy_vplaylist_for_shortcode_display', 'vid_playlist_ytub', 'side', 'default');
114
115 add_meta_box( 'vpfy-vplay-videogallery-setings', __('Slider Settings','video-playlist-for-youtube'), 'vpfy_vplaylist_slider_settings', 'vid_playlist_ytub', 'side', 'default');
116
117 }
118
119 function vpfy_vplaylist_for_shortcode_display(){
120 $ytube_current_id = get_the_ID();
121 echo "[videoPlaylist id=".$ytube_current_id."]";
122 }
123
124 /* Add Meta box*/
125
126 add_action('admin_init', 'vpfysect_vplaylist_add_meta_boxes', 2);
127
128 function vpfysect_vplaylist_add_meta_boxes() {
129 add_meta_box( 'ytube-vplay-gallery', __('Add YouTube Video URL','video-playlist-for-youtube'), 'vpfy_vplaylist_repeatable_meta_box_display', 'vid_playlist_ytub', 'normal', 'default');
130 }
131
132 function vpfy_vplaylist_repeatable_meta_box_display() {
133 global $post;
134 $gpminvoice_group = get_post_meta($post->ID, 'customdata_group', true);
135 wp_nonce_field( 'gpm_repeatable_meta_box_nonce', 'gpm_repeatable_meta_box_nonce' );
136 wp_enqueue_script('vpfyt-vplay-repeatmeta');
137 wp_enqueue_style('vpfy-vplay-adminstyle');
138 wp_enqueue_script('jquery-ui-sortable');
139 ?>
140 <script>
141 jQuery( function() {
142 //jQuery( "tr" ).draggable({ handle: ".ytubedraggable" });
143 jQuery( "tbody.ytub-sortble" ).sortable();
144 jQuery( "tbody.ytub-sortble" ).disableSelection();
145 } );
146 </script>
147
148
149 <table id="repeatable-fieldset-one" width="100%">
150 <tbody class="ytub-sortble">
151 <?php
152 if ( $gpminvoice_group ) :
153 foreach ( $gpminvoice_group as $field ) {
154 ?>
155 <tr class="drgble-sect">
156 <td width="20%">
157 <input type="text" required="required" placeholder="Title" name="TitleItem[]" value="<?php if($field['TitleItem'] != '') echo esc_attr( $field['TitleItem'] ); ?>" /></td>
158 <td width="35%">
159 <textarea placeholder="Description" cols="40" rows="3" name="TitleDescription[]"> <?php if ($field['TitleDescription'] != '') echo esc_attr( $field['TitleDescription'] ); ?> </textarea></td>
160
161 <td width="30%">
162 <input type="text" placeholder="Youtube URL" name="YoutubeUr[]" value="<?php if($field['YoutubeUr'] != '') echo esc_attr( $field['YoutubeUr'] ); ?>" /></td>
163
164 <td width="15%"><a class="button remove-row" href="#1">Remove</a><span class="ytubedraggable">
165 <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M13,8c0.6,0,1-0.4,1-1s-0.4-1-1-1s-1,0.4-1,1S12.4,8,13,8z M5,6C4.4,6,4,6.4,4,7s0.4,1,1,1s1-0.4,1-1S5.6,6,5,6z M5,10 c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S5.6,10,5,10z M13,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S13.6,10,13,10z M9,6 C8.4,6,8,6.4,8,7s0.4,1,1,1s1-0.4,1-1S9.6,6,9,6z M9,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S9.6,10,9,10z"></path></svg></span></td>
166 </tr>
167 <?php
168 }
169 else :
170 // show a blank one
171 ?>
172 <tr class="drgble-sect">
173 <td>
174 <input type="text" required="required" placeholder="Title" title="Title" name="TitleItem[]" /></td>
175 <td>
176 <textarea placeholder="Description" name="TitleDescription[]" cols="40" rows="3"> </textarea>
177 </td>
178
179 <td>
180 <input type="text" placeholder="Youtube URL" name="YoutubeUr[]" />
181 </td>
182
183 <td><a class="button cmb-remove-row-button button-disabled" href="#">Remove</a><span class="ytubedraggable">
184 <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M13,8c0.6,0,1-0.4,1-1s-0.4-1-1-1s-1,0.4-1,1S12.4,8,13,8z M5,6C4.4,6,4,6.4,4,7s0.4,1,1,1s1-0.4,1-1S5.6,6,5,6z M5,10 c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S5.6,10,5,10z M13,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S13.6,10,13,10z M9,6 C8.4,6,8,6.4,8,7s0.4,1,1,1s1-0.4,1-1S9.6,6,9,6z M9,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S9.6,10,9,10z"></path></svg></span></td>
185 </tr>
186 <?php endif; ?>
187
188 <!-- empty hidden one for jQuery -->
189 <tr class="empty-row screen-reader-text drgble-sect">
190 <td>
191 <input type="text" placeholder="Title" name="TitleItem[]"/></td>
192 <td>
193 <textarea placeholder="Description" cols="40" rows="3" name="TitleDescription[]"></textarea>
194 </td>
195 <td>
196 <input type="text" placeholder="Youtube URL" name="YoutubeUr[]" />
197 </td>
198 <td><a class="button remove-row" href="#">Remove</a><span class="ytubedraggable">
199 <svg width="18" height="18" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" role="img" aria-hidden="true" focusable="false"><path d="M13,8c0.6,0,1-0.4,1-1s-0.4-1-1-1s-1,0.4-1,1S12.4,8,13,8z M5,6C4.4,6,4,6.4,4,7s0.4,1,1,1s1-0.4,1-1S5.6,6,5,6z M5,10 c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S5.6,10,5,10z M13,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S13.6,10,13,10z M9,6 C8.4,6,8,6.4,8,7s0.4,1,1,1s1-0.4,1-1S9.6,6,9,6z M9,10c-0.6,0-1,0.4-1,1s0.4,1,1,1s1-0.4,1-1S9.6,10,9,10z"></path></svg></span></td>
200 </tr>
201 </tbody>
202 </table>
203 <p><a id="add-row" class="button" href="#">Add another</a></p>
204 <?php
205 }
206 add_action('save_post', 'custom_repeatable_meta_box_save');
207 function custom_repeatable_meta_box_save($post_id) {
208 if ( ! isset( $_POST['gpm_repeatable_meta_box_nonce'] ) ||
209 ! wp_verify_nonce( $_POST['gpm_repeatable_meta_box_nonce'], 'gpm_repeatable_meta_box_nonce' ) )
210 return;
211
212 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
213 return;
214
215 if (!current_user_can('edit_post', $post_id))
216 return;
217
218 $old = get_post_meta($post_id, 'customdata_group', true);
219 $new = array();
220
221
222 /* Title */
223 $invoiceItems = array();
224 foreach ($_POST['TitleItem'] as $titlValue) {
225 $invoiceItems[] = sanitize_text_field($titlValue);
226 }
227 /*Description*/
228 $prices = array();
229 foreach ($_POST['TitleDescription'] as $titlDesValue) {
230 $prices[] = sanitize_textarea_field($titlDesValue);
231 }
232
233 /*URL*/
234 $YoutubeUr = array();
235 foreach ($_POST['YoutubeUr'] as $youtubeUrlValue) {
236 $YoutubeUr[] = sanitize_text_field($youtubeUrlValue);
237 }
238
239 $count = count( $invoiceItems );
240 for ( $i = 0; $i < $count; $i++ ) {
241 if ( $invoiceItems[$i] != '' ) :
242 $new[$i]['TitleItem'] = stripslashes( strip_tags( trim($invoiceItems[$i]) ) );
243 $new[$i]['TitleDescription'] = stripslashes( trim($prices[$i]) ); // and however you want to sanitize
244 $new[$i]['YoutubeUr'] = filter_var($YoutubeUr[$i], FILTER_SANITIZE_URL);
245 endif;
246 }
247 if ( !empty( $new ) && $new != $old )
248 update_post_meta( $post_id, 'customdata_group', $new );
249 elseif ( empty($new) && $old )
250 delete_post_meta( $post_id, 'customdata_group', $old );
251 if(isset($_POST['utubeSliderRange'])){
252 $new_itm_range = array();
253 foreach ($_POST['utubeSliderRange'] as $rangevalue) {
254 $new_itm_range[] = sanitize_text_field($rangevalue);
255 }
256 update_post_meta( $post_id, '_utubeSliderRange', $new_itm_range );
257 }
258
259 }
260
261 /*Display playlist*/
262 add_shortcode('videoPlaylist','vpfy_vplaylist_display_gallery');
263 function vpfy_vplaylist_display_gallery($atts){
264 $arry_arg = shortcode_atts(array('id'=>''),$atts);
265
266 $output = '';
267 ob_start(); ?>
268 <link href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800%7CShadows+Into+Light" rel="stylesheet" type="text/css">
269 <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
270 <?php
271 wp_enqueue_script('vpfy-playlist-min');
272 wp_enqueue_script('vpfy-playlist-video');
273 wp_enqueue_style('vpfy-vplay-galcss');
274 wp_enqueue_style('vpfy-playlist-ryt-no-thumb');
275 wp_enqueue_style('vpfy-playlist-ryt-thumb');
276 wp_enqueue_style('vpfy-playlist-ryt-ttl-only');
277
278 if(!empty($arry_arg['id'])){
279 $ytube_custmgrp = get_post_meta($arry_arg['id'], 'customdata_group', true);
280
281 echo '<div id="gallery'.$arry_arg['id'].'" style="margin:0px auto;display:none;">';
282 foreach ($ytube_custmgrp as $ykey => $ytubvalue) {
283 $ytuburl = parse_url($ytubvalue['YoutubeUr']);
284
285 $existance = 0;
286 foreach ($ytuburl as $utkey => $utvalue) {
287 if('query' == $utkey){
288 $existance = 1;
289 }
290 else{
291 $existance = 0;
292 }
293 }
294
295 if($existance == 1){
296 $ytubid = explode('v=', $ytuburl['query']);
297 $ytubid = explode('&', $ytubid[1]);
298 if(strlen($ytubvalue['TitleItem']) > 25){
299 $ytvidTitle = substr($ytubvalue['TitleItem'], 0, 25)."...";
300 }
301 else{
302 $ytvidTitle = $ytubvalue['TitleItem'];
303 }
304 ?>
305 <div data-type="youtube"
306 data-title="<?php echo $ytvidTitle; ?>"
307 data-description="<?php echo substr($ytubvalue['TitleDescription'], 0, 80); ?>"
308 data-thumb="https://i.ytimg.com/vi/<?php echo $ytubid[0]; ?>/mqdefault.jpg"
309 data-image="https://i.ytimg.com/vi/<?php echo $ytubid[0]; ?>/sddefault.jpg"
310 data-videoid="<?php echo $ytubid[0]; ?>" ></div>
311 <?php }
312 elseif($existance == 0){ ?>
313 <div data-type="youtube"
314 data-title="<?php echo $ytubvalue['TitleItem']; ?>"
315 data-description="<?php echo substr($ytubvalue['TitleDescription'], 0, 80); ?>"
316 data-thumb="https://i.ytimg.com/vi/123/mqdefault.jpg"
317 data-image="https://i.ytimg.com/vi/123/sddefault.jpg"
318 data-videoid="123" ></div>
319 <?php }
320
321 }
322 echo '</div>';
323
324 if( null!== get_post_meta( $arry_arg['id'], '_utubeSliderRange', true )){
325 $sliderRange = get_post_meta($arry_arg['id'], '_utubeSliderRange', true);
326 }
327 $sliderWidth = !empty($sliderRange) ? $sliderRange[0] : '1100';
328 $sliderHeight = !empty($sliderRange) ? $sliderRange[1] : '450';
329 if (!empty(get_option('vpfy_vid_autoply')) && get_option('vpfy_vid_autoply') == 1){
330 $autoply = 'true';
331 }
332 else{
333 $autoply = 'false';
334 }
335 ?>
336 <script>
337 jQuery(document).ready(function() {
338 jQuery("#gallery<?php echo $arry_arg['id']; ?>").unitegallery({
339 gallery_theme: "video",
340 gallery_width: <?php echo $sliderWidth; ?>,
341 gallery_height: <?php echo $sliderHeight; ?>,
342 theme_autoplay: <?php echo $autoply; ?>,
343 });
344 });
345 </script>
346 <?php
347 }
348 ?>
349
350 <?php $output = ob_get_clean();
351 return $output;
352 }
353
354
355 // Add the custom columns to the youtube playlist post type:
356 add_filter( 'manage_vid_playlist_ytub_posts_columns', 'set_custom_vpfy_shortcode_columns' );
357 function set_custom_vpfy_shortcode_columns($columns) {
358 $columns['vpfy_col_shortcode'] = __( 'Shortcode', 'video-playlist-for-youtube' );
359 return $columns;
360 }
361
362 // Add the data to the custom columns for the youtube playlist post type:
363 add_action( 'manage_vid_playlist_ytub_posts_custom_column' , 'vpfy_custom_vidyou_column', 10, 2 );
364 function vpfy_custom_vidyou_column( $column, $post_id ) {
365 switch ( $column ) {
366
367 case 'vpfy_col_shortcode' :
368 echo "[videoPlaylist id=".$post_id."]";
369 break;
370 }
371 }
372
373
374 /*Plugin settings */
375 function vpfy_vplaylist_slider_settings(){
376 if( null!== get_post_meta( get_the_ID(), '_utubeSliderRange', true )){
377 $sliderRange = get_post_meta(get_the_ID(), '_utubeSliderRange', true);
378 }
379 $sliderWidth = !empty($sliderRange) ? $sliderRange[0] : '1100';
380 $sliderHeight = !empty($sliderRange) ? $sliderRange[1] : '450';
381 ?>
382 <div class="ytube-slide-container">
383 <!-- slider width -->
384 <p><strong><?php _e('Slider Width: ', 'video-playlist-for-youtube');?></strong><span id="ytube_slide_wdth"></span>px</p>
385 <input type="range" name="utubeSliderRange[]" min="320" max="2200" value="<?php echo $sliderWidth; ?>" class="ytube-plyslider" id="vpfu_plyst_width">
386
387 <!-- slider height -->
388 <p><strong><?php _e('Slider Height: ', 'video-playlist-for-youtube');?></strong><span id="ytube_slide_height"></span>px</p>
389 <input type="range" name="utubeSliderRange[]" min="165" max="900" value="<?php echo $sliderHeight; ?>" class="ytube-plyslider" id="vpfu_plyst_height">
390 </div>
391 <?php }
392
393 /*Ajax response for video duration*/
394 function vpfytGetYoutubeDuration() {
395 $vid = $_POST['ytvideo_id'];
396 $get_Gapi_key = get_option('vpfy_reg_ytubapi_key');
397 $response = wp_remote_get("https://www.googleapis.com/youtube/v3/videos?id=".$vid."&part=contentDetails,statistics&key=".$get_Gapi_key[0]);
398
399 if ( is_array( $response ) && ! is_wp_error( $response ) ) {
400 $videoDetails = $response['body']; // use the content
401 $videoDetails =json_decode($videoDetails, true);
402 $responsearry = array();
403 foreach ($videoDetails['items'] as $vidTime)
404 {
405 $youtube_time = $vidTime['contentDetails']['duration'];
406 preg_match_all('!\d+!',$youtube_time,$parts);
407 if(count($parts[0]) == 3){
408 $ythours = $parts[0][0];
409 $ytminuts = $parts[0][1];
410 $ytsecond = $parts[0][2];
411 $responsearry = array('ythours'=>$ythours,'ytminuts'=>$ytminuts,'ytsecond'=>$ytsecond);
412 wp_send_json_success($responsearry);
413 }
414 if(count($parts[0]) == 2){
415 $ythours = '00';
416 $ytminuts = $parts[0][0];
417 $ytsecond = $parts[0][1];
418 $responsearry = array('ythours'=>$ythours,'ytminuts'=>$ytminuts,'ytsecond'=>$ytsecond);
419 wp_send_json_success($responsearry);
420 }
421 if(count($parts[0]) == 1){
422 $ythours = '00';
423 $ytminuts = '00';
424 $ytsecond = $parts[0][0];
425 $responsearry = array('ythours'=>$ythours,'ytminuts'=>$ytminuts,'ytsecond'=>$ytsecond);
426 wp_send_json_success($responsearry);
427 }
428 else{
429 $ythours = '00';
430 $ytminuts = '00';
431 $ytsecond = '00';
432 $responsearry = array('ythours'=>$ythours,'ytminuts'=>$ytminuts,'ytsecond'=>$ytsecond);
433 wp_send_json_success($responsearry);
434 }
435
436 }
437 }
438 }
439
440 /*Create global ajax varialble*/
441 add_action("wp_ajax_vpfytGetYoutubeDuration", "vpfytGetYoutubeDuration");
442 add_action("wp_ajax_nopriv_vpfytGetYoutubeDuration", "vpfytGetYoutubeDuration");
443