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

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