PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.0.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.0.1
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / admin / class-wpstream-admin.php

class-wpstream-admin.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.0.1, at admin/class-wpstream-admin.php

1,735 lines 83.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link http://wpstream.net
7 * @since 3.0.1
8 *
9 * @package Wpstream
10 * @subpackage Wpstream/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Wpstream
20 * @subpackage Wpstream/admin
21 * @author wpstream <office@wpstream.net>
22 */
23 class Wpstream_Admin {
24
25
26 /**
27 * Store plugin main class to allow public access.
28 *
29 * @since 20180622
30 * @var object The main class.
31 */
32 public $main;
33
34
35 /**
36 * The ID of this plugin.
37 *
38 * @since 3.0.1
39 * @access private
40 * @var string $plugin_name The ID of this plugin.
41 */
42 private $plugin_name;
43
44 /**
45 * The version of this plugin.
46 *
47 * @since 3.0.1
48 * @access private
49 * @var string $version The current version of this plugin.
50 */
51 private $version;
52
53 /**
54 * Initialize the class and set its properties.
55 *
56 * @since 3.0.1
57 * @param string $plugin_name The name of this plugin.
58 * @param string $version The version of this plugin.
59 */
60
61 public $global_event_options ;
62
63
64
65
66
67 public function __construct( $plugin_name, $version,$plugin_main ) {
68
69 $this->plugin_name = $plugin_name;
70 $this->version = $version;
71 $this->main = $plugin_main;
72
73 $this->global_event_options = array(
74
75 'record' =>array(
76 'name' => esc_html__('Record Live Stream','wpstream'),
77 'details' => esc_html__('If enabled, live streams will be recorded and saved to your library.','wpstream'),
78 'defaults' => 'no',
79
80 ),
81 'view_count' =>array(
82 'name' => esc_html__('Display Viewer Count','wpstream'),
83 'details' => esc_html__('If enabled, the live viewer count will show up in the player.','wpstream'),
84 'defaults' => 'yes',
85 ),
86 'domain_lock'=>array(
87 'name' => esc_html__('Lock To Website','wpstream'),
88 'details' => sprintf ( esc_html__('If enabled, live video will only display on %1$s, otherwise it can show up on any website.','wpstream'),home_url() ),
89 'defaults' => 'yes',
90 ),
91 'autoplay' =>array(
92 'name' => esc_html__('Autoplay','wpstream'),
93 'details' => esc_html__('If enabled, live video will attempt to start playing automatically. This is only achievable in some browsers.','wpstream'),
94 'defaults' => 'yes',
95 ),
96 'mute' =>array(
97 'name' => esc_html__('Start Muted','wpstream'),
98 'details' => esc_html__('If enabled, live video will start muted. This may increase the rate of autoplay in some browsers. ','wpstream'),
99 'defaults' => 'no',
100
101 ),
102
103 'encrypt' =>array(
104 'name' => esc_html__('Encrypt Live Stream','wpstream'),
105 'details' => esc_html__('If enabled, video data will be encrypted. Enabling encryption may lead to reduced website performance under certain configurations. Encrypted video may not display in all browsers.','wpstream'),
106 'defaults' => 'no',
107 ),
108 'ses_encrypt'=>array(
109 'name' => esc_html__('Use Sessions with Encryption','wpstream'),
110 'details' => esc_html__('If enabled, encryption key distribution will be checked against valid user sessions. Setting may malfunction or lead to reduced website performance under certain configurations. ','wpstream'),
111 'defaults' => 'no',
112 ),
113 );
114
115 }
116
117 /**
118 * Register the stylesheets for the admin area.
119 *
120 * @since 3.0.1
121 */
122 public function enqueue_styles() {
123
124 /**
125 * This function is provided for demonstration purposes only.
126 *
127 * An instance of this class should be passed to the run() function
128 * defined in Wpstream_Loader as all of the hooks are defined
129 * in that particular class.
130 *
131 * The Wpstream_Loader will then create the relationship
132 * between the defined hooks and the functions defined in this
133 * class.
134 */
135 wp_enqueue_style( 'wpstream-roboto', "https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700,900&display=swap&subset=latin-ext" );
136 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpstream-admin.css', array(), WPSTREAM_PLUGIN_VERSION, 'all' );
137
138 }
139
140 /**
141 * Register the JavaScript for the admin area.
142 *
143 * @since 3.0.1
144 */
145 public function enqueue_scripts() {
146
147 wp_enqueue_script("jquery-ui-slider");
148 wp_enqueue_script("jquery-ui-datepicker");
149 wp_enqueue_script('jquery.fileupload', plugin_dir_url( __FILE__ ) .'js/jquery.fileupload.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
150 wp_enqueue_script('wpstream-admin-control', plugin_dir_url( __FILE__ ) .'js/admin_control.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
151 wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
152 array(
153 'admin_url' => get_admin_url(),
154 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
155 'download_mess' => esc_html__('Click to download!','wpstream'),
156 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
157 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
158 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
159 'upload_complete' => esc_html('Upload Complete!','wpstream'),
160 'no_band' => esc_html('Not enough streaming data.','wpsteam'),
161 'no_band_no_store' => esc_html('Not enough streaming data or storage.','wpsteam')
162
163 ));
164
165
166
167 wp_enqueue_script('wpstream-start-streaming_admin', plugin_dir_url( __DIR__ ) .'/public/js/start_streaming.js?v='.time(),array(), WPSTREAM_PLUGIN_VERSION, true);
168 wp_localize_script('wpstream-start-streaming_admin', 'wpstream_start_streaming_vars',
169 array(
170 'admin_url' => get_admin_url(),
171 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
172 'download_mess' => esc_html__('Click to download!','wpstream'),
173 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
174 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
175 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
176 'upload_complete' => esc_html('Upload Complete!','wpstream'),
177 'no_band' => esc_html('Not enough streaming data.','wpsteam'),
178 'no_band_no_store' => esc_html('Not enough streaming data or storage.','wpsteam')
179
180 ));
181
182 }
183
184
185 /**
186 * Add Plugin Administation menu
187 *
188 * @since 3.0.1
189 */
190
191 public function wpstream_manage_admin_menu() {
192
193 add_menu_page( __('WpStream','wpestream'), __('WpStream ','wpstream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
194 add_submenu_page( 'wpstream_plugin_options', __('WpStream Credentials','wpestream'), __('Credentials','wpestream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
195 add_submenu_page( 'wpstream_plugin_options', __('WpStream Channels','wpestream'), __('Channels','wpestream'), 'administrator', 'wpstream_new_general_set', array( $this,'wpstream_new_general_set'));
196 add_submenu_page( 'wpstream_plugin_options', __('WpStream Media Management','wpestream'), __('Media Management','wpestream'), 'administrator', 'wpstream_media_management', array($this,'wpstream_media_management'));
197 add_submenu_page( 'wpstream_plugin_options', __('WpStream Settings','wpestream'), __('Settings','wpestream'), 'administrator', 'wpstream_settings', array($this,'wpstream_settings'));
198
199 }
200
201
202
203 /**
204 * Shows events wpstream
205 *
206 * @since 3.0.1
207 */
208
209 public function wpstream_new_general_set() {
210
211 $no_channel=1;
212
213 if(class_exists ('WC_Subscription')){
214
215 }
216
217 //event_passed
218 $args = array(
219 'posts_per_page' => -1,
220 'post_type' => 'product',
221 'post_status' => 'publish',
222 'meta_query' => array(
223 array(
224 'key' => 'event_passed',
225 'value' => 1,
226 'compare' => '!=',
227 )
228 ),
229
230 'tax_query' => array(
231 'relation' => 'AND',
232 array(
233 'taxonomy' => 'product_type',
234 'field' => 'slug',
235 'terms' => array('live_stream','subscription')
236 )
237 ),
238 );
239
240
241
242 $event_list = new WP_Query($args);
243 global $live_event_for_user;
244 $live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
245 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
246
247 $this->main->show_user_data($pack_details);
248 if( $event_list->have_posts()){
249
250
251 print '<div class="pack_details_wrapper_transparent">
252 <h3>'.__('Your Pay-Per-View Channel List','wpstream').'</h3>';
253
254
255 $link_new = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
256
257 print '<a href="'.esc_url($link_new).'" class="wpstream_create_new_product_link">'.esc_html__('Create new pay-per-view channel.','wpstream').'</a>';
258 print '</div>';
259
260 print '<div style="clear: both;"></div><div class="event_list_wrapper">';
261
262 while ($event_list->have_posts()): $event_list->the_post();
263
264 $the_id = get_the_ID();
265 $is_subscription_live_event = esc_html(get_post_meta($the_id,'_subscript_live_event',true));
266 $term_list = wp_get_post_terms($the_id, 'product_type');
267
268 if( $term_list[0]->name=='subscription' && $is_subscription_live_event=='no'){
269 continue;
270 }
271
272 $this->wpstream_live_stream_unit($the_id);
273
274 endwhile;
275
276 print'</div>';
277 $no_channel=1;
278 }else{
279 $no_channel=0;
280 }
281
282
283 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
284 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
285 $current_user = wp_get_current_user();
286 $allowded_html = array();
287 $userID = $current_user->ID;
288 $user_live_streams = get_user_meta($userID,'live_shows');
289
290
291 wp_reset_postdata();
292
293
294
295
296 // free
297
298 $args_free = array(
299 'posts_per_page' => -1,
300 'post_type' => 'wpstream_product',
301 'post_status' => 'publish',
302 'meta_query' => array(
303 'relation' => 'AND',
304 array(
305 'key' => 'wpstream_product_type',
306 'value' => 1,
307 'compare' => '==',
308 ),
309
310 ),
311
312
313 );
314 $event_list_free = new WP_Query($args_free);
315
316
317 if( $event_list_free->have_posts()){
318 print '<div class="pack_details_wrapper_transparent">
319 <h3>'.__('Your Free Channel List','wpstream').'</h3>';
320
321 $link_new = admin_url('post-new.php?post_type=wpstream_product');
322 print '<a href="'.esc_url($link_new).'" class="wpstream_create_new_product_link">'.esc_html__('Create new free channel.','wpstream').'</a>';
323 print '</div>';
324 print '<div style="clear: both;"></div><div class="event_list_wrapper">';
325
326 while ($event_list_free->have_posts()): $event_list_free->the_post();
327
328
329 $the_id = get_the_ID();
330
331 if( get_post_meta ($the_id,'event_passed',true)!=1){
332 $this->wpstream_live_stream_unit($the_id);
333 }
334
335 endwhile;
336
337 print'</div>';
338 $no_channel=1;
339 }else{
340 $no_channel=0;
341 }
342
343
344
345
346 $link_new_paid = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
347 $link_new_free = admin_url('post-new.php?post_type=wpstream_product');
348 print '<div class="no_events_warning"> ';
349 if($event_list->found_posts==0){
350 print '<div class="no_events_warning_mes">'.__('* You don\'t have any paid channels!','wpstream').'</div>';
351 }
352 if($event_list_free->found_posts==0){
353 print '<div class="no_events_warning_mes">'. __('* You don\'t have any free channels!','wpstream').'</div>';
354 }
355
356 print '<a href="'.esc_url($link_new_free).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Add new free channel ','wpstream').'</a>';
357 print '<a href="'.esc_url($link_new_paid).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Add new pay-per-view channel ','wpstream').'</a>';
358
359 print '</div>';
360
361
362
363
364 }
365 // end wpstream_new_general_set
366
367
368 /**
369 * Social share
370 *
371 * @since 3.0.1
372 */
373
374 public function wpstream_social_share($the_id){
375 $protocol = is_ssl() ? 'https' : 'http';
376 $pinterest = wp_get_attachment_image_src(get_post_thumbnail_id($the_id), 'full');
377 $link = esc_url ( get_permalink($the_id) );
378 $title = get_the_title($the_id);
379 $twiter_status = urlencode( $title.' '.$link);
380 $email_link = 'subject='.urlencode ( $title ) .'&body='. urlencode( esc_url($link));
381
382 print '<div class="wpstream_social_share_wrapper">';
383 print 'Share on: ';?>
384
385 <a href="<?php print esc_html($protocol);?>://www.facebook.com/sharer.php?u=<?php echo esc_url($link); ?>&amp;t=<?php echo urlencode(get_the_title()); ?>" target="_blank" class="social_facebook wpstream_sharing_social">
386 <span class="dashicons dashicons-facebook-alt"></span>
387 </a>
388
389 <a href="<?php print esc_html($protocol);?>://twitter.com/intent/tweet?text=<?php echo esc_html($twiter_status); ?>" class="social_tweet wpstream_sharing_social" target="_blank">
390 <span class="dashicons dashicons-twitter"></span>
391 </a>
392
393 <a href="<?php print esc_html($protocol);?>://pinterest.com/pin/create/button/?url=<?php echo esc_url($link); ?>&amp;media=<?php if (isset( $pinterest[0])){ echo esc_url($pinterest[0]); }?>&amp;description=<?php echo urlencode(get_the_title()); ?>" target="_blank" class="social_pinterest wpstream_sharing_social">
394 <span class="dashicons dashicons-pinterest"></span>
395 </a>
396
397 <a href="<?php print esc_html($protocol);?>://api.whatsapp.com/send?text=<?php echo urlencode( get_the_title().' '. esc_url( $link )); ?>" class="social_whatsup wpstream_sharing_social" target="_blank">
398 <span class="dashicons dashicons-whatsapp"></span>
399 </a>
400
401 <a href="<?php print esc_html($protocol);?>://www.linkedin.com/sharing/share-offsite/?url=<?php echo urlencode(esc_url($link)); ?>" class="social_linkedin wpstream_sharing_social" target="_blank">
402 <span class="dashicons dashicons-linkedin"></span>
403 </a>
404
405 <a href="mailto:email@email.com?<?php echo trim(esc_html($email_link));?>" data-action="share email" class="social_email wpstream_sharing_social">
406 <span class="dashicons dashicons-email-alt"></span>
407 </a>
408
409 <?php
410
411 print '</div>';
412 }
413
414
415
416
417 /**
418 * Shows event unit card in admin
419 *
420 * @since 3.0.1
421 */
422 public function wpstream_live_stream_unit($the_id,$is_front=''){
423 global $live_event_for_user;
424
425 $current_user = wp_get_current_user();
426
427 if(!current_user_can('administrator')){
428 if($is_front=='' ){
429 print '<div class="event_list_unit">';
430 esc_html_e('You are not allowed to broadcast.','wpstream');
431 print '</div>';
432 return;
433 }
434
435 }
436
437 if( !$this->main->wpstream_check_user_can_stream() ){
438 print '<div class="event_list_unit">';
439 esc_html_e('You are not allowed to broadcast','wpstream');
440 print '</div>';
441 return;
442
443 }
444
445
446 $live_class='';
447 if(isset($live_event_for_user[$the_id])) {
448 $live_class=" wpstream_show_started";
449 }
450
451
452 print '<div class="event_list_unit '.$live_class.' event_unit_style_'.esc_attr($is_front).'">';
453 if(has_post_thumbnail($the_id)){
454 $thumb = get_the_post_thumbnail_url($the_id,'thumbnail');
455 }else{
456 $thumb= plugin_dir_url( dirname( __FILE__ ) ). 'img/default_150.png';
457 }
458
459 global $wpstream_plugin;
460
461
462
463 print '<div class="event_thumb_wrapper"><img class="event_thumb" src="'.$thumb.'" alt="show_imagge"></div>';
464 print '<div class="event_title" data-prodid="'.$the_id.'">'.get_the_title($the_id).' - '.esc_html__('Id','wpstream').': '.$the_id;
465 print '<a class="view_channel" href="'.get_permalink($the_id).'" target="_blank">'.esc_html__('View Channel','wprentals').'</a> ';
466 $this->wpstream_social_share($the_id);
467 print '</div>';
468
469
470 $live_event_stream_name = get_post_meta($the_id,'live_event_stream_name',true);
471 $live_event_array = get_post_meta($the_id,'live_event_uri',true);
472 $live_event_uri = '';
473
474
475 $pending_streaming_class = '';
476 $wpstream_ready_to_stream_class = '';
477 $external_software_streaming_class = '';
478 $wpstream_no_stream_class = '';
479 $carnat_key1 = '';
480 $carnat_key2 = '';
481 $uri = '';
482 $webcaster_url = '';
483 $rtmp_ip_uri = '';
484 $uri_ip = '';
485 $server_id = '';
486 $obs_uri = '';
487 $obs_stream = '';
488
489
490 if( $live_event_for_user=='' && $is_front=='front' ){
491 $live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
492 }
493
494
495
496 $live_data_url='';
497 if(is_array($live_event_for_user) && isset($live_event_for_user[$the_id])) {
498
499 $pending_streaming_class = 'show_stream_data pending_trigger';
500 $wpstream_ready_to_stream_class = 'hide_stream_data';
501 $external_software_streaming_class = 'show_stream_data';
502 $wpstream_no_stream_class = 'hide_stream_data';
503 if(isset($live_event_for_user[$the_id]['live_uri'])){
504 $explode = explode('wpstream.net/', $live_event_for_user[$the_id]['live_uri']);
505 $uri = $explode[0].'wpstream.net/wpstream/';
506 $stream_name = get_post_meta($the_id,'live_event_stream_name',true);
507 $carnat_key1 = $live_event_for_user[$the_id]['carnat1'];
508 $carnat_key2 = $live_event_for_user[$the_id]['carnat2'];
509 $webcaster_url = 'https://'.$live_event_for_user[$the_id]['subdomain_key'].'.live.streamer.wpstream.net:8443/'.$live_event_for_user[$the_id]['carnat2'];
510
511 $rtmp_ip_uri = 'http://'.$live_event_for_user[$the_id]['ip'].':8444';
512 $uri_ip= 'rtmp://'.$live_event_for_user[$the_id]['ip'].'/wpstream/';
513
514 // starting from 2.0
515 $server_id = get_post_meta($the_id,'server_id',true);
516 $obs_uri = get_post_meta($the_id,'obs_uri',true);
517 $obs_stream = get_post_meta($the_id,'obs_stream',true);
518 $webcaster_url= get_post_meta($the_id,'webcaster_url',true);
519
520 // if local server id diffrens than wpstream server id it means call was made via api and we use wpstream ip
521 if( $server_id != $live_event_for_user[$the_id]['api20_event_id'] && $live_event_for_user[$the_id]['api20_event_id']!='' ){
522
523 $server_id=esc_html($live_event_for_user[$the_id]['api20_event_id']);
524 }
525
526 $live_data_url=get_post_meta($the_id,'qos_url',true);
527 }
528
529 }else{
530
531 $pending_streaming_class = 'hide_stream_data';
532 $wpstream_ready_to_stream_class = 'hide_stream_data';
533 $external_software_streaming_class = 'hide_stream_data';
534 $wpstream_no_stream_class = 'show_stream_data';
535 }
536
537
538
539
540 print' <div class="pending_streaming '.$pending_streaming_class.' " data-show-id="'.$the_id.'" data-server-id="'.$server_id.'" data-server-url="'.$rtmp_ip_uri.'">';
541 print'<div class="wpstream_channel_status not_ready_to_stream"><span class="dashicons dashicons-dismiss"></span>'.esc_html__('Your Event is starting. Please wait...','wprentals').' ';
542 print '<img class="server_loading_new" src="'.plugin_dir_url( dirname( __FILE__ ) ).'img/loading.gif" alt="loading" /></div>';
543 print '<div class="multiple_warning_events"> '.esc_html__('To go Live on a Channel, you need to start an Event. It will stop automatically after an hour of inactivity.','wpstream').'</div>';
544 print '</div>';
545
546
547 print '<div class="wpstream_ready_to_stream '.$wpstream_ready_to_stream_class.'">';
548 print '<div class="wpstream_channel_status"><span class="dashicons dashicons-yes"></span>'.esc_html__('Ready to Go Live !','wpstream').'</div>';
549 print '<div class="start_webcaster wpstream_button" data-webcaster-url="'.$webcaster_url.'" >'.esc_html__('Go Live from Browser','wpstream').'</div>';
550 print '<div class="start_external wpstream_button" >'.esc_html__('Go Live with External Broadcaster','wpstream').'</div>';
551 print '<a href="'.esc_url($live_data_url).'" class="wpstream_live_data wpstream_button" target="_blank">'.esc_html__('Live Metrics','wpstream').'</a>';
552 print '<div class="stop_server wpstream_button" data-show-id="'.$the_id.'">'.esc_html__('Turn Off Channel','wpstream').'</div>';
553 $ajax_nonce_stop = wp_create_nonce( "wpstream_stop_event_nonce" );
554 print '<input type="hidden" id="wpstream_stop_event_nonce" value="'.$ajax_nonce_stop.'">';
555 print '</div>';
556
557
558
559 print '<div class="external_software_streaming '. $external_software_streaming_class.' ">';
560 print '<div class="event_list_unit_notificationx"><strong>'.__('Server:').' </strong> <div class="wpstream_live_uri_text">' . $obs_uri.'</div><div class="copy_live_uri">'.__('copy to clipboard','wpstream').'</div>';
561 print '<div class="event_list_stream_key_wrap"><strong>'.__('Stream Key:').' </strong><div class="wpstream_live_key_text">'. $obs_stream.'</div><div class="copy_live_key">'.__('copy to clipboard','wpstream').'</div></div>';
562 print '<div class="warning_stream">'.
563 sprintf(esc_html__('Use %s on your Windows or Mac computer, or the Larix Broadcaster app on your %s or %s smartphone/tablet. Various other Apps and devices are compatible. See %s for more details.','wpstream'),'<a href="https://obsproject.com/download" target="_blank">OBS Studio</a>','<a href="https://apps.apple.com/us/app/larix-broadcaster/id1042474385" target="_blank"> iOS</a>','<a href="https://play.google.com/store/apps/details?id=com.wmspanel.larix_broadcaster&hl=en" target="_blank">Android</a>','<a href="https://wpstream.net/external-broadcasters/" target="_blank">this page</a>').'</div>';
564 print ' <img class="how_to" src="'.plugin_dir_url( dirname( __FILE__ ) ).'img/how_to_obs.jpg" alt="show_imagge">';
565 print'</div>';
566 print'</div>';
567
568
569
570
571 print '<div class="wpstream_no_stream '.$wpstream_no_stream_class.' ">';
572 print '<div class="event_list_unit_notificationx"><span class="server_notification">'.__('Broadcast Offline.','wpestream').' <img class="server_loading" src="'.plugins_url().'/wpstream/img/loading.gif" alt="loading" /></span></div>';
573
574 print '<input class="start_event wpstream_button" type="button" data-show-id="'.$the_id.'" value="'.esc_html__('Start Live Event','wpstream').'">';
575
576 if($is_front==''){
577 // print '<input class="close_event wpstream_button" type="button" data-show-id="'.$the_id.'" value="'.esc_html__('Delete Channel','wpstream').'">';
578 print '<input class="wpstream_show_settings wpstream_button" type="button" data-show-id="'.$the_id.'" value="'.esc_html__('Settings','wpstream').'">';
579 }
580
581 print '<div class="multiple_warning_events"> '.esc_html__('To go Live on a Channel, you need to start an Event. It will stop automatically after an hour of inactivity.','wpstream').'</div>';
582
583
584
585
586 if($is_front==''){
587
588 $local_event_options = get_post_meta($the_id,'local_event_options',true);
589
590 if(!is_array($local_event_options)){
591 $local_event_options = get_option('wpstream_user_streaming_global_channel_options') ;
592 }
593
594
595 print '<div class="wpstream_event_streaming_local">';
596
597 $this->user_streaming_global_channel_options('',$local_event_options,'ses_encrypt');
598 print '</div>';
599
600
601
602 print '<div class="wpstream_social_media_broadcast">';
603
604 print '<div class="wpstream_social_media_unit"><input type="checkbox" class="wpstream_on_facebook" id="wpstream_on_facebook'.$the_id.'"><label for="wpstream_on_facebook'.$the_id.'">'.esc_html__('Stream on Facebook','wpstream').'</label>';
605 print '</div>';
606
607 print '<div class="wpstream_social_media_unit"><input type="checkbox" class="wpstream_on_youtube" id="wpstream_on_youtube'.$the_id.'"><label for="wpstream_on_youtube'.$the_id.'">'.esc_html__('Stream on Youtube','wpstream').'</label>';
608 print '</div>';
609
610
611 print '<div class="wpstream_social_media_unit"><input type="checkbox" class="wpstream_on_twich" id="wpstream_on_twich'.$the_id.'"><label for="wpstream_on_twich'.$the_id.'">'.esc_html__('Stream on Twich','wpstream').'</label>';
612 print '</div>';
613
614 print '<div class="wpstream_on_facebook_container wpstream_social_stream_container">';
615 print 'Some Facebook Settings for event '.$the_id;
616 print '</div>';
617
618 print '<div class="wpstream_on_youtube_container wpstream_social_stream_container">';
619 print '<label for="wpstream_youtube_rtmp'.$the_id.'">'.esc_html__('Youtube RTMP','wpstream').'</label>';
620 print '<input type="text" class="wpstream_youtube_rtmp" id="wpstream_youtube_rtmp'.$the_id.'" value="'.esc_html(get_post_meta($the_id,'wpstream_youtube_rtmp',true )).'">';
621 print '</div>';
622
623 print '<div class="wpstream_on_twich_container wpstream_social_stream_container">';
624 print '<label for="wpstream_twich_rtmp'.$the_id.'">'.esc_html__('Twich RTMP','wpstream').'</label>';
625 print '<input type="text" class="wpstream_twich_rtmp" id="wpstream_twich_rtmp'.$the_id.'" value="'.esc_html(get_post_meta($the_id,'wpstream_twich_rtmp',true )).'">';
626 print '</div>';
627
628
629 print '</div>';
630 }
631 print '</div>';
632
633
634 print '</div>';
635 }
636
637
638
639 public function wpstream_show_settings_per_event(){
640
641 }
642
643
644
645 /**
646 * Set Settings
647 *
648 *
649 */
650
651 public function wpstream_settings(){
652
653 if($_SERVER['REQUEST_METHOD'] === 'POST'){
654 $allowed_html = array();
655 $exclude_array = array();
656 $allowed_html = array();
657
658
659
660 if( isset($_POST['user_streaming_channel_type_hidden']) && intval($_POST['user_streaming_channel_type_hidden'])==1 && !isset($_POST['stream_role']) ){
661 update_option( sanitize_key('wpstream_stream_role'), '' );
662 }
663
664 foreach($_POST as $variable=>$value){
665 if ($variable!='submit'){
666 if (!in_array($variable, $exclude_array) ){
667 update_option( sanitize_key('wpstream_'.$variable), sanitize_text_field ($value) );
668 }
669
670 if($variable=='stream_role'){
671 update_option( sanitize_key('wpstream_stream_role'), $value );
672 }
673
674 }
675 }
676
677
678 if( isset($_GET['tab']) && $_GET['tab']=='default_options' ){
679 $event_settings=array();
680 foreach($this->global_event_options as $key=>$option){
681 $event_settings[$key]='';
682 if(isset($_POST['wpstream_event_set_'.$key]) && $_POST['wpstream_event_set_'.$key]=='on'){
683 $event_settings[$key]=1;
684 }else{
685 $event_settings[$key]=0;
686 }
687 }
688 update_option('wpstream_user_streaming_global_channel_options',$event_settings);
689 }
690
691
692
693
694 // reset permalinkgs
695 global $wp_rewrite;
696
697 update_option( "rewrite_rules", FALSE );
698 $wp_rewrite->flush_rules( true );
699
700 }
701
702 $wpstream_settings_array =array(
703 1 => array(
704 'tab' => 'general_options',
705 'label' => esc_html__('Slug for free video/channel pages ','wpstream'),
706 'name' => 'free_media_slug',
707 'type' => 'text',
708 'details' => esc_html__('This will replace the default "wpstream" of all your free video/channel urls. Special characters like "&" are not permitted. To have your new slug show up you need to re-save the "Permalinks Settings" under Settings -> Permalinks, even if not making any changes.','wpstream'),
709 ),
710
711 2 => array(
712 'tab' => 'general_options',
713 'label' => esc_html__('Non-Admin User Roles Allowed to Broadcast','wpstream'),
714 'name' => 'stream_role',
715 'type' => 'user_roles',
716 'details' => esc_html__('These types of users can stream via frontend shortcodes / blocks. Single individual channels are automaticlally created for streaming by non-admins.','wpstream'),
717
718 ),
719 3 => array(
720 'tab' => 'general_options',
721 'label' => esc_html__('Non Admin Streamers Channel Type.','wpstream'),
722 'name' => 'user_streaming_channel_type',
723 'type' => 'select',
724 'select_values'=>array(
725 'free' => esc_html__('Free Live Channel','wpstream'),
726 'paid' => esc_html__('Pay-Per-View','wpstream')
727 ),
728 'details' => esc_html__('Choose whether the channels assigned to non-admins are free-for-all or pay-per-view (WooCommerce product).','wpstream'),
729 ),
730
731 4 => array(
732 'tab' => 'general_options',
733 'label' => esc_html__('Default Pay-Per-View Price','wpstream'),
734 'name' => 'user_streaming_default_price',
735 'type' => 'text',
736 'details' => esc_html__('Default price of pay-per-view channels assigned to non-admins.','wpstream'),
737 ),
738
739
740
741 6 => array(
742 'tab' => 'subscription_options',
743 'label' => esc_html__('Use Global Subscription Mode','wpstream'),
744 'name' => 'global_sub',
745 'type' => 'slidertoogle',
746 'details' => esc_html__('If enabled, a client can access all the media products (live and VOD) by purchasing a single subscription. The "WooCommerce Subscriptions" plugin is required.','wpstream'),
747 ),
748
749 7 => array(
750 'tab' => 'subscription_options',
751 'label' => esc_html__('Subscription ID for Global Subscription Mode','wpstream'),
752 'name' => 'global_sub_id',
753 'type' => 'text',
754 'details' => esc_html__('ID of the subscription product to be purchased for global access to media. All non-subscription video products that are not already attached to a subscription will be accessible to users that have purchased it.','wpstream'),
755 ),
756 8 => array(
757 'tab' => 'messages_options',
758 'label' => esc_html__('PPV not logged in message','wpstream'),
759 'name' => 'product_not_login',
760 'type' => 'text',
761 'details' => esc_html__('This message will be displayed on top of the media player for pay-per-view items when user is not logged in.','wpstream'),
762 'default' => esc_html__('You must be logged in to watch this video.','wpstream'),
763 ),
764 9 => array(
765 'tab' => 'messages_options',
766 'label' => esc_html__('PPV not purchased message','wpstream'),
767 'name' => 'product_not_bought',
768 'type' => 'text',
769 'details' => esc_html__('This message will be displayed on top of the media player for common pay-per-view items that have not been purchased.','wpstream'),
770 'default' => esc_html__('You did not yet purchase this item.','wpstream'),
771 ),
772 10 => array(
773 'tab' => 'messages_options',
774 'label' => esc_html__('Subscription not purchased message','wpstream'),
775 'name' => 'product_not_subscribe',
776 'type' => 'text',
777 'details' => esc_html__('This message will be displayed on top of the media player for subscription-type pay-per-view items that have not been purchased.','wpstream'),
778 'default' => esc_html__(' You did not yet subscribe to this item.','wpstream'),
779 ),
780 11 => array(
781 'tab' => 'messages_options',
782 'label' => esc_html__('Thank you message','wpstream'),
783 'name' => 'product_thankyou',
784 'type' => 'text',
785 'details' => esc_html__('This message will be displayed on the thank you page (after purchase) and the confirmation email.','wpstream'),
786 'default' => esc_html__('Thanks for your purchase. You can access your item at any time by visiting the following page: {item_link}','wpstream'),
787 ),
788
789 12 => array(
790 'tab' => 'messages_options',
791 'label' => esc_html__('Thank you message','wpstream'),
792 'name' => 'subscription_active',
793 'type' => 'text',
794 'details' => esc_html__('This message will be displayed on subscription product page.','wpstream'),
795 'default' => esc_html__('Your Subscription is Active','wpstream'),
796 ),
797
798 99 => array(
799 'tab' => 'default_options',
800 'label' => esc_html__('Events Options ','wpstream'),
801 'name' => 'user_streaming_global_channel_options',
802 'type' => 'user_streaming_global_channel_options',
803 'details' => esc_html__('Global Options for live events.','wpstream'),
804 ),
805 );
806
807 $active_tab = 'general_options';
808 if( isset( $_GET[ 'tab' ] ) ) {
809 $active_tab = $_GET[ 'tab' ];
810 }
811
812
813 print '<div class="theme_options_tab_wpstream" style="display:block;" >
814 <h1>'.__('WpStream Settings','wpstream').'</h1>
815 <form method="post" action="" >';
816
817 print '<h2 class="nav-tab-wrapper">
818 <a href="?page=wpstream_settings&tab=general_options" class="nav-tab '; echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; echo '">General Options</a>
819 <a href="?page=wpstream_settings&tab=default_options" class="nav-tab '; echo $active_tab == 'default_options' ? 'nav-tab-active' : ''; echo '">Default Channel Settings</a>
820 <a href="?page=wpstream_settings&tab=subscription_options" class="nav-tab '; echo $active_tab == 'subscription_options' ? 'nav-tab-active' : ''; echo '">Subscription Options</a>
821 <a href="?page=wpstream_settings&tab=messages_options" class="nav-tab '; echo $active_tab == 'messages_options' ? 'nav-tab-active' : ''; echo '">Customize Messages</a>
822
823 </h2>';
824
825 print '<div class="wpstream_option_wrapper">';
826 foreach ($wpstream_settings_array as $key=>$option){
827 if($option['tab']!=$active_tab){
828 continue;
829 }
830
831 print '<div class="wpstream_option">';
832 $options_value = get_option('wpstream_'.$option['name']) ;
833
834
835 if($option['type']=='user_roles'){
836
837 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
838 print $this->wpstream_select_user_roles($option['name'],$options_value);
839 print '<div class="settings_details">'.$option['details'].'</div>';
840
841 }else if($option['type']=='user_streaming_global_channel_options'){
842
843 // print '<label style="margin:20px 0px;font-size:20px;" >'.esc_html('Default Channel Settings','wpstream').'</label>';
844 $this->user_streaming_global_channel_options($option['name'],$options_value);
845
846
847 }else if($option['type']=='text'){
848
849 if($options_value==''){
850 $options_value='';
851 if(isset($option['default'])){
852 $options_value=$option['default'];
853 }
854 }
855
856 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
857 print '<input id="'.$option['name'].'" type="'.$option['type'].'" size="36" name="'.$option['name'].'" value="'.esc_attr($options_value).'" />';
858 print '<div class="settings_details">'.$option['details'].'</div>';
859
860 } else if($option['type']=='select'){
861
862 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
863 print '<select id="'.$option['name'].'" name="'.$option['name'].'" >';
864 foreach($option['select_values'] as $key=>$value){
865 print '<option value="'.$key.'" ';
866 if( $key == esc_html($options_value) ){
867 print ' selected ';
868 }
869 print '>'.$value.'</option>';
870 }
871 print '</select>';
872 print '<input type="hidden" name="'.$option['name'].'_hidden" value="1" >';
873 print '<div class="settings_details">'.$option['details'].'</div>';
874
875 } else if($option['type']=='slidertoogle'){
876 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
877 print '<label class="wpstream_switch">
878 <input type="hidden" class="wpstream_event_option_itemc" value="0" name="'.$option['name'].'" >
879 <input type="checkbox" class="wpstream_event_option_itemc" value="1" name="'.$option['name'].'" ';
880
881 if( intval($options_value) !==0 ){
882 print ' checked ';
883 }
884
885
886
887 print '> <span class="slider round"></span>';
888 print '</label>';
889 print '<div class="settings_details">'.$option['details'].'</div>';
890 }
891 print '</div>';
892 }
893 print '</div>';
894
895
896 print '<input type="submit" name="submit" class="wpstream_button" value="'.__('Save Changes','wpstream').'" />';
897
898
899 print '</form>';
900 print '</div>';
901
902 }
903
904
905
906 /**
907 * Set user roles
908 *
909 * @since 3.0.1
910 */
911 public function user_streaming_global_channel_options($name,$value,$local=''){
912
913
914
915 foreach($this->global_event_options as $key=>$option){
916
917 if( $local != $key){
918 print '<div class="wpstream_setting_event_unit_wrapper">';
919
920 print '<label for="'.$option['name'].'">'.$option['name'].'</label>';
921
922 print '
923 <label class="wpstream_switch">
924 <input type="checkbox" class="wpstream_event_option_item" data-attr-ajaxname="'.esc_attr($key).'" name="wpstream_event_set_'.esc_attr($key).'" ';
925 if( isset($value[$key]) ){
926 if( intval($value[$key]) !==0 ){
927 print ' checked ';
928 }
929 }else{
930 if($option['defaults']=='yes') {
931 print ' checked ';
932 }
933 }
934
935
936 print '> <span class="slider round"></span>';
937 print '</label>';
938 print '<div class="settings_details">'.$option['details'].'</div>';
939
940
941 print '</div>';
942 }
943 }
944
945
946 }
947
948
949
950 /**
951 * Set user roles
952 *
953 * @since 3.0.1
954 */
955 public function wpstream_select_user_roles($name,$value){
956 if($value==''){
957 $value=array();
958 }
959
960 $roles = get_editable_roles();
961 $return = '<select id="wpstream_user_roles" name="'.esc_html($name).'[]" multiple>';
962 unset( $roles['administrator'] );
963
964 foreach ($roles as $key=>$role){
965 $return .= '<option value="'.$key.'" ';
966 if( in_array($key, $value) ){
967 $return .= ' selected ';
968 }
969 $return .= '>'.$role['name'].'</option>';
970 }
971 $return .= '</select>';
972
973
974 return $return;
975 }
976
977
978 /**
979 * Set credential admin function
980 *
981 * @since 3.0.1
982 */
983 public function wpstream_set_wpstream_credentials(){
984
985 if($_SERVER['REQUEST_METHOD'] === 'POST'){
986 $allowed_html = array();
987 $exclude_array = array();
988 $allowed_html = array();
989
990 foreach($_POST as $variable=>$value){
991 if ($variable!='submit'){
992 if (!in_array($variable, $exclude_array) ){
993 update_option( sanitize_key('wpstream_'.$variable), wp_kses ($value,$allowed_html) );
994 }
995 }
996 }
997
998
999
1000
1001 update_option('wp_estate_token_expire',0);
1002 update_option('wp_estate_curent_token',' ');
1003 delete_transient( 'wpstream_token_request');
1004 delete_transient('wpstream_token_request_30');
1005 delete_transient('wpstream_request_pack_data_per_user_transient');
1006 }
1007
1008
1009 $allowed_html = array();
1010
1011
1012
1013 $wpstream_options_array =array(
1014 2 => array(
1015 'label' => 'WpStream.net Username or Email',
1016 'name' => 'api_username',
1017 'type' => 'text',
1018 ),
1019 3 => array(
1020 'label' => 'WpStream.net Password',
1021 'name' => 'api_password',
1022 'type' => 'password',
1023 ),
1024
1025 );
1026
1027
1028 $token = $this->main->wpstream_live_connection->wpstream_get_token();
1029 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
1030
1031 $this->main->show_user_data($pack_details);
1032
1033 print '<form method="post" action="" >';
1034 print '<div class="theme_options_tab_wpstream" style="display:block;" >
1035 <h1>'.__('WpStream Credentials','wpstream').'</h1>';
1036
1037
1038 if( get_option('wpstream_api_username')=='' || get_option('wpstream_api_password')== ' '){
1039 echo '<div class="api_not_conected wpstream_orange">'.__('To connect your plugin, enter your WpStream credentials below or go <a href="https://wpstream.net/my-account/" target="_blank">here</a> to create an account.','wpstream').'</div>';
1040 }else if($token==''){
1041 echo '<div class="api_not_conected">'.__(' Incorrect username or password. Please check your credentials or go <a href="https://wpstream.net/my-account/edit-account/" target="_blank">here</a> to reset your password.','wpstream').'</div>';
1042 }else if( $this->main->wpstream_live_connection->wpstream_client_check_api_status() ){
1043 echo '<div class="api_conected">'.__('Connected to WpStream.net!','wpstream').'</div>';
1044 }else{
1045 echo '<div class="api_not_conected wpstream_brown">'.__('Failed to connect to WpStream.net. Please address CURL connectivity with your hosting provider.','wpstream').'</div>';
1046 }
1047 print '<div class="wpstream_option_wrapper">';
1048 foreach ($wpstream_options_array as $key=>$option){
1049 print '<div class="wpstream_option">';
1050
1051 $options_value = esc_html( get_option('wpstream_'.$option['name'],'') );
1052 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
1053 print '<input id="'.$option['name'].'" type="'.$option['type'].'" size="36" name="'.$option['name'].'" value="'.esc_html($options_value).'" />';
1054
1055 print '</div>';
1056 }
1057 print '</div>';
1058
1059
1060 print '<input type="submit" name="submit" class="wpstream_button" value="'.__('Save Changes','wpstream').'" />';
1061
1062 print '<h3>Video Tutorials</h3>';
1063
1064 print '<a class="how_to_videos" target="_blank" href="https://youtu.be/9DQrxsKcpmQ">How to Live Stream to WordPress with OBS</a>';
1065 print '<a class="how_to_videos" target="_blank" href="https://youtu.be/qMSjJCskAfM">How to Live Stream to WordPress in less than 3 Minutes</a>';
1066 print '<a class="how_to_videos" target="_blank" href="https://youtu.be/h6myD_vhKcg">How to Live-Stream to WordPress using your iPhone</a>';
1067
1068 print '<a style="margin-top:10px;" href="https://www.youtube.com/channel/UCIjItiJc4Z7aJApj3W6ArJA" target="_blank" class="how_to_videos">More Tutorials On Our YouTube Channel</a>';
1069
1070
1071 print '</div>';
1072 print '</form>';
1073
1074 print '<div class="theme_options_tab_wpstream" style="display:block;" >';
1075 $link_new = admin_url('admin.php?page=wpstream_new_general_set');
1076 $link_new_paid = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
1077 $link_new_free = admin_url('post-new.php?post_type=wpstream_product');
1078
1079
1080 print '<a href="'.esc_url($link_new_free).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Create new free channel','wpstream').'</a>';
1081 print '<a href="'.esc_url($link_new_paid).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Create pay-per-view channel','wpstream').'</a>';
1082 print '<a href="'.esc_url($link_new).'" class="wpstream_no_chanel_add_channel">'.esc_html('My Channels','wpstream').'</a>';
1083 print '</div>';
1084
1085
1086 }
1087
1088
1089
1090 /**
1091 * Media Management
1092 *
1093 * @since 3.0.1
1094 */
1095 public function wpstream_media_management(){
1096 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
1097
1098 $this->main->show_user_data($pack_details);
1099
1100
1101 print '<div id="wpstream_media_upload"><h3>'.__('Media Upload','wpstream').'</h3>'.$this->wpstream_present_media_upload().'</div>';
1102
1103 print '<div id="wpstream_file_management"><h3 id="video_management_title">'.__('Video Management','wpstream').'</h3>'.$this->wpstream_present_file_management().'</div>';
1104
1105 }
1106
1107
1108
1109 /**
1110 * Media upload
1111 *
1112 * @since 3.0.1
1113 */
1114 public function wpstream_present_media_upload(){
1115 $to_return='';
1116 $formInputs=$this->main->wpstream_live_connection->wpstream_get_signed_form_upload_data();
1117
1118 if($formInputs === 'notenough'){
1119 $to_return.='<div class="wpstream_upload_alert">'.esc_html__('You do not have enough streaming data or storage to upload a video!','wpstream').'</div>';
1120 return $to_return;
1121 }
1122
1123
1124 $to_return.='<div class="wpstream_upload_container">';
1125 $to_return.='<div id="wpstream_uploaded_mes">'.esc_html__('Please select or drop a video file. Do not close this window during the upload!','wpstream').'</div>';
1126 $to_return.='<form action="https://wpstream-videos.s3.amazonaws.com/"
1127 method="POST"
1128 enctype="multipart/form-data"
1129 class="direct-upload">';
1130
1131 $to_return.='<input id="wpstream_upload" type="file" class="inputfile inputfile-1" value="Pick a video file" name="file" multiple>';
1132 $to_return.='<label for="wpstream_upload"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> <span id="wpstream_label_action">Choose a file&hellip;</span></label>';
1133
1134
1135 $to_return.='<div class="wpstream_file_drop_color">';
1136 $to_return.='<div class="wpstream_form_ex">'.esc_html__('Drop a video file here!','wpstream').'</div>';
1137 $to_return.='<div class="wpstream_form_ex_details">'.esc_html__('The Video File must be encoded with the following settings:
1138
1139 Container: MP4,
1140 Video codec: H264,
1141 Audio codec: AAC. Media will fail to play back if it does not follow the above settings.
1142 You may use a tool like MediaInfo to verify your file. Also you may convert it with specialized software like HandBrake.','wpstream').'<strong>'.esc_html__('Accepted file extensions: .mp4, .mov .','wpstream').'</strong></div>';
1143 if(is_array($formInputs)){
1144 foreach ($formInputs as $name => $value) {
1145 $to_return.='<input type="hidden" name="'. $name.'" value="'.$value.'">';
1146 }
1147 }
1148
1149 $to_return.='
1150 <div class="progress-bar-area"></div></div>
1151 </form>';
1152
1153 $to_return.='</div>';
1154 return $to_return;
1155
1156 }
1157
1158
1159
1160 /**
1161 * Display movie list
1162 *
1163 * @since 3.0.1
1164 */
1165 public function wpstream_present_file_management(){
1166 $video_list_raw = $this->main->wpstream_live_connection->wpstream_get_videos_from_storage_raw_data();
1167
1168
1169
1170 $to_return='';
1171
1172 if(is_array($video_list_raw)){
1173 foreach ($video_list_raw as $key =>$video){
1174
1175
1176 $video_size = intval($video['size']/1048576);
1177 $to_return.='<div class="wpstream_video_wrapper">';
1178
1179 $to_return.='<div class="wpstream_video_title">';
1180 $to_return.='<div class="wpstream_video_notice"></div></div>';
1181 $to_return.='<div class="wpstream_video_title"><strong class="storage_file_name">'.esc_html__('File Name :','wpstream').'</strong>'.'<span class="storage_file_name_real">'.$video['video_name_storage'].'</span><span class="storage_file_size">'.$video_size.' MB </span></div>';
1182 $to_return.=' <div class="wpstream_delete_media" ';
1183 $to_return.=' onclick="return confirm(\' Are you sure you wish to delete '.$video['video_name_storage'].'?\')" data-filename="'.$video['video_name_storage'].'">'.esc_html__('delete file','wpstream').'</div>';
1184 $to_return.='<div class="wpstream_get_download_link" data-filename="'.$video['video_name_storage'].'">'.esc_html__('get download link','wpstream').'</div>';
1185 $to_return.='<a href="" class="wpstream_download_link">'.esc_html__('Click to download! The url will work for the next 20 minutes!','wpstream').'</a>';
1186
1187 $add_free_video_url=admin_url('post-new.php?post_type=wpstream_product').'&new_video_name='. rawurlencode($video['video_name_storage']);
1188 $add_paid_video_url=admin_url('post-new.php?post_type=product').'&new_video_name='. rawurlencode($video['video_name_storage']);
1189
1190
1191
1192 $to_return .='<a class="create_new_free_video" href="'.esc_url($add_free_video_url).'">'.esc_html__('Create new free VOD from this video').'</a>';
1193 $to_return .='<a class="create_new_ppv_video" href="'.esc_url($add_paid_video_url).'">'.esc_html__('Create pay-per-view VOD from this video').'</a>';
1194
1195 $to_return.='</div>';
1196
1197 }
1198 } else {
1199 $to_return.= '<div class="wpstream_video_wrapper">'.esc_html__('You don\'t have any videos.','wpstream').'</div>';
1200 }
1201 return $to_return;
1202 }
1203
1204
1205
1206
1207
1208 /**
1209 * save meta options
1210 *
1211 * @since 3.0.1
1212 */
1213 public function wpstream_free_product_update_post($post_id,$post){
1214
1215 if(!is_object($post) || !isset($post->post_type)) {
1216 return;
1217 }
1218
1219 if($post->post_type!='wpstream_product'){
1220 return;
1221 }
1222
1223
1224 $allowed_keys=array(
1225 'wpstream_product_type',
1226 'wpstream_free_video',
1227 'wpstream_free_video_external'
1228 );
1229
1230 $allowed_html=array();
1231
1232 foreach ($_POST as $key => $value) {
1233 if( !is_array ($value) ){
1234 if (in_array ($key, $allowed_keys)) {
1235 $postmeta = wp_kses ( $value,$allowed_html );
1236 update_post_meta($post_id, sanitize_key($key), $postmeta );
1237 }
1238 }
1239 }
1240 }
1241
1242
1243 /**
1244 * save meta options
1245 *
1246 * @since 3.0.1
1247 */
1248 public function add_wpstream_product_metaboxes() {
1249 add_meta_box( 'add_wpstream_product_metaboxes-sectionid', __( 'Live Channel/Video Settings', 'wpstream' ),array($this,'display_meta_options'),'wpstream_product' ,'normal','default');
1250 }
1251
1252
1253 /**
1254 * make woocomerce virtual products
1255 *
1256 * @since 3.0.1
1257 */
1258
1259
1260 public function wpstream_make_product_virtual($post_id,$post){
1261 global $post;
1262 if(isset($post->ID)){
1263 if ( $post->post_type !== 'product' ) return;
1264 $term_list = wp_get_post_terms($post->ID, 'product_type');
1265 if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream'){
1266 update_post_meta( $post->ID, '_virtual', 'yes' );
1267 }
1268 }
1269 }
1270
1271
1272
1273 /**
1274 * render meta options
1275 *
1276 * @since 3.0.1
1277 */
1278 public function display_meta_options( $post ) {
1279 wp_nonce_field( plugin_basename( __FILE__ ), 'estate_agent_noncename' );
1280 global $post;
1281
1282 $is_live = '';
1283 $is_video = '';
1284 $is_video_external = '';
1285 if( isset( $_GET['new_video_name']) && $_GET['new_video_name']!='' ){
1286 $is_video = ' selected ';
1287 $wpstream_free_video = esc_html( $_GET['new_video_name']);
1288 }else{
1289 $wpstream_product_type = esc_html(get_post_meta($post->ID, 'wpstream_product_type', true));
1290 $wpstream_free_video = esc_html(get_post_meta($post->ID, 'wpstream_free_video', true));
1291
1292 if($wpstream_product_type==1){
1293 $is_live = ' selected ';
1294 }
1295
1296 if($wpstream_product_type==2){
1297 $is_video = ' selected ';
1298 }
1299
1300 if($wpstream_product_type==3){
1301 $is_video_external = ' selected ';
1302 }
1303 }
1304
1305 print'
1306 <p class="meta-options">
1307 <label for="wpstream_product_type">'.__('Media Type:','wpstream').' </label><br />
1308 <select id="wpstream_product_type" name="wpstream_product_type">
1309 <option value="1" '.$is_live.'>'.__('Free Live Channel - encrypted streaming & copy protection','wpstream').'</option>
1310 <option value="2" '.$is_video.'>'.__('Free Video - encrypted streaming & copy protection','wpstream').'</option>
1311 <option value="3" '.$is_video_external.'>'.__('Free Video - unprotected','wpstream').'</option>
1312 </select>
1313 </p>
1314 ';
1315
1316
1317
1318 print '
1319 <p class="meta-options video_free">
1320 <label for="wpstream_free_video">'.__('Choose video:','wpstream').' </label><br />
1321 <select id="wpstream_free_video" name="wpstream_free_video">';
1322 $video_list = $this->main->wpstream_live_connection->wpstream_get_videos();
1323
1324 if(is_array($video_list)){
1325 foreach ($video_list as $key=>$value){
1326 print '<option value="'.$key.'"';
1327 if($wpstream_free_video === $key){
1328 print ' selected ';
1329 }
1330 print '>'.$value.'</option>';
1331 }
1332 }
1333 print'
1334 </select>
1335 </p>
1336 ';
1337
1338 $wpstream_free_video_external= esc_html(get_post_meta($post->ID, 'wpstream_free_video_external', true));
1339 print '<p class="meta-options1 video_free_external">
1340 <label for="wpstream_free_video_external">'.__('Choose video:','wpstream').' </label><br />
1341
1342 <input id="wpstream_free_video_external" type="text" size="36" name="wpstream_free_video_external" value="'.$wpstream_free_video_external.'" />
1343 <input id="wpstream_free_video_external_button" type="button" size="40" class="upload_button button" value="'.esc_html__('Select Video','wpstream').'" />
1344
1345 <p>'.esc_html__('You can choose a video from your computer or use the url from external source or use the url of a YouTube Video or use the url from a Vimeo video.','wpstream').'</p>
1346
1347 </p> ';
1348 }
1349
1350
1351
1352
1353
1354
1355
1356 /**
1357 * Add new product types to Woocommerce select product type
1358 *
1359 * @since 3.0.1
1360 */
1361 public function wpstream_add_products( $types ){
1362 $types[ 'live_stream' ] = __( 'Live Channel','wpestream' );
1363 $types[ 'video_on_demand' ] = __( 'Video On Demand','wpestream' );
1364
1365 return $types;
1366 }
1367
1368
1369
1370 /**
1371 * Js action to do when user pick live stream or video on demand
1372 *
1373 * @since 3.0.1
1374 */
1375
1376 public function wpstream_products_custom_js() {
1377 if ( 'product' != get_post_type() ) :
1378 return;
1379 endif;
1380
1381 ?>
1382 <script type='text/javascript'>
1383 jQuery( document ).ready( function() {
1384 jQuery('.options_group.pricing' ).addClass ( 'show_if_live_stream' ).show();
1385 jQuery('.options_group.pricing' ).addClass ( 'show_if_video_on_demand' ).show();
1386 jQuery('._sold_individually_field').parent().addClass('show_if_live_stream').show();
1387 jQuery('._sold_individually_field').parent().addClass('show_if_video_on_demand').show();
1388 jQuery('._sold_individually_field').show();
1389
1390 var selected = jQuery('#product-type').val();
1391 });
1392 </script>
1393 <?php
1394
1395 }
1396
1397
1398 /**
1399 * Add custom classes to the product types
1400 *
1401 * @since 3.0.1
1402 */
1403
1404 public function wpstream_hide_attributes_data_panel( $tabs) {
1405
1406 $tabs['shipping']['class'][] = 'hide_if_live_stream hide_if_video_on_demand';
1407 $tabs['inventory']['class'][] = 'show_if_live_stream show_if_video_on_demand';
1408 // $tabs['general']['class'][] = 'show_if_live_stream show_if_video_on_demand';
1409
1410 return $tabs;
1411 }
1412
1413
1414
1415 /**
1416 * Hide buy now on products if Netflix mode
1417 *
1418 * @since 3.12
1419 */
1420
1421
1422 public function wpstream_hide_buy_now_subscription_mode( $purchaseable_product_wpblog,$product){
1423 $product_id=$product->get_id();
1424
1425 $term_list = wp_get_post_terms($product_id, 'product_type');
1426
1427 $subscription_model = esc_html( get_option('wpstream_global_sub','')) ;
1428
1429 if($subscription_model==1){ // if we have Neflix mode
1430 if( $term_list[0]->name=='live_stream' || $term_list[0]->name=='video_on_demand' ){
1431 return false;
1432 }
1433 }
1434
1435 return $purchaseable_product_wpblog;
1436 }
1437
1438
1439
1440
1441
1442
1443 /**
1444 * Add custom fields to custom product types
1445 *
1446 * @since 3.0.1
1447 */
1448
1449 public function wpstream_add_custom_general_fields() {
1450
1451 global $woocommerce, $post;
1452 if(function_exists('wcs_user_has_subscription')){
1453 echo '<div class="options_group show_if_subscription">';
1454 woocommerce_wp_select(
1455 array(
1456 'id' => '_subscript_live_event',
1457 'label' => __( 'Is a subscription based live channel ?', 'woocommerce' ),
1458 'options' => array("yes"=>"yes","no"=>"no")
1459 )
1460 );
1461 echo '</div>';
1462 }
1463
1464 echo '<div class="options_group show_if_live_stream" style="border:none;"></div>';
1465 echo '<div class="options_group show_if_video_on_demand">';
1466 $selected='';
1467 if( isset( $_GET['new_video_name']) && $_GET['new_video_name']!='' ){
1468 $selected=esc_html($_GET['new_video_name']);
1469 }
1470 if($selected==''){
1471 $selected= get_post_meta($post->ID,'_movie_url',true);
1472 }
1473
1474 woocommerce_wp_select(
1475 array(
1476 'id' => '_movie_url',
1477 'label' => __( 'Library video file', 'woocommerce' ),
1478 'options' => $this->main->wpstream_live_connection->wpstream_get_videos(),
1479 'selected'=> true,
1480 'value' => $selected
1481 )
1482 );
1483
1484
1485
1486 echo '</div>';
1487
1488 if(function_exists('wcs_user_has_subscription')){
1489 $selected_sub='';
1490 echo '<div class="options_group show_if_video_on_demand show_if_live_stream">';
1491 if( isset( $_GET['wpstream_parent_sub']) && $_GET['wpstream_parent_sub']!='' ){
1492 $selected_sub=esc_html($_GET['wpstream_parent_sub']);
1493 }
1494 if($selected_sub==''){
1495 $selected_sub= get_post_meta($post->ID,'_wpstream_parent_sub',true);
1496 }
1497 woocommerce_wp_select(
1498 array(
1499 'id' => '_wpstream_parent_sub',
1500 'name' => '_wpstream_parent_sub[]',
1501 'label' => __( 'Attach to subscription', 'woocommerce' ),
1502 'options' => $this->wpstream_return_subscriptions_created(),
1503 'selected'=> true,
1504 'value' => $selected_sub,
1505 'custom_attributes' => array('multiple' => 'multiple')
1506 )
1507 );
1508
1509 echo '</div>';
1510
1511 }
1512 }
1513
1514
1515 public function wpstream_return_subscriptions_created(){
1516 $return=array('0'=>'none');
1517
1518 $args = array(
1519 'post_type' => 'product',
1520 'posts_per_page' => -1,
1521 'orderby' => 'title',
1522 'order' => 'ASC',
1523 'tax_query' => array(
1524 'relation' => 'AND',
1525 array(
1526 'taxonomy' => 'product_type',
1527 'field' => 'slug',
1528 'terms' => array( 'subscription'),
1529 )
1530 )
1531 );
1532
1533 $subscriptions = new WP_Query($args);
1534 if($subscriptions->have_posts()):
1535 while ($subscriptions->have_posts()): $subscriptions->the_post();
1536 $return[ get_the_ID() ] = get_the_title();
1537 endwhile;
1538 endif;
1539
1540 wp_reset_postdata();
1541 return $return;
1542
1543 }
1544
1545
1546
1547
1548
1549
1550 /**
1551 * Save custom fields
1552 *
1553 * @since 3.0.1
1554 */
1555
1556 public function wpstream_add_custom_general_fields_save( $post_id ){
1557
1558 $permited_values = array(
1559 '_movie_url',
1560 '_subscript_live_event',
1561 '_wpstream_parent_sub',
1562
1563 );
1564
1565
1566
1567 foreach($_POST as $key=>$value){
1568 update_post_meta( $post_id, 'event_passed', 0 );
1569 if( in_array($key, $permited_values) ){
1570 if( !empty( $_POST[$key] ) ){
1571 $key = sanitize_key($key);
1572 $value = sanitize_text_field($_POST[$key]);
1573
1574 if($key=='_wpstream_parent_sub'){
1575 $value= $_POST[$key];
1576 $value = array_map("sanitize_text_field", $value);
1577
1578 }
1579 update_post_meta( $post_id, $key, $value );
1580 }
1581 }
1582 }
1583 //die();
1584
1585 }
1586
1587 /**
1588 * Add to cart redirect
1589 *
1590 * @since 3.0.1
1591 */
1592
1593 public function wpstream_add_to_cart() {
1594 wc_get_template( 'single-product/add-to-cart/simple.php' );
1595 }
1596
1597
1598 /**
1599 * Replace add to cart button
1600 *
1601 * @since 3.0.1
1602 */
1603 public function replacing_add_to_cart_button( $button, $product ) {
1604 global $product;
1605 $product_type = $product->get_type();
1606
1607 if($product_type==='live_stream' || $product_type=='video_on_demand'){
1608 return $button = '<a class="button" href="'.get_site_url().'/shop/?add-to-cart=' .$product->get_id(). '&quantity=1">' . __( 'Add to Cart', 'woocommerce' ) . '</a>';
1609 }else{
1610 return $button;
1611 }
1612 }
1613
1614
1615 /**
1616 * Admin notices
1617 *
1618 * @since 3.0.1
1619 */
1620 public function wpstream_admin_notice() {
1621 global $pagenow;
1622 global $typenow;
1623
1624 $wpstream_notices = get_option('wpstream_notices');
1625
1626
1627 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
1628 if( !is_array($wpstream_notices) ||
1629 !isset($wpstream_notices['wpstream_woo_notice']) ||
1630 ( isset($wpestate_notices['wpstream_woo_notice']) && $wpestate_notices['wpstream_woo_notice']!='yes') ){
1631
1632
1633 print '<div class="notice wpstream_notices notice-error is-dismissible" data-notice-type="wpstream_woo_notice" >
1634 <p>'.__( 'WpStream Pay-Per-View Live Streaming and VOD only works with WooCommerce - Please enable and activate the WooCommerce plugin if you want to monetize your Live Events or Recorded Videos', 'wpstream' ).'</p>
1635 </div>';
1636 }
1637 }
1638
1639 if( !in_array ('curl', get_loaded_extensions())) {
1640 print '<div class="notice notice-error is-dismissible">
1641 <p>'.__( 'The php CURL library is not enabled on your server. WpStream plugin needs this library in order to work. Please address this issue with your hosting provider.', 'wpstream' ).'</p>
1642 </div>';
1643 }
1644
1645
1646 // $wpestate_notices = get_option('wp_stream_notices');
1647 //
1648 // if( !is_array($wpestate_notices) ||
1649 // !isset($wpestate_notices['wpstream_update_1021']) ||
1650 // ( isset($wpestate_notices['wpstream_update_1021']) && $wpestate_notices['wpstream_update_1021']!='yes') ){
1651 //
1652 // print '<div id ="setting-error-wprentals-cache" data-notice-type="wpstream_update_1021" data-dismissible="disable-done-notice-forever" class="wpestate_notices updated settings-error notice is-dismissible">
1653 // <p>'.esc_html__('New! We just released WpStream WordPress Theme - a turn key solution for video delivery & live streaming. This theme is built around WpStream plugin and is the perfect solution for video streaming or rentals platform. ','wpstream').'<a href="https://wpstream.net/wpstream-theme-a-live-streaming-wordpress-theme" target="_blank">'.esc_html__('Download Theme','wpstream').'</a></p>
1654 // </div>';
1655 // }
1656 //
1657
1658
1659
1660
1661 $ajax_nonce = wp_create_nonce( "wpstream_notice_nonce" );
1662 print '<input type="hidden" id="wpstream_notice_nonce" value="'.esc_html($ajax_nonce).'"/>';
1663
1664 }
1665
1666 /**
1667 * Admin notices
1668 *
1669 * @since 3.0.1
1670 */
1671 public function wpstream_update_cache_notice(){
1672
1673 //check_ajax_referer( 'wpstream_notice_nonce', 'security' );
1674
1675 $notice_type = esc_html($_POST['notice_type']);
1676 $notices = get_option('wp_stream_notices');
1677
1678 if(! is_array($notices) ){
1679 $notices=array();
1680 }
1681
1682 $notices[$notice_type]='yes';
1683
1684 update_option('wpstream_notices',$notices);
1685 die();
1686 }
1687
1688
1689
1690 /**
1691 * Activate metaboxes for Streaming controls on sidebar
1692 *
1693 * @since 3.0.1
1694 */
1695 public function wpstream_startstreaming_sidebar_meta() {
1696 global $post;
1697 $term_list = wp_get_post_terms($post->ID, 'product_type');
1698 if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
1699 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'wpstream_product', 'side', 'high');
1700 }
1701
1702 $is_subscription_live_event = esc_html(get_post_meta($post->ID,'_subscript_live_event',true));
1703
1704
1705 if(!is_wp_error( $term_list )){
1706 if( isset($term_list[0]->name) ){
1707 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
1708 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'product', 'side', 'high');
1709 }
1710 }
1711 }
1712
1713 }
1714
1715 /**
1716 * edited 4.0
1717 *
1718 * Show Streaming controls on sidebar
1719 *
1720 * @since 3.0.1
1721 */
1722 public function wpstream_start_stream_meta(){
1723 global $live_event_for_user;
1724 $live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
1725 // was - i think for front tend
1726 // $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user();
1727 global $post;
1728
1729 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
1730 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
1731
1732 $this->wpstream_live_stream_unit($post->ID);
1733
1734 }
1735 }