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
|
|
|
include( FrmAppHelper::plugin_path() . '/classes/views/addons/settings.php' ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
private static function get_api_addons() { |
35
|
|
|
$addons = array( |
36
|
|
|
'formidable-pro' => array( |
37
|
|
|
'title' => 'Formidable Pro', |
38
|
|
|
'link' => 'pricing/', |
39
|
|
|
'docs' => '', |
40
|
|
|
'file' => 'formidable/pro', |
41
|
|
|
'excerpt' => 'Enhance your basic Formidable forms with a plethora of Pro field types and features. Create advanced forms and data-driven applications in minutes.', |
42
|
|
|
), |
43
|
|
|
'mailchimp' => array( |
44
|
|
|
'title' => 'MailChimp', |
45
|
|
|
'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.', |
46
|
|
|
), |
47
|
|
|
'registration' => array( |
48
|
|
|
'title' => 'User Registration', |
49
|
|
|
'link' => 'downloads/user-registration/', |
50
|
|
|
'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.', |
51
|
|
|
), |
52
|
|
|
'paypal' => array( |
53
|
|
|
'title' => 'PayPal Standard', |
54
|
|
|
'link' => 'downloads/paypal-standard/', |
55
|
|
|
'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.', |
56
|
|
|
), |
57
|
|
|
'stripe' => array( |
58
|
|
|
'title' => 'Stripe', |
59
|
|
|
'docs' => 'stripe/', |
60
|
|
|
'excerpt' => 'Any Formidable forms on your site can accept credit card payments without users ever leaving your site.', |
61
|
|
|
), |
62
|
|
|
'authorize-net' => array( |
63
|
|
|
'title' => 'Authorize.net AIM', |
64
|
|
|
'link' => 'downloads/authorize-net-aim/', |
65
|
|
|
'docs' => 'authorize-net-aim/', |
66
|
|
|
'excerpt' => 'Accept one-time payments directly on your site, using Authorize.net AIM.', |
67
|
|
|
), |
68
|
|
|
'woocommerce' => array( |
69
|
|
|
'title' => 'WooCommerce', |
70
|
|
|
'excerpt' => 'Use a Formidable form on your WooCommerce product pages.', |
71
|
|
|
), |
72
|
|
|
'autoresponder' => array( |
73
|
|
|
'title' => 'Form Action Automation', |
74
|
|
|
'docs' => 'schedule-autoresponder/', |
75
|
|
|
'excerpt' => 'Schedule email notifications, SMS messages, and API actions.', |
76
|
|
|
), |
77
|
|
|
'modal' => array( |
78
|
|
|
'title' => 'Bootstrap Modal', |
79
|
|
|
'link' => 'downloads/bootstrap-modal/', |
80
|
|
|
'docs' => 'bootstrap-modal/', |
81
|
|
|
'excerpt' => 'Open a view or form in a Bootstrap popup.', |
82
|
|
|
), |
83
|
|
|
'bootstrap' => array( |
84
|
|
|
'title' => 'Bootstrap', |
85
|
|
|
'excerpt' => 'Instantly add Bootstrap styling to all your Formidable forms.', |
86
|
|
|
), |
87
|
|
|
'zapier' => array( |
88
|
|
|
'title' => 'Zapier', |
89
|
|
|
'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.', |
90
|
|
|
), |
91
|
|
|
'signature' => array( |
92
|
|
|
'title' => 'Signature', |
93
|
|
|
'excerpt' => 'Add a signature field to your form. The user may write their signature with a trackpad/mouse or just type it.', |
94
|
|
|
), |
95
|
|
|
'api' => array( |
96
|
|
|
'title' => 'Formidable API', |
97
|
|
|
'link' => 'downloads/formidable-api/', |
98
|
|
|
'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.', |
99
|
|
|
), |
100
|
|
|
'twilio' => array( |
101
|
|
|
'title' => 'Twilio', |
102
|
|
|
'docs' => 'twilio-add-on/', |
103
|
|
|
'excerpt' => 'Allow users to text their votes for polls created by Formidable Forms, or send SMS notifications when entries are submitted or updated.', |
104
|
|
|
), |
105
|
|
|
'aweber' => array( |
106
|
|
|
'title' => 'AWeber', |
107
|
|
|
'excerpt' => 'Subscribe users to an AWeber mailing list when they submit a form. AWeber is a powerful email marketing service.', |
108
|
|
|
), |
109
|
|
|
'highrise' => array( |
110
|
|
|
'title' => 'Highrise', |
111
|
|
|
'excerpt' => 'Add your leads to your Highrise CRM account any time a Formidable form is submitted.', |
112
|
|
|
), |
113
|
|
|
'wpml' => array( |
114
|
|
|
'title' => 'WP Multilingual', |
115
|
|
|
'link' => 'downloads/wp-multilingual/', |
116
|
|
|
'docs' => 'formidable-multi-language/', |
117
|
|
|
'excerpt' => 'Translate your forms into multiple languages using the Formidable-integrated WPML plugin.', |
118
|
|
|
), |
119
|
|
|
'polylang' => array( |
120
|
|
|
'title' => 'Polylang', |
121
|
|
|
'excerpt' => 'Create bilingual or multilingual forms with help from Polylang.', |
122
|
|
|
), |
123
|
|
|
'math-captcha' => array( |
124
|
|
|
'title' => 'Math Captcha', |
125
|
|
|
'excerpt' => 'Require users to perform a simple calculation before submitting a form to prevent spam. This add-on extends BestWebSoft\'s Captcha plugin.', |
126
|
|
|
), |
127
|
|
|
'locations' => array( |
128
|
|
|
'title' => 'Locations', |
129
|
|
|
'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.', |
130
|
|
|
), |
131
|
|
|
'user-tracking' => array( |
132
|
|
|
'title' => 'User Tracking', |
133
|
|
|
'excerpt' => 'Track which pages a user visits prior to submitting a form.', |
134
|
|
|
), |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
return $addons; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
private static function prepare_addons( &$addons ) { |
141
|
|
|
$activate_url = ''; |
142
|
|
|
if ( current_user_can( 'activate_plugins' ) ) { |
143
|
|
|
$activate_url = add_query_arg( array( 'action' => 'activate' ), admin_url( 'plugins.php' ) ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$loop_addons = $addons; |
147
|
|
|
foreach ( $loop_addons as $slug => $addon ) { |
148
|
|
|
if ( isset( $addon['file'] ) ) { |
149
|
|
|
$base_file = $addon['file']; |
150
|
|
|
} else { |
151
|
|
|
$base_file = 'formidable-' . $slug; |
152
|
|
|
} |
153
|
|
|
$file = WP_PLUGIN_DIR . '/' . $base_file; |
154
|
|
|
|
155
|
|
|
$addon['installed'] = is_dir( $file ); |
156
|
|
|
$addon['activate_url'] = ''; |
157
|
|
|
if ( $addon['installed'] && ! empty( $activate_url ) ) { |
158
|
|
|
if ( file_exists( $file . '/' . $base_file . '.php' ) ) { |
159
|
|
|
$file_name = $base_file . '/' . $base_file . '.php'; |
160
|
|
|
if ( ! is_plugin_active( $file_name ) ) { |
161
|
|
|
$addon['activate_url'] = add_query_arg( array( |
162
|
|
|
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $file_name ), |
163
|
|
|
'plugin' => $file_name, |
164
|
|
|
), $activate_url ); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
if ( ! isset( $addon['docs'] ) ) { |
170
|
|
|
$addon['docs'] = 'formidable-' . $slug . '/'; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if ( ! isset( $addon['link'] ) ) { |
174
|
|
|
$addon['link'] = 'downloads/' . $slug . '/'; |
175
|
|
|
} |
176
|
|
|
$addon['link'] = FrmAppHelper::make_affiliate_url( $addon['link'] ); |
177
|
|
|
|
178
|
|
|
$addons[ $slug ] = $addon; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public static function get_licenses() { |
183
|
|
|
FrmAppHelper::permission_check('frm_change_settings'); |
184
|
|
|
check_ajax_referer( 'frm_ajax', 'nonce' ); |
185
|
|
|
|
186
|
|
|
$license = get_option('frmpro-credentials'); |
187
|
|
|
if ( $license && is_array( $license ) && isset( $license['license'] ) ) { |
188
|
|
|
$url = 'https://formidableforms.com/frm-edd-api/licenses?l=' . urlencode( base64_encode( $license['license'] ) ); |
189
|
|
|
$licenses = self::send_api_request( $url, array( 'name' => 'frm_api_licence', 'expires' => 60 * 60 * 5 ) ); |
190
|
|
|
echo json_encode( $licenses ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
wp_die(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
private static function send_api_request( $url, $transient = array() ) { |
197
|
|
|
$data = get_transient( $transient['name'] ); |
198
|
|
|
if ( $data !== false ) { |
199
|
|
|
return $data; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$arg_array = array( |
203
|
|
|
'body' => array( |
204
|
|
|
'url' => home_url(), |
205
|
|
|
), |
206
|
|
|
'timeout' => 15, |
207
|
|
|
'sslverify' => false, |
208
|
|
|
'user-agent' => 'Formidable/' . FrmAppHelper::$plug_version . '; ' . home_url(), |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$response = wp_remote_post( $url, $arg_array ); |
212
|
|
|
$body = wp_remote_retrieve_body( $response ); |
213
|
|
|
$data = false; |
214
|
|
|
if ( ! is_wp_error( $response ) && ! is_wp_error( $body ) ) { |
215
|
|
|
$data = json_decode( $body, true ); |
216
|
|
|
set_transient( $transient['name'], $data, $transient['expires'] ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return $data; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public static function upgrade_to_pro() { |
223
|
|
|
$pro_pricing = self::prepare_pro_info(); |
224
|
|
|
|
225
|
|
|
include( FrmAppHelper::plugin_path() . '/classes/views/addons/upgrade_to_pro.php' ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
private static function prepare_pro_info() { |
229
|
|
|
$pro_pricing = array( |
230
|
|
|
'personal' => array( 'id' => 5, 'price' => '49.00', 'name' => 'Personal' ), |
231
|
|
|
'professional' => array( 'id' => 6, 'price' => '99.00', 'name' => 'Professional' ), |
232
|
|
|
'smallbusiness' => array( 'id' => 3, 'price' => '199.00', 'name' => 'Small Business' ), |
233
|
|
|
'enterprise' => array( 'id' => 4, 'price' => '399.00', 'name' => 'Enterprise' ), |
234
|
|
|
); |
235
|
|
|
|
236
|
|
|
return $pro_pricing; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Add a filter to shorten the EDD filename for Formidable plugin, and add-on, updates |
241
|
|
|
* |
242
|
|
|
* @since 2.03.08 |
243
|
|
|
* |
244
|
|
|
* @param boolean $return |
245
|
|
|
* @param string $package |
246
|
|
|
* |
247
|
|
|
* @return boolean |
248
|
|
|
*/ |
249
|
|
|
public static function add_shorten_edd_filename_filter( $return, $package ) { |
250
|
|
|
if ( strpos( $package, '/edd-sl/package_download/' ) !== false && strpos( $package, 'formidableforms.com' ) !== false ) { |
251
|
|
|
add_filter( 'wp_unique_filename', 'FrmAddonsController::shorten_edd_filename', 10, 2 ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return $return; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Shorten the EDD filename for automatic updates |
259
|
|
|
* Decreases size of file path so file path limit is not hit on Windows servers |
260
|
|
|
* |
261
|
|
|
* @since 2.03.08 |
262
|
|
|
* |
263
|
|
|
* @param string $filename |
264
|
|
|
* @param string $ext |
265
|
|
|
* |
266
|
|
|
* @return string |
267
|
|
|
*/ |
268
|
|
|
public static function shorten_edd_filename( $filename, $ext ) { |
269
|
|
|
$filename = substr( $filename, 0, 50 ) . $ext; |
270
|
|
|
remove_filter( 'wp_unique_filename', 'FrmAddonsController::shorten_edd_filename', 10 ); |
271
|
|
|
|
272
|
|
|
return $filename; |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|