PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.6
WpStream – Live Streaming, Video on Demand, Pay Per View v3.6
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 4.5.12 All 180 releases
wpstream / admin / class-wpstream-admin.php

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

1,184 lines 53.3 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 public function __construct( $plugin_name, $version,$plugin_main ) {
61
62 $this->plugin_name = $plugin_name;
63 $this->version = $version;
64 $this->main = $plugin_main;
65
66 }
67
68 /**
69 * Register the stylesheets for the admin area.
70 *
71 * @since 3.0.1
72 */
73 public function enqueue_styles() {
74
75 /**
76 * This function is provided for demonstration purposes only.
77 *
78 * An instance of this class should be passed to the run() function
79 * defined in Wpstream_Loader as all of the hooks are defined
80 * in that particular class.
81 *
82 * The Wpstream_Loader will then create the relationship
83 * between the defined hooks and the functions defined in this
84 * class.
85 */
86 wp_enqueue_style( 'wpestate-roboto', "https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700,900&display=swap&subset=latin-ext" );
87 wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpstream-admin.css', array(), WPSTREAM_PLUGIN_VERSION, 'all' );
88
89 }
90
91 /**
92 * Register the JavaScript for the admin area.
93 *
94 * @since 3.0.1
95 */
96 public function enqueue_scripts() {
97
98 wp_enqueue_script("jquery-ui-slider");
99 wp_enqueue_script("jquery-ui-datepicker");
100 wp_enqueue_script('jquery.fileupload', plugin_dir_url( __FILE__ ) .'js/jquery.fileupload.js',array(), WPSTREAM_PLUGIN_VERSION, true);
101 wp_enqueue_script('wpstream-admin-control', plugin_dir_url( __FILE__ ) .'js/admin_control.js',array(), WPSTREAM_PLUGIN_VERSION, true);
102 wp_localize_script('wpstream-admin-control', 'wpstream_admin_control_vars',
103 array(
104 'admin_url' => get_admin_url(),
105 'loading_url' => WPSTREAM_PLUGIN_DIR_URL.'/img/loading.gif',
106 'download_mess' => esc_html__('Click to download!','wpstream'),
107 'uploading' => esc_html('We are uploading your file.Do not close this window!','wpstream'),
108 'upload_complete2' => esc_html('Upload Complete! You can upload another file!','wpstream'),
109 'not_accepted' => esc_html('The file is not an accepted video format','wpstream'),
110 'upload_complete' => esc_html('Upload Complete!','wpstream'),
111 'no_band' => esc_html('Not enough bandwidth.','wpsteam'),
112 'no_band_no_store' => esc_html('Not enough bandwidth or storage.','wpsteam')
113
114 ));
115 }
116
117
118 /**
119 * Add Plugin Administation menu
120 *
121 * @since 3.0.1
122 */
123
124 public function wpstream_manage_admin_menu() {
125
126 add_menu_page( __('WpStream','wpestream'), __('WpStream ','wpstream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
127 add_submenu_page( 'wpstream_plugin_options', __('WpStream Credentials','wpestream'), __('WpStream Credentials','wpestream'), 'administrator', 'wpstream_plugin_options', array($this,'wpstream_set_wpstream_credentials') );
128 add_submenu_page( 'wpstream_plugin_options', __('WpStream Channels','wpestream'), __('WpStream Channels','wpestream'), 'administrator', 'wpstream_new_general_set', array( $this,'wpstream_new_general_set'));
129 add_submenu_page( 'wpstream_plugin_options', __('WpStream Media Management','wpestream'), __('WpStream Media Management','wpestream'), 'administrator', 'wpstream_media_management', array($this,'wpstream_media_management'));
130 add_submenu_page( 'wpstream_plugin_options', __('WpStream Settings','wpestream'), __('WpStream Settings','wpestream'), 'administrator', 'wpstream_settings', array($this,'wpstream_settings'));
131
132 }
133
134
135
136 /**
137 * Shows events wpstream
138 *
139 * @since 3.0.1
140 */
141
142 public function wpstream_new_general_set() {
143
144 $no_channel=1;
145
146 if(class_exists ('WC_Subscription')){
147
148 }
149
150 //event_passed
151 $args = array(
152 'posts_per_page' => -1,
153 'post_type' => 'product',
154 'post_status' => 'publish',
155 'meta_query' => array(
156 array(
157 'key' => 'event_passed',
158 'value' => 1,
159 'compare' => '!=',
160 )
161 ),
162
163 'tax_query' => array(
164 'relation' => 'AND',
165 array(
166 'taxonomy' => 'product_type',
167 'field' => 'slug',
168 'terms' => array('live_stream','subscription')
169 )
170 ),
171 );
172
173
174
175 $event_list = new WP_Query($args);
176 global $live_event_for_user;
177 $live_event_for_user = $this->main->wpstream_live_connection->wpstream_get_live_event_for_user();
178 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
179
180 $this->main->show_user_data($pack_details);
181
182
183
184
185 if( $event_list->have_posts()){
186
187
188 print '<div class="pack_details_wrapper_transparent">
189 <h3>'.__('Your Pay-Per-View Channel List','wpstream').'</h3>';
190
191
192 $link_new = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
193
194 print '<a href="'.esc_url($link_new).'" class="wpstream_create_new_product_link">'.esc_html__('Create new pay-per-view channel.','wpstream').'</a>';
195 print '</div>';
196
197 print '<div style="clear: both;"></div><div class="event_list_wrapper">';
198
199 while ($event_list->have_posts()): $event_list->the_post();
200
201 $the_id = get_the_ID();
202 $is_subscription_live_event = esc_html(get_post_meta($the_id,'_subscript_live_event',true));
203 $term_list = wp_get_post_terms($the_id, 'product_type');
204
205 if( $term_list[0]->name=='subscription' && $is_subscription_live_event=='no'){
206 continue;
207 }
208
209 $this->wpstream_live_stream_unit($the_id);
210
211 endwhile;
212
213 print'</div>';
214 $no_channel=1;
215 }else{
216 $no_channel=0;
217 }
218
219
220 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
221 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
222 $current_user = wp_get_current_user();
223 $allowded_html = array();
224 $userID = $current_user->ID;
225 $user_live_streams = get_user_meta($userID,'live_shows');
226
227
228 wp_reset_postdata();
229
230
231
232
233 // free
234
235 $args_free = array(
236 'posts_per_page' => -1,
237 'post_type' => 'wpstream_product',
238 'post_status' => 'publish',
239 'meta_query' => array(
240 'relation' => 'AND',
241 array(
242 'key' => 'wpstream_product_type',
243 'value' => 1,
244 'compare' => '==',
245 ),
246
247 ),
248
249
250 );
251 $event_list_free = new WP_Query($args_free);
252
253
254 if( $event_list_free->have_posts()){
255 print '<div class="pack_details_wrapper_transparent">
256 <h3>'.__('Your Free Channel List','wpestate').'</h3>';
257
258 $link_new = admin_url('post-new.php?post_type=wpstream_product');
259 print '<a href="'.esc_url($link_new).'" class="wpstream_create_new_product_link">'.esc_html__('Create new free channel.','wpstream').'</a>';
260 print '</div>';
261 print '<div style="clear: both;"></div><div class="event_list_wrapper">';
262
263 while ($event_list_free->have_posts()): $event_list_free->the_post();
264
265
266 $the_id = get_the_ID();
267
268 if( get_post_meta ($the_id,'event_passed',true)!=1){
269 $this->wpstream_live_stream_unit($the_id);
270 }
271
272 endwhile;
273
274 print'</div>';
275 $no_channel=1;
276 }else{
277 $no_channel=0;
278 }
279
280
281
282 if($no_channel==0){
283 $link_new_paid = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
284 $link_new_free = admin_url('post-new.php?post_type=wpstream_product');
285 print '<div class="no_events_warning"> '.__('* You don\'t have any live channels!','wpstream');
286
287 print '<a href="'.esc_url($link_new_free).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Add new free channel ','wpstream').'</a>';
288 print '<a href="'.esc_url($link_new_paid).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Add new pay-per-view channel ','wpstream').'</a>';
289
290 print '</div>';
291 }
292
293
294
295
296 }
297 // end wpstream_new_general_set
298
299
300
301
302
303
304
305 /**
306 * Shows event unit card in admin
307 *
308 * @since 3.0.1
309 */
310 public function wpstream_live_stream_unit($the_id){
311 global $live_event_for_user;
312
313
314 $live_class='';
315 if(isset($live_event_for_user[$the_id])) {
316 $live_class=" wpstream_show_started";
317 }
318
319
320 print '<div class="event_list_unit '.$live_class.' ">';
321 $ip= get_post_meta($the_id,'ip',true);
322
323
324 if(has_post_thumbnail($the_id)){
325 $thumb = get_the_post_thumbnail_url($the_id,'thumbnail');
326 }else{
327 $thumb= plugin_dir_url( dirname( __FILE__ ) ). 'img/default_150.jpg';
328 }
329
330
331 print '<div class="event_thumb_wrapper"><img class="event_thumb" src="'.$thumb.'" alt="show_imagge"></div>';
332
333
334 global $wpstream_plugin;
335 $current_user = wp_get_current_user();
336
337
338 // print_R( $wpstream_plugin->wpstream_live_connection->api20_wpstream_get_live_event_for_user($the_id));
339 // print_R( $wpstream_plugin->wpstream_live_connection->wpstream_request_live_stream_uri($the_id,0,));
340
341
342 print '<h3 data-prodid="'.$the_id.'">'.get_the_title($the_id).' - '.esc_html__('Id','wpstream').': '.$the_id.'<a class="view_channel" href="'.get_permalink($the_id).'" target="_blank">'.esc_html__('View Channel','wprentals').'</a></h3> ';
343
344
345
346 $live_event_stream_name = get_post_meta($the_id,'live_event_stream_name',true);
347 $live_event_array = get_post_meta($the_id,'live_event_uri',true);
348 $live_event_uri = '';
349
350
351 $pending_streaming_class = '';
352 $wpstream_ready_to_stream_class = '';
353 $external_software_streaming_class = '';
354 $wpstream_no_stream_class = '';
355 $carnat_key1 = '';
356 $carnat_key2 = '';
357 $uri = '';
358 $webcaster_url = '';
359 $rtmp_ip_uri = '';
360 $uri_ip = '';
361 $server_id = '';
362 $obs_uri = '';
363 $obs_stream = '';
364 $webCasterUrl = '';
365 if(is_array($live_event_for_user) && isset($live_event_for_user[$the_id])) {
366
367 $pending_streaming_class = 'show_stream_data pending_trigger';
368 $wpstream_ready_to_stream_class = 'hide_stream_data';
369 $external_software_streaming_class = 'show_stream_data';
370 $wpstream_no_stream_class = 'hide_stream_data';
371 if(isset($live_event_for_user[$the_id]['live_uri'])){
372 $explode = explode('wpstream.net/', $live_event_for_user[$the_id]['live_uri']);
373 $uri = $explode[0].'wpstream.net/wpstream/';
374 $stream_name = get_post_meta($the_id,'live_event_stream_name',true);
375 $carnat_key1 = $live_event_for_user[$the_id]['carnat1'];
376 $carnat_key2 = $live_event_for_user[$the_id]['carnat2'];
377 $webcaster_url = 'https://'.$live_event_for_user[$the_id]['subdomain_key'].'.live.streamer.wpstream.net:8443/'.$live_event_for_user[$the_id]['carnat2'];
378
379 $rtmp_ip_uri = 'http://'.$live_event_for_user[$the_id]['ip'].':8444';
380 $uri_ip= 'rtmp://'.$live_event_for_user[$the_id]['ip'].'/wpstream/';
381
382 // starting from 2.0
383 $server_id = get_post_meta($the_id,'server_id',true);
384 $obs_uri = get_post_meta($the_id,'obs_uri',true);
385 $obs_stream = get_post_meta($the_id,'obs_stream',true);
386 $webCasterUrl= get_post_meta($the_id,'webCasterUrl',true);
387
388 // if local server id diffrens than wpstream server id it means call was made via api and we use wpstream ip
389 if( $server_id != $live_event_for_user[$the_id]['api20_event_id'] && $live_event_for_user[$the_id]['api20_event_id']!='' ){
390
391 $server_id=esc_html($live_event_for_user[$the_id]['api20_event_id']);
392 }
393
394 }
395
396 }else{
397
398 $pending_streaming_class = 'hide_stream_data';
399 $wpstream_ready_to_stream_class = 'hide_stream_data';
400 $external_software_streaming_class = 'hide_stream_data';
401 $wpstream_no_stream_class = 'show_stream_data';
402 }
403
404
405
406
407 print' <div class="pending_streaming '.$pending_streaming_class.' " data-show-id="'.$the_id.'" data-server-id="'.$server_id.'" data-server-url="'.$rtmp_ip_uri.'">';
408 print'<div class="wpstream_channel_status not_ready_to_stream"><span class="dashicons dashicons-dismiss"></span>'.esc_html__('Getting ready to stream. Please wait...','wprentals').' ';
409 print '<img class="server_loading_new" src="'.plugin_dir_url( dirname( __FILE__ ) ).'img/loading.gif" alt="loading" /></div>';
410 print '<div class="multiple_warning_events"> '.esc_html__('* You can run multiple live events on a single channel. **Once deleted, you can no longer broadcast to it.','wpstream').'</div>';
411 print '</div>';
412
413
414 print '<div class="wpstream_ready_to_stream '.$wpstream_ready_to_stream_class.'">';
415 print '<div class="wpstream_channel_status"><span class="dashicons dashicons-yes"></span>'.esc_html__('Ready To Stream !','wpstream').'</div>';
416 print '<div class="start_webcaster wpstream_button" data-webcaster-url="'.$webCasterUrl.'" >'.esc_html__('Start Browser Broadcast','wpstream').'</div>';
417 print '<div class="start_external wpstream_button" >'.esc_html__('Broadscast With 3rd Party Software','wpstream').'</div>';
418 print '<div class="stop_server wpstream_button" data-show-id="'.$the_id.'">'.esc_html__('Turn Off Channel','wpstream').'</div>';
419 $ajax_nonce_stop = wp_create_nonce( "wpstream_stop_event_nonce" );
420 print '<input type="hidden" id="wpstream_stop_event_nonce" value="'.$ajax_nonce_stop.'">';
421 print '</div>';
422
423
424
425 print '<div class="external_software_streaming '. $external_software_streaming_class.' ">';
426 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>';
427 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>';
428 print '<div class="warning_stream">'.
429 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 software and devices are supported, see our %s for 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/category/guides/" target="_blank">guides</a>').'</div>';
430 print ' <img class="how_to" src="'.plugin_dir_url( dirname( __FILE__ ) ).'img/how_to_obs.jpg" alt="show_imagge">';
431
432 print'</div>';
433 print'</div>';
434
435
436
437
438 print '<div class="wpstream_no_stream '.$wpstream_no_stream_class.' ">';
439 print '<div class="event_list_unit_notificationx"><span class="server_notification">'.__('Channel is inactive.','wpestream').' <img class="server_loading" src="'.plugins_url().'/wpstream/img/loading.gif" alt="loading" /></span></div>';
440 print '<div class="record_wrapper">Record ? <input type="checkbox" name="record_event" class="record_event"/>Yes</div>';
441 print '<div class="encrypt_wrapper">Encrypt ? <input type="checkbox" name="encrypt_event" class="encrypt_event"/>Yes</div>';
442
443 print '<input class="start_event wpstream_button" type="button" data-show-id="'.$the_id.'" value="'.esc_html__('Broadcast To Channel','wpstream').'">';
444 print '<input class="close_event wpstream_button" type="button" data-show-id="'.$the_id.'" value="'.esc_html__('Delete Channel','wpstream').'">';
445 print '<div class="multiple_warning_events"> '.esc_html__('* You can run multiple live events on a single channel. **Once deleted, you can no longer broadcast to it.','wpstream').'</div>';
446
447
448 print '<div class="wpstream_social_media_broadcast">';
449
450 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>';
451 print '</div>';
452
453 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>';
454 print '</div>';
455
456
457 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>';
458 print '</div>';
459
460 print '<div class="wpstream_on_facebook_container wpstream_social_stream_container">';
461 print 'Some Facebook Settings for event '.$the_id;
462 print '</div>';
463
464 print '<div class="wpstream_on_youtube_container wpstream_social_stream_container">';
465 print '<label for="wpstream_youtube_rtmp'.$the_id.'">'.esc_html__('Youtube RTMP','wpstream').'</label>';
466 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 )).'">';
467 print '</div>';
468
469 print '<div class="wpstream_on_twich_container wpstream_social_stream_container">';
470 print '<label for="wpstream_twich_rtmp'.$the_id.'">'.esc_html__('Twich RTMP','wpstream').'</label>';
471 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 )).'">';
472 print '</div>';
473
474
475 print '</div>';
476 print '</div>';
477
478
479 print '</div>';
480 }
481
482
483
484
485
486
487
488 /**
489 * Set Settings
490 *
491 *
492 */
493
494 public function wpstream_settings(){
495
496 if($_SERVER['REQUEST_METHOD'] === 'POST'){
497 $allowed_html = array();
498 $exclude_array = array();
499 $allowed_html = array();
500
501 foreach($_POST as $variable=>$value){
502 if ($variable!='submit'){
503 if (!in_array($variable, $exclude_array) ){
504 update_option( sanitize_key('wpstream_'.$variable), wp_kses ($value,$allowed_html) );
505 }
506
507
508 }
509 }
510
511 // reset permalinkgs
512 global $wp_rewrite;
513
514 update_option( "rewrite_rules", FALSE );
515 $wp_rewrite->flush_rules( true );
516
517 }
518
519 $wpstream_settings_array =array(
520 1 => array(
521 'label' => 'slug for wpstream free videos/channels',
522 'name' => 'free_media_slug',
523 'type' => 'text',
524 'details' => 'It will replace wpstream in the free videos/channels url with your new slug. You cannot use special characters like "&". After changing the url go to Settings - Permalinks and Save again the "Permalinks Settings" - option "Post name" '
525 ),
526
527 );
528
529
530 print '<form method="post" action="" >';
531 print '<div class="theme_options_tab_wpstream" style="display:block;" >
532 <h1>'.__('WpStream Settings','wpstream').'</h1>';
533
534
535
536 print '<div class="wpstream_option_wrapper">';
537 foreach ($wpstream_settings_array as $key=>$option){
538 print '<div class="wpstream_option">';
539
540 $options_value = esc_html( get_option('wpstream_'.$option['name'],'') );
541 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
542 print '<input id="'.$option['name'].'" type="'.$option['type'].'" size="36" name="'.$option['name'].'" value="'.esc_html($options_value).'" />';
543 print '<div class="settings_details">'.$option['details'].'</div>';
544
545 print '</div>';
546 }
547 print '</div>';
548
549
550 print '<input type="submit" name="submit" class="wpstream_button" value="'.__('Save Changes','wpstream').'" />';
551
552
553
554 print '</div>';
555 print '</form>';
556 }
557
558
559 /**
560 * Set credential admin function
561 *
562 * @since 3.0.1
563 */
564 public function wpstream_set_wpstream_credentials(){
565
566 if($_SERVER['REQUEST_METHOD'] === 'POST'){
567 $allowed_html = array();
568 $exclude_array = array();
569 $allowed_html = array();
570
571 foreach($_POST as $variable=>$value){
572 if ($variable!='submit'){
573 if (!in_array($variable, $exclude_array) ){
574 update_option( sanitize_key('wpstream_'.$variable), wp_kses ($value,$allowed_html) );
575 }
576 }
577 }
578
579
580
581
582 update_option('wp_estate_token_expire',0);
583 update_option('wp_estate_curent_token',' ');
584 delete_transient( 'wpstream_token_request');
585
586 }
587
588
589 $allowed_html = array();
590 $api_key = esc_html( get_option('wpstream_api_key','') );
591
592
593 $wpstream_options_array =array(
594 2 => array(
595 'label' => 'WpStream.net Username or Email',
596 'name' => 'api_username',
597 'type' => 'text',
598 ),
599 3 => array(
600 'label' => 'WpStream.net Password',
601 'name' => 'api_password',
602 'type' => 'password',
603 ),
604
605 );
606
607
608 $token = $this->main->wpstream_live_connection->wpstream_get_token();
609 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
610
611 $this->main->show_user_data($pack_details);
612
613 print '<form method="post" action="" >';
614 print '<div class="theme_options_tab_wpstream" style="display:block;" >
615 <h1>'.__('WpStream Credentials','wpstream').'</h1>';
616
617
618 if( get_option('wpstream_api_username')=='' || get_option('wpstream_api_password')== ' '){
619 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>';
620 }else if($token==''){
621 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>';
622 }else if( $this->main->wpstream_live_connection->wpstream_client_check_api_status() ){
623 echo '<div class="api_conected">'.__('Conected to WpStream.net!','wpstream').'</div>';
624 }else{
625 echo '<div class="api_not_conected wpstream_brown">'.__('Failed to connect to WpStream.net. Please address CURL connectivity with your hosting provider.','wpstream').'</div>';
626 }
627 print '<div class="wpstream_option_wrapper">';
628 foreach ($wpstream_options_array as $key=>$option){
629 print '<div class="wpstream_option">';
630
631 $options_value = esc_html( get_option('wpstream_'.$option['name'],'') );
632 print '<label for="'.$option['name'].'">'.$option['label'].'</label>';
633 print '<input id="'.$option['name'].'" type="'.$option['type'].'" size="36" name="'.$option['name'].'" value="'.esc_html($options_value).'" />';
634
635 print '</div>';
636 }
637 print '</div>';
638
639
640 print '<input type="submit" name="submit" class="wpstream_button" value="'.__('Save Changes','wpstream').'" />';
641
642
643
644 print '</div>';
645 print '</form>';
646
647 print '<div class="theme_options_tab_wpstream" style="display:block;" >';
648 $link_new = admin_url('admin.php?page=wpstream_new_general_set');
649 $link_new_paid = admin_url('post-new.php?post_type=product').'&new_stream='. rawurlencode('new');
650 $link_new_free = admin_url('post-new.php?post_type=wpstream_product');
651
652
653 print '<a href="'.esc_url($link_new_free).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Create new free channel','wpstream').'</a>';
654 print '<a href="'.esc_url($link_new_paid).'" class="wpstream_no_chanel_add_channel">'.esc_html__('Create pay-per-view channel','wpstream').'</a>';
655 print '<a href="'.esc_url($link_new).'" class="wpstream_no_chanel_add_channel">'.esc_html('My Channels','wpstream').'</a>';
656 print '</div>';
657
658
659 }
660
661
662
663 /**
664 * Media Management
665 *
666 * @since 3.0.1
667 */
668 public function wpstream_media_management(){
669 $pack_details = $this->main->wpstream_live_connection->wpstream_request_pack_data_per_user();
670
671 $this->main->show_user_data($pack_details);
672
673
674 print '<div id="wpstream_media_upload"><h3>'.__('Media Upload','wpstream').'</h3>'.$this->wpstream_present_media_upload().'</div>';
675
676 print '<div id="wpstream_file_management"><h3 id="video_management_title">'.__('Video Management','wpstream').'</h3>'.$this->wpstream_present_file_management().'</div>';
677
678 }
679
680
681
682 /**
683 * Media upload
684 *
685 * @since 3.0.1
686 */
687 public function wpstream_present_media_upload(){
688 $to_return='';
689 $formInputs=$this->main->wpstream_live_connection->wpstream_get_signed_form_upload_data();
690
691 if($formInputs === 'notenough'){
692 $to_return.='<div class="wpstream_upload_alert">'.esc_html__('You do not have enough bandwidth or storage to upload a video!','wpstream').'</div>';
693 return $to_return;
694 }
695
696
697 $to_return.='<div class="wpstream_upload_container">';
698 $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>';
699 $to_return.='<form action="https://wpstream-videos.s3.amazonaws.com/"
700 method="POST"
701 enctype="multipart/form-data"
702 class="direct-upload">';
703
704 $to_return.='<input id="wpstream_upload" type="file" class="inputfile inputfile-1" value="Pick a video file" name="file" multiple>';
705 $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>';
706
707
708 $to_return.='<div class="wpstream_file_drop_color">';
709 $to_return.='<div class="wpstream_form_ex">'.esc_html__('Drop a video file here!','wpstream').'</div>';
710 $to_return.='<div class="wpstream_form_ex_details">'.esc_html__('The Video File must be encoded with the following settings:
711
712 Container: MP4,
713 Video codec: H264,
714 Audio codec: AAC. Media will fail to play back if it does not follow the above settings.
715 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>';
716 if(is_array($formInputs)){
717 foreach ($formInputs as $name => $value) {
718 $to_return.='<input type="hidden" name="'. $name.'" value="'.$value.'">';
719 }
720 }
721
722 $to_return.='
723 <div class="progress-bar-area"></div></div>
724 </form>';
725
726 $to_return.='</div>';
727 return $to_return;
728
729 }
730
731
732
733 /**
734 * Display movie list
735 *
736 * @since 3.0.1
737 */
738 public function wpstream_present_file_management(){
739 $video_list_raw = $this->main->wpstream_live_connection->wpstream_get_videos_from_storage_raw_data();
740
741 $to_return='';
742 if(is_array($video_list_raw)){
743 foreach ($video_list_raw as $key =>$video){
744 $to_return.='<div class="wpstream_video_wrapper">';
745
746 $to_return.='<div class="wpstream_video_title">';
747 $to_return.='<div class="wpstream_video_notice"></div></div>';
748 $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></div>';
749 $to_return.=' <div class="wpstream_delete_media" ';
750 $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>';
751 $to_return.='<div class="wpstream_get_download_link" data-filename="'.$video['video_name_storage'].'">'.esc_html__('get download link','wpstream').'</div>';
752 $to_return.='<a href="" class="wpstream_download_link">'.esc_html__('Click to download! The url will work for the next 20 minutes!','wpstream').'</a>';
753
754 $add_free_video_url=admin_url('post-new.php?post_type=wpstream_product').'&new_video_name='. rawurlencode($video['video_name_storage']);
755 $add_paid_video_url=admin_url('post-new.php?post_type=product').'&new_video_name='. rawurlencode($video['video_name_storage']);
756
757
758
759 $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>';
760 $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>';
761
762 $to_return.='</div>';
763
764 }
765 } else {
766 $to_return.= '<div class="wpstream_video_wrapper">'.esc_html__('You don\'t have any videos.','wpstream').'</div>';
767 }
768 return $to_return;
769 }
770
771
772
773
774
775 /**
776 * save meta options
777 *
778 * @since 3.0.1
779 */
780 public function wpstream_free_product_update_post($post_id,$post){
781
782 if(!is_object($post) || !isset($post->post_type)) {
783 return;
784 }
785
786 if($post->post_type!='wpstream_product'){
787 return;
788 }
789
790
791 $allowed_keys=array(
792 'wpstream_product_type',
793 'wpstream_free_video',
794 'wpstream_free_video_external'
795 );
796
797 $allowed_html=array();
798
799 foreach ($_POST as $key => $value) {
800 if( !is_array ($value) ){
801 if (in_array ($key, $allowed_keys)) {
802 $postmeta = wp_kses ( $value,$allowed_html );
803 update_post_meta($post_id, sanitize_key($key), $postmeta );
804 }
805 }
806 }
807 }
808
809
810 /**
811 * save meta options
812 *
813 * @since 3.0.1
814 */
815 public function add_wpstream_product_metaboxes() {
816 add_meta_box( 'add_wpstream_product_metaboxes-sectionid', __( 'Live Channel/Video Settings', 'wpestate' ),array($this,'display_meta_options'),'wpstream_product' ,'normal','default');
817 }
818
819
820 /**
821 * make woocomerce virtual products
822 *
823 * @since 3.0.1
824 */
825
826
827 public function wpstream_make_product_virtual($post_id,$post){
828 global $post;
829
830 if ( $post->post_type !== 'product' ) return;
831
832 $term_list = wp_get_post_terms($post->ID, 'product_type');
833 if( $term_list[0]->name=='video_on_demand' || $term_list[0]->name=='live_stream'){
834 update_post_meta( $post->ID, '_virtual', 'yes' );
835 }
836
837 }
838
839
840
841 /**
842 * render meta options
843 *
844 * @since 3.0.1
845 */
846 public function display_meta_options( $post ) {
847 wp_nonce_field( plugin_basename( __FILE__ ), 'estate_agent_noncename' );
848 global $post;
849
850 $is_live = '';
851 $is_video = '';
852 $is_video_external = '';
853 if( isset( $_GET['new_video_name']) && $_GET['new_video_name']!='' ){
854 $is_video = ' selected ';
855 $wpstream_free_video = esc_html( $_GET['new_video_name']);
856 }else{
857 $wpstream_product_type = esc_html(get_post_meta($post->ID, 'wpstream_product_type', true));
858 $wpstream_free_video = esc_html(get_post_meta($post->ID, 'wpstream_free_video', true));
859
860 if($wpstream_product_type==1){
861 $is_live = ' selected ';
862 }
863
864 if($wpstream_product_type==2){
865 $is_video = ' selected ';
866 }
867
868 if($wpstream_product_type==3){
869 $is_video_external = ' selected ';
870 }
871 }
872
873 print'
874 <p class="meta-options">
875 <label for="wpstream_product_type">'.__('Media Type:','wpstream').' </label><br />
876 <select id="wpstream_product_type" name="wpstream_product_type">
877 <option value="1" '.$is_live.'>'.__('Free Live Channel - encrypted streaming & copy protection','wpstream').'</option>
878 <option value="2" '.$is_video.'>'.__('Free Video - encrypted streaming & copy protection','wpstream').'</option>
879 <option value="3" '.$is_video_external.'>'.__('Free Video - unprotected','wpstream').'</option>
880 </select>
881 </p>
882 ';
883
884
885
886 print '
887 <p class="meta-options video_free">
888 <label for="wpstream_free_video">'.__('Choose video:','wpstream').' </label><br />
889 <select id="wpstream_free_video" name="wpstream_free_video">';
890 $video_list = $this->main->wpstream_live_connection->wpstream_get_videos();
891
892 if(is_array($video_list)){
893 foreach ($video_list as $key=>$value){
894 print '<option value="'.$key.'"';
895 if($wpstream_free_video === $key){
896 print ' selected ';
897 }
898 print '>'.$value.'</option>';
899 }
900 }
901 print'
902 </select>
903 </p>
904 ';
905
906 $wpstream_free_video_external= esc_html(get_post_meta($post->ID, 'wpstream_free_video_external', true));
907 print '<p class="meta-options1 video_free_external">
908 <label for="wpstream_free_video_external">'.__('Choose video:','wpstream').' </label><br />
909
910 <input id="wpstream_free_video_external" type="text" size="36" name="wpstream_free_video_external" value="'.$wpstream_free_video_external.'" />
911 <input id="wpstream_free_video_external_button" type="button" size="40" class="upload_button button" value="'.esc_html__('Select Video','wpstream').'" />
912
913 <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>
914
915 </p> ';
916 }
917
918
919
920
921
922
923
924 /**
925 * Add new product types to Woocommerce select product type
926 *
927 * @since 3.0.1
928 */
929 public function wpstream_add_products( $types ){
930 $types[ 'live_stream' ] = __( 'Live Channel','wpestream' );
931 $types[ 'video_on_demand' ] = __( 'Video On Demand','wpestream' );
932
933 return $types;
934 }
935
936
937
938 /**
939 * Js action to do when user pick live stream or video on demand
940 *
941 * @since 3.0.1
942 */
943
944 public function wpstream_products_custom_js() {
945 if ( 'product' != get_post_type() ) :
946 return;
947 endif;
948
949 ?>
950 <script type='text/javascript'>
951 jQuery( document ).ready( function() {
952 jQuery('.options_group.pricing' ).addClass ( 'show_if_live_stream' ).show();
953 jQuery('.options_group.pricing' ).addClass ( 'show_if_video_on_demand' ).show();
954 jQuery('._sold_individually_field').parent().addClass('show_if_live_stream').show();
955 jQuery('._sold_individually_field').parent().addClass('show_if_video_on_demand').show();
956 jQuery('._sold_individually_field').show();
957
958 var selected = jQuery('#product-type').val();
959 });
960 </script>
961 <?php
962
963 }
964
965
966 /**
967 * Add custom classes to the product types
968 *
969 * @since 3.0.1
970 */
971
972 public function wpstream_hide_attributes_data_panel( $tabs) {
973
974 $tabs['shipping']['class'][] = 'hide_if_live_stream hide_if_video_on_demand';
975 $tabs['inventory']['class'][] = 'show_if_live_stream show_if_video_on_demand';
976 // $tabs['general']['class'][] = 'show_if_live_stream show_if_video_on_demand';
977
978 return $tabs;
979 }
980
981
982 /**
983 * Add custom fields to custom product types
984 *
985 * @since 3.0.1
986 */
987
988 public function wpstream_add_custom_general_fields() {
989
990 global $woocommerce, $post;
991 if(function_exists('wcs_user_has_subscription')){
992 echo '<div class="options_group show_if_subscription">';
993 woocommerce_wp_select(
994 array(
995 'id' => '_subscript_live_event',
996 'label' => __( 'Is a subscription based live channel ?', 'woocommerce' ),
997 'options' => array("yes"=>"yes","no"=>"no")
998 )
999 );
1000 echo '</div>';
1001 }
1002
1003 echo '<div class="options_group show_if_live_stream" style="border:none;"></div>';
1004 echo '<div class="options_group show_if_video_on_demand">';
1005 $selected='';
1006 if( isset( $_GET['new_video_name']) && $_GET['new_video_name']!='' ){
1007 $selected=esc_html($_GET['new_video_name']);
1008 }
1009 if($selected==''){
1010 $selected= get_post_meta($post->ID,'_movie_url',true);
1011 }
1012
1013 woocommerce_wp_select(
1014 array(
1015 'id' => '_movie_url',
1016 'label' => __( 'Select the video file.', 'woocommerce' ),
1017 'options' => $this->main->wpstream_live_connection->wpstream_get_videos(),
1018 'selected'=> true,
1019 'value' => $selected
1020 )
1021 );
1022
1023 echo '</div>';
1024 }
1025
1026 /**
1027 * Save custom fields
1028 *
1029 * @since 3.0.1
1030 */
1031
1032 public function wpstream_add_custom_general_fields_save( $post_id ){
1033
1034 $permited_values = array(
1035 '_movie_url',
1036 '_subscript_live_event'
1037 );
1038 $allowed_html=array();
1039 foreach($_POST as $key=>$value){
1040 update_post_meta( $post_id, 'event_passed', 0 );
1041 if( in_array($key, $permited_values) ){
1042 if( !empty( $_POST[$key] ) ){
1043 update_post_meta( $post_id, wp_kses ($key,$allowed_html), wp_kses ( $_POST[$key],$allowed_html) );
1044 }
1045 }
1046 }
1047
1048 }
1049
1050 /**
1051 * Add to cart redirect
1052 *
1053 * @since 3.0.1
1054 */
1055
1056 public function wpstream_add_to_cart() {
1057 wc_get_template( 'single-product/add-to-cart/simple.php' );
1058 }
1059
1060
1061 /**
1062 * Replace add to cart button
1063 *
1064 * @since 3.0.1
1065 */
1066 public function replacing_add_to_cart_button( $button, $product ) {
1067 global $product;
1068 $product_type = $product->get_type();
1069
1070 if($product_type==='live_stream' || $product_type=='video_on_demand'){
1071 return $button = '<a class="button" href="'.get_site_url().'/shop/?add-to-cart=' .$product->get_id(). '&quantity=1">' . __( 'Add to Cart', 'woocommerce' ) . '</a>';
1072 }else{
1073 return $button;
1074 }
1075 }
1076
1077
1078 /**
1079 * Admin notices
1080 *
1081 * @since 3.0.1
1082 */
1083 public function wpstream_admin_notice() {
1084 global $pagenow;
1085 global $typenow;
1086
1087
1088 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
1089 print '<div class="notice notice-error is-dismissible">
1090 <p>'.__( 'WpStream Pay Per View / Subscription mode works only with WooCommerce - If you want to charge money for your live events or videos you need to activate WooCommerce plugin', 'wpestate' ).'</p>
1091 </div>';
1092 }
1093 if( !in_array ('curl', get_loaded_extensions())) {
1094 print '<div class="notice notice-error is-dismissible">
1095 <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.', 'wpestate' ).'</p>
1096 </div>';
1097 }
1098
1099
1100 $wpestate_notices = get_option('wp_stream_notices');
1101
1102 if( !is_array($wpestate_notices) ||
1103 !isset($wpestate_notices['wpstream_update_1021']) ||
1104 ( isset($wpestate_notices['wpstream_update_1021']) && $wpestate_notices['wpstream_update_1021']!='yes') ){
1105
1106 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">
1107 <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>
1108 </div>';
1109 }
1110
1111
1112
1113
1114
1115 $ajax_nonce = wp_create_nonce( "wpstream_notice_nonce" );
1116 print '<input type="hidden" id="wpstream_notice_nonce" value="'.esc_html($ajax_nonce).'"/>';
1117
1118 }
1119
1120 /**
1121 * Admin notices
1122 *
1123 * @since 3.0.1
1124 */
1125 public function wpstream_update_cache_notice(){
1126
1127 //check_ajax_referer( 'wpstream_notice_nonce', 'security' );
1128
1129 $notice_type = esc_html($_POST['notice_type']);
1130 $notices = get_option('wp_stream_notices');
1131
1132 if(! is_array($notices) ){
1133 $notices=array();
1134 }
1135
1136 $notices[$notice_type]='yes';
1137
1138 update_option('wp_stream_notices',$notices);
1139 die();
1140 }
1141
1142
1143
1144 /**
1145 * Activate metaboxes for Streaming controls on sidebar
1146 *
1147 * @since 3.0.1
1148 */
1149 public function wpstream_startstreaming_sidebar_meta() {
1150 global $post;
1151 $term_list = wp_get_post_terms($post->ID, 'product_type');
1152 if( get_post_meta($post->ID, 'wpstream_product_type', true)==1 ){
1153 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'wpstream_product', 'side', 'high');
1154 }
1155
1156 $is_subscription_live_event = esc_html(get_post_meta($post->ID,'_subscript_live_event',true));
1157
1158
1159 if(!is_wp_error( $term_list )){
1160 if( isset($term_list[0]->name) ){
1161 if( $term_list[0]->name=='live_stream' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){
1162 add_meta_box('wpstream-sidebar-meta', esc_html__('Live Streaming', 'wpstream'), array($this,'wpstream_start_stream_meta'), 'product', 'side', 'high');
1163 }
1164 }
1165 }
1166
1167 }
1168
1169 /**
1170 * Show Streaming controls on sidebar
1171 *
1172 * @since 3.0.1
1173 */
1174 public function wpstream_start_stream_meta(){
1175 global $live_event_for_user;
1176 global $post;
1177
1178 $ajax_nonce = wp_create_nonce( "wpstream_start_event_nonce" );
1179 print '<input type="hidden" id="wpstream_start_event_nonce" value="'.$ajax_nonce.'">';
1180 $live_event_for_user = $this->main->wpstream_live_connection->api20_wpstream_request_live_stream_for_user();
1181 $this->wpstream_live_stream_unit($post->ID);
1182
1183 }
1184 }