PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.3
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.22.3, at classes/helpers/FrmDashboardHelper.php

370 lines 11.8 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', 'payments', 'entries', 'inbox', 'video', 'payments' );
91 foreach ( $sections as $section ) {
92 if ( isset( $data[ $section ] ) ) {
93 $this->view[ $section ] = $data[ $section ];
94 }
95 }
96 }
97
98 /**
99 * The dashboard widget that will show right below counters.
100 *
101 * @return void
102 */
103 public function get_main_widget() {
104 if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProDashboardHelper::get_main_widget' ) ) {
105 FrmProDashboardHelper::get_main_widget( $this->view['entries'] );
106 return;
107 }
108
109 self::load_entries_template( $this->view['entries'] );
110 }
111
112 /**
113 * The dashboard widget that will show on the bottom.
114 *
115 * @return void
116 */
117 public function get_bottom_widget() {
118 if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProDashboardHelper::get_bottom_widget' ) ) {
119 echo '<div class="frm-dashboard-widget frm-card-item frm-px-0">';
120 FrmProDashboardHelper::get_bottom_widget( $this->view['entries'] );
121 echo '</div>';
122 } elseif ( ! FrmAppHelper::pro_is_installed() ) {
123 $this->get_pro_features();
124 }
125 }
126
127 /**
128 * Dashboard - welcome banner template.
129 *
130 * @return void
131 */
132 public function get_welcome_banner() {
133 if ( true === FrmDashboardController::welcome_banner_has_closed() || FrmForm::get_forms_count() ) {
134 return;
135 }
136
137 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/notification-banner.php';
138 }
139
140 /**
141 * Dashboard - top counters card widgets template.
142 *
143 * @return void
144 */
145 public function get_counters() {
146 $this->load_counters_template( $this->view['counters'] );
147 }
148
149 /**
150 * Dashboard -license management widget template.
151 *
152 * @return void
153 */
154 public function get_license_management() {
155 $template = $this->view['license'];
156 if ( is_callable( 'FrmProDashboardHelper::load_license_management' ) ) {
157 FrmProDashboardHelper::load_license_management( $template );
158 return;
159 }
160
161 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/license-management.php';
162 }
163
164 /**
165 * Show buttons to in the license key box.
166 *
167 * @since 6.8
168 *
169 * @param array $buttons A list of buttons to show.
170 * @param string $button_classes Used from the global settings page.
171 *
172 * @return void
173 */
174 public static function show_connect_links( $buttons = array(), $button_classes = '' ) {
175 if ( empty( $buttons ) ) {
176 $buttons = self::get_license_buttons();
177 }
178
179 foreach ( $buttons as $i => $button ) {
180 $add_classes = ! empty( $button['classes'] ) ? ' ' . $button['classes'] : ' frm-button-secondary';
181 ?>
182 <a href="<?php echo esc_url( $button['link'] ); ?>" target="_blank"
183 class="<?php echo esc_attr( $button_classes . $add_classes ); ?>"
184 >
185 <?php echo esc_html( $button['label'] ); ?>
186 </a>
187 <?php
188 }
189 }
190
191 /**
192 * Dashboard - license buttons for Lite.
193 *
194 * @since 6.8
195 *
196 * @return array
197 */
198 public static function get_license_buttons() {
199 $cta_text = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_text' );
200 if ( ! $cta_text ) {
201 $cta_text = __( 'Get Formidable PRO', 'formidable' );
202 }
203
204 $upgrade_link = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_link' );
205 $utm = array(
206 'medium' => 'settings-license',
207 'content' => 'dashboard-license-box',
208 );
209
210 if ( $upgrade_link ) {
211 $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, $utm );
212 } else {
213 $upgrade_link = FrmAppHelper::admin_upgrade_link( $utm );
214 }
215
216 return array(
217 array(
218 'label' => __( 'Connect Account', 'formidable' ),
219 'link' => FrmAddonsController::connect_link(),
220 'classes' => 'frm-button-primary frm-show-unauthorized',
221 ),
222 array(
223 'label' => $cta_text,
224 'link' => $upgrade_link,
225 'classes' => 'frm-button-secondary frm-show-unauthorized',
226 ),
227 );
228 }
229
230 /**
231 * Dashboard - inbox widget template.
232 *
233 * @return void
234 */
235 public function get_inbox() {
236 $template = $this->view['inbox'];
237
238 $subscribe_inbox_classnames = 'frm-inbox-subscribe frmcenter';
239 $subscribe_inbox_classnames .= ! empty( $template['unread'] ) ? ' frm_hidden' : '';
240 $subscribe_inbox_classnames .= true === FrmDashboardController::email_is_subscribed( $template['user']->user_email ) ? ' frm-inbox-hide-form' : '';
241
242 include FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php';
243 }
244
245 /**
246 * Dashboard - pro features list widget template.
247 *
248 * @return void
249 */
250 private function get_pro_features() {
251 $features = array(
252 sprintf(
253 /* translators: %d: number of form templates */
254 __( '%d+ Form Templates', 'formidable' ),
255 FrmFormTemplatesController::get_template_count()
256 ),
257 __( 'Calculated Fields and Math', 'formidable' ),
258 __( 'Quizzes', 'formidable' ),
259 __( 'Save and Continue', 'formidable' ),
260 __( 'Smart Forms with Conditional Logic', 'formidable' ),
261 __( 'Ecommerce Pricing Fields', 'formidable' ),
262 __( 'Advanced Fields', 'formidable' ),
263 __( 'Schedule Forms & Limit Responses', 'formidable' ),
264 __( 'Display Form Data with Views', 'formidable' ),
265 __( 'And much more...', 'formidable' ),
266 );
267
268 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/pro-features-list.php';
269 }
270
271 /**
272 * Dashboard - total earnings widget template.
273 *
274 * @return void
275 */
276 public function get_payments() {
277 $this->load_payments_template( $this->view['payments'] );
278 }
279
280 /**
281 * Dashboard - YouTube video widget template.
282 *
283 * @param string $classes The widget's classes.
284 *
285 * @return void
286 */
287 public function get_youtube_video( $classes ) {
288 $template = $this->view['video'];
289 if ( null === $template['id'] ) {
290 return;
291 }
292 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/youtube-video.php';
293 }
294
295 /**
296 * Dashboard - load placeholder template.
297 *
298 * @param array $template
299 *
300 * @return void
301 */
302 public static function load_placeholder_template( $template ) {
303 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/widget-placeholder.php';
304 }
305
306 /**
307 * Dashboard - load total earnings/payments template or placeholder.
308 *
309 * @param array $template
310 *
311 * @return void
312 */
313 private function load_payments_template( $template ) {
314 if ( true === $template['show-placeholder'] ) {
315 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/payment-placeholder.php';
316 return;
317 }
318
319 $this->load_counters_template( $template );
320 }
321
322 /**
323 * Dashboard - load counters template. This function handles the top counters template and total earnings template.
324 *
325 * @param array $template
326 *
327 * @return void
328 */
329 private function load_counters_template( $template ) {
330 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/counters.php';
331 }
332
333 /**
334 * Dashboard - the entries widget template. Load entries placeholder if there are no entries or load the entries list template.
335 *
336 * @param array $template
337 *
338 * @return void
339 */
340 public static function load_entries_template( $template ) {
341 if ( true === $template['show-placeholder'] ) {
342 self::load_placeholder_template( $template );
343 return;
344 }
345
346 self::load_entries_list_template( $template );
347 }
348
349 /**
350 * Dashboard - load the entries list template.
351 *
352 * @return void
353 */
354 private static function load_entries_list_template( $template ) {
355 add_filter(
356 'formidable_page_formidable_entries_per_page',
357 function () {
358 return 7;
359 }
360 );
361
362 $params = FrmForm::get_admin_params();
363 $controller_entries_table = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
364 $wp_list_table = new $controller_entries_table( array( 'params' => $params ) );
365 $wp_list_table->prepare_items();
366
367 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/entries-list.php';
368 }
369 }
370