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

381 lines 12.0 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 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 * Get free templates banner template.
166 *
167 * @since 6.25
168 *
169 * @return void
170 */
171 public function get_free_templates_banner() {
172 include FrmAppHelper::plugin_path() . '/classes/views/shared/get-free-templates-banner.php';
173 }
174
175 /**
176 * Show buttons to in the license key box.
177 *
178 * @since 6.8
179 *
180 * @param array $buttons A list of buttons to show.
181 * @param string $button_classes Used from the global settings page.
182 *
183 * @return void
184 */
185 public static function show_connect_links( $buttons = array(), $button_classes = '' ) {
186 if ( empty( $buttons ) ) {
187 $buttons = self::get_license_buttons();
188 }
189
190 foreach ( $buttons as $i => $button ) {
191 $add_classes = ! empty( $button['classes'] ) ? ' ' . $button['classes'] : ' frm-button-secondary';
192 ?>
193 <a href="<?php echo esc_url( $button['link'] ); ?>" target="_blank"
194 class="<?php echo esc_attr( $button_classes . $add_classes ); ?>"
195 >
196 <?php echo esc_html( $button['label'] ); ?>
197 </a>
198 <?php
199 }
200 }
201
202 /**
203 * Dashboard - license buttons for Lite.
204 *
205 * @since 6.8
206 *
207 * @return array
208 */
209 public static function get_license_buttons() {
210 $cta_text = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_text' );
211 if ( ! $cta_text ) {
212 $cta_text = __( 'Get Formidable PRO', 'formidable' );
213 }
214
215 $upgrade_link = FrmSalesApi::get_best_sale_value( 'dashboard_license_cta_link' );
216 $utm = array(
217 'campaign' => 'settings-license',
218 'content' => 'dashboard-license-box',
219 );
220
221 if ( $upgrade_link ) {
222 $upgrade_link = FrmAppHelper::maybe_add_missing_utm( $upgrade_link, $utm );
223 } else {
224 $upgrade_link = FrmAppHelper::admin_upgrade_link( $utm );
225 }
226
227 return array(
228 array(
229 'label' => __( 'Connect Account', 'formidable' ),
230 'link' => FrmAddonsController::connect_link(),
231 'classes' => 'frm-button-primary frm-show-unauthorized',
232 ),
233 array(
234 'label' => $cta_text,
235 'link' => $upgrade_link,
236 'classes' => 'frm-button-secondary frm-show-unauthorized',
237 ),
238 );
239 }
240
241 /**
242 * Dashboard - inbox widget template.
243 *
244 * @return void
245 */
246 public function get_inbox() {
247 $template = $this->view['inbox'];
248
249 $subscribe_inbox_classnames = 'frm-inbox-subscribe frmcenter';
250 $subscribe_inbox_classnames .= ! empty( $template['unread'] ) ? ' frm_hidden' : '';
251 $subscribe_inbox_classnames .= true === FrmDashboardController::email_is_subscribed( $template['user']->user_email ) ? ' frm-inbox-hide-form' : '';
252
253 include FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php';
254 }
255
256 /**
257 * Dashboard - pro features list widget template.
258 *
259 * @return void
260 */
261 private function get_pro_features() {
262 $features = array(
263 sprintf(
264 /* translators: %d: number of form templates */
265 __( '%d+ Form Templates', 'formidable' ),
266 FrmFormTemplatesController::get_template_count()
267 ),
268 __( 'Calculated Fields and Math', 'formidable' ),
269 __( 'Quizzes', 'formidable' ),
270 __( 'Save and Continue', 'formidable' ),
271 __( 'Smart Forms with Conditional Logic', 'formidable' ),
272 __( 'Ecommerce Pricing Fields', 'formidable' ),
273 __( 'Advanced Fields', 'formidable' ),
274 __( 'Schedule Forms & Limit Responses', 'formidable' ),
275 __( 'Display Form Data with Views', 'formidable' ),
276 __( 'And much more...', 'formidable' ),
277 );
278
279 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/pro-features-list.php';
280 }
281
282 /**
283 * Dashboard - total earnings widget template.
284 *
285 * @return void
286 */
287 public function get_payments() {
288 $this->load_payments_template( $this->view['payments'] );
289 }
290
291 /**
292 * Dashboard - YouTube video widget template.
293 *
294 * @param string $classes The widget's classes.
295 *
296 * @return void
297 */
298 public function get_youtube_video( $classes ) {
299 $template = $this->view['video'];
300 if ( null === $template['id'] ) {
301 return;
302 }
303 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/youtube-video.php';
304 }
305
306 /**
307 * Dashboard - load placeholder template.
308 *
309 * @param array $template
310 *
311 * @return void
312 */
313 public static function load_placeholder_template( $template ) {
314 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/widget-placeholder.php';
315 }
316
317 /**
318 * Dashboard - load total earnings/payments template or placeholder.
319 *
320 * @param array $template
321 *
322 * @return void
323 */
324 private function load_payments_template( $template ) {
325 if ( true === $template['show-placeholder'] ) {
326 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/payment-placeholder.php';
327 return;
328 }
329
330 $this->load_counters_template( $template );
331 }
332
333 /**
334 * Dashboard - load counters template. This function handles the top counters template and total earnings template.
335 *
336 * @param array $template
337 *
338 * @return void
339 */
340 private function load_counters_template( $template ) {
341 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/counters.php';
342 }
343
344 /**
345 * Dashboard - the entries widget template. Load entries placeholder if there are no entries or load the entries list template.
346 *
347 * @param array $template
348 *
349 * @return void
350 */
351 public static function load_entries_template( $template ) {
352 if ( true === $template['show-placeholder'] ) {
353 self::load_placeholder_template( $template );
354 return;
355 }
356
357 self::load_entries_list_template( $template );
358 }
359
360 /**
361 * Dashboard - load the entries list template.
362 *
363 * @return void
364 */
365 private static function load_entries_list_template( $template ) {
366 add_filter(
367 'formidable_page_formidable_entries_per_page',
368 function () {
369 return 7;
370 }
371 );
372
373 $params = FrmForm::get_admin_params();
374 $controller_entries_table = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
375 $wp_list_table = new $controller_entries_table( array( 'params' => $params ) );
376 $wp_list_table->prepare_items();
377
378 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/entries-list.php';
379 }
380 }
381