PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.14.1
WpStream – Live Streaming, Video on Demand, Pay Per View v4.14.1
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 / media_list.php

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

235 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Elementor widgets: WpStream Channel List and Video on Demand List.
4 *
5 * Both lists are the same widget parameterized by Media List kind: one abstract
6 * base builds the controls from the Media List module's catalog and delegates
7 * rendering to the module; the two concrete classes only name the kind, the
8 * title, and the forced legacy product_type. The live-only switch exists only
9 * where the catalog says the kind supports it (Channels).
10 *
11 * Widget names (get_name()) are stored in customers' _elementor_data and must
12 * not change.
13 *
14 * @package Wpstream
15 * @subpackage Wpstream/widgets
16 */
17
18 namespace ElementorWpStream\Widgets;
19
20 use Elementor\Widget_Base;
21 use Elementor\Controls_Manager;
22
23 if ( ! defined( 'ABSPATH' ) ) {
24 exit;
25 }
26
27 /**
28 * Shared Media List widget; subclasses pick the kind.
29 */
30 abstract class Wpstream_Media_List_Widget extends Widget_Base {
31
32 /**
33 * Media List kind handled by this widget: `live_channel` or `vod`.
34 *
35 * @return string
36 */
37 abstract protected function kind();
38
39 /**
40 * Legacy numeric product_type the renderer expects (1 = Live Event, 2 = VOD).
41 *
42 * @return int
43 */
44 abstract protected function product_type();
45
46 /**
47 * Every WpStream widget lives under the WpStream panel category.
48 *
49 * @return array
50 */
51 public function get_categories() {
52 return array( 'wpstream' );
53 }
54
55 /**
56 * Panel icon.
57 *
58 * @return string
59 */
60 public function get_icon() {
61 return 'eicon-play-o';
62 }
63
64 /**
65 * Register the editor controls from the Media List catalog.
66 *
67 * @return void
68 */
69 protected function register_controls() {
70 global $wpstream_plugin;
71 $catalog = $wpstream_plugin->media_list->catalog( $this->kind() );
72
73 $this->start_controls_section( 'section_content', array( 'label' => __( 'Content', 'wpstream' ) ) );
74
75 // Free vs. paid filter; numeric keys are what the renderer accepts.
76 $this->add_control(
77 'product_type_free_paid',
78 array(
79 'label' => __( 'Show Free or Paid Media ?', 'wpstream' ),
80 'type' => Controls_Manager::SELECT,
81 'default' => 0,
82 'options' => array(
83 0 => $catalog['choices']['access']['free'],
84 1 => $catalog['choices']['access']['paid'],
85 ),
86 )
87 );
88
89 // Live-only switch, only for kinds that can be live (Channels).
90 if ( $catalog['supports_active_only'] ) {
91 $this->add_control(
92 'product_show_live',
93 array(
94 'label' => __( 'Only show active channels', 'wpstream' ),
95 'type' => Controls_Manager::SWITCHER,
96 'label_on' => __( 'Yes', 'wpstream' ),
97 'label_off' => __( 'No', 'wpstream' ),
98 'default' => 'no',
99 'return_value' => 'yes',
100 'description' => __( 'Only show channels that are live streaming right now.', 'wpstream' ),
101 )
102 );
103 }
104
105 // Grid columns; capped at 4 by the renderer.
106 $this->add_control(
107 'row_number',
108 array(
109 'label' => __( 'Number of Items per row', 'wpstream' ),
110 'label_block' => true,
111 'type' => Controls_Manager::TEXT,
112 'description' => __( 'How many items will be displayed per row. Maximum no is 4', 'wpstream' ),
113 'default' => $catalog['defaults']['columns'],
114 )
115 );
116
117 // Pagination size.
118 $this->add_control(
119 'media_number',
120 array(
121 'label' => __( 'Number of Items per Page', 'wpstream' ),
122 'label_block' => true,
123 'type' => Controls_Manager::TEXT,
124 'description' => __( 'How many items will be displayed per page', 'wpstream' ),
125 'default' => $catalog['defaults']['items_per_page'],
126 )
127 );
128
129 // Call-to-action label on free items.
130 $this->add_control(
131 'free_label',
132 array(
133 'label' => __( 'Link Label for free items', 'wpstream' ),
134 'label_block' => true,
135 'type' => Controls_Manager::TEXT,
136 'default' => $catalog['builder_defaults']['free_label'],
137 'description' => __( 'Link Label for free items', 'wpstream' ),
138 )
139 );
140
141 // Ordering; numeric keys are what the renderer accepts.
142 $this->add_control(
143 'order_by',
144 array(
145 'label' => __( 'Order by', 'wpstream' ),
146 'type' => Controls_Manager::SELECT,
147 'default' => 0,
148 'options' => array(
149 0 => $catalog['choices']['order']['date_asc'],
150 1 => $catalog['choices']['order']['date_desc'],
151 2 => $catalog['choices']['order']['title_asc'],
152 3 => $catalog['choices']['order']['title_desc'],
153 ),
154 )
155 );
156
157 $this->end_controls_section();
158 }
159
160 /**
161 * Map the editor settings onto the Media List renderer and print its HTML.
162 *
163 * @return void
164 */
165 protected function render() {
166 global $wpstream_plugin;
167 $settings = $this->get_settings_for_display();
168
169 $attributes = array(
170 'product_type' => $this->product_type(),
171 'product_type_free_paid' => $settings['product_type_free_paid'],
172 'media_number' => $settings['media_number'],
173 'row_number' => $settings['row_number'],
174 'free_label' => $settings['free_label'],
175 'order_by' => $settings['order_by'],
176 // Kinds without the switch are never filtered to live-only.
177 'product_show_live' => isset( $settings['product_show_live'] ) ? $settings['product_show_live'] : 'no',
178 );
179
180 echo $wpstream_plugin->media_list->render( $this->kind(), $attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- renderer returns escaped markup.
181 }
182 }
183
184 /**
185 * Channel (live event) list widget.
186 */
187 class Wpstream_Media_List_Channel extends Wpstream_Media_List_Widget {
188
189 /** @inheritDoc */
190 protected function kind() {
191 return 'live_channel';
192 }
193
194 /** @inheritDoc */
195 protected function product_type() {
196 return 1;
197 }
198
199 /** @inheritDoc */
200 public function get_name() {
201 return 'Wpstream_Media_List_Channel';
202 }
203
204 /** @inheritDoc */
205 public function get_title() {
206 return '<div class="wpstream_elementor_widget_title">' . __( 'WpStream - Channel List', 'wpstream' ) . '</div>';
207 }
208 }
209
210 /**
211 * Video on demand list widget.
212 */
213 class Wpstream_Media_List_Vod extends Wpstream_Media_List_Widget {
214
215 /** @inheritDoc */
216 protected function kind() {
217 return 'vod';
218 }
219
220 /** @inheritDoc */
221 protected function product_type() {
222 return 2;
223 }
224
225 /** @inheritDoc */
226 public function get_name() {
227 return 'Wpstream_Media_List_Vod';
228 }
229
230 /** @inheritDoc */
231 public function get_title() {
232 return '<div class="wpstream_elementor_widget_title">' . __( 'WpStream - Video on Demand List', 'wpstream' ) . '</div>';
233 }
234 }
235