PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.28
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.28
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmDashboardHelper.php

FrmDashboardHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.28, at classes/helpers/FrmDashboardHelper.php

389 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmDashboardHelper {
7
8 /**
9 * The dashboard default view args
10 *
11 * @var array
12 */
13 private $view = array();
14
15 /**
16 * Init all dashboard's widgets view args.
17 *
18 * @param array $data {
19 * An array of view args required to construct dashboard view.
20 *
21 * @type array $counters Array of counters.
22 * @type string $counters['counters'][]['heading']
23 * @type int $counters['counters'][]['counter']
24 * @type string $counters['counters'][]['type'] The counter template type: default|currency.
25 * @type array $counters['counters'][]['cta']
26 * @type string $counters['counters'][]['cta']['title']
27 * @type string $counters['counters'][]['cta']['link']
28 * @type bool $counters['counters'][]['cta']['display'] If true a CTA will be displayed instead of the counter.
29 * @type array $license Array of license args
30 * @type string $license['heading']
31 * @type string $license['copy']
32 * @type array $license['buttons']
33 * @type string $license['buttons'][]['label']
34 * @type string $license['buttons'][]['link']
35 * @type string $license['buttons'][]['type'] primary|secondary
36 * @type array $inbox Array of inbox args
37 * @type array $inbox['unread']
38 * @type string $inbox['unread'][]['message']
39 * @type string $inbox['unread'][]['subject']
40 * @type string $inbox['unread'][]['icon']
41 * @type string $inbox['unread'][]['cta']
42 * @type string $inbox['unread'][]['expires']
43 * @type array $inbox['unread'][]['who']
44 * @type int $inbox['unread'][]['starts']
45 * @type int $inbox['unread'][]['created']
46 * @type array $inbox['dismissed']
47 * @type string $inbox['dismissed'][]['message']
48 * @type string $inbox['dismissed'][]['subject']
49 * @type string $inbox['dismissed'][]['icon']
50 * @type string $inbox['dismissed'][]['cta']
51 * @type string $inbox['dismissed'][]['expires']
52 * @type array $inbox['dismissed'][]['who']
53 * @type int $inbox['dismissed'][]['starts']
54 * @type int $inbox['dismissed'][]['created']
55 * @type int $inbox['user']
56 * @type array $entries Array of entries args
57 * @type string $entries['widget-heading']
58 * @type array $entries['cta']
59 * @type string $entries['cta']['label']
60 * @type string $entries['cta']['link']
61 * @type bool $entries['show-placeholder']
62 * @type int $entries['count']
63 * @type array $entries['placeholder']
64 * @type string $entries['placeholder']['background']
65 * @type string $entries['placeholder']['heading']
66 * @type string $entries['placeholder']['copy']
67 * @type array|null $entries['placeholder']['button']
68 * @type string $entries['placeholder']['button']['label']
69 * @type string $entries['placeholder']['button']['link']
70 * @type array $payments Array of payments args
71 * @type bool $payments['show-placeholder']
72 * @type array $payments['placeholder']
73 * @type string $payments['placeholder']['copy']
74 * @type array $payments['placeholder']['cta']
75 * @type string $payments['placeholder']['cta']['link']
76 * @type string $payments['placeholder']['cta']['label']
77 * @type array $payments['counters']
78 * @type string $payments['counters'][]['heading']
79 * @type string $payments['counters'][]['type'] currency|default
80 * @type array $payments['counters'][]['items']
81 * @type string $payments['counters'][]['items'][]['counter_label']
82 * @type int $payments['counters'][]['items'][]['counter']
83 * @type array $video Array of video args
84 * @type string $video['id'] YouTube video ID
85 * }
86 *
87 * @return void
88 */
89 public function __construct( $data ) {
90 $sections = array( 'counters', 'license', 'get_free_templates', 'payments', 'entries', 'inbox', 'video', 'payments' );
91
92 foreach ( $sections as $section ) {
93 if ( isset( $data[ $section ] ) ) {
94 $this->view[ $section ] = $data[ $section ];
95 }
96 }
97 }
98
99 /**
100 * The dashboard widget that will show right below counters.
101 *
102 * @return void
103 */
104 public function get_main_widget() {
105 if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProDashboardHelper::get_main_widget' ) ) {
106 FrmProDashboardHelper::get_main_widget( $this->view['entries'] );
107 return;
108 }
109
110 self::load_entries_template( $this->view['entries'] );
111 }
112
113 /**
114 * The dashboard widget that will show on the bottom.
115 *
116 * @return void
117 */
118 public function get_bottom_widget() {
119 if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProDashboardHelper::get_bottom_widget' ) ) {
120 echo '<div class="frm-dashboard-widget frm-card-item frm-px-0">';
121 FrmProDashboardHelper::get_bottom_widget( $this->view['entries'] );
122 echo '</div>';
123 } elseif ( ! FrmAppHelper::pro_is_installed() ) {
124 $this->get_pro_features();
125 }
126 }
127
128 /**
129 * Dashboard - welcome banner template.
130 *
131 * @return void
132 */
133 public function get_welcome_banner() {
134 if ( true === FrmDashboardController::welcome_banner_has_closed() || FrmForm::get_forms_count() ) {
135 return;
136 }
137
138 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/notification-banner.php';
139 }
140
141 /**
142 * Dashboard - top counters card widgets template.
143 *
144 * @return void
145 */
146 public function get_counters() {
147 $this->load_counters_template( $this->view['counters'] );
148 }
149
150 /**
151 * Dashboard -license management widget template.
152 *
153 * @return void
154 */
155 public function get_license_management() {
156 $template = $this->view['license'];
157
158 if ( is_callable( 'FrmProDashboardHelper::load_license_management' ) ) {
159 FrmProDashboardHelper::load_license_management( $template );
160 return;
161 }
162
163 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/license-management.php';
164 }
165
166 /**
167 * Get free templates banner template.
168 *
169 * @since 6.25
170 *
171 * @return void
172 */
173 public function get_free_templates_banner() {
174 include FrmAppHelper::plugin_path() . '/classes/views/shared/get-free-templates-banner.php';
175 }
176
177 /**
178 * Show buttons to in the license key box.
179 *
180 * @since 6.8
181 *
182 * @param array $buttons A list of buttons to show.
183 * @param string $button_classes Used from the global settings page.
184 *
185 * @return void
186 */
187 public static function show_connect_links( $buttons = array(), $button_classes = '' ) {
188 if ( ! $buttons ) {
189 $buttons = self::get_license_buttons();
190 }
191
192 foreach ( $buttons as $button ) {
193 $add_classes = ! empty( $button['classes'] ) ? ' ' . $button['classes'] : ' frm-button-secondary';
194 // phpcs:disable Generic.WhiteSpace.ScopeIndent
195 ?>
196 <a href="<?php echo esc_url( $button['link'] ); ?>" target="_blank"
197 class="<?php echo esc_attr( $button_classes . $add_classes ); ?>"
198 >
199 <?php echo esc_html( $button['label'] ); ?>
200 </a>
201 <?php
202 // phpcs:enable Generic.WhiteSpace.ScopeIndent
203 }
204 }
205
206 /**
207 * Dashboard - license buttons for Lite.
208 *
209 * @since 6.8
210 *
211 * @return array
212 */
213 public static function get_license_buttons() {
214 $cta_text = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_text' );
215
216 if ( ! $cta_text ) {
217 $cta_text = __( 'Get Formidable PRO', 'formidable' );
218 }
219
220 $upgrade_link = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_link' );
221 $utm = array(
222 'campaign' => 'settings-license',
223 'content' => 'dashboard-license-box',
224 );
225
226 if ( $upgrade_link ) {
227 $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, $utm );
228 } else {
229 $upgrade_link = FrmAppHelper::admin_upgrade_link( $utm );
230 }
231
232 return array(
233 array(
234 'label' => __( 'Connect Account', 'formidable' ),
235 'link' => FrmAddonsController::connect_link(),
236 'classes' => 'frm-button-primary frm-show-unauthorized',
237 ),
238 array(
239 'label' => $cta_text,
240 'link' => $upgrade_link,
241 'classes' => 'frm-button-secondary frm-show-unauthorized',
242 ),
243 );
244 }
245
246 /**
247 * Dashboard - inbox widget template.
248 *
249 * @return void
250 */
251 public function get_inbox() {
252 $template = $this->view['inbox'];
253 $subscribe_inbox_classnames = 'frm-inbox-subscribe frmcenter';
254 $subscribe_inbox_classnames .= ! empty( $template['unread'] ) ? ' frm_hidden' : '';
255 $subscribe_inbox_classnames .= true === FrmDashboardController::email_is_subscribed( $template['user']->user_email ) ? ' frm-inbox-hide-form' : '';
256
257 include FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php';
258 }
259
260 /**
261 * Dashboard - pro features list widget template.
262 *
263 * @return void
264 */
265 private function get_pro_features() {
266 $features = array(
267 sprintf(
268 /* translators: %d: number of form templates */
269 __( '%d+ Form Templates', 'formidable' ),
270 FrmFormTemplatesController::get_template_count()
271 ),
272 __( 'Calculated Fields and Math', 'formidable' ),
273 __( 'Quizzes', 'formidable' ),
274 __( 'Save and Continue', 'formidable' ),
275 __( 'Smart Forms with Conditional Logic', 'formidable' ),
276 __( 'Ecommerce Pricing Fields', 'formidable' ),
277 __( 'Advanced Fields', 'formidable' ),
278 __( 'Schedule Forms & Limit Responses', 'formidable' ),
279 __( 'Display Form Data with Views', 'formidable' ),
280 __( 'And much more...', 'formidable' ),
281 );
282
283 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/pro-features-list.php';
284 }
285
286 /**
287 * Dashboard - total earnings widget template.
288 *
289 * @return void
290 */
291 public function get_payments() {
292 $this->load_payments_template( $this->view['payments'] );
293 }
294
295 /**
296 * Dashboard - YouTube video widget template.
297 *
298 * @param string $classes The widget's classes.
299 *
300 * @return void
301 */
302 public function get_youtube_video( $classes ) {
303 $template = $this->view['video'];
304
305 if ( null === $template['id'] ) {
306 return;
307 }
308
309 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/youtube-video.php';
310 }
311
312 /**
313 * Dashboard - load placeholder template.
314 *
315 * @param array $template
316 *
317 * @return void
318 */
319 public static function load_placeholder_template( $template ) {
320 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/widget-placeholder.php';
321 }
322
323 /**
324 * Dashboard - load total earnings/payments template or placeholder.
325 *
326 * @param array $template
327 *
328 * @return void
329 */
330 private function load_payments_template( $template ) {
331 if ( true === $template['show-placeholder'] ) {
332 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/payment-placeholder.php';
333 return;
334 }
335
336 $this->load_counters_template( $template );
337 }
338
339 /**
340 * Dashboard - load counters template. This function handles the top counters template and total earnings template.
341 *
342 * @param array $template
343 *
344 * @return void
345 */
346 private function load_counters_template( $template ) {
347 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/counters.php';
348 }
349
350 /**
351 * Dashboard - the entries widget template. Load entries placeholder if there are no entries or load the entries list template.
352 *
353 * @param array $template
354 *
355 * @return void
356 */
357 public static function load_entries_template( $template ) {
358 if ( true === $template['show-placeholder'] ) {
359 self::load_placeholder_template( $template );
360 return;
361 }
362
363 self::load_entries_list_template( $template );
364 }
365
366 /**
367 * Dashboard - load the entries list template.
368 *
369 * @param array $template
370 *
371 * @return void
372 */
373 private static function load_entries_list_template( $template ) {
374 add_filter(
375 'formidable_page_formidable_entries_per_page',
376 function () {
377 return 7;
378 }
379 );
380
381 $params = FrmForm::get_admin_params();
382 $controller_entries_table = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
383 $wp_list_table = new $controller_entries_table( array( 'params' => $params ) );
384 $wp_list_table->prepare_items();
385
386 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/entries-list.php';
387 }
388 }
389