PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 2.05.09
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v2.05.09
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 / FrmAddonsController.php

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

319 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class FrmAddonsController {
4
5 public static function menu() {
6 add_submenu_page( 'formidable', 'Formidable | ' . __( 'AddOns', 'formidable' ), __( 'AddOns', 'formidable' ), 'frm_view_forms', 'formidable-addons', 'FrmAddonsController::list_addons' );
7
8 if ( ! FrmAppHelper::pro_is_installed() ) {
9 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Upgrade to Pro', 'formidable' ), __( 'Upgrade to Pro', 'formidable' ), 'frm_view_forms', 'formidable-pro-upgrade', 'FrmAddonsController::upgrade_to_pro' );
10 }
11 }
12
13 public static function list_addons() {
14 $installed_addons = apply_filters( 'frm_installed_addons', array() );
15
16 $addons = self::get_api_addons();
17 self::prepare_addons( $addons );
18
19 $site_url = 'https://formidableforms.com/';
20
21 include( FrmAppHelper::plugin_path() . '/classes/views/addons/list.php' );
22 }
23
24 public static function license_settings() {
25 $plugins = apply_filters( 'frm_installed_addons', array() );
26 if ( empty( $plugins ) ) {
27 _e( 'There are no plugins on your site that require a license', 'formidable' );
28 return;
29 }
30
31 ksort( $plugins );
32 $allow_autofill = self::allow_autofill();
33
34 include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' );
35 }
36
37 /**
38 * Don't allow subsite addon licenses to be fetched
39 * unless the current user has super admin permissions
40 *
41 * @since 2.03.10
42 */
43 private static function allow_autofill() {
44 $allow_autofill = FrmAppHelper::pro_is_installed();
45 if ( $allow_autofill && is_multisite() ) {
46 $sitewide_activated = get_site_option( 'frmpro-wpmu-sitewide' );
47 if ( $sitewide_activated ) {
48 $allow_autofill = current_user_can( 'setup_network' );
49 }
50 }
51 return $allow_autofill;
52 }
53
54 private static function get_api_addons() {
55 $addons = array(
56 'formidable-pro' => array(
57 'title' => 'Formidable Pro',
58 'link' => 'pricing/',
59 'docs' => '',
60 'file' => 'formidable/pro',
61 'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.',
62 ),
63 'mailchimp' => array(
64 'title' => 'MailChimp',
65 'excerpt' => 'Get on the path to more sales and leads in a matter of minutes. Add leads to a MailChimp mailing list when they submit forms and update their information along with the entry.',
66 ),
67 'registration' => array(
68 'title' => 'User Registration',
69 'link' => 'downloads/user-registration/',
70 'excerpt' => 'Give new users access to your site as quickly and painlessly as possible. Allow users to register, edit and be able to login to their profiles on your site from the front end in a clean, customized registration form.',
71 ),
72 'paypal' => array(
73 'title' => 'PayPal Standard',
74 'link' => 'downloads/paypal-standard/',
75 'excerpt' => 'Automate your business by collecting instant payments from your clients. Collect information, calculate a total, and send them on to PayPal. Require a payment before publishing content on your site.',
76 ),
77 'stripe' => array(
78 'title' => 'Stripe',
79 'docs' => 'stripe/',
80 'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.',
81 ),
82 'authorize-net' => array(
83 'title' => 'Authorize.net AIM',
84 'link' => 'downloads/authorize-net-aim/',
85 'docs' => 'authorize-net-aim/',
86 'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.',
87 ),
88 'woocommerce' => array(
89 'title' => 'WooCommerce',
90 'excerpt' => 'Use a Formidable form on your WooCommerce product pages.',
91 ),
92 'autoresponder' => array(
93 'title' => 'Form Action Automation',
94 'docs' => 'schedule-autoresponder/',
95 'excerpt' => 'Schedule email notifications, SMS messages, and API actions.',
96 ),
97 'modal' => array(
98 'title' => 'Bootstrap Modal',
99 'link' => 'downloads/bootstrap-modal/',
100 'docs' => 'bootstrap-modal/',
101 'excerpt' => 'Open a view or form in a Bootstrap popup.',
102 ),
103 'bootstrap' => array(
104 'title' => 'Bootstrap',
105 'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.',
106 ),
107 'zapier' => array(
108 'title' => 'Zapier',
109 'excerpt' => 'Connect with hundreds of different applications through Zapier. Insert a new row in a Google docs spreadsheet, post on Twitter, or add a new Dropbox file with your form.',
110 ),
111 'signature' => array(
112 'title' => 'Signature',
113 'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.',
114 ),
115 'api' => array(
116 'title' => 'Formidable API',
117 'link' => 'downloads/formidable-api/',
118 'excerpt' => 'Send entry results to any other site that has a Rest API. This includes the option of sending entries from one Formidable site to another.',
119 ),
120 'twilio' => array(
121 'title' => 'Twilio',
122 'docs' => 'twilio-add-on/',
123 'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.',
124 ),
125 'aweber' => array(
126 'title' => 'AWeber',
127 'excerpt' => 'Subscribe users to an AWeber mailing list when they submit a form. AWeber is a powerful email marketing service.',
128 ),
129 'highrise' => array(
130 'title' => 'Highrise',
131 'excerpt' => 'Add your leads to your Highrise CRM account any time a Formidable form is submitted.',
132 ),
133 'wpml' => array(
134 'title' => 'WP Multilingual',
135 'link' => 'downloads/wp-multilingual/',
136 'docs' => 'formidable-multi-language/',
137 'excerpt' => 'Translate your forms into multiple languages using the Formidable-integrated WPML plugin.',
138 ),
139 'polylang' => array(
140 'title' => 'Polylang',
141 'excerpt' => 'Create bilingual or multilingual forms with help from Polylang.',
142 ),
143 'locations' => array(
144 'title' => 'Locations',
145 'excerpt' => 'Populate fields with Countries, States/Provinces, U.S. Counties, and U.S. Cities. This data can then be used in dependent Data from Entries fields.',
146 ),
147 'user-tracking' => array(
148 'title' => 'User Tracking',
149 'excerpt' => 'Track which pages a user visits prior to submitting a form.',
150 ),
151 );
152
153 return $addons;
154 }
155
156 private static function prepare_addons( &$addons ) {
157 $activate_url = '';
158 if ( current_user_can( 'activate_plugins' ) ) {
159 $activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) );
160 }
161
162 $loop_addons = $addons;
163 foreach ( $loop_addons as $slug => $addon ) {
164 if ( isset( $addon['file'] ) ) {
165 $base_file = $addon['file'];
166 } else {
167 $base_file = 'formidable-' . $slug;
168 }
169 $file = WP_PLUGIN_DIR . '/' . $base_file;
170
171 $addon['installed'] = is_dir( $file );
172 $addon['activate_url'] = '';
173 if ( $addon['installed'] && ! empty( $activate_url ) ) {
174 if ( file_exists( $file . '/' . $base_file . '.php' ) ) {
175 $file_name = $base_file . '/' . $base_file . '.php';
176 if ( ! is_plugin_active( $file_name ) ) {
177 $addon['activate_url'] = add_query_arg( array(
178 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ),
179 'plugin' => $file_name,
180 ), $activate_url );
181 }
182 }
183 }
184
185 if ( ! isset( $addon['docs'] ) ) {
186 $addon['docs'] = 'formidable-' . $slug . '/';
187 }
188
189 if ( ! isset( $addon['link'] ) ) {
190 $addon['link'] = 'downloads/' . $slug . '/';
191 }
192 $addon['link'] = FrmAppHelper::make_affiliate_url( $addon['link'] );
193
194 $addons[ $slug ] = $addon;
195 }
196 }
197
198 public static function get_licenses() {
199 $allow_autofill = self::allow_autofill();
200 $required_role = $allow_autofill ? 'setup_network' : 'frm_change_settings';
201 FrmAppHelper::permission_check( $required_role );
202 check_ajax_referer( 'frm_ajax', 'nonce' );
203
204 if ( is_multisite() && get_site_option( 'frmpro-wpmu-sitewide' ) ) {
205 $license = get_site_option( 'frmpro-credentials' );
206 } else {
207 $license = get_option( 'frmpro-credentials' );
208 }
209
210 if ( $license && is_array( $license ) && isset( $license['license'] ) ) {
211 $url = 'https://formidableforms.com/frm-edd-api/licenses?l=' . urlencode( base64_encode( $license['license'] ) );
212 $licenses = self::send_api_request( $url, array(
213 'name' => 'frm_api_licence',
214 'expires' => 60 * 60 * 5,
215 ) );
216 echo json_encode( $licenses );
217 }
218
219 wp_die();
220 }
221
222 private static function send_api_request( $url, $transient = array() ) {
223 $data = get_transient( $transient['name'] );
224 if ( $data !== false ) {
225 return $data;
226 }
227
228 $arg_array = array(
229 'body' => array(
230 'url' => home_url(),
231 ),
232 'timeout' => 15,
233 'sslverify' => false,
234 'user-agent' => 'Formidable/' . FrmAppHelper::$plug_version . '; ' . home_url(),
235 );
236
237 $response = wp_remote_post( $url, $arg_array );
238 $body = wp_remote_retrieve_body( $response );
239 $data = false;
240 if ( ! is_wp_error( $response ) && ! is_wp_error( $body ) ) {
241 $data = json_decode( $body, true );
242 set_transient( $transient['name'], $data, $transient['expires'] );
243 }
244
245 return $data;
246 }
247
248 public static function upgrade_to_pro() {
249 $pro_pricing = self::prepare_pro_info();
250
251 include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' );
252 }
253
254 private static function prepare_pro_info() {
255 return array(
256 'personal' => array(
257 'id' => 2,
258 'download' => 19367654,
259 'price' => '49.00',
260 'name' => 'Personal',
261 ),
262 'professional' => array(
263 'id' => 0,
264 'download' => 19367001,
265 'price' => '99.00',
266 'name' => 'Professional',
267 ),
268 'smallbusiness' => array(
269 'id' => 0,
270 'download' => 19366995,
271 'price' => '199.00',
272 'name' => 'Small Business',
273 ),
274 'enterprise' => array(
275 'id' => 0,
276 'download' => 19366992,
277 'price' => '399.00',
278 'name' => 'Enterprise',
279 ),
280 );
281 }
282
283 /**
284 * Add a filter to shorten the EDD filename for Formidable plugin, and add-on, updates
285 *
286 * @since 2.03.08
287 *
288 * @param boolean $return
289 * @param string $package
290 *
291 * @return boolean
292 */
293 public static function add_shorten_edd_filename_filter( $return, $package ) {
294 if ( strpos( $package, '/edd-sl/package_download/' ) !== false && strpos( $package, 'formidableforms.com' ) !== false ) {
295 add_filter( 'wp_unique_filename', 'FrmAddonsController::shorten_edd_filename', 10, 2 );
296 }
297
298 return $return;
299 }
300
301 /**
302 * Shorten the EDD filename for automatic updates
303 * Decreases size of file path so file path limit is not hit on Windows servers
304 *
305 * @since 2.03.08
306 *
307 * @param string $filename
308 * @param string $ext
309 *
310 * @return string
311 */
312 public static function shorten_edd_filename( $filename, $ext ) {
313 $filename = substr( $filename, 0, 50 ) . $ext;
314 remove_filter( 'wp_unique_filename', 'FrmAddonsController::shorten_edd_filename', 10 );
315
316 return $filename;
317 }
318 }
319