PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.13.2
WpStream – Live Streaming, Video on Demand, Pay Per View v4.13.2
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 / widgets / start_streaming.php

start_streaming.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.13.2, at widgets/start_streaming.php

252 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor widget: WpStream - Start Streaming.
4 *
5 * Registers the "Start Streaming" Elementor widget under the plugin's own
6 * widget category. It exposes a single product/free-product id control and,
7 * on render, delegates to the plugin's live-stream unit wrapper to print the
8 * broadcaster UI for that channel (or the user's first free/paid channel).
9 *
10 * @package Wpstream
11 * @subpackage Wpstream/widgets
12 */
13 namespace ElementorWpStream\Widgets;
14
15 use Elementor\Widget_Base;
16 use Elementor\Controls_Manager;
17
18 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
19
20
21 /**
22 * Elementor widget class for the WpStream broadcaster (start streaming).
23 *
24 * Implements the standard Elementor widget contract: identity (name/title/icon),
25 * editor controls, frontend render, and the editor preview template.
26 */
27 class Wpstream_Start_Streaming_Base extends Widget_Base {
28
29 /**
30 * Retrieve the widget name.
31 *
32 * @since 1.0.0
33 *
34 * @access public
35 *
36 * @return string Widget name.
37 */
38 public function get_name() {
39 // Internal identifier Elementor uses to reference this widget.
40 return 'Wpstream_Start_Streaming';
41 }
42
43 /**
44 * Retrieve the widget categories.
45 *
46 * @return array List of Elementor category slugs this widget belongs to.
47 */
48 public function get_categories() {
49 // Group this widget under the plugin's own "wpstream" category.
50 return [ 'wpstream' ];
51 }
52
53
54 /**
55 * Retrieve the widget title.
56 *
57 * @since 1.0.0
58 *
59 * @access public
60 *
61 * @return string Widget title.
62 */
63 public function get_title() {
64 // Wrap the translated label in the theme's widget-title markup.
65 return '<div class="wpestate_elementor_widget_title">'.__( 'WpStream - Start Streaming', 'wpstream' ).'</div>';
66 }
67
68 /**
69 * Retrieve the widget icon.
70 *
71 * @since 1.0.0
72 *
73 * @access public
74 *
75 * @return string Widget icon.
76 */
77 public function get_icon() {
78 // Elementor icon-font class shown for this widget in the panel.
79 return 'eicon-play-o';
80 }
81
82
83
84 /**
85 * Retrieve the list of scripts the widget depended on.
86 *
87 * Used to set scripts dependencies required to run the widget.
88 *
89 * @since 1.0.0
90 *
91 * @access public
92 *
93 * @return array Widget scripts dependencies.
94 */
95 public function get_script_depends() {
96 // No extra script handles are registered as dependencies.
97 return [ '' ];
98 }
99
100 /**
101 * Register the widget controls.
102 *
103 * Adds different input fields to allow the user to change and customize the widget settings.
104 *
105 * @since 1.0.0
106 *
107 * @access protected
108 */
109
110 /**
111 * Flatten a list of {value,label} pairs into a value => label map.
112 *
113 * @param array $input List of arrays each holding 'value' and 'label'.
114 * @return array Map keyed by each item's 'value' with its 'label'.
115 */
116 public function elementor_transform($input){
117 // Accumulator for the resulting value => label map.
118 $output=array();
119 // Only iterate when we were actually handed an array.
120 if( is_array($input) ){
121 // Re-key each entry so the option value becomes the map key.
122 foreach ($input as $key=>$tax){
123 $output[$tax['value']]=$tax['label'];
124 }
125 }
126 return $output;
127 }
128
129 /**
130 * Register the widget's editor controls.
131 *
132 * @access protected
133 */
134 protected function _register_controls() {
135 // Theme-wide taxonomy list kept in scope (unused by this widget).
136 global $all_tax;
137
138 // Local scratch array; declared but not used by this widget.
139 $featured_places_array =array(1=>1,2=>2,3=>3);
140
141 // Open the "Content" settings section.
142 $this->start_controls_section(
143 'section_content',
144 [
145 'label' => __( 'Content', 'wpstream' ),
146 ]
147 );
148
149
150
151
152 // Text field: the product / free-product id to stream on.
153 // Left blank, we stream on the user's first free/paid channel.
154 $this->add_control(
155 'item_id',
156 [
157 'label' => __( 'Product/Free Product id', 'wpstream' ),
158 'label_block'=>true,
159 'type' => Controls_Manager::TEXT,
160 'description'=>__('If you leave this option blank we will stream on the first free/paid channel for this user','wpstream')
161 ]
162 );
163
164
165
166
167 // Close the "Content" settings section.
168 $this->end_controls_section();
169
170
171 }
172
173 /**
174 * Render the widget output on the frontend.
175 *
176 * Written in PHP and used to generate the final HTML.
177 *
178 * @since 1.0.0
179 *
180 * @access protected
181 */
182
183 /**
184 * Join array values into a single comma-separated string.
185 *
186 * @param array|string $input Values to concatenate; '' short-circuits to empty.
187 * @return string Comma-separated list, or empty string when nothing to join.
188 */
189 public function wpresidence_send_to_shortcode($input){
190 // Start with an empty result buffer.
191 $output='';
192 // Nothing to concatenate for an empty input.
193 if($input!==''){
194 // Track the total so we can skip the trailing separator.
195 $numItems = count($input);
196 $i = 0;
197
198 // Append each value, comma-separating all but the last.
199 foreach ($input as $key=>$value){
200 $output.=$value;
201 if(++$i !== $numItems) {
202 $output.=', ';
203 }
204 }
205 }
206 return $output;
207 }
208
209 /**
210 * Render the widget on the frontend.
211 *
212 * Reads the item id control and delegates to the plugin's live-stream unit
213 * wrapper, which echoes the broadcaster UI for that channel.
214 *
215 * @access protected
216 */
217 protected function render() {
218 // Pull the saved control values for this widget instance.
219 $settings = $this->get_settings_for_display();
220
221 // The chosen product/free-product id to broadcast on.
222 $attributes['id'] = $settings['item_id'] ;
223
224 // Main plugin instance that renders the live-stream unit.
225 global $wpstream_plugin;
226
227
228
229 // echo $wpstream_plugin->admin->wpstream_live_stream_unit( $attributes['id'],'front' );
230 // Echo the broadcaster UI wrapper for the chosen id, in front-end mode.
231 echo $wpstream_plugin->wpstream_live_stream_unit_wrapper( $attributes['id'],'front' );
232 }
233
234 /**
235 * Render the widget output in the editor.
236 *
237 * Written as a Backbone JavaScript template and used to generate the live preview.
238 *
239 * @since 1.0.0
240 *
241 * @access protected
242 */
243 protected function content_template() {
244 ?>
245 <div class="title">
246 <!-- Backbone/Underscore template token echoed as the live editor preview. -->
247 {{{ settings.title }}}
248 </div>
249 <?php
250 }
251 }
252