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

360 lines 11.4 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 $upgrade_link = FrmAppHelper::admin_upgrade_link(
200 array(
201 'medium' => 'settings-license',
202 'content' => 'dashboard-license-box',
203 )
204 );
205
206 return array(
207 array(
208 'label' => __( 'Connect Account', 'formidable' ),
209 'link' => FrmAddonsController::connect_link(),
210 'classes' => 'frm-button-primary frm-show-unauthorized',
211 ),
212 array(
213 'label' => __( 'Get Formidable PRO', 'formidable' ),
214 'link' => $upgrade_link,
215 'classes' => 'frm-button-secondary frm-show-unauthorized',
216 ),
217 );
218 }
219
220 /**
221 * Dashboard - inbox widget template.
222 *
223 * @return void
224 */
225 public function get_inbox() {
226 $template = $this->view['inbox'];
227
228 $subscribe_inbox_classnames = 'frm-inbox-subscribe frmcenter';
229 $subscribe_inbox_classnames .= ! empty( $template['unread'] ) ? ' frm_hidden' : '';
230 $subscribe_inbox_classnames .= true === FrmDashboardController::email_is_subscribed( $template['user']->user_email ) ? ' frm-inbox-hide-form' : '';
231
232 include FrmAppHelper::plugin_path() . '/classes/views/inbox/list.php';
233 }
234
235 /**
236 * Dashboard - pro features list widget template.
237 *
238 * @return void
239 */
240 private function get_pro_features() {
241 $features = array(
242 sprintf(
243 /* translators: %d: number of form templates */
244 __( '%d+ Form Templates', 'formidable' ),
245 FrmFormTemplatesController::get_template_count()
246 ),
247 __( 'Calculated Fields and Math', 'formidable' ),
248 __( 'Quizzes', 'formidable' ),
249 __( 'Save and Continue', 'formidable' ),
250 __( 'Smart Forms with Conditional Logic', 'formidable' ),
251 __( 'Ecommerce Pricing Fields', 'formidable' ),
252 __( 'Advanced Fields', 'formidable' ),
253 __( 'Schedule Forms & Limit Responses', 'formidable' ),
254 __( 'Display Form Data with Views', 'formidable' ),
255 __( 'And much more...', 'formidable' ),
256 );
257
258 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/pro-features-list.php';
259 }
260
261 /**
262 * Dashboard - total earnings widget template.
263 *
264 * @return void
265 */
266 public function get_payments() {
267 $this->load_payments_template( $this->view['payments'] );
268 }
269
270 /**
271 * Dashboard - YouTube video widget template.
272 *
273 * @param string $classes The widget's classes.
274 *
275 * @return void
276 */
277 public function get_youtube_video( $classes ) {
278 $template = $this->view['video'];
279 if ( null === $template['id'] ) {
280 return;
281 }
282 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/youtube-video.php';
283 }
284
285 /**
286 * Dashboard - load placeholder template.
287 *
288 * @param array $template
289 *
290 * @return void
291 */
292 public static function load_placeholder_template( $template ) {
293 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/widget-placeholder.php';
294 }
295
296 /**
297 * Dashboard - load total earnings/payments template or placeholder.
298 *
299 * @param array $template
300 *
301 * @return void
302 */
303 private function load_payments_template( $template ) {
304 if ( true === $template['show-placeholder'] ) {
305 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/payment-placeholder.php';
306 return;
307 }
308
309 $this->load_counters_template( $template );
310 }
311
312 /**
313 * Dashboard - load counters template. This function handles the top counters template and total earnings template.
314 *
315 * @param array $template
316 *
317 * @return void
318 */
319 private function load_counters_template( $template ) {
320 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/counters.php';
321 }
322
323 /**
324 * Dashboard - the entries widget template. Load entries placeholder if there are no entries or load the entries list template.
325 *
326 * @param array $template
327 *
328 * @return void
329 */
330 public static function load_entries_template( $template ) {
331 if ( true === $template['show-placeholder'] ) {
332 self::load_placeholder_template( $template );
333 return;
334 }
335
336 self::load_entries_list_template( $template );
337 }
338
339 /**
340 * Dashboard - load the entries list template.
341 *
342 * @return void
343 */
344 private static function load_entries_list_template( $template ) {
345 add_filter(
346 'formidable_page_formidable_entries_per_page',
347 function () {
348 return 7;
349 }
350 );
351
352 $params = FrmForm::get_admin_params();
353 $controller_entries_table = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
354 $wp_list_table = new $controller_entries_table( array( 'params' => $params ) );
355 $wp_list_table->prepare_items();
356
357 include FrmAppHelper::plugin_path() . '/classes/views/dashboard/templates/entries-list.php';
358 }
359 }
360