| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The file that defines the core plugin class |
| 5 |
* |
| 6 |
* A class definition that includes attributes and functions used across both the |
| 7 |
* public-facing side of the site and the admin area. |
| 8 |
* |
| 9 |
* @link http://wpstream.net |
| 10 |
* @since 3.0.1 |
| 11 |
* |
| 12 |
* @package Wpstream |
| 13 |
* @subpackage Wpstream/includes |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* The core plugin class. |
| 18 |
* |
| 19 |
* This is used to define internationalization, admin-specific hooks, and |
| 20 |
* public-facing site hooks. |
| 21 |
* |
| 22 |
* Also maintains the unique identifier of this plugin as well as the current |
| 23 |
* version of the plugin. |
| 24 |
* |
| 25 |
* @since 3.0.1 |
| 26 |
* @package Wpstream |
| 27 |
* @subpackage Wpstream/includes |
| 28 |
* @author wpstream <office@wpstream.net> |
| 29 |
*/ |
| 30 |
class Wpstream { |
| 31 |
|
| 32 |
/** |
| 33 |
* Store plugin main class to allow public access. |
| 34 |
* |
| 35 |
* @since 3.0.1 |
| 36 |
* @var object The main class. |
| 37 |
*/ |
| 38 |
public $main; |
| 39 |
|
| 40 |
/** |
| 41 |
* The loader that's responsible for maintaining and registering all hooks that power |
| 42 |
* the plugin. |
| 43 |
* |
| 44 |
* @since 3.0.1 |
| 45 |
* @access protected |
| 46 |
* @var Wpstream_Loader $loader Maintains and registers all hooks for the plugin. |
| 47 |
*/ |
| 48 |
protected $loader; |
| 49 |
|
| 50 |
/** |
| 51 |
* The unique identifier of this plugin. |
| 52 |
* |
| 53 |
* @since 3.0.1 |
| 54 |
* @access protected |
| 55 |
* @var string $plugin_name The string used to uniquely identify this plugin. |
| 56 |
*/ |
| 57 |
protected $plugin_name; |
| 58 |
|
| 59 |
/** |
| 60 |
* The current version of the plugin. |
| 61 |
* |
| 62 |
* @since 3.0.1 |
| 63 |
* @access protected |
| 64 |
* @var string $version The current version of the plugin. |
| 65 |
*/ |
| 66 |
protected $version; |
| 67 |
|
| 68 |
/** |
| 69 |
* Define the core functionality of the plugin. |
| 70 |
* |
| 71 |
* Set the plugin name and the plugin version that can be used throughout the plugin. |
| 72 |
* Load the dependencies, define the locale, and set the hooks for the admin area and |
| 73 |
* the public-facing side of the site. |
| 74 |
* |
| 75 |
* @since 3.0.1 |
| 76 |
*/ |
| 77 |
|
| 78 |
public $wpstream_live_connection; |
| 79 |
public $wpstream_player; |
| 80 |
public $xtest; |
| 81 |
public $plugin_admin; |
| 82 |
|
| 83 |
public function __construct() { |
| 84 |
$this->main = $this; |
| 85 |
if ( defined( 'WPSTREAM_VERSION' ) ) { |
| 86 |
$this->version = WPSTREAM_VERSION; |
| 87 |
} else { |
| 88 |
$this->version = '3.0.1'; |
| 89 |
} |
| 90 |
$this->plugin_name = 'wpstream'; |
| 91 |
|
| 92 |
$this->load_dependencies(); |
| 93 |
$this->set_locale(); |
| 94 |
$this->define_admin_hooks(); |
| 95 |
$this->define_public_hooks(); |
| 96 |
|
| 97 |
$this->xtest = "this is test2"; |
| 98 |
$this->wpstream_conection(); |
| 99 |
$this->wpstream_player(); |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public function wpstream_convert_band($megabits){ |
| 108 |
$gigabit = $megabits * 0.001; |
| 109 |
$gigabit = number_format($gigabit,2); |
| 110 |
return $gigabit; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
private function wpstream_conection(){ |
| 118 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-live-api-connection.php'; |
| 119 |
$this->wpstream_live_connection = new Wpstream_Live_Api_Connection(); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
private function wpstream_player(){ |
| 124 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-player.php'; |
| 125 |
$this->wpstream_player = new Wpstream_Player($this->main); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
/** |
| 132 |
* Load the required dependencies for this plugin. |
| 133 |
* |
| 134 |
* Include the following files that make up the plugin: |
| 135 |
* |
| 136 |
* - Wpstream_Loader. Orchestrates the hooks of the plugin. |
| 137 |
* - Wpstream_i18n. Defines internationalization functionality. |
| 138 |
* - Wpstream_Admin. Defines all hooks for the admin area. |
| 139 |
* - Wpstream_Public. Defines all hooks for the public side of the site. |
| 140 |
* |
| 141 |
* Create an instance of the loader which will be used to register the hooks |
| 142 |
* with WordPress. |
| 143 |
* |
| 144 |
* @since 3.0.1 |
| 145 |
* @access private |
| 146 |
*/ |
| 147 |
private function load_dependencies() { |
| 148 |
|
| 149 |
/** |
| 150 |
* The class responsible for orchestrating the actions and filters of the |
| 151 |
* core plugin. |
| 152 |
*/ |
| 153 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-loader.php'; |
| 154 |
|
| 155 |
/** |
| 156 |
* The class responsible for defining internationalization functionality |
| 157 |
* of the plugin. |
| 158 |
*/ |
| 159 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream-i18n.php'; |
| 160 |
|
| 161 |
/** |
| 162 |
* The class responsible for defining all actions that occur in the admin area. |
| 163 |
*/ |
| 164 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wpstream-admin.php'; |
| 165 |
|
| 166 |
/** |
| 167 |
* The class responsible for defining all actions that occur in the public-facing |
| 168 |
* side of the site. |
| 169 |
*/ |
| 170 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpstream-public.php'; |
| 171 |
|
| 172 |
/** |
| 173 |
* The class responsible for custom post type |
| 174 |
|
| 175 |
*/ |
| 176 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpstream_product.php'; |
| 177 |
if( class_exists( 'WooCommerce' ) ){ |
| 178 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_live_stream.php'; |
| 179 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wc_product_video_on_demand.php'; |
| 180 |
} |
| 181 |
|
| 182 |
$this->loader = new Wpstream_Loader(); |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Define the locale for this plugin for internationalization. |
| 188 |
* |
| 189 |
* Uses the Wpstream_i18n class in order to set the domain and to register the hook |
| 190 |
* with WordPress. |
| 191 |
* |
| 192 |
* @since 3.0.1 |
| 193 |
* @access private |
| 194 |
*/ |
| 195 |
private function set_locale() { |
| 196 |
|
| 197 |
$plugin_i18n = new Wpstream_i18n(); |
| 198 |
|
| 199 |
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* Register all of the hooks related to the admin area functionality |
| 205 |
* of the plugin. |
| 206 |
* |
| 207 |
* @since 3.0.1 |
| 208 |
* @access private |
| 209 |
*/ |
| 210 |
private function define_admin_hooks() { |
| 211 |
|
| 212 |
$this->admin= $plugin_admin = new Wpstream_Admin( $this->get_plugin_name(), $this->get_version(), $this->main ); |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
| 217 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 218 |
$this->loader->add_action( 'admin_menu', $plugin_admin, 'wpstream_manage_admin_menu',999); |
| 219 |
|
| 220 |
$plugin_post_types = new Wpstream_Product(); |
| 221 |
$this->loader->add_action( 'init', $plugin_post_types, 'create_custom_post_type', 999 ); |
| 222 |
|
| 223 |
// save and render metaboxed |
| 224 |
$this->loader->add_action( 'admin_init', $plugin_admin, 'add_wpstream_product_metaboxes' ); |
| 225 |
$this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_free_product_update_post',1,2 ); |
| 226 |
|
| 227 |
// make product virtual |
| 228 |
$this->loader->add_action( 'save_post', $plugin_admin, 'wpstream_make_product_virtual', 99999, 2 ); |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
// show streaming controls on sidebar |
| 233 |
$this->loader->add_action('add_meta_boxes', $plugin_admin, 'wpstream_startstreaming_sidebar_meta'); |
| 234 |
|
| 235 |
|
| 236 |
$this->loader->add_action( 'admin_notices', $plugin_admin,'wpstream_admin_notice' ); |
| 237 |
$this->loader->add_action( 'wp_ajax_wpstream_update_cache_notice', $plugin_admin,'wpstream_update_cache_notice' ); |
| 238 |
|
| 239 |
// add and save category extra fields |
| 240 |
$this->loader->add_action( 'category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2); |
| 241 |
$this->loader->add_action( 'category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 ); |
| 242 |
$this->loader->add_action( 'created_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 243 |
$this->loader->add_action( 'edited_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 244 |
|
| 245 |
$this->loader->add_action( 'product_cat_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2); |
| 246 |
$this->loader->add_action( 'product_cat_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 ); |
| 247 |
$this->loader->add_action( 'created_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 248 |
$this->loader->add_action( 'edited_product_cat', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 249 |
|
| 250 |
|
| 251 |
$this->loader->add_action( 'wpstream_category_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2); |
| 252 |
$this->loader->add_action( 'wpstream_category_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 ); |
| 253 |
$this->loader->add_action( 'created_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 254 |
$this->loader->add_action( 'edited_wpstream_category', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 255 |
|
| 256 |
|
| 257 |
$this->loader->add_action( 'wpstream_actors_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2); |
| 258 |
$this->loader->add_action( 'wpstream_actors_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 ); |
| 259 |
$this->loader->add_action( 'created_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 260 |
$this->loader->add_action( 'edited_wpstream_actors', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 261 |
|
| 262 |
$this->loader->add_action( 'wpstream_movie_rating_edit_form_fields', $plugin_post_types, 'wpstream_category_callback_function', 10, 2); |
| 263 |
$this->loader->add_action( 'wpstream_movie_rating_add_form_fields', $plugin_post_types, 'wpstream_category_callback_add_function', 10, 2 ); |
| 264 |
$this->loader->add_action( 'created_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 265 |
$this->loader->add_action( 'edited_wpstream_movie_rating', $plugin_post_types, 'wpstream_category_save_extra_fields_callback', 10, 2); |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { |
| 271 |
|
| 272 |
$this->loader->add_filter( 'product_type_selector', $plugin_admin, 'wpstream_add_products' ); |
| 273 |
$this->loader->add_action( 'admin_footer', $plugin_admin, 'wpstream_products_custom_js' ); |
| 274 |
$this->loader->add_filter( 'woocommerce_product_data_tabs', $plugin_admin, 'wpstream_hide_attributes_data_panel',10,1 ); |
| 275 |
|
| 276 |
$this->loader->add_filter( 'woocommerce_product_options_general_product_data',$plugin_admin, 'wpstream_add_custom_general_fields', 10,1); |
| 277 |
$this->loader->add_filter( 'woocommerce_process_product_meta',$plugin_admin, 'wpstream_add_custom_general_fields_save',10,1 ); |
| 278 |
$this->loader->add_action( 'woocommerce_live_stream_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1); |
| 279 |
$this->loader->add_action( 'woocommerce_video_on_demand_add_to_cart', $plugin_admin, 'wpstream_add_to_cart',10,1); |
| 280 |
$this->loader->add_filter( 'woocommerce_loop_add_to_cart_link', $plugin_admin,'replacing_add_to_cart_button', 10, 2 ); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
} |
| 289 |
|
| 290 |
/** |
| 291 |
* Register all of the hooks related to the public-facing functionality |
| 292 |
* of the plugin. |
| 293 |
* |
| 294 |
* @since 3.0.1 |
| 295 |
* @access private |
| 296 |
*/ |
| 297 |
private function define_public_hooks() { |
| 298 |
|
| 299 |
$plugin_public = new Wpstream_Public( $this->get_plugin_name(), $this->get_version(), $this->main ); |
| 300 |
|
| 301 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 302 |
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 303 |
|
| 304 |
$this->loader->add_action( 'init', $plugin_public,'wpstream_my_custom_endpoints' ); |
| 305 |
$this->loader->add_filter( 'query_vars',$plugin_public, 'wpstream_my_custom_query_vars', 0 ); |
| 306 |
|
| 307 |
//live stream action |
| 308 |
$this->loader->add_action('init',$plugin_public,'wpstream_set_cookies',0); |
| 309 |
$this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key'); |
| 310 |
$this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_for_3rdparty'); |
| 311 |
$this->loader->add_action('init',$plugin_public,'wpstream_live_streaming_key_vod'); |
| 312 |
// woo action |
| 313 |
|
| 314 |
$this->loader->add_action( 'woocommerce_before_single_product', $plugin_public,'wpstream_non_image_content_wrapper_start', 20 ); |
| 315 |
$this->loader->add_action( 'woocommerce_after_single_product', $plugin_public,'wpstream_non_image_content_wrapper_end', 20 ); |
| 316 |
|
| 317 |
$this->loader->add_filter( 'woocommerce_account_menu_items', $plugin_public,'wpstream_custom_my_account_menu_items' ); |
| 318 |
$this->loader->add_action( 'woocommerce_account_event-list_endpoint', $plugin_public,'wpstream_custom_endpoint_content_event_list' ); |
| 319 |
$this->loader->add_action( 'woocommerce_account_video-list_endpoint', $plugin_public,'wpstream_custom_endpoint_video_list' ); |
| 320 |
|
| 321 |
|
| 322 |
$this->loader->add_action( 'after_switch_theme', $plugin_public,'wpstream_custom_flush_rewrite_rules' ); |
| 323 |
$this->loader->add_action('init', $plugin_public,'wpstream_shortcodes'); |
| 324 |
|
| 325 |
$this->loader->add_action('wo_before_api', 'wpstream_cors_check_and_response',10,1); |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
/** |
| 332 |
* Run the loader to execute all of the hooks with WordPress. |
| 333 |
* |
| 334 |
* @since 3.0.1 |
| 335 |
*/ |
| 336 |
public function run() { |
| 337 |
$this->loader->run(); |
| 338 |
} |
| 339 |
|
| 340 |
/** |
| 341 |
* The name of the plugin used to uniquely identify it within the context of |
| 342 |
* WordPress and to define internationalization functionality. |
| 343 |
* |
| 344 |
* @since 3.0.1 |
| 345 |
* @return string The name of the plugin. |
| 346 |
*/ |
| 347 |
public function get_plugin_name() { |
| 348 |
return $this->plugin_name; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* The reference to the class that orchestrates the hooks with the plugin. |
| 353 |
* |
| 354 |
* @since 3.0.1 |
| 355 |
* @return Wpstream_Loader Orchestrates the hooks of the plugin. |
| 356 |
*/ |
| 357 |
public function get_loader() { |
| 358 |
return $this->loader; |
| 359 |
} |
| 360 |
|
| 361 |
/** |
| 362 |
* Retrieve the version number of the plugin. |
| 363 |
* |
| 364 |
* @since 3.0.1 |
| 365 |
* @return string The version number of the plugin. |
| 366 |
*/ |
| 367 |
public function get_version() { |
| 368 |
return $this->version; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
public function show_user_data($pack_details){ |
| 374 |
if( isset($pack_details['band']) && isset( $pack_details['storage']) ){ |
| 375 |
$wpstream_convert_band = $this->wpstream_convert_band($pack_details['band']); |
| 376 |
if($wpstream_convert_band<0)$wpstream_convert_band=0; |
| 377 |
|
| 378 |
$wpstream_convert_storage = $this->wpstream_convert_band($pack_details['storage']); |
| 379 |
if($wpstream_convert_storage<0)$wpstream_convert_storage=0; |
| 380 |
|
| 381 |
print '<div class="pack_details_wrapper"><strong>'.__('Your account information: ','wpstream').'</strong> '.__('You have','wpstream').'<strong> '.$wpstream_convert_band.' Gb</strong> '.__('available streaming bandwidth and','wpstream').' <strong>'.$wpstream_convert_storage.' Gb</strong> '.__('available media storage','wpstream').'.</div>'; |
| 382 |
print'<input type="hidden" id="wpstream_band" value="'.$pack_details['band'].'">'; |
| 383 |
print'<input type="hidden" id="wpstream_storage" value="'.$pack_details['storage'].'">'; |
| 384 |
|
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
/** |
| 390 |
* help function for player elementr widget |
| 391 |
* |
| 392 |
* @since 3.0.1 |
| 393 |
* @return string |
| 394 |
*/ |
| 395 |
|
| 396 |
public function wpstream_insert_player_elementor($attributes, $content = null){ |
| 397 |
$product_id = ''; |
| 398 |
$return_string = ''; |
| 399 |
$attributes = shortcode_atts( |
| 400 |
array( |
| 401 |
'id' => 0, |
| 402 |
'user_id' => 0, |
| 403 |
), $attributes) ; |
| 404 |
|
| 405 |
|
| 406 |
if ( isset($attributes['id']) ){ |
| 407 |
$product_id=$attributes['id']; |
| 408 |
} |
| 409 |
if ( isset($attributes['user_id']) ){ |
| 410 |
$user_id = intval( $attributes['user_id'] ); |
| 411 |
} |
| 412 |
|
| 413 |
if(intval($product_id)==0 && $user_id!=0 ){ |
| 414 |
$product_id= $this->wpstream_player_retrive_first_id($user_id); |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
ob_start(); |
| 421 |
$this->main->wpstream_player->wpstream_video_player_shortcode($product_id); |
| 422 |
$return_string= ob_get_contents(); |
| 423 |
ob_end_clean(); |
| 424 |
|
| 425 |
return $return_string; |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* help function for player low latency elementor widget |
| 430 |
* |
| 431 |
* @since 3.0.1 |
| 432 |
* @return string |
| 433 |
*/ |
| 434 |
|
| 435 |
public function wpstream_insert_player__low_latency_elementor($attributes, $content = null){ |
| 436 |
$product_id = ''; |
| 437 |
$return_string = ''; |
| 438 |
$attributes = shortcode_atts( |
| 439 |
array( |
| 440 |
'id' => 0, |
| 441 |
'user_id' => 0, |
| 442 |
), $attributes) ; |
| 443 |
|
| 444 |
|
| 445 |
if ( isset($attributes['id']) ){ |
| 446 |
$product_id=$attributes['id']; |
| 447 |
} |
| 448 |
|
| 449 |
if ( isset($attributes['user_id']) ){ |
| 450 |
$user_id = intval( $attributes['user_id'] ); |
| 451 |
} |
| 452 |
|
| 453 |
if(intval($product_id)==0 && $user_id!=0){ |
| 454 |
$product_id= $this->wpstream_player_retrive_first_id($user_id); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
ob_start(); |
| 459 |
$this->main->wpstream_player->wpstream_video_player_shortcode_low_latency($product_id); |
| 460 |
$return_string= ob_get_contents(); |
| 461 |
ob_end_clean(); |
| 462 |
|
| 463 |
return $return_string; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
public function wpstream_player_retrive_first_id($received_user_id=''){ |
| 469 |
$channel_type = get_option ('wpstream_user_streaming_channel_type'); |
| 470 |
$product_id = $this->wpstream_get_current_event_per_author($received_user_id,$channel_type); |
| 471 |
return $product_id; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
/** |
| 477 |
* help function for chat elementor widget |
| 478 |
* |
| 479 |
* @since 3.0.1 |
| 480 |
* @return string |
| 481 |
*/ |
| 482 |
|
| 483 |
public function wpstream_insert_chat_elementor($attributes, $content = null){ |
| 484 |
$product_id = ''; |
| 485 |
$return_string = ''; |
| 486 |
$attributes = shortcode_atts( |
| 487 |
array( |
| 488 |
'id' => 0, |
| 489 |
), $attributes) ; |
| 490 |
|
| 491 |
|
| 492 |
if ( isset($attributes['id']) ){ |
| 493 |
$product_id=$attributes['id']; |
| 494 |
} |
| 495 |
|
| 496 |
$return_string.= '<div class="wpstream_plugin_chat_wrapper">'; |
| 497 |
ob_start(); |
| 498 |
$this->main->wpstream_player->wpstream_chat_wrapper($product_id); |
| 499 |
$return_string.= ob_get_contents(); |
| 500 |
ob_end_clean(); |
| 501 |
$return_string.='</div>'; |
| 502 |
$this->main->wpstream_player->wpstream_connect_to_chat($product_id); |
| 503 |
|
| 504 |
return $return_string; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
/** |
| 509 |
* Check if user is allowed to stream |
| 510 |
* |
| 511 |
* @since 3.7 |
| 512 |
*/ |
| 513 |
|
| 514 |
public function wpstream_check_user_can_stream(){ |
| 515 |
$current_user = wp_get_current_user(); |
| 516 |
|
| 517 |
if( !is_user_logged_in() ){ |
| 518 |
return false; |
| 519 |
exit('user not logged in 497'); |
| 520 |
} |
| 521 |
|
| 522 |
if(current_user_can('administrator')){ |
| 523 |
// admins can always brodcast |
| 524 |
return true; |
| 525 |
} |
| 526 |
|
| 527 |
$extra_roles = get_option( 'wpstream_stream_role', true ); |
| 528 |
$user_role = $current_user->roles[0]; |
| 529 |
|
| 530 |
if (is_array($extra_roles) && in_array($user_role, $extra_roles)){ |
| 531 |
return true; |
| 532 |
} |
| 533 |
|
| 534 |
if(function_exists('wpstream_get_option') && intval(wpstream_get_option('allow_streaming_regular_users',''))==1 ){ |
| 535 |
return true; |
| 536 |
} |
| 537 |
|
| 538 |
return false; |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
/** |
| 543 |
* Start Streaming wrapper |
| 544 |
* |
| 545 |
* @since 3.7 |
| 546 |
*/ |
| 547 |
|
| 548 |
public function wpstream_live_stream_unit_wrapper($item_id,$type){ |
| 549 |
$item_id = intval($item_id); |
| 550 |
|
| 551 |
if($item_id == 0){ |
| 552 |
//retrive or create channel for front end streamers |
| 553 |
$item_id=$this->wpstream_retrive_front_end_channel(); |
| 554 |
} |
| 555 |
|
| 556 |
$this->admin->wpstream_live_stream_unit( $item_id,$type ); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
/** |
| 564 |
* retrive channel for front end streaming |
| 565 |
* |
| 566 |
* @since 3.7 |
| 567 |
*/ |
| 568 |
public function wpstream_retrive_front_end_channel(){ |
| 569 |
|
| 570 |
$current_user = wp_get_current_user(); |
| 571 |
$channel_type = get_option ('wpstream_user_streaming_channel_type'); |
| 572 |
$channel_price = floatval( get_option ('wpstream_user_streaming_default_price') ); |
| 573 |
|
| 574 |
$front_end_streamin_channel = $this->wpstream_get_current_event_per_author($current_user->ID,$channel_type); |
| 575 |
|
| 576 |
if(intval($front_end_streamin_channel) == 0){ |
| 577 |
$front_end_streamin_channel= $this->wpstrea_create_front_end_event($current_user->ID,$current_user->user_login ,$channel_type,$channel_price); |
| 578 |
} |
| 579 |
return $front_end_streamin_channel; |
| 580 |
|
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* create the event from front end |
| 585 |
* |
| 586 |
* @since 3.7 |
| 587 |
*/ |
| 588 |
|
| 589 |
public function wpstrea_create_front_end_event($userID,$userLogin,$channel_type,$channel_price){ |
| 590 |
|
| 591 |
if( !$this->wpstream_check_user_can_stream() ){ |
| 592 |
return; |
| 593 |
} |
| 594 |
|
| 595 |
$post_type='wpstream_product'; |
| 596 |
if($channel_type=='paid'){ |
| 597 |
$post_type='product'; |
| 598 |
} |
| 599 |
|
| 600 |
$post = array( |
| 601 |
'post_title' => sprintf( esc_html__('%s Channel','wpstream'),$userLogin), |
| 602 |
'post_content' => '', |
| 603 |
'post_type' => $post_type , |
| 604 |
'post_author' => $userID, |
| 605 |
'post_status' => 'publish', |
| 606 |
); |
| 607 |
$post_id = wp_insert_post($post ); |
| 608 |
if($channel_type=='paid'){ |
| 609 |
$product = wc_get_product($post_id); |
| 610 |
$price = wc_format_decimal($channel_price); |
| 611 |
|
| 612 |
$product = wc_get_product( $post_id ); |
| 613 |
// Set the product active price (regular) |
| 614 |
$product->set_price( $price ); |
| 615 |
$product->set_regular_price( $price ); // To be sure |
| 616 |
$product->save(); |
| 617 |
update_post_meta ($post_id,'event_passed',0); |
| 618 |
wp_set_object_terms( $post_id, 'live_stream', 'product_type' ); |
| 619 |
} |
| 620 |
update_post_meta($post_id,'wpstream_product_type',1); |
| 621 |
|
| 622 |
return $post_id; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
public function wpstream_get_current_event_per_author($userID,$channel_type){ |
| 627 |
|
| 628 |
$post_type='wpstream_product'; |
| 629 |
if($channel_type=='paid'){ |
| 630 |
$post_type='product'; |
| 631 |
} |
| 632 |
|
| 633 |
$args = array( |
| 634 |
|
| 635 |
'post_type' => $post_type, |
| 636 |
'author' => $userID, |
| 637 |
'posts_per_page' => 1, |
| 638 |
'fields' => 'ids' |
| 639 |
) |
| 640 |
; |
| 641 |
$author_posts = new WP_Query( $args ); |
| 642 |
if( $author_posts->have_posts() ) { |
| 643 |
$author_posts->the_post(); |
| 644 |
return get_the_ID(); |
| 645 |
}else{ |
| 646 |
return 0; |
| 647 |
} |
| 648 |
|
| 649 |
wp_reset_query(); |
| 650 |
wp_reset_postdata(); |
| 651 |
} |
| 652 |
|
| 653 |
} |
| 654 |
|