| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
function wpstream_shortcodes(){ |
| 5 |
wpstream_register_shortcodes(); |
| 6 |
wpstream_tiny_short_codes_register(); |
| 7 |
} |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
function wpstream_register_shortcodes() { |
| 12 |
add_shortcode('wpstream_player', 'wpstream_insert_player_inpage'); |
| 13 |
add_shortcode('wpstream_list_products', 'wpstream_list_products_function'); |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
function wpstream_tiny_short_codes_register() { |
| 19 |
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
if (get_user_option('rich_editing') == 'true') { |
| 24 |
add_filter('mce_external_plugins', 'wpstream_add_plugin'); |
| 25 |
add_filter('mce_buttons_2', 'wpstream_register_button'); |
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
function wpstream_register_button($buttons) { |
| 33 |
array_push($buttons, "|", "wpstream_player"); |
| 34 |
array_push($buttons, "|", "wpstream_list_products"); |
| 35 |
return $buttons; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
function wpstream_add_plugin($plugin_array) { |
| 41 |
$plugin_array['wpstream_player'] = WPSTREAM_PLUGIN_DIR_URL. '/js/shortcodes.js'; |
| 42 |
$plugin_array['wpstream_list_products'] = WPSTREAM_PLUGIN_DIR_URL. '/js/shortcodes.js'; |
| 43 |
return $plugin_array; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
function wpstream_insert_player_inpage($attributes, $content = null){ |
| 51 |
$product_id = ''; |
| 52 |
$return_string = ''; |
| 53 |
$attributes = shortcode_atts( |
| 54 |
array( |
| 55 |
'id' => 0, |
| 56 |
), $attributes) ; |
| 57 |
|
| 58 |
|
| 59 |
if ( isset($attributes['id']) ){ |
| 60 |
$product_id=$attributes['id']; |
| 61 |
} |
| 62 |
|
| 63 |
ob_start(); |
| 64 |
wpstream_video_player_shortcode($product_id); |
| 65 |
$return_string= ob_get_contents(); |
| 66 |
ob_end_clean(); |
| 67 |
|
| 68 |
return $return_string; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
function wpstream_video_player_shortcode($from_sh_id='') { |
| 75 |
|
| 76 |
if ( is_user_logged_in() ) { |
| 77 |
global $product; |
| 78 |
$current_user = wp_get_current_user(); |
| 79 |
$product_id = intval($from_sh_id); |
| 80 |
|
| 81 |
|
| 82 |
if ( ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product_id) ) || get_post_type($product_id)=='wpstream_product' ){ |
| 83 |
global $product; |
| 84 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode"><div class="wpstream_player_container">'; |
| 85 |
|
| 86 |
|
| 87 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 88 |
|
| 89 |
$wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true)); |
| 90 |
if($wpstream_product_type==1){ |
| 91 |
wpstream_live_event_player($product_id); |
| 92 |
} else if($wpstream_product_type==2 || $wpstream_product_type==3){ |
| 93 |
wpstream_video_on_demand_player($product_id); |
| 94 |
} |
| 95 |
|
| 96 |
}else{ |
| 97 |
$term_list = wp_get_post_terms($product_id, 'product_type'); |
| 98 |
$is_subscription_live_event = esc_html(get_post_meta($product_id,'_subscript_live_event',true)); |
| 99 |
|
| 100 |
if( $term_list[0]->name=='live_stream' || ( $term_list[0]->name=='subscription' && $is_subscription_live_event=='yes' ) ){ |
| 101 |
wpstream_live_event_player($product_id); |
| 102 |
}else if( $term_list[0]->name=='video_on_demand' || ($term_list[0]->name=='subscription' && $is_subscription_live_event=='no' ) ){ |
| 103 |
wpstream_video_on_demand_player($product_id); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
}else{ |
| 110 |
$thumb_id = get_post_thumbnail_id($product_id); |
| 111 |
$thumb = wp_get_attachment_image_src($thumb_id,'medium_large'); |
| 112 |
|
| 113 |
echo '<div class="wpstream_player_wrapper wpstream_player_shortcode no_buy"><div class="wpstream_player_container">'; |
| 114 |
echo '<div class="wpstream_notice">'.__('You did not buy this product!','wpstream'). |
| 115 |
'</div><img src="'.$thumb[0].'" alt="product_thumb">'; |
| 116 |
} |
| 117 |
|
| 118 |
echo '</div></div>'; |
| 119 |
}else{ |
| 120 |
$product_id = intval($from_sh_id); |
| 121 |
if( get_post_type($product_id) == 'wpstream_product' ){ |
| 122 |
|
| 123 |
$wpstream_product_type = esc_html(get_post_meta($product_id, 'wpstream_product_type', true)); |
| 124 |
if($wpstream_product_type==1){ |
| 125 |
wpstream_live_event_player($product_id); |
| 126 |
} else if($wpstream_product_type==2 || $wpstream_product_type==3){ |
| 127 |
wpstream_video_on_demand_player($product_id); |
| 128 |
} |
| 129 |
|
| 130 |
} |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
function wpestate_stream_validate_keys($attributes, $content = null){ |
| 143 |
global $wp_query; |
| 144 |
$current_user = wp_get_current_user(); |
| 145 |
$stream_key = $wp_query->query_vars['streamname']; |
| 146 |
$stream_key_array = explode('-', $stream_key); |
| 147 |
$real_stream_key = $stream_key_array[0]; |
| 148 |
|
| 149 |
|
| 150 |
if ( is_user_logged_in() && intval($current_user->ID)!=0 ) { |
| 151 |
|
| 152 |
$args = array( |
| 153 |
'posts_per_page' => -1, |
| 154 |
'post_type' => 'product', |
| 155 |
'meta_query' => array( |
| 156 |
array( |
| 157 |
'key' => 'live_event_stream_name', |
| 158 |
'value' => $real_stream_key, |
| 159 |
'compare' => '=', |
| 160 |
), |
| 161 |
), |
| 162 |
'tax_query' => array( |
| 163 |
'relation' => 'AND', |
| 164 |
array( |
| 165 |
'taxonomy' => 'product_type', |
| 166 |
'field' => 'slug', |
| 167 |
'terms' => 'live_stream' |
| 168 |
) |
| 169 |
), |
| 170 |
); |
| 171 |
|
| 172 |
|
| 173 |
$event_list = new WP_Query($args); |
| 174 |
|
| 175 |
if ($event_list->have_posts() ){ |
| 176 |
while ( $event_list->have_posts() ): |
| 177 |
$event_list->the_post(); |
| 178 |
$the_id = get_the_ID(); |
| 179 |
$event_data = get_post_meta($the_id,'live_event_uri',true); |
| 180 |
$show_id = $event_data['show_id']; |
| 181 |
|
| 182 |
endwhile; |
| 183 |
$get_key = wpstream_get_encryption_key($stream_key,$event_data['ip']); |
| 184 |
return $get_key; |
| 185 |
} else{ |
| 186 |
exit('not query'); |
| 187 |
} |
| 188 |
|
| 189 |
}else{ |
| 190 |
exit('not log'); |
| 191 |
} |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
function wpstream_list_products_function($atts, $content=null){ |
| 204 |
|
| 205 |
$media_number = ""; |
| 206 |
$product_type = ""; |
| 207 |
$attributes = shortcode_atts( |
| 208 |
array( |
| 209 |
'media_number' => '4', |
| 210 |
'product_type' => __('Free Live Channel','wpstream'), |
| 211 |
|
| 212 |
), $atts); |
| 213 |
|
| 214 |
if ( isset($attributes['media_number']) ){ |
| 215 |
$media_number=$attributes['media_number']; |
| 216 |
} |
| 217 |
|
| 218 |
if ( isset($attributes['product_type']) ){ |
| 219 |
$product_type=$attributes['product_type']; |
| 220 |
} |
| 221 |
|
| 222 |
if($product_type== __('Free Live Channel','wpstream') ){ |
| 223 |
$product_type=1; |
| 224 |
}else{ |
| 225 |
$product_type=2; |
| 226 |
} |
| 227 |
|
| 228 |
$return_string=""; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
$args = array( |
| 233 |
'post_type' => 'wpstream_product', |
| 234 |
'post_status' => 'publish', |
| 235 |
'meta_query' =>array( |
| 236 |
array( |
| 237 |
'key' => 'wpstream_product_type', |
| 238 |
'value' => $product_type, |
| 239 |
'compare' => '=', |
| 240 |
), |
| 241 |
), |
| 242 |
'post_per_page' =>$media_number |
| 243 |
); |
| 244 |
|
| 245 |
|
| 246 |
$media_list= new WP_Query($args); |
| 247 |
|
| 248 |
if($product_type==1){ |
| 249 |
$see_product= __('See Free Live Chanel','wpstream'); |
| 250 |
}else{ |
| 251 |
$see_product =_('See Free Video','wpstream'); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
while($media_list->have_posts()):$media_list->the_post(); |
| 257 |
$return_string.='<div class="wpstream_product_unit">' |
| 258 |
.'<div class="product_image" style="background-image:url('.wp_get_attachment_thumb_url(get_post_thumbnail_id()).')"></div>' |
| 259 |
.'<a href="'.get_permalink().'" class="product_title" >'.get_the_title().'</a>' |
| 260 |
.'<a href="'.get_permalink().'"class="see_product">'.$see_product.'</a>' |
| 261 |
.'</div>'; |
| 262 |
endwhile; |
| 263 |
|
| 264 |
wp_reset_postdata(); |
| 265 |
wp_reset_query(); |
| 266 |
|
| 267 |
|
| 268 |
return '<div class="shortcode_list_wrapper">'.$return_string.'</div>'; |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
if( function_exists('vc_map') ): |
| 276 |
vc_map( |
| 277 |
array( |
| 278 |
"name" => esc_html__( "WpStream Player","wpestate"), |
| 279 |
"base" => "wpstream_player", |
| 280 |
"class" => "", |
| 281 |
"category" => esc_html__( 'WpStream','wpestate'), |
| 282 |
'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'), |
| 283 |
'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'), |
| 284 |
'weight'=>100, |
| 285 |
'icon' =>'', |
| 286 |
'description'=>esc_html__( 'Insert WpStream Player','wpestate'), |
| 287 |
"params" => array( |
| 288 |
array( |
| 289 |
"type" => "textfield", |
| 290 |
"holder" => "div", |
| 291 |
"class" => "", |
| 292 |
"heading" => esc_html__( "Content Id","wpestate"), |
| 293 |
"param_name" => "id", |
| 294 |
"value" => "0", |
| 295 |
"description" => esc_html__( "Add here the live stream id or the video id","wpestate") |
| 296 |
), |
| 297 |
|
| 298 |
) |
| 299 |
) |
| 300 |
); |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
$product_type=array( |
| 305 |
'1' => __('Free Live Channel','wpstream'), |
| 306 |
'2' => __('Free Video','wpstream') |
| 307 |
); |
| 308 |
|
| 309 |
vc_map( |
| 310 |
array( |
| 311 |
"name" => esc_html__( "WpStream Products List","wpestate"), |
| 312 |
"base" => "wpstream_list_products", |
| 313 |
"class" => "", |
| 314 |
"category" => esc_html__( 'WpStream','wpestate'), |
| 315 |
'admin_enqueue_js' => array(get_template_directory_uri().'/vc_extend/bartag.js'), |
| 316 |
'admin_enqueue_css' => array(get_template_directory_uri().'/vc_extend/bartag.css'), |
| 317 |
'weight'=>100, |
| 318 |
'icon' =>'', |
| 319 |
'description'=>esc_html__( ' List wpstream products','wpestate'), |
| 320 |
"params" => array( |
| 321 |
array( |
| 322 |
"type" => "textfield", |
| 323 |
"holder" => "div", |
| 324 |
"class" => "", |
| 325 |
"heading" => esc_html__( "Media number","wpestate"), |
| 326 |
"param_name" => "media_number", |
| 327 |
"value" => "", |
| 328 |
"description" => esc_html__( "No of media ","wpestate") |
| 329 |
), |
| 330 |
|
| 331 |
array( |
| 332 |
"type" => "dropdown", |
| 333 |
"holder" => "div", |
| 334 |
"class" => "", |
| 335 |
"heading" => esc_html__( "Product type","wpestate"), |
| 336 |
"param_name" => "product_type", |
| 337 |
"value" => $product_type, |
| 338 |
"description" => esc_html__( "What type of products ","wpestate") |
| 339 |
), |
| 340 |
|
| 341 |
) |
| 342 |
) |
| 343 |
); |
| 344 |
endif; |