PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 / controllers / FrmApplicationsController.php

FrmApplicationsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 5.3, at classes/controllers/FrmApplicationsController.php

155 lines 4.1 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 /**
7 * @since 5.3
8 */
9 class FrmApplicationsController {
10
11 /**
12 * Add Applications menu item to sidebar and define Applications index page.
13 *
14 * @return void
15 */
16 public static function menu() {
17 $label = __( 'Applications', 'formidable' );
18 $new_pill = '<span class="frm-new-pill">NEW</span>';
19 add_submenu_page( 'formidable', 'Formidable | ' . $label, $label . $new_pill, 'frm_edit_forms', 'formidable-applications', array( __CLASS__, 'landing_page' ) );
20 }
21
22 /**
23 * Render Applications index page.
24 *
25 * @return void
26 */
27 public static function landing_page() {
28 require self::get_view_path() . 'index.php';
29 }
30
31 /**
32 * Get path to application views.
33 *
34 * @return string
35 */
36 private static function get_view_path() {
37 return FrmAppHelper::plugin_path() . '/classes/views/applications/';
38 }
39
40 /**
41 * Get information about applications via AJAX action.
42 *
43 * @return void
44 */
45 public static function get_applications_data() {
46 FrmAppHelper::permission_check( 'frm_edit_forms' );
47
48 $view = FrmAppHelper::get_param( 'view', '', 'get', 'sanitize_text_field' );
49 $data = array();
50 if ( 'applications' !== $view ) {
51 // view may be 'applications', 'templates', or empty.
52 $data['templates'] = self::get_prepared_template_data();
53 $data['categories'] = FrmApplicationTemplate::get_categories();
54 }
55
56 /**
57 * @param array $data
58 */
59 $data = apply_filters( 'frm_applications_data', $data );
60
61 wp_send_json_success( $data );
62 }
63
64 /**
65 * Retrieve API data and return a reduced set back with some restructuring applied to make it easier to read.
66 *
67 * @return array<array>
68 */
69 private static function get_prepared_template_data() {
70 $api = new FrmApplicationApi();
71 $applications = $api->get_api_info();
72 $applications = array_filter( $applications, 'is_array' );
73 $applications = self::sort_templates( $applications );
74
75 FrmApplicationTemplate::init();
76
77 return array_reduce( $applications, array( __CLASS__, 'reduce_template' ), array() );
78 }
79
80 /**
81 * @param array $total the accumulated array of reduced application data.
82 * @param array $current data for the current template from the API.
83 * @return array<array>
84 */
85 private static function reduce_template( $total, $current ) {
86 $template = new FrmApplicationTemplate( $current );
87 $total[] = $template->as_js_object();
88 return $total;
89 }
90
91 /**
92 * Sort applications alphabetically.
93 *
94 * @param array<array> $applications
95 * @return array<array>
96 */
97 private static function sort_templates( $applications ) {
98 usort(
99 $applications,
100 function( $a, $b ) {
101 return strcmp( $a['name'], $b['name'] );
102 }
103 );
104 return $applications;
105 }
106
107 /**
108 * @return void
109 */
110 public static function load_assets() {
111 $plugin_url = FrmAppHelper::plugin_url();
112 $version = FrmAppHelper::plugin_version();
113
114 wp_enqueue_style( 'formidable-admin' );
115 wp_enqueue_style( 'formidable-grids' );
116
117 $js_dependencies = array(
118 'wp-i18n',
119 'formidable_dom',
120 );
121 wp_register_script( 'formidable_applications', $plugin_url . '/js/admin/applications.js', $js_dependencies, $version, true );
122 wp_register_style( 'formidable_applications', $plugin_url . '/css/admin/applications.css', array(), $version );
123
124 $js_vars = array(
125 'proUpgradeUrl' => FrmAppHelper::admin_upgrade_link( 'applications' ),
126 );
127 wp_localize_script( 'formidable_applications', 'frmApplicationsVars', $js_vars );
128
129 wp_enqueue_script( 'formidable_applications' );
130 wp_enqueue_style( 'formidable_applications' );
131
132 do_action( 'frm_applications_assets' );
133 }
134
135 /**
136 * @return void
137 */
138 public static function dequeue_scripts() {
139 if ( 'formidable-applications' === FrmAppHelper::simple_get( 'page', 'sanitize_title' ) ) {
140 // Avoid extra scripts loading on applications index that aren't needed.
141 wp_dequeue_script( 'frm-surveys-admin' );
142 wp_dequeue_script( 'frm-quizzes-form-action' );
143 }
144 }
145
146 /**
147 * @param string $title
148 * @param string $context values include 'index', 'list', and 'edit'.
149 * @return void
150 */
151 public static function render_applications_header( $title, $context ) {
152 require self::get_view_path() . 'header.php';
153 }
154 }
155