PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 3.3
WpStream – Live Streaming, Video on Demand, Pay Per View v3.3
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 3.3, at admin/class-wpstream-admin.php

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