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 / wpstream_chat.php

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

245 lines 6.5 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 Chat (Beta).
4 *
5 * Registers the "WpStream Chat" 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 main plugin object to print the live chat box
8 * bound to that 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 live chat.
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_Chat_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_Chat';
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 Chat - Beta Version', '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 whose chat to display.
153 $this->add_control(
154 'item_id',
155 [
156 'label' => __( 'Product/Free Product id', 'wpstream' ),
157 'label_block'=>true,
158 'type' => Controls_Manager::TEXT,
159 ]
160 );
161
162
163
164
165 // Close the "Content" settings section.
166 $this->end_controls_section();
167
168
169 }
170
171 /**
172 * Render the widget output on the frontend.
173 *
174 * Written in PHP and used to generate the final HTML.
175 *
176 * @since 1.0.0
177 *
178 * @access protected
179 */
180
181 /**
182 * Join array values into a single comma-separated string.
183 *
184 * @param array|string $input Values to concatenate; '' short-circuits to empty.
185 * @return string Comma-separated list, or empty string when nothing to join.
186 */
187 public function wpresidence_send_to_shortcode($input){
188 // Start with an empty result buffer.
189 $output='';
190 // Nothing to concatenate for an empty input.
191 if($input!==''){
192 // Track the total so we can skip the trailing separator.
193 $numItems = count($input);
194 $i = 0;
195
196 // Append each value, comma-separating all but the last.
197 foreach ($input as $key=>$value){
198 $output.=$value;
199 if(++$i !== $numItems) {
200 $output.=', ';
201 }
202 }
203 }
204 return $output;
205 }
206
207 /**
208 * Render the widget on the frontend.
209 *
210 * Reads the item id control and delegates to the plugin to echo the chat box.
211 *
212 * @access protected
213 */
214 protected function render() {
215 // Pull the saved control values for this widget instance.
216 $settings = $this->get_settings_for_display();
217
218 // The chosen product/free-product id whose chat to render.
219 $attributes['id'] = $settings['item_id'] ;
220
221 // Main plugin instance that knows how to build the chat markup.
222 global $wpstream_plugin;
223 // Echo the assembled chat box for the chosen channel.
224 echo $wpstream_plugin->wpstream_insert_chat_elementor($attributes);
225 }
226
227 /**
228 * Render the widget output in the editor.
229 *
230 * Written as a Backbone JavaScript template and used to generate the live preview.
231 *
232 * @since 1.0.0
233 *
234 * @access protected
235 */
236 protected function content_template() {
237 ?>
238 <div class="title">
239 <!-- Backbone/Underscore template token echoed as the live editor preview. -->
240 {{{ settings.title }}}
241 </div>
242 <?php
243 }
244 }
245